diff --git a/testsuites/unittest/xts/BUILD.gn b/testsuites/unittest/xts/BUILD.gn index d653371a..75335428 100644 --- a/testsuites/unittest/xts/BUILD.gn +++ b/testsuites/unittest/xts/BUILD.gn @@ -31,13 +31,16 @@ import("//kernel/liteos_m/liteos.gni") static_library("xts_test") { sources = [ "xts_test.c" ] deps = [ + "cmsis:cmsis_test", "io:io_test", "ipc:ipc_test", "math:math_test", "mem:mem_test", + "net:net_test", "process:pthread_test", "sched:sched_test", "sys:system_test", + "time:time_test", ] configs += [ "$LITEOSTOPDIR/testsuites:include" ] } diff --git a/testsuites/unittest/xts/cmsis/BUILD.gn b/testsuites/unittest/xts/cmsis/BUILD.gn new file mode 100644 index 00000000..314a9549 --- /dev/null +++ b/testsuites/unittest/xts/cmsis/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") + +static_library("cmsis_test") { + sources = [ + "cmsis_timer_func_test.c", + "xts_cmsis.c", + ] + + include_dirs = [ + ".", + "$LITEOSTOPDIR/testsuites/include", + "$LITEOSTOPDIR/testsuites/unittest/xts", + ] +} diff --git a/testsuites/unittest/xts/cmsis/cmsis_timer_func_test.c b/testsuites/unittest/xts/cmsis/cmsis_timer_func_test.c new file mode 100644 index 00000000..78bd6fd1 --- /dev/null +++ b/testsuites/unittest/xts/cmsis/cmsis_timer_func_test.c @@ -0,0 +1,755 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "xts_cmsis.h" + +UINT16 g_cmsisTestTimeCount; + +/** + * @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) +{ + 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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + (void)osTimerDelete(id); + status = osDelay(DELAY_TICKS_5); + ICUNIT_ASSERT_EQUAL(status, osOK, status); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + (void)osTimerDelete(id); + status = osDelay(DELAY_TICKS_5); + ICUNIT_ASSERT_EQUAL(status, osOK, status); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew(NULL, osTimerOnce, &value, NULL); + ICUNIT_ASSERT_EQUAL(id, NULL, id); + status = osDelay(DELAY_TICKS_5); + ICUNIT_ASSERT_EQUAL(status, osOK, status); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew(NULL, osTimerPeriodic, &value, NULL); + ICUNIT_ASSERT_EQUAL(id, NULL, id); + status = osDelay(DELAY_TICKS_5); + ICUNIT_ASSERT_EQUAL(status, osOK, status); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, INVALID_TIMER_TYPE, &value, NULL); + ICUNIT_ASSERT_EQUAL(id, NULL, id); + status = osDelay(DELAY_TICKS_5); + ICUNIT_ASSERT_EQUAL(status, osOK, status); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + g_cmsisTestTimeCount = 0; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc002, osTimerOnce, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + + status = osDelay(DELAY_TICKS_10); + ICUNIT_ASSERT_EQUAL(status, osOK, status); + ICUNIT_ASSERT_EQUAL(1, g_cmsisTestTimeCount, g_cmsisTestTimeCount); /* 1, common data for test, no special meaning */ + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + UINT32 millisec = MILLISEC_NUM_INT4; + g_cmsisTestTimeCount = 0; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc002, osTimerPeriodic, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + + status = osDelay(DELAY_TICKS_10); + ICUNIT_ASSERT_EQUAL(status, osOK, status); + ICUNIT_ASSERT_EQUAL(TIMER_PERIODIC_COUNT, g_cmsisTestTimeCount, g_cmsisTestTimeCount); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + uwRet = osTimerStart(id, 0); + ICUNIT_ASSERT_EQUAL(osErrorParameter, uwRet, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + uwRet = osTimerStart(id, 0); + ICUNIT_ASSERT_EQUAL(osErrorParameter, uwRet, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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 millisec = MILLISEC_NUM_INT4; + UINT32 uwRet = osTimerStart(NULL, millisec); + ICUNIT_ASSERT_EQUAL(osErrorParameter, uwRet, uwRet); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + status = osDelay(1); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(status, osOK, status); + uwRet = osTimerDelete(id); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + status = osDelay(1); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(status, osOK, status); + uwRet = osTimerDelete(id); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + osTimerStart(id, millisec); + status = osDelay(1); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(status, osOK, status); + uwRet = osTimerDelete(id); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + status = osDelay(1); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(status, osOK, status); + uwRet = osTimerDelete(id); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + return 0; +}; + +/** + * @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 = osTimerDelete(NULL); + ICUNIT_ASSERT_EQUAL(osErrorParameter, uwRet, uwRet); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + status = osDelay(1); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(status, osOK, status); + uwRet = osTimerStop(id); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + UINT32 millisec = MILLISEC_NUM_INT10; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + status = osDelay(1); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(status, osOK, status); + uwRet = osTimerStop(id); + ICUNIT_ASSERT_EQUAL(osOK, uwRet, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerOnce, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + status = osDelay(1); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(status, osOK, status); + uwRet = osTimerStop(id); + ICUNIT_ASSERT_EQUAL(osErrorResource, uwRet, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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; + osStatus_t status; + UINT32 value = 0xffff; + id = osTimerNew((osTimerFunc_t)CmsisTimerFunc001, osTimerPeriodic, &value, NULL); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + status = osDelay(1); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(status, osOK, status); + uwRet = osTimerStop(id); + ICUNIT_ASSERT_EQUAL(osErrorResource, uwRet, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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 = osTimerStop(NULL); + ICUNIT_ASSERT_EQUAL(osErrorParameter, uwRet, uwRet); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerIsRunning(id); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + uwRet = osTimerIsRunning(id); + ICUNIT_ASSERT_EQUAL(uwRet, 1, uwRet); /* 1, common data for test, no special meaning */ + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + uwRet = osTimerStop(id); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + + uwRet = osTimerIsRunning(id); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + uwRet = osTimerDelete(id); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + uwRet = osTimerIsRunning(id); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerIsRunning(id); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, osOK, uwRet); + uwRet = osTimerIsRunning(id); + ICUNIT_ASSERT_EQUAL(uwRet, 1, uwRet); /* 1, common data for test, no special meaning */ + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + uwRet = osTimerStop(id); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + uwRet = osTimerIsRunning(id); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + (void)osTimerDelete(id); + return 0; +}; + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(id, NULL, id); + + uwRet = osTimerStart(id, millisec); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + uwRet = osTimerDelete(id); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + uwRet = osTimerIsRunning(id); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + return 0; +}; + +/** + * @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 = osTimerIsRunning(NULL); + ICUNIT_ASSERT_EQUAL(uwRet, 0, uwRet); + return 0; +}; + +/** + * @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 = osKernelGetTickFreq(); + ICUNIT_ASSERT_EQUAL(uwRet, LOSCFG_BASE_CORE_TICK_PER_SECOND, uwRet); + return 0; +}; + +/** + * @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 = osKernelGetSysTimerFreq(); + ICUNIT_ASSERT_EQUAL(uwRet, OS_SYS_CLOCK, uwRet); + return 0; +}; + +RUN_TEST_SUITE(CmsisTimerFuncTestSuite); + +void CmsisTimerFuncTest(void) +{ + RUN_ONE_TESTCASE(testOsTimerNew001); + RUN_ONE_TESTCASE(testOsTimerNew002); + RUN_ONE_TESTCASE(testOsTimerNew003); + RUN_ONE_TESTCASE(testOsTimerNew004); + RUN_ONE_TESTCASE(testOsTimerNew005); + RUN_ONE_TESTCASE(testOsTimerStart001); + RUN_ONE_TESTCASE(testOsTimerStart002); + RUN_ONE_TESTCASE(testOsTimerStart003); + RUN_ONE_TESTCASE(testOsTimerStart004); + RUN_ONE_TESTCASE(testOsTimerStart005); + RUN_ONE_TESTCASE(testOsTimerStart006); + RUN_ONE_TESTCASE(testOsTimerStart007); + RUN_ONE_TESTCASE(testOsTimerDelete001); + RUN_ONE_TESTCASE(testOsTimerDelete002); + RUN_ONE_TESTCASE(testOsTimerDelete003); + RUN_ONE_TESTCASE(testOsTimerDelete004); + RUN_ONE_TESTCASE(testOsTimerDelete005); + RUN_ONE_TESTCASE(testOsTimerStop001); + RUN_ONE_TESTCASE(testOsTimerStop002); + RUN_ONE_TESTCASE(testOsTimerStop003); + RUN_ONE_TESTCASE(testOsTimerStop004); + RUN_ONE_TESTCASE(testOsTimerStop005); + RUN_ONE_TESTCASE(testOsTimerIsRunning001); + RUN_ONE_TESTCASE(testOsTimerIsRunning002); + RUN_ONE_TESTCASE(testOsTimerIsRunning003); + RUN_ONE_TESTCASE(testOsTimerIsRunning004); + RUN_ONE_TESTCASE(testOsTimerIsRunning005); + RUN_ONE_TESTCASE(testOsTimerIsRunning006); + RUN_ONE_TESTCASE(testOsTimerIsRunning007); + RUN_ONE_TESTCASE(testOsTimerIsRunning008); + RUN_ONE_TESTCASE(testOsTimerIsRunning009); + RUN_ONE_TESTCASE(testOsKernelGetTickFreq001); + RUN_ONE_TESTCASE(testOsKernelGetSysTimerFreq001); +} diff --git a/testsuites/unittest/xts/cmsis/xts_cmsis.c b/testsuites/unittest/xts/cmsis/xts_cmsis.c new file mode 100644 index 00000000..011370c4 --- /dev/null +++ b/testsuites/unittest/xts/cmsis/xts_cmsis.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "xts_test.h" + +void CmsisFuncTest(void) +{ + CmsisTimerFuncTest(); +} \ No newline at end of file diff --git a/testsuites/unittest/xts/cmsis/xts_cmsis.h b/testsuites/unittest/xts/cmsis/xts_cmsis.h new file mode 100644 index 00000000..80c50a38 --- /dev/null +++ b/testsuites/unittest/xts/cmsis/xts_cmsis.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef XTS_CMSID_H +#define XTS_CMSID_H + +#include "xts_test.h" +#include +#include +#include "cmsis_os2.h" + +#define MILLISEC_NUM_INT10 10U +#define MILLISEC_NUM_INT4 4U +#define INVALID_TIMER_TYPE 10 +#define TIMER_PERIODIC_COUNT 2 + +#define DELAY_TICKS_1 1 +#define DELAY_TICKS_5 5 +#define DELAY_TICKS_10 10 + +#endif \ No newline at end of file diff --git a/testsuites/unittest/xts/net/BUILD.gn b/testsuites/unittest/xts/net/BUILD.gn new file mode 100644 index 00000000..20a14c27 --- /dev/null +++ b/testsuites/unittest/xts/net/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") + +static_library("net_test") { + sources = [ "acts_net_test.c" ] + + include_dirs = [ + ".", + "$LITEOSTOPDIR/testsuites/include", + "$LITEOSTOPDIR/testsuites/unittest/xts", + "$THIRDPARTY_MUSL_DIR/include/net", + ] +} diff --git a/testsuites/unittest/xts/net/acts_net_test.c b/testsuites/unittest/xts/net/acts_net_test.c new file mode 100644 index 00000000..badc5760 --- /dev/null +++ b/testsuites/unittest/xts/net/acts_net_test.c @@ -0,0 +1,419 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "xts_net.h" + +LITE_TEST_SUIT(NET, ActsNet, ActsNetTestSuite); + +static BOOL ActsNetTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL ActsNetTestSuiteTearDown(void) +{ + 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); + ICUNIT_ASSERT_NOT_EQUAL(udpFd, -1, udpFd); /* -1, common data for test, no special meaning */ + + struct ifreq ifre[5]; /* 5, common data for test, no special meaning */ + struct ifconf ifcf = {0}; + (void)memset_s(&ifcf, sizeof(struct ifconf), 0, sizeof(struct ifconf)); + ifcf.ifc_len = 5 * sizeof(struct ifreq); /* 5, common data for test, no special meaning */ + ifcf.ifc_buf = (char *)ifre; + int ret = ioctl(udpFd, SIOCGIFCONF, (char *)&ifcf); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + char rst1[18]; /* 18, common data for test, no special meaning */ + char *macPtr = NULL; + struct ifreq ifrTmp = {0}; + struct sockaddr_in *addr = NULL; + int ifrCount = ifcf.ifc_len / sizeof(struct ifreq); + ICUNIT_GOTO_EQUAL(ifrCount, 2, ifrCount, EXIT); /* 2, common data for test, no special meaning */ + ICUNIT_ASSERT_WITHIN_EQUAL(ifrCount, 2, INT_MAX, ifrCount); /* 2, common data for test, no special meaning */ +EXIT: + for (int i = 0; i < ifrCount; i++) { + addr = (struct sockaddr_in *)&ifre[i].ifr_addr; + if (strcmp("lo", ifre[i].ifr_name) != 0) { + (void)memset_s(&ifrTmp, sizeof(struct ifreq), 0, sizeof(struct ifreq)); + ret = strcpy_s(ifrTmp.ifr_name, sizeof(ifrTmp.ifr_name), ifre[i].ifr_name); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ret = ioctl(udpFd, SIOCGIFHWADDR, &ifrTmp); + ICUNIT_ASSERT_EQUAL(ret, 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)); /* 1, 2, 3, 4, 5, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL((unsigned int)ret, strlen(rst1), (unsigned int)ret); + } + } + ret = close(udpFd); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + return 0; +} + +/** + * @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); + ICUNIT_ASSERT_NOT_EQUAL(fd, -1, fd); /* -1, common data for test, no special meaning */ + + int error = -1; /* -1, common data for test, no special meaning */ + len = sizeof(error); + int ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(error, 0, error); + + len = sizeof(timeout); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + timeout.tv_sec = 1000; /* 1000, common data for test, no special meaning */ + len = sizeof(timeout); + ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + (void)memset_s(&timeout, len, 0, len); + ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(timeout.tv_sec, 1000, timeout.tv_sec); /* 1000, common data for test, no special meaning */ + + int flag = 1; /* 1, common data for test, no special meaning */ + ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + + flag = 0; + len = sizeof(flag); + ret = getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, &len); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(flag, 1, flag); /* 1, common data for test, no special meaning */ + + error = -1; /* -1, common data for test, no special meaning */ + len = sizeof(error); + ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + ICUNIT_ASSERT_EQUAL(error, 0, error); + + ret = close(fd); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + return 0; +} + +/** + * @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); /* -1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getpeername(-1, &addr, &addrLen); /* -1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getsockname(0, &addr, &addrLen); + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getpeername(0, &addr, &addrLen); + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getsockname(1, &addr, &addrLen); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getpeername(1, &addr, &addrLen); /* 1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getsockname(130, &addr, &addrLen); /* 130, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getpeername(130, &addr, &addrLen); /* 130, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getsockname(10, NULL, &addrLen); /* 10, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getpeername(10, NULL, &addrLen); /* 10, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getsockname(10, &addr, NULL); /* 10, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = getpeername(10, &addr, NULL); /* 10, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + return 0; +} + +/** + * @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 intRst01 = htonl(intInput1); + uint32_t intInput2 = 65536; /* 65536, common data for test, no special meaning */ + uint32_t intRst02 = htonl(intInput2); + uint16_t shortInput1 = 0; + uint16_t shortRst01 = htons(shortInput1); + uint16_t shortInput2 = 255; /* 255, common data for test, no special meaning */ + uint16_t shortRst02 = htons(shortInput2); + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + uint32_t expectZero = 0; + uint32_t expectForIinput2 = 256; /* 255, common data for test, no special meaning */ + uint32_t expectForSinput2 = 65280; /* 65536, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(intRst01, expectZero, intRst01); + ICUNIT_ASSERT_EQUAL(intRst02, expectForIinput2, intRst02); + ICUNIT_ASSERT_EQUAL(shortRst01, expectZero, shortRst01); + ICUNIT_ASSERT_EQUAL(shortRst02, expectForSinput2, shortRst02); +#else + ICUNIT_ASSERT_EQUAL(intRst01, intInput1, intRst01); + ICUNIT_ASSERT_EQUAL(intRst02, intInput2, intRst02); + ICUNIT_ASSERT_EQUAL(shortRst01, shortInput1, shortRst01); + ICUNIT_ASSERT_EQUAL(shortRst02, shortInput2, shortRst02); +#endif + return 0; +} + +/** + * @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; /* 65536, common data for test, no special meaning */ + uint32_t intRst02 = ntohl(intInput2); + uint16_t shortInput1 = 0; + uint16_t shortRst01 = ntohs(shortInput1); + uint16_t shortInput2 = 255; /* 255, common data for test, no special meaning */ + uint16_t shortRst02 = ntohs(shortInput2); + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + uint32_t expectZero = 0; + uint32_t expectForIinput2 = 256; /* 255, common data for test, no special meaning */ + uint32_t expectForSinput2 = 65280; /* 65536, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(intRst1, expectZero, intRst1); + ICUNIT_ASSERT_EQUAL(intRst02, expectForIinput2, intRst02); + ICUNIT_ASSERT_EQUAL(shortRst01, expectZero, shortRst01); + ICUNIT_ASSERT_EQUAL(shortRst02, expectForSinput2, shortRst02); +#else + ICUNIT_ASSERT_EQUAL(intRst1, intInput1, intRst1); + ICUNIT_ASSERT_EQUAL(intRst02, intInput2, intRst02); + ICUNIT_ASSERT_EQUAL(shortRst01, shortInput1, shortRst01); + ICUNIT_ASSERT_EQUAL(shortRst02, shortInput2, shortRst02); +#endif + return 0; +} + +/** + * @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"}; /* 4, 16, common data for test, no special meaning */ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + unsigned int expLittle[4] = {1691630090, 0, 255, 4294967295}; /* 4, common data for test, no special meaning */ +#else + unsigned int expBig[4] = {171627620, 0, 4278190080, 4294967295}; /* 4, common data for test, no special meaning */ +#endif + + for (int i = 0; i < 4; i++) { /* 4, common data for test, no special meaning */ + ret = inet_pton(AF_INET, cpAddrs[i], &rst); + ICUNIT_ASSERT_EQUAL(ret, 1, ret); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + ICUNIT_ASSERT_EQUAL(rst.s_addr, expLittle[i], rst.s_addr); +#else + ICUNIT_ASSERT_EQUAL(rst.s_addr, expBig[i], rst.s_addr); +#endif + } + return 0; +} + +/** + * @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", /* 6, 40, common data for test, no special meaning */ + "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", "::", "1::", "0011:0011:0011:0011:11:11:11:11"}; + for (int i = 0; i < 6; i++) { /* 6, common data for test, no special meaning */ + ret = inet_pton(AF_INET6, cpAddrs[i], &rst); + ICUNIT_ASSERT_EQUAL(ret, 1, ret); /* 1, common data for test, no special meaning */ + } + return 0; +} + +/** + * @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:::", ":::::::", /* 7, 40, common data for test, no special meaning */ + "1111:1111:1111:1111:1111:1111:1111:111G"}; + for (int i = 0; i < 7; i++) { /* 7, common data for test, no special meaning */ + ret = inet_pton(AF_INET6, cpAddrs[i], &rst); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + } + return 0; +} + +/** + * @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); + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ret = inet_pton(-1, "127.0.0.1", &rst); + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + return 0; +} + +/** + * @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 inpLittle[4] = {0x64d43a0a, 0, 255, 4294967295}; /* 4, common data for test, no special meaning */ +#else + unsigned int inpBig[4] = {171627620, 0, 4278190080, 4294967295}; /* 4, common data for test, no special meaning */ +#endif + + char expAddrs[4][16] = {"10.58.212.100", "0.0.0.0", "255.0.0.0", "255.255.255.255"}; /* 4, 16, common data for test, no special meaning */ + for (int i = 0; i < 4; i++) { /* 4, common data for test, no special meaning */ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + inputAddr.s_addr = inpLittle[i]; +#else + inputAddr.s_addr = inpBig[i]; +#endif + ret = inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff)); + if (ret == NULL) { + ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret); + } else { + ICUNIT_ASSERT_STRING_EQUAL(ret, expAddrs[i], ret); + ICUNIT_ASSERT_STRING_EQUAL(rstBuff, expAddrs[i], rstBuff); + } + } + return 0; +} + +/** + * @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 expStr[2][16] = {"255.255.255.255", "0.0.0.0"}; /* 2, 16, common data for test, no special meaning */ + for (int i = 0; i < 2; i++) { /* 2, common data for test, no special meaning */ + inputAddr.s_addr = (i == 0 ? -1 : 4294967296); /* -1, 4294967296, common data for test, no special meaning */ + ret = inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff)); + ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret); + ICUNIT_ASSERT_STRING_EQUAL(ret, expStr[i], ret); + ICUNIT_ASSERT_STRING_EQUAL(rstBuff, expStr[i], rstBuff); + } + return 0; +} + +/** + * @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); + ICUNIT_ASSERT_EQUAL(iret, 1, iret); /* 1, common data for test, no special meaning */ + ret = inet_ntop(AF_IPX, &inputAddr, rstBuff, sizeof(rstBuff)); + ICUNIT_ASSERT_EQUAL(ret, NULL, ret); + ret = inet_ntop(-1, &inputAddr, rstBuff, sizeof(rstBuff)); /* -1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(ret, NULL, ret); + return 0; +} + +RUN_TEST_SUITE(ActsNetTestSuite); + +void ActsNetTest(void) +{ + RUN_ONE_TESTCASE(testIoctlIfhwAddr); + RUN_ONE_TESTCASE(testSocketOpt); + RUN_ONE_TESTCASE(testGetSocketNameInvalidInput); + RUN_ONE_TESTCASE(testHostToNetwork); + RUN_ONE_TESTCASE(testNetworkToHost); + RUN_ONE_TESTCASE(testInetPtonIpv4Normal); + RUN_ONE_TESTCASE(testInetPtonInvalidFamily); + RUN_ONE_TESTCASE(testInetNtopIpv4Normal); + RUN_ONE_TESTCASE(testInetNtopIpv4Abnormal); +#if (LWIP_IPV6 == 1) + RUN_ONE_TESTCASE(testInetPtonIpv6Normal); + RUN_ONE_TESTCASE(testInetPtonIpv6Abnormal); + RUN_ONE_TESTCASE(testInetNtopInvalidFamily); +#endif +} + diff --git a/testsuites/unittest/xts/net/xts_net.h b/testsuites/unittest/xts/net/xts_net.h new file mode 100644 index 00000000..051a97ea --- /dev/null +++ b/testsuites/unittest/xts/net/xts_net.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef XTS_NET_H +#define XTS_NET_H +#define _GNU_SOURCE + +#include "if.h" +#include "xts_test.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lwip/sockets.h" +#include + +#endif diff --git a/testsuites/unittest/xts/time/BUILD.gn b/testsuites/unittest/xts/time/BUILD.gn new file mode 100644 index 00000000..dece037b --- /dev/null +++ b/testsuites/unittest/xts/time/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//kernel/liteos_m/liteos.gni") + +static_library("time_test") { + sources = [ + "alarm_test.c", + "clock_time_test.c", + "sleep_test.c", + "time_utils_test.c", + ] + + include_dirs = [ + ".", + "$LITEOSTOPDIR/testsuites/include", + "$LITEOSTOPDIR/testsuites/unittest/xts", + ] +} diff --git a/testsuites/unittest/xts/time/alarm_test.c b/testsuites/unittest/xts/time/alarm_test.c new file mode 100644 index 00000000..4c32d6c0 --- /dev/null +++ b/testsuites/unittest/xts/time/alarm_test.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "xts_test.h" +#include "alarm_test.h" + +LITE_TEST_SUIT(TIME, TimeAlarmTest, TimeAlarmTestSuite); + +static BOOL TimeAlarmTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL TimeAlarmTestSuiteTearDown(void) +{ + 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) +{ + int ret; + timer_t tid = NULL; + clockid_t clockid = GetRandom(2048); /* 2048, common data for test, no special meaning */ + ret = timer_create(clockid, NULL, &tid); + ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */ + ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno); + return 0; +} + +RUN_TEST_SUITE(TimeAlarmTestSuite); + +void AlarmTest(void) +{ + RUN_ONE_TESTCASE(testTimerCreateEINVAL); +} + +void TimeFuncTest(void) +{ + AlarmTest(); + ClockTimeTest(); + SleepTest(); + TimeUtilsTest(); +} \ No newline at end of file diff --git a/testsuites/unittest/xts/time/alarm_test.h b/testsuites/unittest/xts/time/alarm_test.h new file mode 100644 index 00000000..1d78e70f --- /dev/null +++ b/testsuites/unittest/xts/time/alarm_test.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TIME_ALARM_TEST_H +#define TIME_ALARM_TEST_H +#define _GNU_SOURCE +#include "xts_test.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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) + +#endif \ No newline at end of file diff --git a/testsuites/unittest/xts/time/clock_time_test.c b/testsuites/unittest/xts/time/clock_time_test.c new file mode 100644 index 00000000..b7effddf --- /dev/null +++ b/testsuites/unittest/xts/time/clock_time_test.c @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "alarm_test.h" + +LITE_TEST_SUIT(TIME, TimeClockTimeTest, TimeClockTimeTestSuite); + +static BOOL TimeClockTimeTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL TimeClockTimeTestSuiteTearDown(void) +{ + 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; + struct timespec time1 = {0, 0}; + int rt = clock_gettime(cid, &time1); + ICUNIT_ASSERT_EQUAL(rt, 0, rt); + return 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}; + sleep(1); /* 1, common data for test, no special meaning */ + int rt = clock_gettime(CLOCK_REALTIME, &time1); + ICUNIT_ASSERT_EQUAL(rt, 0, rt); + time_t sec = time1.tv_sec; + time1.tv_sec -= 1; /* 1, common data for test, no special meaning */ + time1.tv_nsec = 1; /* 1, common data for test, no special meaning */ + rt = clock_settime(CLOCK_REALTIME, &time1); + ICUNIT_ASSERT_EQUAL(rt, 0, rt); + sleep(1); /* 1, common data for test, no special meaning */ + rt = clock_gettime(CLOCK_REALTIME, &time1); + ICUNIT_ASSERT_EQUAL(rt, 0, rt); + ICUNIT_ASSERT_EQUAL(time1.tv_sec, sec, time1.tv_sec); + return 0; +} + +/** +* @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 ret; + int sleepSec = 1; /* 1, common data for test, no special meaning */ + struct timeval tValStart = {0}; + struct timeval tValEnd = {0}; + struct timezone tZone; + + int ret1 = gettimeofday(&tValStart, &tZone); + sleep(sleepSec); + int ret2 = gettimeofday(&tValEnd, &tZone); + ICUNIT_ASSERT_EQUAL(ret1, 0, ret1); + ICUNIT_ASSERT_EQUAL(ret2, 0, ret2); + + ret = (int)(tValEnd.tv_sec - tValStart.tv_sec); + ICUNIT_ASSERT_EQUAL(ret, sleepSec, ret); + ICUNIT_ASSERT_WITHIN_EQUAL(ret, sleepSec, INT_MAX, ret); + ret = (int)(tValEnd.tv_sec - tValStart.tv_sec); + ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, sleepSec + 1, ret); /* 1, common data for test, no special meaning */ + return 0; +} + +/** +* @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 ret; + int setSec = 100; /* 100, common data for test, no special meaning */ + int sleepSec = 2; /* 2, common data for test, no special meaning */ + 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); + ICUNIT_ASSERT_EQUAL(ret1, 0, ret1); + ICUNIT_ASSERT_EQUAL(ret2, 0, ret2); + ICUNIT_ASSERT_EQUAL(ret3, 0, ret3); + ICUNIT_ASSERT_EQUAL(tValStart.tv_sec, setSec, tValStart.tv_sec); + + ret = (int)(tValEnd.tv_sec - tValStart.tv_sec); + ICUNIT_ASSERT_EQUAL(ret, sleepSec, ret); + ICUNIT_ASSERT_WITHIN_EQUAL(ret, sleepSec, INT_MAX, ret); + ret = (int)(tValEnd.tv_sec - tValStart.tv_sec); + ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, sleepSec + 1, ret); /* 1, common data for test, no special meaning */ + return 0; +} + +RUN_TEST_SUITE(TimeClockTimeTestSuite); + +void ClockTimeTest(void) +{ + RUN_ONE_TESTCASE(testClockGettimeAll); + RUN_ONE_TESTCASE(testClockSettime); + RUN_ONE_TESTCASE(testGettimeofday); + RUN_ONE_TESTCASE(testSettimeofday); +} diff --git a/testsuites/unittest/xts/time/sleep_test.c b/testsuites/unittest/xts/time/sleep_test.c new file mode 100644 index 00000000..e8aeb6fd --- /dev/null +++ b/testsuites/unittest/xts/time/sleep_test.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "alarm_test.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", +}; + +LITE_TEST_SUIT(TIME, TimeSleepTest, TimeSleepTestSuite); + +static BOOL TimeSleepTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL TimeSleepTestSuiteTearDown(void) +{ + 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; /* 1, common data for test, no special meaning */ + const char *cname = ALL_CLOCKS_NAME[cid]; + struct timespec req = {0, 100}; /* 100, common data for test, no special meaning */ + struct timespec rem = {0}; + int rt = clock_nanosleep(cid, 0, &req, &rem); + if (cid == CLOCK_SGI_CYCLE) { + ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt); + } + return 0; +} + +/** + * @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}; /* 100, common data for test, no special meaning */ + struct timespec rem = {0}; + int rt; + + int id = GetRandom(1000) + 12; /* 1000, 12, common data for test, no special meaning */ + rt = clock_nanosleep(id, 0, &req, &rem); + ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt); + + id = -GetRandom(1000) - 12; /* 1000, 12, common data for test, no special meaning */ + rt = clock_nanosleep(id, 0, &req, &rem); + ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt); + + int flag = TIMER_ABSTIME; + rt = clock_nanosleep(CLOCK_REALTIME, flag, &req, &rem); + ICUNIT_ASSERT_EQUAL(rt, ENOTSUP, rt); + flag = GetRandom(100) + 1; /* 100, 1, common data for test, no special meaning */ + rt = clock_nanosleep(CLOCK_REALTIME, flag, &req, &rem); + ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt); + flag = -GetRandom(100) - 1; /* 100, 1, common data for test, no special meaning */ + rt = clock_nanosleep(CLOCK_REALTIME, flag, &req, &rem); + ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt); + + req.tv_sec = -1; /* -1, common data for test, no special meaning */ + req.tv_nsec = 1; /* 1, common data for test, no special meaning */ + rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); + ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno); + req.tv_sec = 1; /* 1, common data for test, no special meaning */ + req.tv_nsec = -1; /* -1, common data for test, no special meaning */ + rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); + ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno); + req.tv_sec = 1; /* 1, common data for test, no special meaning */ + req.tv_nsec = 1000 * 1000 * 1000 + 1; /* 1000, 1, common data for test, no special meaning */ + rt = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem); + ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno); + return 0; +} + +RUN_TEST_SUITE(TimeSleepTestSuite); + +void SleepTest(void) +{ + RUN_ONE_TESTCASE(testClockNanosleepInvalidID); + RUN_ONE_TESTCASE(testClockNanosleepInvalidPara); +} diff --git a/testsuites/unittest/xts/time/time_utils_test.c b/testsuites/unittest/xts/time/time_utils_test.c new file mode 100644 index 00000000..d2ef669d --- /dev/null +++ b/testsuites/unittest/xts/time/time_utils_test.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "alarm_test.h" + +time_t g_time = 18880; /* 18880, common data for test, no special meaning */ +size_t g_zero = 0; + +LITE_TEST_SUIT(TIME, TimeUtilsTest, TimeUtilsTestSuite); + +static BOOL TimeUtilsTestSuiteSetUp(void) +{ + return TRUE; +} + +static BOOL TimeUtilsTestSuiteTearDown(void) +{ + return TRUE; +} + +/** +* @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 = NULL; + struct tm timeptr = {0}; + struct timeval tv; + struct timezone tz; + + int ret = gettimeofday(&tv, &tz); + ICUNIT_ASSERT_EQUAL(ret, 0, ret); + long sysTimezone = (long)(-tz.tz_minuteswest) * SECS_PER_MIN; + + INIT_TM(timeptr, 2000, 6, 9, 10, 10, 0, 7); /* 2000, 6, 9, 10, 7, common data for test, no special meaning */ + time_t timeRet = mktime(&timeptr); + ICUNIT_ASSERT_EQUAL(sysTimezone, timeptr.__tm_gmtoff, sysTimezone); + ICUNIT_ASSERT_EQUAL(timeRet, 963137400 - timeptr.__tm_gmtoff, timeRet); /* 963137400, common data for test, no special meaning */ + localTime = localtime(&g_time); + ICUNIT_ASSERT_NOT_EQUAL(localTime, NULL, localTime); + time_t timep = mktime(localTime); + ICUNIT_ASSERT_EQUAL(timep, 18880, timep); /* 18880, common data for test, no special meaning */ + return 0; +} + +RUN_TEST_SUITE(TimeUtilsTestSuite); + +void TimeUtilsTest(void) +{ + RUN_ONE_TESTCASE(testMktime); +} diff --git a/testsuites/unittest/xts/xts_test.c b/testsuites/unittest/xts/xts_test.c index f3e6f08c..7fa2d582 100644 --- a/testsuites/unittest/xts/xts_test.c +++ b/testsuites/unittest/xts/xts_test.c @@ -44,7 +44,10 @@ void XtsTestSuite(void) IoFuncTest(); MathFuncTest(); MemFuncTest(); + ActsNetTest(); PthreadFuncTest(); SchedApiFuncTest(); SysApiFuncTest(); + TimeFuncTest(); + CmsisFuncTest(); } \ No newline at end of file diff --git a/testsuites/unittest/xts/xts_test.h b/testsuites/unittest/xts/xts_test.h index 6dd0260b..3cfab89c 100644 --- a/testsuites/unittest/xts/xts_test.h +++ b/testsuites/unittest/xts/xts_test.h @@ -63,10 +63,16 @@ extern void MathFuncTest(void); extern void MemFuncTest(void); +extern void ActsNetTest(void); + extern void PthreadFuncTest(void); extern void SchedApiFuncTest(void); extern void SysApiFuncTest(void); +extern void TimeFuncTest(void); + +extern void CmsisFuncTest(void); + #endif