-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
108 lines (85 loc) · 3.02 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# get those repo via the following link.
# Some cases need to support integer literal -2147483648, which is not included in PKU lab. We can edit them manually.
# https://pku-minic.github.io/online-doc/#/misc-app-ref/environment?id=%e4%bd%bf%e7%94%a8%e5%85%b6%e4%bb%96%e6%b5%8b%e8%af%95%e7%94%a8%e4%be%8b
# find all files whose name include space, and replace those space into "_"
find . -name "* *" -type f | rename 's/ /_/g'
list=()
# get the list of all .c file in "minic-test-cases-2021f" "minic-test-cases-2021s"
list=$(find minic-test-cases-2021f minic-test-cases-2021s -name "*.c")
# get the list of .sy file in "lava-test" and "TrivialCompiler"
list="$list $(find lava-test TrivialCompiler -name "*.sy")"
# sort the list
list=$(echo $list | tr " " "\n" | sort | tr "\n" " ")
cargo build
fail_list=()
# catch control-c, output the failed test cases, and exit
trap 'echo "Failed test cases:"; for file in ${fail_list[@]}; do echo $file; done; exit' INT
for file in $list
do
echo "Testing $file"
rm -f $file.S $file.o $file.elf $file.elf.sysy.out $file.clang.out $file.clang.elf
./target/debug/sysy-compiler -riscv $file -o $file.S > /dev/null 2>&1 # MODIFY ME IF NEEDED
# make sure it return 0
if [ $? -ne 0 ]; then
echo -e "\e[31mOoops\e[0m"
echo "Error in cargo run"
fail_list+=($file)
continue
fi
clang $file.S -c -o $file.o -target riscv32-unknown-linux-elf -march=rv32im -mabi=ilp32
# make sure it return 0
if [ $? -ne 0 ]; then
echo -e "\e[31mOoops\e[0m"
echo "Error in clang"
fail_list+=($file)
continue
fi
ld.lld $file.o -L$CDE_LIBRARY_PATH/riscv32 -lsysy -o $file.elf
# make sure it return 0
if [ $? -ne 0 ]; then
echo -e "\e[31mOoops\e[0m"
echo "Error in ld.lld"
fail_list+=($file)
continue
fi
# build $file.out with clang, with linking
clang -x c $file -L$CDE_LIBRARY_PATH/native -lsysy -o $file.clang.elf > /dev/null 2>&1
# make sure it return 0
if [ $? -ne 0 ]; then
echo -e "\e[31mOoops\e[0m"
echo "Error in clang directly"
fail_list+=($file)
continue
fi
input_file=${file%.c}.in
if [ ! -f $input_file ]; then
input_file=/dev/null
fi
timeout 1m qemu-riscv32-static $file.elf < $input_file > $file.elf.sysy.out
sysy_retval=$?
timeout 1m ./$file.clang.elf < $input_file > $file.clang.out
gcc_retval=$?
# It cannot identify both segmentation fault.
# But it does not matter...
if [ $sysy_retval -ne $gcc_retval ]; then
echo -e "\e[31mOoops\e[0m"
echo "Error: return value not match"
fail_list+=($file)
continue
fi
# compare the output
diff $file.elf.sysy.out $file.clang.out
if [ $? -ne 0 ]; then
echo -e "\e[31mOoops\e[0m"
echo "Error: output not match"
fail_list+=($file)
continue
fi
echo "Test $file passed"
done
echo "Failed test cases:"
for file in ${fail_list[@]}
do
echo $file
done