-
Notifications
You must be signed in to change notification settings - Fork 227
/
run_tests_parallel.sh
executable file
·205 lines (184 loc) · 4.42 KB
/
run_tests_parallel.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
#!/bin/sh
#
# Copyright (C) 2011-2013 pancake <[email protected]>
# Copyright (C) 2011-2012 Edd Barrett <[email protected]>
# Copyright (C) 2012 Simon Ruderich <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
lock() {
while ! ln -s . lock 2>/dev/null ; do :; done
}
unlock() {
mv lock deleteme && rm -f deleteme
}
# Statistics.
TESTS_TOTAL=0
TESTS_SUCCESS=0
TESTS_FAILED=0
TESTS_BROKEN=0
TESTS_FIXED=0
# Let tests.sh know the complete test suite is run, enables statistics.
R2_SOURCED=1
die() {
echo "$1"
exit 1
}
control_c() {
echo
exit 1
}
trap control_c 2
if [ "$1" = "-j" ]; then
shift
THREADS=$1
shift
else
THREADS=8
fi
. ./tests.sh
r2 > /dev/null
if [ $? != 0 ]; then
echo "Cannot find r2"
exit 1
fi
NTH=0
TFS=""
[ "${THREADS}" -lt 1 ] && THREADS=1
[ -z "${THREADS}" ] && THREADS=8
echo "==> Using $THREADS threads"
FILE_SUCCESS=$(mktemp /tmp/.r2-stats.XXXXXX)
FILE_FAILED=$(mktemp /tmp/.r2-stats.XXXXXX)
FILE_BROKEN=$(mktemp /tmp/.r2-stats.XXXXXX)
FILE_FIXED=$(mktemp /tmp/.r2-stats.XXXXXX)
FILE_TOTAL=$(mktemp /tmp/.r2-stats.XXXXXX)
FILES="${FILE_SUCCESS} ${FILE_FAILED} ${FILE_FIXED} ${FILE_BROKEN} ${FILE_TOTAL}"
for a in $FILES ; do
echo 0 > $a
done
runfile() {
[ -z "$2" ] && return
if [ $THREADS -gt 1 ]; then
TF=`mktemp /tmp/.r2-tests.XXXXXX`
TFS="${TFS} $TF"
NTH=$(($NTH+1))
(
cd $1
. ./$2 > $TF
lock
N=$((`cat ${FILE_SUCCESS}`+${TESTS_SUCCESS})); echo $N > ${FILE_SUCCESS}
N=$((`cat ${FILE_FAILED}`+${TESTS_FAILED})); echo $N > ${FILE_FAILED}
N=$((`cat ${FILE_BROKEN}`+${TESTS_BROKEN})); echo $N > ${FILE_BROKEN}
N=$((`cat ${FILE_FIXED}`+${TESTS_FIXED})); echo $N > ${FILE_FIXED}
N=$((`cat ${FILE_TOTAL}`+${TESTS_TOTAL})); echo $N > ${FILE_TOTAL}
unlock
) &
if [ ${NTH} -ge $THREADS ]; then
NTH=0
wait
cat $TFS
rm -f $TFS
TFS=""
fi
# XXX counters fail here
else
(
cd $1
. ./$2
)
fi
}
R=$PWD
# Run all tests.
T="t"; [ -n "$1" ] && T="$1"
[ -f "$T" -a -x "$T" ] && exec $T
cd $T || die "t/ doesn't exist"
for file in * ; do
[ "$file" = '*' ] && break
if [ -d "$file" ]; then
for file2 in $(ls $file); do
TEST_NAME=$(echo "${file2}" | sed 's/.sh$//')
NAME=`cd $file ; basename $file2`
#TEST_NAME=$file
runfile ./$file/ ${file2}
done
else
NAME=`basename $file`
TEST_NAME=$NAME
runfile ./ ${file}
fi
done
rm -f $TFS
wait
if [ $THREADS -gt 1 ]; then
TESTS_SUCCESS=$(cat ${FILE_SUCCESS})
TESTS_FAILED=$(cat ${FILE_FAILED})
TESTS_FIXED=$(cat ${FILE_FIXED})
TESTS_BROKEN=$(cat ${FILE_BROKEN})
TESTS_TOTAL=$(cat ${FILE_TOTAL})
fi
rm -f ${FILES}
# Print report.
echo
echo "=== Report ==="
echo
printf " SUCCESS"
if [ "${TESTS_SUCCESS}" -gt 0 ]; then
print_success "${TESTS_SUCCESS}"
else
print_failed "${TESTS_SUCCESS}"
fi
printf " FIXED"
if [ "${TESTS_FIXED}" -gt 0 ]; then
print_fixed "${TESTS_FIXED}"
else
print_fixed 0
fi
printf " BROKEN"
if [ "${TESTS_BROKEN}" -gt 0 ]; then
print_broken "${TESTS_BROKEN}"
else
print_broken 0
fi
printf " FAILED"
if [ "${TESTS_FAILED}" -gt 0 ]; then
print_failed "${TESTS_FAILED}"
else
print_failed 0
fi
printf " TOTAL\r"
print_label "[${TESTS_TOTAL}]"
echo
# Save statistics
cd $R
V=`r2 -v 2>/dev/null| grep ^rada| awk '{print $5}'`
touch stats.csv
grep -v "^$V" stats.csv > .stats.csv
echo "$V,${TESTS_SUCCESS},${TESTS_FIXED},${TESTS_BROKEN},${TESTS_FAILED},${FAILED}" >> .stats.csv
sort .stats.csv > stats.csv
rm -f .stats.csv
if [ "${TESTS_FAILED}" -gt 0 ]; then
exit 1
fi
exit 0
# Proper exit code.
if [ "${TESTS_TOTAL}" -eq "${TESTS_SUCCESS}" ]; then
exit 0
elif [ "${TESTS_FAILED}" -eq 0 ]; then
if [ "${TESTS_BROKEN}" -ge 0 ]; then
exit 2
elif [ "${TESTS_FIXED}" -ge 0 ]; then
exit 3
fi
fi
exit 1