diff options
author | ngie <ngie@FreeBSD.org> | 2015-05-13 12:09:01 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2015-05-13 12:09:01 +0000 |
commit | 3a757c0c1f3f1d07c1bcfba87100164c348efa06 (patch) | |
tree | 649264e89fc6043121d3a1bf5c0ec4ecd4b55079 /tests/sys/mqueue/mqtest2.c | |
parent | db9d37a97890cb058f3b4016f3ed97da1d6cb728 (diff) | |
download | FreeBSD-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/mqtest2.c')
-rw-r--r-- | tests/sys/mqueue/mqtest2.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/sys/mqueue/mqtest2.c b/tests/sys/mqueue/mqtest2.c new file mode 100644 index 0000000..067e619 --- /dev/null +++ b/tests/sys/mqueue/mqtest2.c @@ -0,0 +1,101 @@ +/* $FreeBSD$ */ + +#include <sys/types.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 "/mytstqueue2" +#define LOOPS 1000 +#define PRIO 10 + +static void +alarmhandler(int sig __unused) +{ + write(1, "timeout\n", 8); + _exit(1); +} + +int +main(void) +{ + struct mq_attr attr; + mqd_t mq; + int status; + 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, alarmhandler); + + mq = mq_open(MQNAME, O_RDWR); + if (mq == (mqd_t)-1) + err(1, "child: mq_open"); + buf = malloc(attr.mq_msgsize); + for (j = 0; j < LOOPS; ++j) { + alarm(3); + status = mq_receive(mq, buf, attr.mq_msgsize, &prio); + if (status == -1) + err(2, "child: mq_receive"); + for (i = 0; i < attr.mq_msgsize; ++i) + if (buf[i] != i) + err(3, "child: message data corrupted"); + if (prio != PRIO) + err(4, "child: 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, alarmhandler); + buf = malloc(attr.mq_msgsize); + for (j = 0; j < LOOPS; ++j) { + for (i = 0; i < attr.mq_msgsize; ++i) + buf[i] = i; + alarm(3); + status = mq_send(mq, buf, attr.mq_msgsize, PRIO); + if (status) + err(1, "mq_send"); + } + alarm(3); + wait(&status); + alarm(0); + } + status = mq_close(mq); + if (status) + err(1, "mq_close"); + mq_unlink(MQNAME); + return (0); +} |