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