Bug 385411 s390x: Tests and internals for z13 vector FP support
[valgrind.git] / none / tests / mq.c
blob8105a8d94252d53e63ee57e1fa64fc6b0e31db7c
1 #include <config.h>
2 #include <errno.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <fcntl.h>
8 #ifdef HAVE_MQUEUE_H
10 #include <mqueue.h>
12 #define MSGMAX 10
13 #define MSGSIZEMAX 1024
15 int main(int argc, char **argv)
17 struct mq_attr mqa;
18 mqd_t mqdw;
19 mqd_t mqdr;
20 char buffer[MSGSIZEMAX];
21 unsigned int priority;
22 int len;
24 mqa.mq_maxmsg = MSGMAX;
25 mqa.mq_msgsize = MSGSIZEMAX;
27 if ((mqdw = mq_open("/valgrind-mqueue", O_CREAT|O_EXCL|O_WRONLY, 0600, &mqa)) < 0)
29 if (errno == ENOSYS)
30 exit(0);
31 perror("mq_open");
32 exit(1);
35 if ((mqdr = mq_open("/valgrind-mqueue", O_RDONLY)) < 0)
37 perror("mq_open");
38 mq_unlink("/valgrind-mqueue");
39 mq_close(mqdw);
40 exit(1);
43 if (mq_unlink("/valgrind-mqueue") < 0)
45 perror("mq_unlink");
46 mq_close(mqdw);
47 mq_close(mqdr);
48 exit(1);
51 if (mq_send(mqdw, "PING", 4, 0) < 0)
53 perror("mq_send");
54 mq_close(mqdr);
55 mq_close(mqdw);
56 exit(1);
59 if ((len = mq_receive(mqdr, buffer, sizeof(buffer), &priority)) < 0)
61 perror("mq_receive");
62 mq_close(mqdr);
63 mq_close(mqdw);
64 exit(1);
67 #if !defined(VGO_solaris)
68 /* On Solaris, there is no existing notification registration. */
69 if (mq_notify(mqdr, NULL) < 0)
71 perror("mq_notify");
72 mq_close(mqdr);
73 mq_close(mqdw);
74 exit(1);
76 #endif /* !VGO_solaris */
78 if (len != 4 || memcmp(buffer, "PING", 4) != 0)
80 fprintf(stderr, "Message corrupt!");
83 if (mq_getattr(mqdr, &mqa) < 0)
85 perror("mq_getattr");
86 mq_close(mqdr);
87 mq_close(mqdw);
88 exit(1);
91 if (mq_setattr(mqdw, &mqa, &mqa) < 0)
93 perror("mq_setattr");
94 mq_close(mqdr);
95 mq_close(mqdw);
96 exit(1);
99 if (mq_close(mqdr) < 0)
101 perror("mq_close");
102 mq_close(mqdw);
103 exit(1);
106 if (mq_close(mqdw) < 0)
108 perror("mq_close");
109 exit(1);
112 exit(0);
115 #else
117 int main(int argc, char **argv)
119 exit(0);
122 #endif