summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2005-11-26 13:19:09 +0000
committerdavidxu <davidxu@FreeBSD.org>2005-11-26 13:19:09 +0000
commitb2bbf4f8ad419c2ffb03ec9002da19d0c41239c6 (patch)
treed571708b3aa40cfd2a5e40ce6f5150a3a63e5565
parentb89632601d64859837e0c14001c916ad8c303063 (diff)
downloadFreeBSD-src-b2bbf4f8ad419c2ffb03ec9002da19d0c41239c6.zip
FreeBSD-src-b2bbf4f8ad419c2ffb03ec9002da19d0c41239c6.tar.gz
Add code to test POSIX message queue.
-rw-r--r--tools/regression/mqueue/Makefile5
-rw-r--r--tools/regression/mqueue/mqtest1/Makefile8
-rw-r--r--tools/regression/mqueue/mqtest1/mqtest1.c51
-rw-r--r--tools/regression/mqueue/mqtest2/Makefile8
-rw-r--r--tools/regression/mqueue/mqtest2/mqtest2.c87
-rw-r--r--tools/regression/mqueue/mqtest3/Makefile8
-rw-r--r--tools/regression/mqueue/mqtest3/mqtest3.c103
-rw-r--r--tools/regression/mqueue/mqtest4/Makefile8
-rw-r--r--tools/regression/mqueue/mqtest4/mqtest4.c109
-rw-r--r--tools/regression/mqueue/mqtest5/Makefile8
-rw-r--r--tools/regression/mqueue/mqtest5/mqtest5.c117
11 files changed, 512 insertions, 0 deletions
diff --git a/tools/regression/mqueue/Makefile b/tools/regression/mqueue/Makefile
new file mode 100644
index 0000000..a4f386b
--- /dev/null
+++ b/tools/regression/mqueue/Makefile
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+SUBDIR=mqtest1 mqtest2 mqtest3 mqtest4 mqtest5
+
+.include <bsd.subdir.mk>
diff --git a/tools/regression/mqueue/mqtest1/Makefile b/tools/regression/mqueue/mqtest1/Makefile
new file mode 100644
index 0000000..4180591
--- /dev/null
+++ b/tools/regression/mqueue/mqtest1/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+PROG=mqtest1
+LDADD+=
+NO_MAN=
+DEBUG_FLAGS=-g
+
+.include <bsd.prog.mk>
diff --git a/tools/regression/mqueue/mqtest1/mqtest1.c b/tools/regression/mqueue/mqtest1/mqtest1.c
new file mode 100644
index 0000000..8026230
--- /dev/null
+++ b/tools/regression/mqueue/mqtest1/mqtest1.c
@@ -0,0 +1,51 @@
+/* $FreeBSD$ */
+
+#include <stdio.h>
+#include <mqueue.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+
+#define MQNAME "/mytstqueue1"
+
+int main()
+{
+ struct mq_attr attr, attr2;
+ struct sigevent sigev;
+ int mq;
+ int status;
+
+ attr.mq_maxmsg = 2;
+ attr.mq_msgsize = 100;
+ mq = mq_open(MQNAME, O_CREAT | O_RDWR | O_EXCL, 0666, &attr);
+ if (mq == -1)
+ err(1, "mq_open");
+ status = mq_unlink(MQNAME);
+ if (status)
+ err(1, "mq_unlink");
+ status = mq_getattr(mq, &attr2);
+ if (status)
+ err(1, "mq_getattr");
+ if (attr.mq_maxmsg != attr2.mq_maxmsg)
+ err(1, "mq_maxmsg changed");
+ if (attr.mq_msgsize != attr2.mq_msgsize)
+ err(1, "mq_msgsize changed");
+
+ sigev.sigev_notify = SIGEV_SIGNAL;
+ sigev.sigev_signo = SIGRTMIN;
+ status = mq_notify(mq, &sigev);
+ if (status)
+ err(1, "mq_notify");
+ status = mq_notify(mq, &sigev);
+ if (status == 0)
+ err(1, "mq_notify 2");
+ else if (errno != EBUSY)
+ err(1, "mq_notify 3");
+ status = mq_notify(mq, NULL);
+ if (status)
+ err(1, "mq_notify 4");
+ status = mq_close(mq);
+ if (status)
+ err(1, "mq_close");
+ return (0);
+}
diff --git a/tools/regression/mqueue/mqtest2/Makefile b/tools/regression/mqueue/mqtest2/Makefile
new file mode 100644
index 0000000..c9e52d9
--- /dev/null
+++ b/tools/regression/mqueue/mqtest2/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+PROG=mqtest2
+LDADD+=
+NO_MAN=
+DEBUG_FLAGS=-g
+
+.include <bsd.prog.mk>
diff --git a/tools/regression/mqueue/mqtest2/mqtest2.c b/tools/regression/mqueue/mqtest2/mqtest2.c
new file mode 100644
index 0000000..3ccdc9f
--- /dev/null
+++ b/tools/regression/mqueue/mqtest2/mqtest2.c
@@ -0,0 +1,87 @@
+/* $FreeBSD$ */
+#include <stdio.h>
+#include <mqueue.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+
+#define MQNAME "/mytstqueue2"
+#define LOOPS 1000
+#define PRIO 10
+
+void alarmhandler(int sig)
+{
+ write(1, "timeout\n", 8);
+ _exit(1);
+}
+
+int main()
+{
+ struct mq_attr attr;
+ int mq, status, pid;
+
+ 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 == -1)
+ err(1, "mq_open");
+ status = mq_getattr(mq, &attr);
+ if (status)
+ err(1, "mq_getattr");
+ pid = fork();
+ if (pid == 0) { /* child */
+ int prio, j, i;
+ char *buf;
+
+ mq_close(mq);
+
+ signal(SIGALRM, alarmhandler);
+
+ mq = mq_open(MQNAME, O_RDWR);
+ if (mq == -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, prio;
+
+ 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);
+}
diff --git a/tools/regression/mqueue/mqtest3/Makefile b/tools/regression/mqueue/mqtest3/Makefile
new file mode 100644
index 0000000..f36e9e9
--- /dev/null
+++ b/tools/regression/mqueue/mqtest3/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+PROG=mqtest3
+LDADD+=
+NO_MAN=
+DEBUG_FLAGS=-g
+
+.include <bsd.prog.mk>
diff --git a/tools/regression/mqueue/mqtest3/mqtest3.c b/tools/regression/mqueue/mqtest3/mqtest3.c
new file mode 100644
index 0000000..e9c67fb
--- /dev/null
+++ b/tools/regression/mqueue/mqtest3/mqtest3.c
@@ -0,0 +1,103 @@
+/* $FreeBSD$ */
+#include <stdio.h>
+#include <mqueue.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/select.h>
+
+#define MQNAME "/mytstqueue3"
+#define LOOPS 1000
+#define PRIO 10
+
+void sighandler(int sig)
+{
+ write(1, "timeout\n", 8);
+ _exit(1);
+}
+
+int main()
+{
+ int mq, status;
+ struct mq_attr attr;
+ int pid;
+ fd_set set;
+
+ 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 == -1)
+ err(1, "mq_open()");
+ status = mq_getattr(mq, &attr);
+ if (status)
+ err(1, "mq_getattr()");
+
+ pid = fork();
+ if (pid == 0) { /* child */
+ int prio, j, i;
+ char *buf;
+
+ mq_close(mq);
+
+ signal(SIGALRM, sighandler);
+
+ mq = mq_open(MQNAME, O_RDWR);
+ if (mq == -1)
+ err(1, "child process: mq_open");
+ buf = malloc(attr.mq_msgsize);
+ for (j = 0; j < LOOPS; ++j) {
+ FD_ZERO(&set);
+ FD_SET(mq, &set);
+ alarm(3);
+ status = select(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, prio;
+
+ 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, &set);
+ status = select(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);
+}
diff --git a/tools/regression/mqueue/mqtest4/Makefile b/tools/regression/mqueue/mqtest4/Makefile
new file mode 100644
index 0000000..14c97f6
--- /dev/null
+++ b/tools/regression/mqueue/mqtest4/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+PROG=mqtest4
+LDADD+=
+NO_MAN=
+DEBUG_FLAGS=-g
+
+.include <bsd.prog.mk>
diff --git a/tools/regression/mqueue/mqtest4/mqtest4.c b/tools/regression/mqueue/mqtest4/mqtest4.c
new file mode 100644
index 0000000..8269957
--- /dev/null
+++ b/tools/regression/mqueue/mqtest4/mqtest4.c
@@ -0,0 +1,109 @@
+/* $FreeBSD$ */
+#include <stdio.h>
+#include <mqueue.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/select.h>
+#include <sys/event.h>
+
+#define MQNAME "/mytstqueue4"
+#define LOOPS 1000
+#define PRIO 10
+
+void sighandler(int sig)
+{
+ write(1, "timeout\n", 8);
+ _exit(1);
+}
+
+int main()
+{
+ int mq, status;
+ struct mq_attr attr;
+ int pid;
+ fd_set set;
+ int kq;
+ struct kevent kev;
+
+ 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 == -1)
+ err(1, "mq_open()");
+ status = mq_getattr(mq, &attr);
+ if (status)
+ err(1, "mq_getattr()");
+ pid = fork();
+ if (pid == 0) { /* child */
+ int prio, j, i;
+ char *buf;
+
+ mq_close(mq);
+ kq = kqueue();
+ mq = mq_open(MQNAME, O_RDWR);
+ if (mq == -1)
+ err(1, "child: mq_open");
+ EV_SET(&kev, mq, EVFILT_READ, EV_ADD, 0, 0, 0);
+ status = kevent(kq, &kev, 1, NULL, 0, NULL);
+ if (status == -1)
+ err(1, "child: kevent");
+ buf = malloc(attr.mq_msgsize);
+ for (j = 0; j < LOOPS; ++j) {
+ alarm(3);
+ status = kevent(kq, NULL, 0, &kev, 1, NULL);
+ if (status != 1)
+ err(1, "child: kevent 2");
+ 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, prio;
+
+ signal(SIGALRM, sighandler);
+ kq = kqueue();
+ EV_SET(&kev, mq, EVFILT_WRITE, EV_ADD, 0, 0, 0);
+ status = kevent(kq, &kev, 1, NULL, 0, NULL);
+ if (status == -1)
+ err(1, "kevent");
+ 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 = kevent(kq, NULL, 0, &kev, 1, NULL);
+ if (status != 1)
+ err(1, "child: kevent 2");
+ status = mq_send(mq, buf, attr.mq_msgsize, PRIO);
+ if (status) {
+ err(2, "mq_send()");
+ }
+ }
+ free(buf);
+ alarm(3);
+ wait(&status);
+ alarm(0);
+ }
+ status = mq_close(mq);
+ if (status)
+ err(1, "mq_close");
+ mq_unlink(MQNAME);
+ return (0);
+}
diff --git a/tools/regression/mqueue/mqtest5/Makefile b/tools/regression/mqueue/mqtest5/Makefile
new file mode 100644
index 0000000..b43c415
--- /dev/null
+++ b/tools/regression/mqueue/mqtest5/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+PROG=mqtest5
+LDADD+=
+NO_MAN=
+DEBUG_FLAGS=-g
+
+.include <bsd.prog.mk>
diff --git a/tools/regression/mqueue/mqtest5/mqtest5.c b/tools/regression/mqueue/mqtest5/mqtest5.c
new file mode 100644
index 0000000..2bb2625
--- /dev/null
+++ b/tools/regression/mqueue/mqtest5/mqtest5.c
@@ -0,0 +1,117 @@
+/* $FreeBSD$ */
+#include <stdio.h>
+#include <mqueue.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/select.h>
+#include <sys/event.h>
+#include <signal.h>
+
+#define MQNAME "/mytstqueue5"
+#define LOOPS 1000
+#define PRIO 10
+
+void sighandler(int sig)
+{
+ write(1, "timeout\n", 8);
+ _exit(1);
+}
+
+int main()
+{
+ int mq, status;
+ struct mq_attr attr;
+ int pid;
+ sigset_t set;
+ struct sigaction sa;
+ siginfo_t info;
+
+ mq_unlink(MQNAME);
+
+ sigemptyset(&set);
+ sigaddset(&set, SIGRTMIN);
+ sigprocmask(SIG_BLOCK, &set, NULL);
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_SIGINFO;
+ sa.sa_sigaction = (void *) SIG_DFL;
+ sigaction(SIGRTMIN, &sa, NULL);
+
+ attr.mq_maxmsg = 5;
+ attr.mq_msgsize = 128;
+ mq = mq_open(MQNAME, O_CREAT | O_RDWR | O_EXCL, 0666, &attr);
+ if (mq == -1)
+ err(1, "mq_open()");
+ status = mq_getattr(mq, &attr);
+ if (status)
+ err(1, "mq_getattr()");
+ pid = fork();
+ if (pid == 0) { /* child */
+ int prio, j, i;
+ char *buf;
+ struct sigevent sigev;
+
+ signal(SIGALRM, sighandler);
+
+ sigev.sigev_notify = SIGEV_SIGNAL;
+ sigev.sigev_signo = SIGRTMIN;
+ sigev.sigev_value.sival_int = 2;
+
+ mq_close(mq);
+ mq = mq_open(MQNAME, O_RDWR | O_NONBLOCK);
+ if (mq == -1)
+ err(1, "child: mq_open");
+ buf = malloc(attr.mq_msgsize);
+ for (j = 0; j < LOOPS; ++j) {
+ alarm(3);
+ status = mq_notify(mq, &sigev);
+ if (status)
+ err(1, "child: mq_notify");
+ status = sigwaitinfo(&set, &info);
+ if (status == -1)
+ err(1, "child: sigwaitinfo");
+ if (info.si_value.sival_int != 2)
+ err(1, "child: sival_int");
+ 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, prio;
+
+ 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);
+ 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