diff --git a/components/shell/include/shmsg.h b/components/shell/include/shmsg.h index c9cb4b2a15488774ae2638f6143304da63b7bfdb..be2f4f485f8d5f946316f2e6d24559ba44d3055f 100644 --- a/components/shell/include/shmsg.h +++ b/components/shell/include/shmsg.h @@ -44,6 +44,10 @@ extern "C" { extern UINT32 ShellMsgTypeGet(CmdParsed *cmdParsed, const CHAR *cmdType); extern VOID ExecCmdline(const CHAR *cmdline); +#if (LOSCFG_USE_SHELL == 1) +UINT32 LOS_ShellInit(VOID); +#endif + #define SHELL_CMD_PARSE_EVENT 0x111 #define SH_OK 0 diff --git a/components/shell/src/base/shmsg.c b/components/shell/src/base/shmsg.c index 8cc37ff28eebfa4e4ce56196bc31fc97100e1ed4..bf044d73b5b2f995e76046c9d0544f5e776a1b23 100644 --- a/components/shell/src/base/shmsg.c +++ b/components/shell/src/base/shmsg.c @@ -245,7 +245,7 @@ VOID ShellTaskEntry(VOID) } } -LITE_OS_SEC_TEXT_MINOR UINT32 LosShellInit(VOID) +LITE_OS_SEC_TEXT_MINOR UINT32 LOS_ShellInit(VOID) { UINT32 ret; UINT32 taskID1; diff --git a/testsuites/kernel_lite/BUILD.gn b/testsuites/kernel_lite/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..a4d66b182a03d2ce6795871381fba69a3371c010 --- /dev/null +++ b/testsuites/kernel_lite/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("ActsKernelTest") { + deps = [ + "futex_posix:ActsFutexApiTest", + "io_posix:ActsIoApiTest", + "ipc_posix:ActsKernelIPCTest", + "kernelcmsis_hal:ActsCMSISTest", + "math_posix:ActsMathApiTest", + "mem_posix:ActsMemApiTest", + # "net_posix:ActsNetTest", # support qemu_mini_system_demo + "process_posix:ActsProcessApiTest", + "sched_posix:ActsSchedApiTest", + "sys_posix:ActsSysApiTest", + "time_posix:ActsTimeApiTest", + "utils:libutils", + "utils:libmt_utils", + "utils:libfs" + ] + deps += ["//base/startup/init/interfaces/innerkits:libbegetutil"] +} diff --git a/testsuites/kernel_lite/futex_posix/BUILD.gn b/testsuites/kernel_lite/futex_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..2d576ca27e7b3153bf6925e8a59a9553cc02fae6 --- /dev/null +++ b/testsuites/kernel_lite/futex_posix/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsFutexApiTest") { + suite_name = "acts" + sources = [ + "src/FutexTest.c", + "src/PthreadCondTest.c", + "src/PthreadMutexTest.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + ] + + cflags = [ "-Wno-sign-compare" ] +} diff --git a/testsuites/kernel_lite/futex_posix/Test.json b/testsuites/kernel_lite/futex_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..8de09ad42aba14365b6d70ecc941e7710ffbfc5b --- /dev/null +++ b/testsuites/kernel_lite/futex_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix futex api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsFutexApiTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/futex_posix/src/FutexTest.c b/testsuites/kernel_lite/futex_posix/src/FutexTest.c new file mode 100755 index 0000000000000000000000000000000000000000..e002bf2c23f6ed28375826e49cc78f674cf17b7c --- /dev/null +++ b/testsuites/kernel_lite/futex_posix/src/FutexTest.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "FutexTest.h" +#include +#include "log.h" + +void ChildAssertEQ(int src, int des) +{ + if (src != des) { + LOG("> src = %d, but des = %d", src, des); + return 1; + } +} + +int ChildExpectEQ(int src, int des) +{ + if (src != des) { + LOG("> src = %d, but des = %d", src, des); + return 1; + } + return 0; +} diff --git a/testsuites/kernel_lite/futex_posix/src/FutexTest.h b/testsuites/kernel_lite/futex_posix/src/FutexTest.h new file mode 100755 index 0000000000000000000000000000000000000000..c4ce6fe66e493b6e6ba8b70c4d9f94d659d6458d --- /dev/null +++ b/testsuites/kernel_lite/futex_posix/src/FutexTest.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KERNEL_LITE_FUTEX_TEST_H +#define KERNEL_LITE_FUTEX_TEST_H + +#define DEF_PROCESS_CONDATTR_CLOCK CLOCK_REALTIME + +void ChildAssertEQ(int src, int des); +int ChildExpectEQ(int src, int des); + +#endif \ No newline at end of file diff --git a/testsuites/kernel_lite/futex_posix/src/PthreadCondTest.c b/testsuites/kernel_lite/futex_posix/src/PthreadCondTest.c new file mode 100755 index 0000000000000000000000000000000000000000..38e4c94e524c896c57aa27218d91025712bfd3cc --- /dev/null +++ b/testsuites/kernel_lite/futex_posix/src/PthreadCondTest.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include "utils.h" +#include "log.h" +#include "KernelConstants.h" +#include "FutexTest.h" +#include "mt_utils.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(FUTEX, PthreadCondApiTest, PthreadCondApiTestSuite); + +static BOOL PthreadCondApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL PthreadCondApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_COND_INIT_0100 + * @tc.name pthread_cond_init initializes condition variables + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadCondApiTestSuite, testPthreadCondInit, Function | MediumTest | Level2) +{ + pthread_condattr_t condattr; + TEST_ASSERT_EQUAL_INT(0, pthread_condattr_init(&condattr)); + pthread_cond_t cond1; + TEST_ASSERT_EQUAL_INT(0, pthread_cond_init(&cond1, &condattr)); + + pthread_cond_t cond2; + TEST_ASSERT_EQUAL_INT(0, pthread_cond_init(&cond2, NULL)); +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_COND_DESTROY_0100 + * @tc.name pthread_cond_destroy destroy condition variables + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadCondApiTestSuite, testPthreadCondDestroy, Function | MediumTest | Level3) +{ + pthread_condattr_t condattr; + TEST_ASSERT_EQUAL_INT(0, pthread_condattr_init(&condattr)); + pthread_cond_t cond1; + TEST_ASSERT_EQUAL_INT(0, pthread_cond_init(&cond1, &condattr)); + TEST_ASSERT_EQUAL_INT(0, pthread_cond_destroy(&cond1)); + + pthread_cond_t cond2; + TEST_ASSERT_EQUAL_INT(0, pthread_cond_init(&cond2, NULL)); + TEST_ASSERT_EQUAL_INT(0, pthread_cond_destroy(&cond2)); + + pthread_cond_t cond3 = PTHREAD_COND_INITIALIZER; + TEST_ASSERT_EQUAL_INT(0, pthread_cond_destroy(&cond3)); +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_CONDATTR_INIT_0100 + * @tc.name Init and destroy operations + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadCondApiTestSuite, testPthreadCondattrInit, Function | MediumTest | Level2) +{ + pthread_condattr_t condattr; + + TEST_ASSERT_EQUAL_INT(0, pthread_condattr_init(&condattr)); + TEST_ASSERT_EQUAL_INT(0, pthread_condattr_destroy(&condattr)); + TEST_ASSERT_EQUAL_INT(0, pthread_condattr_init(&condattr)); +} + +pthread_mutex_t g_mtx3 = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t g_cond3 = PTHREAD_COND_INITIALIZER; + +// pthread_cond_broadcast +void *ThreadPthreadCondBroadcast1(void *arg) +{ + int *testIntP = (int *)arg; + Msleep(20); + TEST_ASSERT_EQUAL_INT(pthread_mutex_lock(&g_mtx3), 0); + *testIntP = 10; + TEST_ASSERT_EQUAL_INT(pthread_cond_broadcast(&g_cond3), 0); + TEST_ASSERT_EQUAL_INT(pthread_mutex_unlock(&g_mtx3), 0); + return arg; +} + +// pthread_cond_wait +void *ThreadPthreadCondBroadcast2(void *arg) +{ + int *testIntP = (int *)arg; + TEST_ASSERT_EQUAL_INT(0, pthread_mutex_lock(&g_mtx3)); + TEST_ASSERT_EQUAL_INT(0, pthread_cond_wait(&g_cond3, &g_mtx3)); + (*testIntP)++; + TEST_ASSERT_EQUAL_INT(0, pthread_mutex_unlock(&g_mtx3)); + return arg; +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_COND_BROADCAST_0100 + * @tc.name Use pthread_cond_broadcast to release conditional semaphore + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadCondApiTestSuite, testPthreadCondBroadcast, Function | MediumTest | Level3) +{ + pthread_t tid[3]; + int testInt = 0; + + TEST_ASSERT_EQUAL_INT(0, pthread_create(&tid[0], NULL, ThreadPthreadCondBroadcast1, (void*)&testInt)); + TEST_ASSERT_EQUAL_INT(0, pthread_create(&tid[1], NULL, ThreadPthreadCondBroadcast2, (void*)&testInt)); + TEST_ASSERT_EQUAL_INT(0, pthread_create(&tid[2], NULL, ThreadPthreadCondBroadcast2, (void*)&testInt)); + + Msleep(100); + pthread_join(tid[0], NULL); + pthread_join(tid[1], NULL); + pthread_join(tid[2], NULL); + TEST_ASSERT_EQUAL_INT(0, pthread_cond_destroy(&g_cond3)); + TEST_ASSERT_EQUAL_INT(0, pthread_mutex_destroy(&g_mtx3)); + TEST_ASSERT_EQUAL_INT(12, testInt); +} + +RUN_TEST_SUITE(PthreadCondApiTestSuite); diff --git a/testsuites/kernel_lite/futex_posix/src/PthreadMutexTest.c b/testsuites/kernel_lite/futex_posix/src/PthreadMutexTest.c new file mode 100755 index 0000000000000000000000000000000000000000..4f131050eaa719b17a8ebfd43f965bbf9fb72891 --- /dev/null +++ b/testsuites/kernel_lite/futex_posix/src/PthreadMutexTest.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" +#include "mt_utils.h" +#include "log.h" +#include "FutexTest.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(FUTEX, PthreadMutexApiTest, PthreadMutexApiTestSuite); + +static BOOL PthreadMutexApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL PthreadMutexApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/********************************************* Test case dividing line ***********************************************/ + +struct PthreadMutexCond { + int loopNum; + int countMax; + int count; + int top; + int bottom; + pthread_cond_t notfull; + pthread_cond_t notempty; + pthread_mutex_t mutex; +}; + +struct PthreadMutexCond g_st1; +void g_st1Init(void) +{ + memset(&g_st1, 0, sizeof(struct PthreadMutexCond)); + g_st1.loopNum = 10; + g_st1.countMax = 5; + g_st1.count = 0; + g_st1.top = 0; + g_st1.bottom = 0; + g_st1.notfull = (pthread_cond_t)PTHREAD_COND_INITIALIZER; + g_st1.notempty = (pthread_cond_t)PTHREAD_COND_INITIALIZER; + g_st1.mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; +} + +void *PthreadProduce(void *arg) +{ + for (int i = 0; i < g_st1.loopNum; i++) { + TEST_ASSERT_EQUAL_INT(pthread_mutex_lock(&g_st1.mutex), 0); + // check full + if ((g_st1.top + 1) % g_st1.countMax == g_st1.bottom) { + TEST_ASSERT_EQUAL_INT(pthread_cond_wait(&g_st1.notempty, &g_st1.mutex), 0); + } + // Produce + g_st1.top = (g_st1.top + 1) % g_st1.countMax; + g_st1.count++; + printf("producer g_st1.top = %d", g_st1.top); + + TEST_ASSERT_EQUAL_INT(pthread_cond_signal(&g_st1.notempty), 0); + TEST_ASSERT_EQUAL_INT(pthread_mutex_unlock(&g_st1.mutex), 0); + Msleep(10); + } + return arg; +} + +void *PthreadConsume(void *arg) +{ + for (int i = 0; i < g_st1.loopNum; i++) { + TEST_ASSERT_EQUAL_INT(pthread_mutex_lock(&g_st1.mutex), 0); + // check empty + if (g_st1.top == g_st1.bottom) { + TEST_ASSERT_EQUAL_INT(pthread_cond_wait(&g_st1.notempty, &g_st1.mutex), 0); + } + // Consume + g_st1.bottom = (g_st1.bottom + 1) % g_st1.countMax; + g_st1.count--; + LOG("consume g_st1.bottom = %d", g_st1.bottom); + + TEST_ASSERT_EQUAL_INT(pthread_cond_signal(&g_st1.notempty), 0); + TEST_ASSERT_EQUAL_INT(pthread_mutex_unlock(&g_st1.mutex), 0); + + Msleep(10); + } + return arg; +} + +/** + * @tc.number SUB_KERNEL_FUTEX_MUTEX_ALL_0300 + * @tc.name test pthread_mutex with condition variable, produce and consume + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadMutexApiTestSuite, testPthreadMutexCond, Function | MediumTest | Level3) +{ + pthread_t tid[2]; + + // g_st1Init(); + g_st1.count = 0; + + memset(tid, 0, sizeof(tid)); + TEST_ASSERT_EQUAL_INT(pthread_create(&tid[0], NULL, PthreadProduce, NULL), 0); + TEST_ASSERT_EQUAL_INT(pthread_create(&tid[1], NULL, PthreadConsume, NULL), 0); + TEST_ASSERT_EQUAL_INT(pthread_join(tid[0], NULL), 0); + TEST_ASSERT_EQUAL_INT(pthread_join(tid[1], NULL), 0); + TEST_ASSERT_EQUAL_INT(g_st1.count, 0); +} + +RUN_TEST_SUITE(PthreadMutexApiTestSuite); diff --git a/testsuites/kernel_lite/io_posix/BUILD.gn b/testsuites/kernel_lite/io_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..bbc58f488fbe1ea66aebee07cd1dc0db1a741fe0 --- /dev/null +++ b/testsuites/kernel_lite/io_posix/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsIoApiTest") { + suite_name = "acts" + sources = [ + "src/IoTestOther.c", + "src/IoTestStdio.c", + "src/IoTestStdlib.c", + "src/IoTestString.c", + "src/IoTestStrings.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils", + "//third_party/bounds_checking_function/include", + ] + deps = [ + "//third_party/bounds_checking_function:libsec_shared", + ] +} diff --git a/testsuites/kernel_lite/io_posix/Test.json b/testsuites/kernel_lite/io_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..c25466f77c6ca6a90488fb4c61c9d54020d89908 --- /dev/null +++ b/testsuites/kernel_lite/io_posix/Test.json @@ -0,0 +1,26 @@ + +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsIoApiTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/io_posix/src/IoTest.h b/testsuites/kernel_lite/io_posix/src/IoTest.h new file mode 100755 index 0000000000000000000000000000000000000000..84f8811c2fbf25437a60db5495650bc99651aaa1 --- /dev/null +++ b/testsuites/kernel_lite/io_posix/src/IoTest.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KERNEL_LITE_IO_TEST_H +#define KERNEL_LITE_IO_TEST_H + +#include +#include "log.h" +#include "utils.h" + +#define IOTEST_TEMPFILE "/littlefs/io_posix_test.txt" + +#define INIT_TEST_FILE(fp) do { \ + FOPEN_WRITE(fp); \ + TEST_ASSERT_NOT_EQUAL(fputs("hello world", fp), -1) \ + TEST_ASSERT_NOT_EQUAL(fclose(fp), -1); \ +} while (0) + +#define FOPEN_WRITE(fp) do { \ + fp = fopen(IOTEST_TEMPFILE, "w"); \ + TEST_ASSERT_NOT_EQUAL(NULL, fp); \ +} while (0) + +#define FOPEN_READ(fp) do { \ + fp = fopen(IOTEST_TEMPFILE, "r"); \ + TEST_ASSERT_NOT_EQUAL(fp, NULL); \ +} while (0) + +#define FILENO(fp) do { \ + fd = fileno(fp); \ + TEST_ASSERT_NOT_EQUAL(fd, -1); \ +} while (0) + +#endif diff --git a/testsuites/kernel_lite/io_posix/src/IoTestOther.c b/testsuites/kernel_lite/io_posix/src/IoTestOther.c new file mode 100755 index 0000000000000000000000000000000000000000..d8a218cf5a8ed8fc4524c67cae701ebb479198da --- /dev/null +++ b/testsuites/kernel_lite/io_posix/src/IoTestOther.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + +#include "IoTest.h" +#include + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(IO, IoOther, IoOtherTestSuite); + +static BOOL IoOtherTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IoOtherTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_IO_OTHER_0900 + * @tc.name strptime basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoOtherTestSuite, testStrptime, Function | MediumTest | Level1) +{ + struct tm tm; + memset_s(&tm, sizeof(struct tm), 0, sizeof(struct tm)); + char *ret = strptime("2020-10-29 21:24:00abc", "%Y-%m-%d %H:%M:%S", &tm); + EXPECT_STREQ(ret, "abc"); + EXPECT_EQ(tm.tm_year, 120); + EXPECT_EQ(tm.tm_mon, 9); + EXPECT_EQ(tm.tm_mday, 29); + EXPECT_EQ(tm.tm_hour, 21); + EXPECT_EQ(tm.tm_min, 24); + + ret = strptime("14 Oct October 20 09:24:00 Sat Saturday 363", "%d %b %B %y %I:%M:%S %a %A %j", &tm); + EXPECT_STREQ(ret, ""); + EXPECT_EQ(tm.tm_year, 120); + EXPECT_EQ(tm.tm_mon, 9); + EXPECT_EQ(tm.tm_mday, 14); + EXPECT_EQ(tm.tm_hour, 9); + EXPECT_EQ(tm.tm_wday, 6); + EXPECT_EQ(tm.tm_yday, 362); +} + +RUN_TEST_SUITE(IoOtherTestSuite); diff --git a/testsuites/kernel_lite/io_posix/src/IoTestStdio.c b/testsuites/kernel_lite/io_posix/src/IoTestStdio.c new file mode 100755 index 0000000000000000000000000000000000000000..bd08b1b92c0f392ff3db8c44bb74baa87635ad43 --- /dev/null +++ b/testsuites/kernel_lite/io_posix/src/IoTestStdio.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include + +#include "libfs.h" +#include "utils.h" +#include "IoTest.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(IO, IoStdio, IoStdioTestSuite); + +static BOOL IoStdioTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IoStdioTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +int FormatVsnprintf(char *format, ...) +{ + va_list vArgList; + va_start(vArgList, format); + char str[50] = {0}; + int ret = vsnprintf(str, sizeof(str), format, vArgList); + va_end(vArgList); + return ret; +} + +/** + * @tc.number SUB_KERNEL_IO_STDIO_2100 + * @tc.name vsnprintf basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStdioTestSuite, testVsnprintf, Function | MediumTest | Level1) +{ + int ret = FormatVsnprintf((char *)"%s has %d words", "hello world", 11); + TEST_ASSERT_EQUAL_INT(ret, 24); + + ret = FormatVsnprintf((char *)"%f and %c as well as %ld\n", 2.2, 'c', 6); + TEST_ASSERT_EQUAL_INT(ret, 28); +} + +RUN_TEST_SUITE(IoStdioTestSuite); diff --git a/testsuites/kernel_lite/io_posix/src/IoTestStdlib.c b/testsuites/kernel_lite/io_posix/src/IoTestStdlib.c new file mode 100755 index 0000000000000000000000000000000000000000..945f60b153afa4bc1b592e32223fa02598aeaf37 --- /dev/null +++ b/testsuites/kernel_lite/io_posix/src/IoTestStdlib.c @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "log.h" +#include "IoTest.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(IO, IoStdlibApi, IoStdlibApiTestSuite); + +static BOOL IoStdlibApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IoStdlibApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_IO_STDLIB_0400 + * @tc.name strtof basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtof, Function | MediumTest | Level1) +{ + char *endPtr = NULL; + float ret = strtof(" -3.40E+38 hello", &endPtr); + EXPECT_FLOAT_EQ(ret, -3.40E+38); + EXPECT_STREQ(endPtr, " hello"); + + ret = strtof(" 3.40E+38 ===", &endPtr); + EXPECT_FLOAT_EQ(ret, 3.40E+38); + EXPECT_STREQ(endPtr, " ==="); + + ret = strtof("-9.6e17 this 123", &endPtr); + EXPECT_FLOAT_EQ(ret, -9.6e17); + EXPECT_STREQ(endPtr, " this 123"); + + ret = strtof("this is string", &endPtr); + EXPECT_FLOAT_EQ(ret, 0); + EXPECT_STREQ(endPtr, "this is string"); +} + +/** + * @tc.number SUB_KERNEL_IO_STDLIB_0500 + * @tc.name strtod basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtod, Function | MediumTest | Level1) +{ + char *endPtr = NULL; + double ret = strtod(" -1.79E+308 hello", &endPtr); + EXPECT_DOUBLE_EQ(ret, -1.79E+308); + EXPECT_STREQ(endPtr, " hello"); + + ret = strtod("1.79E+308 ===", &endPtr); + EXPECT_DOUBLE_EQ(ret, 1.79E+308); + EXPECT_STREQ(endPtr, " ==="); + + ret = strtod("-9.6e17 this 123", &endPtr); + EXPECT_DOUBLE_EQ(ret, -9.6e17); + EXPECT_STREQ(endPtr, " this 123"); + + ret = strtod("this is string", &endPtr); + EXPECT_DOUBLE_EQ(ret, 0); + EXPECT_STREQ(endPtr, "this is string"); +} + +/** + * @tc.number SUB_KERNEL_IO_STDLIB_0600 + * @tc.name strtold basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtold, Function | MediumTest | Level1) +{ + char *endPtr = NULL; + long double ret = strtold(" 2.22507e-308 hello", &endPtr); + EXPECT_STREQ(endPtr, " hello"); + + ret = strtold(" 1.79769e+308 ===", &endPtr); + EXPECT_STREQ(endPtr, " ==="); + + ret = strtold("-9.6e17 this 123", &endPtr); + EXPECT_DOUBLE_EQ(ret, -9.6e17); + EXPECT_STREQ(endPtr, " this 123"); + + ret = strtold("this is string", &endPtr); + EXPECT_DOUBLE_EQ(ret, 0); + EXPECT_STREQ(endPtr, "this is string"); +} + + +/** + * @tc.number SUB_KERNEL_IO_STDLIB_0700 + * @tc.name strtol basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtol, Function | MediumTest | Level1) +{ + char nPtr[] = "12 0110 0XDEFE 0666 -1.6"; + char *endPtr = NULL; + long ret = strtol(nPtr, &endPtr, 10); // decimal + EXPECT_EQ(ret, 12); + EXPECT_STREQ(endPtr, " 0110 0XDEFE 0666 -1.6"); + + ret = strtol(endPtr, &endPtr, 2); // binary + EXPECT_EQ(ret, 6); + EXPECT_STREQ(endPtr, " 0XDEFE 0666 -1.6"); + + ret = strtol(endPtr, &endPtr, 16); // hexadecimal + EXPECT_EQ(ret, 0XDEFE); + EXPECT_STREQ(endPtr, " 0666 -1.6"); + + + ret = strtol(endPtr, &endPtr, 8); // octal + EXPECT_EQ(ret, 0666); + EXPECT_STREQ(endPtr, " -1.6"); + + ret = strtol(endPtr, &endPtr, 65); // Invalid number format + EXPECT_EQ(ret, 0); + EXPECT_STREQ(endPtr, " -1.6"); + + ret = strtol(endPtr, &endPtr, 0); // decimal + EXPECT_EQ(ret, -1); + EXPECT_STREQ(endPtr, ".6"); + + ret = strtol(endPtr, &endPtr, 10); // Invalid transform + EXPECT_EQ(ret, 0); + EXPECT_STREQ(endPtr, ".6"); + + char nPtr1[] = "2147483647 2147483648 -2147483648 -2147483649"; // boundary value:2^31-1 + ret = strtol(nPtr1, &endPtr, 10); + EXPECT_EQ(ret, 2147483647); + EXPECT_STREQ(endPtr, " 2147483648 -2147483648 -2147483649"); + + ret = strtol(endPtr, &endPtr, 10); + EXPECT_EQ(ret, 2147483647); + EXPECT_STREQ(endPtr, " -2147483648 -2147483649"); + + ret = strtol(endPtr, &endPtr, 10); + EXPECT_EQ(ret, -2147483648); + EXPECT_STREQ(endPtr, " -2147483649"); + + ret = strtol(endPtr, &endPtr, 10); + EXPECT_EQ(ret, -2147483648); + EXPECT_STREQ(endPtr, ""); +} + +/** + * @tc.number SUB_KERNEL_IO_STDLIB_0800 + * @tc.name strtoul basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtoul, Function | MediumTest | Level1) +{ + char nPtr[] = "12 0110 0XDEFE 0666 4294967295 4294967296 12.34"; // 2^32-1 + char *endPtr = NULL; + unsigned long ret = strtoul(nPtr, &endPtr, 10); + EXPECT_EQ(ret, 12UL); + EXPECT_STREQ(endPtr, " 0110 0XDEFE 0666 4294967295 4294967296 12.34"); + + ret = strtoul(endPtr, &endPtr, 2); + EXPECT_EQ(ret, 6UL); + EXPECT_STREQ(endPtr, " 0XDEFE 0666 4294967295 4294967296 12.34"); + + ret = strtoul(endPtr, &endPtr, 16); + EXPECT_EQ(ret, 0XDEFEUL); + EXPECT_STREQ(endPtr, " 0666 4294967295 4294967296 12.34"); + + + ret = strtoul(endPtr, &endPtr, 8); + EXPECT_EQ(ret, 0666UL); + EXPECT_STREQ(endPtr, " 4294967295 4294967296 12.34"); + + ret = strtoul(endPtr, &endPtr, 0); + EXPECT_EQ(ret, 4294967295UL); + EXPECT_STREQ(endPtr, " 4294967296 12.34"); + + ret = strtoul(endPtr, &endPtr, 0); + EXPECT_EQ(ret, 4294967295UL); + EXPECT_STREQ(endPtr, " 12.34"); + + ret = strtoul(endPtr, &endPtr, 65); + EXPECT_EQ(ret, 0UL); + EXPECT_STREQ(endPtr, " 12.34"); + + ret = strtoul(endPtr, &endPtr, 0); + EXPECT_EQ(ret, 12UL); + EXPECT_STREQ(endPtr, ".34"); + + ret = strtoul(endPtr, &endPtr, 0); + EXPECT_EQ(ret, 0UL); + EXPECT_STREQ(endPtr, ".34"); +} + +/** + * @tc.number SUB_KERNEL_IO_STDLIB_1000 + * @tc.name strtoull basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtoull, Function | MediumTest | Level1) +{ + char nPtr[] = "12 0110 0XDEFE 0666 1.6"; + char *endPtr = NULL; + unsigned long long ret = strtoull(nPtr, &endPtr, 10); + EXPECT_EQ(ret, 12ULL); + EXPECT_STREQ(endPtr, " 0110 0XDEFE 0666 1.6"); + + ret = strtoull(endPtr, &endPtr, 2); + EXPECT_EQ(ret, 6ULL); + EXPECT_STREQ(endPtr, " 0XDEFE 0666 1.6"); + + ret = strtoull(endPtr, &endPtr, 16); + EXPECT_EQ(ret, 0XDEFEULL); + EXPECT_STREQ(endPtr, " 0666 1.6"); + + + ret = strtoull(endPtr, &endPtr, 8); + EXPECT_EQ(ret, 0666ULL); + EXPECT_STREQ(endPtr, " 1.6"); + + ret = strtoull(endPtr, &endPtr, 65); + EXPECT_EQ(ret, 0ULL); + EXPECT_STREQ(endPtr, " 1.6"); + + ret = strtoull(endPtr, &endPtr, 0); + EXPECT_EQ(ret, 1ULL); + EXPECT_STREQ(endPtr, ".6"); + + ret = strtoull(endPtr, &endPtr, 0); + EXPECT_EQ(ret, 0ULL); + EXPECT_STREQ(endPtr, ".6"); + + char nPtr1[] = "18446744073709551615 18446744073709551616"; // 2^64-1 + ret = strtoull(nPtr1, &endPtr, 10); + EXPECT_EQ(ret, 18446744073709551615ULL); + EXPECT_STREQ(endPtr, " 18446744073709551616"); + + ret = strtoull(endPtr, &endPtr, 10); + EXPECT_EQ(ret, 18446744073709551615ULL); + EXPECT_STREQ(endPtr, ""); +} + +RUN_TEST_SUITE(IoStdlibApiTestSuite); diff --git a/testsuites/kernel_lite/io_posix/src/IoTestString.c b/testsuites/kernel_lite/io_posix/src/IoTestString.c new file mode 100755 index 0000000000000000000000000000000000000000..2a9cdeffc1c7e672f9f7039784b89e899a0ecc6a --- /dev/null +++ b/testsuites/kernel_lite/io_posix/src/IoTestString.c @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "IoTest.h" +#include + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(IO, IoStringApi, IoStringApiTestSuite); + +static BOOL IoStringApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IoStringApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_0300 + * @tc.name strcmp basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrcmp, Function | MediumTest | Level1) +{ + int ret = strcmp("abcdef", "ABCDEF"); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + + ret = strcmp("123456", "654321"); + TEST_ASSERT_LESS_THAN_INT(0, ret); + + EXPECT_EQ(strcmp("~!@#$%^&*()_+", "~!@#$%^&*()_+"), 0); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_0400 + * @tc.name strncmp basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrncmp, Function | MediumTest | Level1) +{ + const char dest[] = "abcdef"; + const char src[] = "ABCDEF"; + int ret = strncmp(dest, src, 1); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + + ret = strncmp("123456", "654321", 6); + TEST_ASSERT_LESS_THAN_INT(0, ret); + + ret = strncmp("~!@#$%^&*()_+", "~!@#$%^&*()_+", 8); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_0700 + * @tc.name stpcpy basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStpcpy, Function | MediumTest | Level1) +{ + const char *src = "hello world !"; + char dest[50] = {0}; + char *ret = stpcpy(dest, src); + ASSERT_NE(ret, NULL); + EXPECT_STREQ(dest, src); + + const char *srcT = "~!@#$%%^&*()_+"; + char destT[50] = {0}; + ret = stpcpy(destT, srcT); + ASSERT_NE(ret, NULL); + EXPECT_STREQ(destT, "~!@#$%%^&*()_+"); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_0800 + * @tc.name stpncpy basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStpncpy, Function | MediumTest | Level1) +{ + char src[] = "hello world !"; + char dest[50] = {0}; + char *ret = stpncpy(dest, src, 5); + EXPECT_STREQ(ret, ""); + EXPECT_STREQ(dest, "hello"); + + char srcT[] = "~!@#$%%^&*()_+"; + char destT[50] = {0}; + ret = stpncpy(destT, srcT, 15); + EXPECT_STREQ(ret, ""); + EXPECT_STREQ(destT, "~!@#$%%^&*()_+"); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_1000 + * @tc.name strcpy basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrcpy, Function | MediumTest | Level1) +{ + char src[] = "hello world !"; + char dest[20] = {0}; + char *ret = strcpy(dest, src); + EXPECT_STREQ(ret, dest); + + char srcT[] = "This is String1"; + char destT[20] = {0}; + ret = strcpy(destT, srcT); + EXPECT_STREQ(ret, destT); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_1100 + * @tc.name strncpy basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrncpy, Function | MediumTest | Level1) +{ + char src[] = "hello world !"; + char dest[] = {0}; + char *ret = strncpy(dest, src, 6); + EXPECT_STREQ(ret, dest); + + char destT[] = "~!@#$%^&*()_+"; + ret = strncpy(destT, "hello world", 0); + EXPECT_STREQ(ret, destT); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_1400 + * @tc.name strcat basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrcat, Function | MediumTest | Level1) +{ + char dest[50] = {0}; + char *ret = strcat(dest, "hello world !"); + EXPECT_STREQ(ret, dest); + + char destT[50] = "hello world ! || "; + ret = strcat(destT, "This is String1"); + EXPECT_STREQ(ret, destT); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_1500 + * @tc.name strncat basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrncat, Function | MediumTest | Level1) +{ + char dest[50] = "hello world || "; + char *ret = strncat(dest, "This is String1", 7); + EXPECT_STREQ(ret, "hello world || This is"); + + char destT[20] = "|/*"; + ret = strncat(destT, "~!@#$%^&*()_+", 13); + EXPECT_STREQ(ret, destT); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_1600 + * @tc.name strchr basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrchr, Function | MediumTest | Level1) +{ + char src[] = "hello !! world"; + char *ret = strchr(src, '!'); + EXPECT_STREQ(ret, "!! world"); + + ret = strchr(src, '?'); + EXPECT_STREQ(ret, NULL); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_1700 + * @tc.name strrchr basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrrchr, Function | MediumTest | Level1) +{ + char src[] = "hello world & HEELO & WORLD"; + char *ret = strrchr(src, '&'); + EXPECT_STREQ(ret, "& WORLD"); + + ret = strrchr(src, '?'); + EXPECT_STREQ(ret, NULL); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_1800 + * @tc.name strnlen basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrnlen, Function | MediumTest | Level1) +{ + char src[] = "hello world !"; + unsigned int ltSrcSize = strlen(src) - 2; + unsigned int gtSrcSize = strlen(src) + 2; + + size_t ret = strnlen(src, ltSrcSize); + EXPECT_EQ(ret, ltSrcSize); + + ret = strnlen(src, gtSrcSize); + EXPECT_EQ(ret, strlen(src)); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_1900 + * @tc.name strtok basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrtok, Function | MediumTest | Level1) +{ + char src[] = "hello world & This is-String1"; + char *ret = strtok(src, "&"); + EXPECT_STREQ(ret, src); + + ret = strtok(NULL, "-"); + EXPECT_STREQ(ret, " This is"); + + char srcS[] = "hello world !"; + ret = strtok(srcS, "?"); + EXPECT_STREQ(ret, srcS); + + char srcT[50] = {0}; + ret = strtok(srcT, "~"); + EXPECT_STREQ(ret, NULL); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_2200 + * @tc.name strdup basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrdup, Function | MediumTest | Level1) +{ + char src[] = "hello world !"; + char *ret = strdup(src); + EXPECT_STREQ(ret, src); + + char srcS[] = "This is String1"; + ret = strdup(srcS); + EXPECT_STREQ(ret, "This is String1"); + free(ret); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_2500 + * @tc.name strcspn basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrcspn, Function | MediumTest | Level1) +{ + const char dest[] = "hello world !"; + const char src[] = "!"; + size_t ret = strcspn(dest, src); + EXPECT_EQ(ret, 12U); + + const char srcS[] = "a"; + ret = strcspn(dest, srcS); + EXPECT_EQ(ret, 13U); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_2600 + * @tc.name strspn basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrspn, Function | MediumTest | Level1) +{ + const char dest[] = "hello world !"; + const char src[] = "heAlo"; + size_t ret = strspn(dest, src); + EXPECT_EQ(ret, 5U); + EXPECT_EQ(ret, 5U); + + const char destS[] = "this is string"; + const char srcS[] = "abc"; + ret = strspn(destS, srcS); + EXPECT_EQ(ret, 0U); + + const char srcT[] = "helo\0 wal"; + ret = strspn(dest, srcT); + EXPECT_EQ(ret, 5U); +} + +/** + * @tc.number SUB_KERNEL_IO_STRING_2700 + * @tc.name strstr basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringApiTestSuite, testStrstr, Function | MediumTest | Level1) +{ + const char dest[] = "hello world !"; + const char src[] = "heAlo"; + const char *ret = strstr(dest, src); + EXPECT_STREQ(ret, NULL); + + const char destS[] = "string this is string"; + const char srcS[] = "string"; + ret = strstr(destS, srcS); + EXPECT_STREQ(ret, "string this is string"); + + const char srcT[] = "\0hello"; + ret = strstr(dest, srcT); + EXPECT_STREQ(ret, "hello world !"); +} + +RUN_TEST_SUITE(IoStringApiTestSuite); diff --git a/testsuites/kernel_lite/io_posix/src/IoTestStrings.c b/testsuites/kernel_lite/io_posix/src/IoTestStrings.c new file mode 100755 index 0000000000000000000000000000000000000000..f93aff3ba07dfc9a3a824a5fe5c41a0ab5780347 --- /dev/null +++ b/testsuites/kernel_lite/io_posix/src/IoTestStrings.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "IoTest.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(IO, IoStringsApi, IoStringsApiTestSuite); + +static BOOL IoStringsApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IoStringsApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_IO_STRINGS_0200 + * @tc.name strncasecmp basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringsApiTestSuite, testStrncasecmp, Function | MediumTest | Level1) +{ + int ret = strncasecmp("abcdefg", "abcdEFg", 7); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = strncasecmp("abcdefg", "abcdEF", 7); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + + ret = strncasecmp("abcdef", "abcdEFg", 7); + TEST_ASSERT_LESS_THAN_INT(0, ret); +} + +/** + * @tc.number SUB_KERNEL_IO_STRINGS_0300 + * @tc.name strcasecmp basic function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IoStringsApiTestSuite, testStrcasecmp, Function | MediumTest | Level1) +{ + int ret = strcasecmp("abcdefg", "abcdEFg"); + TEST_ASSERT_EQUAL_INT(0, ret); + + ret = strcasecmp("abcdefg", "abcdEF"); + TEST_ASSERT_GREATER_THAN_INT(0, ret); + + ret = strcasecmp("abcdef", "abcdEFg"); + TEST_ASSERT_LESS_THAN_INT(0, ret); +} + +RUN_TEST_SUITE(IoStringsApiTestSuite); diff --git a/testsuites/kernel_lite/ipc_posix/BUILD.gn b/testsuites/kernel_lite/ipc_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..7e669c4c1f3cc2dc886d4073856931b3d2aef7f7 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("ActsKernelIPCTest") { + deps = [ + "message_queue:ActsIpcMqTest", + "semaphore:ActsIpcSemTest", + ] +} diff --git a/testsuites/kernel_lite/ipc_posix/message_queue/BUILD.gn b/testsuites/kernel_lite/ipc_posix/message_queue/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..9c91c14d55e02cee44c66a7083c442cac7a29e69 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/message_queue/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsIpcMqTest") { + suite_name = "acts" + sources = [ + "src/IpcMqExceptionTest.c", + "src/IpcMqTest.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//third_party/bounds_checking_function/include", + "../../utils/", + ] +} diff --git a/testsuites/kernel_lite/ipc_posix/message_queue/Test.json b/testsuites/kernel_lite/ipc_posix/message_queue/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..b091fe7112f21e8d2777ab9c70e52139eced5e2a --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/message_queue/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsIpcMqTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqExceptionTest.c b/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqExceptionTest.c new file mode 100755 index 0000000000000000000000000000000000000000..cf6d485631be31e1dddef9fc2317fa15f4b42348 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqExceptionTest.c @@ -0,0 +1,873 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "IpcMqTest.h" +#include +#include +#include +#include +#include +#include "log.h" +#include "utils.h" +#include "KernelConstants.h" +#include + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(IPC, IpcMqExceptionApi, IpcMqExceptionApiTestSuite); + +static BOOL IpcMqExceptionApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IpcMqExceptionApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0100 + * @tc.name mq_open function errno for EEXIST test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqOpenEEXIST, Function | MediumTest | Level2) +{ + char qName[MQ_NAME_LEN]; + mqd_t queue, queueOther; + + sprintf_s(qName, sizeof(qName), "testMqOpenEEXIST_%d", GetRandom(10000)); + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + queueOther = mq_open(qName, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, NULL); + TEST_ASSERT_TRUE(queueOther == (mqd_t)-1); + TEST_ASSERT_TRUE(errno == EEXIST); + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0200 + * @tc.name mq_open function errno for EINVAL test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqOpenEINVAL, Function | MediumTest | Level2) +{ + int i; + mqd_t queue; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN]; + const int max = 65535; + + sprintf_s(qName, sizeof(qName), "testMqOpenEINVAL_%d", GetRandom(10000)); + + for (i = 0; i < 6; i++) { + switch (i) { + case 0: + attr.mq_msgsize = -1; + attr.mq_maxmsg = max; + break; + case 1: + /* attr.mq_msgsize > USHRT_MAX - 4 */ + attr.mq_msgsize = max; + attr.mq_maxmsg = max; + break; + case 2: + attr.mq_msgsize = 10; + attr.mq_maxmsg = -1; + break; + case 3: + attr.mq_msgsize = 10; + attr.mq_maxmsg = max + 1; + break; + + case 4: + attr.mq_msgsize = 0; + attr.mq_maxmsg = 16; + break; + + case 5: + attr.mq_msgsize = 64; + attr.mq_maxmsg = 0; + break; + } + + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue == (mqd_t)-1); + + if (queue != (mqd_t)-1) { + mq_close(queue); + mq_unlink(qName); + } + + /* if NOT call mq_close & mq_unlink then errno == ENOENT */ + TEST_ASSERT_TRUE(errno == EINVAL); + } + + for (i = 0; i < MQ_NAME_LEN; i++) { + qName[i] = 0; + } + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(errno == EINVAL); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0300 + * @tc.name mq_open function errno for ENAMETOOLONG test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqOpenENAMETOOLONG, Function | MediumTest | Level2) +{ + char qName[MAX_MQ_NAME_LEN + 10]; + mqd_t queue; + int i; + + for (i = 0; i < MAX_MQ_NAME_LEN + 5; i++) { + qName[i] = '8'; + } + qName[i] = '\0'; + + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + TEST_ASSERT_TRUE(queue == (mqd_t)-1); + + if (queue != (mqd_t)-1) { + mq_close(queue); + mq_unlink(qName); + } + + TEST_ASSERT_TRUE(errno == ENAMETOOLONG); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0400 + * @tc.name mq_open function errno for ENOENT test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqOpenENOENT, Function | MediumTest | Level3) +{ + mqd_t queue; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqOpenENOENT_%d", GetRandom(10000)); + queue = mq_open(qName, O_RDWR, S_IRUSR | S_IWUSR, NULL); + TEST_ASSERT_TRUE(queue == (mqd_t)-1); + + if (queue != (mqd_t)-1) { + mq_close(queue); + mq_unlink(qName); + } + TEST_ASSERT_TRUE(errno == ENOENT); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0500 + * @tc.name mq_open function errno for ENFILE test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqOpenENFILE, Function | MediumTest | Level3) +{ + char qName[MAX_MQ_NUMBER + 1][24]; + mqd_t queue[MAX_MQ_NUMBER + 1]; + int flag = 0; + int i; + + memset(queue, 0, sizeof(queue)); + for (i = 0; i < MAX_MQ_NUMBER + 1; i++) { + sprintf_s(qName[i], 24, "testMqOpenENFILE_%d", i); + } + + for (i = 0; i < MAX_MQ_NUMBER; i++) { + queue[i] = mq_open(qName[i], O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + + if (queue[i] == (mqd_t)-1) { + flag = 1; + printf("break: i = %d\n", i); + break; + } + + TEST_ASSERT_TRUE(queue[i] != (mqd_t)-1); + } + + printf("func: i = %d\n", i); + if (flag == 0) { + queue[i] = mq_open(qName[i], O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + } + TEST_ASSERT_TRUE(queue[i] == (mqd_t)-1); + TEST_ASSERT_TRUE(errno == ENFILE); + + for (i = 0; i < MAX_MQ_NUMBER + 1; i++) { + mq_close(queue[i]); + mq_unlink(qName[i]); + } +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_OPEN_0600 + * @tc.name mq_open function errno for ENOSPC test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqOpenENOSPC, Function | MediumTest | Level3) +{ + mqd_t queue; + struct mq_attr setAttr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqOpenENOSPC_%d", GetRandom(10000)); + setAttr.mq_msgsize = MAX_MQ_MSG_SIZE + 1; + setAttr.mq_maxmsg = MAX_MQ_NAME_LEN; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + TEST_ASSERT_TRUE(queue == (mqd_t)-1); + + if (queue != (mqd_t)-1) { + mq_close(queue); + mq_unlink(qName); + } + TEST_ASSERT_TRUE(errno == ENOSPC); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_CLOSE_0100 + * @tc.name mq_close function errno for EBADF test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqCloseEBADF, Function | MediumTest | Level2) +{ + TEST_ASSERT_TRUE(mq_close(NULL) == -1); + TEST_ASSERT_TRUE(errno == EBADF); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_SEND_0100 + * @tc.name mq_send function errno for EAGAIN test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqSendEAGAIN, Function | MediumTest | Level2) +{ + mqd_t queue; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqSendEAGAIN_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = 1; + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0) == 0); + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0) == -1); + TEST_ASSERT_TRUE(errno == EAGAIN); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_SEND_0200 + * @tc.name mq_send function errno for EBADF and EMSGSIZE test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqSendEBADFEMSGSIZE, Function | MediumTest | Level2) +{ + mqd_t queue; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqSendEAGAIN_%d", GetRandom(10000)); + attr.mq_msgsize = 1; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_send(NULL, MQ_MSG, 1, MQ_MSG_PRIO) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == -1); + TEST_ASSERT_TRUE(errno == EMSGSIZE); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); + + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDONLY | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + attr.mq_flags |= O_NONBLOCK; + TEST_ASSERT_TRUE(mq_setattr(queue, &attr, NULL) == 0); + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_SEND_0300 + * @tc.name mq_send function errno for EINVAL test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqSendEINVAL, Function | MediumTest | Level3) +{ + mqd_t queue; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqSendEINVAL_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, 0, MQ_MSG_PRIO) == -1); + TEST_ASSERT_TRUE(errno == EINVAL); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_RECEIVE_0100 + * @tc.name mq_receive function errno for EAGAIN test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqReceiveEAGAIN, Function | MediumTest | Level2) +{ + mqd_t queue; + unsigned int prio; + struct mq_attr attr = { 0 }; + struct mq_attr getAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEAGAIN_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1); + TEST_ASSERT_TRUE(prio == MQ_MSG_PRIO); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) == -1); + TEST_ASSERT_TRUE(errno == EAGAIN); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_RECEIVE_0200 + * @tc.name mq_receive function errno for EBADF and EMSGSIZE test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqReceiveEBADFEMSGSIZE, Function | MediumTest | Level2) +{ + mqd_t queue; + unsigned int prio; + struct mq_attr attr = { 0 }; + struct mq_attr getAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN], rMsgErr[1]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEAGAIN_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + + TEST_ASSERT_TRUE(mq_receive(NULL, rMsg, getAttr.mq_msgsize, &prio) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + TEST_ASSERT_TRUE(mq_receive(queue, rMsgErr, sizeof(rMsgErr), &prio) == -1); + TEST_ASSERT_TRUE(errno == EMSGSIZE); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); + + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_WRONLY | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + attr.mq_flags |= O_NONBLOCK; + TEST_ASSERT_TRUE(mq_setattr(queue, &attr, NULL) == 0); + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_RECEIVE_0300 + * @tc.name mq_receive function errno for EINVAL test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqReceiveEINVAL, Function | MediumTest | Level3) +{ + mqd_t queue; + unsigned int prio; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEINVAL_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, 0, &prio) == -1); + TEST_ASSERT_TRUE(errno == EINVAL); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_TIMEDSEND_0100 + * @tc.name mq_timedsend function errno for EAGAIN and EBADF test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqTimedSendEAGAINEBADF, Function | MediumTest | Level2) +{ + mqd_t queue; + struct timespec ts = { 0, 0 }; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqTimedSendEAGAIN_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = 1; + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == 0); + + ts.tv_sec = 0; + ts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == -1); + TEST_ASSERT_TRUE(errno == EAGAIN); + + TEST_ASSERT_TRUE(mq_timedsend(NULL, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); + + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDONLY | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + attr.mq_flags |= O_NONBLOCK; + TEST_ASSERT_TRUE(mq_setattr(queue, &attr, NULL) == 0); + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_TIMEDSEND_0200 + * @tc.name mq_timedsend function errno for EINVAL test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqTimedSendEINVAL, Function | MediumTest | Level2) +{ + mqd_t queue; + int i; + struct timespec ts = { 0, 0 }; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqTimedSendEINVAL_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + for (i = 0; i < 3; i++) { + switch (i) { + case 0: + ts.tv_sec = -1; + ts.tv_nsec = 0; + break; + case 1: + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = -1; + break; + case 2: + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = 1000000000UL + 1UL; + break; + } + + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == -1); + TEST_ASSERT_TRUE(errno == EINVAL); + } + + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, 0, MQ_MSG_PRIO, &ts) == -1); + TEST_ASSERT_TRUE(errno == EINVAL); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_TIMEDSEND_0300 + * @tc.name mq_timedsend function errno for EMSGSIZE test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqTimedSendEMSGSIZE, Function | MediumTest | Level3) +{ + mqd_t queue; + struct timespec ts = { 0, 0 }; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqTimedSendEMSGSIZE_%d", GetRandom(10000)); + attr.mq_msgsize = 1; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == -1); + TEST_ASSERT_TRUE(errno == EMSGSIZE); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_TIMEDSEND_0400 + * @tc.name mq_timedsend function errno for ETIMEDOUT test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqTimedSendETIMEDOUT, Function | MediumTest | Level3) +{ + mqd_t queue; + struct timespec ts = { 0, 0 }; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqTimedSendETIMEDOUT_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = 1; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == 0); + + ts.tv_sec = 0; + ts.tv_nsec = 100; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts) == -1); + TEST_ASSERT_TRUE(errno == ETIMEDOUT); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_TIMEDRECEIVE_0100 + * @tc.name mq_timedreceive function errno for EAGAIN and EBADF test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqTimedReceiveEAGAINEBADF, Function | MediumTest | Level2) +{ + mqd_t queue; + unsigned int prio; + struct timespec ts = { 0, 0 }; + struct mq_attr attr = { 0 }; + struct mq_attr getAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqTimedReceiveEAGAIN_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &ts) == -1); + TEST_ASSERT_TRUE(errno == EAGAIN); + + TEST_ASSERT_TRUE(mq_timedreceive(NULL, rMsg, getAttr.mq_msgsize, &prio, &ts) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); + + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_WRONLY | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_timedreceive(NULL, rMsg, getAttr.mq_msgsize, &prio, &ts) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + attr.mq_flags |= O_NONBLOCK; + TEST_ASSERT_TRUE(mq_setattr(queue, &attr, NULL) == 0); + TEST_ASSERT_TRUE(mq_timedreceive(NULL, rMsg, getAttr.mq_msgsize, &prio, &ts) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_TIMEDRECEIVE_0200 + * @tc.name mq_timedreceive function errno for EINVAL test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqTimedReceiveEINVAL, Function | MediumTest | Level2) +{ + mqd_t queue; + int i; + unsigned int prio; + struct timespec ts = { 0, 0 }; + struct mq_attr attr = { 0 }; + struct mq_attr getAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqTimedReceiveEINVAL_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + for (i = 0; i < 3; i++) { + switch (i) { + case 0: + ts.tv_sec = -1; + ts.tv_nsec = 0; + break; + case 1: + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = -1; + break; + case 2: + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = 1000000000UL + 1UL; + break; + } + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &ts) == -1); + TEST_ASSERT_TRUE(errno == EINVAL); + } + + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, 0, &prio, &ts) == -1); + TEST_ASSERT_TRUE(errno == EINVAL); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_TIMEDRECEIVE_0300 + * @tc.name mq_timedreceive function errno for ETIMEDOUT test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqTimedReceiveETIMEDOUT, Function | MediumTest | Level3) +{ + mqd_t queue; + unsigned int prio; + struct timespec ts = { 0, 0 }; + struct mq_attr attr = { 0 }; + struct mq_attr getAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqTimedReceiveETIMEDOUT_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + ts.tv_sec = 0; + ts.tv_nsec = 100; + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &ts) == -1); + TEST_ASSERT_TRUE(errno == ETIMEDOUT); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_TIMEDRECEIVE_0400 + * @tc.name mq_timedreceive function errno for EMSGSIZE test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqTimedReceiveEMSGSIZE, Function | MediumTest | Level3) +{ + mqd_t queue; + unsigned int prio; + struct timespec ts = { 0, 0 }; + struct mq_attr attr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, MQ_NAME_LEN, "testMqTimedReceiveEMSGSIZE_%d", GetRandom(10000)); + attr.mq_msgsize = MQ_MSG_SIZE; + attr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + ts.tv_sec = time(NULL) + 1; + ts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, 1, &prio, &ts) == -1); + TEST_ASSERT_TRUE(errno == EMSGSIZE); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_UNLINK_0100 + * @tc.name mq_unlink function errno for ENAMETOOLONG test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqUnlinkENAMETOOLONG, Function | MediumTest | Level2) +{ + char qName[MAX_MQ_NAME_LEN + 10]; + int i; + + for (i = 0; i < MAX_MQ_NAME_LEN + 5; i++) { + qName[i] = '8'; + } + qName[i] = '\0'; + + TEST_ASSERT_TRUE(mq_unlink(qName) == -1); + TEST_ASSERT_TRUE(errno == ENAMETOOLONG); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_UNLINK_0200 + * @tc.name mq_unlink function errno for ENOENT test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqUnlinkENOENT, Function | MediumTest | Level2) +{ + char qName[64] = "/mq_file-does-not-exit"; + + TEST_ASSERT_TRUE(mq_unlink(qName) == -1); + TEST_ASSERT_TRUE(errno == ENOENT); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_UNLINK_0300 + * @tc.name mq_unlink function errno for EINVAL test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqUnlinkEINVAL, Function | MediumTest | Level3) +{ + TEST_ASSERT_TRUE(mq_unlink("") == -1); + TEST_ASSERT_TRUE(errno == EINVAL); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_GETATTR_0100 + * @tc.name mq_getattr function errno for EBAD and EINVALF test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqGetAttrEBADFEINVAL, Function | MediumTest | Level2) +{ + int ret; + mqd_t queue; + struct mq_attr mqstat = { 0 }; + char qName[MQ_NAME_LEN]; + + memset_s(&mqstat, sizeof(mqstat), 0, sizeof(mqstat)); + + sprintf_s(qName, MQ_NAME_LEN, "testMqSendEINVAL_%d", GetRandom(10000)); + queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, NULL); + + ret = mq_getattr(NULL, &mqstat); + TEST_ASSERT_TRUE(ret == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + ret = mq_getattr(queue, nullptr); + TEST_ASSERT_TRUE(ret == -1); + TEST_ASSERT_TRUE(errno == EINVAL); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_SETATTR_0100 + * @tc.name mq_receive function errno for EBADF and EINVAL test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqExceptionApiTestSuite, testMqSetAttrEBADFEINVAL, Function | MediumTest | Level2) +{ + char qName[MQ_NAME_LEN]; + mqd_t queue; + struct mq_attr gMqstat = { 0 }, sMqstat = { 0 }; + + sprintf_s(qName, MQ_NAME_LEN, "testMqSetAttrEBADFEINVAL_%d", GetRandom(10000)); + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + memset_s(&gMqstat, sizeof(gMqstat), 0, sizeof(gMqstat)); + memset_s(&sMqstat, sizeof(sMqstat), 0, sizeof(sMqstat)); + TEST_ASSERT_TRUE(mq_getattr(queue, &gMqstat) == 0); + + sMqstat.mq_flags |= O_NONBLOCK; + TEST_ASSERT_TRUE(mq_setattr(queue, &sMqstat, NULL) == 0); + TEST_ASSERT_TRUE(mq_getattr(queue, &gMqstat) == 0); + TEST_ASSERT_TRUE(gMqstat.mq_flags != sMqstat.mq_flags); + + TEST_ASSERT_TRUE(mq_setattr(NULL, &sMqstat, NULL) == -1); + TEST_ASSERT_TRUE(errno == EBADF); + + TEST_ASSERT_TRUE(mq_setattr(queue, NULL, NULL) == -1); + TEST_ASSERT_TRUE(errno == EINVAL); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +RUN_TEST_SUITE(IpcMqExceptionApiTestSuite); diff --git a/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqTest.c b/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqTest.c new file mode 100755 index 0000000000000000000000000000000000000000..54efa72af8afab268283186d346f3006c707598f --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqTest.c @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "IpcMqTest.h" +#include +#include +#include +#include +#include +#include "log.h" +#include "utils.h" +#include "KernelConstants.h" +#include + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(IPC, IpcMqApi, IpcMqApiTestSuite); + +static BOOL IpcMqApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IpcMqApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_0100 + * @tc.name mq_send and mq_receive function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqApiTestSuite, testMqOneLevelCom, Function | MediumTest | Level0) +{ + mqd_t queue; + unsigned int prio; + struct mq_attr getAttr = { 0 }; + struct mq_attr setAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, sizeof(qName), "testMqOneLevelCom_%d", GetRandom(10000)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(getAttr.mq_msgsize == MQ_MSG_SIZE); + TEST_ASSERT_TRUE(getAttr.mq_maxmsg == MQ_MAX_MSG); + + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1); + TEST_ASSERT_TRUE(prio == 0); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_0200 + * @tc.name mq_timedsend and mq_timedreceive function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqApiTestSuite, testMqTimedOneLevelCom, Function | MediumTest | Level1) +{ + mqd_t queue; + unsigned int prio; + struct timespec tts = { 0 }, rts = { 0 }; + struct mq_attr getAttr = { 0 }; + struct mq_attr setAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, sizeof(qName), "testMqTimedOneLevelCom_%d", GetRandom(10000)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + tts.tv_sec = time(NULL) + 1; + tts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts) == 0); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(getAttr.mq_msgsize == MQ_MSG_SIZE); + TEST_ASSERT_TRUE(getAttr.mq_maxmsg == MQ_MAX_MSG); + rts.tv_sec = time(NULL) + 1; + rts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts) != -1); + TEST_ASSERT_TRUE(prio == 0); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_0300 + * @tc.name all send and all receive function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqApiTestSuite, testMqAllOneLevelCom, Function | MediumTest | Level2) +{ + mqd_t queue; + unsigned int prio; + struct timespec tts = { 0 }, rts = { 0 }; + struct mq_attr getAttr = { 0 }; + struct mq_attr setAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, sizeof(qName), "testMqAllOneLevelCom_%d", GetRandom(10000)); + + memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr)); + memset_s(&setAttr, sizeof(setAttr), 0, sizeof(setAttr)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(mq_getattr(queue, &setAttr) == 0); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + TEST_ASSERT_TRUE(mq_setattr(queue, &setAttr, NULL) == 0); + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(getAttr.mq_msgsize == setAttr.mq_msgsize); + TEST_ASSERT_TRUE(getAttr.mq_maxmsg == setAttr.mq_maxmsg); + TEST_ASSERT_TRUE(getAttr.mq_curmsgs == 1); + + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + + tts.tv_sec = time(NULL) + 1; + tts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts) == 0); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(getAttr.mq_msgsize == setAttr.mq_msgsize); + TEST_ASSERT_TRUE(getAttr.mq_maxmsg == setAttr.mq_maxmsg); + TEST_ASSERT_TRUE(getAttr.mq_curmsgs == 1); + + rts.tv_sec = time(NULL) + 1; + rts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts) != -1); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +static void *PthreadCom(void *arg) +{ + mqd_t queue; + unsigned int prio; + struct mq_attr getAttr = { 0 }; + char rMsg[MQ_RX_LEN]; + + queue = (mqd_t)arg; + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1); + TEST_ASSERT_TRUE(prio == MQ_MSG_PRIO); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + + return nullptr; +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_0700 + * @tc.name mq_send and mq_receive function test in thread and process + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqApiTestSuite, testMqTwoThreadCom, Function | MediumTest | Level1) +{ + mqd_t queue; + pthread_t tid; + unsigned int prio; + struct mq_attr getAttr = { 0 }; + struct mq_attr setAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, sizeof(qName), "testMqTwoLevelCom_%d", GetRandom(10000)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(pthread_create(&tid, NULL, PthreadCom, (void *)queue) != -1); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + TEST_ASSERT_TRUE(pthread_join(tid, NULL) == 0); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(getAttr.mq_curmsgs == 1); + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1); + TEST_ASSERT_TRUE(prio == MQ_MSG_PRIO); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +static void *PthreadTimedCom(void *arg) +{ + mqd_t queue; + unsigned int prio; + struct timespec tts = { 0 }, rts = { 0 }; + struct mq_attr getAttr = { 0 }; + char rMsg[MQ_RX_LEN]; + + queue = (mqd_t)arg; + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + rts.tv_sec = time(NULL) + 1; + rts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts) != -1); + TEST_ASSERT_TRUE(prio == MQ_MSG_PRIO); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + + tts.tv_sec = time(NULL) + 1; + tts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts) == 0); + + return nullptr; +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_0800 + * @tc.name mq_timedsend and mq_timedreceive function test in thread and process + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqApiTestSuite, testMqTimedTwoThreadCom, Function | MediumTest | Level1) +{ + mqd_t queue; + pthread_t tid; + unsigned int prio; + struct timespec tts = { 0 }, rts = { 0 }; + struct mq_attr getAttr = { 0 }; + struct mq_attr setAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, sizeof(qName), "testMqTimedTwoThreadCom_%d", GetRandom(10000)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(pthread_create(&tid, NULL, PthreadTimedCom, (void *)queue) != -1); + + tts.tv_sec = time(NULL) + 1; + tts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts) == 0); + TEST_ASSERT_TRUE(pthread_join(tid, NULL) == 0); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(getAttr.mq_curmsgs == 1); + rts.tv_sec = time(NULL) + 1; + rts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts) != -1); + TEST_ASSERT_TRUE(prio == MQ_MSG_PRIO); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +static void *PthreadAllCom(void *arg) +{ + mqd_t queue; + unsigned int prio; + struct timespec tts = { 0 }, rts = { 0 }; + struct mq_attr getAttr = { 0 }; + char rMsg[MQ_RX_LEN]; + + queue = (mqd_t)arg; + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + rts.tv_sec = time(NULL) + 1; + rts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts) != -1); + TEST_ASSERT_TRUE(prio == MQ_MSG_PRIO); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + tts.tv_sec = time(NULL) + 1; + tts.tv_nsec = 0; + TEST_ASSERT_TRUE(mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts) == 0); + + return nullptr; +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_0900 + * @tc.name all send and all receive function test in thread and process + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqApiTestSuite, testMqAllTwoThreadCom, Function | MediumTest | Level1) +{ + mqd_t queue; + pthread_t tid; + unsigned int prio; + struct mq_attr getAttr = { 0 }; + struct mq_attr setAttr = { 0 }; + char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN]; + + sprintf_s(qName, sizeof(qName), "testMqAllTwoThreadCom_%d", GetRandom(10000)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + TEST_ASSERT_TRUE(pthread_create(&tid, NULL, PthreadAllCom, (void *)queue) != -1); + + TEST_ASSERT_TRUE(mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO) == 0); + TEST_ASSERT_TRUE(pthread_join(tid, NULL) == 0); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE(getAttr.mq_curmsgs == 1); + TEST_ASSERT_TRUE(mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio) != -1); + TEST_ASSERT_TRUE(prio == MQ_MSG_PRIO); + TEST_ASSERT_TRUE(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN) == 0); + + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +/* * + * @tc.number SUB_KERNEL_IPC_MQ_1200 + * @tc.name mq_setattr set and clean mq_flags for O_NONBLOCK function test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcMqApiTestSuite, testMqSetGetAttr, Function | MediumTest | Level1) +{ + mqd_t queue; + struct mq_attr getAttr = { 0 }; + struct mq_attr setAttr = { 0 }; + char qName[MQ_NAME_LEN]; + + sprintf_s(qName, sizeof(qName), "testMqFunction_%d", GetRandom(10000)); + + memset_s(&setAttr, sizeof(setAttr), 0, sizeof(setAttr)); + setAttr.mq_msgsize = MQ_MSG_SIZE; + setAttr.mq_maxmsg = MQ_MAX_MSG; + setAttr.mq_flags = O_NONBLOCK; + queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr); + TEST_ASSERT_TRUE(queue != (mqd_t)-1); + + memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr)); + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + TEST_ASSERT_TRUE((getAttr.mq_flags & O_NONBLOCK) == O_NONBLOCK); + + setAttr.mq_flags &= ~O_NONBLOCK; + TEST_ASSERT_TRUE(mq_setattr(queue, &setAttr, NULL) == 0); + + TEST_ASSERT_TRUE(mq_getattr(queue, &getAttr) == 0); + printf("setAttr.mq_flags = 0x%x, getAttr.mq_flags = 0x%x\n", setAttr.mq_flags, getAttr.mq_flags); + TEST_ASSERT_TRUE((getAttr.mq_flags & O_NONBLOCK) == 0); + TEST_ASSERT_TRUE(mq_close(queue) == 0); + TEST_ASSERT_TRUE(mq_unlink(qName) == 0); +} + +RUN_TEST_SUITE(IpcMqApiTestSuite); diff --git a/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqTest.h b/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqTest.h new file mode 100755 index 0000000000000000000000000000000000000000..0d1081246549cc67976b52a3133c7a9d70405ad1 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/message_queue/src/IpcMqTest.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef IPC_MQUEUE_TEST +#define IPC_MQUEUE_TEST + +#include +#include +#include +#include +#include + +#define MQ_NAME_LEN 64 // mqueue name len +#define MQ_TX_LEN 64 // mqueue send buffer len +#define MQ_RX_LEN 64 // mqueue receive buffer len +#define MQ_MSG_SIZE 64 // mqueue message size +#define MQ_MSG_PRIO 0 // mqueue message priority +#define MQ_MAX_MSG 16 // mqueue message number + +#define MQ_MSG "MessageToSend" // mqueue message to send +#define MQ_MSG_LEN sizeof(MQ_MSG) // mqueue message len to send + +#endif diff --git a/testsuites/kernel_lite/ipc_posix/semaphore/BUILD.gn b/testsuites/kernel_lite/ipc_posix/semaphore/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..2ea1779708adfafcd98e15f628344b48b98e1db3 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/semaphore/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsIpcSemTest") { + suite_name = "acts" + sources = [ + "src/SemTest.c", + "src/SemXtsTest.c", + "src/SemAbnormalTest.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../../utils/", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/testsuites/kernel_lite/ipc_posix/semaphore/Test.json b/testsuites/kernel_lite/ipc_posix/semaphore/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..02d3c3b30156a9ed650a906703a0bf3b236d12ab --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/semaphore/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsIpcSemTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/ipc_posix/semaphore/src/SemAbnormalTest.c b/testsuites/kernel_lite/ipc_posix/semaphore/src/SemAbnormalTest.c new file mode 100755 index 0000000000000000000000000000000000000000..0de5619c29208e9a047528b96728d43d39dd3413 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/semaphore/src/SemAbnormalTest.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include "utils.h" +#include "log.h" + +#include "ohos_types.h" +#include "hctest.h" +#include "SemTest.h" + +#define KERNEL_NS_PER_SECOND 1000000000 +#define SEM_VALUE_MAX 0xFFFE + +LITE_TEST_SUIT(IPC, SemAbnormalTestSuite, SemAbnormalTestSuite); + +static BOOL SemAbnormalTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL SemAbnormalTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_INIT_0200 + * @tc.name Use sem_init initialized value when value is SEM_VALUE_MAX + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(SemAbnormalTestSuite, testSemInitAbnormalSemvaluemax, Function | MediumTest | Level3) +{ + sem_t sem; + int semValue = 0; + LOG("> SEM_VALUE_MAX = %d", SEM_VALUE_MAX); + + TEST_ASSERT_NOT_EQUAL(-1, sem_init(&sem, 0, SEM_VALUE_MAX)); + TEST_ASSERT_EQUAL_INT(0, sem_getvalue(&sem, &semValue)); + TEST_ASSERT_EQUAL_INT(SEM_VALUE_MAX, semValue); + TEST_ASSERT_EQUAL_INT(0, sem_destroy(&sem)); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_INIT_0210 + * @tc.name Use sem_init initialized value when value is greater than SEM_VALUE_MAX + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(SemAbnormalTestSuite, testSemInitAbnormalGtsemvaluemax, Function | MediumTest | Level3) +{ + sem_t sem; + unsigned int gtSemMax = (unsigned int)SEM_VALUE_MAX + 1; + LOG("> SEM_VALUE_MAX = %d", SEM_VALUE_MAX); + + if (sem_init(&sem, 0, gtSemMax) == -1) { + TEST_ASSERT_EQUAL_INT(errno, EINVAL); + } else { + LOG("> sem_init return unexpected"); + ADD_FAILURE(); + } +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_INIT_0220 + * @tc.name Use sem_init initialized value twice + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(SemAbnormalTestSuite, testSemInitAbnormalInitTwice, Function | MediumTest | Level3) +{ + sem_t sem; + TEST_ASSERT_NOT_EQUAL(-1, sem_init(&sem, 0, 1)); + TEST_ASSERT_NOT_EQUAL(-1, sem_init(&sem, 0, 1)); + TEST_ASSERT_EQUAL_INT(0, sem_destroy(&sem)); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_POST_0200 + * @tc.name sem_post increases the semaphore count near the maximum value + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(SemAbnormalTestSuite, testSemPostAbnormal, Function | MediumTest | Level3) +{ + sem_t sem; + int semValue = 0; + + // = SEM_VALUE_MAX + printf("> SEM_VALUE_MAX = %d\n", SEM_VALUE_MAX); + TEST_ASSERT_NOT_EQUAL(-1, sem_init(&sem, 0, SEM_VALUE_MAX)); + if (sem_post(&sem) == -1) { // not support OVERFLOW + TEST_ASSERT_EQUAL_INT(errno, EOVERFLOW); + } else { + LOG("> sem_post return unexpected"); + } + + TEST_ASSERT_EQUAL_INT(0, sem_destroy(&sem)); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_0200 + * @tc.name sem_timedwait get semaphore, wait time abnormal, tv_nsec less than 0 + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(SemAbnormalTestSuite, testSemTimedwaitAbnormalA, Function | MediumTest | Level3) +{ + struct timespec ts = {0}; + sem_t sem; + int semValue = 0; + + TEST_ASSERT_EQUAL_INT(0, sem_init(&sem, 0, 0)); + + ts.tv_sec = time(NULL); + ts.tv_nsec = -2; + if (sem_timedwait(&sem, &ts) == -1) { + TEST_ASSERT_EQUAL_INT(errno, EINVAL); + } else { + LOG("> sem_timedwait return unexpected"); + } + + TEST_ASSERT_EQUAL_INT(0, sem_getvalue(&sem, &semValue)); + TEST_ASSERT_EQUAL_INT(0, semValue); + TEST_ASSERT_EQUAL_INT(0, sem_destroy(&sem)); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_0300 + * @tc.name sem_timedwait get semaphore, wait time abnormal + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(SemAbnormalTestSuite, testSemTimedwaitAbnormalB, Function | MediumTest | Level3) +{ + struct timespec ts = {0}; + sem_t sem; + int semValue = 0; + + TEST_ASSERT_EQUAL_INT(0, sem_init(&sem, 0, 0)); + + ts.tv_sec = time(NULL); + ts.tv_nsec = KERNEL_NS_PER_SECOND; + if (sem_timedwait(&sem, &ts) == -1) { + TEST_ASSERT_EQUAL_INT(errno, EINVAL); + } else { + LOG("> sem_timedwait return unexpected"); + } + + TEST_ASSERT_EQUAL_INT(0, sem_getvalue(&sem, &semValue)); + TEST_ASSERT_EQUAL_INT(0, semValue); + TEST_ASSERT_EQUAL_INT(0, sem_destroy(&sem)); +} + +RUN_TEST_SUITE(SemAbnormalTestSuite); diff --git a/testsuites/kernel_lite/ipc_posix/semaphore/src/SemTest.c b/testsuites/kernel_lite/ipc_posix/semaphore/src/SemTest.c new file mode 100755 index 0000000000000000000000000000000000000000..03b4e494e0b1bbf4f538e44498ea0ff789d35fb0 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/semaphore/src/SemTest.c @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" +#include "SemTest.h" +#include "ohos_types.h" +#include "hctest.h" + +#define SEM_VALUE_MAX 0xFFFE + +static int g_semTestStep = 0; + +LITE_TEST_SUIT(IPC, SemApi, IpcSemApiTestSuite); + +static BOOL IpcSemApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IpcSemApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testSemInit0100, Function | MediumTest | Level2) +{ + int ret; + sem_t sem; + int testValue[3] = {0, 1, 10}; + + for (int i = 0; i < (int)(sizeof(testValue)/sizeof(int)); i++) { + printf("test index of testValue %d\n", i); + + ret = sem_init((sem_t *)&sem, 0, testValue[0]); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + } +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testSemPost0100, Function | MediumTest | Level2) +{ + int ret; + sem_t sem; + + ret = sem_init((sem_t *)&sem, 0, 0); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_post(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_post(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_post(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testSemWait0100, Function | MediumTest | Level2) +{ + int ret; + sem_t sem; + + ret = sem_init((sem_t *)&sem, 0, 3); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_wait(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_wait(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_wait(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +void *ThreadChat(void *arg) +{ + int ret; + sem_t *sem = (sem_t *)arg; + + TEST_ASSERT_EQUAL_INT(g_semTestStep, 0); + + g_semTestStep = 1; + ret = sem_wait(sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + g_semTestStep = 2; + return NULL; +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testThreadChat0100, Function | MediumTest | Level3) +{ + pthread_t tid; + sem_t sem; + int ret = 0; + struct timespec req; + g_semTestStep = 0; + + ret = sem_init((sem_t *)&sem, 0, 0); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = pthread_create(&tid, NULL, ThreadChat, (void *)&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + req.tv_sec = 0; + req.tv_nsec = TEN_CONT * NANO_MS; + nanosleep(&req, NULL); + TEST_ASSERT_EQUAL_INT(g_semTestStep, 1); + + ret = sem_post(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + nanosleep(&req, NULL); + TEST_ASSERT_EQUAL_INT(g_semTestStep, 2); + + ret = sem_post(&sem); + TEST_ASSERT_EQUAL_INT(g_semTestStep, 2); + + ret = pthread_join(tid, NULL); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +void *ThreadNThreadWait1(void *arg) +{ + int ret; + sem_t *sem = (sem_t *)arg; + struct timespec req; + + req.tv_sec = 0; + req.tv_nsec = HUNDRED_CONT * NANO_MS; + + nanosleep(&req, NULL); + g_semTestStep = 1; + ret = sem_wait(sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + g_semTestStep = 2; + return NULL; +} + +void *ThreadNThreadWait2(void *arg) +{ + int ret; + sem_t *sem = (sem_t *)arg; + struct timespec req; + + req.tv_sec = 0; + req.tv_nsec = 300 * NANO_MS; + nanosleep(&req, NULL); + g_semTestStep = 3; + + req.tv_nsec = 200 * NANO_MS; + nanosleep(&req, NULL); + ret = sem_wait(sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + g_semTestStep = 4; + return NULL; +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testThreadChat0400, Function | MediumTest | Level4) +{ + pthread_t tid1; + pthread_t tid2; + sem_t sem; + int ret = 0; + struct timespec req; + + req.tv_sec = 0; + req.tv_nsec = 200 * NANO_MS; + g_semTestStep = 0; + + ret = sem_init((sem_t *)&sem, 0, 0); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = pthread_create(&tid1, NULL, ThreadNThreadWait1, (void *)&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = pthread_create(&tid2, NULL, ThreadNThreadWait2, (void *)&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + nanosleep(&req, NULL); + TEST_ASSERT_EQUAL_INT(g_semTestStep, 1); + + ret = sem_post(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + req.tv_nsec = 20 * NANO_MS; + nanosleep(&req, NULL); + TEST_ASSERT_EQUAL_INT(g_semTestStep, 2); + + req.tv_nsec = 200 * NANO_MS; + nanosleep(&req, NULL); + TEST_ASSERT_EQUAL_INT(g_semTestStep, 3); + + ret = sem_post(&sem); + req.tv_nsec = 20 * NANO_MS; + nanosleep(&req, NULL); + TEST_ASSERT_EQUAL_INT(g_semTestStep, 3); + + ret = pthread_join(tid1, NULL); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = pthread_join(tid2, NULL); + TEST_ASSERT_EQUAL_INT(ret, 0); + + TEST_ASSERT_EQUAL_INT(g_semTestStep, 4); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testSemInitAbnormal0200, Function | MediumTest | Level3) +{ + int ret; + sem_t sem; + unsigned int gtSemMax = (unsigned int)SEM_VALUE_MAX + 1; + printf("> SEM_VALUE_MAX = %d \n", SEM_VALUE_MAX); + + ret = sem_init(&sem, 0, SEM_VALUE_MAX); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_init(&sem, 0, gtSemMax); + TEST_ASSERT_EQUAL_INT(ret, -1); + + TEST_ASSERT_EQUAL_INT(errno, EINVAL); + + ret = sem_init(&sem, 0, 1); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testSemPostAbnormal, Function | MediumTest | Level3) +{ + int ret; + sem_t sem; + + ret = sem_init(&sem, 0, SEM_VALUE_MAX); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_post(&sem); + // not support OVERFLOW + TEST_ASSERT_EQUAL_INT(ret, 0); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testSemTimedWaitAbnormalA, Function | MediumTest | Level3) +{ + int ret; + struct timespec ts; + sem_t sem; + + ret = sem_init(&sem, 0, 0); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ts.tv_sec = 0; + ts.tv_nsec = -2; + ret = sem_timedwait(&sem, &ts); + TEST_ASSERT_EQUAL_INT(ret, -1); + + TEST_ASSERT_EQUAL_INT(errno, EINVAL); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +LITE_TEST_CASE(IpcSemApiTestSuite, testSemTimedWaitAbnormalB, Function | MediumTest | Level3) +{ + int ret; + struct timespec ts; + sem_t sem; + + ret = sem_init(&sem, 0, 0); + TEST_ASSERT_EQUAL_INT(ret, 0); + + ts.tv_sec = time(NULL); + ts.tv_nsec = NANO_S; + ret = sem_timedwait(&sem, &ts); + TEST_ASSERT_EQUAL_INT(ret, -1); + + TEST_ASSERT_EQUAL_INT(errno, EINVAL); + + ret = sem_destroy(&sem); + TEST_ASSERT_EQUAL_INT(ret, 0); +} + +RUN_TEST_SUITE(IpcSemApiTestSuite); + +void IpcSemApiTest() +{ + printf("begin IpcSemApiTest....\n"); + + RUN_ONE_TESTCASE(testSemInit0100); + RUN_ONE_TESTCASE(testSemPost0100); + RUN_ONE_TESTCASE(testSemWait0100); + RUN_ONE_TESTCASE(testThreadChat0100); + RUN_ONE_TESTCASE(testThreadChat0400); + RUN_ONE_TESTCASE(testSemInitAbnormal0200); + RUN_ONE_TESTCASE(testSemPostAbnormal); + RUN_ONE_TESTCASE(testSemTimedWaitAbnormalA); + RUN_ONE_TESTCASE(testSemTimedWaitAbnormalB); + + return; +} diff --git a/testsuites/kernel_lite/ipc_posix/semaphore/src/SemTest.h b/testsuites/kernel_lite/ipc_posix/semaphore/src/SemTest.h new file mode 100755 index 0000000000000000000000000000000000000000..aa85a772ca45d44478dd98489519d95b7bb08fe5 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/semaphore/src/SemTest.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SEM_TEST_H +#define SEM_TEST_H + +#define NANO_S 1000000000 +#define NANO_MS 1000000 + +#define TEN_CONT 10 +#define FIFTY_CONT 50 +#define HUNDRED_CONT 100 + +#define HIGHEST_USER_PROCESS_PRIORITY 10 +#define LOWEST_USER_PROCESS_PRIORITY 31 +#define HIGHEST_USER_THREAD_PRIORITY 0 +#define LOWEST_USER_THREAD_PRIORITY 31 + +#define DEFAULT_SHELL_PROCESS_PRIORITY 15 +#define DEFAULT_INIT_PROCESS_PRIORITY 28 +#define DEFAULT_KERNEL_PROCESS_PRIORITY 0 + +#define DEFAULT_THREAD_PRIORITY 25 + +#define DEFAULT_RR_SCHED_INTERVAL 20000000 // defaluit sched interval of RR, in ms + +#endif /* SEM_TEST_H */ diff --git a/testsuites/kernel_lite/ipc_posix/semaphore/src/SemXtsTest.c b/testsuites/kernel_lite/ipc_posix/semaphore/src/SemXtsTest.c new file mode 100755 index 0000000000000000000000000000000000000000..5c388d9d8378e550a315cedb3d009bb3a9a08e60 --- /dev/null +++ b/testsuites/kernel_lite/ipc_posix/semaphore/src/SemXtsTest.c @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include "utils.h" +#include "log.h" + +#include "ohos_types.h" +#include "hctest.h" +#include "SemTest.h" + +#define KERNEL_NS_PER_SECOND 1000000000 +#define KERNEL_100MS_BY_NS 100000000 + +LITE_TEST_SUIT(IPC, SemApi, IpcSemApiXtsTestSuite); + +static BOOL IpcSemApiXtsTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL IpcSemApiXtsTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_INIT_0100 + * @tc.name Use sem_init initialize the semaphore with 0 + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemInitA, Function | MediumTest | Level2) +{ + sem_t sem; + int semValue = 0; + int testValue = 0; + + EXPECT_NE(sem_init(&sem, 0, testValue), -1); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_TRUE(semValue == testValue); + EXPECT_EQ(sem_destroy(&sem), 0); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_INIT_0110 + * @tc.name Use sem_init initialize the semaphore with 1 + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemInitB, Function | MediumTest | Level2) +{ + sem_t sem; + int semValue = 0; + int testValue = 1; + + EXPECT_NE(sem_init(&sem, 0, testValue), -1); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, testValue); + EXPECT_EQ(sem_destroy(&sem), 0); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_INIT_0120 + * @tc.name Use sem_init initialize the semaphore with 100 + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemInitC, Function | MediumTest | Level2) +{ + sem_t sem; + int semValue = 0; + int testValue = 10; + + EXPECT_NE(sem_init(&sem, 0, testValue), -1); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, testValue); + EXPECT_EQ(sem_destroy(&sem), 0); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_POST_0100 + * @tc.name sem_post increases the semaphore count + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemPost, Function | MediumTest | Level2) +{ + sem_t sem; + int semValue = 0; + + ASSERT_NE(sem_init(&sem, 0, 0), -1); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + + EXPECT_EQ(sem_post(&sem), 0); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 1); + + EXPECT_EQ(sem_post(&sem), 0); + EXPECT_EQ(sem_post(&sem), 0); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 3); + + EXPECT_EQ(sem_destroy(&sem), 0); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_WAIT_0100 + * @tc.name sem_wait get semaphore + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemWait, Function | MediumTest | Level2) +{ + sem_t sem; + int semValue = 0; + + ASSERT_NE(sem_init(&sem, 0, 3), -1); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 3); + + EXPECT_EQ(sem_wait(&sem), 0); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 2); + + EXPECT_EQ(sem_wait(&sem), 0); + EXPECT_EQ(sem_wait(&sem), 0); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + + EXPECT_EQ(sem_destroy(&sem), 0); +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_DESTROY_0100 + * @tc.name check sem_destroy function + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemdestroy, Function | MediumTest | Level3) +{ + sem_t sem; + ASSERT_EQ(sem_init(&sem, 0, 0), 0); + EXPECT_EQ(sem_destroy(&sem), 0); +} + +void *ThreadChat_F01(void *arg) +{ + sem_t *sem = (sem_t*)arg; + int semValue = 0; + + EXPECT_EQ(sem_getvalue(sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + EXPECT_EQ(sem_wait(sem), 0); + return NULL; +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_CHAT_0100 + * @tc.name Inter-thread communication, check sem_wait function + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testThreadChat, Function | MediumTest | Level3) +{ + pthread_t tid; + sem_t sem; + int reInt = 0; + int semValue = 0; + + ASSERT_EQ(sem_init(&sem, 0, 0), 0); + + reInt = pthread_create(&tid, NULL, ThreadChat_F01, (void*)&sem); + ASSERT_EQ(reInt, 0); + + Msleep(20); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + + EXPECT_EQ(sem_post(&sem), 0); + EXPECT_EQ(sem_post(&sem), 0); + + Msleep(20); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 1); + + reInt = pthread_join(tid, NULL); + EXPECT_EQ(reInt, 0); + EXPECT_EQ(sem_destroy(&sem), 0); +} + +void *ThreadSemTimedWait(void *arg) +{ + struct timespec ts = {0}; + sem_t *sem = (sem_t*)arg; + int semValue = 0; + + EXPECT_EQ(sem_getvalue(sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec = ts.tv_sec + (ts.tv_nsec + KERNEL_100MS_BY_NS) / KERNEL_NS_PER_SECOND; + ts.tv_nsec = (ts.tv_nsec + KERNEL_100MS_BY_NS) % KERNEL_NS_PER_SECOND; + Msleep(50); + EXPECT_EQ(sem_timedwait(sem, &ts), 0); + EXPECT_EQ(sem_getvalue(sem, &semValue), 0); + + Msleep(100); + EXPECT_EQ(semValue, 1); + return NULL; +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_CHAT_0300 + * @tc.name Inter-thread communication, check sem_timedwait function + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testThreadSemTimedWait, Function | MediumTest | Level3) +{ + pthread_t tid; + sem_t sem; + int reInt = 0; + int semValue = 0; + + ASSERT_EQ(sem_init(&sem, 0, 0), 0); + + reInt = pthread_create(&tid, NULL, ThreadSemTimedWait, (void*)&sem); + ASSERT_EQ(reInt, 0); + + Msleep(10); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + EXPECT_EQ(sem_post(&sem), 0); + EXPECT_EQ(sem_post(&sem), 0); + + reInt = pthread_join(tid, NULL); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 1); + EXPECT_EQ(reInt, 0); + EXPECT_EQ(sem_destroy(&sem), 0); +} + +void *ThreadNThreadWait_F01(void *arg) +{ + sem_t *sem = (sem_t*)arg; + int semValue = 0; + + Msleep(100); + EXPECT_EQ(sem_getvalue(sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + EXPECT_EQ(sem_wait(sem), 0); + return NULL; +} + +void *ThreadNThreadWait_F02(void *arg) +{ + sem_t *sem = (sem_t*)arg; + int semValue = 0; + EXPECT_EQ(sem_getvalue(sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + + Msleep(300); + EXPECT_EQ(sem_getvalue(sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + + Msleep(200); + EXPECT_EQ(sem_getvalue(sem, &semValue), 0); + EXPECT_EQ(semValue, 1); + EXPECT_EQ(sem_wait(sem), 0); + return NULL; +} + +/** + * @tc.number SUB_KERNEL_IPC_SEM_CHAT_0400 + * @tc.name N threads wait, main thread post + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(IpcSemApiXtsTestSuite, testNThreadWait, Function | MediumTest | Level4) +{ + pthread_t tid1; + pthread_t tid2; + sem_t sem; + int reInt = 0; + int semValue = 0; + + ASSERT_EQ(sem_init(&sem, 0, 0), 0); + + reInt = pthread_create(&tid1, NULL, ThreadNThreadWait_F01, (void*)&sem); + ASSERT_EQ(reInt, 0); + + reInt = pthread_create(&tid2, NULL, ThreadNThreadWait_F02, (void*)&sem); + ASSERT_EQ(reInt, 0); + + Msleep(200); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + EXPECT_EQ(sem_post(&sem), 0); + + Msleep(20); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + + Msleep(200); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 0); + EXPECT_EQ(sem_post(&sem), 0); + + Msleep(20); + EXPECT_EQ(sem_getvalue(&sem, &semValue), 0); + EXPECT_EQ(semValue, 1); + + reInt = pthread_join(tid1, NULL); + EXPECT_EQ(reInt, 0); + reInt = pthread_join(tid2, NULL); + EXPECT_EQ(reInt, 0); + EXPECT_EQ(sem_destroy(&sem), 0); +} + +RUN_TEST_SUITE(IpcSemApiXtsTestSuite); diff --git a/testsuites/kernel_lite/kernelcmsis_hal/BUILD.gn b/testsuites/kernel_lite/kernelcmsis_hal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..909f27788d6b5fd47c9178d19765b901783ffcef --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsCMSISTest") { + suite_name = "acts" + sources = [ + "src/cmsis_event_func_test.c", + "src/cmsis_msg_func_test.c", + "src/cmsis_mutex_func_test.c", + "src/cmsis_sem_func_test.c", + "src/cmsis_task_func_test.c", + "src/cmsis_task_pri_func_test.c", + "src/cmsis_timer_func_test.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "//third_party/unity/src", + "src", + "//kernel/liteos_m/kal", + ] + cflags = [ "-Wno-error" ] +} diff --git a/testsuites/kernel_lite/kernelcmsis_hal/Test.tmpl b/testsuites/kernel_lite/kernelcmsis_hal/Test.tmpl new file mode 100755 index 0000000000000000000000000000000000000000..be8407e1286041a5af2bdc75a15633337376eb9d --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/Test.tmpl @@ -0,0 +1,19 @@ +{ + "description": "Config for $module test cases", + "environment": [ + { + "type": "device", + "label": "wifiiot" + } + ], + "kits": [ + { + "type": "DeployKit", + "timeout": "20000", + "burn_file": "$subsystem/$module.bin" + } + ], + "driver": { + "type": "CTestLite" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_event_func_test.c b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_event_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..ec6bffa68e64b1a0974639c23f3d87feb1caa5fd --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_event_func_test.c @@ -0,0 +1,359 @@ +/** + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "ohos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +osEventFlagsId_t g_eventId; +UINT16 g_cmsisTestEventCount; +#define EVENT_MASK_HEX_1 0x01 +#define EVENT_MASK_HEX_2 0x02 +#define EVENT_MASK_HEX_4 0x04 +#define EVENT_MASK_HEX_10 0x10 +#define EVENT_MASK_HEX_11 0x11 +#define TIMEOUT_NUM_3 3 +#define TIMEOUT_NUM_10 10 +#define INVALID_FLAG_OPTION 0x00000004U + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisEventFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsisevent, CmsisEventFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisEventFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisEventFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisEventFlagsWaitFunc001(void const *argument) +{ + (void)argument; + UINT32 uwRet; + g_cmsisTestEventCount++; + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_11, (osFlagsWaitAll | osFlagsNoClear), osWaitForever); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_11, uwRet); + g_cmsisTestEventCount++; + osThreadExit(); +} + +static void CmsisEventFlagsSetFunc002(void const *argument) +{ + (void)argument; + UINT32 uwRet; + g_cmsisTestEventCount++; + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_11, (osFlagsWaitAll | osFlagsNoClear), TIMEOUT_NUM_3); + TEST_ASSERT_EQUAL_INT(osErrorTimeout, uwRet); + g_cmsisTestEventCount++; + + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_4, (osFlagsWaitAll | osFlagsNoClear), osWaitForever); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_4, uwRet); + g_cmsisTestEventCount++; + osThreadExit(); +} + +static void CmsisEventFlagsClearFunc001(void const *argument) +{ + (void)argument; + UINT32 uwRet; + g_cmsisTestEventCount++; + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_1, osFlagsWaitAll, osWaitForever); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_1, uwRet); + g_cmsisTestEventCount++; + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0100 + * @tc.name : event operation for creat + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsNew001, Function | MediumTest | Level1) +{ + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + (void)osEventFlagsDelete(g_eventId); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0200 + * @tc.name : event operation for delete + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsDelete001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0300 + * @tc.name : event delete operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsDelete002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + + uwRet = osEventFlagsDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0400 + * @tc.name : event operation for flags set + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsSet001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_eventId = osEventFlagsNew(NULL); + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0500 + * @tc.name : event reliability test for flags set + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsSet002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + g_cmsisTestEventCount = 0; + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + id = osThreadNew((osThreadFunc_t)CmsisEventFlagsSetFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestEventCount); + g_cmsisTestEventCount++; + uwRet=osEventFlagsSet(g_eventId, EVENT_MASK_HEX_2); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestEventCount); + + g_cmsisTestEventCount++; + uwRet=osEventFlagsSet(g_eventId, EVENT_MASK_HEX_11); + osDelay(DELAY_TICKS_5); + + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_4, g_cmsisTestEventCount); + uwRet=osEventFlagsSet(g_eventId, EVENT_MASK_HEX_4); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_5, g_cmsisTestEventCount); + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0600 + * @tc.name : event flags set operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsSet003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osEventFlagsSet(NULL, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0700 + * @tc.name : event operation for wait + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsWait001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + g_cmsisTestEventCount = 0; + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + id = osThreadNew((osThreadFunc_t)CmsisEventFlagsWaitFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestEventCount); + + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_1); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_11, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestEventCount); + + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0800 + * @tc.name : event operation for invalid option + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsWait002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_eventId = osEventFlagsNew(NULL); + TEST_ASSERT_NOT_NULL(g_eventId); + + uwRet = osEventFlagsWait(g_eventId, EVENT_MASK_HEX_11, INVALID_FLAG_OPTION, osWaitForever); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); + + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_0900 + * @tc.name : event wait operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsWait003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osEventFlagsWait(NULL, EVENT_MASK_HEX_11, (osFlagsWaitAll | osFlagsNoClear), osWaitForever); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_1000 + * @tc.name : event operation for flags get + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsGet001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_eventId = osEventFlagsNew(NULL); + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + uwRet = 0; + uwRet = osEventFlagsGet(g_eventId); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_1100 + * @tc.name : event flags get operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsGet002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osEventFlagsGet(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_1200 + * @tc.name : event operation for flags clear + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsClear001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osThreadId_t id; + + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + g_cmsisTestEventCount = 0; + g_eventId = osEventFlagsNew(NULL); + id = osThreadNew((osThreadFunc_t)CmsisEventFlagsClearFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_10); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestEventCount); + + uwRet = osEventFlagsClear(g_eventId, 0xffff); + TEST_ASSERT_EQUAL_INT(EVENT_MASK_HEX_10, uwRet); + uwRet = osEventFlagsGet(g_eventId); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osEventFlagsSet(g_eventId, EVENT_MASK_HEX_1); + // after the event is triggered, the flag is reset to be zero + TEST_ASSERT_EQUAL_INT(0, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestEventCount); + uwRet = osEventFlagsDelete(g_eventId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_EVENT_OPERATION_1300 + * @tc.name : event flags clear operation with EventFlagsId = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisEventFuncTestSuite, testOsEventFlagsClear002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osEventFlagsClear(NULL, 0xffff); + TEST_ASSERT_EQUAL_INT(osFlagsErrorParameter, uwRet); +}; + +RUN_TEST_SUITE(CmsisEventFuncTestSuite); diff --git a/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_msg_func_test.c b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_msg_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..a93ae0864ac338c71c74bb31c18c5fbf580ad9cd --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_msg_func_test.c @@ -0,0 +1,389 @@ +/** + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "ohos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +osMessageQueueId_t g_cmsisMessageQId; +#define MSGQUEUE_COUNT 16 +#define MSGQUEUE_SPACE_COUNT 13 +#define MSGQUEUE_PUT_COUNT 3 +#define MSG_SIZE 4 +#define MSGINFO_LEN 4 +#define TIMEOUT_COUNT 1000 +#define BUF_LEN 32 +#define MSGQUEUE_COUNT_INDEX_0 0 +#define MSGQUEUE_COUNT_INDEX_1 1 +#define MSGQUEUE_COUNT_INDEX_2 2 +static char *g_cmsisMessageInfo[] = {"msg1", "msg2", "msg3", "msg4", "msg5", "msg6", "msg7", "msg8"}; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisMsgFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsismsg, CmsisMsgFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisMsgFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisMsgFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisMessageQueueGetFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + UINT8 msg_prio = 0; + CHAR uctemp[MSGINFO_LEN] = ""; + UINT32 uwCmp; + uwRet = osMessageQueueGet(g_cmsisMessageQId, uctemp, &msg_prio, TIMEOUT_COUNT); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + uwCmp = memcmp(uctemp, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], MSGINFO_LEN); + TEST_ASSERT_EQUAL_INT(0, uwCmp); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0100 + * @tc.name : message queue operation for creat + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueNew001, Function | MediumTest | Level1) +{ + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + (void)osMessageQueueDelete(g_cmsisMessageQId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0200 + * @tc.name : message queue operation for creat when msg_count = 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueNew002, Function | MediumTest | Level1) +{ + g_cmsisMessageQId = osMessageQueueNew(0, MSG_SIZE, NULL); + TEST_ASSERT_NULL(g_cmsisMessageQId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0300 + * @tc.name : message queue operation for creat when msg_size = 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueNew003, Function | MediumTest | Level1) +{ + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, 0, NULL); + TEST_ASSERT_NULL(g_cmsisMessageQId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0400 + * @tc.name : message queue operation for delete + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueDelete001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0500 + * @tc.name : message queue delete operation with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueDelete002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osMessageQueueDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0600 + * @tc.name : message queue operation for put + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueuePut001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0700 + * @tc.name : message queue put operation with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueuePut002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osMessageQueuePut(NULL, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0800 + * @tc.name : message queue operation for put when msg_ptr = 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueuePut003, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, NULL, 0, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_0900 + * @tc.name : message queue operation for get + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGet001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + osKernelLock(); + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + id = osThreadNew((osThreadFunc_t)CmsisMessageQueueGetFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osKernelUnlock(); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1000 + * @tc.name : message queue get operation with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGet002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + UINT8 msg_prio = 0; + CHAR uctemp[MSGINFO_LEN] = ""; + uwRet = osMessageQueueGet(NULL, uctemp, &msg_prio, TIMEOUT_COUNT); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1100 + * @tc.name : message queue operation for get when msg_ptr = 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGet003, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + UINT8 msg_prio = 0; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueueGet(g_cmsisMessageQId, NULL, &msg_prio, TIMEOUT_COUNT); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1200 + * @tc.name : message queue operation for get msg size + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetMsgSize001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueueGetMsgSize(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(MSG_SIZE, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1300 + * @tc.name : message queue get msg size with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetMsgSize002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osMessageQueueGetMsgSize(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1400 + * @tc.name : message queue operation for get capacity + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetCapacity001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + uwRet = osMessageQueueGetCapacity(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(MSGQUEUE_COUNT, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1500 + * @tc.name : message queue get capacity with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetCapacity002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osMessageQueueGetCapacity(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1600 + * @tc.name : message queue operation for get count + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetCount001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_1], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_2], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueueGetCount(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(MSGQUEUE_PUT_COUNT, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1700 + * @tc.name : message queue get count with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetCount002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osMessageQueueGetCount(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1800 + * @tc.name : message queue operation for get space + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetSpace001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_cmsisMessageQId = osMessageQueueNew(MSGQUEUE_COUNT, MSG_SIZE, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMessageQId); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_0], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_1], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueuePut(g_cmsisMessageQId, g_cmsisMessageInfo[MSGQUEUE_COUNT_INDEX_2], 0, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMessageQueueGetSpace(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(MSGQUEUE_SPACE_COUNT, uwRet); + + uwRet = osMessageQueueDelete(g_cmsisMessageQId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MSG_OPERATION_1900 + * @tc.name : message queue get space with mq_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMsgFuncTestSuite, testOsMessageQueueGetSpace002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osMessageQueueGetSpace(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +RUN_TEST_SUITE(CmsisMsgFuncTestSuite); diff --git a/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_mutex_func_test.c b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_mutex_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..27009dfff6a1b6d76e9ae4769957404631704d4c --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_mutex_func_test.c @@ -0,0 +1,275 @@ +/** + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "ohos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +#define LOS_WAIT_FOREVER 0xFFFFFFFF + +UINT16 g_cmsisTestMutexCount; +osMutexId_t g_cmsisMutexId; +osMutexAttr_t g_cmsisMutexAttr; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisMutexFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsismutex, CmsisMutexFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisMutexFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisMutexFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisMutexGetOwnerFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + osThreadId_t id1; + osThreadId_t id2; + osThreadAttr_t attr; + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + + uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + id1 = osMutexGetOwner(g_cmsisMutexId); + id2 = osThreadGetId(); + TEST_ASSERT_EQUAL_STRING(id1, id2); + + attr.name = osThreadGetName(id1); + TEST_ASSERT_EQUAL_STRING("testMutexGetOwner001", attr.name); + + uwRet = osMutexRelease(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0100 + * @tc.name : mutex operation for creat with NULL parameter + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexNew001, Function | MediumTest | Level1) +{ + g_cmsisMutexId = osMutexNew(NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + (void)osMutexDelete(g_cmsisMutexId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0200 + * @tc.name : mutex operation for creat + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexNew002, Function | MediumTest | Level1) +{ + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + (void)osMutexDelete(g_cmsisMutexId); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0300 + * @tc.name : mutex operation for delete after creat mutex with NULL parameter + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0400 + * @tc.name : mutex operation for delete + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0500 + * @tc.name : mutex operation for delete after mutex acquire and release + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete003, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(NULL); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + + osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + osMutexRelease(g_cmsisMutexId); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0600 + * @tc.name : mutex delete operation with mutex_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete004, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osMutexDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0700 + * @tc.name : mutex acquire operation with mutex_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexAcquire001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osMutexAcquire(NULL, LOS_WAIT_FOREVER); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0800 + * @tc.name : mutex operation for acquire + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexAcquire002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + + uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + (void)osMutexRelease(g_cmsisMutexId); + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_0900 + * @tc.name : mutex operation for release + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexRelease001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr); + TEST_ASSERT_NOT_NULL(g_cmsisMutexId); + + uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osMutexRelease(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osMutexDelete(g_cmsisMutexId); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_1000 + * @tc.name : mutex release operation with mutex_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexRelease002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osMutexRelease(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_1100 + * @tc.name : mutex operation for get owner + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexGetOwner001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "testMutexGetOwner001"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisMutexGetOwnerFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_MUTEX_OPERATION_1200 + * @tc.name : mutex get owner operation with mutex_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexGetOwner002, Function | MediumTest | Level1) +{ + osThreadId_t id; + id = osMutexGetOwner(NULL); + TEST_ASSERT_NULL(id); +}; + +RUN_TEST_SUITE(CmsisMutexFuncTestSuite); diff --git a/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_sem_func_test.c b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_sem_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..42e9eef5bf463c6d88908733f7ab9e423e9497b8 --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_sem_func_test.c @@ -0,0 +1,420 @@ +/** + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "ohos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +osSemaphoreId_t g_cmsisSemSema; +#define SEMAPHHORE_COUNT_HEX_MAX 0xFE +#define SEMAPHHORE_COUNT_INT0 0 +#define SEMAPHHORE_COUNT_INT1 1 +#define SEMAPHHORE_COUNT_INT10 10 + + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, CmsisSem, CmsisSemFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisSemFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisSemFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0100 + * @tc.name : semaphore operation for creat when Semaphhore count = 1 and 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew001, Function | MediumTest | Level1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + (void)osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0200 + * @tc.name : semaphore operation for creat when Semaphhore count = 10 and 1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew002, Function | MediumTest | Level1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + (void)osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0300 + * @tc.name : semaphore operation for creat when Semaphhore count = 0 and 10 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew003, Function | MediumTest | Level1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT10, NULL); + TEST_ASSERT_NULL(g_cmsisSemSema); + (void)osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0400 + * @tc.name : semaphore operation for creat when Semaphhore count = 0 and 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew004, Function | MediumTest | Level1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0500 + * @tc.name : semaphore operation for creat when Semaphhore count = 1 and 1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew005, Function | MediumTest | Level1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0600 + * @tc.name : semaphore operation for creat when Semaphhore count = 10 and 10 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew006, Function | MediumTest | Level1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT10, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0700 + * @tc.name : semaphore operation for creat when Semaphhore count = 0xFE and 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew007, Function | MediumTest | Level1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0800 + * @tc.name : semaphore operation for creat when Semaphhore count = 0 and 0xFE + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreNew008, Function | MediumTest | Level1) +{ + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_HEX_MAX, NULL); + TEST_ASSERT_NULL(g_cmsisSemSema); + osSemaphoreDelete(g_cmsisSemSema); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_0900 + * @tc.name : semaphore operation for delete + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1000 + * @tc.name : semaphore delete operation twice + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT10, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1100 + * @tc.name : semaphore delete operation with semaphore_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreDelete003, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osSemaphoreDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1200 + * @tc.name : semaphore operation for acquire when Semaphhore count = 1 and 1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1300 + * @tc.name : semaphore operation for acquire when Semaphhore count = 1 and 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1400 + * @tc.name : semaphore operation for acquire when Semaphhore count = 0 and 1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire003, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NULL(g_cmsisSemSema); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1500 + * @tc.name : semaphore acquire operation with semaphore_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreAcquire004, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osSemaphoreAcquire(NULL, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1600 + * @tc.name : semaphore operation for release + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1700 + * @tc.name : semaphore release operation twice + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1800 + * @tc.name : semaphore operation for release after semaphore acquire + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease003, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreAcquire(g_cmsisSemSema, 0); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + uwRet = osSemaphoreRelease(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_1900 + * @tc.name : semaphore release operation with semaphore_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreRelease004, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osSemaphoreRelease(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_2000 + * @tc.name : semaphore operation for get count when Semaphhore count = 1 or 0xFE + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount001, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_HEX_MAX, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(SEMAPHHORE_COUNT_HEX_MAX, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_2100 + * @tc.name : semaphore operation for get count when Semaphhore count = 1 or 0 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT1, SEMAPHHORE_COUNT_INT0, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_INT0, SEMAPHHORE_COUNT_INT1, NULL); + TEST_ASSERT_NULL(g_cmsisSemSema); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_2200 + * @tc.name : semaphore operation for get count + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount003, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + g_cmsisSemSema = osSemaphoreNew(SEMAPHHORE_COUNT_HEX_MAX, SEMAPHHORE_COUNT_HEX_MAX, NULL); + TEST_ASSERT_NOT_NULL(g_cmsisSemSema); + uwRet = osSemaphoreAcquire(g_cmsisSemSema, osWaitForever); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + uwRet = osSemaphoreGetCount(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(SEMAPHHORE_COUNT_HEX_MAX - 1, uwRet); + uwRet = osSemaphoreDelete(g_cmsisSemSema); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_SEM_OPERATION_2300 + * @tc.name : semaphore get count operation with semaphore_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisSemFuncTestSuite, testOsSemaphoreGetCount004, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osSemaphoreGetCount(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); + +}; + +RUN_TEST_SUITE(CmsisSemFuncTestSuite); diff --git a/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..c457cf032aaad582f694cba1c3f4f02c9cdc04b2 --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_task_func_test.c @@ -0,0 +1,3302 @@ +/** + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "ohos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +UINT32 g_threadCount; +UINT16 g_cmsisTestTaskCount; +UINT16 g_getStackSizeExit; +UINT16 g_threadCreateExit; +UINT16 g_threadCreateExit1; +UINT16 g_getNameExit; +UINT16 g_getStackSpaceExit; +osThreadId_t g_puwTaskID01; +osThreadId_t g_puwTaskID02; +osPriority_t g_threadPriority; + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsistask, CmsisTaskFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTaskFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTaskFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisThreadCreatFunc(void const *argument) +{ + (void)argument; + printf(">> in CmsisThreadCreatFunc\n"); + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadCreat002Func001(void const *argument) +{ + (void)argument; + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadCreat002Func002(void const *argument) +{ + (void)argument; + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadCreat003Func001(void const *argument) +{ + (void)argument; + TEST_ASSERT_EQUAL_INT(0, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadCreat003Func002(void const *argument) +{ + (void)argument; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_4, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osThreadExit(); +} + +static void CmsisThreadCreat004Func002(void const *argument) +{ + (void)argument; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + osThreadExit(); +} + +static void CmsisThreadCreat004Func001(void const *argument) +{ + (void)argument; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + TEST_ASSERT_EQUAL_INT(0, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat004Func002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void KeepRunByTick(UINT32 tick) +{ + UINT32 tickA = osKernelGetTickCount(); + UINT32 runned = 0; + UINT32 loop = 0; + UINT32 tickB = 0; + while (runned < tick) { + loop++; + tickB = osKernelGetTickCount(); + if (tickB >= tickA) { + runned = tickB - tickA; + } else { + runned = tickB + (MAX_UINT32 - tickA); + } + if (loop % ALIVE_INFO_DIS == 0) { + printf("runned:%u, tickB:%u, tickA:%u, loop:%u\t\n", + runned, tickB, tickA, loop); + } + } + printf("return runned:%u, tickB:%u, tickA:%u\t\n", + runned, tickB, tickA); + return; +} + +static void WaitThreadExit(osThreadId_t id, UINT16 const *exitFlag) +{ + UINT32 uwRet = osThreadSetPriority(id, osPriorityAboveNormal6); + printf("WaitThreadExit id = %d, uwRet = %d\n", id, uwRet); + UINT32 loop = 0; + while (*exitFlag != TESTCOUNT_NUM_1) { + osDelay(DELAY_TICKS_10); + if (loop % ALIVE_INFO_DIS == 0) { + printf("WaitThreadExit id = %d, loop = %d\n", id, loop++); + } + } + printf("WaitThreadExit exit\n"); +} + +static void CmsisThreadCreat005Func001(void const *argument) +{ + (void)argument; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + while (g_cmsisTestTaskCount < TESTCOUNT_NUM_2) { + KeepRunByTick(DELAY_TICKS_10); + } + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadGetIDFunc001(void const *argument) +{ + (void)argument; + g_puwTaskID01 = osThreadGetId(); + TEST_ASSERT_NOT_NULL(g_puwTaskID01); + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadGetNameFunc001(void const *argument) +{ + (void)argument; + osThreadAttr_t attr; + printf(">> in CmsisThreadGetNameFunc001\n"); + g_puwTaskID01 = osThreadGetId(); + attr.name = osThreadGetName(g_puwTaskID01); + TEST_ASSERT_EQUAL_STRING("testThreadGetName", attr.name); + g_getNameExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadGetStateFunc001(void const *argument) +{ + (void)argument; + osThreadState_t state; + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + + g_puwTaskID02 = osThreadGetId(); + state = osThreadGetState(g_puwTaskID02); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + g_threadCreateExit1 = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadGetStateFunc002(void const *argument) +{ + (void)argument; + osThreadState_t state; + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadReady, state); + + g_puwTaskID02 = osThreadGetId(); + state = osThreadGetState(g_puwTaskID02); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadSuspendFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + g_puwTaskID01 = osThreadGetId(); + uwRet = osThreadSuspend(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadGetStackSizeFunc001(void const *argument) +{ + (void)argument; + osThreadAttr_t attr; + printf(">> in CmsisThreadGetStackSizeFunc001\n"); + g_puwTaskID01 = osThreadGetId(); + attr.stack_size = osThreadGetStackSize(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(TEST_TASK_STACK_SIZE, attr.stack_size); + g_getStackSizeExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadGetStackSpaceFunc001(void const *argument) +{ + (void)argument; + UINT32 uwCount; + printf(">> in CmsisThreadGetStackSpaceFunc001\n"); + g_puwTaskID01 = osThreadGetId(); + uwCount = osThreadGetStackSpace(g_puwTaskID01); + TEST_ASSERT_GREATER_THAN_INT32(0, uwCount); + g_getStackSpaceExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadYieldFunc002(void const *argument) +{ + (void)argument; + osThreadState_t state; + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadReady, state); + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + g_threadCreateExit = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadYieldFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + osThreadId_t id; + osThreadState_t state; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_threadCreateExit = 0; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + uwRet = osThreadYield(); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + g_threadCreateExit1 = TESTCOUNT_NUM_1; + WaitThreadExit(id, &g_threadCreateExit); + osThreadExit(); +} + +static void CmsisThreadYieldFunc003(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + osThreadId_t id; + osThreadState_t state; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_puwTaskID01 = osThreadGetId(); + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); + uwRet = osThreadYield(); + WaitThreadExit(id, &g_threadCreateExit); + g_threadCreateExit1 = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadResumeFunc002(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + osDelay(DELAY_TICKS_5); + osThreadExit(); +} + +static void CmsisThreadResumeFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew((osThreadFunc_t)CmsisThreadResumeFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + uwRet = osThreadSuspend(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + g_threadCreateExit1 = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadTerminateFunc001(void const *argument) +{ + (void)argument; + osStatus_t uwRet; + g_puwTaskID01 = osThreadGetId(); + uwRet = osThreadTerminate(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + osThreadExit(); +} + +static void CmsisThreadGetCountFunc002(void const *argument) +{ + (void)argument; + UINT32 uwRet; + uwRet = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(1, uwRet); + osThreadExit(); +} + +static void CmsisThreadGetCountFunc001(void const *argument) +{ + (void)argument; + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + g_threadCreateExit1 = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadGetCountFunc003(void const *argument) +{ + (void)argument; + UINT32 uwRet; + uwRet = osThreadGetCount(); + TEST_ASSERT_EQUAL_INT(g_threadCount + 1, uwRet); + g_threadCreateExit1 = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisOSKernelLockFunc002(void const *argument) +{ + (void)argument; + g_cmsisTestTaskCount++; + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0040 + * @tc.name : thread operation for creat fail with invalid parameter + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_threadCreateExit = 0; + + osDelay(DELAY_TICKS_5); + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, NULL); + TEST_ASSERT_NOT_NULL(id); + id = osThreadNew(NULL, NULL, NULL); + TEST_ASSERT_NULL(id); + id = osThreadNew(NULL, NULL, &attr); + TEST_ASSERT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0080 + * @tc.name : thread operation for creat success + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew002, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_cmsisTestTaskCount = 0; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat002Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(0, g_cmsisTestTaskCount); + + g_cmsisTestTaskCount++; + attr.priority = osPriorityAboveNormal; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat002Func002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0120 + * @tc.name : thread operation for delay scheduler + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + osThreadAttr_t attr1; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadCreat003Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + g_cmsisTestTaskCount++; + attr1.name = "test1"; + attr1.attr_bits = 0U; + attr1.cb_mem = NULL; + attr1.cb_size = 0U; + attr1.stack_mem = NULL; + attr1.stack_size = TEST_TASK_STACK_SIZE; + attr1.priority = osPriorityAboveNormal; + osDelay(DELAY_TICKS_1); + id = osThreadNew ((osThreadFunc_t)CmsisThreadCreat003Func002, NULL, &attr1); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_5, g_cmsisTestTaskCount); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0160 + * @tc.name : thread operation for nesting schedule + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + g_cmsisTestTaskCount = 0; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat004Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0200 + * @tc.name : thread operation for cycle schdule + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreat005Func001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_1); + g_cmsisTestTaskCount++; + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + osDelay(DELAY_TICKS_5); + while (g_cmsisTestTaskCount != TESTCOUNT_NUM_3) { + KeepRunByTick(DELAY_TICKS_10); + } + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0240 + * @tc.name : thread operation for creat fail when priority = osPriorityNone + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNone; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0280 + * @tc.name : thread operation for creat fail when priority = osPriorityIdle + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityIdle; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0320 + * @tc.name : thread operation for creat fail when priority = osPriorityLow + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0360 + * @tc.name : thread operation for creat success when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0400 + * @tc.name : thread operation for creat success when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew010, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0440 + * @tc.name : thread operation for creat success when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew011, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0480 + * @tc.name : thread operation for creat success when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew012, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0520 + * @tc.name : thread operation for creat success when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew013, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0560 + * @tc.name : thread operation for creat success when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew014, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0600 + * @tc.name : thread operation for creat success when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew015, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0640 + * @tc.name : thread operation for creat success when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew016, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_threadCreateExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0680 + * @tc.name : thread operation for creat fail when priority = osPriorityAboveNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew017, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal7; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0720 + * @tc.name : thread operation for creat fail when priority = osPriorityHigh + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew018, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityHigh; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0760 + * @tc.name : thread operation for creat fail when priority = osPriorityHigh7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew019, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityHigh7; + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0800 + * @tc.name : thread operation for creat fail when priority = osPriorityRealtime + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew020, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityRealtime; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0840 + * @tc.name : thread operation for creat fail when priority = osPriorityRealtime7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew021, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityRealtime7; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0880 + * @tc.name : thread operation for creat fail when priority = osPriorityISR + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew022, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityISR; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0920 + * @tc.name : thread operation for creat fail when priority = osPriorityError + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew023, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityError; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_0960 + * @tc.name : thread operation for creat fail when priority = osPriorityReserved + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew024, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityReserved; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1000 + * @tc.name : thread creat operation with func = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew025, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + id = osThreadNew(NULL, NULL, &attr); + TEST_ASSERT_NULL(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1040 + * @tc.name : thread creat operation with attr = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadNew026, Function | MediumTest | Level1) +{ + osThreadId_t id; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadCreatFunc, NULL, NULL); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1080 + * @tc.name : thread operation for get name when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + + g_cmsisTestTaskCount = 0; + g_getNameExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_getNameExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1120 + * @tc.name : thread operation for get state when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit = 0; + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1160 + * @tc.name : thread operation for suspend when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1200 + * @tc.name : thread operation for get current ID + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId001, Function | MediumTest | Level1) +{ + g_puwTaskID01 = osThreadGetId(); + TEST_ASSERT_NOT_NULL(g_puwTaskID01); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1240 + * @tc.name : thread operation for get ID when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId002, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1280 + * @tc.name : thread operation for get ID when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1320 + * @tc.name : thread operation for get ID when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1360 + * @tc.name : thread operation for get ID when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1400 + * @tc.name : thread operation for get ID when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1440 + * @tc.name : thread operation for get ID when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1480 + * @tc.name : thread operation for get ID when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1520 + * @tc.name : thread operation for get ID when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_threadCreateExit = 0; + + id = osThreadNew((osThreadFunc_t)CmsisThreadGetIDFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT((uintptr_t)id, (uintptr_t)g_puwTaskID01); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1560 + * @tc.name : thread operation for get ID then exit thread + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetId010, Function | MediumTest | Level1) +{ + g_puwTaskID01 = osThreadGetId(); + TEST_ASSERT_NOT_NULL(g_puwTaskID01); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1600 + * @tc.name : thread operation for get stack size when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_cmsisTestTaskCount = 0; + g_puwTaskID01 = 0; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_getStackSizeExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSizeExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1640 + * @tc.name : thread operation for get stack space + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace001, Function | MediumTest | Level1) +{ + UINT32 uwCount; + g_cmsisTestTaskCount = 0; + g_puwTaskID01 = osThreadGetId(); + uwCount = osThreadGetStackSpace(g_puwTaskID01); + TEST_ASSERT_GREATER_THAN_INT32(0, uwCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1680 + * @tc.name : thread operation for yield when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityLow1; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1720 + * @tc.name : thread operation for yield when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield002, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityLow7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1760 + * @tc.name : thread operation for yield when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityBelowNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1800 + * @tc.name : thread operation for yield when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityBelowNormal7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1840 + * @tc.name : thread operation for yield when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1880 + * @tc.name : thread operation for yield when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityNormal7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1920 + * @tc.name : thread operation for yield when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityAboveNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_1960 + * @tc.name : thread operation for yield when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_threadPriority = osPriorityAboveNormal6; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_threadPriority; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc001, NULL, &attr); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_2, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2000 + * @tc.name : thread yield operation for thread with different priority + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadYield009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadYieldFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2040 + * @tc.name : thread operation for resume + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadResume001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + + id = osThreadNew((osThreadFunc_t)CmsisThreadResumeFunc001, NULL, &attr); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_3, g_cmsisTestTaskCount); + TEST_ASSERT_NOT_NULL(id); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2080 + * @tc.name : thread operation for terminate when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2120 + * @tc.name : get thread count with callback function when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2160 + * @tc.name : thread operation for current count + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2200 + * @tc.name : get thread count when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_threadCreateExit1 = 0; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2240 + * @tc.name : get thread count when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_threadCreateExit1 = 0; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2280 + * @tc.name : get thread count when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_threadCreateExit1 = 0; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2320 + * @tc.name : get thread count when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_threadCreateExit1 = 0; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2360 + * @tc.name : get thread count when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_threadCreateExit1 = 0; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2400 + * @tc.name : get thread count when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_threadCreateExit1 = 0; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2440 + * @tc.name : get thread count when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit1 = 0; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2480 + * @tc.name : get thread count when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetCount010, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_threadCreateExit1 = 0; + g_threadCount = osThreadGetCount(); + TEST_ASSERT_GREATER_THAN_INT32(0, g_threadCount); + id = osThreadNew((osThreadFunc_t)CmsisThreadGetCountFunc003, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2520 + * @tc.name : thread operation for get name input exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName002, Function | MediumTest | Level1) +{ + osThreadAttr_t attr; + attr.name = osThreadGetName(NULL); + TEST_ASSERT_NULL(attr.name); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2560 + * @tc.name : thread operation for get name when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_getNameExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_getNameExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2600 + * @tc.name : thread operation for get name when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_getNameExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_getNameExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2640 + * @tc.name : thread operation for get name when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_getNameExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_getNameExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2680 + * @tc.name : thread operation for get name when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_getNameExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_getNameExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2720 + * @tc.name : thread operation for get name when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_getNameExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getNameExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2760 + * @tc.name : thread operation for get name when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_getNameExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getNameExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2800 + * @tc.name : thread operation for get name when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "testThreadGetName"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_getNameExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetNameFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getNameExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2840 + * @tc.name : thread operation for get name + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetName010, Function | MediumTest | Level1) +{ + osThreadAttr_t attr; + g_puwTaskID01 = osThreadGetId(); + attr.name = osThreadGetName(g_puwTaskID01); + TEST_ASSERT_NOT_NULL(attr.name); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2880 + * @tc.name : thread operation for get state input exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osThreadGetState(NULL); + TEST_ASSERT_EQUAL_INT(osThreadError, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2920 + * @tc.name : thread operation for get state when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_threadCreateExit1 = 0; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_2960 + * @tc.name : thread operation for get state when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_threadCreateExit1 = 0; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3000 + * @tc.name : thread operation for get state when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_threadCreateExit1 = 0; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3040 + * @tc.name : thread operation for get state when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_threadCreateExit1 = 0; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3080 + * @tc.name : thread operation for get state when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_threadCreateExit1 = 0; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit1); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3120 + * @tc.name : thread operation for get state when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_threadCreateExit = 0; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3160 + * @tc.name : thread operation for get state when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_threadCreateExit = 0; + + g_puwTaskID01 = osThreadGetId(); + id = osThreadNew ((osThreadFunc_t)CmsisThreadGetStateFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3200 + * @tc.name : thread operation for get current state + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetState010, Function | MediumTest | Level1) +{ + osThreadState_t state; + g_puwTaskID01 = osThreadGetId(); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadRunning, state); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3240 + * @tc.name : thread operation for suspend input exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend002, Function | MediumTest | Level1) +{ + osStatus_t uwRet; + uwRet = osThreadSuspend(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3280 + * @tc.name : thread operation for suspend when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3320 + * @tc.name : thread operation for suspend when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3360 + * @tc.name : thread operation for suspend when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3400 + * @tc.name : thread operation for suspend when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3440 + * @tc.name : thread operation for suspend when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3480 + * @tc.name : thread operation for suspend when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3520 + * @tc.name : thread operation for suspend when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadSuspend009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osStatus_t uwRet; + osThreadAttr_t attr; + osThreadState_t state; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_threadCreateExit = 0; + id = osThreadNew ((osThreadFunc_t)CmsisThreadSuspendFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + state = osThreadGetState(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osThreadBlocked, state); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + WaitThreadExit(id, &g_threadCreateExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3560 + * @tc.name : thread operation for get stack size input exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osThreadGetStackSize(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3600 + * @tc.name : thread operation for get stack size when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_getStackSizeExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSizeExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3640 + * @tc.name : thread operation for get stack size when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_getStackSizeExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSizeExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3680 + * @tc.name : thread operation for get stack size when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_getStackSizeExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSizeExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3720 + * @tc.name : thread operation for get stack size when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_getStackSizeExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSizeExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3760 + * @tc.name : thread operation for get stack size when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_getStackSizeExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSizeExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3800 + * @tc.name : thread operation for get stack size when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_getStackSizeExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSizeExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3840 + * @tc.name : thread operation for get stack size when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_getStackSizeExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSizeFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSizeExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3880 + * @tc.name : thread operation for get stack size + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSize010, Function | MediumTest | Level1) +{ + osThreadAttr_t attr; + g_puwTaskID01 = osThreadGetId(); + attr.stack_size = osThreadGetStackSize(g_puwTaskID01); + TEST_ASSERT_GREATER_THAN_INT32(0, attr.stack_size); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3920 + * @tc.name : thread operation for get stack space input exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osThreadGetStackSpace(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_3960 + * @tc.name : thread operation for get stack space when priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_getStackSpaceExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSpaceExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4000 + * @tc.name : thread operation for get stack space when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_getStackSpaceExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSpaceExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4040 + * @tc.name : thread operation for get stack space when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_getStackSpaceExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSpaceExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4080 + * @tc.name : thread operation for get stack space when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_getStackSpaceExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSpaceExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4120 + * @tc.name : thread operation for get stack space when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_getStackSpaceExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSpaceExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4160 + * @tc.name : thread operation for get stack space when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_getStackSpaceExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSpaceExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4200 + * @tc.name : thread operation for get stack space when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_getStackSpaceExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSpaceExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4240 + * @tc.name : thread operation for get stack space when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadGetStackSpace010, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_getStackSpaceExit = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetStackSpaceFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_getStackSpaceExit); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4280 + * @tc.name : thread operation for resume input exception with NULL parameter + * @tc.desc : [C- SOFTWARE -0200] + + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadResume002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osThreadResume(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4320 + * @tc.name : thread operation for resume input exception + * @tc.desc : [C- SOFTWARE -0200] + + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadResume003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_puwTaskID01 = osThreadGetId(); + uwRet = osThreadResume(g_puwTaskID01); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4360 + * @tc.name : thread operation for terminate input exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osThreadTerminate(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4400 + * @tc.name : thread operation for terminate when priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow7; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4440 + * @tc.name : thread operation for terminate when priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4480 + * @tc.name : thread operation for terminate when priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityBelowNormal7; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4520 + * @tc.name : thread operation for terminate when priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4560 + * @tc.name : thread operation for terminate when priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal7; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4600 + * @tc.name : thread operation for terminate when priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4640 + * @tc.name : thread operation for terminate when priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsThreadTerminate009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_cmsisTestTaskCount = 0; + g_cmsisTestTaskCount++; + g_threadCreateExit1 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadTerminateFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); + +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4680 + * @tc.name : kernel operation for get info + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelGetInfo001, Function | MediumTest | Level1) +{ + CHAR infobuf[100]; + osVersion_t osv; + osStatus_t status; + status = osKernelGetInfo(&osv, infobuf, sizeof(infobuf)); + TEST_ASSERT_EQUAL_INT(osOK, status); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4720 + * @tc.name : kernel operation for get state + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelGetState001, Function | MediumTest | Level1) +{ + osKernelState_t uwRet; + uwRet = osKernelGetState(); + TEST_ASSERT_EQUAL_INT(osKernelRunning, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4760 + * @tc.name : kernel operation for get state after kernel lock + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelGetState002, Function | MediumTest | Level1) +{ + osKernelLock (); + osKernelState_t uwRet; + uwRet = osKernelGetState(); + TEST_ASSERT_EQUAL_INT(osKernelLocked, uwRet); + osKernelUnlock (); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4800 + * @tc.name : kernel lock operation twice + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelLock001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osKernelLock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osKernelLock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); + osKernelUnlock(); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4840 + * @tc.name : kernel operation for lock + * @tc.desc : [C- SOFTWARE -0200] + + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelLock002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osThreadId_t id; + osThreadAttr_t attr; + g_cmsisTestTaskCount = 0; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal; + + uwRet = osKernelLock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); + id = osThreadNew((osThreadFunc_t)CmsisOSKernelLockFunc002, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + TEST_ASSERT_EQUAL_INT(0, g_cmsisTestTaskCount); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); + TEST_ASSERT_EQUAL_INT(TESTCOUNT_NUM_1, g_cmsisTestTaskCount); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4880 + * @tc.name : kernel operation for unlock + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelUnLock001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4920 + * @tc.name : kernel operation for unlock after kernel lock + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelUnLock002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + (void)osKernelLock(); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_4960 + * @tc.name : kernel operation for unlock after kernel lock twice + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelUnLock003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + (void)osKernelLock(); + (void)osKernelLock(); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5000 + * @tc.name : kernel operation for restore lock after kernel lock + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelRestoreLock001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + (void)osKernelLock(); + uwRet = osKernelRestoreLock(0); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5040 + * @tc.name : kernel operation for restore lock after kernel lock twice + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelRestoreLock002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + (void)osKernelLock(); + (void)osKernelLock(); + uwRet = osKernelRestoreLock(0); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5080 + * @tc.name : kernel operation for restore lock + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskFuncTestSuite, testOsKernelRestoreLock003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(0, uwRet); + uwRet = osKernelRestoreLock(1); + TEST_ASSERT_EQUAL_INT(1, uwRet); + uwRet = osKernelUnlock(); + TEST_ASSERT_EQUAL_INT(1, uwRet); +}; + +RUN_TEST_SUITE(CmsisTaskFuncTestSuite); diff --git a/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_task_pri_func_test.c b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_task_pri_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..428cac6c3b76d8774a2eae9feaed5b6c42ceee59 --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_task_pri_func_test.c @@ -0,0 +1,1782 @@ +/** + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "ohos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +osThreadId_t g_priTaskID01; +osPriority_t g_setPriority; +UINT16 g_threadCreateExit2; +UINT16 g_threadCreateExit3; +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskPriFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsistask, CmsisTaskPriFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTaskPriFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTaskPriFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void WaitThreadExit(osThreadId_t id, UINT16 const *exitFlag) +{ + UINT32 uwRet = osThreadSetPriority(id, osPriorityAboveNormal6); + printf("WaitThreadExit id = %d, uwRet = %d\n", id, uwRet); + UINT32 loop = 0; + while (*exitFlag != TESTCOUNT_NUM_1) { + osDelay(DELAY_TICKS_5); + if (loop % ALIVE_INFO_DIS == 0) { + printf("WaitThreadExit id = %d, loop = %d\n", id, loop++); + } + } + printf("WaitThreadExit exit\n"); +} +static void CmsisThreadGetPriorityFunc001(void const *argument) +{ + (void)argument; + osThreadAttr_t attr; + g_priTaskID01 = osThreadGetId(); + attr.priority = osThreadGetPriority(g_priTaskID01); + TEST_ASSERT_EQUAL_INT(g_setPriority, attr.priority); + g_threadCreateExit2 = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadSetPriorityFunc001(void const *argument) +{ + (void)argument; + osThreadAttr_t attr; + UINT32 uwRet; + g_priTaskID01 = osThreadGetId(); + uwRet = osThreadSetPriority(g_priTaskID01, g_setPriority); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + attr.priority = osThreadGetPriority(g_priTaskID01); + TEST_ASSERT_EQUAL_INT(g_setPriority, attr.priority); + g_threadCreateExit2 = TESTCOUNT_NUM_1; + osThreadExit(); +} + +static void CmsisThreadSetPriorityFunc002(void const *argument) +{ + (void)argument; + UINT32 uwRet; + g_priTaskID01 = osThreadGetId(); + uwRet = osThreadSetPriority(g_priTaskID01, g_setPriority); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + g_threadCreateExit2 = TESTCOUNT_NUM_1; + osThreadExit(); +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5120 + * @tc.name : thread operation for get priority when Priority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority001, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityLow1; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5160 + * @tc.name : thread operation for get priority input exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osThreadGetPriority(NULL); + TEST_ASSERT_EQUAL_INT(osPriorityError, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5200 + * @tc.name : thread operation for get current priority + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_priTaskID01 = osThreadGetId(); + uwRet = osThreadGetPriority(g_priTaskID01); + TEST_ASSERT_EQUAL_INT(osPriorityNormal, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5240 + * @tc.name : thread operation for get priority when Priority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityLow7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5280 + * @tc.name : thread operation for get priority when Priority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityBelowNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5320 + * @tc.name : thread operation for get priority when Priority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityBelowNormal7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5360 + * @tc.name : thread operation for get priority when Priority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5400 + * @tc.name : thread operation for get priority when Priority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityNormal7; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5440 + * @tc.name : thread operation for get priority when Priority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityAboveNormal; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5480 + * @tc.name : thread operation for get priority when Priority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadGetPriority010, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityAboveNormal6; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadGetPriorityFunc001, NULL, &attr); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5520 + * @tc.name : thread operation for set priority input1 exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osThreadSetPriority(NULL, osPriorityNormal); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5560 + * @tc.name : thread operation for set priority input2 exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + g_priTaskID01 = osThreadGetId(); + uwRet = osThreadSetPriority(g_priTaskID01, osPriorityNone); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5600 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityNone + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority003, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityNone; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5640 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityIdle + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority004, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityIdle; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5680 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityLow + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority005, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityLow; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5720 + * @tc.name : set priority when curPriority = osPriorityLow1 and setPriority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority006, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityLow1; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5760 + * @tc.name : set priority when curPriority = osPriorityLow1 and setPriority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority007, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityLow7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5800 + * @tc.name : set priority when curPriority = osPriorityLow1 and setPriority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority008, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityBelowNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5840 + * @tc.name : set priority when curPriority = osPriorityLow1 and setPriority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority009, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityBelowNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5880 + * @tc.name : set priority when curPriority = osPriorityLow1 and setPriority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority010, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5920 + * @tc.name : set priority when curPriority = osPriorityLow1 and setPriority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority011, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_5960 + * @tc.name : set priority when curPriority = osPriorityLow1 and setPriority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority012, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityAboveNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6000 + * @tc.name : set priority when curPriority = osPriorityLow1 and setPriority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority013, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityAboveNormal6; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6040 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityAboveNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority014, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityAboveNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6080 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityHigh + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority015, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityHigh; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6120 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityHigh7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority016, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityHigh7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6160 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityRealtime + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority017, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityRealtime; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6200 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityRealtime7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority018, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityRealtime7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6240 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityISR + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority019, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityISR; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6280 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityError + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority020, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityError; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6320 + * @tc.name : set invalid priority when curPriority = osPriorityLow1 and setPriority = osPriorityReserved + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority021, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityLow1; + g_setPriority = osPriorityReserved; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6360 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityNone + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority022, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityNone; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6400 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityIdle + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority023, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityIdle; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6440 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityLow + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority024, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityLow; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6480 + * @tc.name : set priority when curPriority = osPriorityNormal and setPriority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority025, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityLow1; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6520 + * @tc.name : set priority when curPriority = osPriorityNormal and setPriority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority026, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityLow7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6560 + * @tc.name : set priority when curPriority = osPriorityNormal and setPriority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority027, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityBelowNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6600 + * @tc.name : set priority when curPriority = osPriorityNormal and setPriority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority028, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityBelowNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6640 + * @tc.name : set priority when curPriority = osPriorityNormal and setPriority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority029, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6680 + * @tc.name : set priority when curPriority = osPriorityNormal and setPriority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority030, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6720 + * @tc.name : set priority when curPriority = osPriorityNormal and setPriority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority031, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityAboveNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6760 + * @tc.name : set priority when curPriority = osPriorityNormal and setPriority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority032, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityAboveNormal6; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6800 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityAboveNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority033, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityAboveNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6840 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityHigh + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority034, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityHigh; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6880 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityHigh7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority035, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityHigh7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6920 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityRealtime + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority036, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityRealtime; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_6960 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityRealtime7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority037, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityRealtime7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7000 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityISR + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority038, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityISR; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7040 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityError + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority039, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityError; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7080 + * @tc.name : set invalid priority when curPriority = osPriorityNormal and setPriority = osPriorityReserved + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority040, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityNormal; + g_setPriority = osPriorityReserved; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7120 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityNone + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority041, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityNone; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7160 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityIdle + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority042, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityIdle; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7200 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityLow + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority043, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityLow; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7240 + * @tc.name : set priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityLow1 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority044, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityLow1; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7280 + * @tc.name : set priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityLow7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority045, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityLow7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7320 + * @tc.name : set priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityBelowNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority046, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityBelowNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7360 + * @tc.name : set priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityBelowNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority047, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityBelowNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7400 + * @tc.name : set priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority048, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7440 + * @tc.name : set priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority049, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7480 + * @tc.name : set priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityAboveNormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority050, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityAboveNormal; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7520 + * @tc.name : set priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityAboveNormal6 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority051, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityAboveNormal6; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc001, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7560 + * @tc.name : set invalid priority when curPriority = PriorityAboveNormal6 and setPriority = PriorityAboveNormal7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority052, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityAboveNormal7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7600 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityHigh + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority053, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityHigh; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7640 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityHigh7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority054, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityHigh7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7680 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityRealtime + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority055, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityRealtime; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7720 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityRealtime7 + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority056, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityRealtime7; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7760 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityISR + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority057, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityISR; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7800 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityError + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority058, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityError; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7840 + * @tc.name : set invalid priority when curPriority = osPriorityAboveNormal6 and setPriority = osPriorityReserved + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsThreadSetPriority059, Function | MediumTest | Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = osPriorityAboveNormal6; + g_setPriority = osPriorityReserved; + g_threadCreateExit2 = 0; + id = osThreadNew((osThreadFunc_t)CmsisThreadSetPriorityFunc002, NULL, &attr); + osDelay(DELAY_TICKS_5); + TEST_ASSERT_NOT_NULL(id); + WaitThreadExit(id, &g_threadCreateExit2); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7880 + * @tc.name : delay operation for 5 ticks + * @tc.desc : [C- SOFTWARE -0200] + + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelay001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osDelay(DELAY_TICKS_5); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7920 + * @tc.name : delay operation + * @tc.desc : [C- SOFTWARE -0200] + + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelay002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osDelay(0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_7960 + * @tc.name : delay until operation + * @tc.desc : [C- SOFTWARE -0200] + + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelayUntil001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + UINT32 uwTickCnt; + UINT32 uwUntilTickCnt; + uwTickCnt = osKernelGetTickCount(); + uwUntilTickCnt = uwTickCnt + DELAY_TICKS_5; + uwRet = osDelayUntil(uwUntilTickCnt); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_8000 + * @tc.name : delay until operation input exception for 1 tick + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelayUntil002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osDelayUntil(DELAY_TICKS_1); + TEST_ASSERT_EQUAL_INT(osError, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TASK_OPERATION_8040 + * @tc.name : delay until operation input exception + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTaskPriFuncTestSuite, testOsDelayUntil003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + UINT32 uwTickCnt; + UINT32 uwUntilTickCnt; + uwTickCnt = osKernelGetTickCount(); + uwUntilTickCnt = uwTickCnt - DELAY_TICKS_5; + uwRet = osDelayUntil(uwUntilTickCnt); + TEST_ASSERT_EQUAL_INT(osError, uwRet); +}; + +RUN_TEST_SUITE(CmsisTaskPriFuncTestSuite); diff --git a/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_timer_func_test.c b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_timer_func_test.c new file mode 100755 index 0000000000000000000000000000000000000000..8d842b22c3f5d475595c5536e4ffb229213078f2 --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/src/cmsis_timer_func_test.c @@ -0,0 +1,657 @@ +/** + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#include "ohos_types.h" +#include +#include "hctest.h" +#include "los_config.h" +#include "cmsis_os2.h" +#include "kernel_test.h" + +UINT16 g_cmsisTestTimeCount; +#define MILLISEC_NUM_INT10 10U +#define MILLISEC_NUM_INT4 4U +#define INVALID_TIMER_TYPE 10 +#define TIMER_PERIODIC_COUNT 2 + + +/** + * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency + * @param : subsystem name is utils + * @param : module name is utilsFile + * @param : test suit name is CmsisTaskFuncTestSuite + */ +LITE_TEST_SUIT(Cmsis, Cmsistimer, CmsisTimerFuncTestSuite); + +/** + * @tc.setup : setup for all testcases + * @return : setup result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTimerFuncTestSuiteSetUp(void) +{ + return TRUE; +} + +/** + * @tc.teardown : teardown for all testcases + * @return : teardown result, TRUE is success, FALSE is fail + */ +static BOOL CmsisTimerFuncTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +static void CmsisTimerFunc001(void const *argument) +{ + (void)argument; + return; +} + +static void CmsisTimerFunc002(void const *argument) +{ + (void)argument; + g_cmsisTestTimeCount++; + return; +} + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0100 + * @tc.name : timer operation for creat with parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew001, Function | MediumTest | Level1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + (void)osTimerDelete(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0200 + * @tc.name : timer operation for creat with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew002, Function | MediumTest | Level1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + (void)osTimerDelete(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0300 + * @tc.name : timer creat operation with NULL func and parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew003, Function | MediumTest | Level1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew(NULL, osTimerOnce, &value, NULL); + TEST_ASSERT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0400 + * @tc.name : timer creat operation with NULL func and parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew004, Function | MediumTest | Level1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew(NULL, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0500 + * @tc.name : timer operation for invalid timer type + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerNew005, Function | MediumTest | Level1) +{ + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, INVALID_TIMER_TYPE, &value, NULL); + TEST_ASSERT_NULL(id); + osDelay(DELAY_TICKS_5); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0600 + * @tc.name : timer operation for start with parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, millisec); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0700 + * @tc.name : timer operation for start with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, millisec); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0800 + * @tc.name : timer operation for start with callback func and parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + g_cmsisTestTimeCount = 0; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc002, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, millisec); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + osDelay(DELAY_TICKS_10); + TEST_ASSERT_EQUAL_INT(1, g_cmsisTestTimeCount); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_0900 + * @tc.name : timer operation for start with callback func and parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart004, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + g_cmsisTestTimeCount = 0; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc002, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, millisec); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + + osDelay(DELAY_TICKS_10); + TEST_ASSERT_EQUAL_INT(TIMER_PERIODIC_COUNT, g_cmsisTestTimeCount); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1000 + * @tc.name : timer start operation with ticks = 0 and parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart005, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1100 + * @tc.name : timer start operation with ticks = 0 and parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart006, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + uwRet = osTimerStart(id, 0); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1200 + * @tc.name : timer start operation with timer_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStart007, Function | MediumTest | Level1) +{ + UINT32 uwRet; + UINT32 millisec = MILLISEC_NUM_INT4; + uwRet = osTimerStart(NULL, millisec); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1300 + * @tc.name : timer operation for delete with parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osDelay(1); + uwRet = osTimerDelete(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1400 + * @tc.name : timer operation for delete with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osDelay(1); + uwRet = osTimerDelete(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1500 + * @tc.name : timer operation for delete after osTimerStart with parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osDelay(1); + uwRet = osTimerDelete(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1600 + * @tc.name : timer operation for delete after osTimerStart with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete004, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osDelay(1); + uwRet = osTimerDelete(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1700 + * @tc.name : timer delete operation with timer_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerDelete005, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osTimerDelete(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1800 + * @tc.name : timer operation for stop after osTimerStart with parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osDelay(1); + uwRet = osTimerStop(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_1900 + * @tc.name : timer operation for stop after osTimerStart with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osDelay(1); + uwRet = osTimerStop(id); + TEST_ASSERT_EQUAL_INT(osOK, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2000 + * @tc.name : timer operation for stop with parameter osTimerOnce + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osDelay(1); + uwRet = osTimerStop(id); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2100 + * @tc.name : timer operation for stop with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop004, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osDelay(1); + uwRet = osTimerStop(id); + TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2200 + * @tc.name : timer stop operation with timer_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerStop005, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osTimerStop(NULL); + TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2300 + * @tc.name : timer operation for running + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2400 + * @tc.name : timer operation for running after osTimerStart + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning002, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(1, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2500 + * @tc.name : timer operation for running after osTimerStart and osTimerStop + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning003, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osTimerStop(id); + + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2600 + * @tc.name : timer operation for running after osTimerStart and osTimerDelete + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning004, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osTimerDelete(id); + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2700 + * @tc.name : timer operation for running with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning005, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2800 + * @tc.name : timer operation for running after osTimerStart with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning006, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(1, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_2900 + * @tc.name : timer operation for running after osTimerStart and osTimerStop with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning007, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osTimerStop(id); + + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); + (void)osTimerDelete(id); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_3000 + * @tc.name : timer operation for running after osTimerStart and osTimerDelete with parameter osTimerPeriodic + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning008, Function | MediumTest | Level1) +{ + UINT32 uwRet; + osTimerId_t id; + UINT32 value=0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew ((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + TEST_ASSERT_NOT_NULL(id); + + osTimerStart(id, millisec); + osTimerDelete(id); + uwRet = osTimerIsRunning(id); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_3100 + * @tc.name : timer running inquiry with timer_id = NULL + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsTimerIsRunning009, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osTimerIsRunning(NULL); + TEST_ASSERT_EQUAL_INT(0, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_3200 + * @tc.name : os operation for get tick freq + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsKernelGetTickFreq001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osKernelGetTickFreq(); + TEST_ASSERT_EQUAL_INT(LOSCFG_BASE_CORE_TICK_PER_SECOND, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_3300 + * @tc.name : os operation for get sys time freq + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsKernelGetSysTimerFreq001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osKernelGetSysTimerFreq(); + TEST_ASSERT_EQUAL_INT(OS_SYS_CLOCK, uwRet); +}; + +/** + * @tc.number : SUB_KERNEL_CMSIS_TIMER_OPERATION_3400 + * @tc.name : os operation for get sys time count + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(CmsisTimerFuncTestSuite, testOsKernelGetSysTimerCount001, Function | MediumTest | Level1) +{ + UINT32 uwRet; + uwRet = osKernelGetSysTimerCount(); + TEST_ASSERT_GREATER_THAN_UINT32(0, uwRet); +}; + +RUN_TEST_SUITE(CmsisTimerFuncTestSuite); diff --git a/testsuites/kernel_lite/kernelcmsis_hal/src/kernel_test.h b/testsuites/kernel_lite/kernelcmsis_hal/src/kernel_test.h new file mode 100755 index 0000000000000000000000000000000000000000..4e9ac3617ccbb81aea7108434a345ecc9004a43d --- /dev/null +++ b/testsuites/kernel_lite/kernelcmsis_hal/src/kernel_test.h @@ -0,0 +1,51 @@ +/* + * @Author: your name + * @Date: 2022-01-18 15:06:32 + * @LastEditTime: 2022-01-18 15:06:38 + * @LastEditors: your name + * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + * @FilePath: \OpenHarmonyLiteOS\kernel\liteos_m\testsuites\kernel_lite\kernelcmsis_hal\src\kernel_test.h + */ +/** + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef KERNEL_TEST_H +#define KERNEL_TEST_H + +#define TESTCOUNT_NUM_1 1 +#define TESTCOUNT_NUM_2 2 +#define TESTCOUNT_NUM_3 3 +#define TESTCOUNT_NUM_4 4 +#define TESTCOUNT_NUM_5 5 + +#define DELAY_TICKS_1 1 +#define DELAY_TICKS_5 5 +#define DELAY_TICKS_10 10 + +#define TEST_TASK_STACK_SIZE 0x1000 +#define TASK_LOOP_NUM 0x10000000 +#define TEST_TIME 10 +#define THREAD_COUNT_MIN 3 +#define THREAD_COUNT_MAX 30 +#define THREAD_STACK_SPACE_MAX 4096 +#define MAX_UINT32 0xFFFFFFFF +#define ALIVE_INFO_DIS 10000 + +#ifdef __cplusplus +#if __cplusplus +#endif +#endif /* __cplusplus */ +#endif diff --git a/testsuites/kernel_lite/math_posix/BUILD.gn b/testsuites/kernel_lite/math_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..9c35d5c4ba951d50dc019a9728ee5dd7203a29fe --- /dev/null +++ b/testsuites/kernel_lite/math_posix/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsMathApiTest") { + suite_name = "acts" + sources = [ + "src/MathApiTest.c", + "src/MathStdApiTest.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + ] +} diff --git a/testsuites/kernel_lite/math_posix/Test.json b/testsuites/kernel_lite/math_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..1ffe9051cc1693c512e5add9a9c35401ce54fce1 --- /dev/null +++ b/testsuites/kernel_lite/math_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix math api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsMathApiTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/math_posix/src/MathApiTest.c b/testsuites/kernel_lite/math_posix/src/MathApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..185961314785d65feb1d8102c943a3ed2726ca7e --- /dev/null +++ b/testsuites/kernel_lite/math_posix/src/MathApiTest.c @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "log.h" +#include "utils.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(MATH, MathApi, MathApiTestSuite); + +static BOOL MathApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL MathApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** +* @tc.number SUB_KERNEL_MATH_MATH_SIGNBIT_0100 +* @tc.name test signbit api +* @tc.desc [C- SOFTWARE -0100] +**/ +LITE_TEST_CASE(MathApiTestSuite, testsignbit, Function | MediumTest | Level1) +{ + const int testCount = 3; + float testValues[] = {3.000001, -3.000001, 0.0}; + float expected[] = {0, 1, 0}; + float ret; + for (int i = 0; i < testCount; ++i) { + ret = signbit(testValues[i]); + TEST_ASSERT_EQUAL_INT(ret, expected[i]); + } +} + +RUN_TEST_SUITE(MathApiTestSuite); + +void MathApiTest() +{ + RUN_ONE_TESTCASE(testsignbit); +} diff --git a/testsuites/kernel_lite/math_posix/src/MathStdApiTest.c b/testsuites/kernel_lite/math_posix/src/MathStdApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..96890c1ffc881ec6ddb7b96140baeb5bee5cb4c1 --- /dev/null +++ b/testsuites/kernel_lite/math_posix/src/MathStdApiTest.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "log.h" +#include "inttypes.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(MATH, MathStdApi, MathStdApiTestSuite); + +static BOOL MathStdApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL MathStdApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** +* @tc.number SUB_KERNEL_MATH_STD_STDLIB_0100 +* @tc.name test abs api +* @tc.desc [C- SOFTWARE -0100] +*/ +LITE_TEST_CASE(MathStdApiTestSuite, testAbs, Function | MediumTest | Level1) +{ + const int testCount = 3; + int testValues[] = {-3, 0, 3}; + int expected[] = {3, 0, 3}; + int ret; + for (int i = 0; i < testCount; ++i) { + ret = abs(testValues[i]); + TEST_ASSERT_EQUAL_INT(ret, expected[i]); + } +} + +/** +* @tc.number SUB_KERNEL_MATH_STD_LLABS_0100 +* @tc.name test llabs api +* @tc.desc [C- SOFTWARE -0100] +**/ +LITE_TEST_CASE(MathStdApiTestSuite, testllabs, Function | MediumTest | Level1) +{ + const int testCount = 3; + intmax_t testValues[] = {2147483649, -2147483649, 0}; + intmax_t expected[] = {2147483649, 2147483649, 0}; + + long long ret; + for (int i = 0; i < testCount; ++i) { + ret = llabs(testValues[i]); + TEST_ASSERT_EQUAL_INT(ret, expected[i]); + } +} + +RUN_TEST_SUITE(MathStdApiTestSuite); diff --git a/testsuites/kernel_lite/math_posix/src/MathUtils.h b/testsuites/kernel_lite/math_posix/src/MathUtils.h new file mode 100755 index 0000000000000000000000000000000000000000..0bb658ab70ccb1816e52baeedaf8edf46c585285 --- /dev/null +++ b/testsuites/kernel_lite/math_posix/src/MathUtils.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KERNEL_MATH_UTILS +#define KERNEL_MATH_UTILS + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static inline int Equalf(float a, float b) +{ + return fabsf(a - b) <= FLT_EPSILON; +} + +static inline int Equal(double a, double b) +{ + return fabs(a - b) <= DBL_EPSILON; +} + +static inline int Equall(long double a, long double b) +{ + return fabsl(a - b) <= LDBL_EPSILON; +} + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/testsuites/kernel_lite/mem_posix/BUILD.gn b/testsuites/kernel_lite/mem_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..e32aa88666243580c8836774c1f582d72c3fee36 --- /dev/null +++ b/testsuites/kernel_lite/mem_posix/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsMemApiTest") { + suite_name = "acts" + sources = [ + "src/ActsMemApiTest.c", + "src/MemApiTest.c", + ] + + include_dirs = [ + "//test/xts/tools/lite/hctest/include", + "//third_party/unity/src", + "src", + "//utils/native/lite/include", + "../utils", + ] + + cflags = [ "-Wno-error" ] +} + diff --git a/testsuites/kernel_lite/mem_posix/Test.json b/testsuites/kernel_lite/mem_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..4de6d76c4febb01daaafb76abe4b10eda608fe03 --- /dev/null +++ b/testsuites/kernel_lite/mem_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix mem api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsMemApiTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/mem_posix/src/ActsMemApiTest.c b/testsuites/kernel_lite/mem_posix/src/ActsMemApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..346f86a9e044a0290194c1dfb6dd242660cf9a5b --- /dev/null +++ b/testsuites/kernel_lite/mem_posix/src/ActsMemApiTest.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include "ohos_types.h" +#include "hctest.h" +#include "utils.h" +#include "log.h" + +LITE_TEST_SUIT(MEM, ActsMemApi, ActsMemApiTestSuite); + +static BOOL ActsMemApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL ActsMemApiTestSuiteTearDown(void) +{ + LOG("+-------------------------------------------+\n"); + return TRUE; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMCHR_0100 +* @tc.name test memchr api +* @tc.desc [C- SOFTWARE -0200] +*/ +LITE_TEST_CASE(ActsMemApiTestSuite, testMemchr_0100, Function | MediumTest | Level1) { + char srcStr[] = "this is str a;"; + char *pos = nullptr; + + LogPrint(" memchr *s:='%s' c:='a' size:='14',", srcStr); + pos = (char *)memchr(srcStr, 'a', 14); + LogPrint(" --> return pos:='%x'\n", pos); + + ASSERT_TRUE(pos); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMCHR_1000 +* @tc.name test memchr api para len not enough +* @tc.desc [C- SOFTWARE -0200] +*/ +LITE_TEST_CASE(ActsMemApiTestSuite, testMemchr_1000, Function | MediumTest | Level1) { + char srcStr[] = "this is str a;"; + char *pos = nullptr; + + LogPrint(" memchr *s:='%s' c:='a' size:='4',", srcStr); + pos = (char *)memchr(srcStr, 'a', 4); + LogPrint(" --> return pos:='%x'\n", pos); + ASSERT_FALSE(pos); +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_MEM_MEMCHR_1100 +* @tc.name test memchr api para c not found +* @tc.desc [C- SOFTWARE -0200] +*/ +LITE_TEST_CASE(ActsMemApiTestSuite, testMemchr_1100, Function | MediumTest | Level1) { + char srcStr[] = "this is str a;"; + char *pos = nullptr; + + LogPrint(" memchr *s:='%s' c:='b' size:='14',", srcStr); + pos = (char *)memchr(srcStr, 'b', 14); + LogPrint(" --> return pos:='%x'\n", pos); + ASSERT_FALSE(pos); +} + +RUN_TEST_SUITE(ActsMemApiTestSuite); + diff --git a/testsuites/kernel_lite/mem_posix/src/MemApiTest.c b/testsuites/kernel_lite/mem_posix/src/MemApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..72bf188878aaf9186e6967153040e952cee7b230 --- /dev/null +++ b/testsuites/kernel_lite/mem_posix/src/MemApiTest.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "ohos_types.h" +#include "hctest.h" +#include "utils.h" +#include "log.h" + +LITE_TEST_SUIT(MEM, MemApi, MemApiTestSuite); + +static BOOL MemApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL MemApiTestSuiteTearDown(void) +{ + LOG("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_MEM_MEMSET_0100 + * @tc.name memset function set buffer value test + * @tc.desc [C-L*-311] MUST NOT alter NDK API behavior. + */ +LITE_TEST_CASE(MemApiTestSuite, testMemset, Function | MediumTest | Level1) +{ + char chr = 'A'; + int i, len, failure; + len = GetRandom(1024); + errno_t err = EOK; + + char buf[1024]; + err = memset_s(buf, sizeof(buf), chr, len); + if(err != EOK) { + LOG("memset_s failed, err = %d\n", err); + } + failure = 0; + for (i = 0; i < len; i++) { + if (buf[i] != chr) { + failure = 1; + break; + } + } + ASSERT_TRUE(failure == 0); +} + +/** + * @tc.number SUB_KERNEL_MEM_MEMCPY_0100 + * @tc.name memcpy function copy buffer test + * @tc.desc [C-L*-311] MUST NOT alter NDK API behavior. + */ +LITE_TEST_CASE(MemApiTestSuite, testMemcpy, Function | MediumTest | Level2) +{ + char chr = 'A'; + int i, len, failure; + char src[1024]; + char dst[1024]; + + len = GetRandom(1024); + + for (i = 0; i < len; i++) { + src[i] = chr + i % 26; + } + + memcpy(dst, src, len); + failure = 0; + for (i = 0; i < len; i++) { + if (dst[i] != src[i]) { + failure = 1; + break; + } + } + ASSERT_TRUE(failure == 0); +} + +/** + * @tc.number SUB_KERNEL_MEM_MEMMOVE_0100 + * @tc.name memmove function move buffer test + * @tc.desc [C-L*-311] MUST NOT alter NDK API behavior. + */ +LITE_TEST_CASE(MemApiTestSuite, testMemmove, Function | MediumTest | Level2) +{ + char chr = 'A'; + char buf[1024]; + int i, len, failure; + + len = sizeof(buf); + for (i = 0; i < len; i++) { + buf[i] = chr + GetRandom(26); + } + memmove(&buf[0], &buf[len / 2], len / 2); + + failure = 0; + for (i = 0; i < len / 2; i++) { + if (buf[i] != buf[len / 2 + i]) { + failure = 1; + LOG("buf[i] != buf[len / 2 + i], buf[i] = %d, buf[len / 2 + i] = %d", buf[i], buf[len / 2 + i]); + break; + } + } + /* buf[i] not equal to buf[len / 2 + i] */ + ASSERT_TRUE(failure == 0); +} + +/** + * @tc.number SUB_KERNEL_MEM_MEMMOVE_0200 + * @tc.name memmove function overlay move buffer test + * @tc.desc [C-L*-311] MUST NOT alter NDK API behavior. + */ +LITE_TEST_CASE(MemApiTestSuite, testMemmoveOverlay, Function | MediumTest | Level3) +{ + char chr = 'A'; + char buf[1024]; + char backup[1024]; + int i, len, failure; + + len = sizeof(buf); + for (i = 0; i < len; i++) { + buf[i] = chr + GetRandom(26); + backup[i] = buf[i]; + } + memmove(&buf[16], &buf[0], len / 2); + + failure = 0; + for (i = 0; i < len / 2; i++) { + if (buf[i + 16] != backup[i]) { + failure = 1; + LOG("buf[i + 16] != backup[i], buf[i + 16] = %d, backup[i] = %d", buf[i + 16], backup[i]); + break; + } + } + ASSERT_TRUE(failure == 0); +} + + +/** + * @tc.number SUB_KERNEL_MEM_MEMCMP_0100 + * @tc.name memmove function move buffer test + * @tc.desc [C-L*-311] MUST NOT alter NDK API behavior. + */ +LITE_TEST_CASE(MemApiTestSuite, testMemcmp, Function | MediumTest | Level2) +{ + char orign[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; + char lt[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x77}; + char eq[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; + char gt[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x99}; + + int ret; + int len = sizeof(orign); + + ret = memcmp(lt, orign, len); + ASSERT_TRUE(ret < 0); + + ret = memcmp(eq, orign, len); + ASSERT_TRUE(ret == 0); + + ret = memcmp(gt, orign, len); + ASSERT_TRUE(ret > 0); + + ret = memcmp(gt, orign, 0); + ASSERT_TRUE(ret == 0); +} + +RUN_TEST_SUITE(MemApiTestSuite); diff --git a/testsuites/kernel_lite/net_posix/BUILD.gn b/testsuites/kernel_lite/net_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..88ffe62891d45e42a54170aa5edbaf6c87982627 --- /dev/null +++ b/testsuites/kernel_lite/net_posix/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsNetTest") { + suite_name = "acts" + sources = [ + "src/ActsNetTest.c", + ] + + include_dirs = [ + "//test/xts/tools/lite/hctest/include", + "//third_party/unity/src", + "src", + "//utils/native/lite/include", + "../utils", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/testsuites/kernel_lite/net_posix/Test.json b/testsuites/kernel_lite/net_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..b533aa4349bd3f1d2c4b08f18fff15e23e29ff25 --- /dev/null +++ b/testsuites/kernel_lite/net_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsNetTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/net_posix/src/ActsNetTest.c b/testsuites/kernel_lite/net_posix/src/ActsNetTest.c new file mode 100755 index 0000000000000000000000000000000000000000..67d21fe7377c614f831e1f27ed89ea731c726750 --- /dev/null +++ b/testsuites/kernel_lite/net_posix/src/ActsNetTest.c @@ -0,0 +1,430 @@ +/** + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ohos_types.h" +#include "hctest.h" +#include "utils.h" +#include "log.h" +#include "lwip/sockets.h" + +#define PROTOCOL_COUNT 36 +#define TEST_FD_COUNT 10 +#define STACK_PORT 2288 +#define PEER_PORT 2288 +#define BUF_SIZE (100) +static const char* g_udpMsg = "Hi, this is UDP"; +static const char* g_srvMsg = "Hi, this is TCP server"; +static const char* g_cliMsg = "Hello, this is TCP client"; +static const char* g_localHost = "127.0.0.1"; +static char g_protocolList[PROTOCOL_COUNT][11] = { + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", + "egp", "pup", "udp", "hmp", "xns-idp", "rdp", "iso-tp4", "xtp", "ddp", "idpr-cmtp", "ipv6", + "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre", "esp", "ah", "skip", "ipv6-icmp", "ipv6-nonxt", + "ipv6-opts", "rspf", "vmtp", "ospf", "ipip", "encap", "pim", "raw" +}; +static int g_protocolNumber[PROTOCOL_COUNT] = { + 0, 1, 2, 3, 4, 5, 6, 8, 12, 17, 20, 22, 27, 29, 36, 37, + 38, 41, 43, 44, 45, 46, 47, 50, 51, 57, 58, 59, 60, 73, 81, 89, 94, 98, 103, 255 +}; + +static pthread_barrier_t g_barrier; +#define WAIT() pthread_barrier_wait(&g_barrier) + +LITE_TEST_SUIT(NET, ActsNet, ActsNetTestSuite); + +static BOOL ActsNetTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL ActsNetTestSuiteTearDown(void) +{ + LOG("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number : SUB_KERNEL_NET_0730 + * @tc.name : test ioctl get and set IFHWADDR + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testIoctlIfhwAddr, Function | MediumTest | Level2) +{ + int udpFd = socket(AF_INET, SOCK_DGRAM, 0); + ASSERT_NE(-1, udpFd); + + struct ifreq ifr[5]; + struct ifconf ifc = {0}; + memset_s(&ifc, sizeof(struct ifconf), 0, sizeof(struct ifconf)); + ifc.ifc_len = 5 * sizeof(struct ifreq); + ifc.ifc_buf = (char *)ifr; + int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifc); + ASSERT_EQ(0, ret); + + char rst1[18]; + char rst2[18]; + char* macPtr = NULL; + struct ifreq ifrTmp = {0}; + struct sockaddr_in *addr = NULL; + int ifrCount = ifc.ifc_len / sizeof(struct ifreq); + EXPECT_TRUE(ifrCount >= 2); + for (int i = 0; i < ifrCount; i++) { + addr = (struct sockaddr_in *)&ifr[i].ifr_addr; + if (strcmp("lo", ifr[i].ifr_name) != 0) { + // get ifhwaddr + memset_s(&ifrTmp, sizeof(struct ifreq), 0, sizeof(struct ifreq)); + ret = strcpy_s(ifrTmp.ifr_name, sizeof(ifrTmp.ifr_name), ifr[i].ifr_name); + EXPECT_EQ(0, ret); + ret = ioctl(udpFd, SIOCGIFHWADDR, &ifrTmp); + ASSERT_EQ(0, ret); + macPtr = ifrTmp.ifr_hwaddr.sa_data; + ret = sprintf_s(rst1, sizeof(rst1), "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", *macPtr, *(macPtr+1), + *(macPtr+2), *(macPtr+3), *(macPtr+4), *(macPtr+5)); + EXPECT_EQ(strlen(rst1), (unsigned int)ret); + printf("[###]get %s rst[%s]\n", ifrTmp.ifr_name, rst1); + } + } + ret = close(udpFd); + EXPECT_EQ(0, ret); +} + +/** + * @tc.number : SUB_KERNEL_NET_1000 + * @tc.name : test socket operation + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testSocketOpt, Function | MediumTest | Level2) +{ + socklen_t len; + struct timeval timeout = {0}; + int fd = socket(AF_INET, SOCK_STREAM, 0); + EXPECT_NE(-1, fd); + + int error = -1; + len = sizeof(error); + int ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, error); + + len = sizeof(timeout); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + EXPECT_EQ(0, ret); + + timeout.tv_sec = 1000; + len = sizeof(timeout); + ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len); + EXPECT_EQ(0, ret); + + memset_s(&timeout, len, 0, len); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + EXPECT_EQ(0, ret); + EXPECT_EQ(1000, timeout.tv_sec); + + int flag = 1; + ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); + EXPECT_EQ(0, ret); + + flag = 0; + len = sizeof(flag); + ret = getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, &len); + EXPECT_EQ(0, ret); + EXPECT_EQ(1, flag); + + error = -1; + len = sizeof(error); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + EXPECT_EQ(0, ret); + EXPECT_EQ(0, error); + + ret = close(fd); + EXPECT_EQ(0, ret); +} + +/** + * @tc.number : SUB_KERNEL_NET_1100 + * @tc.name : test getsockname and getpeername invalid input + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testGetSocketNameInvalidInput, Function | MediumTest | Level3) +{ + struct sockaddr addr = {0}; + socklen_t addrLen = sizeof(addr); + int ret = getsockname(-1, &addr, &addrLen); + EXPECT_EQ(-1, ret); + ret = getpeername(-1, &addr, &addrLen); + EXPECT_EQ(-1, ret); + ret = getsockname(0, &addr, &addrLen); + EXPECT_EQ(-1, ret); + ret = getpeername(0, &addr, &addrLen); + EXPECT_EQ(-1, ret); + ret = getsockname(1, &addr, &addrLen); + EXPECT_EQ(-1, ret); + ret = getpeername(1, &addr, &addrLen); + EXPECT_EQ(-1, ret); + ret = getsockname(130, &addr, &addrLen); + EXPECT_EQ(-1, ret); + ret = getpeername(130, &addr, &addrLen); + EXPECT_EQ(-1, ret); + ret = getsockname(10, NULL, &addrLen); + EXPECT_EQ(-1, ret); + ret = getpeername(10, NULL, &addrLen); + EXPECT_EQ(-1, ret); + ret = getsockname(10, &addr, NULL); + EXPECT_EQ(-1, ret); + ret = getpeername(10, &addr, NULL); + EXPECT_EQ(-1, ret); +} + +/** + * @tc.number : SUB_KERNEL_NET_2400 + * @tc.name : test convert value from host to network byte order + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testHostToNetwork, Function | MediumTest | Level2) +{ + uint32_t intInput1 = 0; + uint32_t intRst1 = htonl(intInput1); + uint32_t intInput2 = 65536; + uint32_t intRst2 = htonl(intInput2); + + uint16_t shortInput1 = 0; + uint16_t shortRst1 = htons(shortInput1); + uint16_t shortInput2 = 255; + uint16_t shortRst2 = htons(shortInput2); + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + uint32_t expectZero = 0; + uint32_t expectForIinput2 = 256; + uint32_t expectForSinput2 = 65280; + EXPECT_EQ(expectZero, intRst1); + EXPECT_EQ(expectForIinput2, intRst2); + EXPECT_EQ(expectZero, shortRst1); + EXPECT_EQ(expectForSinput2, shortRst2); +#else + EXPECT_EQ(intInput1, intRst1); + EXPECT_EQ(intInput2, intRst2); + EXPECT_EQ(shortInput1, shortRst1); + EXPECT_EQ(shortInput2, shortRst2); +#endif +} + +/** + * @tc.number : SUB_KERNEL_NET_2500 + * @tc.name : test convert value from network to host byte order + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testNetworkToHost, Function | MediumTest | Level2) +{ + uint32_t intInput1 = 0; + uint32_t intRst1 = ntohl(intInput1); + uint32_t intInput2 = 65536; + uint32_t intRst2 = ntohl(intInput2); + uint16_t shortInput1 = 0; + uint16_t shortRst1 = ntohs(shortInput1); + uint16_t shortInput2 = 255; + uint16_t shortRst2 = ntohs(shortInput2); + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + uint32_t expectZero = 0; + uint32_t expectForIinput2 = 256; + uint32_t expectForSinput2 = 65280; + EXPECT_EQ(expectZero, intRst1); + EXPECT_EQ(expectForIinput2, intRst2); + EXPECT_EQ(expectZero, shortRst1); + EXPECT_EQ(expectForSinput2, shortRst2); +#else + EXPECT_EQ(intInput1, intRst1); + EXPECT_EQ(intInput2, intRst2); + EXPECT_EQ(shortInput1, shortRst1); + EXPECT_EQ(shortInput2, shortRst2); +#endif +} + +/** + * @tc.number : SUB_KERNEL_NET_2600 + * @tc.name : test inet_pton IPv4 normal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testInetPtonIpv4Normal, Function | MediumTest | Level2) +{ + int ret; + struct in_addr rst = {0}; + char cpAddrs[4][16] = {"10.58.212.100", "0.0.0.0", "255.0.0.0", "255.255.255.255"}; +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + unsigned int expectLittle[4] = {1691630090, 0, 255, 4294967295}; +#else + unsigned int expectBig[4] = {171627620, 0, 4278190080, 4294967295}; +#endif + + for (int i = 0; i < 4; i++) { + ret = inet_pton(AF_INET, cpAddrs[i], &rst); + EXPECT_EQ(1, ret); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + EXPECT_EQ(expectLittle[i], rst.s_addr); +#else + EXPECT_EQ(expectBig[i], rst.s_addr); +#endif + printf("[###]inet_pton %s: un[%u],s[%d],hex[%x]\n", cpAddrs[i], rst.s_addr, rst.s_addr, rst.s_addr); + } +} + +/** + * @tc.number : SUB_KERNEL_NET_2800 + * @tc.name : test inet_pton IPv6 normal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testInetPtonIpv6Normal, Function | MediumTest | Level2) +{ + int ret; + struct in6_addr rst = {0}; + char cpAddrs[6][40] = {"0101:0101:0101:0101:1010:1010:1010:1010", "0:0:0:0:0:0:0:0", + "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "::", "1::", "0011:0011:0011:0011:11:11:11:11"}; + for (int i = 0; i < 6; i++) { + ret = inet_pton(AF_INET6, cpAddrs[i], &rst); +printf("i = %d, cpAddrs = %s , ret = %d \n", i, cpAddrs[i], ret); + EXPECT_EQ(1, ret); + } +} + +/** + * @tc.number : SUB_KERNEL_NET_2900 + * @tc.name : test inet_pton IPv6 abnormal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testInetPtonIpv6Abnormal, Function | MediumTest | Level2) +{ + int ret; + struct in6_addr rst = {0}; + char cpAddrs[7][40] = {"127.0.0.1", "f", ":", "0:0", "1:::", ":::::::", + "1111:1111:1111:1111:1111:1111:1111:111G"}; + for (int i = 0; i < 7; i++) { + ret = inet_pton(AF_INET6, cpAddrs[i], &rst); +printf("i = %d, cpAddrs = %s , ret = %d \n", i, cpAddrs[i], ret); + EXPECT_EQ(0, ret); + } +} + +/** + * @tc.number : SUB_KERNEL_NET_3000 + * @tc.name : test inet_pton with invalid family + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testInetPtonInvalidFamily, Function | MediumTest | Level2) +{ + struct in_addr rst = {0}; + int ret = inet_pton(AF_IPX, "127.0.0.1", &rst); + EXPECT_EQ(-1, ret); + ret = inet_pton(-1, "127.0.0.1", &rst); + EXPECT_EQ(-1, ret); +} + +/** + * @tc.number : SUB_KERNEL_NET_3100 + * @tc.name : test inet_ntop IPv4 normal + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testInetNtopIpv4Normal, Function | MediumTest | Level2) +{ + const char* ret = NULL; + struct in_addr inputAddr = {0}; + char rstBuff[INET_ADDRSTRLEN]; +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + unsigned int inputLittle[4] = {0x64d43a0a, 0, 255, 4294967295}; +#else + unsigned int inputBig[4] = {171627620, 0, 4278190080, 4294967295}; +#endif + + char expectAddrs[4][16] = {"10.58.212.100", "0.0.0.0", "255.0.0.0", "255.255.255.255"}; + for (int i = 0; i < 4; i++) { +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + inputAddr.s_addr = inputLittle[i]; +#else + inputAddr.s_addr = inputBig[i]; +#endif + ret = inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff)); + if (ret == NULL) { + EXPECT_TRUE(ret != NULL); + } else { + printf("[###]inet_ntop expect [%s]: ret[%s], buf[%s]\n", expectAddrs[i], ret, rstBuff); + EXPECT_STREQ(expectAddrs[i], ret); + EXPECT_STREQ(expectAddrs[i], rstBuff); + } + } +} + +/** + * @tc.number : SUB_KERNEL_NET_3200 + * @tc.name : test inet_ntop IPv4 boundary input + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testInetNtopIpv4Abnormal, Function | MediumTest | Level2) +{ + const char* ret = NULL; + struct in_addr inputAddr = {0}; + char rstBuff[INET_ADDRSTRLEN]; + char expectStr[2][16] = {"255.255.255.255", "0.0.0.0"}; + for (int i = 0; i < 2; i++) { + inputAddr.s_addr = (i == 0 ? -1 : 4294967296); + ret = inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff)); + ASSERT_TRUE(ret != NULL); + EXPECT_STREQ(expectStr[i], ret); + EXPECT_STREQ(expectStr[i], rstBuff); + } +} + +/** + * @tc.number : SUB_KERNEL_NET_3500 + * @tc.name : test inet_ntop with invalid family + * @tc.desc : [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ActsNetTestSuite, testInetNtopInvalidFamily, Function | MediumTest | Level2) +{ + int iret; + const char* ret = NULL; + struct in6_addr inputAddr = {0}; + char rstBuff[INET6_ADDRSTRLEN]; + + iret = inet_pton(AF_INET6, "1::", &inputAddr); +printf("inputAddr = %s , ret = %d \n", inputAddr, ret); + ASSERT_EQ(1, iret); + ret = inet_ntop(AF_IPX, &inputAddr, rstBuff, sizeof(rstBuff)); + EXPECT_TRUE(ret == NULL); + ret = inet_ntop(-1, &inputAddr, rstBuff, sizeof(rstBuff)); + EXPECT_TRUE(ret == NULL); +} + +RUN_TEST_SUITE(ActsNetTestSuite); + diff --git a/testsuites/kernel_lite/process_posix/BUILD.gn b/testsuites/kernel_lite/process_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..5bcb160448185916a7c65c7007f46f262a5f8344 --- /dev/null +++ b/testsuites/kernel_lite/process_posix/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsProcessApiTest") { + suite_name = "acts" + sources = [ + "src/ActsProcessApiTest.c", + "src/PthreadAttrTest.c", + "src/PthreadBasicApiTest.c", + "src/PthreadTest.c", + ] + + include_dirs = [ + "//test/xts/tools/lite/hctest/include", + "//third_party/unity/src", + "src", + "//utils/native/lite/include", + "../utils", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/testsuites/kernel_lite/process_posix/Test.json b/testsuites/kernel_lite/process_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..12d503d0c6d2689979c3ab00722e551b577f321e --- /dev/null +++ b/testsuites/kernel_lite/process_posix/Test.json @@ -0,0 +1,28 @@ +{ + "description": "Config for kernel_lite posix process api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel_lite" + },{ + "source": "resource/kernel/process", + "target": "/test_root/kernel/process" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel_lite/ActsProcessApiTest.bin" + } +} diff --git a/testsuites/kernel_lite/process_posix/src/ActsProcessApiTest.c b/testsuites/kernel_lite/process_posix/src/ActsProcessApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..e54d1b4e0c55f98a7e482bfa58b25c4245ee7742 --- /dev/null +++ b/testsuites/kernel_lite/process_posix/src/ActsProcessApiTest.c @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ohos_types.h" +#include "hctest.h" +#include "utils.h" +#include "log.h" + +LITE_TEST_SUIT(PROCESS, ProcessApi, ProcessApiTestSuite); + +static BOOL ProcessApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL ProcessApiTestSuiteTearDown(void) +{ + LOG("+-------------------------------------------+\n"); + return TRUE; +} + +static void *ThreadFunc(void* arg) +{ + LogPrint(" This is ThreadFunc()\n"); + return NULL; +} + +/** +* @tc.number SUB_KERNEL_NDKAPI_PROCESS_PTHREAD_SETNAME_NP_1000 +* @tc.name test pthread_setname_np api para stringlong +* @tc.desc [C- SOFTWARE -0200] +*/ +LITE_TEST_CASE(ProcessApiTestSuite, testPthreadSetnameNp1000, Function | MediumTest | Level1) { + pthread_t thisThread; + int returnVal; + + returnVal = pthread_create(&thisThread, NULL, ThreadFunc, NULL); + // thisThread = pthread_self(); + LogPrint(" pthread_self(), --> return pthread_t:='%u(0x%x)'\n", + (unsigned int)thisThread, (unsigned int)thisThread); + + returnVal = pthread_setname_np(thisThread, "funcThreadNamelongName"); + LogPrint(" pthread_setname_np thread:='%u(0x%x)' *name:='funcThreadNamelongName', " + "--> returnVal:='%d'\n", thisThread, thisThread, returnVal); + + EXPECT_NE(returnVal, 0); + EXPECT_EQ(returnVal, ERANGE); +} + +RUN_TEST_SUITE(ProcessApiTestSuite); + diff --git a/testsuites/kernel_lite/process_posix/src/PthreadAttrTest.c b/testsuites/kernel_lite/process_posix/src/PthreadAttrTest.c new file mode 100755 index 0000000000000000000000000000000000000000..0ede04cae9e714d65fda8ef20e6ac2d1da11413a --- /dev/null +++ b/testsuites/kernel_lite/process_posix/src/PthreadAttrTest.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ohos_types.h" +#include "hctest.h" +#include "utils.h" +#include "PthreadTest.h" +#include "log.h" + +LITE_TEST_SUIT(PROCESS, PthreadAttr, PthreadAttrTestSuite); + +static BOOL PthreadAttrTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL PthreadAttrTestSuiteTearDown(void) +{ + LOG("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_ATTR_SETDETACHSTATE_0100 + * @tc.name basic test about pthread_attr_setdetachstate + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadAttrTestSuite, testPthreadAttrSetdetachstate, Function | MediumTest | Level3) +{ + pthread_t tid; + pthread_attr_t attr; + int param; + + // PTHREAD_CREATE_DETACHED + EXPECT_EQ(pthread_attr_init(&attr), 0); + EXPECT_EQ(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED), 0); + EXPECT_EQ(pthread_attr_getdetachstate(&attr, ¶m), 0); + EXPECT_EQ(param, PTHREAD_CREATE_DETACHED); + + ASSERT_EQ(pthread_create(&tid, &attr, ThreadPublic, NULL), 0); + EXPECT_EQ(pthread_attr_destroy(&attr), 0); + EXPECT_EQ(pthread_join(tid, NULL), EINVAL); + + // PTHREAD_CREATE_JOINABLE + EXPECT_EQ(pthread_attr_init(&attr), 0); + EXPECT_EQ(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE), 0); + EXPECT_EQ(pthread_attr_getdetachstate(&attr, ¶m), 0); + EXPECT_EQ(param, PTHREAD_CREATE_JOINABLE); + + ASSERT_EQ(pthread_create(&tid, &attr, ThreadPublic, NULL), 0); + EXPECT_EQ(pthread_attr_destroy(&attr), 0); + EXPECT_EQ(pthread_join(tid, NULL), 0); +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_ATTR_SETSTACKSIZE_0200 + * @tc.name test pthread_attr_setstacksize EINVAL + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadAttrTestSuite, testPthreadAttrSetstacksizeEINVAL, Function | MediumTest | Level3) +{ + pthread_attr_t attr; + size_t stackSize; + + EXPECT_EQ(pthread_attr_init(&attr), 0); + EXPECT_EQ(pthread_attr_getstacksize(&attr, &stackSize), 0); + stackSize = PTHREAD_STACK_MIN - 1; + LOG("PTHREAD_STACK_MIN = %d", PTHREAD_STACK_MIN); + EXPECT_EQ(pthread_attr_setstacksize(&attr, stackSize), EINVAL); + EXPECT_EQ(pthread_attr_destroy(&attr), 0); +} + +RUN_TEST_SUITE(PthreadAttrTestSuite); + diff --git a/testsuites/kernel_lite/process_posix/src/PthreadBasicApiTest.c b/testsuites/kernel_lite/process_posix/src/PthreadBasicApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..84893a64a06c908c842e30abe8b45581cc538972 --- /dev/null +++ b/testsuites/kernel_lite/process_posix/src/PthreadBasicApiTest.c @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ohos_types.h" +#include "hctest.h" +#include "utils.h" +#include "PthreadTest.h" +#include "mt_utils.h" +#include "log.h" + +LITE_TEST_SUIT(PROCESS, PthreadBasicApi, PthreadBasicApiTestSuite); + +static BOOL PthreadBasicApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL PthreadBasicApiTestSuiteTearDown(void) +{ + LOG("+-------------------------------------------+\n"); + return TRUE; +} + +void *ThreadPthreadCreateBasic(void *arg) +{ + char *s = (char*)arg; + EXPECT_STREQ(s, "1234567890 !@#$%^&*()_= ZXCVBNM [];'./>?:\" +-*/qwertyuiopasdfghjklzxcvbnm"); + return arg; +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_CREATE_0100 + * @tc.name pthread_create create a thread + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadBasicApiTestSuite, testPthreadCreateBasic, Function | MediumTest | Level2) +{ + pthread_t tid; + char str[] = "1234567890 !@#$%^&*()_= ZXCVBNM [];'./>?:\" +-*/qwertyuiopasdfghjklzxcvbnm"; + ASSERT_EQ(pthread_create(&tid, NULL, ThreadPthreadCreateBasic, (void*)str), 0); + + EXPECT_EQ(pthread_join(tid, NULL), 0); +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_JOIN_0200 + * @tc.name Test the function of pthread_join to get the return value + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadBasicApiTestSuite, testJoinReturn, Function | MediumTest | Level3) +{ + pthread_t tid; + int num = 4; + void *joinRe = NULL; + + ASSERT_EQ(pthread_create(&tid, NULL, ThreadPublic, (void*)&num), 0); + EXPECT_EQ(pthread_join(tid, &joinRe), 0); + + int *p = (int*)joinRe; + EXPECT_TRUE(&num == p); +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_JOIN_0300 + * @tc.name Test the function about pthread_join, but child thread Exited + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadBasicApiTestSuite, testJoinExited, Function | MediumTest | Level3) +{ + pthread_t tid; + ASSERT_EQ(pthread_create(&tid, NULL, ThreadPublic, NULL), 0); + Msleep(50); + EXPECT_EQ(pthread_join(tid, NULL), 0); +} + +void *ThreadPthreadExitThread(void *arg) +{ + pthread_exit(arg); + return NULL; +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_EXIT_0100 + * @tc.name Test the return function of pthread_exit in the child thread + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadBasicApiTestSuite, testPthreadExitThread, Function | MediumTest | Level3) +{ + pthread_t tid; + int num = 4; + void *joinRe = NULL; + + ASSERT_EQ(pthread_create(&tid, NULL, ThreadPthreadExitThread, (void*)&num), 0); + EXPECT_EQ(pthread_join(tid, &joinRe), 0); + int *p = (int*)joinRe; + EXPECT_TRUE(&num == p); +} + +void FunPthreadExit(void *arg) +{ + pthread_exit(arg); +} + +void *ThreadPthreadExitFunction(void *arg) +{ + FunPthreadExit(arg); + return NULL; +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_EXIT_0200 + * @tc.name Test the return function of pthread_exit in the child thread function + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadBasicApiTestSuite, testPthreadExitFunction, Function | MediumTest | Level3) +{ + pthread_t tid; + int num = 4; + void *joinRe = NULL; + + ASSERT_EQ(pthread_create(&tid, NULL, ThreadPthreadExitFunction, (void*)&num), 0); + EXPECT_EQ(pthread_join(tid, &joinRe), 0); + int *p = (int*)joinRe; + EXPECT_TRUE(&num == p); +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_DETACH_0100 + * @tc.name Use pthread_detach to detach child threads + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadBasicApiTestSuite, testPthreadDetach, Function | MediumTest | Level3) +{ + pthread_t tid; + ASSERT_EQ(pthread_create(&tid, NULL, ThreadPublic, NULL), 0); + EXPECT_EQ(pthread_detach(tid), 0); + EXPECT_EQ(pthread_join(tid, NULL), EINVAL); +} + +void *ThreadPthreadEqual(void *arg) +{ + pthread_t *tid = (pthread_t*)arg; + EXPECT_NE(pthread_equal(*tid, pthread_self()), 0); + Msleep(10); + return arg; +} + +/** + * @tc.number SUB_KERNEL_PTHREAD_EQUAL_0100 + * @tc.name Use pthread_equal checks process equality + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadBasicApiTestSuite, testPthreadEqual, Function | MediumTest | Level3) +{ + pthread_t tid; + ASSERT_EQ(pthread_create(&tid, NULL, ThreadPthreadEqual, (void*)&tid), 0); + EXPECT_EQ(pthread_equal(tid, pthread_self()), 0); + EXPECT_EQ(pthread_join(tid, NULL), 0); +} + +RUN_TEST_SUITE(PthreadBasicApiTestSuite); + diff --git a/testsuites/kernel_lite/process_posix/src/PthreadTest.c b/testsuites/kernel_lite/process_posix/src/PthreadTest.c new file mode 100755 index 0000000000000000000000000000000000000000..7acd4ec95c635b768ac419acb2d84ebb8e7d5dbd --- /dev/null +++ b/testsuites/kernel_lite/process_posix/src/PthreadTest.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "PthreadTest.h" +#include +#include +#include +#include "log.h" + +// public thread +void *ThreadPublic(void *arg) +{ + LOG("> This is ThreadPublic"); + Msleep(10); + return arg; +} diff --git a/testsuites/kernel_lite/process_posix/src/PthreadTest.h b/testsuites/kernel_lite/process_posix/src/PthreadTest.h new file mode 100755 index 0000000000000000000000000000000000000000..4722212494fcb0fc0d15be2ce7dded21a9041499 --- /dev/null +++ b/testsuites/kernel_lite/process_posix/src/PthreadTest.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KERNEL_LITE_PTHREAD_TEST_H +#define KERNEL_LITE_PTHREAD_TEST_H + +#define FIFO_PATH "/dev/xtsTestFifo" + +// Thread default value +#define DEF_PROCESS_DETACHSTATE PTHREAD_CREATE_JOINABLE +#define DEF_PROCESS_STACK_SIZE 131072 +#define DEF_PROCESS_GUARD_SIZE 8192 + +extern void *ThreadPublic(void *arg); + +#endif diff --git a/testsuites/kernel_lite/sched_posix/BUILD.gn b/testsuites/kernel_lite/sched_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..bf8f7d7f9464f93bc26b792cb4cce81da7f5ff7c --- /dev/null +++ b/testsuites/kernel_lite/sched_posix/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsSchedApiTest") { + suite_name = "acts" + sources = [ + "src/ProcessSchedApiTest.c", + "src/PthreadSchedApiTest.c", + ] + + include_dirs = [ + "//test/xts/tools/lite/hctest/include", + "//third_party/unity/src", + "src", + "//utils/native/lite/include", + "../utils", + ] + + cflags = [ "-Wno-error" ] +} diff --git a/testsuites/kernel_lite/sched_posix/Test.json b/testsuites/kernel_lite/sched_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..52391502131ea6e28cbd5cbb1fda0091c6d079c8 --- /dev/null +++ b/testsuites/kernel_lite/sched_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix sched api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsSchedApiTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/sched_posix/src/ProcessSchedApiTest.c b/testsuites/kernel_lite/sched_posix/src/ProcessSchedApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..20562f1de7beff8126429b835a5f7cb1718af056 --- /dev/null +++ b/testsuites/kernel_lite/sched_posix/src/ProcessSchedApiTest.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include "ohos_types.h" +#include "hctest.h" +#include "utils.h" +#include "KernelConstants.h" +#include "log.h" +#include + +LITE_TEST_SUIT(SCHED, ProcessSchedApi, ProcessSchedApiTestSuite); + +static BOOL ProcessSchedApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL ProcessSchedApiTestSuiteTearDown(void) +{ + LOG("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_GET_PRIORITY_MAX_0200 + * @tc.name sched_get_priority_max api error test with unsupport policy. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ProcessSchedApiTestSuite, testSchedGetPriorityMaxError0200, Function | MediumTest | Level3) +{ + // SCHED_RR is 2 + int invalidPolicy[] = {SCHED_FIFO, SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, SCHED_DEADLINE, SCHED_RESET_ON_FORK}; + int testLoop = sizeof(invalidPolicy)/sizeof(int); + for (int i = 0; i < testLoop; i++) { + errno = 0; + int prio = sched_get_priority_max(invalidPolicy[i]); + EXPECT_EQ(prio, -1); + EXPECT_EQ(errno, EINVAL); + } +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_GET_PRIORITY_MAX_0300 + * @tc.name sched_get_priority_max api error test with invalid policy. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ProcessSchedApiTestSuite, testSchedGetPriorityMaxError0300, Function | MediumTest | Level3) +{ + // SCHED_RR is 2 + int invalidPolicyVal; + int prio; + + invalidPolicyVal = -GetRandom(10000); + errno = 0; + prio = sched_get_priority_max(invalidPolicyVal); + EXPECT_EQ(prio, -1); + EXPECT_EQ(errno, EINVAL); + + invalidPolicyVal = GetRandom(10000) + SCHED_DEADLINE; + errno = 0; + prio = sched_get_priority_max(invalidPolicyVal); + EXPECT_EQ(prio, -1); + EXPECT_EQ(errno, EINVAL); +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_GET_PRIORITY_MIN_0200 + * @tc.name sched_get_priority_min api error test with unsupport policy. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ProcessSchedApiTestSuite, testSchedGetPriorityMinError0200, Function | MediumTest | Level3) +{ + // SCHED_RR is 2 + int invalidPolicy[] = {SCHED_FIFO, SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, SCHED_DEADLINE, SCHED_RESET_ON_FORK}; + int testLoop = sizeof(invalidPolicy)/sizeof(int); + for (int i = 0; i < testLoop; i++) { + errno = 0; + int prio = sched_get_priority_min(invalidPolicy[i]); + EXPECT_EQ(prio, -1); + EXPECT_EQ(errno, EINVAL); + } +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_GET_PRIORITY_MIN_0300 + * @tc.name sched_get_priority_min api error test with invalid policy. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(ProcessSchedApiTestSuite, testSchedGetPriorityMinError0300, Function | MediumTest | Level3) +{ + int invalidPolicyVal; + int prio; + invalidPolicyVal = -GetRandom(10000); + errno = 0; + prio = sched_get_priority_min(invalidPolicyVal); + EXPECT_EQ(prio, -1); + EXPECT_EQ(errno, EINVAL); + + invalidPolicyVal = GetRandom(10000) + SCHED_DEADLINE; + errno = 0; + prio = sched_get_priority_min(invalidPolicyVal); + EXPECT_EQ(prio, -1); + EXPECT_EQ(errno, EINVAL); +} + +RUN_TEST_SUITE(ProcessSchedApiTestSuite); diff --git a/testsuites/kernel_lite/sched_posix/src/PthreadSchedApiTest.c b/testsuites/kernel_lite/sched_posix/src/PthreadSchedApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..b3cd39788f031c0a182d18eb46488f020acbc0ad --- /dev/null +++ b/testsuites/kernel_lite/sched_posix/src/PthreadSchedApiTest.c @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include +#include +#include "ohos_types.h" +#include "hctest.h" +#include "utils.h" +#include "KernelConstants.h" +#include "log.h" + +#define GetParam() 30 // todo sched_priority + +LITE_TEST_SUIT(SCHED, PthreadSchedApi, PthreadSchedApiTestSuite); + +static BOOL PthreadSchedApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL PthreadSchedApiTestSuiteTearDown(void) +{ + LOG("+-------------------------------------------+\n"); + return TRUE; +} + +// global variables used to communicate between threads +static int g_policy = 0; +static int g_prioriy = 0; + +/** + * @tc.number SUB_KERNEL_SCHED_API_PATTR_INHERIT_0100 + * @tc.name test the default value of inheritsched. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadSchedApiTestSuite, testAttrGetInheritsched, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + ASSERT_EQ(pthread_attr_init(&attr), 0); + + int inheritsched = -1; + int rt = pthread_attr_getinheritsched(&attr, &inheritsched); + EXPECT_EQ(rt, 0); + EXPECT_EQ(inheritsched, PTHREAD_INHERIT_SCHED); +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_PATTR_INHERIT_0200 + * @tc.name test set and get inheritsched. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadSchedApiTestSuite, testAttrSetInheritsched, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + ASSERT_EQ(pthread_attr_init(&attr), 0); + + int rt = pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); + EXPECT_EQ(rt, 0); + int inheritsched = -1; + rt = pthread_attr_getinheritsched(&attr, &inheritsched); + EXPECT_EQ(rt, 0); + EXPECT_EQ(inheritsched, PTHREAD_INHERIT_SCHED); + + rt = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); + EXPECT_EQ(rt, 0); + inheritsched = -1; + rt = pthread_attr_getinheritsched(&attr, &inheritsched); + EXPECT_EQ(rt, 0); + EXPECT_EQ(inheritsched, PTHREAD_EXPLICIT_SCHED); +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_PATTR_INHERIT_0300 + * @tc.name pthread_attr_setinheritsched error test. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadSchedApiTestSuite, testAttrSetInheritschedError, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + ASSERT_EQ(pthread_attr_init(&attr), 0); + + int n = -GetRandom(100); + int rt = pthread_attr_setinheritsched(&attr, n); + EXPECT_EQ(rt, EINVAL); + n = 2 + GetRandom(100); + rt = pthread_attr_setinheritsched(&attr, n); + EXPECT_EQ(rt, EINVAL); +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_PATTR_SCHEDPARAM_0200 + * @tc.name test set and get sched param. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadSchedApiTestSuite, testAttrSetSchedParam, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + ASSERT_EQ(pthread_attr_init(&attr), 0); + + struct sched_param param = {0}; + int rt = pthread_attr_getschedparam(&attr, ¶m); + EXPECT_EQ(rt, 0); + + param.sched_priority = 22; + rt = pthread_attr_setschedparam(&attr, ¶m); + EXPECT_EQ(rt, 0); + + rt = pthread_attr_getschedparam(&attr, ¶m); + EXPECT_EQ(rt, 0); + EXPECT_EQ(param.sched_priority, 22); +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_PATTR_SCHEDPOLICY_0100 + * @tc.name test the default value of sched policy. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadSchedApiTestSuite, testAttrGetSchedPolicy, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + ASSERT_EQ(pthread_attr_init(&attr), 0); + + int policy = -1; + int rt = pthread_attr_getschedpolicy(&attr, &policy); + EXPECT_EQ(rt, 0); + EXPECT_EQ(policy, SCHED_RR); +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_PATTR_SCHEDPOLICY_0300 + * @tc.name pthread_attr_setschedpolicy error test. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadSchedApiTestSuite, testAttrSetSchedPolicyError, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + ASSERT_EQ(pthread_attr_init(&attr), 0); + int rt; + + // SCHED_FIFO is 1, and SCHED_RR is 2 + /*const int testLoop = 7;*/ + int invalidPolicy[7] = {SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, SCHED_DEADLINE, SCHED_RESET_ON_FORK}; + invalidPolicy[5] = -GetRandom(10000); + invalidPolicy[6] = GetRandom(10000) + 6; + for (int i = 0; i < 7; i++) { + rt = pthread_attr_setschedpolicy(&attr, invalidPolicy[i]); + EXPECT_EQ(rt, EINVAL); + } +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_PATTR_SCOPE_0100 + * @tc.name test the default value of sched scope. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadSchedApiTestSuite, testAttrGetScope, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + ASSERT_EQ(pthread_attr_init(&attr), 0); + + int scope = -1; + int rt = pthread_attr_getscope(&attr, &scope); + EXPECT_EQ(rt, 0); + EXPECT_EQ(scope, PTHREAD_SCOPE_SYSTEM); +} + +/** + * @tc.number SUB_KERNEL_SCHED_API_PATTR_SCOPE_0200 + * @tc.name test set and get scope. + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(PthreadSchedApiTestSuite, testAttrSetScope, Function | MediumTest | Level1) +{ + pthread_attr_t attr; + ASSERT_EQ(pthread_attr_init(&attr), 0); + + int rt = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); + EXPECT_EQ(rt, ENOTSUP); // liteos support PTHREAD_SCOPE_SYSTEM only + + rt = pthread_attr_setscope(&attr, -GetRandom(10000)); + EXPECT_EQ(rt, EINVAL); + + rt = pthread_attr_setscope(&attr, GetRandom(10000) + 2); + EXPECT_EQ(rt, EINVAL); + + int scope = -1; + rt = pthread_attr_getscope(&attr, &scope); + EXPECT_EQ(rt, 0); + EXPECT_EQ(scope, PTHREAD_SCOPE_SYSTEM); +} + +RUN_TEST_SUITE(PthreadSchedApiTestSuite); diff --git a/testsuites/kernel_lite/sys_posix/BUILD.gn b/testsuites/kernel_lite/sys_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..61446d44d5165b4ea9368c45443ede216b2a9c8f --- /dev/null +++ b/testsuites/kernel_lite/sys_posix/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsSysApiTest") { + suite_name = "acts" + sources = [ "src/SysApiTest.c" ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../utils/", + ] +} diff --git a/testsuites/kernel_lite/sys_posix/Test.json b/testsuites/kernel_lite/sys_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..607a2c0406d7f452e5c2e359b1a768aacd1b850f --- /dev/null +++ b/testsuites/kernel_lite/sys_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix sys api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsSysApiTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/sys_posix/src/SysApiTest.c b/testsuites/kernel_lite/sys_posix/src/SysApiTest.c new file mode 100755 index 0000000000000000000000000000000000000000..f439269e0ca40cfbc88e848242d611ebc2d61adf --- /dev/null +++ b/testsuites/kernel_lite/sys_posix/src/SysApiTest.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "log.h" +#include "utils.h" +#include "KernelConstants.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(SYSTEM, SysApiTest, SysApiTestSuite); + +static BOOL SysApiTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL SysApiTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** +* @tc.number SUB_KERNEL_SYS_STRERROR_0100 +* @tc.name test strerror +* @tc.desc [C- SOFTWARE -0200] +*/ +LITE_TEST_CASE(SysApiTestSuite, testStrerror, Function | MediumTest | Level1) +{ + for (int i = 0; i < 15; i++) { + LOG("%d : %s", i, strerror(i)); + } + EXPECT_STREQ("No error information", strerror(-1)); + EXPECT_STREQ("No error information", strerror(0)); + EXPECT_STREQ("No such file or directory", strerror(2)); + EXPECT_STREQ("No child process", strerror(10)); + EXPECT_STREQ("No error information", strerror(65536)); +} + +RUN_TEST_SUITE(SysApiTestSuite); diff --git a/testsuites/kernel_lite/time_posix/BUILD.gn b/testsuites/kernel_lite/time_posix/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d205da0708a97c2ae489858b29d9e19ad003cfee --- /dev/null +++ b/testsuites/kernel_lite/time_posix/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/lite/build/suite_lite.gni") + +hctest_suite("ActsTimeApiTest") { + suite_name = "acts" + sources = [ + "src/AlarmTest.c", + "src/ClockTimeTest.c", + "src/SleepTest.c", + "src/TimeUtilsTest.c", + ] + + include_dirs = [ + "//test/xts/tools/hctest/include", + "../util_posix/src", + "../utils/", + ] +} diff --git a/testsuites/kernel_lite/time_posix/Test.json b/testsuites/kernel_lite/time_posix/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..28956cb729a9101118c57d8884de0fb4d20d86d2 --- /dev/null +++ b/testsuites/kernel_lite/time_posix/Test.json @@ -0,0 +1,25 @@ +{ + "description": "Config for kernel_lite posix time api test cases", + "environment": [ + { + "type": "device", + "label": "ipcamera" + } + ], + "kits": [ + { + "type": "MountKit", + "server": "NfsServer", + "mount": [ + { + "source": "testcases/kernel", + "target": "/test_root/kernel" + } + ] + } + ], + "driver": { + "type": "CppTestLite", + "execute": "/test_root/kernel/ActsTimeApiTest.bin" + } +} \ No newline at end of file diff --git a/testsuites/kernel_lite/time_posix/src/AlarmTest.c b/testsuites/kernel_lite/time_posix/src/AlarmTest.c new file mode 100755 index 0000000000000000000000000000000000000000..02ae6866ade3bea99f238ea7fe6e867b9a612a75 --- /dev/null +++ b/testsuites/kernel_lite/time_posix/src/AlarmTest.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AlarmTest.h" + +#include +#include +#include +#include +#include +#include "log.h" +#include "utils.h" + +#define true 1 + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(TIME, TimeAlarmTest, TimeAlarmTestSuite); + +static BOOL TimeAlarmTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL TimeAlarmTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_TIME_API_TIMER_CREATE_0500 + * @tc.name timer_create function errno for EINVAL test + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(TimeAlarmTestSuite, testTimerCreateEINVAL, Function | MediumTest | Level4) +{ + timer_t tid = NULL; + clockid_t clockid = GetRandom(2048); + + EXPECT_EQ(timer_create(clockid, NULL, &tid), -1); + EXPECT_EQ(errno, EINVAL); +} + +RUN_TEST_SUITE(TimeAlarmTestSuite); diff --git a/testsuites/kernel_lite/time_posix/src/AlarmTest.h b/testsuites/kernel_lite/time_posix/src/AlarmTest.h new file mode 100755 index 0000000000000000000000000000000000000000..337a79e4e4eedc93a4e936281b358eb95f8258f4 --- /dev/null +++ b/testsuites/kernel_lite/time_posix/src/AlarmTest.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIME_ALARM_TEST +#define TIME_ALARM_TEST + +#include + +#define ACCURACY_ERROR 8 +#define MSLEEP_TIME 1200 + +#endif \ No newline at end of file diff --git a/testsuites/kernel_lite/time_posix/src/ClockID.h b/testsuites/kernel_lite/time_posix/src/ClockID.h new file mode 100755 index 0000000000000000000000000000000000000000..7b9c900006f543e3f54bdf90870a0242ed236589 --- /dev/null +++ b/testsuites/kernel_lite/time_posix/src/ClockID.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIMER_CLOCK_ID +#define TIMER_CLOCK_ID + +#include + +// defined in musl/include/time.h +static const char *ALL_CLOCKS_NAME[CLOCK_TAI + 1] = { + "CLOCK_REALTIME", + "CLOCK_MONOTONIC", + "CLOCK_PROCESS_CPUTIME_ID", + "CLOCK_THREAD_CPUTIME_ID", + "CLOCK_MONOTONIC_RAW", + "CLOCK_REALTIME_COARSE", + "CLOCK_MONOTONIC_COARSE", + "CLOCK_BOOTTIME", + "CLOCK_REALTIME_ALARM", + "CLOCK_BOOTTIME_ALARM", + "CLOCK_SGI_CYCLE", + "CLOCK_TAI", +}; + +#endif diff --git a/testsuites/kernel_lite/time_posix/src/ClockTimeTest.c b/testsuites/kernel_lite/time_posix/src/ClockTimeTest.c new file mode 100755 index 0000000000000000000000000000000000000000..db47c4e5c78d7340d5b187f7708d99abc3254e75 --- /dev/null +++ b/testsuites/kernel_lite/time_posix/src/ClockTimeTest.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include "log.h" +#include "utils.h" +#include "ClockID.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(TIME, TimeClockTimeTest, TimeClockTimeTestSuite); + +static BOOL TimeClockTimeTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL TimeClockTimeTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_TIME_API_CLOCK_GETTIME_0100 + * @tc.name test all supported clockid of clock_gettime + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(TimeClockTimeTestSuite, testClockGettimeAll, Function | MediumTest | Level1) +{ + clockid_t cid = CLOCK_REALTIME; + const char* cname = ALL_CLOCKS_NAME[cid]; + + struct timespec time1 = {0, 0}; + int rt = clock_gettime(cid, &time1); + if (rt == 0) { + LOG("clock_gettime(%s) : tv_sec=%ld, tv_nsec=%ld\n", cname, time1.tv_sec, time1.tv_nsec); + } else { + LOG("%s return error, rt=%d, errno=%d:%s\n", cname, rt, errno, strerror(errno)); + } + EXPECT_EQ(rt, 0); +} + +/** + * @tc.number SUB_KERNEL_TIME_API_CLOCK_SETTIME_0100 + * @tc.name test clock_settime basic + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(TimeClockTimeTestSuite, testClockSettime, Function | MediumTest | Level1) +{ + struct timespec time1 = {0, 0}; + int rt = clock_gettime(CLOCK_REALTIME, &time1); + ASSERT_EQ(rt, 0); + LOG("current time: sec=%llu, nsec=%ld", time1.tv_sec, time1.tv_nsec); + time_t sec = time1.tv_sec; + time1.tv_sec -= 1; + time1.tv_nsec = 1; + rt = clock_settime(CLOCK_REALTIME, &time1); + ASSERT_EQ(rt, 0); + sleep(1); + rt = clock_gettime(CLOCK_REALTIME, &time1); + ASSERT_EQ(rt, 0); + ASSERT_EQ(sec, time1.tv_sec); +} + +/** +* @tc.number SUB_KERNEL_TIME_API_GETTIMEOFDAY_0100 +* @tc.name test gettimeofday api +* @tc.desc [C- SOFTWARE -0200] +*/ +LITE_TEST_CASE(TimeClockTimeTestSuite, testGettimeofday, Function | MediumTest | Level1) { + int sleepSec = 1; + struct timeval tvalStart = {0}; + struct timeval tvalEnd = {0}; + struct timezone tzone; + + int ret1 = gettimeofday(&tvalStart, &tzone); + sleep(sleepSec); + int ret2 = gettimeofday(&tvalEnd, &tzone); + EXPECT_EQ(0, ret1); + EXPECT_EQ(0, ret2); + EXPECT_TRUE((tvalEnd.tv_sec - tvalStart.tv_sec) >= sleepSec); + EXPECT_TRUE((tvalEnd.tv_sec - tvalStart.tv_sec) < sleepSec+1); +} + +/** +* @tc.number SUB_KERNEL_TIME_API_SETTIMEOFDAY_0100 +* @tc.name test settimeofday api +* @tc.desc [C- SOFTWARE -0200] +*/ +LITE_TEST_CASE(TimeClockTimeTestSuite, testSettimeofday, Function | MediumTest | Level1) { + int setSec = 100; + int sleepSec = 2; + struct timeval tvalStart = {0}; + struct timeval tvalEnd = {0}; + struct timeval set = {.tv_sec = setSec, .tv_usec = 0}; + + int ret1 = settimeofday(&set, NULL); + int ret2 = gettimeofday(&tvalStart, NULL); + sleep(sleepSec); + int ret3 = gettimeofday(&tvalEnd, NULL); + EXPECT_EQ(0, ret1); + EXPECT_EQ(0, ret2); + EXPECT_EQ(0, ret3); + EXPECT_EQ(setSec, tvalStart.tv_sec); + EXPECT_TRUE((tvalEnd.tv_sec - tvalStart.tv_sec) >= sleepSec); + EXPECT_TRUE((tvalEnd.tv_sec - tvalStart.tv_sec) < sleepSec+1); +} + +RUN_TEST_SUITE(TimeClockTimeTestSuite); diff --git a/testsuites/kernel_lite/time_posix/src/SleepTest.c b/testsuites/kernel_lite/time_posix/src/SleepTest.c new file mode 100755 index 0000000000000000000000000000000000000000..a8f12fb2d350ba2346e09c1e851e45a7e01b76c1 --- /dev/null +++ b/testsuites/kernel_lite/time_posix/src/SleepTest.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "log.h" +#include "utils.h" +#include "ClockID.h" + +#include "ohos_types.h" +#include "hctest.h" + +LITE_TEST_SUIT(TIME, TimeSleepTest, TimeSleepTestSuite); + +static BOOL TimeSleepTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL TimeSleepTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} + +/** + * @tc.number SUB_KERNEL_TIME_API_CLOCK_NANOSLEEP_0200 + * @tc.name clock_nanosleep fail test - non-support clock_id + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(TimeSleepTestSuite, testClockNanosleepInvalidID, Reliability | SmallTest | Level2) +{ + clockid_t cid = 1; + const char* cname = ALL_CLOCKS_NAME[cid]; + printf("test %s", cname); + struct timespec req = {0, 100}; + struct timespec rem = {0}; + int rt = clock_nanosleep(cid, 0, &req, &rem); + if (cid == CLOCK_SGI_CYCLE) { + ASSERT_EQ(rt, EINVAL); + } +} + +/** + * @tc.number SUB_KERNEL_TIME_API_CLOCK_NANOSLEEP_0300 + * @tc.name clock_nanosleep fail test - invalid parameter + * @tc.desc [C- SOFTWARE -0200] + */ +LITE_TEST_CASE(TimeSleepTestSuite, testClockNanosleepInvalidPara, Reliability | SmallTest | Level2) +{ + struct timespec req = {0, 100}; + struct timespec rem = {0}; + int rt; + + // invlid clock_id + int id = GetRandom(1000) + 12; + LOG("check invlid clockid: %d...", id); + rt = clock_nanosleep(id, 0, &req, &rem); + EXPECT_EQ(rt, EINVAL); + + id = -GetRandom(1000) - 12; + LOG("check invlid clockid: %d...", id); + rt = clock_nanosleep(id, 0, &req, &rem); + EXPECT_EQ(rt, EINVAL); + + // invlid flag + int flag = TIMER_ABSTIME; + LOG("check invlid flag: %d...", flag); + rt = clock_nanosleep(CLOCK_REALTIME, flag, &req, &rem); + EXPECT_EQ(rt, ENOTSUP); + flag = GetRandom(100) + 1; + LOG("check invlid flag: %d...", flag); + rt = clock_nanosleep(CLOCK_REALTIME, flag, &req, &rem); + EXPECT_EQ(rt, EINVAL); + flag = -GetRandom(100) - 1; + LOG("check invlid flag: %d...", flag); + rt = clock_nanosleep(CLOCK_REALTIME, flag, &req, &rem); + EXPECT_EQ(rt, EINVAL); + + // invlid timespec + req.tv_sec = -1; + req.tv_nsec = 1; + LOG("check invlid timespec: tv_sec=-1 ..."); + rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); + EXPECT_EQ(errno, EINVAL); + req.tv_sec = 1; + req.tv_nsec = -1; + LOG("\ncheck invlid timespec: tv_nsec=-1 ..."); + rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); + EXPECT_EQ(errno, EINVAL); + req.tv_sec = 1; + req.tv_nsec = 1000 * 1000 * 1000 + 1; + LOG("check invlid timespec: tv_nsec overflow ..."); + rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); + EXPECT_EQ(errno, EINVAL); + + // invlid remain + // para not used, so not tested. +} + +RUN_TEST_SUITE(TimeSleepTestSuite); diff --git a/testsuites/kernel_lite/time_posix/src/TimeUtilsTest.c b/testsuites/kernel_lite/time_posix/src/TimeUtilsTest.c new file mode 100755 index 0000000000000000000000000000000000000000..7369987387e40e4b4c41c5073b408ddebf2d355b --- /dev/null +++ b/testsuites/kernel_lite/time_posix/src/TimeUtilsTest.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include +#include "log.h" + +#include "utils.h" + +#include "ohos_types.h" +#include "hctest.h" + +time_t g_time = 18880; +size_t g_zero = 0; + +LITE_TEST_SUIT(TIME, TimeUtilsTest, TimeUtilsTestSuite); + +static BOOL TimeUtilsTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL TimeUtilsTestSuiteTearDown(void) +{ + printf("+-------------------------------------------+\n"); + return TRUE; +} +#define SECS_PER_MIN 60 +#define INIT_TM(tmSt, year, mon, day, hour, min, sec, wday) \ + do { \ + (tmSt).tm_sec = (sec); \ + (tmSt).tm_min = (min); \ + (tmSt).tm_hour = (hour); \ + (tmSt).tm_mday = (day); \ + (tmSt).tm_mon = (mon); \ + (tmSt).tm_year = (year) - 1900; \ + (tmSt).tm_wday = wday; \ + (tmSt).__tm_gmtoff = 0; \ + (tmSt).__tm_zone = ""; \ + } while (0) +/** +* @tc.number SUB_KERNEL_TIME_API_MKTIME_0100 +* @tc.name test mktime api +* @tc.desc [C- SOFTWARE -0200] +*/ +LITE_TEST_CASE(TimeUtilsTestSuite, testMktime, Function | MediumTest | Level2) +{ + struct tm *localTime; + struct tm timeptr = {0}; + struct timeval tv; + struct timezone tz; + + int ret = gettimeofday(&tv, &tz); + EXPECT_EQ(0, ret); + long sysTimezone = (long)(-tz.tz_minuteswest) * SECS_PER_MIN; + LOG("\n system timezone = %ld\n", sysTimezone); + INIT_TM(timeptr, 2000, 6, 9, 10, 10, 0, 7); + time_t timeRet = mktime(&timeptr); + EXPECT_EQ(sysTimezone, timeptr.__tm_gmtoff); + EXPECT_EQ(963137400 - timeptr.__tm_gmtoff, timeRet); + localTime = localtime(&g_time); + ASSERT_NE(NULL, localTime); + time_t timep = mktime(localTime); + EXPECT_EQ(timep, 18880); +} + +RUN_TEST_SUITE(TimeUtilsTestSuite); diff --git a/testsuites/kernel_lite/utils/BUILD.gn b/testsuites/kernel_lite/utils/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..ff2dcbde7673f7155869b437a52f284487969b7f --- /dev/null +++ b/testsuites/kernel_lite/utils/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2020-2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +static_library("libutils") { + sources = [ "utils.c" ] + include_dirs = [ "//test/xts/tools/hctest/include" ] +} + +static_library("libfs") { + sources = [ "libfs.c" ] +} + +static_library("libmt_utils") { + sources = [ "mt_utils.c" ] +} diff --git a/testsuites/kernel_lite/utils/KernelConstants.h b/testsuites/kernel_lite/utils/KernelConstants.h new file mode 100755 index 0000000000000000000000000000000000000000..491892b567fa3570ca86e69c960af19b033d6759 --- /dev/null +++ b/testsuites/kernel_lite/utils/KernelConstants.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KERNEL_CONSTANTS_H +#define KERNEL_CONSTANTS_H + +#include +#include "los_config.h" + +/** + * ================ DAC and Caps ================ + */ +#define SHELL_UID 2 +#define SHELL_GID 2 + + +/** + * ================ Process Manager ================ + */ +#define MAX_PROCESS_GROUPS 255 // max number of groups a process can have +#define MAX_PROCESS_NUMBER 63 // max allowd process [0,63] +#define MAX_TASK_NUMBER 128 // max allowd task(process+thread) + +#define INIT_PROCESS_ID 1 // pid of init +#define KERNEL_PROCESS_ID 2 // pid of KProcess + +#define HIGHEST_USER_PROCESS_PRIORITY 10 +#define LOWEST_USER_PROCESS_PRIORITY 31 +#define HIGHEST_USER_THREAD_PRIORITY 0 +#define LOWEST_USER_THREAD_PRIORITY 31 + +#define DEFAULT_SHELL_PROCESS_PRIORITY 15 +#define DEFAULT_INIT_PROCESS_PRIORITY 28 +#define DEFAULT_KERNEL_PROCESS_PRIORITY 0 +#define DEFAULT_THREAD_PRIORITY 25 +#define DEFAULT_RR_SCHED_INTERVAL 5000000 // defalult sched interval of RR, in ms + +/** + * ================ Memory Manager ================ + */ +typedef unsigned long addr_t; + +#define USER_ASPACE_BASE ((addr_t)0x01000000UL) +#define USER_ASPACE_TOP_MAX ((addr_t)0x3FFFFFFFUL) +#define USER_ASPACE_SIZE ((addr_t)(USER_ASPACE_TOP_MAX - USER_ASPACE_BASE)) +#define USER_HEAP_BASE ((addr_t)(USER_ASPACE_TOP_MAX >> 2)) +#define USER_MAP_BASE ((addr_t)(USER_ASPACE_TOP_MAX >> 1)) +#define USER_MAP_SIZE ((addr_t)(USER_ASPACE_SIZE >> 3)) + +#ifndef PAGE_SIZE +#define PAGE_SIZE 0x1000U +#endif +#define PAGE_MASK (~(PAGE_SIZE - 1)) +#define PAGE_SHIFT 12 + +#define MEM_PAGESTART(addr) ((addr) & ~(PAGE_SIZE - 1)) +#define MEM_PAGEOFFSET(addr) ((addr) & (PAGE_SIZE - 1)) +#define MEM_PAGEALIGN(addr) (((addr) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) + + +/** + * ================ IPC ================ + */ +#define MAX_SIGNAL_NUMBER 64 // max number of allowed signal, [1,64] +#define MAX_PIPE_BUFFER 1023 // max size of a pipe buffer +#define MAX_PIPE_NUMBER 32 // max pipe number + +#define MAX_MQ_NUMBER LOSCFG_BASE_IPC_QUEUE_LIMIT // max mqueue number +#define MAX_MQ_NAME_LEN 2560 // max mqueue name length +#define MAX_MQ_MSG_SIZE 65530 // max mqueue message size + + +/** + * ================ FS ================ + */ +#define MAX_PATH_SIZE 256 // max size of path string + +/** + * ================ SYSTEM ================ + */ +#define SYSINFO_SYSNAME "Huawei LiteOS" // sys name from 'uname' + +/** + * ================ XTS ================ + */ +#define RES_DIR_KERNEL "/test_root/kernel/" // top dir of test resource of kernel +#define WRITABLE_TEST_DIR "/storage/" // writable dir for test file + +#endif diff --git a/testsuites/kernel_lite/utils/libfs.c b/testsuites/kernel_lite/utils/libfs.c new file mode 100755 index 0000000000000000000000000000000000000000..94d216f43979512812a2c876b51086d86fb0c6da --- /dev/null +++ b/testsuites/kernel_lite/utils/libfs.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "log.h" +#include "libfs.h" +#include "KernelConstants.h" + + +int MakeDir(const char *dirname) +{ + if (access(dirname, F_OK) == 0) { + LOG("dir:%s exists", dirname); + return 1; + } else { + int rt = mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR | S_IRWXG | S_IXOTH); + if (rt) { + LOG("create dir failed! path=%s, errno=%d:%s", dirname, errno, strerror(errno)); + return -1; + } + } + return 0; +} + +int RemoveDir(const char *dirname) +{ + char subDir[MAX_PATH_SIZE]; + struct stat dirStat = {0}; + + if (stat(dirname, &dirStat) < 0) { + LOG("get directory stat error, errno=%d:%s", errno, strerror(errno)); + return -1; + } + + if (S_ISDIR(dirStat.st_mode)) { + DIR *pDir = opendir(dirname); + struct dirent *entry; + while ((entry = readdir(pDir))) { + char *fname = entry->d_name; + if (!strcmp(fname, ".") || !strcmp(fname, "..")) { + continue; // skip . and .. + } + // MAX_PATH_SIZE is the max length of allowed path string, so it safe to use sprintf here. + sprintf(subDir, "%s/%s", dirname, fname); + RemoveDir(subDir); // remove sub dir or file + } + closedir(pDir); + if (rmdir(dirname) == -1) { // delete empty dir + LOG("delete empty directory failed, path=%s, errno=%d:%s", dirname, errno, strerror(errno)); + return -1; + } + } else { + if (remove(dirname) == -1) { + LOG("remove regular file failed, path=%s, errno=%d:%s", dirname, errno, strerror(errno)); + return -1; + } + } + + return 0; +} + +int RemoveFile(const char *fpath) +{ + if (!remove(fpath)) { + LOG("remove file success"); + } else { + LOG("remove file failed! path=%s: errno=%d:%s", fpath, errno, strerror(errno)); + return -1; + } + return 0; +} + +int CopyFile(const char *srcFile, const char *dstFile) +{ + int rt = 0; + FILE *srcFp = fopen(srcFile, "rb"); + if (srcFp == NULL) { + LOG("Cannot open source file %s: errno=%d,%s \n", srcFile, errno, strerror(errno)); + return -1; + } + FILE *dstFp = fopen(dstFile, "wb"); + if (dstFp == NULL) { + LOG("Cannot create dest file %s: errno=%d,%s \n", dstFile, errno, strerror(errno)); + fclose(srcFp); + return -1; + } + + const int BUF_SIZE = 100 * 1024; + char buffer[BUF_SIZE]; + size_t bytes; + while ((bytes = fread(buffer, 1, sizeof(buffer), srcFp)) > 0) { + if (fwrite(buffer, 1, bytes, dstFp) != bytes) { + LOG("write to dest file failed: errno=%d,%s \n", errno, strerror(errno)); + rt = -1; + break; + } + } + fclose(srcFp); + fclose(dstFp); + return rt; +} + +char* GetCurrentPath() +{ + static char path1[MAX_PATH_SIZE]; + char *path = getcwd(path1, MAX_PATH_SIZE); + LOG("current Path = %s,path1=%s", path, path1); + return path1; +} diff --git a/testsuites/kernel_lite/utils/libfs.h b/testsuites/kernel_lite/utils/libfs.h new file mode 100755 index 0000000000000000000000000000000000000000..2d5bfde649fcd55d343bb25139a7a464a8626c0d --- /dev/null +++ b/testsuites/kernel_lite/utils/libfs.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KERNEL_LIBFS_H +#define KERNEL_LIBFS_H + +/** + * desc: make a new directory + * input: dirname + * output: -1 -- mkdir failed, detail info printed + * 0 -- mkdir ok, or dirname already exists + * 1 -- dirname already exists + */ +int MakeDir(const char *dirname); + +/** + * desc: remove a dir, even it's not empty + * input: dirname + * output: -1 -- rmdir failed, detail info printed + * 0 -- remove ok + */ +int RemoveDir(const char *dirname); + +/** + * desc: remove a file + * input: dirname + * output: -1 -- rmdir failed, detail info printed + * 0 -- remove ok + */ +int RemoveFile(const char *fpath); + +/** + * desc: copy srcFile to dstFile. if dstFile exist, it will be reflashed + * output: -1 -- copy failed, detail info printed + * 0 -- copy ok + */ +int CopyFile(const char *srcFile, const char *dstFile); + +/** + * desc: get current working directory + * output: NULL -- getcwd failed, detail info printed + * string -- the current working directory + */ +char* GetCurrentPath(); + +#endif // header diff --git a/testsuites/kernel_lite/utils/log.h b/testsuites/kernel_lite/utils/log.h new file mode 100755 index 0000000000000000000000000000000000000000..b16b137cb613c66c4eb586b88cf412b30979de2b --- /dev/null +++ b/testsuites/kernel_lite/utils/log.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KERNEL_LITE_LOG +#define KERNEL_LITE_LOG + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef DEBUG + const static float SYS_NS_PER_S = 1000 * 1000 * 1000; + // get current time, for logging only + static float GetCurTime(void) + { + struct timespec time1 = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &time1); + return time1.tv_sec + ((float)time1.tv_nsec) / SYS_NS_PER_S; + } + #define LOGD(format, ...) printf(stdout, "[%.06f] " format "\n", GetCurTime(), ##__VA_ARGS__) + #define LOG(format, ...) printf(stdout, "[%.06f] " format "\n", GetCurTime(), ##__VA_ARGS__) +#else + #define LOGD(...) + #define LOG(format, ...) printf(format "\n", ##__VA_ARGS__) +#endif + +#define LOGE(format, ...) printf(stdout, "\n%s:%d: " format "\n", __FILE__, __LINE__, ##__VA_ARGS__) + +#define PANIC(format, ...) do { \ + LOGE(format, ##__VA_ARGS__); \ + exit(1); \ + } while (0) + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/testsuites/kernel_lite/utils/mt_utils.c b/testsuites/kernel_lite/utils/mt_utils.c new file mode 100755 index 0000000000000000000000000000000000000000..1e297bfba017320e7a641b1562113584119738b3 --- /dev/null +++ b/testsuites/kernel_lite/utils/mt_utils.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// utils for multi-thread and multi-process test + +#include "mt_utils.h" +#include +#include +#include +#include +#include +#include +#include "log.h" + +#define MAX_INDEX 12 +const uint32_t MSECOND_INDEX[MAX_INDEX] = {10, 20, 30, 60, 100, 150, 200, 300, 400, 600, 1000, 2000}; +const uint32_t NUMBER_INDEX[MAX_INDEX] = {2500, 3600, 4500, 6600, 8800, 1000, 12000, 15000, 18000, 2000, 3000, 42000 }; + +int CountPrimes(uint32_t maxNumber) +{ + uint32_t primesCount = 0; + uint32_t i, num; + for (num = 2; num <= maxNumber; ++num) { + for (i = 2; i <= num; i++) { + if (num % i == 0) { + break; + } + } + if (i == num) { + primesCount++; + } + } + return primesCount; +} + +static uint32_t GetNumberFromMS(uint32_t ms) +{ + for (uint32_t i = 0; i < MAX_INDEX; i++) { + if (MSECOND_INDEX[i] == ms) { + return NUMBER_INDEX[i]; + } + } + return 0; +} + +int BusyRun(uint32_t ms) +{ + uint32_t n = GetNumberFromMS(ms); + if (n == 0) { + LOG("BusyRun Error: %d ms not support", n); + _exit(1); + } + return CountPrimes(n); +} diff --git a/testsuites/kernel_lite/utils/mt_utils.h b/testsuites/kernel_lite/utils/mt_utils.h new file mode 100755 index 0000000000000000000000000000000000000000..8271a0d9a090ca7aec05bdc549029369a1abd18b --- /dev/null +++ b/testsuites/kernel_lite/utils/mt_utils.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// utils for multi-thread and multi-process test + +#ifndef KERNEL_LITE_MT_UTILS +#define KERNEL_LITE_MT_UTILS + +#include + +// count all primes numbers below 'maxNumber', used for keep cpu busy +int CountPrimes(uint32_t maxNumber); + +/** + * desc: keep cpu run for 'ms' miliseconds, without any syscall or pend operation + * input: miliseconds value, only some specific value is supported, as below: + * -- 10, 20, 30, 60, 100, 150, 200, 300, 400, 600, 1000, 2000 + * output: useless, only used for avoid the whole function is optimized by gcc + * note: the actual elasped time is not so accurate + */ +int BusyRun(uint32_t ms); + +/** + * desc: used for check if the code is runned as expected, in multi-thread or multi-process scenario + * input: step -- from 1 to 15(0xf). + * output: the actual steps the this function is called. + Example: + LOG("step=%lx", CheckStep(1)); // may called in thread 1 + LOG("step=%lx", CheckStep(2)); // may called in thread 2 + LOG("step=%lx", CheckStep(3)); // may called in thread 3 + LOG("step=%lx", CheckStep(4)); // may called in thread 2 + uint64_t step = CheckStep(5); // may called in thread 1 + if (step == 0x12345) { + LOG("everything is ok"); + } else { + LOG("code not run as expected!"); + } + Output: + step=1 + step=12 + step=123 + step=1234 + everything is ok + */ +uint64_t CheckStep(int step); + + +/** + * desc: used for synchronize in multi-process scenario, not suitable for multi-thread. + * usage: + InitPipe(); + fork(); + if parent: + ... + BlockOnPipe(); // will block until UnBlockPipe is called in another process. + ... + if child: + ... + UnBlockPipe(); + ... + */ +// return -1 if pipe-init failed, user should check return code +int InitPipe(); +void BlockOnPipe(); +void UnBlockPipe(); + +/** + * desc: get and set a global variable, can be used in multi-process scenario + * usage: + * InitGlobalVariable(); + * fork(); + * if child: + * ... + * SetGlobalVariable(x); + * ... + * if parent: + * ... + * SetGlobalVariable(y); + * ... + * int i = GetGlobalVariable(); + * // check if i is ok + * ... + * DeleteGlobalVariable(); // Call before exit + * exit... + */ +// output: return -1 if the operation fails, user should check return code +int InitGlobalVariable(); +// return -1 if the operation fails +int SetGlobalVariable(int value); +// return -1 if the operation fails. +int GetGlobalVariable(); +// return -1 if the operation fails +int DeleteGlobalVariable(); + +#endif diff --git a/testsuites/kernel_lite/utils/utils.c b/testsuites/kernel_lite/utils/utils.c new file mode 100755 index 0000000000000000000000000000000000000000..5a6b28a74f9f9388f508fd0fdcdbdc721c2124ef --- /dev/null +++ b/testsuites/kernel_lite/utils/utils.c @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "utils.h" +#include "log.h" + +// init rand seed at startup +__attribute__((constructor)) static void Initialize(void) +{ + LOGD("srand(time(0)) is called."); + srand(time(nullptr)); +} + +int CheckValueClose(double target, double actual, double accuracy) +{ + double diff = actual - target; + double pct; + if (diff < 0) { + diff = -diff; + } + if(actual == 0) { + return 0; + }else { + pct = diff / actual; + } + LOGD("diff=%f, pct=%f\n", diff, pct); + return (pct <= accuracy); +} + +const int SYS_US_PER_MS = 1000; +void Msleep(int msec) +{ + usleep(msec * SYS_US_PER_MS); +} + +int KeepRun(int msec) +{ + struct timespec time1 = { 0, 0 }; + struct timespec time2 = { 0, 0 }; + clock_gettime(CLOCK_MONOTONIC, &time1); + LOGD("KeepRun start : tv_sec=%ld, tv_nsec=%ld\n", time1.tv_sec, time1.tv_nsec); + int loop = 0; + int runned = 0; + while (runned < msec) { + ++loop; + clock_gettime(CLOCK_MONOTONIC, &time2); + runned = (time2.tv_sec - time1.tv_sec) * 1000 + (time2.tv_nsec - time1.tv_nsec) / 1000000; + } + LOGD("KeepRun end : tv_sec=%ld, tv_nsec=%ld\n", time2.tv_sec, time2.tv_nsec); + return loop; +} + +// start a elf, only check if execve success or not +static int StartElf(const char *fname, char * const argv[], char * const envp[]) +{ + int pid = fork(); + if (pid == -1) { + LOGE("ERROR: Fork Error, errno=%d, err=%s\n", errno, strerror(errno)); + return -1; + } else if (pid == 0) { // child + errno = 0; + int rt = execve(fname, argv, envp); + if (rt == -1) { + LOGE("ERROR: execve return -1, errno=%d, err=%s\n", errno, strerror(errno)); + exit(EXECVE_RETURN_ERROR); + } + LOGE("ERROR: execve should never return on success. rt=%d, errno=%d, err=%s\n", rt, errno, strerror(errno)); + exit(EXECVE_RETURN_OK); + } + return pid; +} + +int RunElf(const char *fname, char * const argv[], char * const envp[], int timeoutSec) +{ + int isTimeout = 0; + int exitCode; + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGCHLD); + + int pid = StartElf(fname, argv, envp); + if (pid == -1) { // fork error + return -1; + } + + if (timeoutSec > 0) { + struct timespec time1 = { timeoutSec, 0 }; + if (sigtimedwait(&set, nullptr, &time1) == -1) { + if (errno == EAGAIN) { + isTimeout = 1; + } else { + LOGE("ERROR: sigtimedwait FAIL: %s\n", strerror(errno)); + return -1; + } + if (kill(pid, SIGKILL) == -1) { + LOGE("ERROR: kill child FAIL: %s\n", strerror(errno)); + return -1; + } + } + // else: sigtimedwait return ok, child has exited already, nothing else to do + } + int rt = CheckProcStatus(pid, &exitCode, 0); + if ((rt <= 0) || (exitCode == EXECVE_RETURN_OK) || (exitCode == EXECVE_RETURN_ERROR)) { + return -1; + } + if (isTimeout) { + LOGE("ERROR: child execute timed out!\n"); + return -2; + } + return exitCode; +} + +int StartExecveError(const char *fname, char * const argv[], char * const envp[]) +{ + pid_t pid = fork(); + if (pid == -1) { + LOGE("ERROR: Fork Error, errno=%d, err=%s\n", errno, strerror(errno)); + return -1; + } else if (pid == 0) { // child + int rt = execve(fname, argv, envp); + if (rt == -1) { + LOG("ERROR: execve return -1, errno=%d, err=%s\n", errno, strerror(errno)); + exit(errno); + } + LOGE("ERROR: execve should never return on success. rt=%d, errno=%d, err=%s\n", rt, errno, strerror(errno)); + exit(EXECVE_RETURN_OK); + } + // parent + Msleep(30); + int exitCode; + int procStat = CheckProcStatus(pid, &exitCode, WNOHANG); + LOG("procStat=%d, exitCode=%d\n", procStat, exitCode); + if (procStat != 1) { + return -3; + } else if (exitCode == EXECVE_RETURN_OK) { + return -2; + } else { + return exitCode; + } +} + +// return n: 0 < n <= max +uint32_t GetRandom(uint32_t max) +{ + if (max == 0 || max == 1) { + return 1; + } + return (rand() % max) + 1; +} + +// get cur-time plus ms +void GetDelayedTime(struct timespec *ts, unsigned int ms) +{ + const unsigned int nsecPerSec = 1000000000; + unsigned int setTimeNs = ms * 1000000; + struct timespec tsNow = { 0 }; + clock_gettime(CLOCK_REALTIME, &tsNow); + ts->tv_sec = tsNow.tv_sec + (tsNow.tv_nsec + setTimeNs) / nsecPerSec; + ts->tv_nsec = (tsNow.tv_nsec + setTimeNs) % nsecPerSec; +} + +// calculate time difference, in ms +int GetTimeDiff(struct timespec ts1, struct timespec ts2) +{ + const unsigned int nsecPerSec = 1000000000; + int ms = (ts1.tv_sec - ts2.tv_sec) * nsecPerSec + (ts1.tv_nsec - ts2.tv_nsec); + ms = ms / 1000000; + return ms; +} + +int FixCurProcessToOneCpu(int cpuIndex, cpu_set_t *pOldMask) +{ + int ret; + cpu_set_t setMask; + CPU_ZERO(pOldMask); + ret = sched_getaffinity(0, sizeof(cpu_set_t), pOldMask); + if (ret != 0) { + LOG("sched_getaffinity failed, ret = %d", ret); + return -1; + } + if (CPU_ISSET(0, pOldMask)) { + LOG("before affinity cpu is 0"); + } + if (CPU_ISSET(1, pOldMask)) { + LOG("before affinity cpu is 1"); + } + CPU_ZERO(&setMask); + CPU_SET(cpuIndex, &setMask); + LOG("fix cpu to %d", cpuIndex); + ret = sched_setaffinity(0, sizeof(setMask), &setMask); + if (ret != 0) { + LOG("sched_setaffinity failed, ret = %d", ret); + return -1; + } + return 0; +} \ No newline at end of file diff --git a/testsuites/kernel_lite/utils/utils.h b/testsuites/kernel_lite/utils/utils.h new file mode 100755 index 0000000000000000000000000000000000000000..5b445a79bf8cd1097a5c09e6aaf3fc526012c0bc --- /dev/null +++ b/testsuites/kernel_lite/utils/utils.h @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef KERNEL_LITE_UTILS +#define KERNEL_LITE_UTILS + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RUN_ONE_TESTCASE(caseName) UnityDefaultTestRun(caseName##_runTest, __FILE__, __LINE__) + +#define LogPrint(...) LOG(__VA_ARGS__) + +#define EXPECT_EQ(retCode, value) TEST_ASSERT_EQUAL_INT(value, retCode) // retCode = value +#define EXPECT_NE(retCode, value) TEST_ASSERT_NOT_EQUAL(value, retCode) // retCode != value +#define EXPECT_GT(retCode, value) TEST_ASSERT_GREATER_THAN_INT(value, retCode) // retCode > value +#define EXPECT_LT(retCode, value) TEST_ASSERT_LESS_THAN_INT(value, retCode) // retCode < value +#define EXPECT_GE(retCode, value) TEST_ASSERT_GREATER_OR_EQUAL_INT(value, retCode) // retCode >= value +#define EXPECT_LE(retCode, value) TEST_ASSERT_LESS_THAN_INT(value, retCode) // retCode <= value + +#define ASSERT_FALSE(retCode) TEST_ASSERT_FALSE(retCode) // retCode = flash +#define ASSERT_TRUE(retCode) TEST_ASSERT_TRUE(retCode) // retCode = true, 致命的失败 +#define EXPECT_FALSE(retCode) TEST_ASSERT_FALSE(retCode) +#define EXPECT_TRUE(retCode) TEST_ASSERT_TRUE(retCode) // retCode = true, 非致命的失败 +#define EXPECT_STREQ(retCode, value) TEST_ASSERT_EQUAL_STRING(value, retCode) + +#define ASSERT_EQ(retCode, value) TEST_ASSERT_EQUAL_INT(value, retCode) +#define EXPECT_STRNE(a, b) // not equal +#define ASSERT_NE(retCode, value) TEST_ASSERT_NOT_EQUAL(value, retCode) +#define FAIL(message) printf("%s:%s:\n"message,__func__,__LINE__) // TEST_FAIL_MESSAGE(message) +#define nullptr NULL +#define PAGE_SIZE (0x1000) + +#define EXPECT_FLOAT_EQ(retCode, value) TEST_ASSERT_EQUAL_FLOAT(value, retCode); +#define EXPECT_DOUBLE_EQ(retCode, value) TEST_ASSERT_EQUAL_DOUBLE(value, retCode); + +#define ADD_FAILURE() printf("%s:%s:ADD_FAILURE Execution failed!\n",__func__,__LINE__); // GTEST_NONFATAL_FAILURE_("Failed") +#define assert printf("enter assert\n");while(1); + +// get thread id +#define gettid() ((pid_t)syscall(SYS_gettid)) + +// check if 'actual' is close to 'target', within 5% in default +int CheckValueClose(double target, double actual, double accuracy); + +// sleep n millisecond(1/1000 sec) +void Msleep(int n); + +/** + * desc: check process state use 'waitpid' + * input: pid -- target pid + * code -- store exit code or signal number + * flag -- flag for waitpid, default to WNOHANG + * output: -1 -- waitpid return -1 + * -2 -- waitpid return value error(not -1 and not pid) + * 0 -- target process still alive + * 1 -- target process existd, exist code is set in 'code' + * 2 -- target process killed by a signal, signal number is set in 'code' + * 3 -- target process is stopped, signal number is set in 'code' + * 4 -- get target process state error, due to waitpid error + */ +int CheckProcStatus(pid_t pid, int* code, int flag); + +// make sure process is still alive +#define AssertProcAlive(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode, WNOHANG); \ + TEST_ASSERT_EQUAL_INT(procStat, 0); \ + } while (0) +#define ExpectProcAlive(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode, WNOHANG); \ + TEST_ASSERT_EQUAL_INT(procStat, 0); \ + } while (0) + +// make sure process exited with exitCode 0 +#define AssertProcExitedOK(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode, WNOHANG); \ + TEST_ASSERT_EQUAL_INT(procStat, 1); \ + TEST_ASSERT_EQUAL_INT(exitCode, 0); \ + } while (0) +#define ExpectProcExitedOK(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode, WNOHANG); \ + TEST_ASSERT_EQUAL_INT(procStat, 1); \ + TEST_ASSERT_EQUAL_INT(exitCode, 0); \ + } while (0) +// wait until child statu changed +#define WaitProcExitedOK(pid) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode, 0); \ + TEST_ASSERT_EQUAL_INT(procStat, 1); \ + TEST_ASSERT_EQUAL_INT(exitCode, 0); \ + } while (0) + +// make sure process killed by signal signum +#define AssertProcKilled(pid, signum) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode, WNOHANG); \ + TEST_ASSERT_EQUAL_INT(procStat, 2); \ + TEST_ASSERT_EQUAL_INT(exitCode, signum); \ + } while (0) +#define ExpectProcKilled(pid, signum) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode, WNOHANG); \ + TEST_ASSERT_EQUAL_INT(procStat, 2); \ + TEST_ASSERT_EQUAL_INT(exitCode, signum); \ + } while (0) +// wait until child statu changed +#define WaitProcKilled(pid, signum) do { \ + int exitCode; \ + int procStat = CheckProcStatus(pid, &exitCode, 0); \ + TEST_ASSERT_EQUAL_INT(procStat, 2); \ + TEST_ASSERT_EQUAL_INT(exitCode, signum); \ + } while (0) + +// for now, crash process act like killed by SIGUSR2 +#define ExpectProcCrashed(pid) WaitProcKilled(pid, SIGUSR2) + +// keep current process run for a specific time, no sleep. +// msec is millisecond (1/1000 sec). +// return value is the loop count(generally you don't need to care about it) +int KeepRun(int msec); + +/** + * code to determain if execve is faild, may confic with actual sub program's exit code + */ +static const int EXECVE_RETURN_ERROR = 190; // execve return -1 +static const int EXECVE_RETURN_OK = 191; // execve return not -1: execve should never return on success + +/** + * desc: start a elf, check if execve success, and return child process exit code within timeout_sec + * input: fname, argv, envp -- parameters for execve + * timeout_sec -- timeout of the child executing, default: 5 seconds. + * timeout_sec<=0 means no timeout, wait forever until child exit. + * output: -1 -- something wrong for internal syscall, check log for detail + * -2 -- child does not finish in 'timeout_sec' + * n(>=0) -- child exit code + */ +int RunElf(const char* fname, char* const argv[], char* const envp[], int timeoutSec); + +/** + * desc: call execve with error parameters(e.g. a non-exist file) + * input: fname, argv, envp -- parameters for execve + * output: 0 -- execve ok + * -1 -- unexpected fork error + * -2 -- unexpected execve error + * -3 -- unknow error + * n(>0) -- errno of execve + */ +int StartExecveError(const char* fname, char* const argv[], char* const envp[]); + +// Get a pid number that currently not exist +pid_t GetNonExistPid(); + +/** + * return random number n: 0 < n <= max + * we found in most case '0' is not expected. + */ +uint32_t GetRandom(uint32_t max); + +/** + * desc: get current time, plus 'ms' + */ +void GetDelayedTime(struct timespec *ts, unsigned int ms); + +/** + * desc: calculate time difference, in ms + * output: return time difference, unit is ms + */ +int GetTimeDiff(struct timespec ts1, struct timespec ts2); + +/** + * desc: fix calling process to one cpu + * output: return 0 successful, -1 fail + */ +// int FixCurProcessToOneCpu(int cpuIndex, cpu_set_t* pOldMask); + +/** + * desc: get cpu count + * output: return cpu count + */ +int GetCpuCount(void); +uint32_t GetRandom(uint32_t max); + +#endif \ No newline at end of file