1 /* $NetBSD: t_mqueue.c,v 1.4 2014/03/02 19:56:48 jmmv Exp $ */
4 * Test for POSIX message queue priority handling.
6 * This file is in the Public Domain.
19 #define MQ_PRIO_BASE 24
29 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
) != -1,
30 "mq_send 1 failed: %d", errno
);
33 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
+ 1) != -1,
34 "mq_send 2 failed: %d", errno
);
37 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
) != -1,
38 "mq_send 3 failed: %d", errno
);
41 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
- 1) != -1,
42 "mq_send 4 failed: %d", errno
);
45 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), 0) != -1,
46 "mq_send 5 failed: %d", errno
);
49 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
+ 1) != -1,
50 "mq_send 6 failed: %d", errno
);
54 receive_msgs(mqd_t mqfd
)
61 ATF_REQUIRE_MSG(mq_getattr(mqfd
, &mqa
) != -1, "mq_getattr failed %d",
66 ATF_REQUIRE_MSG(m
!= NULL
, "calloc failed");
68 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
69 "mq_receive 1 failed: %d", errno
);
70 ATF_REQUIRE_MSG(p
== (MQ_PRIO_BASE
+ 1) && m
[0] == 'b',
71 "mq_receive 1 prio/data mismatch");
73 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
74 "mq_receive 2 failed: %d", errno
);
75 ATF_REQUIRE_MSG(p
== (MQ_PRIO_BASE
+ 1) && m
[0] == 'f',
76 "mq_receive 2 prio/data mismatch");
78 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
79 "mq_receive 3 failed: %d", errno
);
80 ATF_REQUIRE_MSG(p
== MQ_PRIO_BASE
&& m
[0] == 'a',
81 "mq_receive 3 prio/data mismatch");
83 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
84 "mq_receive 4 failed: %d", errno
);
85 ATF_REQUIRE_MSG(p
== MQ_PRIO_BASE
&& m
[0] == 'c',
86 "mq_receive 4 prio/data mismatch");
88 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
89 "mq_receive 5 failed: %d", errno
);
90 ATF_REQUIRE_MSG(p
== (MQ_PRIO_BASE
- 1) && m
[0] == 'd',
91 "mq_receive 5 prio/data mismatch");
93 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
94 "mq_receive 6 failed: %d", errno
);
95 ATF_REQUIRE_MSG(p
== 0 && m
[0] == 'e',
96 "mq_receive 6 prio/data mismatch");
100 ATF_TC_HEAD(mqueue
, tc
)
103 atf_tc_set_md_var(tc
, "timeout", "3");
104 atf_tc_set_md_var(tc
, "descr", "Checks mqueue send/receive");
107 ATF_TC_BODY(mqueue
, tc
)
114 strlcpy(template, "./t_mqueue.XXXXXX", sizeof(template));
115 tmpdir
= mkdtemp(template);
116 ATF_REQUIRE_MSG(tmpdir
!= NULL
, "mkdtemp failed: %d", errno
);
117 snprintf(mq_name
, sizeof(mq_name
), "%s/mq", tmpdir
);
121 mqfd
= mq_open(mq_name
, O_RDWR
| O_CREAT
,
122 S_IRUSR
| S_IRWXG
| S_IROTH
, NULL
);
123 ATF_REQUIRE_MSG(mqfd
!= -1, "mq_open failed: %d", errno
);
128 status
= mq_close(mqfd
);
129 ATF_REQUIRE_MSG(status
== 0, "mq_close failed: %d", errno
);
134 ATF_TP_ADD_TC(tp
, mqueue
);
136 return atf_no_error();