Skip to content

Commit dbeebaa

Browse files
committed
riscvtest: Script for downloading and running the RISC-V test suite
1 parent 9f30d90 commit dbeebaa

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

riscvtest

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/bin/sh
2+
3+
readonly SIMULATOR="/Applications/logisim-generic-2.7.1.jar"
4+
readonly TESTSUITE="https://github.com/riscv-software-src/riscv-tests"
5+
readonly SUBDIRECT="isa/rv32ui"
6+
readonly EXPECTOUT="01010a"
7+
8+
repo="`basename "$TESTSUITE"`"
9+
[ -e "$repo" ] || git submodule add "$TESTSUITE" 2>&1 | grep -vF fatal: || git clone "$TESTSUITE"
10+
[ -e "$repo/env/v" ] || git -C riscv-tests submodule update --init --recursive
11+
[ -e libc.a ] || touch libc.a
12+
[ -e crt0.o ] || riscv32-as -o crt0.o <<-sa-23vcsir
13+
.globl _start
14+
_start:
15+
j userstart
16+
sa-23vcsir
17+
18+
if [ ! -e "$SIMULATOR" ]
19+
then
20+
echo "ERROR: Did not find Logisim at $SIMULATOR" >&2
21+
exit 3
22+
fi
23+
24+
if ! type riscv32-gcc >/dev/null 2>&1
25+
then
26+
echo "ERROR: Have you installed the RISC-V toolchain?"
27+
exit 4
28+
fi
29+
30+
if ! type logisimage >/dev/null 2>&1
31+
then
32+
echo "ERROR: Have you installed logisimage and marked it executable?"
33+
exit 5
34+
fi
35+
36+
tests="`basename -s.S "$repo/$SUBDIRECT/"*.S`"
37+
if [ "$#" -lt "1" ]
38+
then
39+
cat <<-tac
40+
USAGE: `basename "$0"` <path to Logisim CPU> [test name]...
41+
42+
Run the official RISC-V test suite.
43+
44+
<simulator> is the path to your CPU project. It may also contain Logisim command-line options.
45+
46+
[test name], if provided, limits the instructions to test. Choose from this list:
47+
$tests
48+
tac
49+
exit 1
50+
fi
51+
52+
flags="$1"
53+
shift
54+
55+
if [ "$#" -eq "0" ]
56+
then
57+
set -- $tests
58+
fi
59+
60+
passed="0"
61+
total="$#"
62+
show="true"
63+
for test in "$@"
64+
do
65+
printf %s "Running test '$test'... "
66+
if riscv32-gcc -I"$repo/env/v" -I"$repo/isa/macros/scalar" "$repo/$SUBDIRECT/$test.S"
67+
then
68+
logisimage a.out a.img
69+
70+
result="`java -jar "$SIMULATOR" -tty tty -load a.img $flags | od -tx1 -An | tr -d " "`"
71+
if [ "$result" = "$EXPECTOUT" ]
72+
then
73+
echo "Passed."
74+
passed="$((passed + 1))"
75+
else
76+
subtest="$((0x$(echo "$result" | head -c2) >> 1))"
77+
echo "FAILED in test case $subtest!"
78+
79+
if "$show"
80+
then
81+
printf %s "Would you like to see the test (Y/n)? " >&2
82+
read choice
83+
case "$choice" in
84+
n)
85+
echo "Declined. Will not ask again." >&2
86+
show="false"
87+
;;
88+
*)
89+
symbol="test_$subtest"
90+
if [ "$symbol" = "test_2" ]
91+
then
92+
symbol="userstart"
93+
fi
94+
95+
riscv32-objdump --disassemble="$symbol" -Mnumeric a.out >&2
96+
echo >&2
97+
98+
printf %s "Hit enter to continue..." >&2
99+
read choice
100+
;;
101+
esac
102+
fi
103+
fi
104+
else
105+
echo "Skipping test of unsupported instruction."
106+
total="$((total - 1))"
107+
fi
108+
done
109+
110+
echo "Passed $passed tests out of $total."
111+
if [ "$passed" -ne "$total" ]
112+
then
113+
echo "THERE WERE FAILING TESTS!" >&2
114+
exit 2
115+
fi

0 commit comments

Comments
 (0)