[CRIU] [PATCH 10/12] zdtm: Add file owners test on pipes
Cyrill Gorcunov
gorcunov at openvz.org
Sun Mar 25 17:33:56 EDT 2012
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
test/zdtm.sh | 1 +
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/file_fown.c | 95 +++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 0 deletions(-)
create mode 100644 test/zdtm/live/static/file_fown.c
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 2c35100..180c0e4 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -34,6 +34,7 @@ static/cmdlinenv00
static/socket_listen
static/socket_udp
static/selfexe00
+static/file_fown
"
UTS_TEST_LIST="
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index c75b038..cc5a8ec 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -37,6 +37,7 @@ TST_NOFILE = \
selfexe00 \
sem \
maps01 \
+ file_fown \
# jobctl00 \
TST_FILE = \
diff --git a/test/zdtm/live/static/file_fown.c b/test/zdtm/live/static/file_fown.c
new file mode 100644
index 0000000..fffaee9
--- /dev/null
+++ b/test/zdtm/live/static/file_fown.c
@@ -0,0 +1,95 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <utime.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+
+#include "zdtmtst.h"
+
+#ifndef F_SETSIG
+#define F_SETSIG 10 /* for sockets. */
+#define F_GETSIG 11 /* for sockets. */
+#endif
+
+const char *test_doc = "Check for signal delivery for file owners";
+const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+static int received_io;
+
+static void signal_handler_io(int status)
+{
+ received_io++;
+}
+
+int main(int argc, char ** argv)
+{
+ struct sigaction saio;
+ int pipes[2];
+ int own_befor[2], sig_befor[2];
+ int own_after[2], sig_after[2];
+ int v = 1;
+
+ test_init(argc, argv);
+
+ if (pipe(pipes)) {
+ err("Can't create pipes: %m\n");
+ exit(1);
+ }
+
+ memset(&saio, 0, sizeof(saio));
+ saio.sa_handler = (sig_t)signal_handler_io;
+ sigaction(SIGIO, &saio, 0);
+
+ fcntl(pipes[0], F_SETOWN, getpid());
+ fcntl(pipes[1], F_SETOWN, getpid());
+
+ own_befor[0] = fcntl(pipes[0], F_GETOWN);
+ own_befor[1] = fcntl(pipes[1], F_GETOWN);
+ test_msg("befor: owner %d %d\n", own_befor[0], own_befor[1]);
+
+ fcntl(pipes[0], F_SETSIG, SIGIO);
+ fcntl(pipes[1], F_SETSIG, SIGIO);
+
+ sig_befor[0] = fcntl(pipes[0], F_GETSIG);
+ sig_befor[1] = fcntl(pipes[1], F_GETSIG);
+ test_msg("befor: siganls %d %d\n", sig_befor[0], sig_befor[1]);
+
+ fcntl(pipes[0], F_SETFL, fcntl(pipes[0], F_GETFL) | O_NONBLOCK | O_ASYNC);
+ fcntl(pipes[1], F_SETFL, fcntl(pipes[1], F_GETFL) | O_NONBLOCK | O_ASYNC);
+
+ write(pipes[1], &v, sizeof(v));
+ read(pipes[0], &v, sizeof(v));
+
+ write(pipes[1], &v, sizeof(v));
+ read(pipes[0], &v, sizeof(v));
+
+ test_daemon();
+ test_waitsig();
+
+ own_after[0] = fcntl(pipes[0], F_GETOWN);
+ own_after[1] = fcntl(pipes[1], F_GETOWN);
+ test_msg("after: owner %d %d\n", own_after[0], own_after[1]);
+
+ fcntl(pipes[0], F_SETSIG, SIGIO);
+ fcntl(pipes[1], F_SETSIG, SIGIO);
+
+ sig_after[0] = fcntl(pipes[0], F_GETSIG);
+ sig_after[1] = fcntl(pipes[1], F_GETSIG);
+ test_msg("after: siganls %d %d\n", sig_after[0], sig_after[1]);
+
+ if (received_io < 1 ||
+ memcmp(own_befor, own_after, sizeof(own_befor)) ||
+ memcmp(sig_befor, sig_after, sizeof(own_befor))) {
+ fail();
+ exit(1);
+ }
+
+ pass();
+ return 0;
+}
--
1.7.7.6
More information about the CRIU
mailing list