inside.sh 3.2 KB

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