-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.sh
93 lines (69 loc) · 2.7 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Author : James Nock (@Jpnock)
# Year : 2023
make clean
set -uo pipefail
shopt -s globstar
make bin/c_compiler
if [[ "$?" -ne 0 ]]; then
echo "Build failed.";
exit;
fi
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}"
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}"
timeout --foreground 5s ./bin/c_compiler -S "${TO_ASSEMBLE}" -o "${OUT}.s" 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
timeout --foreground 5s 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
timeout --foreground 5s 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
timeout --foreground 5s 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}"
#####################################################
# Added for test purposes by @alvi-codes
source test_parsing.sh
custom_total=0
for file in compiler_tests/_custom/*_driver.c; do
((custom_total++))
done
echo "Custom Test Files Included: $custom_total"
#####################################################