1 #!/bin/bash 2 3 # Kernel configuration options. 4 OPTIONS=" DEBUG_SPINLOCK DEBUG_ATOMIC_SLEEP DEBUG_MUTEXES DEBUG_RT_MUTEXES" 5 OPTIONS="$OPTIONS IPV6 IPV6_ROUTER_PREF IPV6_MULTIPLE_TABLES IPV6_ROUTE_INFO" 6 OPTIONS="$OPTIONS TUN SYN_COOKIES IP_ADVANCED_ROUTER IP_MULTIPLE_TABLES" 7 OPTIONS="$OPTIONS NETFILTER NETFILTER_ADVANCED NETFILTER_XTABLES" 8 OPTIONS="$OPTIONS NETFILTER_XT_MARK NETFILTER_XT_TARGET_MARK" 9 OPTIONS="$OPTIONS IP_NF_IPTABLES IP_NF_MANGLE" 10 OPTIONS="$OPTIONS IP6_NF_IPTABLES IP6_NF_MANGLE INET6_IPCOMP" 11 OPTIONS="$OPTIONS IPV6_PRIVACY IPV6_OPTIMISTIC_DAD" 12 OPTIONS="$OPTIONS CONFIG_NETFILTER_XT_TARGET_NFLOG" 13 OPTIONS="$OPTIONS CONFIG_NETFILTER_XT_MATCH_QUOTA CONFIG_NETFILTER_XT_MATCH_QUOTA2" 14 OPTIONS="$OPTIONS CONFIG_NETFILTER_XT_MATCH_QUOTA2_LOG" 15 OPTIONS="$OPTIONS CONFIG_INET_UDP_DIAG CONFIG_INET_DIAG_DESTROY" 16 17 # For 3.1 kernels, where devtmpfs is not on by default. 18 OPTIONS="$OPTIONS DEVTMPFS DEVTMPFS_MOUNT" 19 20 # These two break the flo kernel due to differences in -Werror on recent GCC. 21 DISABLE_OPTIONS=" CONFIG_REISERFS_FS CONFIG_ANDROID_PMEM" 22 23 # How many TAP interfaces to create to provide the VM with real network access 24 # via the host. This requires privileges (e.g., root access) on the host. 25 # 26 # This is not needed to run the tests, but can be used, for example, to allow 27 # the VM to update system packages, or to write tests that need access to a 28 # real network. The VM does not set up networking by default, but it contains a 29 # DHCP client and has the ability to use IPv6 autoconfiguration. This script 30 # does not perform any host-level setup beyond configuring tap interfaces; 31 # configuring IPv4 NAT and/or IPv6 router advertisements or ND proxying must 32 # be done separately. 33 NUMTAPINTERFACES=0 34 35 # The root filesystem disk image we'll use. 36 ROOTFS=net_test.rootfs.20150203 37 COMPRESSED_ROOTFS=$ROOTFS.xz 38 URL=https://dl.google.com/dl/android/$COMPRESSED_ROOTFS 39 40 # Figure out which test to run. 41 if [ -z "$1" ]; then 42 echo "Usage: $0 <test>" >&2 43 exit 1 44 fi 45 test=$1 46 47 set -e 48 49 # Check if we need to uncompress the disk image. 50 # We use xz because it compresses better: to 42M vs 72M (gzip) / 62M (bzip2). 51 cd $(dirname $0) 52 if [ ! -f $ROOTFS ]; then 53 echo "Deleting $COMPRESSED_ROOTFS" >&2 54 rm -f $COMPRESSED_ROOTFS 55 echo "Downloading $URL" >&2 56 wget $URL 57 echo "Uncompressing $COMPRESSED_ROOTFS" >&2 58 unxz $COMPRESSED_ROOTFS 59 fi 60 echo "Using $ROOTFS" 61 cd - 62 63 # If network access was requested, create NUMTAPINTERFACES tap interfaces on 64 # the host, and prepare UML command line params to use them. The interfaces are 65 # called <user>TAP0, <user>TAP1, on the host, and eth0, eth1, ..., in the VM. 66 if (( $NUMTAPINTERFACES > 0 )); then 67 user=${USER:0:10} 68 tapinterfaces= 69 netconfig= 70 for id in $(seq 0 $(( NUMTAPINTERFACES - 1 )) ); do 71 tap=${user}TAP$id 72 tapinterfaces="$tapinterfaces $tap" 73 mac=$(printf fe:fd:00:00:00:%02x $id) 74 netconfig="$netconfig eth$id=tuntap,$tap,$mac" 75 done 76 77 for tap in $tapinterfaces; do 78 if ! ip link list $tap > /dev/null; then 79 echo "Creating tap interface $tap" >&2 80 sudo tunctl -u $USER -t $tap 81 sudo ip link set $tap up 82 fi 83 done 84 fi 85 86 if [ -z "$KERNEL_BINARY" ]; then 87 # Exporting ARCH=um SUBARCH=x86_64 doesn't seem to work, as it "sometimes" 88 # (?) results in a 32-bit kernel. 89 90 # If there's no kernel config at all, create one or UML won't work. 91 [ -f .config ] || make defconfig ARCH=um SUBARCH=x86_64 92 93 # Enable the kernel config options listed in $OPTIONS. 94 cmdline=${OPTIONS// / -e } 95 ./scripts/config $cmdline 96 97 # Disable the kernel config options listed in $DISABLE_OPTIONS. 98 cmdline=${DISABLE_OPTIONS// / -d } 99 ./scripts/config $cmdline 100 101 # olddefconfig doesn't work on old kernels. 102 if ! make olddefconfig ARCH=um SUBARCH=x86_64 CROSS_COMPILE= ; then 103 cat >&2 << EOF 104 105 Warning: "make olddefconfig" failed. 106 Perhaps this kernel is too old to support it. 107 You may get asked lots of questions. 108 Keep enter pressed to accept the defaults. 109 110 EOF 111 fi 112 113 # Compile the kernel. 114 make -j32 linux ARCH=um SUBARCH=x86_64 CROSS_COMPILE= 115 KERNEL_BINARY=./linux 116 fi 117 118 119 # Get the absolute path to the test file that's being run. 120 dir=/host$(dirname $(readlink -f $0)) 121 122 # Start the VM. 123 exec $KERNEL_BINARY umid=net_test ubda=$(dirname $0)/$ROOTFS \ 124 mem=512M init=/sbin/net_test.sh net_test=$dir/$test \ 125 $netconfig 126