[CRIU] [PATCH 01/14] zdtm: add a test case for pending signals

Andrey Vagin avagin at openvz.org
Thu Jan 17 09:38:25 EST 2013


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/Makefile     |   2 +
 test/zdtm/live/static/sigpending.c | 120 +++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+)
 create mode 100644 test/zdtm/live/static/sigpending.c

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 8a67dd2..70bd094 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -85,6 +85,7 @@ TST_NOFILE	=				\
 		cow00				\
 		child_opened_proc		\
 		posix_timers			\
+		sigpending			\
 #		jobctl00			\
 
 TST_FILE	=				\
@@ -219,6 +220,7 @@ posix_timers:		override LDLIBS += -lrt
 socket-tcp6: override CFLAGS += -D ZDTM_IPV6
 socket-tcpbuf6: override CFLAGS += -D ZDTM_IPV6
 socket_listen6: override CFLAGS += -D ZDTM_IPV6
+sigpending:		override LDLIBS += -lrt
 
 $(LIB):	force
 	$(MAKE) -C $(LIBDIR)
diff --git a/test/zdtm/live/static/sigpending.c b/test/zdtm/live/static/sigpending.c
new file mode 100644
index 0000000..35e3856
--- /dev/null
+++ b/test/zdtm/live/static/sigpending.c
@@ -0,0 +1,120 @@
+#define _GNU_SOURCE 
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include "zdtmtst.h"
+
+const char *test_doc    = "Check pending signals";
+const char *test_author = "Andrew Vagin <avagin at parallels.com>";
+
+static pid_t child;
+static int numsig;
+
+#define TESTSIG (SIGRTMAX)
+static siginfo_t siginfo[2];
+static int siginfo_nr;
+
+#ifndef offsetof
+# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+static void sig_handler(int signal, siginfo_t *info, void *data)
+{
+        uint32_t crc;
+
+        test_msg("signo=%d si_code=%x\n", signal, info->si_code);
+
+        switch (signal) {
+        case SIGCHLD:
+                if ((info->si_code & CLD_EXITED) &&
+                    (info->si_pid == child) &&
+                    (info->si_status == 5))
+                        numsig++;
+                else {
+                        fail("Wrong siginfo");
+                        exit(1);
+                }
+                return;
+        }
+
+        if (TESTSIG == signal) {
+                crc = ~0;
+                if (datachk((uint8_t *) &siginfo[siginfo_nr].si_code,
+                            sizeof(siginfo_t) - offsetof(siginfo_t, si_code), &crc)) {
+                        fail("CRC mismatch\n");
+                        exit(1);
+                }
+
+                siginfo_nr++;
+                numsig++;
+                return;
+        }
+
+        err("Unexpected signal");
+        exit(1);
+}
+
+int main(int argc, char ** argv)
+{
+        sigset_t blockmask;
+        struct sigaction act;
+        uint32_t crc;
+        int i;
+
+        test_init(argc, argv);
+
+        sigfillset(&blockmask);
+        sigdelset(&blockmask, SIGTERM);
+
+        if (sigprocmask(SIG_BLOCK, &blockmask, NULL) == -1) {
+                err("sigprocmask");
+                return -1;
+        }
+
+        child = fork();
+        if (child == -1) {
+                err("fork");
+                return -1;
+        } else if(child == 0) {
+                return 5;
+        }
+
+        for (i = 0; i < 2; i++) {
+                crc = ~0;
+                siginfo[i].si_code = -12;
+                datagen((uint8_t *) &siginfo[i].si_code,
+                            sizeof(siginfo_t) - offsetof(siginfo_t, si_code), &crc);
+                syscall(SYS_rt_sigqueueinfo, getpid(), TESTSIG, &siginfo[i]);
+        }
+
+        act.sa_flags = SA_SIGINFO | SA_RESTART;
+        act.sa_sigaction = sig_handler;
+        sigemptyset(&act.sa_mask);
+
+        if (sigaction(SIGCHLD, &act, NULL)) {
+                err("sigaction() failed\n");
+                return -1;
+        }
+
+        sigaddset(&act.sa_mask, TESTSIG);
+        if (sigaction(TESTSIG, &act, NULL)) {
+                err("sigaction() failed\n");
+                return -1;
+        }
+
+        test_daemon();
+
+        test_waitsig();
+
+        if (sigprocmask(SIG_UNBLOCK, &blockmask, NULL) == -1) {
+                err("sigprocmask");
+                return -1;
+        }
+
+        if (numsig == 3)
+                pass();
+
+        return 0;
+}
+
-- 
1.7.11.7



More information about the CRIU mailing list