[CRIU] [PATCH 5/5] test: Add testing of a unix socket with relative name
Cyrill Gorcunov
gorcunov at openvz.org
Thu Jul 23 12:22:40 PDT 2015
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
test/zdtm.sh | 1 +
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/sk-unix-rel.c | 104 ++++++++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+)
create mode 100644 test/zdtm/live/static/sk-unix-rel.c
diff --git a/test/zdtm.sh b/test/zdtm.sh
index e7c0e6fc0daf..13c6008aa313 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -74,6 +74,7 @@ generate_test_list()
static/socket_queues
static/deleted_unix_sock
static/sk-unix-unconn
+ static/sk-unix-rel
static/pid00
static/pstree
static/caps00
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 8e98ac8a9ead..3a350933c007 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -136,6 +136,7 @@ TST_FILE = \
link10 \
file_attr \
deleted_unix_sock \
+ sk-unix-rel \
deleted_dev \
unlink_fstat00 \
unlink_fstat01 \
diff --git a/test/zdtm/live/static/sk-unix-rel.c b/test/zdtm/live/static/sk-unix-rel.c
new file mode 100644
index 000000000000..b5299cc4efde
--- /dev/null
+++ b/test/zdtm/live/static/sk-unix-rel.c
@@ -0,0 +1,104 @@
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <sys/un.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <fcntl.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Test unix stream sockets with relative name\n";
+const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org";
+
+#define SK_DATA "packet"
+
+char *filename;
+TEST_OPTION(filename, string, "socket file name", 1);
+
+#define TEST_MODE 0640
+
+int main(int argc, char *argv[])
+{
+ struct sockaddr_un addr;
+ unsigned int addrlen;
+ int sock[2];
+
+ char path[PATH_MAX];
+ char buf[64];
+ char *cwd;
+ int ret;
+
+ test_init(argc, argv);
+
+ cwd = get_current_dir_name();
+ if (!cwd) {
+ fail("getcwd\n");
+ exit(1);
+ }
+
+ snprintf(path, sizeof(path), "%s/%s", cwd, filename);
+ unlink(path);
+
+ addr.sun_family = AF_UNIX;
+ strncpy(addr.sun_path, filename, sizeof(addr.sun_path));
+ addrlen = sizeof(addr.sun_family) + strlen(filename);
+
+ sock[0] = socket(AF_UNIX, SOCK_STREAM, 0);
+ sock[1] = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (sock[0] < 0 || sock[1] < 0) {
+ fail("socket\n");
+ exit(1);
+ }
+
+ ret = bind(sock[0], &addr, addrlen);
+ if (ret) {
+ fail("bind\n");
+ exit(1);
+ }
+
+ ret = listen(sock[0], 16);
+ if (ret) {
+ fail("bind\n");
+ exit(1);
+ }
+
+ if (connect(sock[1], &addr, addrlen)) {
+ fail("connect\n");
+ exit(1);
+ }
+
+ ret = accept(sock[0], NULL, NULL);
+ if (ret < 0) {
+ fail("accept");
+ exit(1);
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ memset(buf, 0, sizeof(buf));
+ write(sock[1], SK_DATA, sizeof(SK_DATA));
+ read(ret, &buf, sizeof(buf));
+
+ if (strcmp(buf, SK_DATA)) {
+ fail("data corrupted\n");
+ exit(1);
+ }
+ test_msg("stream : '%s'\n", buf);
+ close(sock[0]);
+ close(sock[1]);
+ unlink(path);
+
+ pass();
+ return 0;
+}
--
2.4.3
More information about the CRIU
mailing list