-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·224 lines (189 loc) · 5.62 KB
/
test
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#! /bin/bash
#====================================================
# file: test.sh
#----------------------------------------------------
# - Test all examples for compilation and tests/
# By
#====================================================
Testfold="tests"
Iterfold="interoperation"
Failfold="fails"
Timefold="timing"
Logfold="log"
Compiler=./compile
Linker=./link
Outfold="out"
TestCounter=0
SuccesCounter=0
#==== newlog : spawn new log ====
function newlog
{
local unique=$(date +"%y-%m-%d-%H-%M-%S")
local newlog="$Logfold/test_$unique"
echo > $newlog
echo "$newlog"
}
#==== logtest : log what happens for test $2 ====
function logtest
{
echo "" >> $1
echo "" >> $1
echo "#==========================================#" >> $1
echo "# Result for $2" >> $1
echo "#==========================================#" >> $1
echo "" >> $1
}
#==== printr : print succes or failure ====
function printr
{
if [[ $# -lt 0 ]];then
exit 1;
else
TestCounter=$((TestCounter+1))
if [[ $1 -ne $2 ]];then
echo -e "\033[1;31m[FAIL]\033[0m"
else
SuccesCounter=$((SuccesCounter+1))
echo -e "\033[1;33m[PASS]\033[0m"
fi
fi
}
# Make Log
logname=$(newlog)
echo "== All output stored in: $logname =="
echo "== $logname ==" >>$logname
#==== Normal Tests ====
StartTime=`date +%s`
echo ">> Normal Tests <<"
echo ">> Normal Tests <<" >> $logname
for file in ${Testfold}/*.ml
do
name=${file##*/}
base=${name%.ml}
logtest $logname $base
echo -e "Testing :: \033[1;34m$base\033[0m"
# test compilation and abort further tests if failed
printf " %s" "Compilation :: "
$Compiler 0 $file >> $logname 2>&1
res=$?
printr $res 0
case $res in
0) ;;#let's move on
1) printf " %s\n" "Compilation of C code Failed !"
continue;;
2) printf " %s\n" "MiniML Type Checker Failed !"
continue;;
3) printf " %s\n" "MiniML Compiler Failed !"
continue;;
*) printf " %s\n" "Unkown Error"
esac
# the specific interoperation tests for this file
for testf in ${Testfold}/${Iterfold}/*.c
do
testname=${testf##*/}
testbase=${testname%-*}
if [[ $base =~ .*$testbase.* ]];then
uppname=$(echo $testname | tr '[:lower:]' '[:upper:]')
echo -e " ==> ${uppname} <== "
# Attempt to link - next if failure
printf " %s" "Linking :: "
$Linker ${Outfold}/${base}.o ${testf} >> $logname 2>&1
res=$?
printr $res 0
if [[ $res -ne 0 ]];then
printf " -->"
if [[ $res -ne 2 ]];then
printf "%s\n" "Could not compile $testname!"
fi
continue
fi
# The actual test
printf " %s" "Execution :: "
./${Outfold}/${base}.bin >> $logname 2>&1
printr $? 0
fi
done
done
#==== Failure Tests ====
echo -e "\n>> Failure Tests <<"
echo ">> Failure Tests <<" >> $logname
for file in ${Testfold}/${Failfold}/*.ml
do
testname=${file##*/}
logtest $logname $testname
printf "%s\n" "Testing for :: $testname"
code=$(perl -pe "m/ERRORCODE (?<num>\d+)/; print $+{num}; exit" $file) # I don't understan perl -ne
printf " %s" "Compilation :: "
$Compiler 0 $file >> $logname 2>&1
res=$?
printr $res $code
done
#==== Timing Tests ====
echo -e "\n>> Timing Tests <<"
echo ">> Timing Tests <<" >> $logname
for testf in ${Testfold}/${Timefold}/*.c
do
testname=${testf##*/}
logtest $logname $testname
testbase=${testname%-*}
compbase="${Testfold}/${testbase}.ml"
cbase="${Outfold}/${testbase}.c"
outputb="${Outfold}/${base}.bin"
printf "%s\n" "Testing :: $testname"
# Attempt to link - the secure test
printf " %s" "Linking Secure :: "
$Compiler 0 $compbase > /dev/null 2>&1;
$Linker ${Outfold}/${testbase}.o ${testf} >> $logname 2>&1
res=$?
printr $res 0
if [[ $res -ne 0 ]];then
printf " --> "
if [[ $res -ne 2 ]];then
printf "%s\n" "Could not compile $testname!"
fi
continue
fi
# The secure test
printf " %s" "Secure Execution :: "
output=$(./${Outfold}/${testbase}.bin 2> /dev/null)
echo $output >> $logname
echo $output
# compile an insecure link target
printf " %s" "Insecure Compilation :: "
$Compiler -n $compbase >> $logname 2>&1
res=$?
printr $res 0
if [[ $res -ne 0 ]];then
printf "%s\n" "Could not insec compile $compbase!"
continue
fi
# gcc $cbase ${testf} -I./lib/ -I./out -g -std=c99 -Werror -Wfatal-errors -Wno-unused-value -DINSECURE -o $outputb >> $logname 2>&1
printf " %s" "Linking InSecure :: "
$Linker ${Outfold}/${testbase}_1.o ${testf} -DINSECURE >> $logname 2>&1
res=$?
printr $res 0
if [[ $res -ne 0 ]];then
printf " --> "
if [[ $res -ne 2 ]];then
printf "%s\n" "Could not compile $testname!"
fi
continue
fi
# The insecure test
printf " %s" "InSecure Execution :: "
output=$(./${Outfold}/${testbase}_1.bin 2> /dev/null)
echo $output >> $logname
echo $output
done
#==== Final Result ====
echo -e "\n== FINAL RESULT =="
printf "%s" " "
val=0
if [[ $SuccesCounter -ne $TestCounter ]];then
echo -ne "\033[1;31m[$SuccesCounter]\033[0m"
val=1
else
echo -ne "\033[1;33m[$SuccesCounter]\033[0m"
fi
echo -e " of \033[1;33m[$TestCounter]\033[0m Tests in $(expr `date +%s` - $StartTime)(s)"
exit $val