OSDN Git Service

am db1d49c7: (-s ours) DO NOT MERGE New ext4enc kernel switching from xattrs to ioctl
[android-x86/system-extras.git] / tests / net_test / run_net_test.sh
1 #!/bin/bash
2
3 # Kernel configuration 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 # These two break the flo kernel due to differences in -Werror on recent GCC.
15 DISABLE_OPTIONS=" CONFIG_REISERFS_FS CONFIG_ANDROID_PMEM"
16
17 # How many tap interfaces to create.
18 NUMTAPINTERFACES=2
19
20 # The root filesystem disk image we'll use.
21 ROOTFS=net_test.rootfs.20150203
22 COMPRESSED_ROOTFS=$ROOTFS.xz
23 URL=https://dl.google.com/dl/android/$COMPRESSED_ROOTFS
24
25 # Figure out which test to run.
26 if [ -z "$1" ]; then
27   echo "Usage: $0 <test>" >&2
28   exit 1
29 fi
30 test=$1
31
32 set -e
33
34 # Check if we need to uncompress the disk image.
35 # We use xz because it compresses better: to 42M vs 72M (gzip) / 62M (bzip2).
36 cd $(dirname $0)
37 if [ ! -f $ROOTFS ]; then
38   echo "Deleting $COMPRESSED_ROOTFS" >&2
39   rm -f $COMPRESSED_ROOTFS
40   echo "Downloading $URL" >&2
41   wget $URL
42   echo "Uncompressing $COMPRESSED_ROOTFS" >&2
43   unxz $COMPRESSED_ROOTFS
44 fi
45 echo "Using $ROOTFS"
46 cd -
47
48 # Create NUMTAPINTERFACES tap interfaces on the host, and prepare UML command
49 # line params to use them. The interfaces are called <user>TAP0, <user>TAP1,
50 # ..., on the host, and eth0, eth1, ..., in the VM.
51 user=${USER:0:10}
52 tapinterfaces=
53 netconfig=
54 for id in $(seq 0 $(( NUMTAPINTERFACES - 1 )) ); do
55   tap=${user}TAP$id
56   tapinterfaces="$tapinterfaces $tap"
57   mac=$(printf fe:fd:00:00:00:%02x $id)
58   netconfig="$netconfig eth$id=tuntap,$tap,$mac"
59 done
60
61 for tap in $tapinterfaces; do
62   if ! ip link list $tap > /dev/null; then
63     echo "Creating tap interface $tap" >&2
64     sudo tunctl -u $USER -t $tap
65     sudo ip link set $tap up
66   fi
67 done
68
69 # Exporting ARCH=um SUBARCH=x86_64 doesn't seem to work, as it "sometimes" (?)
70 # results in a 32-bit kernel.
71
72 # If there's no kernel config at all, create one or UML won't work.
73 [ -f .config ] || make defconfig ARCH=um SUBARCH=x86_64
74
75 # Enable the kernel config options listed in $OPTIONS.
76 cmdline=${OPTIONS// / -e }
77 ./scripts/config $cmdline
78
79 # Disable the kernel config options listed in $DISABLE_OPTIONS.
80 cmdline=${DISABLE_OPTIONS// / -d }
81 ./scripts/config $cmdline
82
83 # olddefconfig doesn't work on old kernels.
84 if ! make olddefconfig ARCH=um SUBARCH=x86_64 CROSS_COMPILE= ; then
85   cat >&2 << EOF
86
87 Warning: "make olddefconfig" failed.
88 Perhaps this kernel is too old to support it.
89 You may get asked lots of questions.
90 Keep enter pressed to accept the defaults.
91
92 EOF
93 fi
94
95 # Compile the kernel.
96 make -j12 linux ARCH=um SUBARCH=x86_64 CROSS_COMPILE=
97
98 # Get the absolute path to the test file that's being run.
99 dir=/host$(dirname $(readlink -f $0))
100
101 # Start the VM.
102 exec ./linux umid=net_test ubda=$(dirname $0)/$ROOTFS \
103     mem=512M init=/sbin/net_test.sh net_test=$dir/$test \
104     $netconfig