1 /* $NetBSD: mq_prio_test.c,v 1.1 2009/07/13 02:55:42 rmind Exp $ */
4 * Test for POSIX message queue priority handling.
6 * This file is in the Public Domain.
16 #define MQUEUE "/mq_prio_test"
17 #define MQ_PRIO_BOUNDARY 31
27 if (mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BOUNDARY
) == -1)
28 err(EXIT_FAILURE
, "mq_send 1");
31 if (mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BOUNDARY
+ 1) == -1)
32 err(EXIT_FAILURE
, "mq_send 2");
35 if (mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BOUNDARY
) == -1)
36 err(EXIT_FAILURE
, "mq_send 3");
39 if (mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BOUNDARY
- 1) == -1)
40 err(EXIT_FAILURE
, "mq_send 4");
43 if (mq_send(mqfd
, msg
, sizeof(msg
), 0) == -1)
44 err(EXIT_FAILURE
, "mq_send 5");
47 if (mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BOUNDARY
+ 1) == -1)
48 err(EXIT_FAILURE
, "mq_send 6");
52 receive_msgs(mqd_t mqfd
)
59 if (mq_getattr(mqfd
, &mqa
) == -1) {
60 err(EXIT_FAILURE
, "mq_getattr");
65 err(EXIT_FAILURE
, "calloc");
68 if (mq_receive(mqfd
, m
, len
, &p
) == -1) {
69 err(EXIT_FAILURE
, "mq_receive 1");
71 assert(p
== (MQ_PRIO_BOUNDARY
+ 1) && m
[0] == 'b');
73 if (mq_receive(mqfd
, m
, len
, &p
) == -1) {
74 err(EXIT_FAILURE
, "mq_receive 2");
76 assert(p
== (MQ_PRIO_BOUNDARY
+ 1) && m
[0] == 'f');
78 if (mq_receive(mqfd
, m
, len
, &p
) == -1) {
79 err(EXIT_FAILURE
, "mq_receive 3");
81 assert(p
== MQ_PRIO_BOUNDARY
&& m
[0] == 'a');
83 if (mq_receive(mqfd
, m
, len
, &p
) == -1) {
84 err(EXIT_FAILURE
, "mq_receive 4");
86 assert(p
== MQ_PRIO_BOUNDARY
&& m
[0] == 'c');
88 if (mq_receive(mqfd
, m
, len
, &p
) == -1) {
89 err(EXIT_FAILURE
, "mq_receive 5");
91 assert(p
== (MQ_PRIO_BOUNDARY
- 1) && m
[0] == 'd');
93 if (mq_receive(mqfd
, m
, len
, &p
) == -1) {
94 err(EXIT_FAILURE
, "mq_receive 6");
96 assert(p
== 0 && m
[0] == 'e');
102 main(int argc
, char **argv
)
106 (void)mq_unlink(MQUEUE
);
108 mqfd
= mq_open(MQUEUE
, O_RDWR
| O_CREAT
,
109 S_IRUSR
| S_IRWXG
| S_IROTH
, NULL
);
111 err(EXIT_FAILURE
, "mq_open");
118 if (mq_unlink(MQUEUE
) == -1)
119 err(EXIT_FAILURE
, "mq_unlink");