1#!/bin/sh 2 3set -ex 4 5test_variant=$1 6 7### defaults 8extra_xen_opts= 9wait_and_wakeup= 10timeout=120 11domU_config=' 12type = "pvh" 13name = "domU" 14kernel = "/boot/vmlinuz" 15ramdisk = "/boot/initrd-domU" 16extra = "root=/dev/ram0 console=hvc0" 17memory = 512 18vif = [ "bridge=xenbr0", ] 19disk = [ ] 20' 21 22### test: smoke test & smoke test PVH & smoke test HVM 23if [ -z "${test_variant}" ] || [ "${test_variant}" = "dom0pvh" ] || [ "${test_variant}" = "dom0pvh-hvm" ]; then 24 passed="ping test passed" 25 domU_check=" 26ifconfig eth0 192.168.0.2 27until ping -c 10 192.168.0.1; do 28 sleep 1 29done 30echo \"${passed}\" 31" 32 dom0_check=" 33set +x 34until grep -q \"${passed}\" /var/log/xen/console/guest-domU.log; do 35 sleep 1 36done 37set -x 38echo \"${passed}\" 39" 40if [ "${test_variant}" = "dom0pvh" ] || [ "${test_variant}" = "dom0pvh-hvm" ]; then 41 extra_xen_opts="dom0=pvh" 42fi 43 44if [ "${test_variant}" = "dom0pvh-hvm" ]; then 45 domU_config=' 46type = "hvm" 47name = "domU" 48kernel = "/boot/vmlinuz" 49ramdisk = "/boot/initrd-domU" 50extra = "root=/dev/ram0 console=hvc0" 51memory = 512 52vif = [ "bridge=xenbr0", ] 53disk = [ ] 54' 55fi 56 57### test: S3 58elif [ "${test_variant}" = "s3" ]; then 59 passed="suspend test passed" 60 wait_and_wakeup="started, suspending" 61 domU_check=" 62ifconfig eth0 192.168.0.2 63echo domU started 64" 65 dom0_check=" 66until grep 'domU started' /var/log/xen/console/guest-domU.log; do 67 sleep 1 68done 69echo \"${wait_and_wakeup}\" 70# let the above message flow to console, then suspend 71sync /dev/stdout 72sleep 5 73set -x 74echo deep > /sys/power/mem_sleep 75echo mem > /sys/power/state 76xl list 77xl dmesg | grep 'Finishing wakeup from ACPI S3 state' || exit 1 78# check if domU is still alive 79ping -c 10 192.168.0.2 || exit 1 80echo \"${passed}\" 81" 82 83### test: pci-pv, pci-hvm 84elif [ "${test_variant}" = "pci-pv" ] || [ "${test_variant}" = "pci-hvm" ]; then 85 86 if [ -z "$PCIDEV" ]; then 87 echo "Please set 'PCIDEV' variable with BDF of test network adapter" >&2 88 echo "Optionally set also 'PCIDEV_INTR' to 'MSI' or 'MSI-X'" >&2 89 exit 1 90 fi 91 92 passed="pci test passed" 93 94 domU_config=' 95type = "'${test_variant#pci-}'" 96name = "domU" 97kernel = "/boot/vmlinuz" 98ramdisk = "/boot/initrd-domU" 99extra = "root=/dev/ram0 console=hvc0 earlyprintk=xen" 100memory = 512 101vif = [ ] 102disk = [ ] 103pci = [ "'$PCIDEV',seize=1" ] 104on_reboot = "destroy" 105' 106 107 domU_check=" 108set -x -e 109interface=eth0 110ip link set \"\$interface\" up 111timeout 30s udhcpc -i \"\$interface\" 112pingip=\$(ip -o -4 r show default|cut -f 3 -d ' ') 113ping -c 10 \"\$pingip\" 114echo domU started 115pcidevice=\$(basename \$(readlink /sys/class/net/\$interface/device)) 116lspci -vs \$pcidevice 117" 118 if [ -n "$PCIDEV_INTR" ]; then 119 domU_check="$domU_check 120lspci -vs \$pcidevice | fgrep '$PCIDEV_INTR: Enable+' 121" 122 fi 123 domU_check="$domU_check 124echo \"${passed}\" 125" 126 127 dom0_check=" 128tail -F /var/log/xen/qemu-dm-domU.log & 129until grep -q \"^domU Welcome to Alpine Linux\" /var/log/xen/console/guest-domU.log; do 130 sleep 1 131done 132" 133fi 134 135# DomU 136mkdir -p rootfs 137cd rootfs 138# fakeroot is needed to preserve device nodes in rootless podman container 139fakeroot -s ../fakeroot-save tar xzf ../binaries/initrd.tar.gz 140mkdir proc 141mkdir run 142mkdir srv 143mkdir sys 144rm var/run 145echo "#!/bin/sh 146 147${domU_check} 148" > etc/local.d/xen.start 149chmod +x etc/local.d/xen.start 150echo "rc_verbose=yes" >> etc/rc.conf 151sed -i -e 's/^Welcome/domU \0/' etc/issue 152find . | fakeroot -i ../fakeroot-save cpio -H newc -o | gzip > ../binaries/domU-rootfs.cpio.gz 153cd .. 154rm -rf rootfs 155 156# DOM0 rootfs 157mkdir -p rootfs 158cd rootfs 159fakeroot -s ../fakeroot-save tar xzf ../binaries/initrd.tar.gz 160mkdir boot 161mkdir proc 162mkdir run 163mkdir srv 164mkdir sys 165rm var/run 166cp -ar ../binaries/dist/install/* . 167 168echo "#!/bin/bash 169 170export LD_LIBRARY_PATH=/usr/local/lib 171bash /etc/init.d/xencommons start 172 173brctl addbr xenbr0 174brctl addif xenbr0 eth0 175ifconfig eth0 up 176ifconfig xenbr0 up 177ifconfig xenbr0 192.168.0.1 178 179# get domU console content into test log 180tail -F /var/log/xen/console/guest-domU.log 2>/dev/null | sed -e \"s/^/(domU) /\" & 181xl create /etc/xen/domU.cfg 182${dom0_check} 183" > etc/local.d/xen.start 184chmod +x etc/local.d/xen.start 185echo "$domU_config" > etc/xen/domU.cfg 186 187echo "rc_verbose=yes" >> etc/rc.conf 188echo "XENCONSOLED_TRACE=all" >> etc/default/xencommons 189echo "QEMU_XEN=/bin/false" >> etc/default/xencommons 190mkdir -p var/log/xen/console 191cp ../binaries/bzImage boot/vmlinuz 192cp ../binaries/domU-rootfs.cpio.gz boot/initrd-domU 193find . | fakeroot -i ../fakeroot-save cpio -H newc -o | gzip > ../binaries/dom0-rootfs.cpio.gz 194cd .. 195 196 197TFTP=/scratch/gitlab-runner/tftp 198CONTROLLER=control@thor.testnet 199 200echo " 201multiboot2 (http)/gitlab-ci/xen $CONSOLE_OPTS loglvl=all guest_loglvl=all dom0_mem=4G console_timestamps=boot $extra_xen_opts 202module2 (http)/gitlab-ci/vmlinuz console=hvc0 root=/dev/ram0 earlyprintk=xen 203module2 (http)/gitlab-ci/initrd-dom0 204" > $TFTP/grub.cfg 205 206cp -f binaries/xen $TFTP/xen 207cp -f binaries/bzImage $TFTP/vmlinuz 208cp -f binaries/dom0-rootfs.cpio.gz $TFTP/initrd-dom0 209 210# start logging the serial; this gives interactive console, don't close its 211# stdin to not close it; the 'cat' is important, plain redirection would hang 212# until somebody opens the pipe; opening and closing the pipe is used to close 213# the console 214mkfifo /tmp/console-stdin 215cat /tmp/console-stdin |\ 216ssh $CONTROLLER console | tee smoke.serial | sed 's/\r//' & 217 218# start the system pointing at gitlab-ci predefined config 219ssh $CONTROLLER gitlabci poweron 220trap "ssh $CONTROLLER poweroff; : > /tmp/console-stdin" EXIT 221 222if [ -n "$wait_and_wakeup" ]; then 223 # wait for suspend or a timeout 224 until grep "$wait_and_wakeup" smoke.serial || [ $timeout -le 0 ]; do 225 sleep 1; 226 : $((--timeout)) 227 done 228 if [ $timeout -le 0 ]; then 229 echo "ERROR: suspend timeout, aborting" 230 exit 1 231 fi 232 # keep it suspended a bit, then wakeup 233 sleep 30 234 ssh $CONTROLLER wake 235fi 236 237set +x 238until grep "^Welcome to Alpine Linux" smoke.serial || [ $timeout -le 0 ]; do 239 sleep 1; 240 : $((--timeout)) 241done 242set -x 243 244tail -n 100 smoke.serial 245 246if [ $timeout -le 0 ]; then 247 echo "ERROR: test timeout, aborting" 248 exit 1 249fi 250 251sleep 1 252 253(grep -q "^Welcome to Alpine Linux" smoke.serial && grep -q "${passed}" smoke.serial) || exit 1 254exit 0 255