summaryrefslogtreecommitdiffstats
path: root/tests/sys/mqueue/mqtest3.c
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2015-05-13 12:09:01 +0000
committerngie <ngie@FreeBSD.org>2015-05-13 12:09:01 +0000
commit3a757c0c1f3f1d07c1bcfba87100164c348efa06 (patch)
tree649264e89fc6043121d3a1bf5c0ec4ecd4b55079 /tests/sys/mqueue/mqtest3.c
parentdb9d37a97890cb058f3b4016f3ed97da1d6cb728 (diff)
downloadFreeBSD-src-3a757c0c1f3f1d07c1bcfba87100164c348efa06.zip
FreeBSD-src-3a757c0c1f3f1d07c1bcfba87100164c348efa06.tar.gz
MFC r281593,r282071,r282074,r282133,r282134,r282135,r282136,r282137,r282138:
r282071: Integrate tools/regression/mqueue into the FreeBSD test suite as tests/sys/mqueue r282074: Integrate tools/regression/aio/aiotest and tools/regression/aio/kqueue into the FreeBSD test suite as tests/sys/aio r282133: Fill in the copyright boilerplate for the test program r282134: Add initial (unpolished) macros for interfacing with the FreeBSD test suite This is very rough, but will be replaced/redesigned some time soon after I fix the Jenkins breakage I introduced r282135: Use ATF_REQUIRE_KERNEL_MODULE instead of aio_available function r282136: - Use ATF_REQUIRE_KERNEL_MDOULE to require aio(4) - Don't use /tmp as a basis for temporary files as it's outside of the ATF sandbox - Don't override MAX macro in sys/param.h r282137: Use PLAIN_REQUIRE_KERNEL_MODULE to require "mqueuefs" r282138: Adjust CFLAGS to find freebsd_test_suite/macros.h
Diffstat (limited to 'tests/sys/mqueue/mqtest3.c')
-rw-r--r--tests/sys/mqueue/mqtest3.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/tests/sys/mqueue/mqtest3.c b/tests/sys/mqueue/mqtest3.c
new file mode 100644
index 0000000..c4b849e
--- /dev/null
+++ b/tests/sys/mqueue/mqtest3.c
@@ -0,0 +1,116 @@
+/* $FreeBSD$ */
+
+#include <sys/types.h>
+#include <sys/select.h>
+#include <sys/wait.h>
+#include <err.h>
+#include <fcntl.h>
+#include <mqueue.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "freebsd_test_suite/macros.h"
+
+#define MQNAME "/mytstqueue3"
+#define LOOPS 1000
+#define PRIO 10
+
+static void
+sighandler(int sig __unused)
+{
+ write(1, "timeout\n", 8);
+ _exit(1);
+}
+
+int
+main(void)
+{
+ fd_set set;
+ struct mq_attr attr;
+ int status;
+ mqd_t mq;
+ pid_t pid;
+
+ PLAIN_REQUIRE_KERNEL_MODULE("mqueuefs", 0);
+
+ mq_unlink(MQNAME);
+
+ attr.mq_maxmsg = 5;
+ attr.mq_msgsize = 128;
+ mq = mq_open(MQNAME, O_CREAT | O_RDWR | O_EXCL, 0666, &attr);
+ if (mq == (mqd_t)-1)
+ err(1, "mq_open()");
+ status = mq_getattr(mq, &attr);
+ if (status)
+ err(1, "mq_getattr()");
+
+ pid = fork();
+ if (pid == 0) { /* child */
+ char *buf;
+ int j, i;
+ unsigned int prio;
+
+ mq_close(mq);
+
+ signal(SIGALRM, sighandler);
+
+ mq = mq_open(MQNAME, O_RDWR);
+ if (mq == (mqd_t)-1)
+ err(1, "child process: mq_open");
+ buf = malloc(attr.mq_msgsize);
+ for (j = 0; j < LOOPS; ++j) {
+ FD_ZERO(&set);
+ FD_SET(__mq_oshandle(mq), &set);
+ alarm(3);
+ status = select(__mq_oshandle(mq)+1, &set, NULL, NULL, NULL);
+ if (status != 1)
+ err(1, "child process: select()");
+ status = mq_receive(mq, buf, attr.mq_msgsize, &prio);
+ if (status == -1)
+ err(2, "child process: mq_receive");
+ for (i = 0; i < attr.mq_msgsize; ++i)
+ if (buf[i] != i)
+ err(3, "message data corrupted");
+ if (prio != PRIO)
+ err(4, "priority is incorrect: %d", prio);
+ }
+ alarm(0);
+ free(buf);
+ mq_close(mq);
+ return (0);
+ } else if (pid == -1) {
+ err(1, "fork()");
+ } else {
+ char *buf;
+ int i, j;
+
+ signal(SIGALRM, sighandler);
+ buf = malloc(attr.mq_msgsize);
+ for (j = 0; j < LOOPS; ++j) {
+ for (i = 0; i < attr.mq_msgsize; ++i) {
+ buf[i] = i;
+ }
+ alarm(3);
+ FD_ZERO(&set);
+ FD_SET(__mq_oshandle(mq), &set);
+ status = select(__mq_oshandle(mq)+1, NULL, &set, NULL, NULL);
+ if (status != 1)
+ err(1, "select()");
+ status = mq_send(mq, buf, attr.mq_msgsize, PRIO);
+ if (status) {
+ kill(pid, SIGKILL);
+ err(2, "mq_send()");
+ }
+ }
+ alarm(3);
+ wait(&status);
+ alarm(0);
+ }
+ status = mq_close(mq);
+ if (status)
+ err(1, "mq_close");
+ mq_unlink(MQNAME);
+ return (0);
+}
OpenPOWER on IntegriCloud