Fixes for Heimdal (macOS) builds from Stefan.
[mech_eap.git] / libeap / tests / hwsim / vm / inside.sh
1 #!/bin/sh
2
3 # mount all kinds of things
4 mount tmpfs -t tmpfs /etc
5 # we need our own /dev/rfkill, and don't want device access
6 mount tmpfs -t tmpfs /dev
7 mount tmpfs -t tmpfs /tmp
8 # some sockets go into /var/run, and / is read-only
9 mount tmpfs -t tmpfs /var/run
10 mount proc -t proc /proc
11 mount sysfs -t sysfs /sys
12 # needed for tracing
13 mount debugfs -t debugfs /sys/kernel/debug
14
15 export PATH=/usr/sbin:$PATH
16
17 # reboot on any sort of crash
18 sysctl kernel.panic_on_oops=1
19 sysctl kernel.panic=1
20
21 # get extra command line variables from /proc/cmdline
22 TESTDIR=$(sed 's/.*testdir=\([^ ]*\) .*/\1/' /proc/cmdline)
23 TIMEWARP=$(sed 's/.*timewarp=\([^ ]*\) .*/\1/' /proc/cmdline)
24 EPATH=$(sed 's/.*EPATH=\([^ ]*\) .*/\1/' /proc/cmdline)
25 ARGS=$(sed 's/.*ARGS=\([^ ]*\)\( \|$\).*/\1/' /proc/cmdline)
26
27 # create /dev entries we need
28 mknod -m 660 /dev/ttyS0 c 4 64
29 mknod -m 660 /dev/random c 1 8
30 mknod -m 660 /dev/urandom c 1 9
31 mknod -m 666 /dev/null c 1 3
32 mknod -m 666 /dev/kmsg c 1 11
33 test -f /sys/class/misc/rfkill/dev && \
34         mknod -m 660 /dev/rfkill c $(cat /sys/class/misc/rfkill/dev | tr ':' ' ')
35 ln -s /proc/self/fd/0 /dev/stdin
36 ln -s /proc/self/fd/1 /dev/stdout
37 ln -s /proc/self/fd/2 /dev/stderr
38
39 # create dummy sudo - everything runs as uid 0
40 mkdir /tmp/bin
41 cat > /tmp/bin/sudo << EOF
42 #!/bin/bash
43
44 exec "\$@"
45 EOF
46 chmod +x /tmp/bin/sudo
47 # and put it into $PATH, as well as our extra-$PATH
48 export PATH=/tmp/bin:$EPATH:$PATH
49
50 # some tests assume adm/admin group(s) exist(s)
51 cat > /etc/group <<EOF
52 adm:x:0:
53 admin:x:0:
54 messagebus:x:106:
55 EOF
56 # root should exist
57 cat > /etc/passwd <<EOF
58 root:x:0:0:root:/tmp:/bin/bash
59 messagebus:x:102:106::/var/run/dbus:/bin/false
60 EOF
61 cat > /etc/ethertypes <<EOF
62 IPv4            0800    ip ip4
63 ARP             0806    ether-arp
64 IPv6            86DD    ip6
65 EOF
66 cat > /etc/protocols <<EOF
67 ip      0       IP
68 icmp    1       ICMP
69 tcp     6       TCP
70 udp     17      UDP
71 ipv6-icmp 58    IPv6-ICMP
72 EOF
73
74 # local network is needed for some tests
75 ip link set lo up
76
77 # create logs mountpoint and mount the logshare
78 mkdir /tmp/logs
79 mount -t 9p -o trans=virtio,rw logshare /tmp/logs
80
81 # allow access to any outside directory (e.g. /tmp) we also have
82 mkdir /tmp/host
83 mount --bind / /tmp/host
84
85 if [ "$TIMEWARP" = "1" ] ; then
86     (
87         while sleep 1 ; do
88             date --set "@$(($(date +%s) + 19))"
89         done
90     ) &
91 fi
92
93 # check if we're rebooting due to a kernel panic ...
94 if grep -q 'Kernel panic' /tmp/logs/console ; then
95         echo "KERNEL CRASHED!" >/dev/ttyS0
96 else
97         # finally run the tests
98         export USER=0
99         export LOGDIR=/tmp/logs
100         export DBFILE=$LOGDIR/results.db
101         export PREFILL_DB=y
102
103         # some tests need CRDA, install a simple uevent helper
104         # and preload the 00 domain it will have asked for already
105         echo $TESTDIR/vm/uevent.sh > /sys/kernel/uevent_helper
106         COUNTRY=00 crda
107
108         mkdir -p /var/run/dbus
109         touch /var/run/dbus/hwsim-test
110         chown messagebus.messagebus /var/run/dbus
111         dbus-daemon --config-file=$TESTDIR/vm/dbus.conf --fork
112
113         cd $TESTDIR
114         ./run-all.sh $(cat /tmp/host$ARGS) </dev/ttyS0 >/dev/ttyS0 2>&1
115         if test -d /sys/kernel/debug/gcov ; then
116                 cp -ar /sys/kernel/debug/gcov /tmp/logs/
117                 # these are broken as they're updated while being read ...
118                 find /tmp/logs/gcov/ -wholename '*kernel/gcov/*' -print0 | xargs -0 rm
119         fi
120         #bash </dev/ttyS0 >/dev/ttyS0 2>&1
121 fi
122
123 # and shut down the machine again
124 halt -f -p