[CRIU] [PATCH v9 9/9] tests: add a test for macvlan
Tycho Andersen
tycho.andersen at canonical.com
Wed Oct 19 09:15:15 PDT 2016
Note that this test doesn't run in uns mode, even though we have support
for that. Without a full container engine, I couldn't think of a nice way
to pass a macvlan device into the zdtm "container" when in UNS mode.
v2: use the nsid_manip feature flag
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
test/zdtm/static/Makefile | 1 +
test/zdtm/static/macvlan.c | 70 +++++++++++++++++++++++++++++++++++++++++++
test/zdtm/static/macvlan.desc | 1 +
test/zdtm/static/macvlan.hook | 30 +++++++++++++++++++
4 files changed, 102 insertions(+)
create mode 100644 test/zdtm/static/macvlan.c
create mode 100644 test/zdtm/static/macvlan.desc
create mode 100755 test/zdtm/static/macvlan.hook
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index af1254f..e2717a0 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -152,6 +152,7 @@ TST_NOFILE := \
cgroupns \
helper_zombie_child \
clone_fs \
+ macvlan \
# jobctl00 \
ifneq ($(SRCARCH),arm)
diff --git a/test/zdtm/static/macvlan.c b/test/zdtm/static/macvlan.c
new file mode 100644
index 0000000..018dffd
--- /dev/null
+++ b/test/zdtm/static/macvlan.c
@@ -0,0 +1,70 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <linux/limits.h>
+#include <signal.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#include "zdtmtst.h"
+
+const char *test_doc = "check that macvlan interfaces are c/r'd correctly";
+const char *test_author = "Tycho Andersen <tycho.andersen at canonical.com>";
+
+#define BRIDGE_NAME "zdtmbr0"
+#define IF_NAME "zdtmmvlan0"
+
+static bool wait_for_macvlan(void)
+{
+ int i;
+
+ for (i = 0; i < 10; i++) {
+ if (system("ip addr list dev " IF_NAME) == 0)
+ return true;
+
+ sleep(1);
+ }
+
+ return false;
+}
+
+int main(int argc, char **argv)
+{
+ int ret = 1;
+
+ test_init(argc, argv);
+
+ if (!wait_for_macvlan()) {
+ fail("failed to inject macvlan device\n");
+ return 1;
+ }
+
+ if (system("ip addr list dev " IF_NAME " > macvlan.dump.test")) {
+ fail("can't save net config");
+ goto out;
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ if (system("ip addr list dev " IF_NAME " > macvlan.rst.test")) {
+ fail("can't get net config");
+ goto out;
+ }
+
+ if (system("diff macvlan.rst.test macvlan.dump.test")) {
+ fail("Net config differs after restore");
+ goto out;
+ }
+
+ pass();
+ ret = 0;
+
+out:
+ return ret;
+}
diff --git a/test/zdtm/static/macvlan.desc b/test/zdtm/static/macvlan.desc
new file mode 100644
index 0000000..f7b15e4
--- /dev/null
+++ b/test/zdtm/static/macvlan.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'deps': [ '/bin/sh', '/usr/bin/sort', '/bin/grep', '/sbin/ip', '/usr/bin/diff'], 'flags': 'suid', 'ropts': '--external macvlan[zdtmmvlan0]:zdtmbr0', 'feature': 'nsid_manip'}
diff --git a/test/zdtm/static/macvlan.hook b/test/zdtm/static/macvlan.hook
new file mode 100755
index 0000000..0dea7d1
--- /dev/null
+++ b/test/zdtm/static/macvlan.hook
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+[ "$1" == "--clean" -o "$1" == "--pre-restore" -o "$1" == "--post-start" ] || exit 0
+
+if [ "$1" == "--post-start" ]; then
+ set -e
+
+ i=0
+ while [ -z "$(pidof -s macvlan)" ]; do
+ i=$(($i+1))
+ if [ "$i" -eq "10" ]; then
+ echo "failed to create macvlan test"
+ exit 1
+ fi
+ sleep 1
+ done
+
+ ip link add zdtmbr0 type bridge
+ ip addr add 10.0.55.55/32 dev zdtmbr0
+ ip link set zdtmbr0 up
+ ip link add zdtmmvlan0 link zdtmbr0 type macvlan mode bridge
+ ip addr add 10.0.55.56/32 dev zdtmmvlan0
+ ip link set zdtmmvlan0 netns $(pidof -s macvlan)
+else
+ ip link del zdtmmvlan0 || true
+
+ [ "$1" == "--clean" ] || exit 0
+
+ ip link del zdtmbr0 || true
+fi
--
2.7.4
More information about the CRIU
mailing list