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
|
#!/bin/sh -x
#
# Copyright (c) 2013, 2014, 2015 Intel, Inc.
#
# 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; version 2 of the License
#
# 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.
#
# This file is started by cron inside tester VM instance.
# This file should be copied to tester VM image during its setup phase.
# NB! this file is not to be called during regular testing,
# it is included in git repo only to keep it together with
# other scripts.
#
# This script relies on fact that qemu VM gets 10.0.2.2
# configured as default GW. We use it to see that network
# connectivity has reached good state.
#
# set up PATH in case we dont have it (when called from crontab)
PATH=/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin
export PATH
# Regular testing session terminates with poweroff as shutdown
# may take extra time on some distros and regular testing session
# does not care about file system state as HDA is used in snapshot
# mode and never modified.
# However, in some cases, like distro update session,
# the clean shutdown is desired, so we have flag for doing it.
terminate() {
if [ -f /home/build/need_shutdown ]; then
/sbin/shutdown -h now
else
/bin/sync
/bin/umount /home
if grep -q "Debian GNU" /etc/os-release ; then
/sbin/poweroff -f -d
else
/sbin/poweroff --force --poweroff
fi
fi
}
runtest() {
if [ -x /home/build/run ]; then
sleep 10
/home/build/run
echo "$?" > /home/build/testresult
terminate
fi
}
timer=0
while [ $timer -lt 300 ]; do
if mountpoint /home ; then
if grep -q 0202000A /proc/net/route ; then
runtest
exit 0
fi
fi
sleep 5
timer=$((timer + 5))
done
# if we reach here, timeout occured without conditions
# becoming true, we reboot for retry, but not endlessly,
# checking reboot counter we keep in hdb
cntfile="/home/bootcnt"
if mountpoint /home ; then
bootcnt=0
if [ -f $cntfile ]; then
bootcnt=`cat $cntfile`
if [ $bootcnt -gt 5 ]; then
terminate
fi
fi
bootcnt=$((bootcnt+1))
echo "$bootcnt" > $cntfile
/sbin/reboot
else
terminate
fi
|