From b483627ec72246276f3c98072a0fc15f8e9baac5 Mon Sep 17 00:00:00 2001 From: yinjiaming Date: Tue, 8 Nov 2022 15:59:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20POSIX=20=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=90=8E=E7=BB=AD=E8=A1=A5=E5=85=85=20=E3=80=90?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E3=80=91=20kernel=5Flitos=5Fm=20=E4=B8=AD?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E8=A1=A5=E5=85=85=20POSIX=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 从 A 核中移植了一部分的POSIX 相关的测试用例 到 sample/posix/mqueue 目录下 【影响】 对现有的产品编译不会有影响 Signed-off-by: yinjiaming Change-Id: I64efeb7d3ae3dbd966b716bf8e296a9eb0f5db06 --- testsuites/sample/posix/BUILD.gn | 17 ++ .../sample/posix/mqueue/It_posix_queue.c | 17 ++ .../sample/posix/mqueue/It_posix_queue.h | 17 ++ .../sample/posix/mqueue/It_posix_queue_036.c | 148 ++++++++++++++++++ .../sample/posix/mqueue/It_posix_queue_037.c | 78 +++++++++ .../sample/posix/mqueue/It_posix_queue_038.c | 98 ++++++++++++ .../sample/posix/mqueue/It_posix_queue_039.c | 79 ++++++++++ .../sample/posix/mqueue/It_posix_queue_040.c | 79 ++++++++++ .../sample/posix/mqueue/It_posix_queue_041.c | 80 ++++++++++ .../sample/posix/mqueue/It_posix_queue_042.c | 58 +++++++ .../sample/posix/mqueue/It_posix_queue_043.c | 81 ++++++++++ .../sample/posix/mqueue/It_posix_queue_044.c | 91 +++++++++++ .../sample/posix/mqueue/It_posix_queue_045.c | 86 ++++++++++ .../sample/posix/mqueue/It_posix_queue_046.c | 87 ++++++++++ .../sample/posix/mqueue/It_posix_queue_047.c | 79 ++++++++++ .../sample/posix/mqueue/It_posix_queue_048.c | 92 +++++++++++ .../sample/posix/mqueue/It_posix_queue_049.c | 93 +++++++++++ .../sample/posix/mqueue/It_posix_queue_050.c | 93 +++++++++++ .../sample/posix/mqueue/It_posix_queue_051.c | 103 ++++++++++++ .../sample/posix/mqueue/It_posix_queue_052.c | 83 ++++++++++ 20 files changed, 1559 insertions(+) create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_036.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_037.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_038.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_039.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_040.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_041.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_042.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_043.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_044.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_045.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_046.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_047.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_048.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_049.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_050.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_051.c create mode 100644 testsuites/sample/posix/mqueue/It_posix_queue_052.c diff --git a/testsuites/sample/posix/BUILD.gn b/testsuites/sample/posix/BUILD.gn index db4a77e3..686fff50 100644 --- a/testsuites/sample/posix/BUILD.gn +++ b/testsuites/sample/posix/BUILD.gn @@ -64,6 +64,23 @@ static_library("test_posix") { "mqueue/It_posix_queue_033.c", "mqueue/It_posix_queue_034.c", "mqueue/It_posix_queue_035.c", + "mqueue/It_posix_queue_036.c", + "mqueue/It_posix_queue_037.c", + "mqueue/It_posix_queue_038.c", + "mqueue/It_posix_queue_039.c", + "mqueue/It_posix_queue_040.c", + "mqueue/It_posix_queue_041.c", + "mqueue/It_posix_queue_042.c", + "mqueue/It_posix_queue_043.c", + "mqueue/It_posix_queue_044.c", + "mqueue/It_posix_queue_045.c", + "mqueue/It_posix_queue_046.c", + "mqueue/It_posix_queue_047.c", + "mqueue/It_posix_queue_048.c", + "mqueue/It_posix_queue_049.c", + "mqueue/It_posix_queue_050.c", + "mqueue/It_posix_queue_051.c", + "mqueue/It_posix_queue_052.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 28845655..abecfd71 100644 --- a/testsuites/sample/posix/mqueue/It_posix_queue.c +++ b/testsuites/sample/posix/mqueue/It_posix_queue.c @@ -87,4 +87,21 @@ VOID ItSuitePosixMqueue(void) ItPosixQueue033(); ItPosixQueue034(); ItPosixQueue035(); + ItPosixQueue036(); + ItPosixQueue037(); + ItPosixQueue038(); + ItPosixQueue039(); + ItPosixQueue040(); + ItPosixQueue041(); + ItPosixQueue042(); + ItPosixQueue043(); + ItPosixQueue044(); + ItPosixQueue045(); + ItPosixQueue046(); + ItPosixQueue047(); + ItPosixQueue048(); + ItPosixQueue049(); + ItPosixQueue050(); + ItPosixQueue051(); + ItPosixQueue052(); } diff --git a/testsuites/sample/posix/mqueue/It_posix_queue.h b/testsuites/sample/posix/mqueue/It_posix_queue.h index 8a2af110..6a931dda 100644 --- a/testsuites/sample/posix/mqueue/It_posix_queue.h +++ b/testsuites/sample/posix/mqueue/It_posix_queue.h @@ -140,4 +140,21 @@ VOID ItPosixQueue032(VOID); VOID ItPosixQueue033(VOID); VOID ItPosixQueue034(VOID); VOID ItPosixQueue035(VOID); +VOID ItPosixQueue036(VOID); +VOID ItPosixQueue037(VOID); +VOID ItPosixQueue038(VOID); +VOID ItPosixQueue039(VOID); +VOID ItPosixQueue040(VOID); +VOID ItPosixQueue041(VOID); +VOID ItPosixQueue042(VOID); +VOID ItPosixQueue043(VOID); +VOID ItPosixQueue044(VOID); +VOID ItPosixQueue045(VOID); +VOID ItPosixQueue046(VOID); +VOID ItPosixQueue047(VOID); +VOID ItPosixQueue048(VOID); +VOID ItPosixQueue049(VOID); +VOID ItPosixQueue050(VOID); +VOID ItPosixQueue051(VOID); +VOID ItPosixQueue052(VOID); #endif diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_036.c b/testsuites/sample/posix/mqueue/It_posix_queue_036.c new file mode 100644 index 00000000..76235e33 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_036.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2022 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 *argument) +{ + INT32 ret; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + + g_testCount = 1; + + TestAssertWaitDelay(&g_testCount, 3); // 3, Here, assert the g_testCount. + + ret = mq_send(g_gqueue, msgptr, strlen(msgptr), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + g_testCount = 2; // 2, Init test count value. + + return NULL; +EXIT: + mq_close(g_gqueue); + mq_unlink(g_gqname); + g_testCount = 0; + return NULL; +} + +static VOID *PthreadF02(VOID *argument) +{ + INT32 ret; + CHAR msgrv[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + + g_testCount = 3; // 3, Init test count value. + + ret = mq_receive(g_gqueue, msgrv, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT); + + ret = MqueueTaskDelay(1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, 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); + + g_testCount = 4; // 4, Init test count value. + return NULL; +EXIT: + mq_close(g_gqueue); +EXIT1: + mq_unlink(g_gqname); +EXIT2: + g_testCount = 0; + return NULL; +} + +static UINT32 Testcase(VOID) +{ + INT32 ret; + struct mq_attr attr = {0}; + pthread_attr_t attr1; + pthread_t newTh1, newTh2; + + (void)snprintf_s(g_gqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, + "/mq036_%d", LOS_CurTaskIDGet()); + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + 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, EXIT3); + + g_testCount = 0; + + ret = PosixPthreadInit(&attr1, MQUEUE_PTHREAD_PRIORITY_TEST1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = pthread_create(&newTh1, &attr1, PthreadF01, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + TestAssertWaitDelay(&g_testCount, 1); + + ret = PosixPthreadInit(&attr1, MQUEUE_PTHREAD_PRIORITY_TEST2); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = pthread_create(&newTh2, &attr1, PthreadF02, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = MqueueTaskDelay(10); // 10, Set delay time. + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + TestAssertWaitDelay(&g_testCount, 4); // 4, Here, assert the g_testCount. + + ret = PosixPthreadDestroy(&attr1, newTh2); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = PosixPthreadDestroy(&attr1, newTh1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + return LOS_OK; +EXIT2: + PosixPthreadDestroy(&attr1, newTh2); +EXIT1: + PosixPthreadDestroy(&attr1, newTh1); +EXIT: + mq_close(g_gqueue); + mq_unlink(g_gqname); +EXIT3: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue036 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue036(VOID) +{ + TEST_ADD_CASE("ItPosixQueue036", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_037.c b/testsuites/sample/posix/mqueue/It_posix_queue_037.c new file mode 100644 index 00000000..ae77e993 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_037.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 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 msgrv[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + mqd_t mqueue; + struct mq_attr attr = {0}; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq037_%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_NONBLOCK | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ret = mq_receive(mqueue, msgrv, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT1); + ICUNIT_GOTO_EQUAL(errno, EAGAIN, 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: ItPosixQueue037 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue037(VOID) +{ + TEST_ADD_CASE("ItPosixQueue037", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_038.c b/testsuites/sample/posix/mqueue/It_posix_queue_038.c new file mode 100644 index 00000000..bf1d1b0c --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_038.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 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 msgrv1[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + CHAR msgrv2[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + const CHAR *msgptr1 = "test message1"; + const CHAR *msgptr2 = "test message2 with differnet length"; + mqd_t mqueue; + struct mq_attr attr = {0}; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq038_%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, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ret = mq_send(mqueue, msgptr1, strlen(msgptr1), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_send(mqueue, msgptr2, strlen(msgptr2), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_receive(mqueue, msgrv1, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, strlen(msgptr1), ret, EXIT1); + + ret = mq_receive(mqueue, msgrv2, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, strlen(msgptr2), ret, EXIT1); + + ret = strcmp(msgptr1, msgrv1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = strcmp(msgptr2, msgrv2); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = strcmp(msgrv1, msgrv2); + ICUNIT_GOTO_NOT_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: ItPosixQueue038 + * @tc.desc: Test interface mq_send + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue038(VOID) +{ + TEST_ADD_CASE("ItPosixQueue038", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_039.c b/testsuites/sample/posix/mqueue/It_posix_queue_039.c new file mode 100644 index 00000000..a56d0dee --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_039.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 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 mqname[MQUEUE_STANDARD_NAME_LENGTH], msgrv[MQUEUE_STANDARD_NAME_LENGTH]; + mqd_t mqdes; + struct mq_attr attr = {0}; + INT32 unresolved = 0; + INT32 failure = 0; + INT32 ret = 0; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq039-1-%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + mqdes = mq_open(mqname, O_CREAT | O_NONBLOCK | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqdes, (mqd_t)-1, mqdes, EXIT1); + + ret = mq_receive(mqdes, msgrv, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); + ICUNIT_GOTO_EQUAL(errno, EAGAIN, errno, EXIT); + + ret = mq_close(mqdes); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + return LOS_OK; +EXIT: + mq_close(mqdes); +EXIT2: + mq_unlink(mqname); +EXIT1: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue039 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue039(VOID) +{ + TEST_ADD_CASE("ItPosixQueue039", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_040.c b/testsuites/sample/posix/mqueue/It_posix_queue_040.c new file mode 100644 index 00000000..c386e666 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_040.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 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] = ""; + mqd_t mqueue; + CHAR msgrv[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + struct mq_attr attr = {0}; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq040_%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, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + mqueue = (mqd_t)((UINTPTR)mqueue + PER_ADDED_VALUE); + ret = mq_receive(mqueue, msgrv, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT1); + ICUNIT_GOTO_EQUAL(errno, EBADF, errno, EXIT1); + + ret = mq_close((mqd_t)((UINTPTR)mqueue - PER_ADDED_VALUE)); + 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: ItPosixQueue040 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue040(VOID) +{ + TEST_ADD_CASE("ItPosixQueue040", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_041.c b/testsuites/sample/posix/mqueue/It_posix_queue_041.c new file mode 100644 index 00000000..7262e679 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_041.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 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 mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqdes; + CHAR msgrv[MQUEUE_STANDARD_NAME_LENGTH]; + struct mq_attr attr = {0}; + INT32 unresolved = 0; + INT32 failure = 0; + INT32 ret = 0; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq041-2-%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + mqdes = mq_open(mqname, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqdes, (mqd_t)-1, mqdes, EXIT1); + + ret = mq_receive(mqdes, msgrv, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); + ICUNIT_GOTO_EQUAL(errno, EBADF, errno, EXIT); + + ret = mq_close(mqdes); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + return LOS_OK; +EXIT: + mq_close(mqdes); +EXIT2: + mq_unlink(mqname); +EXIT1: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue041 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue041(VOID) +{ + TEST_ADD_CASE("ItPosixQueue041", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_042.c b/testsuites/sample/posix/mqueue/It_posix_queue_042.c new file mode 100644 index 00000000..8ef78aee --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_042.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 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] = ""; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq042_%d", LOS_CurTaskIDGet()); + ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); + + ret = mq_unlink(mqname); + ICUNIT_ASSERT_EQUAL(ret, -1, ret); + ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno); + + return LOS_OK; +} + +/** + * @tc.name: ItPosixQueue042 + * @tc.desc: Test interface mq_unlink + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue042(VOID) +{ + TEST_ADD_CASE("ItPosixQueue042", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_043.c b/testsuites/sample/posix/mqueue/It_posix_queue_043.c new file mode 100644 index 00000000..94181daf --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_043.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 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 mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqdes; + struct mq_attr mqstat; + INT32 unresolved = 0; + INT32 failure = 0; + INT32 ret = 0; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq043-1_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + mqdes = mq_open(mqname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, NULL); + ICUNIT_GOTO_NOT_EQUAL(mqdes, (mqd_t)-1, mqdes, EXIT1); + + ret = memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_getattr(mqdes, &mqstat); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_close(mqdes); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ICUNIT_ASSERT_NOT_EQUAL((mqstat.mq_flags & O_NONBLOCK), 0, ret); + + return LOS_OK; +EXIT: + mq_close(mqdes); +EXIT2: + mq_unlink(mqname); +EXIT1: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue043 + * @tc.desc: Test interface mq_getattr + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue043(VOID) +{ + TEST_ADD_CASE("ItPosixQueue043", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_044.c b/testsuites/sample/posix/mqueue/It_posix_queue_044.c new file mode 100644 index 00000000..ed327882 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_044.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022 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] = ""; + mqd_t mqueue; + struct mq_attr mqstat1 = {0}; + struct mq_attr mqstat2 = {0}; + + (void)snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH - 1, MQUEUE_STANDARD_NAME_LENGTH, "/mq044_%d", + LOS_CurTaskIDGet()); + + mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ret = memset_s(&mqstat1, sizeof(mqstat1), 0, sizeof(mqstat1)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + ret = memset_s(&mqstat2, sizeof(mqstat2), 0, sizeof(mqstat2)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_getattr(mqueue, &mqstat1); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + mqstat1.mq_flags |= O_NONBLOCK; + ret = mq_setattr(mqueue, &mqstat1, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_getattr(mqueue, &mqstat2); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + ICUNIT_GOTO_EQUAL(mqstat2.mq_flags, mqstat1.mq_flags, mqstat2.mq_flags, EXIT1); + ICUNIT_GOTO_EQUAL(mqstat2.mq_curmsgs, 0, mqstat2.mq_curmsgs, EXIT1); + ICUNIT_GOTO_EQUAL(mqstat2.mq_flags, O_CREAT | O_RDWR | O_NONBLOCK, mqstat2.mq_flags, EXIT1); + ICUNIT_GOTO_EQUAL(mqstat2.mq_maxmsg, mqstat1.mq_maxmsg, mqstat2.mq_maxmsg, EXIT1); + ICUNIT_GOTO_EQUAL(mqstat2.mq_msgsize, mqstat1.mq_msgsize, mqstat2.mq_msgsize, 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: ItPosixQueue044 + * @tc.desc: Test interface mq_getattr + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue044(VOID) +{ + TEST_ADD_CASE("ItPosixQueue044", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL0, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_045.c b/testsuites/sample/posix/mqueue/It_posix_queue_045.c new file mode 100644 index 00000000..703195c9 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_045.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2022 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 mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqdes; + struct mq_attr mqstat, nmqstat; + INT32 unresolved = 0; + INT32 failure = 0; + INT32 ret = 0; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq045-1_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + ret = memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + mqstat.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + mqstat.mq_maxmsg = 40; // 40, queue max message size. + mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &mqstat); + ICUNIT_GOTO_NOT_EQUAL(mqdes, (mqd_t)-1, mqdes, EXIT1); + + ret = memset_s(&nmqstat, sizeof(nmqstat), 0, sizeof(nmqstat)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_getattr(mqdes, &nmqstat); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ICUNIT_GOTO_EQUAL(mqstat.mq_maxmsg, nmqstat.mq_maxmsg, mqstat.mq_maxmsg, EXIT); + ICUNIT_GOTO_EQUAL(mqstat.mq_msgsize, nmqstat.mq_msgsize, mqstat.mq_msgsize, EXIT); + + ret = mq_close(mqdes); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + return LOS_OK; +EXIT: + mq_close(mqdes); +EXIT2: + mq_unlink(mqname); +EXIT1: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue045 + * @tc.desc: Test interface mq_getattr + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue045(VOID) +{ + TEST_ADD_CASE("ItPosixQueue045", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_046.c b/testsuites/sample/posix/mqueue/It_posix_queue_046.c new file mode 100644 index 00000000..d0305762 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_046.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 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; + INT32 i; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + const CHAR *msgptr = "test message"; + mqd_t mqueue; + struct mq_attr mqstat; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq046_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + ret = memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + mqstat.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + mqstat.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &mqstat); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + for (i = 0; i < 5; i++) { // 5, the loop frequency. + ret = mq_send(mqueue, msgptr, strlen(msgptr), 0); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + } + ret = memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + ret = mq_getattr(mqueue, &mqstat); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + ICUNIT_GOTO_EQUAL(mqstat.mq_curmsgs, 5, mqstat.mq_curmsgs, EXIT1); // 5, assert the curmsgs. + + 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: ItPosixQueue046 + * @tc.desc: Test interface mq_getattr + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue046(VOID) +{ + TEST_ADD_CASE("ItPosixQueue046", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_047.c b/testsuites/sample/posix/mqueue/It_posix_queue_047.c new file mode 100644 index 00000000..5ed46e59 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_047.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 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] = ""; + mqd_t mqueue, mqdesInvalid; + struct mq_attr mqstat; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq047_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + mqdesInvalid = (mqd_t)((UINTPTR)mqueue + PER_ADDED_VALUE); + ret = memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_getattr(mqdesInvalid, &mqstat); + 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: ItPosixQueue047 + * @tc.desc: Test interface mq_getattr + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue047(VOID) +{ + TEST_ADD_CASE("ItPosixQueue047", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_048.c b/testsuites/sample/posix/mqueue/It_posix_queue_048.c new file mode 100644 index 00000000..7002ae78 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_048.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 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 mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqdes; + struct mq_attr mqstat = {0}; + struct mq_attr nmqstat = {0}; + INT32 unresolved = 0; + INT32 failure = 0; + INT32 ret = 0; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq048-1_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); + ICUNIT_GOTO_NOT_EQUAL(mqdes, (mqd_t)-1, mqdes, EXIT1); + + ret = memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + ret = memset_s(&nmqstat, sizeof(nmqstat), 0, sizeof(nmqstat)); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = mq_getattr(mqdes, &mqstat); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT); + + mqstat.mq_flags |= O_NONBLOCK; + + ret = mq_setattr(mqdes, &mqstat, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_getattr(mqdes, &nmqstat); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT); + + ret = mq_close(mqdes); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT2); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ICUNIT_GOTO_EQUAL(nmqstat.mq_flags, mqstat.mq_flags, nmqstat.mq_flags, EXIT1); + + return LOS_OK; +EXIT: + mq_close(mqdes); +EXIT2: + mq_unlink(mqname); +EXIT1: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue048 + * @tc.desc: Test interface mq_setattr + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue048(VOID) +{ + TEST_ADD_CASE("ItPosixQueue048", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_049.c b/testsuites/sample/posix/mqueue/It_posix_queue_049.c new file mode 100644 index 00000000..5b3700e4 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_049.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2022 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] = ""; + mqd_t mqueue; + struct mq_attr mqstat1 = {0}; + struct mq_attr mqstat2 = {0}; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq049_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ret = memset_s(&mqstat1, sizeof(mqstat1), 0, sizeof(mqstat1)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + ret = memset_s(&mqstat2, sizeof(mqstat2), 0, sizeof(mqstat1)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_getattr(mqueue, &mqstat1); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT1); + + mqstat1.mq_maxmsg = mqstat1.mq_maxmsg + 1; + mqstat1.mq_msgsize = mqstat1.mq_msgsize + 1; + mqstat1.mq_curmsgs = mqstat1.mq_curmsgs + 1; + + ret = mq_setattr(mqueue, &mqstat1, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_getattr(mqueue, &mqstat2); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + ICUNIT_GOTO_NOT_EQUAL(mqstat2.mq_maxmsg, mqstat1.mq_maxmsg, mqstat2.mq_maxmsg, EXIT1); + ICUNIT_GOTO_NOT_EQUAL(mqstat2.mq_msgsize, mqstat1.mq_msgsize, mqstat2.mq_msgsize, EXIT1); + ICUNIT_GOTO_NOT_EQUAL(mqstat2.mq_curmsgs, mqstat1.mq_curmsgs, mqstat2.mq_curmsgs, 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: ItPosixQueue049 + * @tc.desc: Test interface mq_setattr + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue049(VOID) +{ + TEST_ADD_CASE("ItPosixQueue049", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_050.c b/testsuites/sample/posix/mqueue/It_posix_queue_050.c new file mode 100644 index 00000000..e41e18b5 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_050.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2022 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] = ""; + mqd_t mqueue1, mqueue2; + struct mq_attr mqstat1; + struct mq_attr mqstat2; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq050_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT3); + + mqueue1 = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); + ICUNIT_GOTO_NOT_EQUAL(mqueue1, (mqd_t)-1, mqueue1, EXIT3); + + mqueue2 = mqueue1; + mqueue1 = (mqd_t)((UINTPTR)mqueue1 + PER_ADDED_VALUE); + + ret = memset_s(&mqstat1, sizeof(mqstat1), 0, sizeof(mqstat1)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + ret = memset_s(&mqstat2, sizeof(mqstat2), 0, sizeof(mqstat2)); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + mqstat2.mq_flags = 1; + + ret = mq_setattr(mqueue1, &mqstat1, NULL); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT2); + ICUNIT_GOTO_EQUAL(errno, EBADF, errno, EXIT2); + + ret = mq_close(mqueue1); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT1); + + ret = mq_close(mqueue2); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = mq_close(mqueue2); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); + + ret = mq_unlink(mqname); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT3); + + return LOS_OK; +EXIT2: + mq_close(mqueue1); +EXIT1: + mq_close(mqueue2); +EXIT: + mq_unlink(mqname); +EXIT3: + return LOS_NOK; +} + +/** + * @tc.name: ItPosixQueue050 + * @tc.desc: Test interface mq_setattr + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue050(VOID) +{ + TEST_ADD_CASE("ItPosixQueue050", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_051.c b/testsuites/sample/posix/mqueue/It_posix_queue_051.c new file mode 100644 index 00000000..4456a336 --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_051.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2022 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; + mqd_t mqueue; + struct mq_attr attr = {0}; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + CHAR *msgptr1 = "1234567890"; + CHAR *msgptr2 = "2345678901"; + CHAR *msgptr3 = "3456789012"; + CHAR msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0}; + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq051_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ret = mq_send(mqueue, msgptr1, strlen(msgptr1), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_send(mqueue, msgptr2, strlen(msgptr2), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_send(mqueue, msgptr3, strlen(msgptr3), 0); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT1); + + ret = mq_receive(mqueue, msgrcd, 0, NULL); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT1); + ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT1); + + ret = mq_receive(mqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT1); + ICUNIT_GOTO_STRING_EQUAL(msgrcd, msgptr1, msgrcd, EXIT1); + + ret = mq_receive(mqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT1); + ICUNIT_GOTO_STRING_EQUAL(msgrcd, msgptr2, msgrcd, EXIT1); + + ret = mq_receive(mqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL); + ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT1); + ICUNIT_GOTO_STRING_EQUAL(msgrcd, msgptr3, msgrcd, 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: ItPosixQueue051 + * @tc.desc: Test interface mq_receive + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue051(VOID) +{ + TEST_ADD_CASE("ItPosixQueue051", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/mqueue/It_posix_queue_052.c b/testsuites/sample/posix/mqueue/It_posix_queue_052.c new file mode 100644 index 00000000..a84aceea --- /dev/null +++ b/testsuites/sample/posix/mqueue/It_posix_queue_052.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 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; + INT32 i; + const CHAR *msgptr = MQUEUE_SEND_STRING_TEST; + CHAR mqname[MQUEUE_STANDARD_NAME_LENGTH] = ""; + mqd_t mqueue; + struct mq_attr attr = {0}; + + attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH; + attr.mq_maxmsg = MQUEUE_STANDARD_NAME_LENGTH; + + ret = snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, \ + "/mq052_%d", LOS_CurTaskIDGet()); + ICUNIT_GOTO_NOT_EQUAL(ret, -1, ret, EXIT2); + + mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT2); + + ret = mq_send(mqueue, NULL, 0, 0); + ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT1); + + for (i = 0; i < 3; i++) { // 3, the loop frequency. + ret = mq_send(mqueue, msgptr, strlen(msgptr), 0); + 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: ItPosixQueue052 + * @tc.desc: Test interface mq_send + * @tc.type: FUNC + * @tc.require: issueI61YO0 + */ + +VOID ItPosixQueue052(VOID) +{ + TEST_ADD_CASE("ItPosixQueue052", Testcase, TEST_POSIX, TEST_QUE, TEST_LEVEL2, TEST_FUNCTION); +}