1 /* $NetBSD: t_mqueue.c,v 1.3 2012/11/06 19:35:38 pgoyette Exp $ */
4 * Test for POSIX message queue priority handling.
6 * This file is in the Public Domain.
21 #define MQ_PRIO_BASE 24
31 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
) != -1,
32 "mq_send 1 failed: %d", errno
);
35 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
+ 1) != -1,
36 "mq_send 2 failed: %d", errno
);
39 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
) != -1,
40 "mq_send 3 failed: %d", errno
);
43 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
- 1) != -1,
44 "mq_send 4 failed: %d", errno
);
47 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), 0) != -1,
48 "mq_send 5 failed: %d", errno
);
51 ATF_REQUIRE_MSG(mq_send(mqfd
, msg
, sizeof(msg
), MQ_PRIO_BASE
+ 1) != -1,
52 "mq_send 6 failed: %d", errno
);
56 receive_msgs(mqd_t mqfd
)
63 ATF_REQUIRE_MSG(mq_getattr(mqfd
, &mqa
) != -1, "mq_getattr failed %d",
68 ATF_REQUIRE_MSG(m
!= NULL
, "calloc failed");
70 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
71 "mq_receive 1 failed: %d", errno
);
72 ATF_REQUIRE_MSG(p
== (MQ_PRIO_BASE
+ 1) && m
[0] == 'b',
73 "mq_receive 1 prio/data mismatch");
75 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
76 "mq_receive 2 failed: %d", errno
);
77 ATF_REQUIRE_MSG(p
== (MQ_PRIO_BASE
+ 1) && m
[0] == 'f',
78 "mq_receive 2 prio/data mismatch");
80 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
81 "mq_receive 3 failed: %d", errno
);
82 ATF_REQUIRE_MSG(p
== MQ_PRIO_BASE
&& m
[0] == 'a',
83 "mq_receive 3 prio/data mismatch");
85 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
86 "mq_receive 4 failed: %d", errno
);
87 ATF_REQUIRE_MSG(p
== MQ_PRIO_BASE
&& m
[0] == 'c',
88 "mq_receive 4 prio/data mismatch");
90 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
91 "mq_receive 5 failed: %d", errno
);
92 ATF_REQUIRE_MSG(p
== (MQ_PRIO_BASE
- 1) && m
[0] == 'd',
93 "mq_receive 5 prio/data mismatch");
95 ATF_REQUIRE_MSG(mq_receive(mqfd
, m
, len
, &p
) != -1,
96 "mq_receive 6 failed: %d", errno
);
97 ATF_REQUIRE_MSG(p
== 0 && m
[0] == 'e',
98 "mq_receive 6 prio/data mismatch");
101 ATF_TC_WITH_CLEANUP(mqueue
);
102 ATF_TC_HEAD(mqueue
, tc
)
105 atf_tc_set_md_var(tc
, "timeout", "3");
106 atf_tc_set_md_var(tc
, "descr", "Checks mqueue send/receive");
109 ATF_TC_BODY(mqueue
, tc
)
115 strlcpy(template, "./t_mqueue.XXXXXX", sizeof(template));
116 tmpdir
= mkdtemp(template);
117 ATF_REQUIRE_MSG(tmpdir
!= NULL
, "mkdtemp failed: %d", errno
);
118 snprintf(mq_name
, sizeof(mq_name
), "%s/mq", tmpdir
);
122 mqfd
= mq_open(mq_name
, O_RDWR
| O_CREAT
,
123 S_IRUSR
| S_IRWXG
| S_IROTH
, NULL
);
124 ATF_REQUIRE_MSG(mqfd
!= -1, "mq_open failed: %d", errno
);
129 status
= mq_close(mqfd
);
130 ATF_REQUIRE_MSG(status
== 0, "mq_close failed: %d", errno
);
133 ATF_TC_CLEANUP(mqueue
, tc
)
137 if (tmpdir
!= NULL
) {
138 status
= rmdir(tmpdir
);
139 ATF_REQUIRE_MSG(status
== 0, "rmdir failed: %d", errno
);
145 ATF_TP_ADD_TC(tp
, mqueue
);
147 return atf_no_error();