Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/checkpoint-restore/criu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>2019-11-14 14:50:43 +0300
committerAndrei Vagin <avagin@gmail.com>2020-02-04 23:39:05 +0300
commit55f7a571f286baa6eac6fe7a020914505a0eb464 (patch)
tree3c700b6f40c64eac41b8cf0ceb71283f4fb5fad1 /test
parentebe3b52353c5d380d01c332e7d57594995258c18 (diff)
zdtm: sysctl net.unix.max_dgram_qlen value preservation test
Test checks that if the /proc/sys/net/unix/max_dgram_qlen value has been changed in process net namespace, then it is saved after c/r. Signed-off-by: Alexander Mikhalitsyn <alexander@mihalicyn.com> Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
Diffstat (limited to 'test')
-rw-r--r--test/zdtm/lib/Makefile2
-rw-r--r--test/zdtm/lib/sysctl.c59
-rw-r--r--test/zdtm/lib/sysctl.h7
-rw-r--r--test/zdtm/static/Makefile1
-rw-r--r--test/zdtm/static/netns_sub_sysctl.c56
-rw-r--r--test/zdtm/static/netns_sub_sysctl.desc4
6 files changed, 128 insertions, 1 deletions
diff --git a/test/zdtm/lib/Makefile b/test/zdtm/lib/Makefile
index d2d9f1cc3..b87f36e8f 100644
--- a/test/zdtm/lib/Makefile
+++ b/test/zdtm/lib/Makefile
@@ -4,7 +4,7 @@ CFLAGS += $(USERCFLAGS)
LIB := libzdtmtst.a
-LIBSRC := datagen.c msg.c parseargs.c test.c streamutil.c lock.c ns.c tcp.c fs.c
+LIBSRC := datagen.c msg.c parseargs.c test.c streamutil.c lock.c ns.c tcp.c fs.c sysctl.c
LIBOBJ := $(LIBSRC:%.c=%.o)
BIN := groups
diff --git a/test/zdtm/lib/sysctl.c b/test/zdtm/lib/sysctl.c
new file mode 100644
index 000000000..9583ec3df
--- /dev/null
+++ b/test/zdtm/lib/sysctl.c
@@ -0,0 +1,59 @@
+#include <fcntl.h>
+
+#include "zdtmtst.h"
+#include "sysctl.h"
+
+int sysctl_read_int(const char *name, int *data)
+{
+ int fd;
+ int ret;
+ char buf[16];
+
+ fd = open(name, O_RDONLY);
+ if (fd < 0) {
+ pr_perror("Can't open %s", name);
+ return fd;
+ }
+
+ ret = read(fd, buf, sizeof(buf) - 1);
+ if (ret < 0) {
+ pr_perror("Can't read %s", name);
+ ret = -errno;
+ goto err;
+ }
+
+ buf[ret] = '\0';
+
+ *data = (int)strtoul(buf, NULL, 10);
+ ret = 0;
+err:
+ close(fd);
+ return ret;
+}
+
+int sysctl_write_int(const char *name, int val)
+{
+ int fd;
+ int ret;
+ char buf[16];
+
+ fd = open(name, O_WRONLY);
+ if (fd < 0) {
+ pr_perror("Can't open %s", name);
+ return fd;
+ }
+
+ sprintf(buf, "%d\n", val);
+
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0) {
+ pr_perror("Can't write %d into %s", val, name);
+ ret = -errno;
+ goto err;
+ }
+
+ ret = 0;
+err:
+ close(fd);
+ return ret;
+}
diff --git a/test/zdtm/lib/sysctl.h b/test/zdtm/lib/sysctl.h
new file mode 100644
index 000000000..67129102f
--- /dev/null
+++ b/test/zdtm/lib/sysctl.h
@@ -0,0 +1,7 @@
+#ifndef __ZDTM_SYSCTL__
+#define __ZDTM_SYSCTL__
+
+extern int sysctl_read_int(const char *name, int *data);
+extern int sysctl_write_int(const char *name, int val);
+
+#endif
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 36d00ca5c..f9d2efe74 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -207,6 +207,7 @@ TST_NOFILE := \
pipe03 \
netns_sub \
netns_sub_veth \
+ netns_sub_sysctl \
unlink_multiple_largefiles \
config_inotify_irmap \
thp_disable \
diff --git a/test/zdtm/static/netns_sub_sysctl.c b/test/zdtm/static/netns_sub_sysctl.c
new file mode 100644
index 000000000..bf828e08e
--- /dev/null
+++ b/test/zdtm/static/netns_sub_sysctl.c
@@ -0,0 +1,56 @@
+#include <sched.h>
+
+#include "zdtmtst.h"
+#include "sysctl.h"
+
+const char *test_doc = "Check dump and restore a net.unix.max_dgram_qlen sysctl parameter in subns";
+const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>";
+
+typedef struct {
+ const char *path;
+ int old;
+ int new;
+} sysctl_opt_t;
+
+#define CONF_UNIX_BASE "/proc/sys/net/unix"
+
+static sysctl_opt_t net_unix_params[] = {
+ {CONF_UNIX_BASE"/max_dgram_qlen", 0, 0},
+ {NULL, 0, 0}
+};
+
+int main(int argc, char **argv)
+{
+ int ret = 0;
+ sysctl_opt_t *p;
+ test_init(argc, argv);
+
+ for (p = net_unix_params; p->path != NULL; p++) {
+ p->old = (((unsigned)lrand48()) % 1023) + 1;
+ if (sysctl_write_int(p->path, p->old)) {
+ pr_perror("Can't change %s", p->path);
+ return -1;
+ }
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ for (p = net_unix_params; p->path != NULL; p++) {
+ if (sysctl_read_int(p->path, &p->new))
+ ret = 1;
+
+ if (p->old != p->new) {
+ errno = EINVAL;
+ pr_perror("%s changed: %d ---> %d", p->path, p->old, p->new);
+ ret = 1;
+ }
+ }
+
+ if (ret)
+ fail();
+ else
+ pass();
+
+ return ret;
+}
diff --git a/test/zdtm/static/netns_sub_sysctl.desc b/test/zdtm/static/netns_sub_sysctl.desc
new file mode 100644
index 000000000..535842668
--- /dev/null
+++ b/test/zdtm/static/netns_sub_sysctl.desc
@@ -0,0 +1,4 @@
+{
+ 'flavor': 'ns',
+ 'flags': 'suid'
+}