Skip to content

Commit c07714a

Browse files
author
Octavian Purdila
committed
Merge pull request torvalds#91 from pscollins/faster-hijack-tests-standalone
lkl: Let hijack tests run faster
2 parents 520c1f2 + ee42ac0 commit c07714a

File tree

1 file changed

+57
-23
lines changed

1 file changed

+57
-23
lines changed

tools/lkl/tests/hijack-test.sh

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
#!/bin/bash -e
1+
#!/bin/bash
2+
3+
set -e
24

35
script_dir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd)
4-
hijack_script=lkl-hijack.sh
5-
export PATH=${script_dir}/../bin/:${PATH}
6+
hijack_script=${script_dir}/../bin/lkl-hijack.sh
67

7-
if ! [ -e ${script_dir}/../liblkl-hijack.so ]; then
8+
if [[ ! -e ${script_dir}/../liblkl-hijack.so ]]; then
9+
echo "WARNING: tests can't be run. Quitting early."
810
exit 0;
911
fi
1012

13+
# Make a temporary directory to run tests in, since we'll be copying
14+
# things there.
15+
work_dir=$(mktemp -d)
16+
17+
# And make sure we clean up when we're done
18+
function clear_work_dir {
19+
rm -rf ${work_dir}
20+
sudo ip link set dev lkl_ptt0 down &> /dev/null || true
21+
sudo ip tuntap del dev lkl_ptt0 mode tap &> /dev/null || true
22+
}
23+
24+
trap clear_work_dir EXIT
25+
26+
echo "Running tests in ${work_dir}"
27+
1128
echo "== ip addr test=="
1229
${hijack_script} ip addr
1330

@@ -16,13 +33,13 @@ ${hijack_script} ip route
1633

1734
echo "== ping test=="
1835
cp `which ping` .
19-
${hijack_script} ./ping 127.0.0.1 -c 2
20-
rm ping
36+
${hijack_script} ./ping 127.0.0.1 -c 1
37+
rm ./ping
2138

2239
echo "== ping6 test=="
2340
cp `which ping6` .
24-
${hijack_script} ./ping6 ::1 -c 2
25-
rm ping6
41+
${hijack_script} ./ping6 ::1 -c 1
42+
rm ./ping6
2643

2744
echo "== Mount/dump tests =="
2845
# Need to say || true because ip -h returns < 0
@@ -37,18 +54,35 @@ echo "$ans" | tail -n 15 | grep "65536" # lo's MTU
3754
echo "$ans" | grep "0x0" # lo's dev_id
3855

3956
echo "== TAP tests =="
40-
if [ -c /dev/net/tun ]; then
41-
sudo ip tuntap del dev lkl_ptt0 mode tap || true
42-
sudo ip tuntap add dev lkl_ptt0 mode tap user $USER
43-
sudo ip link set dev lkl_ptt0 up
44-
sudo ip addr add dev lkl_ptt0 192.168.13.1/24
45-
LKL_HIJACK_NET_TAP=lkl_ptt0 LKL_HIJACK_NET_IP=192.168.13.2 LKL_HIJACK_NET_NETMASK_LEN=24 ${hijack_script} ip link | grep eth0
46-
LKL_HIJACK_NET_TAP=lkl_ptt0 LKL_HIJACK_NET_IP=192.168.13.2 LKL_HIJACK_NET_NETMASK_LEN=24 ${hijack_script} ip addr | grep 192.168.13.2
47-
cp `which ping` .
48-
LKL_HIJACK_NET_TAP=lkl_ptt0 LKL_HIJACK_NET_IP=192.168.13.2 LKL_HIJACK_NET_NETMASK_LEN=24 ${hijack_script} ./ping 192.168.13.1 -i 0.2 -c 65
49-
rm ./ping
50-
(sudo arp -d 192.168.13.2 && ping -i 0.2 -c 65 192.168.13.2 & LKL_HIJACK_NET_TAP=lkl_ptt0 LKL_HIJACK_NET_IP=192.168.13.2 LKL_HIJACK_NET_NETMASK_LEN=24 ${hijack_script} sleep 15)
51-
LKL_HIJACK_NET_MAC="aa:bb:cc:dd:ee:ff" LKL_HIJACK_NET_TAP=lkl_ptt0 LKL_HIJACK_NET_IP=192.168.13.2 LKL_HIJACK_NET_NETMASK_LEN=24 ${hijack_script} ip addr | grep "aa:bb:cc:dd:ee:ff"
52-
sudo ip link set dev lkl_ptt0 down
53-
sudo ip tuntap del dev lkl_ptt0 mode tap
54-
fi;
57+
if [ ! -c /dev/net/tun ]; then
58+
echo "WARNING: missing /dev/net/tun, skipping TAP tests ."
59+
exit 0
60+
fi
61+
62+
export LKL_HIJACK_NET_TAP=lkl_ptt0
63+
export LKL_HIJACK_NET_IP=192.168.13.2
64+
export LKL_HIJACK_NET_NETMASK_LEN=24
65+
66+
# Set up the TAP device we'd like to use
67+
sudo ip tuntap del dev lkl_ptt0 mode tap || true
68+
sudo ip tuntap add dev lkl_ptt0 mode tap user $USER
69+
sudo ip link set dev lkl_ptt0 up
70+
sudo ip addr add dev lkl_ptt0 192.168.13.1/24
71+
72+
# Make sure our device has the addresses we expect
73+
addr=$(LKL_HIJACK_NET_MAC="aa:bb:cc:dd:ee:ff" ${hijack_script} ip addr)
74+
echo "$addr" | grep eth0
75+
echo "$addr" | grep 192.168.13.2
76+
echo "$addr" | grep "aa:bb:cc:dd:ee:ff"
77+
78+
# Copy ping so we're allowed to run it under LKL
79+
cp `which ping` .
80+
81+
# Make sure we can ping the host from inside LKL
82+
${hijack_script} ./ping 192.168.13.1 -c 1
83+
rm ./ping
84+
85+
# Now let's check that the host can see LKL.
86+
sudo arp -d 192.168.13.2
87+
sudo ping -i 0.01 -c 65 192.168.13.2 &
88+
${hijack_script} sleep 3

0 commit comments

Comments
 (0)