[CRIU] [PATCH 5/5] tests: add a test for macvlan

Tycho Andersen tycho.andersen at canonical.com
Tue Jun 14 09:45:32 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.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 test/zdtm/.gitignore          |  1 +
 test/zdtm/static/Makefile     |  1 +
 test/zdtm/static/macvlan.c    | 97 +++++++++++++++++++++++++++++++++++++++++++
 test/zdtm/static/macvlan.desc |  1 +
 4 files changed, 100 insertions(+)
 create mode 100644 test/zdtm/static/macvlan.c
 create mode 100644 test/zdtm/static/macvlan.desc

diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
index 85e39a2..6769266 100644
--- a/test/zdtm/.gitignore
+++ b/test/zdtm/.gitignore
@@ -227,6 +227,7 @@
 /static/file_locks03
 /static/file_locks04
 /static/file_locks05
+/static/macvlan
 /static/mlock_setuid
 /static/mntns_root_bind
 /static/mntns_root_bind02
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 82c73cd..e146f98 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -151,6 +151,7 @@ TST_NOFILE	=				\
 		oom_score_adj			\
 		loginuid			\
 		cgroupns			\
+		macvlan			\
 #		jobctl00			\
 
 TST_FILE	=				\
diff --git a/test/zdtm/static/macvlan.c b/test/zdtm/static/macvlan.c
new file mode 100644
index 0000000..d7112a3
--- /dev/null
+++ b/test/zdtm/static/macvlan.c
@@ -0,0 +1,97 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.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"
+
+int add_macvlan(void)
+{
+	/* create a bridge to attach a macvlan interface to */
+	if (system("ip link add " BRIDGE_NAME " type bridge")) {
+		pr_err("creating bridge");
+		return -1;
+	}
+
+	if (system("ip addr add 10.0.55.55/32 dev " BRIDGE_NAME)) {
+		pr_err("adding bridge addr");
+		return -1;
+	}
+
+	if (system("ip link set " BRIDGE_NAME " up")) {
+		pr_err("setting bridge up");
+		return -1;
+	}
+
+	if (system("ip link add " IF_NAME " link " BRIDGE_NAME " type macvlan mode bridge")) {
+		pr_err("adding macvlan link failed");
+		return -1;
+	}
+
+	if (system("ip addr add 10.0.55.56/32 dev " IF_NAME)) {
+		pr_err("adding bridge addr");
+		return -1;
+	}
+
+
+	if (system("ip link set up " IF_NAME)) {
+		pr_err("setting macvlan link up");
+		return -1;
+	}
+
+	return 0;
+}
+
+int del_macvlan(void)
+{
+	system("ip link del " IF_NAME);
+	return system("ip link del " BRIDGE_NAME);
+}
+
+int main(int argc, char **argv)
+{
+	int ret = 1;
+
+	test_init(argc, argv);
+
+	if (add_macvlan() < 0)
+		return ret;
+
+	if (system("ip addr list dev " IF_NAME " | grep inet > macvlan.dump.test")) {
+		fail("can't save net config");
+		goto out;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (system("ip addr list dev " IF_NAME " | grep inet > 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:
+	del_macvlan();
+	return ret;
+}
diff --git a/test/zdtm/static/macvlan.desc b/test/zdtm/static/macvlan.desc
new file mode 100644
index 0000000..09929a2
--- /dev/null
+++ b/test/zdtm/static/macvlan.desc
@@ -0,0 +1 @@
+{'flavor': 'h ns', 'deps': [ '/bin/sh', '/usr/bin/sort', '/bin/grep', '/sbin/ip', '/usr/bin/diff'], 'flags': 'suid'}
-- 
2.7.4



More information about the CRIU mailing list