inside.sh 3.0 KB

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