From 54a5365a257044cfaf8105e3740ef1d6b5c8ba18 Mon Sep 17 00:00:00 2001 From: yinjiaming Date: Sun, 9 Oct 2022 15:13:15 +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=20POSIX=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E4=B8=8D=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 继续将 A 核posix 相关的测试用例移植一部分到M核 【影响】 对现有的产品编译不会有影响。 Signed-off-by: yinjiaming Change-Id: I9a7fff077c5bc00609e51ba9121d93dc67895656 --- testsuites/sample/posix/BUILD.gn | 9 ++ .../sample/posix/pthread/It_posix_pthread.c | 9 ++ .../posix/pthread/It_posix_pthread_017.c | 77 +++++++++++++++++ .../posix/pthread/It_posix_pthread_018.c | 76 +++++++++++++++++ .../posix/pthread/It_posix_pthread_019.c | 65 +++++++++++++++ .../posix/pthread/It_posix_pthread_020.c | 72 ++++++++++++++++ .../posix/pthread/It_posix_pthread_021.c | 64 +++++++++++++++ .../posix/pthread/It_posix_pthread_022.c | 82 +++++++++++++++++++ .../posix/pthread/It_posix_pthread_023.c | 63 ++++++++++++++ .../posix/pthread/It_posix_pthread_024.c | 82 +++++++++++++++++++ .../posix/pthread/It_posix_pthread_025.c | 62 ++++++++++++++ 11 files changed, 661 insertions(+) create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_017.c create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_018.c create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_019.c create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_020.c create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_021.c create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_022.c create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_023.c create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_024.c create mode 100644 testsuites/sample/posix/pthread/It_posix_pthread_025.c diff --git a/testsuites/sample/posix/BUILD.gn b/testsuites/sample/posix/BUILD.gn index ac7ac1b1..09bd0758 100644 --- a/testsuites/sample/posix/BUILD.gn +++ b/testsuites/sample/posix/BUILD.gn @@ -45,6 +45,15 @@ static_library("test_posix") { "pthread/It_posix_pthread_014.c", "pthread/It_posix_pthread_015.c", "pthread/It_posix_pthread_016.c", + "pthread/It_posix_pthread_017.c", + "pthread/It_posix_pthread_018.c", + "pthread/It_posix_pthread_019.c", + "pthread/It_posix_pthread_020.c", + "pthread/It_posix_pthread_021.c", + "pthread/It_posix_pthread_022.c", + "pthread/It_posix_pthread_023.c", + "pthread/It_posix_pthread_024.c", + "pthread/It_posix_pthread_025.c", "pthread_func_test.c", ] diff --git a/testsuites/sample/posix/pthread/It_posix_pthread.c b/testsuites/sample/posix/pthread/It_posix_pthread.c index ba84ab3c..fa15677e 100644 --- a/testsuites/sample/posix/pthread/It_posix_pthread.c +++ b/testsuites/sample/posix/pthread/It_posix_pthread.c @@ -62,4 +62,13 @@ VOID ItSuitePosixPthread() ItPosixPthread014(); ItPosixPthread015(); ItPosixPthread016(); + ItPosixPthread017(); + ItPosixPthread018(); + ItPosixPthread019(); + ItPosixPthread020(); + ItPosixPthread021(); + ItPosixPthread022(); + ItPosixPthread023(); + ItPosixPthread024(); + ItPosixPthread025(); } diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_017.c b/testsuites/sample/posix/pthread/It_posix_pthread_017.c new file mode 100644 index 00000000..91b98f70 --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_017.c @@ -0,0 +1,77 @@ +/* + * 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_pthread.h" + +static int g_testCnt; + +static VOID *PthreadF01(VOID *num) +{ + intptr_t i = (intptr_t)num; + PRINTK("Passed argument for thread: %d, g_testCnt = %d\n", (int)i, g_testCnt); + ICUNIT_TRACK_EQUAL(g_testCnt, i, g_testCnt); + g_testCnt++; + + return NULL; +} + +static UINT32 Testcase(VOID) +{ + pthread_t newTh; + long i; + INT32 ret; + + g_testCnt = 1; + + for (i = 1; i < PTHREAD_THREADS_NUM + 1; i++) { + ret = pthread_create(&newTh, NULL, PthreadF01, (void *)i); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_join(newTh, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + } + + return LOS_OK; +EXIT: + pthread_detach(newTh); + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread017 + * @tc.desc: Test interface pthread_create + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread017(VOID) +{ + TEST_ADD_CASE("ItPosixPthread017", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_018.c b/testsuites/sample/posix/pthread/It_posix_pthread_018.c new file mode 100644 index 00000000..49d2aab0 --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_018.c @@ -0,0 +1,76 @@ +/* + * 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_pthread.h" + +static VOID *PthreadF01(VOID *num) +{ + int *arg = (int *)num; + + for (int i = 0; i < PTHREAD_THREADS_NUM; i++) { + dprintf("Passed argument %d for thread\n", arg[i]); + ICUNIT_TRACK_EQUAL(arg[i], i + 1, arg[i]); + } + + return NULL; +} + +static UINT32 Testcase(VOID) +{ + pthread_t newTh; + INT32 arg[PTHREAD_THREADS_NUM], ret; + + for (int i = 0; i < PTHREAD_THREADS_NUM; i++) { + arg[i] = i + 1; + } + + ret = pthread_create(&newTh, NULL, PthreadF01, (void *)&arg); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + ret = pthread_join(newTh, NULL); + ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); + + return LOS_OK; +EXIT: + pthread_detach(newTh); + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread018 + * @tc.desc: Test interface pthread_join + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread018(VOID) +{ + TEST_ADD_CASE("ItPosixPthread018", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_019.c b/testsuites/sample/posix/pthread/It_posix_pthread_019.c new file mode 100644 index 00000000..85ad20db --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_019.c @@ -0,0 +1,65 @@ +/* + * 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_pthread.h" + +static VOID *PthreadF01(VOID *argument) +{ + return NULL; +} + +static UINT32 Testcase(VOID) +{ + pthread_t newTh; + INT32 ret; + + ret = pthread_create(&newTh, NULL, PthreadF01, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_equal(newTh, newTh); + ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread019 + * @tc.desc: Test interface pthread_equal + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread019(VOID) +{ + TEST_ADD_CASE("ItPosixPthread019", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_020.c b/testsuites/sample/posix/pthread/It_posix_pthread_020.c new file mode 100644 index 00000000..87adf3d2 --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_020.c @@ -0,0 +1,72 @@ +/* + * 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_pthread.h" + +static VOID *PthreadF01(VOID *argument) +{ + sleep(1); + return NULL; +} + +static UINT32 Testcase(VOID) +{ + pthread_t newTh1, newTh2; + INT32 ret; + + ret = pthread_create(&newTh1, NULL, PthreadF01, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_create(&newTh2, NULL, PthreadF01, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_equal(newTh1, newTh2); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh1, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh2, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread020 + * @tc.desc: Test interface pthread_equal + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread020(VOID) +{ + TEST_ADD_CASE("ItPosixPthread020", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_021.c b/testsuites/sample/posix/pthread/It_posix_pthread_021.c new file mode 100644 index 00000000..f8d28bcf --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_021.c @@ -0,0 +1,64 @@ +/* + * 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_pthread.h" + +static UINT32 Testcase(VOID) +{ + pthread_attr_t newAttr; + INT32 detachState, ret; + + ret = pthread_attr_init(&newAttr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + /* The test passes if the attribute object has a detachstate of + * PTHREAD_CREATE_JOINABLE, which is the default value for this + * attribute. */ + ret = pthread_attr_getdetachstate(&newAttr, &detachState); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(detachState, PTHREAD_CREATE_JOINABLE, detachState); + + ret = pthread_attr_destroy(&newAttr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread021 + * @tc.desc: Test interface pthread_getdetachstate + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread021(VOID) +{ + TEST_ADD_CASE("ItPosixPthread021", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_022.c b/testsuites/sample/posix/pthread/It_posix_pthread_022.c new file mode 100644 index 00000000..abacd231 --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_022.c @@ -0,0 +1,82 @@ +/* + * 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_pthread.h" + +static INT32 g_pthreadSchedPolicy = 0; + +static VOID *PthreadF01(VOID *argument) +{ + struct sched_param sparam; + INT32 priority, policy; + INT32 ret; + + g_pthreadSchedPolicy = SCHED_RR; + + priority = sched_get_priority_max(g_pthreadSchedPolicy); + + sparam.sched_priority = priority; + + ret = pthread_setschedparam(pthread_self(), g_pthreadSchedPolicy, &sparam); + ICUNIT_TRACK_EQUAL(ret, 0, ret); + + ret = pthread_getschedparam(pthread_self(), &policy, &sparam); + ICUNIT_TRACK_EQUAL(ret, 0, ret); + ICUNIT_TRACK_EQUAL(policy, g_pthreadSchedPolicy, policy); + ICUNIT_TRACK_EQUAL(sparam.sched_priority, priority, sparam.sched_priority); + + return NULL; +} + +static UINT32 Testcase(VOID) +{ + pthread_t newTh; + INT32 ret; + + ret = pthread_create(&newTh, NULL, PthreadF01, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread022 + * @tc.desc: Test interface pthread_setschedparam + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread022(VOID) +{ + TEST_ADD_CASE("ItPosixPthread022", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_023.c b/testsuites/sample/posix/pthread/It_posix_pthread_023.c new file mode 100644 index 00000000..2437b1c6 --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_023.c @@ -0,0 +1,63 @@ +/* + * 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_pthread.h" + +static UINT32 Testcase(VOID) +{ + pthread_attr_t newAttr; + INT32 ret; + + ret = pthread_attr_init(&newAttr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_destroy(&newAttr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_init(&newAttr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_destroy(&newAttr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread023 + * @tc.desc: Test interface pthread_attr_init + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread023(VOID) +{ + TEST_ADD_CASE("ItPosixPthread023", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_024.c b/testsuites/sample/posix/pthread/It_posix_pthread_024.c new file mode 100644 index 00000000..006f7f81 --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_024.c @@ -0,0 +1,82 @@ +/* + * 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_pthread.h" + +static VOID *PthreadF01(VOID *arg) +{ + return NULL; +} + +static UINT32 Testcase(VOID) +{ + pthread_t newTh; + pthread_attr_t attr; + size_t stackSize = PTHREAD_STACK_MIN; + size_t ssize; + INT32 ret; + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_getstacksize(&attr, &ssize); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(ssize, PTHREAD_DEFAULT_STACK_SIZE, ssize); + + ret = pthread_attr_setstacksize(&attr, stackSize); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_getstacksize(&attr, &ssize); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(ssize, stackSize, ssize); + + ret = pthread_create(&newTh, &attr, PthreadF01, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_join(newTh, NULL); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_destroy(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread024 + * @tc.desc: Test interface pthread_attr_getstacksize + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread024(VOID) +{ + TEST_ADD_CASE("ItPosixPthread024", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +} diff --git a/testsuites/sample/posix/pthread/It_posix_pthread_025.c b/testsuites/sample/posix/pthread/It_posix_pthread_025.c new file mode 100644 index 00000000..0d8f0a9b --- /dev/null +++ b/testsuites/sample/posix/pthread/It_posix_pthread_025.c @@ -0,0 +1,62 @@ +/* + * 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_pthread.h" + +static UINT32 Testcase(VOID) +{ + INT32 ret; + pthread_attr_t attr; + + INT32 g_pthreadScopeValue = 999; // 999, init + + ret = pthread_attr_init(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + ret = pthread_attr_setscope(&attr, g_pthreadScopeValue); + ICUNIT_ASSERT_EQUAL(ret, EINVAL, errno); + + ret = pthread_attr_destroy(&attr); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + return LOS_OK; +} + +/** + * @tc.name: ItPosixPthread025 + * @tc.desc: Test interface pthread_attr_setscope + * @tc.type: FUNC + * @tc.require: issueI5TIRQ + */ + +VOID ItPosixPthread025(VOID) +{ + TEST_ADD_CASE("ItPosixPthread025", Testcase, TEST_POSIX, TEST_PTHREAD, TEST_LEVEL2, TEST_FUNCTION); +}