-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-extended.sh
executable file
·96 lines (82 loc) · 2.61 KB
/
test-extended.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
#!/bin/bash
# Author: Bowen (bm2734)
basedir="extended_tests"
files="extended-*.xpp"
TOPLEVEL="./toplevel.native"
LLC="llc"
CC="gcc"
CXX="g++"
CFLAGS="-std=c99 -Wall" # Add -no-pie here for relocation error
CXXFLAGS="-std=c++11 -Wall"
HASH="shasum -a 256"
CheckPass() {
basename=`echo $1 | sed 's/.*\\///
s/.xpp//'`
echo "Testing ${basename}..."
# Build Pixel++ program
../${TOPLEVEL} $1 > ${basename}.ll
${LLC} ${basename}.ll > ${basename}.s
${CC} ${CFLAGS} ${basename}.s stdlib.s load.o -lm -o ${basename}
./${basename} > ${basename}.xpp.out
# Testing
if [[ -f ${basename}.out ]]; then # If the comparison file exists
if diff -bB ${basename}.xpp.out ${basename}.out > ${basename}.diff; then
echo "Positive test passed. The output matches."
else
echo "Positive test failed. The output does not match."
diff -bB ${basename}.xpp.out ${basename}.out
fi
# Clean up
rm -f ${basename}.diff
else
# Build verification program
${CXX} ${CXXFLAGS} ${basename}-v.cpp xppstdlib.cpp -o ${basename}-v
./${basename}-v
# Compare two images
hash1=`${HASH} ${basename}.png | cut -d\ -f1`
hash2=`${HASH} ${basename}-v.png | cut -d\ -f1`
if [ ${hash1} == ${hash2} ]; then
echo "Positive test passed. Images are identical."
else
echo "Positive test failed. Images are different."
${HASH} ${basename}.png ${basename}-v.png
fi
# Clean up
rm -f ${basename}-v ${basename}-v.png
fi
# Clean up
rm -f ${basename}.ll ${basename}.s ${basename} ${basename}.xpp.out
}
CheckFail() {
basename=`echo $1 | sed 's/.*\\///
s/.xpp//'`
echo "Testing ${basename}..."
# Build Pixel++ program
../${TOPLEVEL} $1 2> ${basename}.xpp.err
if diff -bB ${basename}.xpp.err ${basename}.err > ${basename}.diff; then
echo "Negative test passed. The expected error messages are generated."
else
echo "Negative test failed. The expected error messages are not generated."
fi
rm -f ${basename}.xpp.err ${basename}.diff
}
cd ${basedir}
# Build built-in and C libraries
../stdlib/${TOPLEVEL} -c2 ../stdlib/stdlib.xpp > stdlib.ll
${LLC} stdlib.ll > stdlib.s
${CC} ${CFLAGS} -c ../load.c
# Start testing
for file in $files
do
case $file in
*extended*pos*)
CheckPass $file
;;
*extended*neg*)
CheckFail $file
;;
*)
echo "unknown file type $file"
;;
esac
done