Commit a0e7d4fd authored by Kinsbursky Stanislav's avatar Kinsbursky Stanislav Committed by Andrey Vagin

zdtm: static/msgque test update

v2: msgque test removed from zdtm.sh (feature is not supported yet)

1) Added namesapce isolation
2) Added non-empty queue state before migration
3) Added one more backward message send (child send message back
after receiving one from parent).
Signed-off-by: 's avatarStanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: 's avatarAndrey Vagin <avagin@gmail.com>
parent d131bdfc
...@@ -147,6 +147,7 @@ unlink_largefile: override CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURC ...@@ -147,6 +147,7 @@ unlink_largefile: override CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURC
inotify_system_nodel: override CFLAGS += -DNODEL inotify_system_nodel: override CFLAGS += -DNODEL
pthread00: override LDLIBS += -pthread pthread00: override LDLIBS += -pthread
shm: override CFLAGS += -DNEW_IPC_NS shm: override CFLAGS += -DNEW_IPC_NS
msgque: override CFLAGS += -DNEW_IPC_NS
$(LIB): force $(LIB): force
$(MAKE) -C $(LIBDIR) $(MAKE) -C $(LIBDIR)
......
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -13,23 +16,25 @@ ...@@ -13,23 +16,25 @@
#include "zdtmtst.h" #include "zdtmtst.h"
const char *test_doc="Tests sysv5 msg queues supporting by checkpointing"; const char *test_doc="Tests sysv5 msg queues supporting by checkpointing";
const char *test_author="Pavel Emelianov <xemul@parallels.com>"; const char *test_author="Stanislav Kinsbursky <skinsbursky@openvz.org>";
struct msg1 { struct msg1 {
long mtype; long mtype;
char mtext[20]; char mtext[20];
}; };
#define TEST_STRING "Test sysv5 msg" #define TEST_STRING "Test sysv5 msg"
#define MSG_TYPE 1
int main(int argc, char **argv) #define ANOTHER_TEST_STRING "Yet another test sysv5 msg"
#define ANOTHER_MSG_TYPE 26538
static int test_fn(int argc, char **argv)
{ {
key_t key; key_t key;
int msg, pid; int msg, pid;
struct msg1 msgbuf; struct msg1 msgbuf;
int chret; int chret;
test_init(argc, argv);
key = ftok(argv[0], 822155650); key = ftok(argv[0], 822155650);
if (key == -1) { if (key == -1) {
err("Can't make key"); err("Can't make key");
...@@ -47,53 +52,89 @@ int main(int argc, char **argv) ...@@ -47,53 +52,89 @@ int main(int argc, char **argv)
msg = msgget(key, 0666); msg = msgget(key, 0666);
if (msg == -1) { if (msg == -1) {
err("Can't get queue"); err("Can't get queue");
if (pid) { goto err_kill;
kill(pid, SIGKILL);
wait(NULL);
}
exit(1);
} }
} }
if (pid == 0) { if (pid == 0) {
if (msgrcv(msg, &msgbuf, sizeof(TEST_STRING), 1, 0) == -1) { test_waitsig();
chret = errno;
fail("msgrcv failed %d(%m)", errno); if (msgrcv(msg, &msgbuf, sizeof(TEST_STRING), MSG_TYPE, 0) == -1) {
return chret; fail("Child: msgrcv failed (%m)");
return -errno;
} }
if (strncmp(TEST_STRING, msgbuf.mtext, sizeof(TEST_STRING))) { if (strncmp(TEST_STRING, msgbuf.mtext, sizeof(TEST_STRING))) {
fail("The source and received strings aren't equal"); fail("Child: the source and received strings aren't equal");
return 1; return -errno;
} }
test_msg("Recived %s\n", msgbuf.mtext); test_msg("Child: received %s\n", msgbuf.mtext);
msgbuf.mtype = ANOTHER_MSG_TYPE;
memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING));
if (msgsnd(msg, &msgbuf, sizeof(ANOTHER_TEST_STRING), 0) != 0) {
fail("Child: msgsnd failed (%m)");
return -errno;
};
pass(); pass();
goto out; return 0;
} else { } else {
msgbuf.mtype = MSG_TYPE;
memcpy(msgbuf.mtext, TEST_STRING, sizeof(TEST_STRING));
if (msgsnd(msg, &msgbuf, sizeof(TEST_STRING), 0) != 0) {
fail("Parent: msgsnd failed (%m)");
goto err_kill;
};
test_daemon(); test_daemon();
test_waitsig(); test_waitsig();
msgbuf.mtype = 1; kill(pid, SIGTERM);
memcpy(msgbuf.mtext, TEST_STRING, sizeof(TEST_STRING));
if (msgsnd(msg, &msgbuf, sizeof(TEST_STRING), 0) != 0) {
fail("msgsnd failed %d(%m)", errno);
kill(pid, SIGKILL);
wait(NULL);
return 1;
};
wait(&chret); wait(&chret);
chret = WEXITSTATUS(chret); chret = WEXITSTATUS(chret);
if (chret) { if (chret) {
fail("child exited with non-zero code %d (%s)\n", fail("Parent: child exited with non-zero code %d (%s)\n",
chret, strerror(chret)); chret, strerror(chret));
return 1; goto out;
} }
pass();
if (msgrcv(msg, &msgbuf, sizeof(ANOTHER_TEST_STRING), ANOTHER_MSG_TYPE, 0) == -1) {
fail("Parent: msgrcv failed (%m)");
goto err;
} }
msgctl(msg, IPC_RMID, 0); if (strncmp(ANOTHER_TEST_STRING, msgbuf.mtext, sizeof(ANOTHER_TEST_STRING))) {
fail("Parent: the source and received strings aren't equal");
goto err;
}
test_msg("Parent: received %s\n", msgbuf.mtext);
pass();
}
out: out:
if (msgctl(msg, IPC_RMID, 0)) {
fail("Failed to destroy message queue: %d\n", -errno);
return -errno;
}
return chret;
err_kill:
kill(pid, SIGKILL);
wait(NULL);
err:
chret = -errno;
goto out;
}
int main(int argc, char **argv)
{
#ifdef NEW_IPC_NS
test_init_ns(argc, argv, CLONE_NEWIPC, test_fn);
#else
test_init(argc, argv);
test_fn();
#endif
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment