Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Maciej Żenczykowski | 99cd00d | 2018-10-14 20:03:23 -0700 | [diff] [blame] | 3 | # Builds mysteriously fail if stdout is non-blocking. |
| 4 | fixup_ptys() { |
Maciej Żenczykowski | dc93e52 | 2022-04-28 01:56:40 -0700 | [diff] [blame] | 5 | python3 << 'EOF' |
Maciej Żenczykowski | 99cd00d | 2018-10-14 20:03:23 -0700 | [diff] [blame] | 6 | import fcntl, os, sys |
| 7 | fd = sys.stdout.fileno() |
| 8 | flags = fcntl.fcntl(fd, fcntl.F_GETFL) |
| 9 | flags &= ~(fcntl.FASYNC | os.O_NONBLOCK | os.O_APPEND) |
| 10 | fcntl.fcntl(fd, fcntl.F_SETFL, flags) |
| 11 | EOF |
| 12 | } |
| 13 | |
Alistair Strachan | ab98710 | 2018-05-10 16:44:52 -0700 | [diff] [blame] | 14 | # Common kernel options |
Maciej Żenczykowski | 38ea59b | 2022-10-10 15:51:20 -0700 | [diff] [blame] | 15 | OPTIONS=" ANDROID GKI_NET_XFRM_HACKS" |
| 16 | OPTIONS="$OPTIONS DEBUG_SPINLOCK DEBUG_ATOMIC_SLEEP DEBUG_MUTEXES DEBUG_RT_MUTEXES" |
Alistair Delva | afbd632 | 2019-07-10 17:18:39 -0700 | [diff] [blame] | 17 | OPTIONS="$OPTIONS WARN_ALL_UNSEEDED_RANDOM IKCONFIG IKCONFIG_PROC" |
Alistair Strachan | 9493cb1 | 2018-06-17 14:10:52 -0700 | [diff] [blame] | 18 | OPTIONS="$OPTIONS DEVTMPFS DEVTMPFS_MOUNT FHANDLE" |
Lorenzo Colitti | 4620bd8 | 2015-12-21 11:39:16 +0900 | [diff] [blame] | 19 | OPTIONS="$OPTIONS IPV6 IPV6_ROUTER_PREF IPV6_MULTIPLE_TABLES IPV6_ROUTE_INFO" |
Lorenzo Colitti | 611c908 | 2014-03-31 13:25:48 +0900 | [diff] [blame] | 20 | OPTIONS="$OPTIONS TUN SYN_COOKIES IP_ADVANCED_ROUTER IP_MULTIPLE_TABLES" |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 21 | OPTIONS="$OPTIONS NETFILTER NETFILTER_ADVANCED NETFILTER_XTABLES" |
| 22 | OPTIONS="$OPTIONS NETFILTER_XT_MARK NETFILTER_XT_TARGET_MARK" |
Erik Kline | 7cfe31e | 2016-05-31 16:18:01 +0900 | [diff] [blame] | 23 | OPTIONS="$OPTIONS IP_NF_IPTABLES IP_NF_MANGLE IP_NF_FILTER" |
| 24 | OPTIONS="$OPTIONS IP6_NF_IPTABLES IP6_NF_MANGLE IP6_NF_FILTER INET6_IPCOMP" |
Alistair Strachan | ab98710 | 2018-05-10 16:44:52 -0700 | [diff] [blame] | 25 | OPTIONS="$OPTIONS IPV6_OPTIMISTIC_DAD" |
Alistair Strachan | 5055c07 | 2018-05-10 15:36:55 -0700 | [diff] [blame] | 26 | OPTIONS="$OPTIONS IPV6_ROUTE_INFO IPV6_ROUTER_PREF" |
Maciej Żenczykowski | ca84977 | 2020-08-19 17:50:50 -0700 | [diff] [blame] | 27 | OPTIONS="$OPTIONS NETFILTER_XT_TARGET_IDLETIMER" |
Alistair Strachan | 5055c07 | 2018-05-10 15:36:55 -0700 | [diff] [blame] | 28 | OPTIONS="$OPTIONS NETFILTER_XT_TARGET_NFLOG" |
Maciej Żenczykowski | ccad07c | 2019-03-21 13:33:37 -0700 | [diff] [blame] | 29 | OPTIONS="$OPTIONS NETFILTER_XT_MATCH_POLICY" |
Alistair Strachan | 5055c07 | 2018-05-10 15:36:55 -0700 | [diff] [blame] | 30 | OPTIONS="$OPTIONS NETFILTER_XT_MATCH_QUOTA" |
| 31 | OPTIONS="$OPTIONS NETFILTER_XT_MATCH_QUOTA2" |
| 32 | OPTIONS="$OPTIONS NETFILTER_XT_MATCH_QUOTA2_LOG" |
Alistair Strachan | 5055c07 | 2018-05-10 15:36:55 -0700 | [diff] [blame] | 33 | OPTIONS="$OPTIONS NETFILTER_XT_MATCH_SOCKET" |
| 34 | OPTIONS="$OPTIONS NETFILTER_XT_MATCH_QTAGUID" |
Alistair Delva | afbd632 | 2019-07-10 17:18:39 -0700 | [diff] [blame] | 35 | OPTIONS="$OPTIONS INET_DIAG INET_UDP_DIAG INET_DIAG_DESTROY" |
Alistair Strachan | ab98710 | 2018-05-10 16:44:52 -0700 | [diff] [blame] | 36 | OPTIONS="$OPTIONS IP_SCTP" |
Alistair Strachan | 5055c07 | 2018-05-10 15:36:55 -0700 | [diff] [blame] | 37 | OPTIONS="$OPTIONS IP_NF_TARGET_REJECT IP_NF_TARGET_REJECT_SKERR" |
| 38 | OPTIONS="$OPTIONS IP6_NF_TARGET_REJECT IP6_NF_TARGET_REJECT_SKERR" |
Alistair Strachan | ab98710 | 2018-05-10 16:44:52 -0700 | [diff] [blame] | 39 | OPTIONS="$OPTIONS NET_KEY XFRM_USER XFRM_STATISTICS CRYPTO_CBC" |
Alistair Strachan | 8f52a62 | 2018-05-10 15:48:44 -0700 | [diff] [blame] | 40 | OPTIONS="$OPTIONS CRYPTO_CTR CRYPTO_HMAC CRYPTO_AES CRYPTO_SHA1" |
Maciej Żenczykowski | 87eedb0 | 2020-09-25 16:45:04 -0700 | [diff] [blame] | 41 | OPTIONS="$OPTIONS CRYPTO_XCBC CRYPTO_CHACHA20POLY1305" |
Alistair Strachan | 8f52a62 | 2018-05-10 15:48:44 -0700 | [diff] [blame] | 42 | OPTIONS="$OPTIONS CRYPTO_USER INET_ESP INET_XFRM_MODE_TRANSPORT" |
| 43 | OPTIONS="$OPTIONS INET_XFRM_MODE_TUNNEL INET6_ESP" |
Lorenzo Colitti | cbcfcf0 | 2016-12-22 14:42:58 +0900 | [diff] [blame] | 44 | OPTIONS="$OPTIONS INET6_XFRM_MODE_TRANSPORT INET6_XFRM_MODE_TUNNEL" |
Jonathan Basseri | 3187de0 | 2017-11-22 10:09:23 -0800 | [diff] [blame] | 45 | OPTIONS="$OPTIONS CRYPTO_SHA256 CRYPTO_SHA512 CRYPTO_AES_X86_64 CRYPTO_NULL" |
Alistair Strachan | ab98710 | 2018-05-10 16:44:52 -0700 | [diff] [blame] | 46 | OPTIONS="$OPTIONS CRYPTO_GCM CRYPTO_ECHAINIV NET_IPVTI" |
Maciej Żenczykowski | 0be11c1 | 2019-08-15 17:00:22 -0700 | [diff] [blame] | 47 | OPTIONS="$OPTIONS DUMMY" |
Lorenzo Colitti | a76a450 | 2015-09-18 15:12:39 +0900 | [diff] [blame] | 48 | |
Alistair Strachan | ab98710 | 2018-05-10 16:44:52 -0700 | [diff] [blame] | 49 | # Kernel version specific options |
| 50 | OPTIONS="$OPTIONS XFRM_INTERFACE" # Various device kernels |
Yan Yan | ac77a01 | 2020-12-22 17:23:50 -0800 | [diff] [blame] | 51 | OPTIONS="$OPTIONS XFRM_MIGRATE" # Added in 5.10 |
Alistair Strachan | ab98710 | 2018-05-10 16:44:52 -0700 | [diff] [blame] | 52 | OPTIONS="$OPTIONS CGROUP_BPF" # Added in android-4.9 |
| 53 | OPTIONS="$OPTIONS NF_SOCKET_IPV4 NF_SOCKET_IPV6" # Added in 4.9 |
| 54 | OPTIONS="$OPTIONS INET_SCTP_DIAG" # Added in 4.7 |
| 55 | OPTIONS="$OPTIONS SOCK_CGROUP_DATA" # Added in 4.5 |
| 56 | OPTIONS="$OPTIONS CRYPTO_ECHAINIV" # Added in 4.1 |
| 57 | OPTIONS="$OPTIONS BPF_SYSCALL" # Added in 3.18 |
| 58 | OPTIONS="$OPTIONS IPV6_VTI" # Added in 3.13 |
| 59 | OPTIONS="$OPTIONS IPV6_PRIVACY" # Removed in 3.12 |
| 60 | OPTIONS="$OPTIONS NETFILTER_TPROXY" # Removed in 3.11 |
Dmitry Shmidt | 77a507a | 2018-01-08 13:26:19 -0800 | [diff] [blame] | 61 | |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 62 | # UML specific options |
| 63 | OPTIONS="$OPTIONS BLK_DEV_UBD HOSTFS" |
| 64 | |
| 65 | # QEMU specific options |
Maciej Żenczykowski | 2b0d052 | 2019-04-16 17:25:52 -0700 | [diff] [blame] | 66 | OPTIONS="$OPTIONS PCI VIRTIO VIRTIO_PCI VIRTIO_BLK NET_9P NET_9P_VIRTIO 9P_FS" |
Alistair Delva | afbd632 | 2019-07-10 17:18:39 -0700 | [diff] [blame] | 67 | OPTIONS="$OPTIONS CRYPTO_DEV_VIRTIO SERIAL_8250 SERIAL_8250_PCI" |
Alistair Delva | 2d10e03 | 2022-12-05 16:06:40 -0800 | [diff] [blame] | 68 | OPTIONS="$OPTIONS SERIAL_8250_CONSOLE PCI_HOST_GENERIC SERIAL_AMBA_PL011" |
| 69 | OPTIONS="$OPTIONS SERIAL_AMBA_PL011_CONSOLE" |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 70 | |
Alistair Strachan | ab98710 | 2018-05-10 16:44:52 -0700 | [diff] [blame] | 71 | # Obsolete options present at some time in Android kernels |
| 72 | OPTIONS="$OPTIONS IP_NF_TARGET_REJECT_SKERR IP6_NF_TARGET_REJECT_SKERR" |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 73 | |
Maciej Żenczykowski | e2e6f03 | 2022-12-19 09:42:38 +0000 | [diff] [blame] | 74 | # b/262323440 - UML *sometimes* seems to have issues with: |
| 75 | # UPSTREAM: hardening: Clarify Kconfig text for auto-var-init |
| 76 | # which is in 4.14.~299/4.19.~266 LTS and which does: |
| 77 | # prompt "Initialize kernel stack variables at function entry" |
| 78 | # default GCC_PLUGIN_STRUCTLEAK_BYREF_ALL if COMPILE_TEST && GCC_PLUGINS |
| 79 | # default INIT_STACK_ALL_PATTERN if COMPILE_TEST && CC_HAS_AUTO_VAR_INIT_PATTERN |
| 80 | # + default INIT_STACK_ALL_ZERO if CC_HAS_AUTO_VAR_INIT_PATTERN |
| 81 | # default INIT_STACK_NONE |
| 82 | # and thus presumably switches from INIT_STACK_NONE to INIT_STACK_ALL_ZERO |
| 83 | # |
| 84 | # My guess it that this is triggering some sort of UML and/or compiler bug... |
| 85 | # Let's just turn it off... we don't care that much. |
| 86 | OPTIONS="$OPTIONS INIT_STACK_NONE" |
| 87 | |
Lorenzo Colitti | 5812a19 | 2015-05-20 15:53:30 +0900 | [diff] [blame] | 88 | # These two break the flo kernel due to differences in -Werror on recent GCC. |
Alistair Strachan | 5055c07 | 2018-05-10 15:36:55 -0700 | [diff] [blame] | 89 | DISABLE_OPTIONS=" REISERFS_FS ANDROID_PMEM" |
| 90 | |
Lorenzo Colitti | 93ea218 | 2015-10-16 12:57:39 +0900 | [diff] [blame] | 91 | # How many TAP interfaces to create to provide the VM with real network access |
| 92 | # via the host. This requires privileges (e.g., root access) on the host. |
| 93 | # |
| 94 | # This is not needed to run the tests, but can be used, for example, to allow |
| 95 | # the VM to update system packages, or to write tests that need access to a |
| 96 | # real network. The VM does not set up networking by default, but it contains a |
| 97 | # DHCP client and has the ability to use IPv6 autoconfiguration. This script |
| 98 | # does not perform any host-level setup beyond configuring tap interfaces; |
| 99 | # configuring IPv4 NAT and/or IPv6 router advertisements or ND proxying must |
| 100 | # be done separately. |
| 101 | NUMTAPINTERFACES=0 |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 102 | |
| 103 | # The root filesystem disk image we'll use. |
Krzysztof Kosiński | 3dee82d | 2022-11-30 09:34:05 +0000 | [diff] [blame] | 104 | ROOTFS=${ROOTFS:-net_test.rootfs.20221014} |
Lorenzo Colitti | cd7717e | 2015-02-03 16:20:57 +0900 | [diff] [blame] | 105 | COMPRESSED_ROOTFS=$ROOTFS.xz |
| 106 | URL=https://dl.google.com/dl/android/$COMPRESSED_ROOTFS |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 107 | |
Lorenzo Colitti | b41d497 | 2016-08-29 13:49:02 +0900 | [diff] [blame] | 108 | # Parse arguments and figure out which test to run. |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 109 | ARCH=${ARCH:-um} |
Alessio Balsini | 0f36856 | 2019-07-23 09:42:39 +0100 | [diff] [blame] | 110 | J=${J:-$(nproc)} |
Patrick Tjin | 848fe27 | 2016-09-07 15:27:19 -0700 | [diff] [blame] | 111 | MAKE="make" |
| 112 | OUT_DIR=$(readlink -f ${OUT_DIR:-.}) |
| 113 | KERNEL_DIR=$(readlink -f ${KERNEL_DIR:-.}) |
| 114 | if [ "$OUT_DIR" != "$KERNEL_DIR" ]; then |
| 115 | MAKE="$MAKE O=$OUT_DIR" |
| 116 | fi |
| 117 | SCRIPT_DIR=$(dirname $(readlink -f $0)) |
| 118 | CONFIG_SCRIPT=${KERNEL_DIR}/scripts/config |
| 119 | CONFIG_FILE=${OUT_DIR}/.config |
Bindu Mahadev | 2fac109 | 2016-03-03 16:45:10 -0800 | [diff] [blame] | 120 | consolemode= |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 121 | netconfig= |
Bindu Mahadev | 2fac109 | 2016-03-03 16:45:10 -0800 | [diff] [blame] | 122 | testmode= |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 123 | cmdline= |
Maciej Żenczykowski | 43115d5 | 2018-10-12 15:02:07 -0700 | [diff] [blame] | 124 | nowrite=1 |
Lorenzo Colitti | 9e4fc1b | 2016-12-06 13:30:46 +0900 | [diff] [blame] | 125 | nobuild=0 |
Lorenzo Colitti | 695d415 | 2016-12-06 17:21:15 +0900 | [diff] [blame] | 126 | norun=0 |
| 127 | |
Patrick Rohr | e5d5a0e | 2024-04-15 14:32:26 -0700 | [diff] [blame] | 128 | if [[ ! -f "${KERNEL_DIR}/Makefile" ]]; then |
| 129 | echo "No kernel Makefile found. Are you running this from a kernel directory?" |
| 130 | exit 1 |
| 131 | fi |
| 132 | |
Maciej Żenczykowski | 04a54a9 | 2022-05-25 04:31:30 -0700 | [diff] [blame] | 133 | KVER_MAJOR="$(sed -rn 's@^ *VERSION *= *([0-9]+)$@\1@p' < "${KERNEL_DIR}/Makefile")" |
| 134 | KVER_MINOR="$(sed -rn 's@^ *PATCHLEVEL *= *([0-9]+)$@\1@p' < "${KERNEL_DIR}/Makefile")" |
| 135 | KVER_LEVEL="$(sed -rn 's@^ *SUBLEVEL *= *([0-9]+)$@\1@p' < "${KERNEL_DIR}/Makefile")" |
| 136 | KVER="${KVER_MAJOR}.${KVER_MINOR}.${KVER_LEVEL}" |
| 137 | echo "Detected kernel version ${KVER}" |
| 138 | |
Maciej Żenczykowski | 5e0d888 | 2021-05-21 06:25:58 -0700 | [diff] [blame] | 139 | if [[ -z "${DEFCONFIG:-}" ]]; then |
Maciej Żenczykowski | d07fcb0 | 2020-01-30 02:22:42 -0800 | [diff] [blame] | 140 | case "${ARCH}" in |
| 141 | um) |
| 142 | export DEFCONFIG=defconfig |
| 143 | ;; |
| 144 | arm64) |
| 145 | if [[ -e arch/arm64/configs/gki_defconfig ]]; then |
| 146 | export DEFCONFIG=gki_defconfig |
| 147 | elif [[ -e arch/arm64/configs/cuttlefish_defconfig ]]; then |
| 148 | export DEFCONFIG=cuttlefish_defconfig |
| 149 | fi |
| 150 | ;; |
| 151 | x86_64) |
| 152 | if [[ -e arch/x86/configs/gki_defconfig ]]; then |
| 153 | export DEFCONFIG=gki_defconfig |
| 154 | elif [[ -e arch/x86/configs/x86_64_cuttlefish_defconfig ]]; then |
| 155 | export DEFCONFIG=x86_64_cuttlefish_defconfig |
| 156 | fi |
| 157 | esac |
| 158 | fi |
| 159 | |
Maciej Żenczykowski | 42f9634 | 2018-11-07 02:16:37 -0800 | [diff] [blame] | 160 | if tty >/dev/null; then |
| 161 | verbose= |
| 162 | else |
| 163 | verbose=1 |
| 164 | fi |
| 165 | |
Maciej Żenczykowski | 1dbe505 | 2020-01-30 02:27:39 -0800 | [diff] [blame] | 166 | test=all_tests.sh |
Maciej Żenczykowski | 43115d5 | 2018-10-12 15:02:07 -0700 | [diff] [blame] | 167 | while [[ -n "$1" ]]; do |
Maciej Żenczykowski | d2d9f4a | 2020-01-30 02:26:45 -0800 | [diff] [blame] | 168 | if [[ "$1" == "--builder" || "$1" == "-b" ]]; then |
Lorenzo Colitti | 9e4fc1b | 2016-12-06 13:30:46 +0900 | [diff] [blame] | 169 | consolemode="con=null,fd:1" |
| 170 | testmode=builder |
| 171 | shift |
Maciej Żenczykowski | 43115d5 | 2018-10-12 15:02:07 -0700 | [diff] [blame] | 172 | elif [[ "$1" == "--readwrite" || "$1" == "--rw" ]]; then |
| 173 | nowrite=0 |
| 174 | shift |
| 175 | elif [[ "$1" == "--readonly" || "$1" == "--ro" ]]; then |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 176 | nowrite=1 |
Lorenzo Colitti | 9e4fc1b | 2016-12-06 13:30:46 +0900 | [diff] [blame] | 177 | shift |
Maciej Żenczykowski | 43115d5 | 2018-10-12 15:02:07 -0700 | [diff] [blame] | 178 | elif [[ "$1" == "--nobuild" ]]; then |
Lorenzo Colitti | 9e4fc1b | 2016-12-06 13:30:46 +0900 | [diff] [blame] | 179 | nobuild=1 |
| 180 | shift |
Maciej Żenczykowski | 19a5822 | 2025-02-11 18:01:42 -0800 | [diff] [blame] | 181 | elif [[ "$1" == "--build" ]]; then |
| 182 | nobuild=0 |
| 183 | shift |
Maciej Żenczykowski | 43115d5 | 2018-10-12 15:02:07 -0700 | [diff] [blame] | 184 | elif [[ "$1" == "--norun" ]]; then |
Lorenzo Colitti | 695d415 | 2016-12-06 17:21:15 +0900 | [diff] [blame] | 185 | norun=1 |
| 186 | shift |
Maciej Żenczykowski | 19a5822 | 2025-02-11 18:01:42 -0800 | [diff] [blame] | 187 | elif [[ "$1" == "--run" ]]; then |
| 188 | norun=0 |
| 189 | shift |
Maciej Żenczykowski | 42f9634 | 2018-11-07 02:16:37 -0800 | [diff] [blame] | 190 | elif [[ "$1" == "--verbose" ]]; then |
| 191 | verbose=1 |
| 192 | shift |
| 193 | elif [[ "$1" == "--noverbose" ]]; then |
| 194 | verbose= |
| 195 | shift |
Lorenzo Colitti | 9e4fc1b | 2016-12-06 13:30:46 +0900 | [diff] [blame] | 196 | else |
| 197 | test=$1 |
Joel Scherpelz | de316e8 | 2017-02-23 13:51:31 +0900 | [diff] [blame] | 198 | break # Arguments after the test file are passed to the test itself. |
Lorenzo Colitti | 9e4fc1b | 2016-12-06 13:30:46 +0900 | [diff] [blame] | 199 | fi |
| 200 | done |
Lorenzo Colitti | b41d497 | 2016-08-29 13:49:02 +0900 | [diff] [blame] | 201 | |
Joel Scherpelz | de316e8 | 2017-02-23 13:51:31 +0900 | [diff] [blame] | 202 | # Check that test file exists and is readable |
| 203 | test_file=$SCRIPT_DIR/$test |
| 204 | if [[ ! -e $test_file ]]; then |
| 205 | echo "test file '${test_file}' does not exist" |
| 206 | exit 1 |
| 207 | fi |
| 208 | |
| 209 | if [[ ! -x $test_file ]]; then |
| 210 | echo "test file '${test_file}' is not executable" |
| 211 | exit 1 |
| 212 | fi |
| 213 | |
| 214 | # Collect trailing arguments to pass to $test |
| 215 | test_args=${@:2} |
| 216 | |
Lorenzo Colitti | 695d415 | 2016-12-06 17:21:15 +0900 | [diff] [blame] | 217 | function isRunningTest() { |
Lorenzo Colitti | 8506ff9 | 2020-05-09 16:17:46 +0900 | [diff] [blame] | 218 | ! (( norun )) |
Lorenzo Colitti | 695d415 | 2016-12-06 17:21:15 +0900 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | function isBuildOnly() { |
Lorenzo Colitti | 8506ff9 | 2020-05-09 16:17:46 +0900 | [diff] [blame] | 222 | (( norun )) && ! (( nobuild )) |
Lorenzo Colitti | 695d415 | 2016-12-06 17:21:15 +0900 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | if ! isRunningTest && ! isBuildOnly; then |
| 226 | echo "Usage:" >&2 |
Lorenzo Colitti | 8506ff9 | 2020-05-09 16:17:46 +0900 | [diff] [blame] | 227 | echo " $0 [--builder] [--readonly|--ro|--readwrite|--rw] [--nobuild] [--verbose] [<test>]" >&2 |
| 228 | echo " - if [<test>] is not specified, run all_tests.sh" >&2 |
Lorenzo Colitti | 695d415 | 2016-12-06 17:21:15 +0900 | [diff] [blame] | 229 | echo " $0 --norun" >&2 |
Lorenzo Colitti | b41d497 | 2016-08-29 13:49:02 +0900 | [diff] [blame] | 230 | exit 1 |
Bindu Mahadev | 2fac109 | 2016-03-03 16:45:10 -0800 | [diff] [blame] | 231 | fi |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 232 | |
Patrick Tjin | 848fe27 | 2016-09-07 15:27:19 -0700 | [diff] [blame] | 233 | cd $OUT_DIR |
| 234 | echo Running tests from: `pwd` |
| 235 | |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 236 | set -e |
| 237 | |
| 238 | # Check if we need to uncompress the disk image. |
| 239 | # We use xz because it compresses better: to 42M vs 72M (gzip) / 62M (bzip2). |
Patrick Tjin | 848fe27 | 2016-09-07 15:27:19 -0700 | [diff] [blame] | 240 | cd $SCRIPT_DIR |
Lorenzo Colitti | cd7717e | 2015-02-03 16:20:57 +0900 | [diff] [blame] | 241 | if [ ! -f $ROOTFS ]; then |
| 242 | echo "Deleting $COMPRESSED_ROOTFS" >&2 |
| 243 | rm -f $COMPRESSED_ROOTFS |
| 244 | echo "Downloading $URL" >&2 |
Bindu Mahadev | 3f8e37d | 2016-07-13 17:00:02 -0700 | [diff] [blame] | 245 | wget -nv $URL |
Lorenzo Colitti | cd7717e | 2015-02-03 16:20:57 +0900 | [diff] [blame] | 246 | echo "Uncompressing $COMPRESSED_ROOTFS" >&2 |
| 247 | unxz $COMPRESSED_ROOTFS |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 248 | fi |
Maciej Żenczykowski | 952a9fa | 2020-09-02 15:32:24 -0700 | [diff] [blame] | 249 | if ! [[ "${ROOTFS}" =~ ^/ ]]; then |
| 250 | ROOTFS="${SCRIPT_DIR}/${ROOTFS}" |
| 251 | fi |
Lorenzo Colitti | cd7717e | 2015-02-03 16:20:57 +0900 | [diff] [blame] | 252 | echo "Using $ROOTFS" |
| 253 | cd - |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 254 | |
Lorenzo Colitti | 93ea218 | 2015-10-16 12:57:39 +0900 | [diff] [blame] | 255 | # If network access was requested, create NUMTAPINTERFACES tap interfaces on |
| 256 | # the host, and prepare UML command line params to use them. The interfaces are |
| 257 | # called <user>TAP0, <user>TAP1, on the host, and eth0, eth1, ..., in the VM. |
| 258 | if (( $NUMTAPINTERFACES > 0 )); then |
| 259 | user=${USER:0:10} |
| 260 | tapinterfaces= |
Lorenzo Colitti | 93ea218 | 2015-10-16 12:57:39 +0900 | [diff] [blame] | 261 | for id in $(seq 0 $(( NUMTAPINTERFACES - 1 )) ); do |
| 262 | tap=${user}TAP$id |
| 263 | tapinterfaces="$tapinterfaces $tap" |
| 264 | mac=$(printf fe:fd:00:00:00:%02x $id) |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 265 | if [ "$ARCH" == "um" ]; then |
| 266 | netconfig="$netconfig eth$id=tuntap,$tap,$mac" |
| 267 | else |
| 268 | netconfig="$netconfig -netdev tap,id=hostnet$id,ifname=$tap,script=no,downscript=no" |
| 269 | netconfig="$netconfig -device virtio-net-pci,netdev=hostnet$id,id=net$id,mac=$mac" |
| 270 | fi |
Lorenzo Colitti | 93ea218 | 2015-10-16 12:57:39 +0900 | [diff] [blame] | 271 | done |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 272 | |
Lorenzo Colitti | 93ea218 | 2015-10-16 12:57:39 +0900 | [diff] [blame] | 273 | for tap in $tapinterfaces; do |
| 274 | if ! ip link list $tap > /dev/null; then |
| 275 | echo "Creating tap interface $tap" >&2 |
| 276 | sudo tunctl -u $USER -t $tap |
| 277 | sudo ip link set $tap up |
| 278 | fi |
| 279 | done |
| 280 | fi |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 281 | |
Maciej Żenczykowski | 5e0d888 | 2021-05-21 06:25:58 -0700 | [diff] [blame] | 282 | if [[ -n "${KERNEL_BINARY:-}" ]]; then |
Lorenzo Colitti | 9e4fc1b | 2016-12-06 13:30:46 +0900 | [diff] [blame] | 283 | nobuild=1 |
Benedict Wong | 7878ca7 | 2018-07-13 15:56:36 -0700 | [diff] [blame] | 284 | else |
| 285 | # Set default KERNEL_BINARY location if it was not provided. |
| 286 | if [ "$ARCH" == "um" ]; then |
| 287 | KERNEL_BINARY=./linux |
Alistair Strachan | 9ea6092 | 2018-10-25 13:36:34 -0700 | [diff] [blame] | 288 | elif [ "$ARCH" == "i386" -o "$ARCH" == "x86_64" -o "$ARCH" == "x86" ]; then |
Benedict Wong | 7878ca7 | 2018-07-13 15:56:36 -0700 | [diff] [blame] | 289 | KERNEL_BINARY=./arch/x86/boot/bzImage |
Alistair Strachan | 9ea6092 | 2018-10-25 13:36:34 -0700 | [diff] [blame] | 290 | elif [ "$ARCH" == "arm64" ]; then |
| 291 | KERNEL_BINARY=./arch/arm64/boot/Image.gz |
Benedict Wong | 7878ca7 | 2018-07-13 15:56:36 -0700 | [diff] [blame] | 292 | fi |
Lorenzo Colitti | 9e4fc1b | 2016-12-06 13:30:46 +0900 | [diff] [blame] | 293 | fi |
| 294 | |
| 295 | if ((nobuild == 0)); then |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 296 | make_flags= |
| 297 | if [ "$ARCH" == "um" ]; then |
| 298 | # Exporting ARCH=um SUBARCH=x86_64 doesn't seem to work, as it |
| 299 | # "sometimes" (?) results in a 32-bit kernel. |
Maciej Żenczykowski | 9520f1f | 2020-09-02 13:31:56 -0700 | [diff] [blame] | 300 | make_flags="$make_flags ARCH=$ARCH SUBARCH=${SUBARCH:-x86_64} CROSS_COMPILE= " |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 301 | fi |
Maciej Żenczykowski | 5e0d888 | 2021-05-21 06:25:58 -0700 | [diff] [blame] | 302 | if [[ -n "${CC:-}" ]]; then |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 303 | # The CC flag is *not* inherited from the environment, so it must be |
| 304 | # passed in on the command line. |
| 305 | make_flags="$make_flags CC=$CC" |
Lorenzo Colitti | 3544a6f | 2015-09-18 11:48:49 +0900 | [diff] [blame] | 306 | fi |
| 307 | |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 308 | # If there's no kernel config at all, create one or UML won't work. |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 309 | [ -f $CONFIG_FILE ] || (cd $KERNEL_DIR && $MAKE $make_flags $DEFCONFIG) |
| 310 | |
| 311 | # Enable the kernel config options listed in $OPTIONS. |
| 312 | $CONFIG_SCRIPT --file $CONFIG_FILE ${OPTIONS// / -e } |
| 313 | |
Maciej Żenczykowski | ef5ee4d | 2024-04-04 20:06:58 -0700 | [diff] [blame] | 314 | # Increase acceptable frame size. |
| 315 | $CONFIG_SCRIPT --file $CONFIG_FILE --set-val FRAME_WARN 3172 |
| 316 | |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 317 | # Disable the kernel config options listed in $DISABLE_OPTIONS. |
| 318 | $CONFIG_SCRIPT --file $CONFIG_FILE ${DISABLE_OPTIONS// / -d } |
| 319 | |
Maciej Żenczykowski | 5e0d888 | 2021-05-21 06:25:58 -0700 | [diff] [blame] | 320 | echo "Running: $MAKE $make_flags olddefconfig" |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 321 | $MAKE $make_flags olddefconfig |
| 322 | |
Lorenzo Colitti | 3544a6f | 2015-09-18 11:48:49 +0900 | [diff] [blame] | 323 | # Compile the kernel. |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 324 | if [ "$ARCH" == "um" ]; then |
Maciej Żenczykowski | 5e0d888 | 2021-05-21 06:25:58 -0700 | [diff] [blame] | 325 | echo "Running: $MAKE -j$J $make_flags linux" |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 326 | $MAKE -j$J $make_flags linux |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 327 | else |
Maciej Żenczykowski | 5e0d888 | 2021-05-21 06:25:58 -0700 | [diff] [blame] | 328 | echo "Running: $MAKE -j$J $make_flags" |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 329 | $MAKE -j$J $make_flags |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 330 | fi |
Lorenzo Colitti | 62ec904 | 2014-05-11 20:29:42 +0900 | [diff] [blame] | 331 | fi |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 332 | |
Lorenzo Colitti | 695d415 | 2016-12-06 17:21:15 +0900 | [diff] [blame] | 333 | if (( norun == 1 )); then |
| 334 | exit 0 |
| 335 | fi |
| 336 | |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 337 | if (( nowrite == 1 )); then |
| 338 | cmdline="ro" |
| 339 | fi |
Maciej Żenczykowski | 42f9634 | 2018-11-07 02:16:37 -0800 | [diff] [blame] | 340 | |
| 341 | if (( verbose == 1 )); then |
| 342 | cmdline="$cmdline verbose=1" |
| 343 | fi |
| 344 | |
Maciej Żenczykowski | cfa88f7 | 2019-09-02 09:33:34 -0700 | [diff] [blame] | 345 | cmdline="$cmdline panic=1 init=/sbin/net_test.sh" |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 346 | cmdline="$cmdline net_test_args=\"$test_args\" net_test_mode=$testmode" |
Lorenzo Colitti | 08c05d3 | 2014-03-27 20:10:14 +0900 | [diff] [blame] | 347 | |
Maciej Żenczykowski | 40fe156 | 2020-01-28 19:18:07 -0800 | [diff] [blame] | 348 | # Experience shows that we need at least 128 bits of entropy for the |
| 349 | # kernel's crng init to complete (before it fully initializes stuff behaves |
| 350 | # *weirdly* and there's plenty of kernel warnings and some tests even fail), |
| 351 | # hence net_test.sh needs at least 32 hex chars (which is the amount of hex |
| 352 | # in a single random UUID) provided to it on the kernel cmdline. |
| 353 | # |
| 354 | # Just to be safe, we'll pass in 384 bits, and we'll do this as a random |
| 355 | # 64 character base64 seed (because this is shorter than base16). |
| 356 | # We do this by getting *three* random UUIDs and concatenating their hex |
| 357 | # digits into an *even* length hex encoded string, which we then convert |
| 358 | # into base64. |
| 359 | entropy="$(cat /proc/sys/kernel/random{/,/,/}uuid | tr -d '\n-')" |
| 360 | entropy="$(xxd -r -p <<< "${entropy}" | base64 -w 0)" |
Maciej Żenczykowski | 8bc63c3 | 2020-02-05 07:42:59 -0800 | [diff] [blame] | 361 | cmdline="${cmdline} random.trust_cpu=on entropy=${entropy}" |
Maciej Żenczykowski | 40fe156 | 2020-01-28 19:18:07 -0800 | [diff] [blame] | 362 | |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 363 | if [ "$ARCH" == "um" ]; then |
| 364 | # Get the absolute path to the test file that's being run. |
| 365 | cmdline="$cmdline net_test=/host$SCRIPT_DIR/$test" |
| 366 | |
Maciej Żenczykowski | 0c89e40 | 2021-02-02 21:25:59 -0800 | [diff] [blame] | 367 | # We'd use UML's /proc/exitcode feature to communicate errors on test failure, |
| 368 | # if not for UML having a tendency to crash during shutdown, |
| 369 | # so instead use an extra serial line we'll redirect to an open fd... |
Alistair Delva | 668071d | 2021-04-09 11:54:59 -0700 | [diff] [blame] | 370 | cmdline="$cmdline exitcode=/dev/ttyS3" |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 371 | |
| 372 | # Map the --readonly flag to UML block device names |
| 373 | if ((nowrite == 0)); then |
| 374 | blockdevice=ubda |
| 375 | else |
Maciej Żenczykowski | 75b9e5e | 2018-10-12 14:57:55 -0700 | [diff] [blame] | 376 | blockdevice=ubdar |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 377 | fi |
| 378 | |
Maciej Żenczykowski | 0c89e40 | 2021-02-02 21:25:59 -0800 | [diff] [blame] | 379 | # Create a temp file for 'serial line 3' for return code. |
| 380 | SSL3="$(mktemp)" |
| 381 | |
Maciej Żenczykowski | d8cd125 | 2019-02-05 15:43:34 -0800 | [diff] [blame] | 382 | exitcode=0 |
Maciej Żenczykowski | 0c89e40 | 2021-02-02 21:25:59 -0800 | [diff] [blame] | 383 | $KERNEL_BINARY >&2 3>"${SSL3}" umid=net_test mem=512M \ |
| 384 | $blockdevice=$ROOTFS $netconfig $consolemode ssl3=null,fd:3 $cmdline \ |
Maciej Żenczykowski | d8cd125 | 2019-02-05 15:43:34 -0800 | [diff] [blame] | 385 | || exitcode=$? |
| 386 | |
Maciej Żenczykowski | 7c95cc3 | 2021-10-11 11:16:34 -0700 | [diff] [blame] | 387 | # Return to beginning of line (via carriage return) after the above newline moved us down. |
| 388 | echo -en '\r' |
| 389 | # re-enable: 'postprocess output' and 'translate newline to carriage return-newline' |
| 390 | stty opost onlcr || : |
| 391 | |
Maciej Żenczykowski | 0c89e40 | 2021-02-02 21:25:59 -0800 | [diff] [blame] | 392 | if [[ "${exitcode}" == 134 && -s "${SSL3}" && "$(tr -d '\r' < "${SSL3}")" == 0 ]]; then |
| 393 | # Sometimes the tests all pass, but UML crashes during the shutdown process itself. |
| 394 | # As such we can't actually rely on the /proc/exitcode returned value. |
| 395 | echo "Warning: UML appears to have crashed after successfully executing the tests." 1>&2 |
| 396 | elif [[ "${exitcode}" != 0 ]]; then |
| 397 | echo "Warning: UML exited with ${exitcode} instead of zero." 1>&2 |
| 398 | fi |
| 399 | |
| 400 | if [[ -s "${SSL3}" ]]; then |
| 401 | exitcode="$(tr -d '\r' < "${SSL3}")" |
| 402 | echo "Info: retrieved exit code ${exitcode}." 1>&2 |
| 403 | fi |
| 404 | |
| 405 | rm -f "${SSL3}" |
| 406 | unset SSL3 |
| 407 | |
Maciej Żenczykowski | d8cd125 | 2019-02-05 15:43:34 -0800 | [diff] [blame] | 408 | # UML is kind of crazy in how guest syscalls work. It requires host kernel |
| 409 | # to not be in vsyscall=none mode. |
| 410 | if [[ "${exitcode}" != '0' ]]; then |
| 411 | { |
| 412 | # Hopefully one of these exists |
| 413 | cat /proc/config || : |
| 414 | zcat /proc/config.gz || : |
| 415 | cat "/boot/config-$(uname -r)" || : |
| 416 | zcat "/boot/config-$(uname -r).gz" || : |
| 417 | } 2>/dev/null \ |
| 418 | | egrep -q '^CONFIG_LEGACY_VSYSCALL_NONE=y' \ |
Maciej Żenczykowski | 58a8141 | 2019-10-23 13:52:51 -0700 | [diff] [blame] | 419 | && ! egrep -q '(^| )vsyscall=(native|emulate|xonly)( |$)' /proc/cmdline \ |
Maciej Żenczykowski | d8cd125 | 2019-02-05 15:43:34 -0800 | [diff] [blame] | 420 | && { |
Maciej Żenczykowski | fd59e75 | 2019-03-05 17:51:32 -0800 | [diff] [blame] | 421 | echo -e "\r" |
| 422 | echo -e "-----=====-----\r" |
| 423 | echo -e "If above you saw a 'net_test.sh[1]: segfault at ...' followed by\r" |
| 424 | echo -e "'Kernel panic - not syncing: Attempted to kill init!' then please\r" |
| 425 | echo -e "set 'vsyscall=emulate' on *host* kernel command line.\r" |
Maciej Żenczykowski | 58a8141 | 2019-10-23 13:52:51 -0700 | [diff] [blame] | 426 | echo -e "On Linux 5.2+ you can instead use the slightly safer 'vsyscall=xonly'.\r" |
Maciej Żenczykowski | fd59e75 | 2019-03-05 17:51:32 -0800 | [diff] [blame] | 427 | echo -e "(for example via GRUB_CMDLINE_LINUX in /etc/default/grub)\r" |
| 428 | echo -e "-----=====-----\r" |
Maciej Żenczykowski | d8cd125 | 2019-02-05 15:43:34 -0800 | [diff] [blame] | 429 | } |
| 430 | fi |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 431 | else |
| 432 | # We boot into the filesystem image directly in all cases |
| 433 | cmdline="$cmdline root=/dev/vda" |
| 434 | |
| 435 | # The path is stripped by the 9p export; we don't need SCRIPT_DIR |
| 436 | cmdline="$cmdline net_test=/host/$test" |
| 437 | |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 438 | # Map the --readonly flag to a QEMU block device flag |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 439 | if ((nowrite > 0)); then |
Alistair Delva | 0797d52 | 2022-12-05 16:08:46 -0800 | [diff] [blame] | 440 | blockdevice=",readonly=on" |
Maciej Żenczykowski | 75b9e5e | 2018-10-12 14:57:55 -0700 | [diff] [blame] | 441 | else |
| 442 | blockdevice= |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 443 | fi |
Maciej Żenczykowski | 952a9fa | 2020-09-02 15:32:24 -0700 | [diff] [blame] | 444 | blockdevice="-drive file=$ROOTFS,format=raw,if=none,id=drive-virtio-disk0$blockdevice" |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 445 | blockdevice="$blockdevice -device virtio-blk-pci,drive=drive-virtio-disk0" |
| 446 | |
Maciej Żenczykowski | 42f9634 | 2018-11-07 02:16:37 -0800 | [diff] [blame] | 447 | # Pass through our current console/screen size to inner shell session |
| 448 | read rows cols < <(stty size 2>/dev/null) |
| 449 | [[ -z "${rows}" ]] || cmdline="${cmdline} console_rows=${rows}" |
| 450 | [[ -z "${cols}" ]] || cmdline="${cmdline} console_cols=${cols}" |
| 451 | unset rows cols |
| 452 | |
Alistair Strachan | 9ea6092 | 2018-10-25 13:36:34 -0700 | [diff] [blame] | 453 | # QEMU has no way to modify its exitcode; simulate it with a serial port. |
| 454 | # |
| 455 | # Choose to do it this way over writing a file to /host, because QEMU will |
| 456 | # initialize the 'exitcode' file for us, it avoids unnecessary writes to the |
| 457 | # host filesystem (which is normally not written to) and it allows us to |
| 458 | # communicate an exit code back in cases we do not have /host mounted. |
| 459 | # |
| 460 | if [ "$ARCH" == "i386" -o "$ARCH" == "x86_64" -o "$ARCH" == "x86" ]; then |
| 461 | # Assume we have hardware-accelerated virtualization support for amd64 |
| 462 | qemu="qemu-system-x86_64 -machine pc,accel=kvm -cpu host" |
| 463 | |
Alistair Delva | 297632a | 2019-07-10 17:22:15 -0700 | [diff] [blame] | 464 | # We know 'ttyS0' will be our serial port on x86 from the hard-coded |
| 465 | # '-serial mon:stdio' flag below |
| 466 | cmdline="$cmdline console=ttyS0" |
| 467 | |
| 468 | # The assignment of 'ttyS1' here is magical; we know ttyS0 was used up |
| 469 | # by '-serial mon:stdio', and so this second serial port will be 'ttyS1' |
Alistair Delva | 668071d | 2021-04-09 11:54:59 -0700 | [diff] [blame] | 470 | cmdline="$cmdline exitcode=/dev/ttyS1" |
Alistair Strachan | 9ea6092 | 2018-10-25 13:36:34 -0700 | [diff] [blame] | 471 | elif [ "$ARCH" == "arm64" ]; then |
| 472 | # This uses a software model CPU, based on cortex-a57 |
| 473 | qemu="qemu-system-aarch64 -machine virt -cpu cortex-a57" |
| 474 | |
Alistair Delva | 297632a | 2019-07-10 17:22:15 -0700 | [diff] [blame] | 475 | # We know 'ttyAMA0' will be our serial port on arm64 from the hard-coded |
| 476 | # '-serial mon:stdio' flag below |
| 477 | cmdline="$cmdline console=ttyAMA0" |
| 478 | |
Alistair Strachan | 9ea6092 | 2018-10-25 13:36:34 -0700 | [diff] [blame] | 479 | # The kernel will print messages via a virtual ARM serial port (ttyAMA0), |
| 480 | # but for command line consistency with x86, we put the exitcode serial |
| 481 | # port on the PCI bus, and it will be the only one. |
Alistair Delva | 668071d | 2021-04-09 11:54:59 -0700 | [diff] [blame] | 482 | cmdline="$cmdline exitcode=/dev/ttyS0" |
Alistair Strachan | 9ea6092 | 2018-10-25 13:36:34 -0700 | [diff] [blame] | 483 | fi |
| 484 | |
| 485 | $qemu >&2 -name net_test -m 512 \ |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 486 | -kernel $KERNEL_BINARY \ |
Maciej Żenczykowski | 42f9634 | 2018-11-07 02:16:37 -0800 | [diff] [blame] | 487 | -no-user-config -nodefaults -no-reboot \ |
| 488 | -display none -nographic -serial mon:stdio -parallel none \ |
Alistair Strachan | 9ea6092 | 2018-10-25 13:36:34 -0700 | [diff] [blame] | 489 | -smp 4,sockets=4,cores=1,threads=1 \ |
Maciej Żenczykowski | 2cc987d | 2018-10-09 15:54:58 -0700 | [diff] [blame] | 490 | -device virtio-rng-pci \ |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 491 | -chardev file,id=exitcode,path=exitcode \ |
Alistair Strachan | 9ea6092 | 2018-10-25 13:36:34 -0700 | [diff] [blame] | 492 | -device pci-serial,chardev=exitcode \ |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 493 | -fsdev local,security_model=mapped-xattr,id=fsdev0,fmode=0644,dmode=0755,path=$SCRIPT_DIR \ |
| 494 | -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=host \ |
Maciej Żenczykowski | 42f9634 | 2018-11-07 02:16:37 -0800 | [diff] [blame] | 495 | $blockdevice $netconfig -append "$cmdline" |
| 496 | [[ -s exitcode ]] && exitcode=`cat exitcode | tr -d '\r'` || exitcode=1 |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 497 | rm -f exitcode |
Alistair Strachan | 473536b | 2018-05-14 12:58:46 -0700 | [diff] [blame] | 498 | fi |
Maciej Żenczykowski | 99cd00d | 2018-10-14 20:03:23 -0700 | [diff] [blame] | 499 | |
| 500 | # UML reliably screws up the ptys, QEMU probably can as well... |
| 501 | fixup_ptys |
Maciej Żenczykowski | 42f9634 | 2018-11-07 02:16:37 -0800 | [diff] [blame] | 502 | stty sane || : |
Maciej Żenczykowski | eedec7f | 2019-08-28 22:51:12 -0700 | [diff] [blame] | 503 | tput smam || : |
Maciej Żenczykowski | 42f9634 | 2018-11-07 02:16:37 -0800 | [diff] [blame] | 504 | |
| 505 | echo "Returning exit code ${exitcode}." 1>&2 |
Maciej Żenczykowski | 99cd00d | 2018-10-14 20:03:23 -0700 | [diff] [blame] | 506 | exit "${exitcode}" |