-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_runner.sh
executable file
·154 lines (136 loc) · 4.18 KB
/
test_runner.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#! /bin/sh
# Format functions lifed from here:
#bold://askubuntu.com/questions/528928/how-to-do-underline-bold-italic-strikethrough-color-background-and-size-i
bold() { ansi 1 "$@"; }
italic() { ansi 3 "$@"; }
underline() { ansi 4 "$@"; }
strikethrough() { ansi 9 "$@"; }
red() { ansi 31 "$@"; }
green() { ansi 32 "$@"; }
ansi() { printf "\e[${1}m${*:2}\e[0m"; }
if [ ! $(which lli) ]
then
echo $(bold $(red "LLVM not found."))
echo $(bold $(red "Please run this script using make, or add the location of LLVM binaries to your path."))
exit 1
fi
# failures is used as a buffer to hold failure messages
# until the tests are finished running
failures=""
function run_test {
# Param $1: file name
# Param $2: compiler flag
# Param $3: pass or fail - describes if the test should pass or fail
generated_output=$(./toplevel.native -$2 $1 2>&1)
ret_code=$?
if [ $2 == "c" ] && [ $ret_code -ne 0 ]
then
printf "F"
failures+="$(bold "========================================")"
failures+=$'\nTest '
failures+="$f"
failures+=$' failed.\n'
failures+="$generated_output"
failures+=$'\n'
return
fi
if [ $2 == "c" ]
then
# Try running llc, if it errors, write to output and move on
llc_output=$(llc output.ll 2>&1)
ret_code=$?
if [ $ret_code -ne 0 ]
then
generated_output+="$llc_output"
else
# Try running clang, if it errors, write to output and move on
clang_output=$(clang -Wno-override-module -lm output.s _build/src/runtime.o -o output 2>&1)
ret_code=$?
if [ $ret_code -ne 0 ]
then
generated_output+="$clang_output"
else
# Else, capture to output of the compiled program
generated_output=$(./output)
fi
fi
fi
# Set a 'pass mode', this variable describes if a test does what
# we expect, i.e. if we expect a test to fail, and it passes, then
# the pass mode is fail.
if [ $ret_code -eq 0 ] && [ $3 == "pass" ]
then
pass_mode="pass"
elif [ $ret_code -gt 0 ] && [ $3 == "fail" ]
then
pass_mode="pass"
else
pass_mode="fail"
fi
if [ $pass_mode == "pass" ]
then
printf "."
else
printf "F"
failures+="$(bold "========================================")"
failures+=$'\nTest '
failures+="$f"
failures+=$' failed.\n'
failures+="$generated_output"
failures+=$'\n'
return
fi
# If an expected output file exists, compare the generated and expected output
passing_output_file=$(echo $1 | sed -E 's/(.*\/)(.*\.)(tf)/\1\2expected/')
if [ -f $passing_output_file ]; then
passing_output=$(cat $passing_output_file)
if [ "$generated_output" != "$passing_output" ]
then
printf "F"
failures+="$(bold "========================================")"
failures+=$'\nTest '
failures+="$f"
failures+=$' failed.\n'
failures+="$(underline "Expected:")"
failures+=$'\n'
failures+="$(green $passing_output)"
failures+=$'\n\n'
failures+="$(underline "Received:")"
failures+=$'\n'
failures+="$(red $generated_output)"
failures+=$'\n\n'
fi
fi
generated_output=""
passing_output=""
passing_output_file=""
}
# Register new tests below
for f in ./tests/syntax_tests/pass/*.tf; do
run_test $f a pass
done
for f in ./tests/syntax_tests/fail/*.tf; do
run_test $f a fail
done
for f in ./tests/semant_tests/pass/*.tf; do
run_test $f s pass
done
for f in ./tests/semant_tests/fail/*.tf; do
run_test $f s fail
done
for f in ./tests/lift_tests/pass/*.tf; do
run_test $f lift pass
done
for f in ./tests/codegen/pass/*.tf; do
run_test $f c pass
done
echo
if [[ ! -z $failures ]]
then
failures+="$(bold "========================================")"
failures+=$'\n'
printf "%s" "$failures"
exit 1
fi
echo $(bold $(green "All tests pass."))
exit 0