run_net_test.sh revision d7c3975614112794fccf8a576d442c19e801daa8
1#!/bin/bash 2 3# Kernel configration options. 4OPTIONS=" IPV6 IPV6_ROUTER_PREF IPV6_MULTIPLE_TABLES IPV6_ROUTE_INFO" 5OPTIONS="$OPTIONS TUN SYN_COOKIES IP_ADVANCED_ROUTER IP_MULTIPLE_TABLES" 6OPTIONS="$OPTIONS NETFILTER NETFILTER_ADVANCED NETFILTER_XTABLES" 7OPTIONS="$OPTIONS NETFILTER_XT_MARK NETFILTER_XT_TARGET_MARK" 8OPTIONS="$OPTIONS IP_NF_IPTABLES IP_NF_MANGLE" 9OPTIONS="$OPTIONS IP6_NF_IPTABLES IP6_NF_MANGLE INET6_IPCOMP" 10# For 3.1 kernels, where devtmpfs is not on by default. 11OPTIONS="$OPTIONS DEVTMPFS DEVTMPFS_MOUNT" 12 13# How many tap interfaces to create. 14NUMTAPINTERFACES=2 15 16# The root filesystem disk image we'll use. 17ROOTFS=$(dirname $0)/net_test.rootfs 18 19# Figure out which test to run. 20if [ -z "$1" ]; then 21 echo "Usage: $0 <test>" >&2 22 exit 1 23fi 24test=$1 25 26set -e 27 28# Check if we need to uncompress the disk image. 29# We use xz because it compresses better: to 42M vs 72M (gzip) / 62M (bzip2). 30if [ $ROOTFS.xz -nt $ROOTFS ]; then 31 echo "Deleting $ROOTFS" >&2 32 rm -f $ROOTFS 33 echo "Uncompressing $ROOTFS.xz" >&2 34 unxz --keep $ROOTFS.xz 35fi 36 37 38# Create NUMTAPINTERFACES tap interfaces on the host, and prepare UML command 39# line params to use them. The interfaces are called <user>TAP0, <user>TAP1, 40# ..., on the host, and eth0, eth1, ..., in the VM. 41user=${USER:0:10} 42tapinterfaces= 43netconfig= 44for id in $(seq 0 $(( NUMTAPINTERFACES - 1 )) ); do 45 tap=${user}TAP$id 46 tapinterfaces="$tapinterfaces $tap" 47 mac=$(printf fe:fd:00:00:00:%02x $id) 48 netconfig="$netconfig eth$id=tuntap,$tap,$mac" 49done 50 51for tap in $tapinterfaces; do 52 if ! ip link list $tap > /dev/null; then 53 echo "Creating tap interface $tap" >&2 54 sudo tunctl -u $USER -t $tap 55 sudo ip link set $tap up 56 fi 57done 58 59# Exporting ARCH=um SUBARCH=x86_64 doesn't seem to work, as it "sometimes" (?) 60# results in a 32-bit kernel. 61 62# If there's no kernel config at all, create one or UML won't work. 63[ -f .config ] || make defconfig ARCH=um SUBARCH=x86_64 64 65# Enable the kernel config options listed in $OPTIONS. 66cmdline=${OPTIONS// / -e } 67./scripts/config $cmdline 68 69# olddefconfig doesn't work on old kernels. 70if ! make olddefconfig ARCH=um SUBARCH=x86_64 CROSS_COMPILE= ; then 71 cat >&2 << EOF 72 73Warning: "make olddefconfig" failed. 74Perhaps this kernel is too old to support it. 75You may get asked lots of questions. 76Keep enter pressed to accept the defaults. 77 78EOF 79fi 80 81# Compile the kernel. 82make -j12 linux ARCH=um SUBARCH=x86_64 CROSS_COMPILE= 83 84# Get the absolute path to the test file that's being run. 85dir=/host$(dirname $(readlink -f $0)) 86 87# Start the VM. 88exec ./linux umid=net_test ubda=$(dirname $0)/net_test.rootfs \ 89 mem=512M init=/sbin/net_test.sh net_test=$dir/$test \ 90 $netconfig 91