-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_full.sh
executable file
·435 lines (404 loc) · 10.3 KB
/
run_full.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
cat <<EOF > /tmp/subprojects
selftests selftests
huge_zero huge_zero
hotremove hotremove
sysfs_hotplug acpi_hotplug.*sysfs
acpi_hotplug acpi_hotplug
1gb_hugetlb 1GB
mce_einj mce/einj
mce mce/uc/sr
kvm kvm/
pmem pmem
normal
EOF
if [ "$MODE" == baremetal ] ; then
cat <<EOF > /tmp/run_order
selftests
1gb_hugetlb
normal
reboot
mce_einj
EOF
elif [ "$MODE" == kvm ] ; then
cat <<EOF > /tmp/run_order
sysfs_hotplug,needvm
reboot
acpi_hotplug,needvm
reboot
kvm,needvm
reboot
EOF
elif [ "$MODE" == onlystable ] ; then
cat <<EOF > /tmp/run_ordfer
sysfs_hotplug,needvm
reboot
acpi_hotplug,needvm
reboot
1gb_hugetlb
normal
reboot
huge_zero
reboot
hotremove
reboot
mce_einj
EOF
else
cat <<EOF > /tmp/run_order
sysfs_hotplug,needvm
reboot
acpi_hotplug,needvm
reboot
1gb_hugetlb
normal
pmem
reboot
kvm,needvm
reboot
huge_zero
reboot
hotremove
reboot
mce_einj
reboot
mce
EOF
fi
#
# Usage
# ./run_full.sh <project_basename> [options] [prepare|run|show|summary|check_finished]
#
# Description
# - This script is supposed to be called on host server and the testing
# server is the guest specified by VM=.
# You have to give environment variable VM= when running `prepare` subcommand.
# - Assuming that the remote testing server should have this test tool
# just under home directory.
#
# Options:
# -r|--run-order <file> provide run_order file from command line
# -h|--help
#
# TODO:
# - run subset of subproject only
# - change config setting for each subproject
#
# Environment variable
# - VM
# - STAP_DIR
# - PMEMDEV
# - DAXDEV
# - REBOOTABLE
# - MODE
#
show_help() {
sed -n 2,$[$BASH_LINENO-4]p $BASH_SOURCE | grep "^#" | sed 's/^#/ /'
exit 0
}
THISDIR=$(readlink -f $(dirname $BASH_SOURCE))
cd $THISDIR
RUN_ORDER=/tmp/run_order
while true ; do
case $1 in
-r|--run-order)
RUN_ORDER="$2"
shift 2
;;
-h|--help)
show_help
;;
*)
break
;;
esac
done
projbase=$1
[ ! "$projbase" ] && echo "No project given." && show_help
cmd=$2
[ ! "$cmd" ] && echo "No command given." && show_help
shift 2
filter_file() {
local input=$1
local projbase=$2
local flavor=$3
shift 3
local keywords="$@"
local tmp=
local outfile=work/${projbase}/${flavor}/recipelist
for k in $keywords ; do
tmp="$tmp -e $k"
done
bash run.sh prepare ${projbase}/${flavor}
if [ "$tmp" ] ; then
grep $tmp $input > $outfile
grep -v $tmp $input > ${input}.bak
# input file is replaced with remaining list
mv ${input}.bak ${input}
else
mv $input $outfile
fi
}
vm_running() {
local vm=$1
if [ ! -f "/var/run/libvirt/qemu/$vm.pid" ] ; then
return 1
fi
if ! kill -0 $(cat /var/run/libvirt/qemu/$vm.pid) 2> /dev/null ; then
return 1
fi
return 0
}
vm_ssh_connectable_one() {
local vm=$1
ssh -o ConnectTimeout=10 $vm date > /dev/null 2>&1
}
vm_start_wait_noexpect() {
local vm=$1
local _tmpd=$(mktemp -d)
if ! vm_running $vm ; then
echo "[$vm] starting domain ... "
virsh start $vm > /dev/null 2>&1
fi
for i in $(seq 60) ; do
if vm_ssh_connectable_one $vm ; then
return 0
fi
sleep 1
done
echo "VM started, but not ssh-connectable."
return 1
}
vm_shutdown_wait() {
local vm=$1
local ret=0
if ! vm_running $vm ; then
echo "[$vm] already shut off"
return 0
fi
if vm_ssh_connectable_one $vm ; then
echo "shutdown vm $vm"
ssh $vm "sync ; shutdown -h now"
# virsh start might fail, because the above command terminates the connection
# before the vm completes the shutdown. Need to confirm vm is shut off.
for i in $(seq 60) ; do
if ! vm_running $vm ; then
echo "[$vm] shutdown done"
return 0
fi
sleep 2
done
echo "[$vm] shutdown timeout, destroy it."
else
echo "[$vm] no ssh-connection, destroy it."
fi
timeout 5 virsh destroy $vm
ret=$?
if [ $ret -eq 0 ] ; then
return 1
else
if [ $ret -eq 124 ] ; then
echo "[$vm] virsh destroy timed out"
else
echo "[$vm] virsh destroy failed"
kill -9 $(cat /var/run/libvirt/qemu/$vm.pid)
fi
fi
}
check_and_set_env_vm() {
local projbase=$1
if ! env | grep -q ^VM=\S ; then
export VM=$(cat work/$projbase/vm)
fi
}
validate_recipelist() {
local pj=$1
local rlfile=work/$pj/recipelist
# recipelist should only have a list of testcases (file path of
# each recipe), so should not have any whitespace, so let's use
# it for validation. This is not 100% reliable, but good enough
# for simple checking.
if [ -s "$rlfile" ] ; then
if grep -q " " "$rlfile" ; then
echo "WARNING: recipefile contains irrelevant (not a recipe) line, so removed it."
sed -i -e '/ /d' "$rlfile"
fi
fi
}
if [ "$VM" ] ; then
vm_start_wait_noexpect $VM
export PMEMDEV=$(ssh $VM ndctl list 2> /dev/null | jq -r '.[] | select(.mode=="fsdax") | [.blockdev] | @csv' | head -n1 | tr -d '"')
fi
if [ "$__DEBUG" ] ; then
echo "=== __DEBUG enabled, so show more information about how runtest.sh is running ==="
env
set -x
fi
if [ "$cmd" = prepare ] ; then
make
bash run.sh recipe list > /tmp/recipe
cat /tmp/subprojects | while read spj keywords ; do
filter_file /tmp/recipe ${projbase} $spj $keywords
done
if [ "$VM" ] ; then
echo "=== preparing VM ($VM) ==="
echo $VM > work/$projbase/vm
echo "=== work/$projbase/vm $(cat work/$projbase/vm) ==="
rsync -a --include=work/$projbase --exclude=work/** -e ssh $THISDIR/ $VM:mm_regression || exit 1
rsync -ae ssh $THISDIR/work/$projbase/ $VM:mm_regression/work/$projbase/ || exit 1
scp lib/test_alloc_generic $VM:/usr/local/bin/test_alloc_generic
scp build/page-types $VM:/usr/local/bin/page-types
ssh $VM sync
vm_shutdown_wait $VM
# TODO: page-types might depend on GLIBC version
TMPD=/tmp bash lib/set_vm_numa_settings.sh $VM 8 8
vm_start_wait_noexpect $VM
fi
for spj in $(cat /tmp/subprojects | cut -f1 -d' ') ; do
wc -l work/${projbase}/$spj/recipelist
done
elif [ "$cmd" = run ] ; then
check_and_set_env_vm $projbase
# checking run option
again=
for opt in $@ ; do
if [ "$opt" = "-a" ] ; then
again=true
fi
done
for line in $(cat $RUN_ORDER) ; do
spj=
kvm=
for tmp in $(echo $line | tr ',' ' ') ; do
if [ "$tmp" = reboot ] ; then
if [ "$FINISHED" = true ] && [ "$VM" ] ; then
echo "[$VM] VM stopped after finishing unstable subproject."
vm_shutdown_wait $VM
sleep 5
FINISHED=
fi
elif [ "$tmp" = needvm ] ; then
kvm=true
else
spj=$tmp
if [ ! -d "work/$projbase/$spj" ] ; then
echo "Undefined subproject '$spj', skipped"
spj=
fi
fi
done
[ ! "$spj" ] && continue
echo "subproject:$spj, cmds:${kvm:+kvm}"
echo "validate recipelist for ${projbase}/$spj"
validate_recipelist ${projbase}/$spj
if [ ! "$VM" ] ; then # running testcases on the current server
if [ "$kvm" ] ; then
echo "KVM-related testset $spj is skipped when VM= is not set."
continue
fi
echo "bash run.sh project run $@ ${projbase}/$spj"
bash run.sh project run $@ ${projbase}/$spj
continue
fi
vm_start_wait_noexpect $VM
if [ "$kvm" ] ; then
finished_before="$(bash run.sh proj check_finished ${projbase}/$spj)"
echo "Running testset \"$spj\" on the host server."
echo "bash run.sh project run $@ ${projbase}/$spj"
bash run.sh project run $@ ${projbase}/$spj
finished_after="$(bash run.sh proj check_finished ${projbase}/$spj)"
if [ "$finished_before" = NOTDONE ] && [ "$finished_after" = DONE ] ; then
echo "Subproject $spj finished."
FINISHED=true
fi
else
finished_before="$(bash run.sh proj check_finished ${projbase}/$spj)"
count=3
while [ "$count" -gt 0 ] ; do
count=$[count - 1]
vm_start_wait_noexpect $VM
sleep 5
echo "Running testset $spj on the guest $VM"
# sync current working on testing server to host server
rsync -ae ssh $VM:mm_regression/work/$projbase/ work/$projbase/
if [ ! "$again" ] ; then
finished="$(bash run.sh proj check_finished ${projbase}/$spj)"
echo "Finished: $finished"
if [ "$finished" = DONE ] ; then
break
fi
else
again=
fi
echo ssh -t $VM "REBOOTABLE=true STAP_DIR=$STAP_DIR PMEMDEV=$PMEMDEV bash mm_regression/run.sh project run $@ ${projbase}/$spj"
ssh -t $VM "REBOOTABLE=true STAP_DIR=$STAP_DIR PMEMDEV=$PMEMDEV bash mm_regression/run.sh project run $@ ${projbase}/$spj"
# Sometimes ssh connection is disconnected with error, so
# we need check that VM can continue to test or need rebooting.
if ! vm_ssh_connectable_one $VM ; then
echo "[$VM] VM stopped forcibly"
vm_shutdown_wait $VM
sleep 5
fi
done
rsync -ae ssh $VM:mm_regression/work/$projbase/ work/$projbase/
finished_after="$(bash run.sh proj check_finished ${projbase}/$spj)"
# reboot only when this subproject is finished at this running.
# If it's already finished (judged by the existence of the file
# work/<subproj>/<maxretry>/__finished
if [ "$finished_before" = NOTDONE ] && [ "$finished_after" = DONE ] ; then
echo "Subproject $spj finished."
FINISHED=true
fi
fi
done
elif [ "$cmd" = show ] ; then
check_and_set_env_vm $projbase
if [ "$VM" ] ; then
rsync -ae ssh $VM:mm_regression/work/$projbase/ work/$projbase/
fi
for spj in $(cat $RUN_ORDER | grep -v reboot | cut -f1 -d,) ; do
./run.sh project show ${projbase}/$spj
done
elif [ "$cmd" = summary ] ; then
check_and_set_env_vm $projbase
if [ "$VM" ] ; then
rsync -ae ssh $VM:mm_regression/work/$projbase/ work/$projbase/
fi
tmpf=$(mktemp)
for spj in $(cat $RUN_ORDER | grep -v reboot | cut -f1 -d,) ; do
./run.sh project sum $@ ${projbase}/$spj >> $tmpf
echo >> $tmpf
done
awk 'NF{c=1} (c++)<3' $tmpf
rm $tmpf
elif [ "$cmd" = summary2 ] ; then
check_and_set_env_vm $projbase
if [ "$VM" ] ; then
rsync -ae ssh $VM:mm_regression/work/$projbase/ work/$projbase/
fi
echo > /tmp/.summary2
for spj in $(cat $RUN_ORDER | grep -v reboot | cut -f1 -d,) ; do
./run.sh project sum -P ${projbase}/$spj >> /tmp/.summary2
done
echo "Summary Table:"
ruby test_core/lib/summary_table.rb /tmp/.summary2
elif [ "$cmd" = check_finished ] ; then
if [ -f "work/${projbase}/__finished" ] ; then
exit 0
fi
check_and_set_env_vm $projbase
if [ "$VM" ] ; then
rsync -ae ssh $VM:mm_regression/work/$projbase/ work/$projbase/
fi
for spj in $(cat $RUN_ORDER | grep -v reboot | cut -f1 -d,) ; do
./run.sh project check_finished ${projbase}/$spj
if [ $? -eq 7 ] ; then
# some subprojects are not done yet.
echo "subproject:$spj NOTDONE"
exit 7
fi
echo "subproject:$spj DONE"
done
# all subprojects are done.
touch work/${projbase}/__finished
exit 0
fi