[CRIU] [PATCH 1/2] tests: add a (failing) test for standalone unix sockets
Tycho Andersen
tycho.andersen at canonical.com
Wed Jun 22 10:35:01 PDT 2016
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
test/zdtm/.gitignore | 1 +
test/zdtm/static/Makefile | 1 +
test/zdtm/static/deleted_standalone_unix.c | 76 +++++++++++++++++++++++++++
test/zdtm/static/deleted_standalone_unix.desc | 1 +
4 files changed, 79 insertions(+)
create mode 100644 test/zdtm/static/deleted_standalone_unix.c
create mode 100644 test/zdtm/static/deleted_standalone_unix.desc
diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
index 85e39a2..4864731 100644
--- a/test/zdtm/.gitignore
+++ b/test/zdtm/.gitignore
@@ -28,6 +28,7 @@
/static/cwd01
/static/cwd02
/static/deleted_dev
+/static/deleted_standalone_unix
/static/deleted_unix_sock
/static/different_creds
/static/dumpable01
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 3da7e3b..b1bd2d8 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -162,6 +162,7 @@ TST_FILE = \
link10 \
file_attr \
deleted_unix_sock \
+ deleted_standalone_unix \
sk-unix-rel \
deleted_dev \
unlink_fstat00 \
diff --git a/test/zdtm/static/deleted_standalone_unix.c b/test/zdtm/static/deleted_standalone_unix.c
new file mode 100644
index 0000000..9288a6d
--- /dev/null
+++ b/test/zdtm/static/deleted_standalone_unix.c
@@ -0,0 +1,76 @@
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Check that deleted unix sockets are restored correctly";
+const char *test_author = "Tycho Andersen <tycho.andersen at canonical.com>";
+
+char *filename;
+TEST_OPTION(filename, string, "file name", 1);
+
+static int fill_sock_name(struct sockaddr_un *name, const char *filename)
+{
+ char *cwd;
+
+ cwd = get_current_dir_name();
+ if (strlen(filename) + strlen(cwd) + 1 >= sizeof(name->sun_path))
+ return -1;
+
+ name->sun_family = AF_LOCAL;
+ sprintf(name->sun_path, "%s/%s", cwd, filename);
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ struct sockaddr_un addr;
+ int sk, ret = 1;
+
+ test_init(argc, argv);
+
+ sk = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (sk < 0) {
+ fail("socket");
+ return 1;
+ }
+
+ if (fill_sock_name(&addr, filename) < 0) {
+ pr_err("filename \"%s\" is too long", filename);
+ goto out;
+ }
+
+ if (bind(sk, &addr, sizeof(addr))) {
+ fail("bind");
+ goto out;
+ }
+
+ if (listen(sk, 1)) {
+ fail("listen");
+ goto out;
+ }
+
+ if (unlink(addr.sun_path) < 0) {
+ fail("unlink");
+ goto out;
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ if (getsockopt(sk, 0, 0, NULL, 0) && errno != EOPNOTSUPP) {
+ fail("socket didn't survive restore");
+ goto out;
+ }
+
+ pass();
+ ret = 0;
+out:
+ close(sk);
+ return ret;
+}
diff --git a/test/zdtm/static/deleted_standalone_unix.desc b/test/zdtm/static/deleted_standalone_unix.desc
new file mode 100644
index 0000000..289362e
--- /dev/null
+++ b/test/zdtm/static/deleted_standalone_unix.desc
@@ -0,0 +1 @@
+{'flavor': 'h ns uns'}
--
2.7.4
More information about the CRIU
mailing list