-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.sh
executable file
·238 lines (195 loc) · 4.59 KB
/
run-tests.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/bin/bash
set -e
. inc/tar-writer.sh
usage() {
echo "$0 options"
echo "Runs tests in tests directory"
echo ""
echo "Options:"
echo " -n space separated nodes where test is executed"
echo " -l logfile write complete log to given logfile (stdout by default)"
echo " -c corosync version (flatiron|needle)"
exit 1
}
# 1 - No nodes to find
# Returns nodes number to use or nothing if there is not enough nodes
find_free_nodes() {
ret=""
no_found=0
for ((i = 0; i < ${#test_nodes[*]}; i++));do
if [ "${test_nodes_pid[$i]}" == 0 ];then
ret="$ret $i"
no_found=$(($no_found + 1))
if [ "$no_found" == "$1" ];then
echo $ret
return 0
fi
fi
done
}
run_test() {
local test_name=$1
local test_out=$2
local node_names=$3
echo "---------- $test_name on $node_names ----------"
res=0
"./$test_name" -c "$corosync_version" -n "$node_names" || res=$?
echo "---------- $test_name result = $res ----------"
exit $res
}
# 1 - test to start
# 2 - nodes to use
start_test() {
local test_out=`mktemp`
local node_names=""
local test_name=$1
for i in $2;do
[ "$node_names" != "" ] && node_names="$node_names "
node_names="$node_names${test_nodes[$i]}"
done
run_test "$test_name" "$test_out" "$node_names" &> $test_out &
tpid=$!
j=0
for i in $2;do
test_nodes_pid[$i]=$tpid
if [ "$j" == 0 ];then
test_nodes_test_out[$i]=$test_out
test_nodes_test_name[$i]="$test_name"
j=1
fi
done
}
# Wait for any child to exit
wait_for_any() {
while true; do
for pid in ${test_nodes_pid[*]}; do
if ! kill -0 "$pid" &> /dev/null;then
echo $pid
return 0
fi
done
sleep 1
done
}
# 1 - pid
finish_test() {
local res=0
local pid=$1
wait $pid || res=$?
j=0
for ((i = 0; i < ${#test_nodes[*]}; i++));do
if [ ${test_nodes_pid[$i]} == "$pid" ];then
test_nodes_pid[$i]=0
if [ "$j" == 0 ];then
test_out=${test_nodes_test_out[$i]}
test_name=${test_nodes_test_name[$i]}
j=1
fi
fi
done
if [ $res == 0 ];then
echo "pass $test_name"
no_pass=$(($no_pass + 1))
else
echo "FAILED $test_name"
no_failed=$(($no_failed + 1))
fi
cat $test_out >> $complete_test_out
echo >> $complete_test_out
rm -f $test_out
}
wait_for_all_tests() {
local need_wait=true
while [ "$need_wait" == true ];do
need_wait=false
for ((i = 0; i < ${#test_nodes[*]}; i++));do
[ ${test_nodes_pid[$i]} != "0" ] && need_wait=true
done
if [ "$need_wait" == true ];then
dead_pid=`wait_for_any`
finish_test "$dead_pid"
fi
done
}
set_no_nodes() {
no_nodes=0
for i in $nodes;do
no_nodes=$(($no_nodes + 1))
done
}
init_test_nodes_pid() {
for ((i = 0; i < $no_nodes; i++));do
test_nodes_pid[$i]=0
done
}
logfile="/dev/stdout"
while getopts "hic:l:n:" optflag; do
case "$optflag" in
h)
usage
;;
n)
nodes="$OPTARG"
;;
l)
logfile="$OPTARG"
;;
c)
corosync_version="$OPTARG"
;;
\?|:)
usage
;;
esac
done
if [ "$corosync_version" == "" ];then
echo "corosync version must be specified"
usage
fi
if [ "$corosync_version" != "flatiron" ] && [ "$corosync_version" != "needle" ];then
echo "Unsupported corosync version"
usage
fi
set_no_nodes
if [ "$no_nodes" -lt 1 ];then
echo "There must be at least one node specified"
usage
fi
read -ra test_nodes <<< "$nodes"
declare -a test_nodes_pid; init_test_nodes_pid
declare -a test_nodes_test_out
declare -a test_nodes_test_name
complete_test_out=`mktemp`
no_failed=0
no_pass=0
no_skipped=0
pushd tests &>/dev/null
for test_exec in *.sh;do
[ ! -x "$test_exec" ] && continue
test_info=`./$test_exec -i`
nodes_needed=`echo "$test_info" | grep test_required_nodes | cut -d '=' -f 2-`
corover_enabled=`echo "$test_info" | grep test_corover_${corosync_version}_enabled | cut -d '=' -f 2-`
if [ "$nodes_needed" -gt "$no_nodes" ] || ! $corover_enabled;then
echo "skipped $test_exec"
no_skipped=$(($no_skipped + 1))
continue
fi
free_nodes=""
while [ "$free_nodes" == "" ];do
free_nodes=`find_free_nodes $nodes_needed`
if [ "$free_nodes" == "" ];then
dead_pid=`wait_for_any`
finish_test "$dead_pid"
fi
done
# Start test on given nodes
start_test "$test_exec" "$free_nodes"
done
wait_for_all_tests
popd &>/dev/null
echo
echo "FAILED: $no_failed, pass: $no_pass, skipped: $no_skipped, total: $(($no_pass + $no_failed))"
echo
cat $complete_test_out > $logfile
rm -f $complete_test_out
[ "$no_failed" == 0 ]