[CRIU] [PATCH cr 1/8] zdtm: change a daemonize procudure for
namespace test cases
Andrey Vagin
avagin at openvz.org
Wed May 16 04:32:34 EDT 2012
The previous one sends signal from test to a controlling process.
It's impossible, if a test process is executed in a separate pid ns.
The new mechanism uses pipe for communication.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
test/zdtm/lib/test.c | 49 ++++++++++++++++++++++++++++-----
test/zdtm/lib/zdtmtst.h | 4 +++
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/ipc_namespace.c | 2 +-
test/zdtm/live/static/msgque.c | 3 +-
test/zdtm/live/static/sem.c | 2 +-
test/zdtm/live/static/shm.c | 2 +-
test/zdtm/live/static/utsname.c | 2 +-
test/zdtm/live/transition/ipc.c | 4 ++-
9 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/test/zdtm/lib/test.c b/test/zdtm/lib/test.c
index 742b325..912f9aa 100644
--- a/test/zdtm/lib/test.c
+++ b/test/zdtm/lib/test.c
@@ -14,6 +14,7 @@
#include "zdtmtst.h"
static volatile sig_atomic_t sig_received = 0;
+static int test_namespace = 0;
static void sig_hand(int signo)
{
@@ -207,6 +208,17 @@ static int do_test_fn(void *_arg)
exit(0);
}
+static int signal_pipe = -1;
+void test_ns_daemon()
+{
+
+ if (!test_namespace) {
+ err("It could be called only for name space test cases");
+ exit(1);
+ }
+ close(signal_pipe);
+}
+
void test_init_ns(int argc, char **argv, unsigned long clone_flags,
int (*fn)(int , char **))
{
@@ -220,6 +232,10 @@ void test_init_ns(int argc, char **argv, unsigned long clone_flags,
};
struct zdtm_clone_arg ca;
void *stack;
+ int p[2], ret, status;
+ char c;
+
+ test_namespace = 1;
sigemptyset(&sa.sa_mask);
@@ -251,6 +267,13 @@ void test_init_ns(int argc, char **argv, unsigned long clone_flags,
exit(1);
}
+ ret = pipe(p);
+ if (ret == -1) {
+ err("Can't create signal pipe");
+ exit(1);
+ }
+ signal_pipe = p[1];
+
ca.pidf = pidf;
ca.fn = fn;
ca.argc = argc;
@@ -260,21 +283,28 @@ void test_init_ns(int argc, char **argv, unsigned long clone_flags,
err("Daemonizing failed: %m\n");
exit(1);
}
+ close(signal_pipe);
- /* parent will exit when the child is ready */
- test_waitsig();
+ ret = read(p[0], &c, 1);
+ if (ret == -1) {
+ err("read(signal_pipe) failed");
+ exit(1);
+ }
- if (sig_received == SIGCHLD) {
- int ret;
- waitpid(pid, &ret, 0);
+ ret = waitpid(pid, &status, WNOHANG);
+ if (ret == -1) {
+ err("waitpid(%d) failed", pid);
+ exit(1);
+ }
+ if (ret != 0) {
if (WIFEXITED(ret)) {
err("Test exited with unexpectedly with code %d\n", WEXITSTATUS(ret));
- exit(0);
+ exit(1);
}
if (WIFSIGNALED(ret)) {
err("Test exited on unexpected signal %d\n", WTERMSIG(ret));
- exit(0);
+ exit(1);
}
}
@@ -287,6 +317,11 @@ void test_daemon()
{
pid_t ppid;
+ if (test_namespace) {
+ err("It could not be called for namespace test cases");
+ exit(1);
+ }
+
ppid = getppid();
if (ppid <= 1) {
err("Test orphaned\n");
diff --git a/test/zdtm/lib/zdtmtst.h b/test/zdtm/lib/zdtmtst.h
index 1873f63..914499c 100644
--- a/test/zdtm/lib/zdtmtst.h
+++ b/test/zdtm/lib/zdtmtst.h
@@ -8,6 +8,10 @@ extern int test_write_pidfile(pid_t pid);
extern void test_init(int argc, char **argv);
extern void test_init_ns(int argc, char **argv, unsigned long clone_flags, int (*fn)(int , char **));
+/* This function should be called for each child,
+ * if it isn't called befor test_fork */
+extern void test_ns_daemon(void);
+
#ifndef CLONE_NEWUTS
#define CLONE_NEWUTS 0x04000000
#endif
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index bd0a094..9897279 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -37,6 +37,7 @@ TST_NOFILE = \
sockets00 \
socket_queues \
ipc_namespace \
+ pid_namespace \
selfexe00 \
sem \
maps01 \
diff --git a/test/zdtm/live/static/ipc_namespace.c b/test/zdtm/live/static/ipc_namespace.c
index 6183c47..b9153d8 100644
--- a/test/zdtm/live/static/ipc_namespace.c
+++ b/test/zdtm/live/static/ipc_namespace.c
@@ -343,7 +343,7 @@ static int test_fn(int argc, char **argv)
return ret;
}
- test_daemon();
+ test_ns_daemon();
test_waitsig();
ret = fill_ipc_ns(&ipc_after);
diff --git a/test/zdtm/live/static/msgque.c b/test/zdtm/live/static/msgque.c
index bb63093..0ff0478 100644
--- a/test/zdtm/live/static/msgque.c
+++ b/test/zdtm/live/static/msgque.c
@@ -57,6 +57,7 @@ static int test_fn(int argc, char **argv)
}
if (pid == 0) {
+ test_ns_daemon();
test_waitsig();
if (msgrcv(msg, &msgbuf, sizeof(TEST_STRING), MSG_TYPE, IPC_NOWAIT) == -1) {
@@ -93,7 +94,7 @@ static int test_fn(int argc, char **argv)
return -errno;
};
- test_daemon();
+ test_ns_daemon();
test_waitsig();
kill(pid, SIGTERM);
diff --git a/test/zdtm/live/static/sem.c b/test/zdtm/live/static/sem.c
index fae91a2..b198ade 100644
--- a/test/zdtm/live/static/sem.c
+++ b/test/zdtm/live/static/sem.c
@@ -130,7 +130,7 @@ static int test_fn(int argc, char **argv)
goto out_destroy;
}
- test_daemon();
+ test_ns_daemon();
test_waitsig();
ret = check_sem_by_id(id, val);
diff --git a/test/zdtm/live/static/shm.c b/test/zdtm/live/static/shm.c
index b29da4a..d8722e2 100644
--- a/test/zdtm/live/static/shm.c
+++ b/test/zdtm/live/static/shm.c
@@ -119,7 +119,7 @@ static int test_fn(int argc, char **argv)
goto out;
}
- test_daemon();
+ test_ns_daemon();
test_waitsig();
ret = check_shm_id(shm, shmem_size);
diff --git a/test/zdtm/live/static/utsname.c b/test/zdtm/live/static/utsname.c
index 934b6b4..1689cb0 100644
--- a/test/zdtm/live/static/utsname.c
+++ b/test/zdtm/live/static/utsname.c
@@ -46,7 +46,7 @@ static int test_fn(int argc, char **argv)
close(fd);
- test_daemon();
+ test_ns_daemon();
test_waitsig();
uname(&after);
diff --git a/test/zdtm/live/transition/ipc.c b/test/zdtm/live/transition/ipc.c
index 5910f13..b9d9327 100644
--- a/test/zdtm/live/transition/ipc.c
+++ b/test/zdtm/live/transition/ipc.c
@@ -58,6 +58,8 @@ static int child(key_t key)
if (mem == (uint8_t *)-1)
return -3;
+ test_ns_daemon();
+
while (test_go()) {
ret = semop(sem, &lock, 1);
if (ret) {
@@ -138,7 +140,7 @@ static int test_fn(int argc, char **argv)
} else if (pid2 == 0)
exit(child(key));
- test_daemon();
+ test_ns_daemon();
while (test_go()) {
ret = semop(sem, &lock, 1);
if (ret) {
--
1.7.1
More information about the CRIU
mailing list