aboutsummaryrefslogtreecommitdiffstats
path: root/test_compiler.sh
blob: cae39889189de14108e6133b94ea2ac809a7bc41 (plain)
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
#!/bin/bash

# script to test the lexer

echo "========================================"
echo " Cleaning the temporaries and outputs"
make clean
rm -rf ./c_compiler/test/{out,ref}
echo " Force building lexer"
make -B bin/c_compiler

if [[ "$?" -ne 0 ]]; then
    echo "Build failed.";
fi

echo ""
echo ""
echo "========================================="
echo " Testing compiler"

PASSED=0
CHECKED=0

mkdir -p c_compiler/test/out
mkdir -p c_compiler/test/ref

for i in c_compiler/test/in/*.c; do
	echo "==========================="
    echo ""
    echo "Input file : ${i}"
	BASENAME=$(basename $i .c);
    cat $i | ./bin/c_compiler > c_compiler/test/out/$BASENAME.s  2> c_compiler/test/out/$BASENAME.stderr.txt

	mips-linux-gnu-gcc -O0 -S -c c_compiler/test/in/$BASENAME.c -o c_compiler/test/ref/$BASENAME.s
	mips-linux-gnu-gcc -O0 -static c_compiler/test/ref/$BASENAME.s -o c_compiler/test/ref/$BASENAME
	
    mips-linux-gnu-gcc -O0 -static c_compiler/test/out/$BASENAME.s -o c_compiler/test/out/$BASENAME

	qemu-mips c_compiler/test/ref/$BASENAME
	REFOUTPUT=$?
	
	qemu-mips c_compiler/test/out/$BASENAME
	TESTOUTPUT=$?

	if [ "$TESTOUTPUT" = "$REFOUTPUT" ]; then
	    PASSED=$(( PASSED+1 ))
	else
	    echo -e "\nERROR"
	fi

	echo -e "output: $TESTOUTPUT\n"

	CHECKED=$(( CHECKED+1 ))
done

echo "########################################"
echo "Passed ${PASSED} out of ${CHECKED}".
echo ""