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