[CRIU] [PATCH] zdtm: Test --external veth option
Pavel Emelyanov
xemul at virtuozzo.com
Fri Oct 21 14:21:47 PDT 2016
Inspired by Tycho's macvlan test, here's the same thing for
--external veth option. In master we still have the --veth-pair
one, but the plan is to move this all under the --external opt.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
diff --git a/test/zdtm.py b/test/zdtm.py
index 96eb73c..e032716 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -1010,6 +1010,7 @@ def cr(cr_api, test, opts):
sbs('pre-restore')
try_run_hook(test, ["--pre-restore"])
cr_api.restore()
+ try_run_hook(test, ["--post-restore"])
sbs('post-restore')
time.sleep(iters[1])
diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
index 920772b..5817013 100644
--- a/test/zdtm/.gitignore
+++ b/test/zdtm/.gitignore
@@ -10,3 +10,4 @@
*.inprogress
*.test
*.test.*
+*.state
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index e2717a0..ec05b89 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -153,6 +153,7 @@ TST_NOFILE := \
helper_zombie_child \
clone_fs \
macvlan \
+ cr_veth \
# jobctl00 \
ifneq ($(SRCARCH),arm)
diff --git a/test/zdtm/static/cr_veth.c b/test/zdtm/static/cr_veth.c
new file mode 100644
index 0000000..deef735
--- /dev/null
+++ b/test/zdtm/static/cr_veth.c
@@ -0,0 +1,69 @@
+#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 veth C/R-s right";
+const char *test_author = "Pavel Emelyanov <xemul at virtuozzo.com>";
+
+#define IF_NAME "zdtmvthc0"
+
+static bool wait_for_veth(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_veth()) {
+ fail("failed to inject veth device\n");
+ return 1;
+ }
+
+ if (system("ip addr list dev " IF_NAME " | sed -e 's/@.*://' > cr_veth.dump.state")) {
+ fail("can't save net config");
+ goto out;
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ if (system("ip addr list dev " IF_NAME " | sed -e 's/@.*://' > cr_veth.rst.state")) {
+ fail("can't get net config");
+ goto out;
+ }
+
+ if (system("diff cr_veth.rst.state cr_veth.dump.state")) {
+ fail("Net config differs after restore");
+ goto out;
+ }
+
+ pass();
+ ret = 0;
+
+out:
+ return ret;
+}
diff --git a/test/zdtm/static/cr_veth.desc b/test/zdtm/static/cr_veth.desc
new file mode 100644
index 0000000..97a0b0c
--- /dev/null
+++ b/test/zdtm/static/cr_veth.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'deps': [ '/bin/sh', '/usr/bin/sed', '/bin/grep', '/sbin/ip', '/usr/bin/diff'], 'flags': 'suid', 'ropts': '--external veth[zdtmvthc0]:zdtmvthh0 at zdtmbr0'}
diff --git a/test/zdtm/static/cr_veth.hook b/test/zdtm/static/cr_veth.hook
new file mode 100755
index 0000000..6c55307
--- /dev/null
+++ b/test/zdtm/static/cr_veth.hook
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+[ "$1" == "--post-restore" -o "$1" == "--post-start" ] || exit 0
+
+if [ "$1" == "--post-start" ]; then
+ set -e
+
+ i=0
+ while [ -z "$(pidof -s cr_veth)" ]; do
+ i=$(($i+1))
+ if [ "$i" -eq "10" ]; then
+ echo "failed to create veth test"
+ exit 1
+ fi
+ sleep 1
+ done
+
+ ip link add zdtmvthc0 type veth peer name zdtmvthh0
+ ip link set zdtmvthc0 netns $(pidof -s cr_veth)
+
+ ip link add zdtmbr0 type bridge
+ ip link set zdtmbr0 up
+ ip link set zdtmvthh0 master zdtmbr0
+else
+ ip link list zdtmvthh0
+
+ if ! ip link list zdtmvthh0 | fgrep -q 'master zdtmbr0'; then
+ echo "Device missing or not in bridge"
+ exit 1
+ fi
+
+ echo "Device OK"
+fi
More information about the CRIU
mailing list