riscv / riscv-test-env

https://jira.riscv.org/browse/RVG-141
Other
42 stars 107 forks source link

Check xlen code will always pass #32

Closed feathertw closed 2 years ago

feathertw commented 2 years ago

I am studying riscv-test and I found that CHECK_XLEN in env/p/riscv_test.h is weird.

#if __riscv_xlen == 64
# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bgez a0, 1f; RVTEST_PASS; 1:
#else
# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bltz a0, 1f; RVTEST_PASS; 1:
#endif

I am testing it on spike-riscv64. When I use # define CHECK_XLEN li a0, 1; slli a0, a0, 31; bltz a0, 1f; RVTEST_PASS; 1: (this is for riscv32) to test, it still pass. but I thought it should fail.

I am doing some fix, I think this will make the code better

diff --git a/p/riscv_test.h b/p/riscv_test.h
index a08f49e..ed8d221 100644
--- a/p/riscv_test.h
+++ b/p/riscv_test.h
@@ -58,9 +58,9 @@
   .endm

 #if __riscv_xlen == 64
-# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bgez a0, 1f; RVTEST_PASS; 1:
+# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bgez a0, 2f; li TESTNUM, 1; RVTEST_FAIL; 2:
 #else
-# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bltz a0, 1f; RVTEST_PASS; 1:
+# define CHECK_XLEN li a0, 1; slli a0, a0, 31; bltz a0, 2f; li TESTNUM, 1; RVTEST_FAIL; 2:
 #endif

 #define INIT_XREG
aswaterman commented 2 years ago

The intent of those macros was to cause the test to pass if run with the wrong XLEN. This way, it's possible to run all tests without knowing the target's XLEN. I can understand why you'd find this behavior surprising, but it is doing what it's designed to do.

feathertw commented 2 years ago

I understand. Thank you for replying.