-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·74 lines (58 loc) · 2.36 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Author : James Nock (@Jpnock)
# Year : 2023
set -uo pipefail
shopt -s globstar
# make clean
make
mkdir -p bin
mkdir -p bin/output
TOTAL=0
PASSING=0
J_UNIT_OUTPUT_FILE="./bin/junit_results.xml"
printf '%s\n' '<?xml version="1.0" encoding="UTF-8"?>' > "${J_UNIT_OUTPUT_FILE}"
printf '%s\n' '<testsuite name="Integration test">' >> "${J_UNIT_OUTPUT_FILE}"
fail_testcase() {
echo -e "\t> ${1}"
printf '%s\n' "<error type=\"error\" message=\"${1}\">${1}</error>" >> "${J_UNIT_OUTPUT_FILE}"
printf '%s\n' "</testcase>" >> "${J_UNIT_OUTPUT_FILE}"
}
for DRIVER in compiler_tests/**/*_driver.c; do
(( TOTAL++ ))
TO_ASSEMBLE="${DRIVER%_driver.c}.c"
LOG_PATH="${TO_ASSEMBLE//\//_}"
LOG_PATH="./bin/output/${LOG_PATH%.c}"
JAVA_ARGS=-XX:+ShowCodeDetailsInExceptionMessages
COMPILER_DIRS=./bin/:./src:./lib/antlr-4.13.0-complete.jar
echo "${TO_ASSEMBLE}"
printf '%s\n' "<testcase name=\"${TO_ASSEMBLE}\">" >> "${J_UNIT_OUTPUT_FILE}"
OUT="${LOG_PATH}"
rm -f "${OUT}.s"
rm -f "${OUT}.o"
rm -f "${OUT}"
java $JAVA_ARGS -cp $COMPILER_DIRS Compiler -S "${TO_ASSEMBLE}" -o "${OUT}.s" -v 2> "${LOG_PATH}.compiler.stderr.log" > "${LOG_PATH}.compiler.stdout.log"
if [ $? -ne 0 ]; then
fail_testcase "Fail: see ${LOG_PATH}.compiler.stderr.log and ${LOG_PATH}.compiler.stdout.log"
continue
fi
riscv64-unknown-elf-gcc -march=rv32imfd -mabi=ilp32d -o "${OUT}.o" -c "${OUT}.s" 2> "${LOG_PATH}.assembler.stderr.log" > "${LOG_PATH}.assembler.stdout.log"
if [ $? -ne 0 ]; then
fail_testcase "Fail: see ${LOG_PATH}.assembler.stderr.log and ${LOG_PATH}.assembler.stdout.log"
continue
fi
riscv64-unknown-elf-gcc -march=rv32imfd -mabi=ilp32d -static -o "${OUT}" "${OUT}.o" "${DRIVER}" 2> "${LOG_PATH}.linker.stderr.log" > "${LOG_PATH}.linker.stdout.log"
if [ $? -ne 0 ]; then
fail_testcase "Fail: see ${LOG_PATH}.linker.stderr.log and ${LOG_PATH}.linker.stdout.log"
continue
fi
spike pk "${OUT}" > "${LOG_PATH}.simulation.log"
if [ $? -eq 0 ]; then
echo -e "\t> Pass"
(( PASSING++ ))
printf '%s\n' "</testcase>" >> "${J_UNIT_OUTPUT_FILE}"
else
fail_testcase "Fail: simulation did not exit with exit-code 0"
fi
done
printf "\nPassing %d/%d tests\n" "${PASSING}" "${TOTAL}"
printf '%s\n' '</testsuite>' >> "${J_UNIT_OUTPUT_FILE}"