-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_blather.sh
220 lines (177 loc) · 6.66 KB
/
test_blather.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
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
#!/bin/bash
# variables which detemine time to wait between client inputs
ticktime_norm=0.05 # ticks during normal test
ticktime_valg=0.5 # ticks during valgrind - longer due to debug delays
ticktime=$ticktime_valg # global tick time, set during normal/valgrind
if [ ! -d $TESTDATA ]; then
printf "Missing directory '%s': create this directory\n" "$TESTDATA"
return 1
fi
CODEDIR=".." # directory where all executables/scripts are stored
TESTDIR="test-data/"
# BL_SERVER="../bl_server"
# BL_CLIENT="../bl_client"
generate=0
run_norm=${RUN_NORM:-"1"} # run normal tests
run_valg=${RUN_VALG:-"1"} # run valgrind tests
# Determine column width of the terminal
if [[ -z "$COLUMNS" ]]; then
printf "Setting COLUMNS based on stty\n"
COLUMNS=$(stty size | awk '{print $2}')
fi
if (($COLUMNS == 0)); then
COLUMNS=126
fi
printf "COLUMNS is $COLUMNS\n"
DIFF="diff -bBy -W $COLUMNS" # -b ignore whitespace, -B ignore blank lines, -y do side-by-side comparison, -W to increase width of columns
VALGRIND="valgrind --leak-check=full --show-leak-kinds=all"
# VALGRIND="valgrind --leak-check=full --show-leak-kinds=all --suppressions=../test.supp"
# VALGRIND="valgrind --leak-check=full --show-leak-kinds=definite" #,indirect,possible"
# VALGRIND="valgrind"
# INPUT=test-data/input.tmp # name for expected output file
# EXPECT=test-data/expect.tmp # name for expected output file
# ACTUAL=test-data/actual.tmp # name for actual output file
# TMPFILE=test-data/temp.tmp # name for actual output file
# DIFFOUT=test-data/diff.tmp # name for diff output file
# VALGOUT=test-data/valgrind.tmp # name for valgrind output file
function major_sep(){
printf '%s\n' '====================================='
}
function minor_sep(){
printf '%s\n' '-------------------------------------'
}
testdata=test_blather_data.sh
if [[ "$1" == "advanced" ]]; then
testdata=test_advanced_data.sh
fi
printf "Loading tests from... "
source "$testdata"
printf "%d tests loaded\n" "$T"
NTESTS=$T
VTESTS=$T
NPASS=0
NVALG=0
all_tests=$(seq $NTESTS)
# Check whether a single test is being run
single_test=$1
if ((single_test > 0 && single_test <= NTESTS)); then
printf "Running single TEST %d\n" "$single_test"
all_tests=$single_test
NTESTS=1
VTESTS=1
else
printf "Running %d tests\n" "$NTESTS"
fi
printf "\n"
printf "RUNNING NORMAL TESTS\n"
cd $TESTDIR
export valg=""
ticktime=$ticktime_norm
if [ "$run_norm" = "1" ]; then
for i in $all_tests; do
printf -v tid "test-%02d" "$i" # test id for various places
printf "TEST %2d %-18s : " "$i" "${tnames[i]}"
# Run the test
outfiles=()
eval "${setup[i]}"
while read -r act; do
eval "$act"
tick
done <<< "${actions[i]}"
eval "${teardown[i]}"
# Check each client output file for failure, print side-by-side diff if problems
failed=0
for ((c=0; c<${#outfiles[*]}; c++)); do
outfile=${outfiles[c]}
printf "%s\n" "${expect_outs[i]}" | awk -F '\t' "{print \$$((c+1))}" > ${outfile}.expect
if ! $DIFF ${outfile}.expect $outfile > ${outfile}.diff
then
printf "FAIL\n"
minor_sep
printf "Difference between '%s' and '%s'\n" "${outfile}.expect" "$outfile"
printf "OUTPUT: EXPECT vs ACTUAL\n"
cat ${outfile}.diff
minor_sep
failed=1
else
rm ${outfile}.diff
# printf "'%s' OK " "${outfile}"
fi
done
if [ "$failed" != "1" ]; then
printf "ALL OK\n"
((NPASS++))
elif [ "$generate" = "1" ]; then
printf "GENERATE\n"
echo "${outfiles[*]}"
paste ${outfiles[*]}
minor_sep
fi
# printf "\n"
done
printf "%s\n" "$major_sep"
printf "Finished:\n"
printf "%2d / %2d Normal correct\n" "$NPASS" "$NTESTS"
printf "\n"
fi
# ================================================================================
if [ "$run_valg" = "1" ]; then
printf "RUNNING VALGRIND TESTS\n"
export valg="$VALGRIND"
export valgpref="valgrind"
ticktime=$ticktime_valg
for i in $all_tests; do
printf -v tid "test-%02d" "$i" # test id for various places
printf "TEST %2d %-18s : " "$i" "${tnames[i]}"
# Run the test
outfiles=()
eval "${setup[i]}"
while read -r act; do
eval "$act"
tick
done <<< "${actions[i]}"
eval "${teardown[i]}"
# Check each client for failure, print side-by-side diff if problems
failed=0
# Check each client for failure, print side-by-side diff if problems
failed=0
for ((c=0; c<${#outfiles[*]}; c++)); do
outfile=${outfiles[c]}
$CODEDIR/test_filter_semopen_bug.awk $outfile > x.tmp # appears that sem_open() bug is resolved
mv x.tmp $outfile
# Check various outputs from valgrind
(grep -q 'ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)' $outfile && # look for 0 errors
grep -q 'in use at exit: 0 bytes in 0 blocks' $outfile) # look for in use at exit
errs=$? # 0 return value if both match
# special case where 'in use at exit' is likely; search only for errors
if [[ "${tnames[i]}" == *"shutdown"* ]]; then
(grep -q 'ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)' $outfile)
errs=$?
fi
if [[ "$errs" != "0" ]]; then
printf "errs: $errs\n"
printf "FAIL\nValgrind detected problems in $outfile\n"
major_sep
cat $outfile
major_sep
failed=1
fi
done
if [ "$failed" != "1" ]; then
printf "ALL OK"
((NVALG++))
fi
printf "\n"
done
major_sep
printf "Finished:\n"
printf "%2d / %2d Valgrind correct\n" "$NVALG" "$VTESTS"
printf "\n"
fi
major_sep
# printf "%2d / %2d Normal correct\n" "$NPASS" "$NTESTS"
# printf "%2d / %2d Valgrind correct\n" "$NVALG" "$VTESTS"
# printf "\n"
totpass=$((NPASS+NVALG))
tottest=$((NTESTS+VTESTS))
printf "RESULTS: %d / %d\n" "$totpass" "$tottest"