aboutsummaryrefslogtreecommitdiff
path: root/src/check
diff options
context:
space:
mode:
authortoni <matzeton@googlemail.com>2016-01-04 11:23:09 +0100
committertoni <matzeton@googlemail.com>2016-01-04 11:23:09 +0100
commitac09bf8f4d1b4e71828199772a76538931a6c72d (patch)
tree3de2a03cc87e218065e7795d76bd4a23d3404c06 /src/check
parent70268fa85ea048fdd26aff38b83466b73048d46a (diff)
added ipc check binary
Diffstat (limited to 'src/check')
-rw-r--r--src/check/check.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/check/check.c b/src/check/check.c
new file mode 100644
index 0000000..bbc22eb
--- /dev/null
+++ b/src/check/check.c
@@ -0,0 +1,55 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <mqueue.h>
+
+#define myassert(x) if ((x)) { ret &= 0xFF; } else { ret &= 0x00; }
+
+static volatile unsigned char ret = 0xFF;
+static mqd_t mq_test;
+static mqd_t mq_recv;
+static const size_t bufsiz = 256;
+
+int main(int argc, char **argv)
+{
+ int c_stat;
+ struct mq_attr m_attr;
+ char buf[bufsiz], recv[bufsiz];
+ unsigned int prio;
+ ssize_t sz_recv;
+
+ memset(buf, '\0', bufsiz);
+ memset(recv, '\0', bufsiz);
+ if (argc > 1)
+ strncpy(buf, argv[1], bufsiz-1);
+
+ m_attr.mq_flags = 0;
+ m_attr.mq_msgsize = bufsiz;
+ m_attr.mq_maxmsg = 10;
+ m_attr.mq_curmsgs = 0;
+
+ mq_unlink("/testmq");
+ myassert( (mq_test = mq_open( "/testmq", O_NONBLOCK | O_CREAT | O_EXCL | O_RDWR, S_IRWXU | S_IRWXG, &m_attr )) != (mqd_t)-1 );
+ myassert( mq_getattr(mq_test, &m_attr) == 0 );
+
+ strcpy(buf, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVQXYZ");
+ myassert( mq_send(mq_test, buf, bufsiz, 0) == 0 );
+ myassert( (sz_recv = mq_receive(mq_test, recv, bufsiz, &prio)) > 0 );
+
+ memset(recv, '\0', bufsiz);
+ if (fork() > 0) {
+ myassert( (mq_recv = mq_open( "/testmq", O_RDONLY, S_IRWXU | S_IRWXG, &m_attr )) != (mqd_t)-1 );
+ myassert( (sz_recv = mq_receive(mq_recv, recv, bufsiz, &prio)) > 0 );
+ return ret;
+ }
+ myassert( mq_send(mq_test, buf, bufsiz, 0) == 0 );
+ wait(&c_stat);
+ myassert( c_stat == 0xFF );
+ myassert( mq_close(mq_test) == 0 );
+ myassert( mq_unlink("/testmq") == 0 );
+
+ return ~ret;
+}