Skip to content

Commit

Permalink
tests: Introduce NS_EXEC and NS_CHECK_EXEC for system tests.
Browse files Browse the repository at this point in the history
Instead of repeating every time "ip netns exec ..." it is better to
introduce some macros.

Signed-off-by: Daniele Di Proietto <[email protected]>
Acked-by: Joe Stringer <[email protected]>
  • Loading branch information
ddiproietto authored and joestringer committed Aug 7, 2015
1 parent f752620 commit b1778a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
27 changes: 21 additions & 6 deletions tests/system-common-macros.at
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ m4_define([DEL_NAMESPACES],
])
]
)
#

# ADD_NAMESPACES(ns [, ns ... ])
#
# Add new namespaces, if ns exists, the old one
Expand All @@ -21,6 +21,21 @@ m4_define([ADD_NAMESPACES],
]
)

# NS_EXEC([namespace], [command])
#
# Execute 'command' in 'namespace'
m4_define([NS_EXEC],
[ip netns exec $1 bash -c "$2"]
)

# NS_CHECK_EXEC([namespace], [command], other_params...)
#
# Wrapper for AT_CHECK that executes 'command' inside 'namespace'.
# 'other_params' as passed as they are to AT_CHECK.
m4_define([NS_CHECK_EXEC],
[ AT_CHECK([NS_EXEC([$1], [$2])], m4_shift(m4_shift($@))) ]
)

# ADD_VETH([port], [namespace], [ovs-br], [ip_addr])
#
# Add a pair of veth ports. 'port' will be added to name space 'namespace',
Expand All @@ -36,8 +51,8 @@ m4_define([ADD_VETH],
AT_CHECK([ip link set $1 netns $2])
AT_CHECK([ovs-vsctl add-port $3 ovs-$1])
AT_CHECK([ip link set dev ovs-$1 up])
AT_CHECK([ip netns exec $2 ip addr add $4 dev $1])
AT_CHECK([ip netns exec $2 ip link set dev $1 up])
NS_CHECK_EXEC([$2], [ip addr add $4 dev $1])
NS_CHECK_EXEC([$2], [ip link set dev $1 up])
]
)

