diff --git a/testsuites/sample/posix/BUILD.gn b/testsuites/sample/posix/BUILD.gn index 686fff50196c54a9e2947402c6fb7ebdc61982fc..8c3c23a62ebfd71f3c642c92a83cab5681bfd51b 100644 --- a/testsuites/sample/posix/BUILD.gn +++ b/testsuites/sample/posix/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved. +# Copyright (c) 2022-2023 Huawei Device Co., Ltd. All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: @@ -81,6 +81,21 @@ static_library("test_posix") { "mqueue/It_posix_queue_050.c", "mqueue/It_posix_queue_051.c", "mqueue/It_posix_queue_052.c", + "mqueue/It_posix_queue_053.c", + "mqueue/It_posix_queue_054.c", + "mqueue/It_posix_queue_055.c", + "mqueue/It_posix_queue_056.c", + "mqueue/It_posix_queue_057.c", + "mqueue/It_posix_queue_058.c", + "mqueue/It_posix_queue_059.c", + "mqueue/It_posix_queue_060.c", + "mqueue/It_posix_queue_061.c", + "mqueue/It_posix_queue_062.c", + "mqueue/It_posix_queue_063.c", + "mqueue/It_posix_queue_064.c", + "mqueue/It_posix_queue_065.c", + "mqueue/It_posix_queue_066.c", + "mqueue/It_posix_queue_067.c", "mutex/It_posix_mutex.c", "mutex/It_posix_mutex_001.c", "mutex/It_posix_mutex_002.c", diff --git a/testsuites/sample/posix/mqueue/It_posix_queue.c b/testsuites/sample/posix/mqueue/It_posix_queue.c index 94957870e7fd7e12ec3ff5a68cf4216966eb88f3..c4dc6bebeb0502f3c00e5b4870efa59b9ec009b2 100644 --- a/testsuites/sample/posix/mqueue/It_posix_queue.c +++ b/testsuites/sample/posix/mqueue/It_posix_queue.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -105,4 +105,19 @@ VOID ItSuitePosixMqueue(void) ItPosixQueue050(); ItPosixQueue051(); ItPosixQueue052(); + ItPosixQueue053(); + ItPosixQueue054(); + ItPosixQueue055(); + ItPosixQueue056(); + ItPosixQueue057(); + ItPosixQueue058(); + ItPosixQueue059(); + ItPosixQueue060(); + ItPosixQueue061(); + ItPosixQueue062(); + ItPosixQueue063(); + ItPosixQueue064(); + ItPosixQueue065(); + ItPosixQueue066(); + ItPosixQueue067(); } diff --git a/testsuites/sample/posix/mqueue/It_posix_queue.h b/testsuites/sample/posix/mqueue/It_posix_queue.h index 2bd0b33d979f1ad689858cc80d6565bbf5b59e10..9c402353c9c2a297c8b78ab03f75a387d956b5f1 100644 --- a/testsuites/sample/posix/mqueue/It_posix_queue.h +++ b/testsuites/sample/posix/mqueue/It_posix_queue.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. All rights reserved. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -162,4 +162,19 @@ VOID ItPosixQueue049(VOID); VOID ItPosixQueue050(VOID); VOID ItPosixQueue051(VOID); VOID ItPosixQueue052(VOID); +VOID ItPosixQueue053(VOID); +VOID ItPosixQueue054(VOID); +VOID ItPosixQueue055(VOID); +VOID ItPosixQueue056(VOID); +VOID ItPosixQueue057(VOID); +VOID ItPosixQueue058(VOID); +VOID ItPosixQueue059(VOID); +VOID ItPosixQueue060(VOID); +VOID ItPosixQueue061(VOID); +VOID ItPosixQueue062(VOID); +VOID ItPosixQueue063(VOID); +VOID ItPosixQueue064(VOID); +VOID ItPosixQueue065(VOID); +VOID ItPosixQueue066(VOID); +VOID ItPosixQueue067(VOID); #endif diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_053.c b/testsuites/sample/posix/mqueue/It_posix_queue_053.c new file mode 100644 index 0000000000000000000000000000000000000000..1e166312cecde7a7421a83b5f387e8c3f26b4edc --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_053.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + UINT32 ret; + + CHAR qName[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgPtr = MQUEUE_SEND_STRING_TEST; + struct mq_attr msgAttr = {0}; + CHAR msgRcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + mqd_t msgQId; + + msgAttr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + msgAttr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + ret = snprintf_s(qName, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq053_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT); + + msgQId = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &msgAttr); + ICUNIT_GOTO_NOT_EQUAL(msgQId, (mqd_t)-1, msgQId, EXIT); + + ret = mq_send(msgQId, msgPtr, strlen(msgPtr), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_receive(msgQId, msgRcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MSGLEN, ret, EXIT2); + ICUNIT_GOTO_STRING_EQUAL(msgRcd, MQUEUE_SEND_STRING_TEST, msgRcd, EXIT2); + + ret = mq_close(msgQId); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_unlink(qName); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + return LOS_OK; +EXIT2: + mq_close(msgQId); +EXIT1: + mq_unlink(qName); +EXIT: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue053 + * @tc.desc: Test interface mq_send + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue053(VOID) +{ + TEST_ADD_CASE("ItPosixQueue053", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_054.c b/testsuites/sample/posix/mqueue/It_posix_queue_054.c new file mode 100644 index 0000000000000000000000000000000000000000..3c0828e7b5813a9f2e3adce54670a9ccdbfcb845 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_054.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + INT32 ret; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + CHAR mqname1[MQUEUE_STANDARD_NAME_LENGTH] = ""; + CHAR mqname2[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqueue1; + mqd_t mqueue2; + struct mq_attr attr = {0}; + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + ret = snprintf_s(mqname1, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq054_1_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + ret = snprintf_s(mqname2, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq054_2_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + mqueue1 = mq_open(mqname1, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqueue1, (mqd_t)-1, mqueue1, EXIT2); + + mqueue2 = mq_open(mqname2, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqueue2, (mqd_t)-1, mqueue2, EXIT); + + ret = mq_send(mqueue1, msgptr, strlen(msgptr), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_send(mqueue2, msgptr, strlen(msgptr), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_close(mqueue2); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_unlink(mqname2); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_close(mqueue1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_unlink(mqname1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + return LOS_OK; +EXIT1: + mq_close(mqueue2); + mq_unlink(mqname2); +EXIT: + mq_close(mqueue1); + mq_unlink(mqname1); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue054 + * @tc.desc: Test interface mq_send + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue054(VOID) +{ + TEST_ADD_CASE("ItPosixQueue054", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_055.c b/testsuites/sample/posix/mqueue/It_posix_queue_055.c new file mode 100644 index 0000000000000000000000000000000000000000..c87f6c38df689fc0629ebda0f13b2a056cb682dc --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_055.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + UINT32 ret; + + CHAR msgRcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + + CHAR qName[MQUEUE_STANDARD_NAME_LENGTH] = "/mq055"; + mqd_t msgQId; + struct mq_attr msgAttr = {0}; + msgAttr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + msgAttr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + msgQId = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &msgAttr); + ICUNIT_ASSERT_NOT_EQUAL(msgQId, (mqd_t)-1, msgQId); + + ret = mq_receive(msgQId, msgRcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, (UINT32)-1, ret, EXIT1); + + ret = mq_close(msgQId); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_unlink(qName); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + return LOS_OK; +EXIT1: + mq_close(msgQId); +EXIT: + mq_unlink(qName); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue055 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue055(VOID) +{ + TEST_ADD_CASE("ItPosixQueue055", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_056.c b/testsuites/sample/posix/mqueue/It_posix_queue_056.c new file mode 100644 index 0000000000000000000000000000000000000000..bf3e666047d67ed4366ad62f7a95d96089fbfc7e --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_056.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" +static int g_testFlag = 0; + +static VOID *PthreadF01(VOID *arg) +{ + INT32 ret; + INT32 i; + CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + struct timespec ts = {0}; + ts.tv_sec = 0xffff; + for (i = 0; i < MQUEUE_STANDARD_NAME_LENGTH * 2; i++) { // 2, The loop frequency name length. + ret = mq_timedreceive(g_gqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL, &ts); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT); + ICUNIT_GOTO_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd, EXIT); + } + g_testFlag = 0; // 0 means the sub thread has executed +EXIT: + return NULL; +} + +static UINT32 Testcase(VOID) +{ + INT32 ret; + INT32 i; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + pthread_t pthread1; + pthread_attr_t attr1; + struct sched_param schedparam; + struct mq_attr attr = {0}; + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + g_testFlag = 1; // 1 initialize the flag + LOS_TaskLock(); + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq056_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + g_gqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(g_gqueue, (mqd_t)-1, g_gqueue, EXIT1); + ret = pthread_attr_init(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + pthread_attr_setinheritsched(&attr1, PTHREAD_EXPLICIT_SCHED); + schedparam.sched_priority = MQUEUE_PTHREAD_PRIORITY_TEST2; + + ret = pthread_attr_setschedparam(&attr1, &schedparam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_create(&pthread1, &attr1, PthreadF01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + LOS_TaskUnlock(); + for (i = 0; i < MQUEUE_STANDARD_NAME_LENGTH * 2; i++) { // 2, The loop frequency name length. + ret = mq_send(g_gqueue, msgptr, strlen(msgptr), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + } + + // waitting for the flag is 0, means the sub thread has executed + while (g_testFlag) { + usleep(1); + } + + ret = mq_close(g_gqueue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT3); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_join(pthread1, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_attr_destroy(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + return LOS_OK; +EXIT1: + mq_close(g_gqueue); +EXIT3: + mq_unlink(mqname); +EXIT: + PosixPthreadDestroy(&attr1, pthread1); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue056 + * @tc.desc: Test interface mq_timedreceive + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue056(VOID) +{ + TEST_ADD_CASE("ItPosixQueue056", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_057.c b/testsuites/sample/posix/mqueue/It_posix_queue_057.c new file mode 100644 index 0000000000000000000000000000000000000000..b73048a45843107eb4f5ccf1dd078d96a7ded29c --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_057.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static VOID *PthreadF01(VOID *arg) +{ + INT32 ret; + CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + + LOS_AtomicInc(&g_testCount); + + ret = mq_receive(g_gqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT); + ICUNIT_GOTO_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd, EXIT); + + return NULL; + +EXIT: + g_testCount = 0; + return NULL; +} + +static VOID *PthreadF02(VOID *arg) +{ + INT32 ret, i; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + pthread_t thread1; + pthread_attr_t attr1; + struct sched_param schedparam; + struct mq_attr attr = {0}; + struct timespec ts = {0}; + + ts.tv_sec = 0xFFFF; + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = 2; // 2, queue max message size. + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq057_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + g_gqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(g_gqueue, (mqd_t)-1, g_gqueue, EXIT1); + ret = pthread_attr_init(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + schedparam.sched_priority = MQUEUE_PTHREAD_PRIORITY_TEST2; + ret = pthread_attr_setschedparam(&attr1, &schedparam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_create(&thread1, &attr1, PthreadF01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + for (i = 0; i < 3; i++) { // 3, the loop frequency. + ret = mq_timedsend(g_gqueue, msgptr, MQUEUE_SHORT_ARRAY_LENGTH, 0, &ts); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + LOS_AtomicInc(&g_testCount); + } + + ret = pthread_join(thread1, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_attr_destroy(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_close(g_gqueue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + return NULL; +EXIT1: + mq_close(g_gqueue); + mq_unlink(mqname); +EXIT: + PosixPthreadDestroy(&attr1, thread1); + g_testCount = 0; +EXIT2: + return NULL; +} + +static UINT32 Testcase(VOID) +{ + INT32 ret; + pthread_t pthread1; + pthread_attr_t attr1; + struct sched_param schedparam; + + g_testCount = 0; + + ret = pthread_attr_init(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + schedparam.sched_priority = MQUEUE_PTHREAD_PRIORITY_TEST2; + ret = pthread_attr_setschedparam(&attr1, &schedparam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_create(&pthread1, &attr1, PthreadF02, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_join(pthread1, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_attr_destroy(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ICUNIT_ASSERT_EQUAL(g_testCount, 4, g_testCount); // 4, Here, assert the g_testCount. + + return LOS_OK; + +EXIT: + PosixPthreadDestroy(&attr1, pthread1); + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue057 + * @tc.desc: Test interface mq_timedsend + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue057(VOID) +{ + TEST_ADD_CASE("ItPosixQueue057", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_058.c b/testsuites/sample/posix/mqueue/It_posix_queue_058.c new file mode 100644 index 0000000000000000000000000000000000000000..534818d9b3bfc7a4594a53233b24df0d35a4544c --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_058.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static VOID *PthreadF01(VOID *arg) +{ + INT32 ret; + CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + + g_testCount++; + + ret = mq_receive(g_gqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT); + ICUNIT_GOTO_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd, EXIT); + + g_testCount++; + + return NULL; +EXIT: + g_testCount = 0; + return NULL; +} + +static UINT32 Testcase(VOID) +{ + INT32 ret; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + pthread_t pthread1; + pthread_attr_t attr1; + struct sched_param schedparam; + struct mq_attr attr = {0}; + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + g_testCount = 0; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq058_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + g_gqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(g_gqueue, (mqd_t)-1, g_gqueue, EXIT); + + ret = mq_send(g_gqueue, msgptr, strlen(msgptr), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_attr_init(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + pthread_attr_setinheritsched(&attr1, PTHREAD_EXPLICIT_SCHED); + + schedparam.sched_priority = MQUEUE_PTHREAD_PRIORITY_TEST2; + ret = pthread_attr_setschedparam(&attr1, &schedparam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_create(&pthread1, &attr1, PthreadF01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_join(pthread1, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_attr_destroy(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT); // 2, Here, assert the g_testCount. + + ret = mq_close(g_gqueue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT3); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + return LOS_OK; +EXIT1: + PosixPthreadDestroy(&attr1, pthread1); +EXIT: + mq_close(g_gqueue); +EXIT3: + mq_unlink(mqname); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue058 + * @tc.desc: Test interface mq_send + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue058(VOID) +{ + TEST_ADD_CASE("ItPosixQueue058", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_059.c b/testsuites/sample/posix/mqueue/It_posix_queue_059.c new file mode 100644 index 0000000000000000000000000000000000000000..9f6e56bc9df625b844bca3684215d5956c924b53 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_059.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static VOID *PthreadF01(VOID *arg) +{ + INT32 ret; + CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + + LOS_AtomicInc(&g_testCount); + + ret = mq_receive(g_gqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); + + LOS_AtomicInc(&g_testCount); + + return NULL; + +EXIT: + g_testCount = 0; + return NULL; +} + +static UINT32 Testcase(VOID) +{ + pthread_t thread1; + pthread_attr_t attr1; + INT32 ret; + struct sched_param schedparam; + + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + struct mq_attr attr = {0}; + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + g_testCount = 0; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq059_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + g_gqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_ASSERT_NOT_EQUAL(g_gqueue, (mqd_t)-1, g_gqueue); + + ret = mq_send(g_gqueue, msgptr, strlen(msgptr), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_receive(g_gqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT); + ICUNIT_ASSERT_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd); + + ret = mq_close(g_gqueue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT3); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = pthread_attr_init(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + schedparam.sched_priority = MQUEUE_PTHREAD_PRIORITY_TEST2; + ret = pthread_attr_setschedparam(&attr1, &schedparam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_create(&thread1, &attr1, PthreadF01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_join(thread1, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_attr_destroy(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ICUNIT_ASSERT_EQUAL(g_testCount, 2, g_testCount); // 2, Here, assert the g_testCount. + + return LOS_OK; +EXIT1: + pthread_attr_destroy(&attr1); + return LOS_NOK; +EXIT: + mq_close(g_gqueue); +EXIT3: + mq_unlink(mqname); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue059 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue059(VOID) +{ + TEST_ADD_CASE("ItPosixQueue059", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_060.c b/testsuites/sample/posix/mqueue/It_posix_queue_060.c new file mode 100644 index 0000000000000000000000000000000000000000..52c71c263214f71c836cbd8022d8084f6da29cd9 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_060.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static VOID *PthreadF01(VOID *arg) +{ + INT32 ret; + CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + + LOS_AtomicInc(&g_testCount); + + ret = mq_receive(g_gqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT); + ICUNIT_GOTO_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd, EXIT); + + ret = mq_close(g_gqueue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_unlink(g_gqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + LOS_AtomicInc(&g_testCount); + + return NULL; +EXIT: + mq_close(g_gqueue); +EXIT1: + mq_unlink(g_gqname); +EXIT2: + g_testCount = 0; + return NULL; +} + +static VOID *PthreadF02(VOID *arg) +{ + INT32 ret; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + struct mq_attr attr = {0}; + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + LOS_AtomicInc(&g_testCount); + + g_gqueue = mq_open(g_gqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(g_gqueue, (mqd_t)-1, g_gqueue, EXIT); + + ret = mq_send(g_gqueue, msgptr, strlen(msgptr), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + LOS_AtomicInc(&g_testCount); + return NULL; +EXIT: + mq_close(g_gqueue); + mq_unlink(g_gqname); + g_testCount = 0; + return NULL; +} + +static UINT32 Testcase(VOID) +{ + INT32 ret; + pthread_t thread1; + pthread_t thread2; + pthread_attr_t attr1; + struct sched_param schedparam; + + ret = memset_s(g_gqname, MQUEUE_STANDARD_NAME_LENGTH, 0, MQUEUE_STANDARD_NAME_LENGTH); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + (void)snprintf_s(g_gqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq060_%d", LOS_CurTaskIDGet()); + + g_testCount = 0; + + ret = pthread_create(&thread1, NULL, PthreadF02, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = MqueueTaskDelay(10); // 10, Set delay time. + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ICUNIT_GOTO_EQUAL(g_testCount, 2, g_testCount, EXIT1); // 2, Here, assert the g_testCount. + + ret = pthread_attr_init(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + schedparam.sched_priority = MQUEUE_PTHREAD_PRIORITY_TEST2; + ret = pthread_attr_setschedparam(&attr1, &schedparam); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_create(&thread2, &attr1, PthreadF01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ICUNIT_GOTO_EQUAL(g_testCount, 4, g_testCount, EXIT2); // 4, Here, assert the g_testCount. + + ret = pthread_join(thread1, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = pthread_join(thread2, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = pthread_attr_destroy(&attr1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + return LOS_OK; +EXIT2: + pthread_join(thread2, NULL); +EXIT1: + pthread_join(thread1, NULL); +EXIT: + pthread_attr_destroy(&attr1); + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue060 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue060(VOID) +{ + TEST_ADD_CASE("ItPosixQueue060", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_061.c b/testsuites/sample/posix/mqueue/It_posix_queue_061.c new file mode 100644 index 0000000000000000000000000000000000000000..184f37f29dfe7ca898d8d0fbc7bb0587d1803ba9 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_061.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + CHAR qname[MQUEUE_STANDARD_NAME_LENGTH], msgrcd[MQUEUE_STANDARD_NAME_LENGTH]; + CHAR msgptr[MQUEUE_STANDARD_NAME_LENGTH]; + struct timespec ts; + struct mq_attr attr = {0}; + mqd_t queue; + INT32 i; + INT32 maxreached = 0; + INT32 ret; + + ret = snprintf_s(qname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq061-1_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MAXMSG5; + queue = mq_open(qname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(queue, (mqd_t)-1, queue, EXIT); + + ts.tv_sec = 0; + ts.tv_nsec = 0; + for (i = 0; i < MAXMSG5 + 1; i++) { + ret = snprintf_s(msgptr, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, "message %d", i); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT); + ts.tv_sec++; + if (mq_timedsend(queue, msgptr, strlen(msgptr), 0, &ts) == -1) { + maxreached = 1; + ICUNIT_GOTO_EQUAL(errno, EAGAIN, errno, EXIT); + break; + } + } + + if ((mq_receive(queue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL) != -1) && (strcmp(msgptr, msgrcd) == 0) && (maxreached != 0)) { + ICUNIT_GOTO_EQUAL(maxreached, 0, maxreached, EXIT); + } + + ret = mq_close(queue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_unlink(qname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + return LOS_OK; +EXIT: + mq_close(queue); +EXIT1: + mq_unlink(qname); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue061 + * @tc.desc: Test interface mq_timedsend + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue061(VOID) +{ + TEST_ADD_CASE("ItPosixQueue061", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_062.c b/testsuites/sample/posix/mqueue/It_posix_queue_062.c new file mode 100644 index 0000000000000000000000000000000000000000..2aa95351df9612d3534800861cba860e02e3be7c --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_062.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + CHAR qname[MQUEUE_STANDARD_NAME_LENGTH], msgrcd[MQUEUE_STANDARD_NAME_LENGTH]; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + struct timespec ts; + mqd_t queue; + struct mq_attr attr = {0}; + INT32 ret; + + ret = snprintf_s(qname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq062-1_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MAXMSG5; + queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(queue, (mqd_t)-1, queue, EXIT1); + + ts.tv_sec = 1; + ts.tv_nsec = 0; + ret = mq_timedsend(queue, msgptr, strlen(msgptr), 0, &ts); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_receive(queue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT); + + ret = strncmp(msgptr, msgrcd, strlen(msgptr)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_close(queue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_unlink(qname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + return LOS_OK; +EXIT: + mq_close(queue); +EXIT2: + mq_unlink(qname); +EXIT1: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue062 + * @tc.desc: Test interface mq_timedsend + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue062(VOID) +{ + TEST_ADD_CASE("ItPosixQueue062", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_063.c b/testsuites/sample/posix/mqueue/It_posix_queue_063.c new file mode 100644 index 0000000000000000000000000000000000000000..78d58dbc73edda04965da5f22f193c467986522c --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_063.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + INT32 ret = 0; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + struct timespec ts; + mqd_t mqueue; + struct mq_attr attr = {0}; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq063_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + mqueue = mq_open(mqname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ts.tv_sec = 1; + ts.tv_nsec = 0; + ret = mq_timedsend((mqd_t)((UINTPTR)mqueue + PER_ADDED_VALUE), msgptr, strlen(msgptr), 0, &ts); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT1); + ICUNIT_GOTO_EQUAL(errno, EBADF, errno, EXIT1); + + ret = mq_receive(mqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT1); + + ret = mq_close(mqueue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + return LOS_OK; +EXIT1: + mq_close(mqueue); +EXIT: + mq_unlink(mqname); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue063 + * @tc.desc: Test interface mq_timedsend + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue063(VOID) +{ + TEST_ADD_CASE("ItPosixQueue063", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_064.c b/testsuites/sample/posix/mqueue/It_posix_queue_064.c new file mode 100644 index 0000000000000000000000000000000000000000..2d63b1c54bbd19fb5893b2b52a911068c938eea0 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_064.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + CHAR qname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + CHAR msgptr[MQUEUE_STANDARD_NAME_LENGTH]; + struct timespec ts; + struct mq_attr attr = {0}; + mqd_t queue; + INT32 i; + INT32 ret; + + ret = snprintf_s(qname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq064-1_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + attr.mq_msgsize = 100; // 100, queue message size. + attr.mq_maxmsg = MAXMSG5; + queue = mq_open(qname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(queue, (mqd_t)-1, queue, EXIT1); + + ts.tv_sec = 1; + ts.tv_nsec = 0; + for (i = 0; i < MAXMSG5; i++) { + ret = snprintf_s(msgptr, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, "message %d", i); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT); + ret = mq_timedsend(queue, msgptr, strlen(msgptr), 0, &ts); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT); + } + + ret = snprintf_s(msgptr, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, "message %d", i); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT); + ret = mq_timedsend(queue, msgptr, strlen(msgptr), 0, &ts); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); + ICUNIT_GOTO_EQUAL(errno, EAGAIN, errno, EXIT); + + ret = mq_close(queue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_unlink(qname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + return LOS_OK; +EXIT: + mq_close(queue); +EXIT2: + mq_unlink(qname); +EXIT1: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue064 + * @tc.desc: Test interface mq_timedsend + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue064(VOID) +{ + TEST_ADD_CASE("ItPosixQueue064", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_065.c b/testsuites/sample/posix/mqueue/It_posix_queue_065.c new file mode 100644 index 0000000000000000000000000000000000000000..0b2d806002861b09d2f6e376f8236d0cab17e223 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_065.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + CHAR qname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + struct timespec ts; + mqd_t queue; + INT32 ret; + + ret = snprintf_s(qname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq065-1_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + ICUNIT_GOTO_NOT_EQUAL(queue, (mqd_t)-1, queue, EXIT1); + + ts.tv_sec = 1; + ts.tv_nsec = 0; + ret = mq_timedsend((mqd_t)(queue + PER_ADDED_VALUE), msgptr, strlen(msgptr), 0, &ts); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); + ICUNIT_GOTO_EQUAL(errno, EBADF, errno, EXIT); + + ret = mq_close(queue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_unlink(qname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + return LOS_OK; +EXIT: + mq_close(queue); +EXIT2: + mq_unlink(qname); +EXIT1: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue065 + * @tc.desc: Test interface mq_timedsend + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue065(VOID) +{ + TEST_ADD_CASE("ItPosixQueue065", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_066.c b/testsuites/sample/posix/mqueue/It_posix_queue_066.c new file mode 100644 index 0000000000000000000000000000000000000000..befb88d2a10ada6b10e2f7286ce4092507cd8269 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_066.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + INT32 ret; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + struct timespec ts; + mqd_t mqueue; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq066_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + mqueue = mq_open(mqname, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR, NULL); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ts.tv_sec = 1; + ts.tv_nsec = 0; + ret = mq_timedsend(mqueue, msgptr, strlen(msgptr), 0, &ts); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT1); + ICUNIT_GOTO_EQUAL(errno, EBADF, errno, EXIT1); + + ret = mq_close(mqueue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + return LOS_OK; +EXIT1: + mq_close(mqueue); +EXIT: + mq_unlink(mqname); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue066 + * @tc.desc: Test interface mq_timedsend + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue066(VOID) +{ + TEST_ADD_CASE("ItPosixQueue066", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_067.c b/testsuites/sample/posix/mqueue/It_posix_queue_067.c new file mode 100644 index 0000000000000000000000000000000000000000..c3c5002194ff09c13ebd5541c8085672bb9f3f0b --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_067.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "It_posix_queue.h" + +static UINT32 Testcase(VOID) +{ + INT32 ret; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + struct timespec ts; + mqd_t mqueue; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "mq067_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ts.tv_sec = 1; + ts.tv_nsec = 0; + ret = mq_timedsend(mqueue, msgptr, strlen(msgptr), 0, &ts); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_close(mqueue); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + return LOS_OK; +EXIT1: + mq_close(mqueue); +EXIT: + mq_unlink(mqname); +EXIT2: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue067 + * @tc.desc: Test interface mq_timedsend + * @tc.type: FUNC + * @tc.require: issueI69NAI + */ + +VOID ItPosixQueue067(VOID) +{ + TEST_ADD_CASE("ItPosixQueue067", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +}