1 #!/bin/sh 2 3 # keep old /etc 4 mount tmpfs -t tmpfs /tmp 5 mkdir /tmp/etc 6 mount --bind /etc /tmp/etc 7 # mount all kinds of things 8 mount tmpfs -t tmpfs /etc 9 # we need our own /dev/rfkill, and don't want device access 10 mount tmpfs -t tmpfs /dev 11 # some sockets go into /var/run, and / is read-only 12 mount tmpfs -t tmpfs /var/run 13 mount proc -t proc /proc 14 mount sysfs -t sysfs /sys 15 # needed for tracing 16 mount debugfs -t debugfs /sys/kernel/debug 17 18 mkdir /tmp/wireshark-share 19 mount --bind /usr/share/wireshark /tmp/wireshark-share 20 mount tmpfs -t tmpfs /usr/share/wireshark 21 22 # for inside telnet 23 mkdir /dev/pts 24 mount devpts -t devpts /dev/pts 25 26 export PATH=/usr/sbin:$PATH 27 export HOME=/tmp 28 29 # reboot on any sort of crash 30 sysctl kernel.panic_on_oops=1 31 sysctl kernel.panic=1 32 33 mount --bind "$TESTDIR/vm/regdb/" /lib/firmware 34 35 if [ "$MODULEDIR" != "" ] ; then 36 mount --bind $MODULEDIR /lib/modules 37 fi 38 39 # reload reg if (and only if) cfg80211.ko is already loaded 40 iw reg reload || true 41 42 # create /dev entries we need 43 mknod -m 660 /dev/ttyS0 c 4 64 44 mknod -m 666 /dev/ptmx c 5 2 45 mknod -m 660 /dev/random c 1 8 46 mknod -m 660 /dev/urandom c 1 9 47 mknod -m 666 /dev/null c 1 3 48 mknod -m 666 /dev/kmsg c 1 11 49 test -f /sys/class/misc/rfkill/dev && \ 50 mknod -m 660 /dev/rfkill c $(cat /sys/class/misc/rfkill/dev | tr ':' ' ') 51 ln -s /proc/self/fd/0 /dev/stdin 52 ln -s /proc/self/fd/1 /dev/stdout 53 ln -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). 58 PYTHONHASHSEED=0 python3 -c 'import fcntl; fd=open("/dev/random", "w"); fcntl.ioctl(fd.fileno(), 0x40045201, b"\x00\x01\x00\x00")' 59 60 echo "VM has started up" > /dev/ttyS0 61 62 # create stub sudo - everything runs as uid 0 63 mkdir /tmp/bin 64 cat > /tmp/bin/sudo << EOF 65 #!/bin/bash 66 67 exec "\$@" 68 EOF 69 chmod +x /tmp/bin/sudo 70 # and put it into $PATH, as well as our extra-$PATH 71 export PATH=/tmp/bin:$EPATH:$PATH 72 73 # some tests assume adm/admin group(s) exist(s) 74 cat > /etc/group <<EOF 75 adm:x:0: 76 admin:x:0: 77 messagebus:x:106: 78 EOF 79 # root should exist 80 cat > /etc/passwd <<EOF 81 root:x:0:0:root:/tmp:/bin/bash 82 messagebus:x:102:106::/var/run/dbus:/bin/false 83 EOF 84 cat > /etc/ethertypes <<EOF 85 IPv4 0800 ip ip4 86 ARP 0806 ether-arp 87 IPv6 86DD ip6 88 EOF 89 cat > /etc/protocols <<EOF 90 ip 0 IP 91 icmp 1 ICMP 92 tcp 6 TCP 93 udp 17 UDP 94 ipv6-icmp 58 IPv6-ICMP 95 EOF 96 # for pyrad 97 cat > /etc/services <<EOF 98 http 80/tcp www www-http 99 http 80/udp www www-http 100 EOF 101 102 # we may need /etc/alternatives, at least on Debian-based systems 103 ln -s /tmp/etc/alternatives /etc/ 104 105 # local network is needed for some tests 106 ip link set lo up 107 108 # create logs mountpoint and mount the logshare 109 mkdir /tmp/logs 110 if grep -q rootfstype=hostfs /proc/cmdline; then 111 mount -t hostfs none /tmp/logs -o $LOGDIR 112 else 113 mount -t 9p -o trans=virtio,rw logshare /tmp/logs 114 fi 115 116 # allow access to any outside directory (e.g. /tmp) we also have 117 mkdir /tmp/host 118 mount --bind / /tmp/host 119 120 if [ "$TIMEWARP" = "1" ] ; then 121 ( 122 while sleep 1 ; do 123 date --set "@$(($(date +%s) + 19))" 124 done 125 ) & 126 fi 127 128 echo hwsimvm > /proc/sys/kernel/hostname 129 echo 8 8 8 8 > /proc/sys/kernel/printk 130 131 cat > /tmp/bin/login <<EOF 132 #!/bin/sh 133 134 export PS1='\h:\w\$ ' 135 exec bash 136 EOF 137 chmod +x /tmp/bin/login 138 139 if [ "$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 ) & 147 fi 148 149 # procps 3.3.17 needs an uptime of >1s (relevant for UML time-travel) 150 sleep 1 151 152 # check if we're rebooting due to a kernel panic ... 153 if grep -q 'Kernel panic' /tmp/logs/console ; then 154 echo "KERNEL CRASHED!" >/dev/ttyS0 155 else 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 181 fi 182 183 # and shut down the machine again 184 halt -f -p 185