[ovs-dev] [PATCH v2 2/4] tests: Introduce NS_EXEC and NS_CHECK_EXEC for system tests.

Daniele Di Proietto diproiettod at vmware.com
Fri Aug 7 18:40:35 UTC 2015


Instead of repeating every time "ip netns exec ..." it is better to
introduce some macros.

Signed-off-by: Daniele Di Proietto <diproiettod at vmware.com>
---
 tests/system-common-macros.at | 27 +++++++++++++++++++++------
 tests/system-traffic.at       | 24 ++++++++++++------------
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/tests/system-common-macros.at b/tests/system-common-macros.at
index bd622d2..ccdfdc6 100644
--- a/tests/system-common-macros.at
+++ b/tests/system-common-macros.at
@@ -7,7 +7,7 @@ m4_define([DEL_NAMESPACES],
 ])
    ]
 )
-#
+
 # ADD_NAMESPACES(ns [, ns ... ])
 #
 # Add new namespaces, if ns exists, the old one
@@ -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',
@@ -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])
     ]
 )
 
@@ -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])
     ]
 )
diff --git a/tests/system-traffic.at b/tests/system-traffic.at
index 9df8b62..34342d6 100644
--- a/tests/system-traffic.at
+++ b/tests/system-traffic.at
@@ -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
@@ -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
@@ -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
@@ -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
-- 
2.1.4




More information about the dev mailing list