WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / test_sock_addr.sh
blob3b9fdb8094aa28b5e5abbe99f15b1e4502869a68
1 #!/bin/sh
3 set -eu
5 ping_once()
7 type ping${1} >/dev/null 2>&1 && PING="ping${1}" || PING="ping -${1}"
8 $PING -q -c 1 -W 1 ${2%%/*} >/dev/null 2>&1
11 wait_for_ip()
13 local _i
14 echo -n "Wait for testing IPv4/IPv6 to become available "
15 for _i in $(seq ${MAX_PING_TRIES}); do
16 echo -n "."
17 if ping_once 4 ${TEST_IPv4} && ping_once 6 ${TEST_IPv6}; then
18 echo " OK"
19 return
21 done
22 echo 1>&2 "ERROR: Timeout waiting for test IP to become available."
23 exit 1
26 setup()
28 # Create testing interfaces not to interfere with current environment.
29 ip link add dev ${TEST_IF} type veth peer name ${TEST_IF_PEER}
30 ip link set ${TEST_IF} up
31 ip link set ${TEST_IF_PEER} up
33 ip -4 addr add ${TEST_IPv4} dev ${TEST_IF}
34 ip -6 addr add ${TEST_IPv6} dev ${TEST_IF}
35 wait_for_ip
38 cleanup()
40 ip link del ${TEST_IF} 2>/dev/null || :
41 ip link del ${TEST_IF_PEER} 2>/dev/null || :
44 main()
46 trap cleanup EXIT 2 3 6 15
47 setup
48 ./test_sock_addr setup_done
51 BASENAME=$(basename $0 .sh)
52 TEST_IF="${BASENAME}1"
53 TEST_IF_PEER="${BASENAME}2"
54 TEST_IPv4="127.0.0.4/8"
55 TEST_IPv6="::6/128"
56 MAX_PING_TRIES=5
58 main