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
|
#!/bin/sh
set -ex
test_variant=$1
### defaults
extra_xen_opts=
wait_and_wakeup=
timeout=120
domU_config='
type = "pvh"
name = "domU"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initrd-domU"
extra = "root=/dev/ram0 console=hvc0"
memory = 512
vif = [ "bridge=xenbr0", ]
disk = [ ]
'
### test: smoke test & smoke test PVH
if [ -z "${test_variant}" ] || [ "${test_variant}" = "dom0pvh" ]; then
passed="ping test passed"
domU_check="
ifconfig eth0 192.168.0.2
until ping -c 10 192.168.0.1; do
sleep 1
done
echo \"${passed}\"
"
dom0_check="
until grep -q \"${passed}\" /var/log/xen/console/guest-domU.log; do
sleep 1
done
# get domU console content into test log
tail -n 100 /var/log/xen/console/guest-domU.log
echo \"${passed}\"
"
if [ "${test_variant}" = "dom0pvh" ]; then
extra_xen_opts="dom0=pvh"
fi
### test: S3
elif [ "${test_variant}" = "s3" ]; then
passed="suspend test passed"
wait_and_wakeup="started, suspending"
domU_check="
ifconfig eth0 192.168.0.2
echo domU started
"
dom0_check="
until grep 'domU started' /var/log/xen/console/guest-domU.log; do
sleep 1
done
echo \"${wait_and_wakeup}\"
set -x
echo deep > /sys/power/mem_sleep
echo mem > /sys/power/state
# now wait for resume
sleep 5
# get domU console content into test log
tail -n 100 /var/log/xen/console/guest-domU.log
xl list
xl dmesg | grep 'Finishing wakeup from ACPI S3 state' || exit 1
# check if domU is still alive
ping -c 10 192.168.0.2 || exit 1
echo \"${passed}\"
"
### test: pci-pv, pci-hvm
elif [ "${test_variant}" = "pci-pv" ] || [ "${test_variant}" = "pci-hvm" ]; then
if [ -z "$PCIDEV" ]; then
echo "Please set 'PCIDEV' variable with BDF of test network adapter" >&2
echo "Optionally set also 'PCIDEV_INTR' to 'MSI' or 'MSI-X'" >&2
exit 1
fi
passed="pci test passed"
domU_config='
type = "'${test_variant#pci-}'"
name = "domU"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initrd-domU"
extra = "root=/dev/ram0 console=hvc0 earlyprintk=xen"
memory = 512
vif = [ ]
disk = [ ]
pci = [ "'$PCIDEV',seize=1" ]
on_reboot = "destroy"
'
domU_check="
set -x -e
ip link set eth0 up
timeout 30s udhcpc -i eth0
pingip=\$(ip -o -4 r show default|cut -f 3 -d ' ')
ping -c 10 \"\$pingip\"
echo domU started
cat /proc/interrupts
"
if [ "$PCIDEV_INTR" = "MSI-X" ]; then
domU_check="$domU_check
grep -- '\\(-msi-x\\|PCI-MSI-X\\).*eth0' /proc/interrupts
"
elif [ "$PCIDEV_INTR" = "MSI" ]; then
# depending on the kernel version and domain type, the MSI can be
# marked as '-msi', 'PCI-MSI', or 'PCI-MSI-<SBDF>'; be careful to not match
# -msi-x nor PCI-MSI-X
domU_check="$domU_check
grep -- '\\(-msi \\|PCI-MSI\\( \\|-[^X]\\)\\).*eth0' /proc/interrupts
"
fi
domU_check="$domU_check
echo \"${passed}\"
"
dom0_check="
until grep -q \"^domU Welcome to Alpine Linux\" /var/log/xen/console/guest-domU.log; do
sleep 1
done
tail -n 100 /var/log/xen/console/guest-domU.log
"
fi
# DomU
mkdir -p rootfs
cd rootfs
# fakeroot is needed to preserve device nodes in rootless podman container
fakeroot -s ../fakeroot-save tar xzf ../binaries/initrd.tar.gz
mkdir proc
mkdir run
mkdir srv
mkdir sys
rm var/run
echo "#!/bin/sh
${domU_check}
" > etc/local.d/xen.start
chmod +x etc/local.d/xen.start
echo "rc_verbose=yes" >> etc/rc.conf
sed -i -e 's/^Welcome/domU \0/' etc/issue
find . | fakeroot -i ../fakeroot-save cpio -H newc -o | gzip > ../binaries/domU-rootfs.cpio.gz
cd ..
rm -rf rootfs
# DOM0 rootfs
mkdir -p rootfs
cd rootfs
fakeroot -s ../fakeroot-save tar xzf ../binaries/initrd.tar.gz
mkdir boot
mkdir proc
mkdir run
mkdir srv
mkdir sys
rm var/run
cp -ar ../binaries/dist/install/* .
echo "#!/bin/bash
export LD_LIBRARY_PATH=/usr/local/lib
bash /etc/init.d/xencommons start
brctl addbr xenbr0
brctl addif xenbr0 eth0
ifconfig eth0 up
ifconfig xenbr0 up
ifconfig xenbr0 192.168.0.1
xl create /etc/xen/domU.cfg
${dom0_check}
" > etc/local.d/xen.start
chmod +x etc/local.d/xen.start
echo "$domU_config" > etc/xen/domU.cfg
echo "rc_verbose=yes" >> etc/rc.conf
echo "XENCONSOLED_TRACE=all" >> etc/default/xencommons
echo "QEMU_XEN=/bin/false" >> etc/default/xencommons
mkdir -p var/log/xen/console
cp ../binaries/bzImage boot/vmlinuz
cp ../binaries/domU-rootfs.cpio.gz boot/initrd-domU
find . | fakeroot -i ../fakeroot-save cpio -H newc -o | gzip > ../binaries/dom0-rootfs.cpio.gz
cd ..
TFTP=/scratch/gitlab-runner/tftp
CONTROLLER=control@thor.testnet
echo "
multiboot2 (http)/gitlab-ci/xen $CONSOLE_OPTS loglvl=all guest_loglvl=all dom0_mem=4G $extra_xen_opts
module2 (http)/gitlab-ci/vmlinuz console=hvc0 root=/dev/ram0 earlyprintk=xen
module2 (http)/gitlab-ci/initrd-dom0
" > $TFTP/grub.cfg
cp -f binaries/xen $TFTP/xen
cp -f binaries/bzImage $TFTP/vmlinuz
cp -f binaries/dom0-rootfs.cpio.gz $TFTP/initrd-dom0
# start logging the serial; this gives interactive console, don't close its
# stdin to not close it; the 'cat' is important, plain redirection would hang
# until somebody opens the pipe; opening and closing the pipe is used to close
# the console
mkfifo /tmp/console-stdin
cat /tmp/console-stdin |\
ssh $CONTROLLER console | tee smoke.serial &
# start the system pointing at gitlab-ci predefined config
ssh $CONTROLLER gitlabci poweron
trap "ssh $CONTROLLER poweroff; : > /tmp/console-stdin" EXIT
if [ -n "$wait_and_wakeup" ]; then
# wait for suspend or a timeout
until grep "$wait_and_wakeup" smoke.serial || [ $timeout -le 0 ]; do
sleep 1;
: $((--timeout))
done
if [ $timeout -le 0 ]; then
echo "ERROR: suspend timeout, aborting"
exit 1
fi
# keep it suspended a bit, then wakeup
sleep 30
ssh $CONTROLLER wake
fi
until grep "^Welcome to Alpine Linux" smoke.serial || [ $timeout -le 0 ]; do
sleep 1;
: $((--timeout))
done
tail -n 100 smoke.serial
if [ $timeout -le 0 ]; then
echo "ERROR: test timeout, aborting"
exit 1
fi
sleep 1
(grep -q "^Welcome to Alpine Linux" smoke.serial && grep -q "${passed}" smoke.serial) || exit 1
exit 0
|