-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mips_compile.sh
executable file
·49 lines (38 loc) · 1.36 KB
/
test_mips_compile.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
#!/bin/bash
if [[ -z "$1" ]]; then
COMPILER=bin/c_compiler
else
COMPILER=$1
fi
workingin="test/mips_test/testin"
workingout="test/mips_test/output"
mkdir -p $workingout
for DRIVER in $workingin/*_driver.c ; do
NAME=$(basename $DRIVER _driver.c)
TESTCODE=$workingin/$NAME.c
>&2 echo "Test case $NAME"
# Compile driver with normal GCC
mips-linux-gnu-gcc -c $DRIVER -o $workingout/${NAME}_driver.o 2> $workingout/${NAME}_driver.compile.stderr
if [[ $? -ne 0 ]]; then
>&2 echo "ERROR : Couldn't compile driver program using GCC."
continue
fi
# Compile test function with compiler under test to assembly
cat $TESTCODE | $COMPILER "mips" > $workingout/$NAME.s 2> $workingout/${NAME}.compile.stderr
if [[ $? -ne 0 ]]; then
>&2 echo "ERROR : Compiler returned error message."
continue
fi
# Link driver object and assembly into executable
mips-linux-gnu-gcc -static $workingout/${NAME}_driver.o $workingout/${NAME}.s -o $workingout/${NAME}.elf 2> $workingout/${NAME}.link.stderr
if [[ $? -ne 0 ]]; then
>&2 echo "ERROR : Linker returned error message."
continue
fi
# Run the actual executable
qemu-mips $workingout/${NAME}.elf
if [[ $? -ne 1 ]]; then
>&2 echo "ERROR : Testcase returned $?, but expected 0."
fi
echo "pass"
done