Expand All @@ -46,8 +61,8 @@ m4_define([ADD_VETH],
# Add a VLAN device named 'port' within 'namespace'. It will be configured
# with the ID 'vlan-id' and the address 'ip-addr'.
m4_define([ADD_VLAN],
[ AT_CHECK([ip netns exec $2 ip link add link $1 name $1.$3 type vlan id $3])
AT_CHECK([ip netns exec $2 ip link set dev $1.$3 up])
AT_CHECK([ip netns exec $2 ip addr add dev $1.$3 $4])
[ NS_CHECK_EXEC([$2], [ip link add link $1 name $1.$3 type vlan id $3])
NS_CHECK_EXEC([$2], [ip link set dev $1.$3 up])
NS_CHECK_EXEC([$2], [ip addr add dev $1.$3 $4])
]
)
24 changes: 12 additions & 12 deletions tests/system-traffic.at
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24")
ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24")

AT_CAPTURE_FILE([ping.output])
AT_CHECK([ip netns exec at_ns0 bash -c "ping -q -c 3 -i 0.3 -w 2 10.1.1.2 > ping.output"])
AT_CHECK([ip netns exec at_ns0 bash -c "ping -s 1600 -q -c 3 -i 0.3 -w 2 10.1.1.2 >> ping.output"])
AT_CHECK([ip netns exec at_ns0 bash -c "ping -s 3200 -q -c 3 -i 0.3 -w 2 10.1.1.2 >> ping.output"])
NS_CHECK_EXEC([at_ns0], [ping -q -c 3 -i 0.3 -w 2 10.1.1.2 > ping.output])
NS_CHECK_EXEC([at_ns0], [ping -s 1600 -q -c 3 -i 0.3 -w 2 10.1.1.2 >> ping.output])
NS_CHECK_EXEC([at_ns0], [ping -s 3200 -q -c 3 -i 0.3 -w 2 10.1.1.2 >> ping.output])

AT_CHECK([cat ping.output | grep "transmitted" | sed 's/time.*ms$/time 0ms/'], [0], [dnl
3 packets transmitted, 3 received, 0% packet loss, time 0ms
Expand All @@ -36,9 +36,9 @@ ADD_VLAN(p0, at_ns0, 100, "10.2.2.1/24")
ADD_VLAN(p1, at_ns1, 100, "10.2.2.2/24")

AT_CAPTURE_FILE([ping.output])
AT_CHECK([ip netns exec at_ns0 bash -c "ping -q -c 3 -i 0.3 -w 2 10.2.2.2 > ping.output"])
AT_CHECK([ip netns exec at_ns0 bash -c "ping -s 1600 -q -c 3 -i 0.3 -w 2 10.2.2.2 >> ping.output"])
AT_CHECK([ip netns exec at_ns0 bash -c "ping -s 3200 -q -c 3 -i 0.3 -w 2 10.2.2.2 >> ping.output"])
NS_CHECK_EXEC([at_ns0], [ping -q -c 3 -i 0.3 -w 2 10.2.2.2 > ping.output])
NS_CHECK_EXEC([at_ns0], [ping -s 1600 -q -c 3 -i 0.3 -w 2 10.2.2.2 >> ping.output])
NS_CHECK_EXEC([at_ns0], [ping -s 3200 -q -c 3 -i 0.3 -w 2 10.2.2.2 >> ping.output])

AT_CHECK([cat ping.output | grep "transmitted" | sed 's/time.*ms$/time 0ms/'], [0], [dnl
3 packets transmitted, 3 received, 0% packet loss, time 0ms
Expand All @@ -63,9 +63,9 @@ dnl "connect: Cannot assign requested address"
sleep 2;

AT_CAPTURE_FILE([ping.output])
AT_CHECK([ip netns exec at_ns0 bash -c "ping6 -q -c 3 -i 0.3 -w 2 fc00::2 > ping.output"])
AT_CHECK([ip netns exec at_ns0 bash -c "ping6 -s 1600 -q -c 3 -i 0.3 -w 2 fc00::2 >> ping.output"])
AT_CHECK([ip netns exec at_ns0 bash -c "ping6 -s 3200 -q -c 3 -i 0.3 -w 2 fc00::2 >> ping.output"])
NS_CHECK_EXEC([at_ns0], [ping6 -q -c 3 -i 0.3 -w 2 fc00::2 > ping.output])
NS_CHECK_EXEC([at_ns0], [ping6 -s 1600 -q -c 3 -i 0.3 -w 2 fc00::2 >> ping.output])
NS_CHECK_EXEC([at_ns0], [ping6 -s 3200 -q -c 3 -i 0.3 -w 2 fc00::2 >> ping.output])

AT_CHECK([cat ping.output | grep "transmitted" | sed 's/time.*ms$/time 0ms/'], [0], [dnl
3 packets transmitted, 3 received, 0% packet loss, time 0ms
Expand Down Expand Up @@ -93,9 +93,9 @@ dnl "connect: Cannot assign requested address"
sleep 2;

AT_CAPTURE_FILE([ping.output])
AT_CHECK([ip netns exec at_ns0 bash -c "ping6 -q -c 3 -i 0.3 -w 2 fc00:1::2 > ping.output"])
AT_CHECK([ip netns exec at_ns0 bash -c "ping6 -s 1600 -q -c 3 -i 0.3 -w 2 fc00:1::2 >> ping.output"])
AT_CHECK([ip netns exec at_ns0 bash -c "ping6 -s 3200 -q -c 3 -i 0.3 -w 2 fc00:1::2 >> ping.output"])
NS_CHECK_EXEC([at_ns0], [ping6 -q -c 3 -i 0.3 -w 2 fc00:1::2 > ping.output])
NS_CHECK_EXEC([at_ns0], [ping6 -s 1600 -q -c 3 -i 0.3 -w 2 fc00:1::2 >> ping.output])
NS_CHECK_EXEC([at_ns0], [ping6 -s 3200 -q -c 3 -i 0.3 -w 2 fc00:1::2 >> ping.output])

AT_CHECK([cat ping.output | grep "transmitted" | sed 's/time.*ms$/time 0ms/'], [0], [dnl
3 packets transmitted, 3 received, 0% packet loss, time 0ms
Expand Down

0 comments on commit b1778a5

Please sign in to comment.