OSDN Git Service

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