2013-10-31 00:23:57 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2019-02-02 23:38:35 +01:00
|
|
|
# keep old /etc
|
|
|
|
mount tmpfs -t tmpfs /tmp
|
|
|
|
mkdir /tmp/etc
|
|
|
|
mount --bind /etc /tmp/etc
|
2013-10-31 00:23:57 +01:00
|
|
|
# mount all kinds of things
|
|
|
|
mount tmpfs -t tmpfs /etc
|
|
|
|
# we need our own /dev/rfkill, and don't want device access
|
|
|
|
mount tmpfs -t tmpfs /dev
|
|
|
|
# some sockets go into /var/run, and / is read-only
|
|
|
|
mount tmpfs -t tmpfs /var/run
|
|
|
|
mount proc -t proc /proc
|
|
|
|
mount sysfs -t sysfs /sys
|
|
|
|
# needed for tracing
|
|
|
|
mount debugfs -t debugfs /sys/kernel/debug
|
|
|
|
|
2021-03-17 22:36:52 +01:00
|
|
|
mkdir /tmp/wireshark-share
|
|
|
|
mount --bind /usr/share/wireshark /tmp/wireshark-share
|
|
|
|
mount tmpfs -t tmpfs /usr/share/wireshark
|
|
|
|
|
2019-02-05 12:26:58 +01:00
|
|
|
# for inside telnet
|
|
|
|
mkdir /dev/pts
|
|
|
|
mount devpts -t devpts /dev/pts
|
|
|
|
|
2015-10-12 22:01:35 +02:00
|
|
|
export PATH=/usr/sbin:$PATH
|
2021-03-17 22:36:52 +01:00
|
|
|
export HOME=/tmp
|
2015-10-12 22:01:35 +02:00
|
|
|
|
2013-10-31 00:23:57 +01:00
|
|
|
# reboot on any sort of crash
|
|
|
|
sysctl kernel.panic_on_oops=1
|
|
|
|
sysctl kernel.panic=1
|
|
|
|
|
|
|
|
# get extra command line variables from /proc/cmdline
|
|
|
|
TESTDIR=$(sed 's/.*testdir=\([^ ]*\) .*/\1/' /proc/cmdline)
|
2014-01-15 20:58:39 +01:00
|
|
|
TIMEWARP=$(sed 's/.*timewarp=\([^ ]*\) .*/\1/' /proc/cmdline)
|
2013-10-31 00:23:57 +01:00
|
|
|
EPATH=$(sed 's/.*EPATH=\([^ ]*\) .*/\1/' /proc/cmdline)
|
2019-02-05 12:26:58 +01:00
|
|
|
TELNET=$(sed 's/.*TELNET=\([^ ]*\) .*/\1/' /proc/cmdline)
|
2015-11-30 11:59:09 +01:00
|
|
|
ARGS=$(sed 's/.*ARGS=\([^ ]*\)\( \|$\).*/\1/' /proc/cmdline)
|
2019-05-04 11:42:02 +02:00
|
|
|
LOGDIR=$(sed 's/.*LOGDIR=\([^ ]*\)\( \|$\).*/\1/' /proc/cmdline)
|
2022-04-14 10:59:22 +02:00
|
|
|
if grep -q "commitid=" /proc/cmdline; then
|
|
|
|
COMMITID=$(sed 's/.*commitid=\([^ ]*\)\( \|$\).*/\1/' /proc/cmdline)
|
|
|
|
else
|
|
|
|
COMMITID=
|
|
|
|
fi
|
2013-10-31 00:23:57 +01:00
|
|
|
|
2021-09-23 17:05:10 +02:00
|
|
|
mount --bind "$TESTDIR/vm/regdb/" /lib/firmware
|
|
|
|
|
2013-10-31 00:23:57 +01:00
|
|
|
# create /dev entries we need
|
|
|
|
mknod -m 660 /dev/ttyS0 c 4 64
|
2019-02-05 12:26:58 +01:00
|
|
|
mknod -m 666 /dev/ptmx c 5 2
|
2013-10-31 00:23:57 +01:00
|
|
|
mknod -m 660 /dev/random c 1 8
|
|
|
|
mknod -m 660 /dev/urandom c 1 9
|
|
|
|
mknod -m 666 /dev/null c 1 3
|
2015-11-24 13:27:57 +01:00
|
|
|
mknod -m 666 /dev/kmsg c 1 11
|
2013-10-31 00:23:57 +01:00
|
|
|
test -f /sys/class/misc/rfkill/dev && \
|
|
|
|
mknod -m 660 /dev/rfkill c $(cat /sys/class/misc/rfkill/dev | tr ':' ' ')
|
|
|
|
ln -s /proc/self/fd/0 /dev/stdin
|
|
|
|
ln -s /proc/self/fd/1 /dev/stdout
|
|
|
|
ln -s /proc/self/fd/2 /dev/stderr
|
|
|
|
|
2022-04-11 11:41:20 +02:00
|
|
|
# pretend we've initialized the RNG, we don't care here
|
|
|
|
# about the actual quality of the randomness. The ioctl
|
|
|
|
# is RNDADDTOENTCNT (at least on x86).
|
|
|
|
PYTHONHASHSEED=0 python3 -c 'import fcntl; fd=open("/dev/random", "w"); fcntl.ioctl(fd.fileno(), 0x40045201, b"\x00\x01\x00\x00")'
|
|
|
|
|
2019-02-05 12:26:46 +01:00
|
|
|
echo "VM has started up" > /dev/ttyS0
|
|
|
|
|
2021-09-19 08:24:29 +02:00
|
|
|
# create stub sudo - everything runs as uid 0
|
2013-10-31 00:23:57 +01:00
|
|
|
mkdir /tmp/bin
|
|
|
|
cat > /tmp/bin/sudo << EOF
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
exec "\$@"
|
|
|
|
EOF
|
|
|
|
chmod +x /tmp/bin/sudo
|
|
|
|
# and put it into $PATH, as well as our extra-$PATH
|
|
|
|
export PATH=/tmp/bin:$EPATH:$PATH
|
|
|
|
|
|
|
|
# some tests assume adm/admin group(s) exist(s)
|
2014-12-26 16:44:24 +01:00
|
|
|
cat > /etc/group <<EOF
|
|
|
|
adm:x:0:
|
|
|
|
admin:x:0:
|
|
|
|
messagebus:x:106:
|
|
|
|
EOF
|
2013-10-31 00:23:57 +01:00
|
|
|
# root should exist
|
2014-12-26 16:44:24 +01:00
|
|
|
cat > /etc/passwd <<EOF
|
|
|
|
root:x:0:0:root:/tmp:/bin/bash
|
|
|
|
messagebus:x:102:106::/var/run/dbus:/bin/false
|
|
|
|
EOF
|
2014-12-15 23:41:52 +01:00
|
|
|
cat > /etc/ethertypes <<EOF
|
|
|
|
IPv4 0800 ip ip4
|
|
|
|
ARP 0806 ether-arp
|
|
|
|
IPv6 86DD ip6
|
|
|
|
EOF
|
|
|
|
cat > /etc/protocols <<EOF
|
|
|
|
ip 0 IP
|
|
|
|
icmp 1 ICMP
|
|
|
|
tcp 6 TCP
|
|
|
|
udp 17 UDP
|
|
|
|
ipv6-icmp 58 IPv6-ICMP
|
|
|
|
EOF
|
2013-10-31 00:23:57 +01:00
|
|
|
|
2019-02-02 23:38:35 +01:00
|
|
|
# we may need /etc/alternatives, at least on Debian-based systems
|
|
|
|
ln -s /tmp/etc/alternatives /etc/
|
|
|
|
|
2013-10-31 00:23:57 +01:00
|
|
|
# local network is needed for some tests
|
|
|
|
ip link set lo up
|
|
|
|
|
|
|
|
# create logs mountpoint and mount the logshare
|
|
|
|
mkdir /tmp/logs
|
2019-05-04 11:42:02 +02:00
|
|
|
if grep -q rootfstype=hostfs /proc/cmdline; then
|
|
|
|
mount -t hostfs none /tmp/logs -o $LOGDIR
|
|
|
|
else
|
|
|
|
mount -t 9p -o trans=virtio,rw logshare /tmp/logs
|
|
|
|
fi
|
2013-10-31 00:23:57 +01:00
|
|
|
|
2015-11-30 11:59:09 +01:00
|
|
|
# allow access to any outside directory (e.g. /tmp) we also have
|
|
|
|
mkdir /tmp/host
|
|
|
|
mount --bind / /tmp/host
|
|
|
|
|
2014-01-15 20:58:39 +01:00
|
|
|
if [ "$TIMEWARP" = "1" ] ; then
|
|
|
|
(
|
|
|
|
while sleep 1 ; do
|
|
|
|
date --set "@$(($(date +%s) + 19))"
|
|
|
|
done
|
|
|
|
) &
|
|
|
|
fi
|
|
|
|
|
2019-02-05 12:26:58 +01:00
|
|
|
echo hwsimvm > /proc/sys/kernel/hostname
|
2017-05-30 16:29:56 +02:00
|
|
|
echo 8 8 8 8 > /proc/sys/kernel/printk
|
|
|
|
|
2019-02-05 12:26:58 +01:00
|
|
|
cat > /tmp/bin/login <<EOF
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
export PS1='\h:\w\$ '
|
|
|
|
exec bash
|
|
|
|
EOF
|
|
|
|
chmod +x /tmp/bin/login
|
|
|
|
|
|
|
|
if [ "$TELNET" = "1" ] ; then
|
|
|
|
ip link set eth0 up
|
|
|
|
ip addr add 172.16.0.15/24 dev eth0
|
|
|
|
which in.telnetd >/dev/null && (
|
|
|
|
while true ; do
|
|
|
|
in.telnetd -debug 23 -L /tmp/bin/login
|
|
|
|
done
|
|
|
|
) &
|
|
|
|
fi
|
|
|
|
|
2013-10-31 00:23:57 +01:00
|
|
|
# check if we're rebooting due to a kernel panic ...
|
|
|
|
if grep -q 'Kernel panic' /tmp/logs/console ; then
|
|
|
|
echo "KERNEL CRASHED!" >/dev/ttyS0
|
|
|
|
else
|
|
|
|
# finally run the tests
|
|
|
|
export USER=0
|
|
|
|
export LOGDIR=/tmp/logs
|
2013-10-31 15:36:44 +01:00
|
|
|
export DBFILE=$LOGDIR/results.db
|
2013-10-31 16:05:11 +01:00
|
|
|
export PREFILL_DB=y
|
2022-04-14 10:59:22 +02:00
|
|
|
export COMMITID
|
2013-10-31 00:23:57 +01:00
|
|
|
|
2013-12-18 21:50:21 +01:00
|
|
|
# some tests need CRDA, install a simple uevent helper
|
|
|
|
# and preload the 00 domain it will have asked for already
|
|
|
|
echo $TESTDIR/vm/uevent.sh > /sys/kernel/uevent_helper
|
|
|
|
COUNTRY=00 crda
|
|
|
|
|
2014-12-26 16:44:24 +01:00
|
|
|
mkdir -p /var/run/dbus
|
|
|
|
touch /var/run/dbus/hwsim-test
|
|
|
|
chown messagebus.messagebus /var/run/dbus
|
|
|
|
dbus-daemon --config-file=$TESTDIR/vm/dbus.conf --fork
|
|
|
|
|
2013-10-31 00:23:57 +01:00
|
|
|
cd $TESTDIR
|
2018-10-23 13:07:05 +02:00
|
|
|
./run-all.sh --vm $(cat /tmp/host$ARGS) </dev/ttyS0 >/dev/ttyS0 2>&1
|
2013-12-05 23:22:10 +01:00
|
|
|
if test -d /sys/kernel/debug/gcov ; then
|
|
|
|
cp -ar /sys/kernel/debug/gcov /tmp/logs/
|
|
|
|
# these are broken as they're updated while being read ...
|
|
|
|
find /tmp/logs/gcov/ -wholename '*kernel/gcov/*' -print0 | xargs -0 rm
|
|
|
|
fi
|
2013-10-31 00:23:57 +01:00
|
|
|
#bash </dev/ttyS0 >/dev/ttyS0 2>&1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# and shut down the machine again
|
|
|
|
halt -f -p
|