[CRIU] [PATCH 21/21] zdtm: check sequence numbers for tcp sockets

Andrei Vagin avagin at openvz.org
Mon Nov 28 11:27:56 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

They have to be the same on each iteration.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 scripts/travis/travis-tests                 |  2 +-
 test/zdtm.py                                |  1 +
 test/zdtm/static/socket-tcp-close-wait.hook |  1 +
 test/zdtm/static/socket-tcp-closed.hook     |  1 +
 test/zdtm/static/socket-tcp-closing.hook    |  1 +
 test/zdtm/static/socket-tcp-fin-wait1.hook  | 66 +++++++++++++++++++++++++++++
 test/zdtm/static/socket-tcp-fin-wait2.hook  |  1 +
 test/zdtm/static/socket-tcp-last-ack.hook   |  1 +
 test/zdtm/static/socket-tcp-local.hook      |  1 +
 test/zdtm/static/socket-tcp-syn-sent.hook   |  1 +
 10 files changed, 75 insertions(+), 1 deletion(-)
 create mode 120000 test/zdtm/static/socket-tcp-close-wait.hook
 create mode 120000 test/zdtm/static/socket-tcp-closed.hook
 create mode 120000 test/zdtm/static/socket-tcp-closing.hook
 create mode 100755 test/zdtm/static/socket-tcp-fin-wait1.hook
 create mode 120000 test/zdtm/static/socket-tcp-fin-wait2.hook
 create mode 120000 test/zdtm/static/socket-tcp-last-ack.hook
 create mode 120000 test/zdtm/static/socket-tcp-local.hook
 create mode 120000 test/zdtm/static/socket-tcp-syn-sent.hook

diff --git a/scripts/travis/travis-tests b/scripts/travis/travis-tests
index 42276d8..75d15f5 100755
--- a/scripts/travis/travis-tests
+++ b/scripts/travis/travis-tests
@@ -4,7 +4,7 @@ set -x -e
 TRAVIS_PKGS="protobuf-c-compiler libprotobuf-c0-dev libaio-dev
 		libprotobuf-dev protobuf-compiler python-ipaddr libcap-dev
 		libnl-3-dev gcc-multilib libc6-dev-i386 gdb bash python-protobuf
-		libnet-dev"
+		libnet-dev util-linux"
 
 travis_prep () {
 	[ -n "$SKIP_TRAVIS_PREP" ] && return
diff --git a/test/zdtm.py b/test/zdtm.py
index ec9a91b..edc4f1e 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -1026,6 +1026,7 @@ def cr(cr_api, test, opts):
 			try_run_hook(test, ["--pre-restore"])
 			cr_api.restore()
 			os.environ["ZDTM_TEST_PID"] = str(test.getpid())
+                        os.environ["ZDTM_IMG_DIR"] = cr_api.logs()
 			try_run_hook(test, ["--post-restore"])
 			sbs('post-restore')
 
diff --git a/test/zdtm/static/socket-tcp-close-wait.hook b/test/zdtm/static/socket-tcp-close-wait.hook
new file mode 120000
index 0000000..73d7da1
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-close-wait.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait1.hook
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp-closed.hook b/test/zdtm/static/socket-tcp-closed.hook
new file mode 120000
index 0000000..73d7da1
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closed.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait1.hook
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp-closing.hook b/test/zdtm/static/socket-tcp-closing.hook
new file mode 120000
index 0000000..73d7da1
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-closing.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait1.hook
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp-fin-wait1.hook b/test/zdtm/static/socket-tcp-fin-wait1.hook
new file mode 100755
index 0000000..76200eb
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-fin-wait1.hook
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+import sys
+
+sys.path.append("../crit")
+
+import pycriu
+import os, os.path
+import json
+import difflib
+import subprocess
+
+if sys.argv[1] in ["--pre-dump", "--post-restore"]:
+    pid = os.getenv("ZDTM_TEST_PID")
+    try:
+        subprocess.Popen(["nsenter", "-t", pid, "-n", "ss", "-t", "-a", "-n"]).wait()
+    except OSError, e:
+        pass
+
+if sys.argv[1] != "--post-restore":
+    sys.exit(0)
+
+print "Check TCP images"
+
+def get_sockets(image_dir):
+    f = open(os.path.join(image_dir, "inetsk.img"))
+    sockets = pycriu.images.load(f)
+    sockets = sockets["entries"]
+
+    for s in sockets:
+        f = open(os.path.join(image_dir, "inetsk.img"))
+        ids = pycriu.images.load(f)
+        tcp_img = os.path.join(image_dir, "tcp-stream-%x.img" % int(s["ino"]))
+        print tcp_img
+        if os.access(tcp_img, os.F_OK):
+            f = open(tcp_img)
+            tcp = pycriu.images.load(f)
+            s['tcp'] = tcp["entries"][0]
+            s["tcp"].pop("extra", None)
+            s["tcp"].pop("timestamp", None)
+            s["tcp"].pop("snd_wl1", None)
+            s["tcp"].pop("rcv_wnd", None)
+            s["tcp"].pop("snd_wnd", None)
+            s["tcp"].pop("max_window", None)
+        s.pop("id", None)
+        s.pop("ino")
+    sockets.sort(lambda a, b: cmp(a["src_port"] + a["dst_port"], b["src_port"] + b["dst_port"]))
+    return sockets
+
+path = os.getenv("ZDTM_IMG_DIR")
+prev = None
+exit_code = 0
+for d in os.listdir(path):
+    sockets = get_sockets(os.path.join(path, d))
+    if not prev:
+        prev = sockets
+        continue
+
+    if prev == sockets:
+        continue
+
+    sockets_str = json.dumps(sockets, sys.stdout, indent=8, sort_keys=True)
+    prev_str = json.dumps(prev, sys.stdout, indent=8, sort_keys=True)
+
+    print "\n".join(difflib.unified_diff(prev_str.split("\n"), sockets_str.split("\n")))
+
+sys.exit(exit_code)
diff --git a/test/zdtm/static/socket-tcp-fin-wait2.hook b/test/zdtm/static/socket-tcp-fin-wait2.hook
new file mode 120000
index 0000000..73d7da1
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-fin-wait2.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait1.hook
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp-last-ack.hook b/test/zdtm/static/socket-tcp-last-ack.hook
new file mode 120000
index 0000000..73d7da1
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-last-ack.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait1.hook
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp-local.hook b/test/zdtm/static/socket-tcp-local.hook
new file mode 120000
index 0000000..4ffe289
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-local.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait2.hook
\ No newline at end of file
diff --git a/test/zdtm/static/socket-tcp-syn-sent.hook b/test/zdtm/static/socket-tcp-syn-sent.hook
new file mode 120000
index 0000000..73d7da1
--- /dev/null
+++ b/test/zdtm/static/socket-tcp-syn-sent.hook
@@ -0,0 +1 @@
+socket-tcp-fin-wait1.hook
\ No newline at end of file
-- 
2.7.4



More information about the CRIU mailing list