1#!/bin/sh 2 3# keep old /etc 4mount tmpfs -t tmpfs /tmp 5mkdir /tmp/etc 6mount --bind /etc /tmp/etc 7# mount all kinds of things 8mount tmpfs -t tmpfs /etc 9# we need our own /dev/rfkill, and don't want device access 10mount tmpfs -t tmpfs /dev 11# some sockets go into /var/run, and / is read-only 12mount tmpfs -t tmpfs /var/run 13mount proc -t proc /proc 14mount sysfs -t sysfs /sys 15# needed for tracing 16mount debugfs -t debugfs /sys/kernel/debug 17 18mkdir /tmp/wireshark-share 19mount --bind /usr/share/wireshark /tmp/wireshark-share 20mount tmpfs -t tmpfs /usr/share/wireshark 21 22# for inside telnet 23mkdir /dev/pts 24mount devpts -t devpts /dev/pts 25 26export PATH=/usr/sbin:$PATH 27export HOME=/tmp 28 29# reboot on any sort of crash 30sysctl kernel.panic_on_oops=1 31sysctl kernel.panic=1 32 33mount --bind "$TESTDIR/vm/regdb/" /lib/firmware 34 35if [ "$MODULEDIR" != "" ] ; then 36 mount --bind $MODULEDIR /lib/modules 37fi 38 39# reload reg if (and only if) cfg80211.ko is already loaded 40iw reg reload || true 41 42# create /dev entries we need 43mknod -m 660 /dev/ttyS0 c 4 64 44mknod -m 666 /dev/ptmx c 5 2 45mknod -m 660 /dev/random c 1 8 46mknod -m 660 /dev/urandom c 1 9 47mknod -m 666 /dev/null c 1 3 48mknod -m 666 /dev/kmsg c 1 11 49test -f /sys/class/misc/rfkill/dev && \ 50 mknod -m 660 /dev/rfkill c $(cat /sys/class/misc/rfkill/dev | tr ':' ' ') 51ln -s /proc/self/fd/0 /dev/stdin 52ln -s /proc/self/fd/1 /dev/stdout 53ln -s /proc/self/fd/2 /dev/stderr 54 55# pretend we've initialized the RNG, we don't care here 56# about the actual quality of the randomness. The ioctl 57# is RNDADDTOENTCNT (at least on x86). 58PYTHONHASHSEED=0 python3 -c 'import fcntl; fd=open("/dev/random", "w"); fcntl.ioctl(fd.fileno(), 0x40045201, b"\x00\x01\x00\x00")' 59 60echo "VM has started up" > /dev/ttyS0 61 62# create stub sudo - everything runs as uid 0 63mkdir /tmp/bin 64cat > /tmp/bin/sudo << EOF 65#!/bin/bash 66 67exec "\$@" 68EOF 69chmod +x /tmp/bin/sudo 70# and put it into $PATH, as well as our extra-$PATH 71export PATH=/tmp/bin:$EPATH:$PATH 72 73# some tests assume adm/admin group(s) exist(s) 74cat > /etc/group <<EOF 75adm:x:0: 76admin:x:0: 77messagebus:x:106: 78EOF 79# root should exist 80cat > /etc/passwd <<EOF 81root:x:0:0:root:/tmp:/bin/bash 82messagebus:x:102:106::/var/run/dbus:/bin/false 83EOF 84cat > /etc/ethertypes <<EOF 85IPv4 0800 ip ip4 86ARP 0806 ether-arp 87IPv6 86DD ip6 88EOF 89cat > /etc/protocols <<EOF 90ip 0 IP 91icmp 1 ICMP 92tcp 6 TCP 93udp 17 UDP 94ipv6-icmp 58 IPv6-ICMP 95EOF 96# for pyrad 97cat > /etc/services <<EOF 98http 80/tcp www www-http 99http 80/udp www www-http 100EOF 101 102# we may need /etc/alternatives, at least on Debian-based systems 103ln -s /tmp/etc/alternatives /etc/ 104 105# local network is needed for some tests 106ip link set lo up 107 108# create logs mountpoint and mount the logshare 109mkdir /tmp/logs 110if grep -q rootfstype=hostfs /proc/cmdline; then 111 mount -t hostfs none /tmp/logs -o $LOGDIR 112else 113 mount -t 9p -o trans=virtio,rw logshare /tmp/logs 114fi 115 116# allow access to any outside directory (e.g. /tmp) we also have 117mkdir /tmp/host 118mount --bind / /tmp/host 119 120if [ "$TIMEWARP" = "1" ] ; then 121 ( 122 while sleep 1 ; do 123 date --set "@$(($(date +%s) + 19))" 124 done 125 ) & 126fi 127 128echo hwsimvm > /proc/sys/kernel/hostname 129echo 8 8 8 8 > /proc/sys/kernel/printk 130 131cat > /tmp/bin/login <<EOF 132#!/bin/sh 133 134export PS1='\h:\w\$ ' 135exec bash 136EOF 137chmod +x /tmp/bin/login 138 139if [ "$TELNET" = "1" ] ; then 140 ip link set eth0 up 141 ip addr add 172.16.0.15/24 dev eth0 142 which in.telnetd >/dev/null && ( 143 while true ; do 144 in.telnetd -debug 23 -L /tmp/bin/login 145 done 146 ) & 147fi 148 149# procps 3.3.17 needs an uptime of >1s (relevant for UML time-travel) 150sleep 1 151 152# check if we're rebooting due to a kernel panic ... 153if grep -q 'Kernel panic' /tmp/logs/console ; then 154 echo "KERNEL CRASHED!" >/dev/ttyS0 155else 156 # finally run the tests 157 export USER=0 158 export LOGDIR=/tmp/logs 159 export DBFILE=$LOGDIR/results.db 160 export PREFILL_DB=y 161 export COMMITID 162 163 # some tests need CRDA, install a simple uevent helper 164 # and preload the 00 domain it will have asked for already 165 echo $TESTDIR/vm/uevent.sh > /sys/kernel/uevent_helper 166 COUNTRY=00 crda 167 168 mkdir -p /var/run/dbus 169 touch /var/run/dbus/hwsim-test 170 chown messagebus.messagebus /var/run/dbus 171 dbus-daemon --config-file=$TESTDIR/vm/dbus.conf --fork 172 173 cd $TESTDIR 174 ./run-all.sh --vm $(cat /tmp/host$ARGS) </dev/ttyS0 >/dev/ttyS0 2>&1 175 if test -d /sys/kernel/debug/gcov ; then 176 cp -ar /sys/kernel/debug/gcov /tmp/logs/ 177 # these are broken as they're updated while being read ... 178 find /tmp/logs/gcov/ -wholename '*kernel/gcov/*' -print0 | xargs -0 rm 179 fi 180 #bash </dev/ttyS0 >/dev/ttyS0 2>&1 181fi 182 183# and shut down the machine again 184halt -f -p 185