1 /*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <securec.h>
33 #include "posix_test.h"
34 #include <mqueue.h>
35 #include <fcntl.h>
36 #include "kernel_test.h"
37 #include "log.h"
38
39 #define MQUEUE_STANDARD_NAME_LENGTH 52
40 #define MQUEUE_NO_ERROR 0
41 #define MQUEUE_SEND_STRING_TEST "mq_test"
42 #define MQUEUE_SHORT_ARRAY_LENGTH strlen(MQUEUE_SEND_STRING_TEST)
43
44 const int MQ_NAME_LEN = 64; // mqueue name len
45 const int MQ_TX_LEN = 64; // mqueue send buffer len
46 const int MQ_RX_LEN = 64; // mqueue receive buffer len
47 const int MQ_MSG_SIZE = 64; // mqueue message size
48 const int MQ_MSG_PRIO = 0; // mqueue message priority
49 const int MQ_MAX_MSG = 16; // mqueue message number
50 const char MQ_MSG[] = "MessageToSend"; // mqueue message to send
51 const int MQ_MSG_LEN = sizeof(MQ_MSG); // mqueue message len to send
52
53 const int MAX_MQ_NUMBER = LOSCFG_BASE_IPC_QUEUE_LIMIT - 1; // max mqueue number
54 const int MAX_MQ_NAME_LEN = 256; // max mqueue name length
55 const int MAX_MQ_MSG_SIZE = 65530; // max mqueue message size
56
57 // return n: 0 < n <= max
GetRandom(unsigned int max)58 static unsigned int GetRandom(unsigned int max)
59 {
60 if (max == 0 || max == 1) {
61 return 1;
62 }
63 return (rand() % max) + 1;
64 }
65
66 /**
67 * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
68 * @param : subsystem name is mqueue
69 * @param : module name is mqueue
70 * @param : test suit name is MqueueFuncTestSuite
71 */
72 LITE_TEST_SUIT(Posix, Mqueue, MqueueFuncTestSuite);
73
74 /**
75 * @tc.setup : setup for all testcases
76 * @return : setup result, TRUE is success, FALSE is fail
77 */
MqueueFuncTestSuiteSetUp(void)78 static BOOL MqueueFuncTestSuiteSetUp(void)
79 {
80 return TRUE;
81 }
82
83 /**
84 * @tc.teardown : teardown for all testcases
85 * @return : teardown result, TRUE is success, FALSE is fail
86 */
MqueueFuncTestSuiteTearDown(void)87 static BOOL MqueueFuncTestSuiteTearDown(void)
88 {
89 printf("+-------------------------------------------+\n");
90 return TRUE;
91 }
92
93 /**
94 * @tc.number : SUB_KERNEL_PTHREAD_OPERATION_001
95 * @tc.name : event operation for create
96 * @tc.desc : [C- SOFTWARE -0200]
97 */
98 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqueue001, Function | MediumTest | Level1)
99 {
100 unsigned int ret;
101 char msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0};
102 char mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
103 const char *msgptr = MQUEUE_SEND_STRING_TEST;
104 struct mq_attr attr = { 0 };
105 mqd_t mqueue;
106
107 attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH;
108 attr.mq_maxmsg = 1;
109
110 snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, "/mq002_%d", 1);
111
112 mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
113 ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT1);
114
115 ret = mq_send(mqueue, msgptr, strlen(msgptr), 0);
116 ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
117
118 ret = mq_receive(mqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL);
119 ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT1);
120 ICUNIT_GOTO_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd, EXIT1);
121
122 ret = mq_close(mqueue);
123 ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
124
125 ret = mq_unlink(mqname);
126 ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT);
127
128 return 0;
129
130 EXIT1:
131 mq_close(mqueue);
132 EXIT:
133 mq_unlink(mqname);
134 return 0;
135 };
136
137 /**
138 * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0100
139 * @tc.name mq_open function errno for EEXIST test
140 * @tc.desc [C- SOFTWARE -0200]
141 */
142 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqOpenEEXIST, Function | MediumTest | Level2)
143 {
144 char qName[MQ_NAME_LEN];
145 mqd_t queue, queueOther;
146 int ret;
147
148 sprintf_s(qName, MQ_NAME_LEN, "testMqOpenEEXIST_%d", GetRandom(10000));
149 queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
150 ICUNIT_GOTO_NOT_EQUAL(queue, (mqd_t)-1, queue, EXIT1);
151
152 queueOther = mq_open(qName, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, NULL);
153 ICUNIT_GOTO_EQUAL(queueOther, (mqd_t)-1, queueOther, EXIT1);
154 ICUNIT_GOTO_EQUAL(errno, EEXIST, errno, EXIT1);
155
156 EXIT1:
157 ret = mq_close(queue);
158 ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
159 EXIT:
160 ret = mq_unlink(qName);
161 ICUNIT_ASSERT_EQUAL(ret, 0, ret);
162 return 0;
163 }
164
165 /**
166 * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0200
167 * @tc.name mq_open function errno for EINVAL test
168 * @tc.desc [C- SOFTWARE -0200]
169 */
170 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqOpenEINVAL, Function | MediumTest | Level2)
171 {
172 int i;
173 mqd_t queue;
174 struct mq_attr attr = {0};
175 char qName[MQ_NAME_LEN];
176 const int max = 65535;
177
178 sprintf_s(qName, MQ_NAME_LEN, "testMqOpenEINVAL_%d", GetRandom(10000));
179
180 for (i = 0; i<6; i++) {
181 switch (i) {
182 case 0:
183 attr.mq_msgsize = -1;
184 attr.mq_maxmsg = max;
185 break;
186 case 1:
187 /* attr.mq_msgsize > USHRT_MAX - 4 */
188 attr.mq_msgsize = max;
189 attr.mq_maxmsg = max;
190 break;
191 case 2:
192 attr.mq_msgsize = 10;
193 attr.mq_maxmsg = -1;
194 break;
195 case 3:
196 attr.mq_msgsize = 10;
197 attr.mq_maxmsg = max + 1;
198 break;
199
200 case 4:
201 attr.mq_msgsize = 0;
202 attr.mq_maxmsg = 16;
203 break;
204
205 case 5:
206 attr.mq_msgsize = 64;
207 attr.mq_maxmsg = 0;
208 break;
209 }
210
211 queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
212 ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
213
214 if (queue != (mqd_t)-1) {
215 mq_close(queue);
216 mq_unlink(qName);
217 }
218
219 /* if NOT call mq_close & mq_unlink then errno == ENOENT */
220 ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
221 }
222
223 for (i=0; i<MQ_NAME_LEN; i++) {
224 qName[i] = 0;
225 }
226 attr.mq_msgsize = MQ_MSG_SIZE;
227 attr.mq_maxmsg = MQ_MAX_MSG;
228 queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
229 ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
230 return 0;
231 }
232
233
234 /**
235 * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0300
236 * @tc.name mq_open function errno for ENAMETOOLONG test
237 * @tc.desc [C- SOFTWARE -0200]
238 */
239 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqOpenENAMETOOLONG, Function | MediumTest | Level2)
240 {
241 char qName[MAX_MQ_NAME_LEN + 10];
242 mqd_t queue;
243 int i;
244
245 for (i=0; i<MAX_MQ_NAME_LEN + 5; i++) {
246 qName[i] = '8';
247 }
248 qName[i] = '\0';
249
250 queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
251 ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
252
253 if (queue != (mqd_t)-1) {
254 mq_close(queue);
255 mq_unlink(qName);
256 }
257
258 ICUNIT_TRACK_EQUAL(errno, ENAMETOOLONG, errno);
259 return 0;
260 }
261
262
263 /**
264 * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0400
265 * @tc.name mq_open function errno for ENOENT test
266 * @tc.desc [C- SOFTWARE -0200]
267 */
268 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqOpenENOENT, Function | MediumTest | Level3)
269 {
270 mqd_t queue;
271 char qName[MQ_NAME_LEN];
272
273 sprintf_s(qName, MQ_NAME_LEN, "testMqOpenENOENT_%d", GetRandom(10000));
274 queue = mq_open(qName, O_RDWR, S_IRUSR | S_IWUSR, NULL);
275 ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
276
277 if (queue != (mqd_t)-1) {
278 mq_close(queue);
279 mq_unlink(qName);
280 }
281 ICUNIT_TRACK_EQUAL(errno, ENOENT, errno);
282 return 0;
283 }
284
285 /**
286 * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0500
287 * @tc.name mq_open function errno for ENFILE test
288 * @tc.desc [C- SOFTWARE -0200]
289 */
290 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqOpenENFILE, Function | MediumTest | Level3)
291 {
292 char qName[MAX_MQ_NUMBER + 1][30];
293 mqd_t queue[MAX_MQ_NUMBER + 1];
294 int flag = 0;
295 int i;
296 (void)memset_s(queue, sizeof(queue), 0, sizeof(queue));
297 for (i=0; i<MAX_MQ_NUMBER + 1; i++) {
298 sprintf_s(qName[i], MQ_NAME_LEN, "testMqOpenENFILE_%d", i);
299 }
300
301 for (i=0; i<MAX_MQ_NUMBER; i++) {
302 queue[i] = mq_open(qName[i], O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
303
304 if (queue[i] == (mqd_t)-1) {
305 flag = 1;
306 printf("break: i = %d", i);
307 break;
308 }
309 ICUNIT_TRACK_NOT_EQUAL(queue[i], (mqd_t)-1, queue[i]);
310 }
311
312 printf("func: i = %d", i);
313 if (flag == 0) {
314 queue[i] = mq_open(qName[i], O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
315 }
316 ICUNIT_TRACK_EQUAL(queue[i], (mqd_t)-1, queue[i]);
317 ICUNIT_TRACK_EQUAL(errno, ENFILE, errno);
318
319 for (i=0; i<MAX_MQ_NUMBER+1; i++) {
320 mq_close(queue[i]);
321 mq_unlink(qName[i]);
322 }
323 return 0;
324 }
325
326 /**
327 * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0600
328 * @tc.name mq_open function errno for ENOSPC test
329 * @tc.desc [C- SOFTWARE -0200]
330 */
331 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqOpenENOSPC, Function | MediumTest | Level3)
332 {
333 mqd_t queue;
334 struct mq_attr setAttr = {0};
335 char qName[MQ_NAME_LEN];
336
337 sprintf_s(qName, MQ_NAME_LEN, "testMqOpenENOSPC_%d", GetRandom(10000));
338 setAttr.mq_msgsize = MAX_MQ_MSG_SIZE + 1;
339 setAttr.mq_maxmsg = MAX_MQ_NAME_LEN;
340 queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr);
341 ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
342
343 if (queue != (mqd_t)-1) {
344 mq_close(queue);
345 mq_unlink(qName);
346 }
347 ICUNIT_TRACK_EQUAL(errno, ENOSPC, errno);
348 return 0;
349 }
350
351 /**
352 * @tc.number SUB_KERNEL_IPC_MQ_CLOSE_0100
353 * @tc.name mq_close function errno for EBADF test
354 * @tc.desc [C- SOFTWARE -0200]
355 */
356 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqCloseEBADF, Function | MediumTest | Level2)
357 {
358 ICUNIT_TRACK_EQUAL(mq_close(NULL), -1, -1);
359 ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
360 return 0;
361 }
362
363 /**
364 * @tc.number SUB_KERNEL_IPC_MQ_SEND_0100
365 * @tc.name mq_send function errno for EAGAIN test
366 * @tc.desc [C- SOFTWARE -0200]
367 */
368 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqSendEAGAIN, Function | MediumTest | Level2)
369 {
370 mqd_t queue;
371 struct mq_attr attr = {0};
372 char qName[MQ_NAME_LEN];
373 int ret;
374
375 sprintf_s(qName, MQ_NAME_LEN, "testMqSendEAGAIN_%d", GetRandom(10000));
376 attr.mq_msgsize = MQ_MSG_SIZE;
377 attr.mq_maxmsg = 1;
378 queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
379 ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue);
380
381 ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0);
382 ICUNIT_TRACK_EQUAL(ret, 0, ret);
383
384 ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0);
385 ICUNIT_TRACK_EQUAL(ret, -1, ret);
386 ICUNIT_TRACK_EQUAL(errno, EAGAIN, errno);
387
388 ret = mq_close(queue);
389 ICUNIT_TRACK_EQUAL(ret, 0, ret);
390
391 ret = mq_unlink(qName);
392 ICUNIT_TRACK_EQUAL(ret, 0, ret);
393 return 0;
394 }
395
396 /**
397 * @tc.number SUB_KERNEL_IPC_MQ_SEND_0200
398 * @tc.name mq_send function errno for EBADF and EMSGSIZE test
399 * @tc.desc [C- SOFTWARE -0200]
400 */
401 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqSendEBADFEMSGSIZE, Function | MediumTest | Level2)
402 {
403 mqd_t queue;
404 struct mq_attr attr = {0};
405 char qName[MQ_NAME_LEN];
406 int ret;
407
408 sprintf_s(qName, MQ_NAME_LEN, "testMqSendEAGAIN_%d", GetRandom(10000));
409 attr.mq_msgsize = 1;
410 attr.mq_maxmsg = MQ_MAX_MSG;
411 queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
412 ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue);
413
414 ret = mq_send(NULL, MQ_MSG, 1, MQ_MSG_PRIO);
415 ICUNIT_TRACK_EQUAL(ret, -1, ret);
416 ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
417
418
419 ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
420 ICUNIT_TRACK_EQUAL(ret, -1, ret);
421 ICUNIT_TRACK_EQUAL(errno, EMSGSIZE, errno);
422
423 ret = mq_close(queue);
424 ICUNIT_TRACK_EQUAL(ret, 0, ret);
425 ret = mq_unlink(qName);
426 ICUNIT_ASSERT_EQUAL(ret, 0, ret);
427
428 attr.mq_msgsize = MQ_MSG_SIZE;
429 attr.mq_maxmsg = MQ_MAX_MSG;
430 queue = mq_open(qName, O_CREAT | O_RDONLY | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
431 ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue);
432
433 ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
434 ICUNIT_TRACK_EQUAL(ret, -1, ret);
435 ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
436
437 attr.mq_flags |= O_NONBLOCK;
438 ret = mq_setattr(queue, &attr, NULL);
439 ICUNIT_TRACK_EQUAL(ret, 0, ret);
440
441 ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
442 ICUNIT_TRACK_EQUAL(ret, -1, ret);
443 ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
444
445 ret = mq_close(queue);
446 ICUNIT_TRACK_EQUAL(ret, 0, ret);
447
448 ret = mq_unlink(qName);
449 ICUNIT_TRACK_EQUAL(ret, 0, ret);
450 return 0;
451 }
452
453 /**
454 * @tc.number SUB_KERNEL_IPC_MQ_SEND_0300
455 * @tc.name mq_send function errno for EINVAL test
456 * @tc.desc [C- SOFTWARE -0200]
457 */
458 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqSendEINVAL, Function | MediumTest | Level3)
459 {
460 mqd_t queue;
461 struct mq_attr attr = {0};
462 char qName[MQ_NAME_LEN];
463 int ret;
464
465 sprintf_s(qName, MQ_NAME_LEN, "testMqSendEINVAL_%d", GetRandom(10000));
466 attr.mq_msgsize = MQ_MSG_SIZE;
467 attr.mq_maxmsg = MQ_MAX_MSG;
468 queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
469 ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue);
470
471 ret = mq_send(queue, MQ_MSG, 0, MQ_MSG_PRIO);
472 ICUNIT_TRACK_EQUAL(ret, -1, ret);
473 ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
474
475 ret = mq_close(queue);
476 ICUNIT_TRACK_EQUAL(ret, 0, ret);
477
478 ret = mq_unlink(qName);
479 ICUNIT_TRACK_EQUAL(ret, 0, ret);
480 return 0;
481 }
482
483 /**
484 * @tc.number SUB_KERNEL_IPC_MQ_RECEIVE_0100
485 * @tc.name mq_receive function errno for EAGAIN test
486 * @tc.desc [C- SOFTWARE -0200]
487 */
488 LITE_TEST_CASE(MqueueFuncTestSuite, TestMqReceiveEAGAIN, Function | MediumTest | Level2)
489 {
490 mqd_t queue;
491 unsigned int prio;
492 struct mq_attr attr = {0};
493 struct mq_attr getAttr = {0};
494 char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN];
495 int ret;
496
497 sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEAGAIN_%d", GetRandom(10000));
498 attr.mq_msgsize = MQ_MSG_SIZE;
499 attr.mq_maxmsg = MQ_MAX_MSG;
500 queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
501 ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue);
502
503 ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
504 ICUNIT_TRACK_EQUAL(ret, 0, ret);
505 ret = mq_getattr(queue, &getAttr);
506 ICUNIT_TRACK_EQUAL(ret, 0, ret);
507 ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
508 ICUNIT_TRACK_NOT_EQUAL(ret, -1, ret);
509 ICUNIT_TRACK_EQUAL(prio, MQ_MSG_PRIO, prio);
510 ICUNIT_TRACK_EQUAL(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN), 0, -1);
511 ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
512 ICUNIT_TRACK_EQUAL(ret, -1, ret);
513 ICUNIT_TRACK_EQUAL(errno, EAGAIN, errno);
514
515 ret = mq_close(queue);
516 ICUNIT_TRACK_EQUAL(ret, 0, ret);
517
518 ret = mq_unlink(qName);
519 ICUNIT_TRACK_EQUAL(ret, 0, ret);
520 return 0;
521 }
522
523 RUN_TEST_SUITE(MqueueFuncTestSuite);
524
PosixMqueueFuncTest(void)525 void PosixMqueueFuncTest(void)
526 {
527 LOG("begin PosixMqueueFuncTest....");
528 RUN_ONE_TESTCASE(TestMqueue001);
529 RUN_ONE_TESTCASE(TestMqOpenEEXIST);
530 RUN_ONE_TESTCASE(TestMqOpenEINVAL);
531 RUN_ONE_TESTCASE(TestMqOpenENAMETOOLONG);
532 RUN_ONE_TESTCASE(TestMqOpenENOENT);
533 RUN_ONE_TESTCASE(TestMqOpenENFILE);
534 RUN_ONE_TESTCASE(TestMqOpenENOSPC);
535 RUN_ONE_TESTCASE(TestMqCloseEBADF);
536 RUN_ONE_TESTCASE(TestMqSendEAGAIN);
537 RUN_ONE_TESTCASE(TestMqSendEBADFEMSGSIZE);
538 RUN_ONE_TESTCASE(TestMqSendEINVAL);
539 RUN_ONE_TESTCASE(TestMqReceiveEAGAIN);
540
541 return;
542 }
543