Compare commits
12 Commits
weekly_202
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab131703be | ||
|
|
f2ddeaebfd | ||
|
|
5d5e155f31 | ||
|
|
0c3dbb4c01 | ||
|
|
873255af51 | ||
|
|
22702a27fc | ||
|
|
b37358cb47 | ||
|
|
b73eb72ba6 | ||
|
|
e98de4489f | ||
|
|
4cfb20d7e9 | ||
|
|
9248d46457 | ||
|
|
808b9de5b8 |
@@ -43,7 +43,7 @@
|
||||
"third_party": [
|
||||
"bounds_checking_function",
|
||||
"cmsis",
|
||||
"fatfs",
|
||||
"FatFs",
|
||||
"littlefs",
|
||||
"lwip",
|
||||
"musl"
|
||||
|
||||
@@ -48,7 +48,10 @@ kernel_module("test_init") {
|
||||
"src/osTest.c",
|
||||
]
|
||||
|
||||
include_dirs = [ "unittest/posix/src" ]
|
||||
include_dirs = [
|
||||
"unittest/posix/src",
|
||||
"unittest/xts",
|
||||
]
|
||||
|
||||
configs += [ ":include" ]
|
||||
}
|
||||
@@ -69,6 +72,7 @@ group("testsuites") {
|
||||
"sample/kernel/task:test_task",
|
||||
"sample/posix:test_posix",
|
||||
"unittest/posix:posix_test",
|
||||
"unittest/xts:xts_test",
|
||||
]
|
||||
if (defined(LOSCFG_DYNLINK)) {
|
||||
deps += [ "sample/kernel/dynlink:test_dynlink" ]
|
||||
|
||||
@@ -96,6 +96,7 @@ extern "C" {
|
||||
#define LOS_KERNEL_LMK_TEST 0
|
||||
#define LOS_KERNEL_SIGNAL_TEST 0
|
||||
|
||||
#define LOS_XTS_TEST 1
|
||||
#define LOS_POSIX_TEST 1
|
||||
#define LOS_CMSIS_TEST 1
|
||||
#define LOS_CMSIS2_CORE_TASK_TEST 0
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
#if (LOS_POSIX_TEST == 1)
|
||||
#include "posix_test.h"
|
||||
#endif
|
||||
#if (LOS_XTS_TEST == 1)
|
||||
#include "xts_test.h"
|
||||
#endif
|
||||
|
||||
UINT32 volatile g_testCount;
|
||||
UINT32 g_testTskHandle;
|
||||
@@ -246,6 +249,10 @@ VOID TestTaskEntry(VOID)
|
||||
CmsisFuncTestSuite();
|
||||
#endif
|
||||
|
||||
#if(LOS_XTS_TEST == 1)
|
||||
XtsTestSuite();
|
||||
#endif
|
||||
|
||||
/* The log is used for testing entrance guard, please do not make any changes. */
|
||||
PRINTF("\nfailed count:%d, success count:%d\n", g_failResult, g_passResult);
|
||||
PRINTF("--- Test End ---\n");
|
||||
|
||||
46
testsuites/unittest/xts/BUILD.gn
Normal file
46
testsuites/unittest/xts/BUILD.gn
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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("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" ]
|
||||
}
|
||||
42
testsuites/unittest/xts/cmsis/BUILD.gn
Normal file
42
testsuites/unittest/xts/cmsis/BUILD.gn
Normal file
@@ -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",
|
||||
]
|
||||
}
|
||||
755
testsuites/unittest/xts/cmsis/cmsis_timer_func_test.c
Normal file
755
testsuites/unittest/xts/cmsis/cmsis_timer_func_test.c
Normal file
@@ -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);
|
||||
}
|
||||
36
testsuites/unittest/xts/cmsis/xts_cmsis.c
Normal file
36
testsuites/unittest/xts/cmsis/xts_cmsis.c
Normal file
@@ -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();
|
||||
}
|
||||
48
testsuites/unittest/xts/cmsis/xts_cmsis.h
Normal file
48
testsuites/unittest/xts/cmsis/xts_cmsis.h
Normal file
@@ -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 <securec.h>
|
||||
#include <limits.h>
|
||||
#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
|
||||
46
testsuites/unittest/xts/io/BUILD.gn
Normal file
46
testsuites/unittest/xts/io/BUILD.gn
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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("io_test") {
|
||||
sources = [
|
||||
"xts_io.c",
|
||||
"xts_io_other_test.c",
|
||||
"xts_io_stdio_test.c",
|
||||
"xts_io_stdlib_test.c",
|
||||
"xts_io_string_test.c",
|
||||
"xts_io_strings_test.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
40
testsuites/unittest/xts/io/xts_io.c
Normal file
40
testsuites/unittest/xts/io/xts_io.c
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
#include "xts_test.h"
|
||||
|
||||
void IoFuncTest(void)
|
||||
{
|
||||
XtsIoOtherTest();
|
||||
XtsIoStdioFuncTest();
|
||||
XtsIoStdlibFuncTest();
|
||||
XtsIoStringFuncTest();
|
||||
XtsIoStringsFuncTest();
|
||||
}
|
||||
51
testsuites/unittest/xts/io/xts_io.h
Normal file
51
testsuites/unittest/xts/io/xts_io.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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_IO_H
|
||||
#define XTS_IO_H
|
||||
|
||||
#include "xts_test.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <securec.h>
|
||||
#include <sys/uio.h>
|
||||
#include <grp.h>
|
||||
#include <shadow.h>
|
||||
#include <pwd.h>
|
||||
#include <inttypes.h>
|
||||
#include <iconv.h>
|
||||
#include <stdarg.h>
|
||||
#include <err.h>
|
||||
#include <threads.h>
|
||||
|
||||
#endif
|
||||
78
testsuites/unittest/xts/io/xts_io_other_test.c
Normal file
78
testsuites/unittest/xts/io/xts_io_other_test.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoOther, IoOtherTestSuite);
|
||||
|
||||
static BOOL IoOtherTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoOtherTestSuiteTearDown(void)
|
||||
{
|
||||
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);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "abc", ret);
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_year, 120, tm.tm_year); /* 120 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_mon, 9, tm.tm_mon); /* 9 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_mday, 29, tm.tm_mday); /* 29 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_hour, 21, tm.tm_hour); /* 21 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_min, 24, tm.tm_min); /* 24 common data for test, no special meaning */
|
||||
|
||||
ret = strptime("14 Oct October 20 09:24:00 Sat Saturday 363", "%d %b %B %y %I:%M:%S %a %A %j", &tm);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "", ret);
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_year, 120, tm.tm_year); /* 120 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_mon, 9, tm.tm_mon); /* 9 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_mday, 14, tm.tm_mday); /* 14 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_hour, 9, tm.tm_hour); /* 9 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_wday, 6, tm.tm_wday); /* 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_yday, 362, tm.tm_yday); /* 362 common data for test, no special meaning */
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoOtherTestSuite);
|
||||
|
||||
void XtsIoOtherTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrptime);
|
||||
}
|
||||
75
testsuites/unittest/xts/io/xts_io_stdio_test.c
Normal file
75
testsuites/unittest/xts/io/xts_io_stdio_test.c
Normal file
@@ -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_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoStdio, IoStdioTestSuite);
|
||||
|
||||
static BOOL IoStdioTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoStdioTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int FormatVsnptf(char *format, ...)
|
||||
{
|
||||
va_list vArgList;
|
||||
va_start(vArgList, format);
|
||||
char str[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
int ret = vsnprintf_s(str, sizeof(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 = FormatVsnptf((char *)"%s has %d words", "hello world", 11); /* 11 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 24, ret); /* 24 common data for test, no special meaning */
|
||||
|
||||
ret = FormatVsnptf((char *)"%f and %c as well as %ld\n", 2.2, 'c', 6); /* 2.2, 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 28, ret); /* 28 common data for test, no special meaning */
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoStdioTestSuite);
|
||||
|
||||
void XtsIoStdioFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testVsnprintf);
|
||||
}
|
||||
282
testsuites/unittest/xts/io/xts_io_stdlib_test.c
Normal file
282
testsuites/unittest/xts/io/xts_io_stdlib_test.c
Normal file
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
* 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_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoStdlibApi, IoStdlibApiTestSuite);
|
||||
|
||||
static BOOL IoStdlibApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoStdlibApiTestSuiteTearDown(void)
|
||||
{
|
||||
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);
|
||||
ICUNIT_ASSERT_EQUAL(ret, (float)(-3.40E+38), ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " hello", endPtr);
|
||||
|
||||
ret = strtof(" 3.40E+38 ===", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, (float)(3.40E+38), ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " ===", endPtr);
|
||||
|
||||
ret = strtof("-9.6e17 this 123", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, (float)(-9.6e17), ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " this 123", endPtr);
|
||||
|
||||
ret = strtof("this is string", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "this is string", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1.79E+308, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " hello", endPtr);
|
||||
|
||||
ret = strtod("1.79E+308 ===", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 1.79E+308, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " ===", endPtr);
|
||||
|
||||
ret = strtod("-9.6e17 this 123", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -9.6e17, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " this 123", endPtr);
|
||||
|
||||
ret = strtod("this is string", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "this is string", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " hello", endPtr);
|
||||
|
||||
ret = strtold(" 1.79769e+308 ===", &endPtr);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " ===", endPtr);
|
||||
|
||||
ret = strtold("-9.6e17 this 123", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -9.6e17, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " this 123", endPtr);
|
||||
|
||||
ret = strtold("this is string", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "this is string", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12, ret); /* 12 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0110 0XDEFE 0666 -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 2); /* 2 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 6, ret); /* 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0XDEFE 0666 -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 16); /* 16 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0XDEFE, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0666 -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 8); /* 8 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0666, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 65); /* 65 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".6", endPtr);
|
||||
|
||||
char nPtr1[] = "2147483647 2147483648 -2147483648 -2147483649";
|
||||
ret = strtol(nPtr1, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 2147483647, ret); /* 2147483647 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 2147483648 -2147483648 -2147483649", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 2147483647, ret); /* 2147483647 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -2147483648 -2147483649", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, -2147483648, ret); /* -2147483648 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -2147483649", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, -2147483648, ret); /* -2147483648 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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";
|
||||
char *endPtr = NULL;
|
||||
unsigned long ret = strtoul(nPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0110 0XDEFE 0666 4294967295 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 2); /* 2 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 6UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0XDEFE 0666 4294967295 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 16); /* 16 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0XDEFEUL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0666 4294967295 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 8); /* 8 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0666UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 4294967295 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 4294967295UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 4294967295UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 65); /* 65 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".34", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0110 0XDEFE 0666 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 2); /* 2 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 6ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0XDEFE 0666 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 16); /* 16 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0XDEFEULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0666 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 8); /* 8 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0666ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 65); /* 65 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 1ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".6", endPtr);
|
||||
|
||||
char nPtr1[] = "18446744073709551615 18446744073709551616";
|
||||
ret = strtoull(nPtr1, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 18446744073709551615ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 18446744073709551616", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 18446744073709551615ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoStdlibApiTestSuite);
|
||||
|
||||
void XtsIoStdlibFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrtof);
|
||||
RUN_ONE_TESTCASE(testStrtod);
|
||||
RUN_ONE_TESTCASE(testStrtold);
|
||||
RUN_ONE_TESTCASE(testStrtol);
|
||||
RUN_ONE_TESTCASE(testStrtoul);
|
||||
RUN_ONE_TESTCASE(testStrtoull);
|
||||
}
|
||||
374
testsuites/unittest/xts/io/xts_io_string_test.c
Normal file
374
testsuites/unittest/xts/io/xts_io_string_test.c
Normal file
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* 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_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoStringApi, IoStringApiTestSuite);
|
||||
|
||||
static BOOL IoStringApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoStringApiTestSuiteTearDown(void)
|
||||
{
|
||||
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");
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = strcmp("123456", "654321");
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
|
||||
ret = strcmp("~!@#$%^&*()_+", "~!@#$%^&*()_+");
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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); /* 1 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = strncmp("123456", "654321", 6); /* 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
|
||||
ret = strncmp("~!@#$%^&*()_+", "~!@#$%^&*()_+", 8); /* 8 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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}; /* 50 common data for test, no special meaning */
|
||||
char *ret = stpcpy(dest, src);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(dest, src, dest);
|
||||
|
||||
const char *srcT = "~!@#$%%^&*()_+";
|
||||
char destT[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
ret = stpcpy(destT, srcT);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(destT, srcT, destT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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}; /* 50 common data for test, no special meaning */
|
||||
char *ret = stpncpy(dest, src, 5); /* 5 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "", ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(dest, "hello", dest);
|
||||
|
||||
char srcT[] = "~!@#$%%^&*()_+";
|
||||
char destT[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
ret = stpncpy(destT, srcT, 15); /* 15 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "", ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(destT, "~!@#$%%^&*()_+", destT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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}; /* 20 common data for test, no special meaning */
|
||||
int ret = strcpy_s(dest, sizeof(dest), src);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
char srcT[] = "This is String1";
|
||||
char destT[20] = {0}; /* 20 common data for test, no special meaning */
|
||||
ret = strcpy_s(destT, sizeof(destT), srcT);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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[20] = {0};
|
||||
int ret = strncpy_s(dest, sizeof(dest), src, 6); /* 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
char destT[] = "~!@#$%^&*()_+";
|
||||
ret = strncpy_s(destT, sizeof(destT), "hello world", 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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}; /* 50 common data for test, no special meaning */
|
||||
int ret = strcat_s(dest, sizeof(dest), "hello world !");
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
char destT[50] = "hello world ! || "; /* 50 common data for test, no special meaning */
|
||||
ret = strcat_s(destT, sizeof(destT), "This is String1");
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 || "; /* 50 common data for test, no special meaning */
|
||||
int ret = strncat_s(dest, sizeof(dest), "This is String1", 7); /* 7 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
char destT[20] = "|/*"; /* 20 common data for test, no special meaning */
|
||||
ret = strncat_s(destT, sizeof(destT), "~!@#$%^&*()_+", 13); /* 13 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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, '!');
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "!! world", ret);
|
||||
|
||||
ret = strchr(src, '?');
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, NULL, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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, '&');
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "& WORLD", ret);
|
||||
|
||||
ret = strrchr(src, '?');
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, NULL, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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; /* 2 common data for test, no special meaning */
|
||||
unsigned int gtSrcSize = strlen(src) + 2; /* 2 common data for test, no special meaning */
|
||||
|
||||
size_t ret = strnlen(src, ltSrcSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ltSrcSize, ret);
|
||||
|
||||
ret = strnlen(src, gtSrcSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(src), ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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, "&");
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, src, ret);
|
||||
|
||||
ret = strtok(NULL, "-");
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, " This is", ret);
|
||||
|
||||
char srcS[] = "hello world !";
|
||||
ret = strtok(srcS, "?");
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, srcS, ret);
|
||||
|
||||
char srcT[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
ret = strtok(srcT, "~");
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, NULL, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, src, ret);
|
||||
|
||||
char srcS[] = "This is String1";
|
||||
ret = strdup(srcS);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "This is String1", ret);
|
||||
free(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12U, ret);
|
||||
|
||||
const char srcS[] = "a";
|
||||
ret = strcspn(dest, srcS);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 13U, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 5U, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 5U, ret);
|
||||
|
||||
const char destS[] = "this is string";
|
||||
const char srcS[] = "abc";
|
||||
ret = strspn(destS, srcS);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0U, ret);
|
||||
|
||||
const char srcT[] = "helo\0 wal";
|
||||
ret = strspn(dest, srcT);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 5U, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, NULL, ret);
|
||||
|
||||
const char destS[] = "string this is string";
|
||||
const char srcS[] = "string";
|
||||
ret = strstr(destS, srcS);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "string this is string", ret);
|
||||
|
||||
const char srcT[] = "\0hello";
|
||||
ret = strstr(dest, srcT);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "hello world !", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoStringApiTestSuite);
|
||||
|
||||
void XtsIoStringFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrcmp);
|
||||
RUN_ONE_TESTCASE(testStrncmp);
|
||||
RUN_ONE_TESTCASE(testStpcpy);
|
||||
RUN_ONE_TESTCASE(testStpncpy);
|
||||
RUN_ONE_TESTCASE(testStrcpy);
|
||||
RUN_ONE_TESTCASE(testStrncpy);
|
||||
RUN_ONE_TESTCASE(testStrcat);
|
||||
RUN_ONE_TESTCASE(testStrncat);
|
||||
RUN_ONE_TESTCASE(testStrchr);
|
||||
RUN_ONE_TESTCASE(testStrrchr);
|
||||
RUN_ONE_TESTCASE(testStrnlen);
|
||||
RUN_ONE_TESTCASE(testStrtok);
|
||||
RUN_ONE_TESTCASE(testStrdup);
|
||||
RUN_ONE_TESTCASE(testStrcspn);
|
||||
RUN_ONE_TESTCASE(testStrspn);
|
||||
RUN_ONE_TESTCASE(testStrstr);
|
||||
}
|
||||
87
testsuites/unittest/xts/io/xts_io_strings_test.c
Normal file
87
testsuites/unittest/xts/io/xts_io_strings_test.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoStringsApi, IoStringsApiTestSuite);
|
||||
|
||||
static BOOL IoStringsApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoStringsApiTestSuiteTearDown(void)
|
||||
{
|
||||
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); /* 7 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = strncasecmp("abcdefg", "abcdEF", 7); /* 7 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = strncasecmp("abcdef", "abcdEFg", 7); /* 7 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 | Level2)
|
||||
{
|
||||
int ret = strcasecmp("abcdefg", "abcdEFg");
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = strcasecmp("abcdefg", "abcdEF");
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = strcasecmp("abcdef", "abcdEFg");
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoStringsApiTestSuite);
|
||||
|
||||
void XtsIoStringsFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrncasecmp);
|
||||
RUN_ONE_TESTCASE(testStrcasecmp);
|
||||
}
|
||||
48
testsuites/unittest/xts/ipc/BUILD.gn
Normal file
48
testsuites/unittest/xts/ipc/BUILD.gn
Normal file
@@ -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.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
static_library("ipc_test") {
|
||||
sources = [
|
||||
"cond/pthread_cond_test.c",
|
||||
"msg_queue/mq_exp_test.c",
|
||||
"msg_queue/mq_test.c",
|
||||
"mutex/pthread_mutex_test.c",
|
||||
"semaphone/sem_abn_test.c",
|
||||
"semaphone/sem_test.c",
|
||||
"semaphone/sem_xts_test.c",
|
||||
"xts_ipc.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
196
testsuites/unittest/xts/ipc/cond/pthread_cond_test.c
Normal file
196
testsuites/unittest/xts/ipc/cond/pthread_cond_test.c
Normal file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* 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_ipc.h"
|
||||
|
||||
pthread_mutex_t g_mtx3 = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t g_cond3 = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
LITE_TEST_SUIT(FUTEX, PthreadCondApiTest, PthreadCondApiTestSuite);
|
||||
|
||||
static BOOL PthreadCondApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL PthreadCondApiTestSuiteTearDown(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
pthread_condattr_t condAttr;
|
||||
|
||||
ret = pthread_condattr_init(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond1;
|
||||
ret = pthread_cond_init(&cond1, &condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond2;
|
||||
ret = pthread_cond_init(&cond2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_condattr_t condAttr;
|
||||
ret = pthread_condattr_init(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond1;
|
||||
ret = pthread_cond_init(&cond1, &condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_cond_destroy(&cond1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond2;
|
||||
ret = pthread_cond_init(&cond2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_cond_destroy(&cond2);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond3 = PTHREAD_COND_INITIALIZER;
|
||||
ret = pthread_cond_destroy(&cond3);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_condattr_t condAttr;
|
||||
|
||||
ret = pthread_condattr_init(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_condattr_destroy(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_condattr_init(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// pthread_cond_broadcast
|
||||
void *ThreadPthreadCondBroadcast1(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int *testIntP = (int *)arg;
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
ret = pthread_mutex_lock(&g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
*testIntP = TEST_INTP_SIZE;
|
||||
ret = pthread_cond_broadcast(&g_cond3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
ret = pthread_mutex_unlock(&g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
return arg;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// pthread_cond_wait
|
||||
void *ThreadPthreadCondBroadcast2(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int *testIntP = (int *)arg;
|
||||
ret = pthread_mutex_lock(&g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
ret = pthread_cond_wait(&g_cond3, &g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
(*testIntP)++;
|
||||
ret = pthread_mutex_unlock(&g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
return arg;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid[3]; /* 3, common data for test, no special meaning */
|
||||
int testInt = 0;
|
||||
|
||||
ret = pthread_create(&tid[0], NULL, ThreadPthreadCondBroadcast1, (void*)&testInt);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_create(&tid[1], NULL, ThreadPthreadCondBroadcast2, (void*)&testInt); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_create(&tid[2], NULL, ThreadPthreadCondBroadcast2, (void*)&testInt); /* 2, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
usleep(100); /* 100, common data for test, no special meaning */
|
||||
int index = (int)(sizeof(tid) / sizeof(tid[0]));
|
||||
for (int i = 0; i < index; i++) {
|
||||
ret = pthread_join(tid[i], NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
EXIT:
|
||||
ret = pthread_cond_destroy(&g_cond3);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_mutex_destroy(&g_mtx3);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ICUNIT_ASSERT_EQUAL(testInt, TEST_SEEK_SIZE, testInt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(PthreadCondApiTestSuite);
|
||||
|
||||
void PosixFutexCondTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testPthreadCondInit);
|
||||
RUN_ONE_TESTCASE(testPthreadCondDestroy);
|
||||
RUN_ONE_TESTCASE(testPthreadCondattrInit);
|
||||
RUN_ONE_TESTCASE(testPthreadCondBroadcast);
|
||||
}
|
||||
670
testsuites/unittest/xts/ipc/msg_queue/mq_exp_test.c
Normal file
670
testsuites/unittest/xts/ipc/msg_queue/mq_exp_test.c
Normal file
@@ -0,0 +1,670 @@
|
||||
/*
|
||||
* 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_ipc.h"
|
||||
|
||||
LITE_TEST_SUIT(IPC, IpcMqExceptionApi, IpcMqExceptionApiTestSuite);
|
||||
|
||||
static BOOL IpcMqExceptionApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IpcMqExceptionApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @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, testMqReceiveEBADFEMSGSIZE001, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
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];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEAGAIN_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_receive(NULL, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_receive(queue, rMsgErr, sizeof(rMsgErr), &prio);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EMSGSIZE, errno);
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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, testMqReceiveEBADFEMSGSIZE002, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
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];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEAGAIN_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
attr.mq_flags |= O_NONBLOCK;
|
||||
ret = mq_setattr(queue, &attr, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
unsigned int prio;
|
||||
struct mq_attr attr = { 0 };
|
||||
char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEINVAL_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = mq_receive(queue, rMsg, 0, &prio);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
struct timespec ts = { 0, 0 };
|
||||
struct mq_attr attr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqTimedSendEAGAIN_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
attr.mq_msgsize = MQ_MSG_SIZE;
|
||||
attr.mq_maxmsg = 1; /* 1, common data for test, no special meaning */
|
||||
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EAGAIN, errno);
|
||||
ret = mq_timedsend(NULL, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
|
||||
attr.mq_flags |= O_NONBLOCK;
|
||||
ret = mq_setattr(queue, &attr, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
struct timespec ts = { 0, 0 };
|
||||
struct mq_attr attr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqTimedSendEINVAL_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
for (int i = 0; i < 3; i++) { /* 3, common data for test, no special meaning */
|
||||
switch (i) {
|
||||
case 0:
|
||||
ts.tv_sec = -1; /* -1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 0;
|
||||
break;
|
||||
case 1:
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = -1; /* -1, common data for test, no special meaning */
|
||||
break;
|
||||
case 2:
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 1000000000UL + 1UL;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
}
|
||||
ret = mq_timedsend(queue, MQ_MSG, 0, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
struct timespec ts = { 0, 0 };
|
||||
struct mq_attr attr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqTimedSendEMSGSIZE_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
attr.mq_msgsize = 1; /* 1, common data for test, no special meaning */
|
||||
attr.mq_maxmsg = MQ_MAX_MSG;
|
||||
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EMSGSIZE, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
struct timespec ts = { 0, 0 };
|
||||
struct mq_attr attr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqTimedSendETIMEDOUT_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
attr.mq_msgsize = MQ_MSG_SIZE;
|
||||
attr.mq_maxmsg = 1; /* 1, common data for test, no special meaning */
|
||||
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 100; /* 100, common data for test, no special meaning */
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, ETIMEDOUT, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
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];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqTimedReceiveEAGAIN_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 0;
|
||||
ret = mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EAGAIN, errno);
|
||||
ret = mq_timedreceive(NULL, rMsg, getAttr.mq_msgsize, &prio, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = mq_timedreceive(NULL, rMsg, getAttr.mq_msgsize, &prio, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
|
||||
attr.mq_flags |= O_NONBLOCK;
|
||||
ret = mq_setattr(queue, &attr, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_timedreceive(NULL, rMsg, getAttr.mq_msgsize, &prio, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
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];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqTimedReceiveEINVAL_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
for (int i = 0; i < 3; i++) { /* 3, common data for test, no special meaning */
|
||||
switch (i) {
|
||||
case 0:
|
||||
ts.tv_sec = -1; /* -1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 0;
|
||||
break;
|
||||
case 1:
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = -1; /* -1, common data for test, no special meaning */
|
||||
break;
|
||||
case 2:
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 1000000000UL + 1UL;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
}
|
||||
ret = mq_timedreceive(queue, rMsg, 0, &prio, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
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];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqTimedReceiveETIMEDOUT_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 100; /* 100, common data for test, no special meaning */
|
||||
ret = mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, ETIMEDOUT, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
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];
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqTimedReceiveEMSGSIZE_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
ts.tv_nsec = 0;
|
||||
ret = mq_timedreceive(queue, rMsg, 1, &prio, &ts); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EMSGSIZE, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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]; /* 10, common data for test, no special meaning */
|
||||
int i;
|
||||
for (i = 0; i < MAX_MQ_NAME_LEN + 5; i++) { /* 5, common data for test, no special meaning */
|
||||
qName[i] = '8';
|
||||
}
|
||||
qName[i] = '\0';
|
||||
int ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENAMETOOLONG, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @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"; /* 64, common data for test, no special meaning */
|
||||
int ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @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)
|
||||
{
|
||||
int ret = mq_unlink("");
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @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));
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqSendEINVAL_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, NULL);
|
||||
|
||||
ret = mq_getattr(NULL, &mqstat);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
|
||||
ret = mq_getattr(queue, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
char qName[MQ_NAME_LEN];
|
||||
mqd_t queue;
|
||||
struct mq_attr gMqstat = { 0 }, sMqstat = { 0 };
|
||||
|
||||
ret = sprintf_s(qName, MQ_NAME_LEN, "testMqSetAttrEBADFEINVAL_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
memset_s(&gMqstat, sizeof(gMqstat), 0, sizeof(gMqstat));
|
||||
memset_s(&sMqstat, sizeof(sMqstat), 0, sizeof(sMqstat));
|
||||
ret = mq_getattr(queue, &gMqstat);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
sMqstat.mq_flags |= O_NONBLOCK;
|
||||
ret = mq_setattr(queue, &sMqstat, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_getattr(queue, &gMqstat);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(gMqstat.mq_flags, sMqstat.mq_flags, gMqstat.mq_flags);
|
||||
|
||||
ret = mq_setattr(NULL, &sMqstat, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EBADF, errno);
|
||||
ret = mq_setattr(queue, NULL, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IpcMqExceptionApiTestSuite);
|
||||
|
||||
void IpcMqExceptionFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testMqReceiveEBADFEMSGSIZE001);
|
||||
RUN_ONE_TESTCASE(testMqReceiveEBADFEMSGSIZE002);
|
||||
RUN_ONE_TESTCASE(testMqReceiveEINVAL);
|
||||
RUN_ONE_TESTCASE(testMqTimedSendEAGAINEBADF);
|
||||
RUN_ONE_TESTCASE(testMqTimedSendEINVAL);
|
||||
RUN_ONE_TESTCASE(testMqTimedSendEMSGSIZE);
|
||||
RUN_ONE_TESTCASE(testMqTimedSendETIMEDOUT);
|
||||
RUN_ONE_TESTCASE(testMqTimedReceiveEAGAINEBADF);
|
||||
RUN_ONE_TESTCASE(testMqTimedReceiveEINVAL);
|
||||
RUN_ONE_TESTCASE(testMqTimedReceiveETIMEDOUT);
|
||||
RUN_ONE_TESTCASE(testMqTimedReceiveEMSGSIZE);
|
||||
RUN_ONE_TESTCASE(testMqUnlinkENAMETOOLONG);
|
||||
RUN_ONE_TESTCASE(testMqUnlinkENOENT);
|
||||
RUN_ONE_TESTCASE(testMqUnlinkEINVAL);
|
||||
RUN_ONE_TESTCASE(testMqGetAttrEBADFEINVAL);
|
||||
RUN_ONE_TESTCASE(testMqSetAttrEBADFEINVAL);
|
||||
}
|
||||
511
testsuites/unittest/xts/ipc/msg_queue/mq_test.c
Normal file
511
testsuites/unittest/xts/ipc/msg_queue/mq_test.c
Normal file
@@ -0,0 +1,511 @@
|
||||
/*
|
||||
* 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_ipc.h"
|
||||
|
||||
LITE_TEST_SUIT(IPC, IpcMqApi, IpcMqApiTestSuite);
|
||||
|
||||
static BOOL IpcMqApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IpcMqApiTestSuiteTearDown(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
unsigned int prio;
|
||||
struct mq_attr getAttr = { 0 };
|
||||
struct mq_attr setAttr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
ret = sprintf_s(qName, sizeof(qName), "testMqOneLevelCom_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_msgsize, MQ_MSG_SIZE, getAttr.mq_msgsize);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_maxmsg, MQ_MAX_MSG, getAttr.mq_maxmsg);
|
||||
|
||||
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(prio, 0, prio);
|
||||
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
unsigned int prio;
|
||||
struct timespec tts = { 0 };
|
||||
struct timespec rts = { 0 };
|
||||
struct mq_attr getAttr = { 0 };
|
||||
struct mq_attr setAttr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
ret = sprintf_s(qName, sizeof(qName), "testMqTimedOneLevelCom_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
tts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
tts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_msgsize, MQ_MSG_SIZE, getAttr.mq_msgsize);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_maxmsg, MQ_MAX_MSG, getAttr.mq_maxmsg);
|
||||
|
||||
rts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
rts.tv_nsec = 0;
|
||||
ret = mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(prio, 0, prio);
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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, testMqAllOneLevelCom001, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
unsigned int prio;
|
||||
struct mq_attr getAttr = { 0 };
|
||||
struct mq_attr setAttr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
ret = sprintf_s(qName, sizeof(qName), "testMqAllOneLevelCom_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
ret = mq_getattr(queue, &setAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
setAttr.mq_msgsize = MQ_MSG_SIZE;
|
||||
setAttr.mq_maxmsg = MQ_MAX_MSG;
|
||||
ret = mq_setattr(queue, &setAttr, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_msgsize, setAttr.mq_msgsize, getAttr.mq_msgsize);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_maxmsg, setAttr.mq_maxmsg, getAttr.mq_maxmsg);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_curmsgs, 1, getAttr.mq_curmsgs); /* 1, common data for test, no special meaning */
|
||||
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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, testMqAllOneLevelCom002, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
unsigned int prio;
|
||||
struct timespec tts = { 0 };
|
||||
struct timespec rts = { 0 };
|
||||
struct mq_attr getAttr = { 0 };
|
||||
struct mq_attr setAttr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
ret = sprintf_s(qName, sizeof(qName), "testMqAllOneLevelCom_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
|
||||
tts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
tts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_msgsize, setAttr.mq_msgsize, getAttr.mq_msgsize);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_maxmsg, setAttr.mq_maxmsg, getAttr.mq_maxmsg);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_curmsgs, 1, getAttr.mq_curmsgs); /* 1, common data for test, no special meaning */
|
||||
|
||||
rts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
rts.tv_nsec = 0;
|
||||
ret = mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *PthreadCom(void *arg)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
unsigned int prio;
|
||||
struct mq_attr getAttr = { 0 };
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
queue = (mqd_t)arg;
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(prio, MQ_MSG_PRIO, prio);
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
pthread_t tid;
|
||||
unsigned int prio;
|
||||
struct mq_attr getAttr = { 0 };
|
||||
struct mq_attr setAttr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
ret = sprintf_s(qName, sizeof(qName), "testMqTwoLevelCom_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = pthread_create(&tid, NULL, PthreadCom, (void *)queue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_curmsgs, 1, getAttr.mq_curmsgs); /* 1, common data for test, no special meaning */
|
||||
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(prio, MQ_MSG_PRIO, prio);
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *PthreadTimedCom(void *arg)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
unsigned int prio;
|
||||
struct timespec tts = { 0 };
|
||||
struct timespec rts = { 0 };
|
||||
struct mq_attr getAttr = { 0 };
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
queue = (mqd_t)arg;
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
rts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
rts.tv_nsec = 0;
|
||||
ret = mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(prio, MQ_MSG_PRIO, prio);
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
tts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
tts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
pthread_t tid;
|
||||
unsigned int prio;
|
||||
struct timespec tts = { 0 };
|
||||
struct timespec rts = { 0 };
|
||||
struct mq_attr getAttr = { 0 };
|
||||
struct mq_attr setAttr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
char rMsg[MQ_RX_LEN];
|
||||
ret = sprintf_s(qName, sizeof(qName), "testMqTimedTwoThreadCom_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = pthread_create(&tid, NULL, PthreadTimedCom, (void *)queue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
tts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
tts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_curmsgs, 1, getAttr.mq_curmsgs); /* 1, common data for test, no special meaning */
|
||||
rts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
rts.tv_nsec = 0;
|
||||
ret = mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(prio, MQ_MSG_PRIO, prio);
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *PthreadAllCom(void *arg)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
unsigned int prio;
|
||||
struct timespec tts = { 0 };
|
||||
struct timespec rts = { 0 };
|
||||
struct mq_attr getAttr = { 0 };
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
queue = (mqd_t)arg;
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
rts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
rts.tv_nsec = 0;
|
||||
ret = mq_timedreceive(queue, rMsg, getAttr.mq_msgsize, &prio, &rts);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(prio, MQ_MSG_PRIO, prio);
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
tts.tv_sec = time(NULL) + 1; /* 1, common data for test, no special meaning */
|
||||
tts.tv_nsec = 0;
|
||||
ret = mq_timedsend(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO, &tts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
pthread_t tid;
|
||||
unsigned int prio;
|
||||
struct mq_attr getAttr = { 0 };
|
||||
struct mq_attr setAttr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
char rMsg[MQ_RX_LEN];
|
||||
|
||||
ret = sprintf_s(qName, sizeof(qName), "testMqAllTwoThreadCom_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = pthread_create(&tid, NULL, PthreadAllCom, (void *)queue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(getAttr.mq_curmsgs, 1, getAttr.mq_curmsgs); /* 1, common data for test, no special meaning */
|
||||
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(prio, MQ_MSG_PRIO, prio);
|
||||
ret = strncmp(MQ_MSG, rMsg, MQ_MSG_LEN);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
mqd_t queue;
|
||||
struct mq_attr getAttr = { 0 };
|
||||
struct mq_attr setAttr = { 0 };
|
||||
char qName[MQ_NAME_LEN];
|
||||
|
||||
ret = sprintf_s(qName, sizeof(qName), "testMqFunction_%d", GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(qName), ret);
|
||||
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);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(queue, (mqd_t)-1, queue); /* -1, common data for test, no special meaning */
|
||||
|
||||
memset_s(&getAttr, sizeof(getAttr), 0, sizeof(getAttr));
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = (getAttr.mq_flags & O_NONBLOCK);
|
||||
ICUNIT_ASSERT_EQUAL(ret, O_NONBLOCK, ret);
|
||||
|
||||
setAttr.mq_flags &= ~O_NONBLOCK;
|
||||
ret = mq_setattr(queue, &setAttr, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = mq_getattr(queue, &getAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = (getAttr.mq_flags & O_NONBLOCK);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_close(queue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = mq_unlink(qName);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IpcMqApiTestSuite);
|
||||
|
||||
void IpcMqFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testMqOneLevelCom);
|
||||
RUN_ONE_TESTCASE(testMqTimedOneLevelCom);
|
||||
RUN_ONE_TESTCASE(testMqAllOneLevelCom001);
|
||||
RUN_ONE_TESTCASE(testMqAllOneLevelCom002);
|
||||
RUN_ONE_TESTCASE(testMqTwoThreadCom);
|
||||
RUN_ONE_TESTCASE(testMqTimedTwoThreadCom);
|
||||
RUN_ONE_TESTCASE(testMqAllTwoThreadCom);
|
||||
RUN_ONE_TESTCASE(testMqSetGetAttr);
|
||||
}
|
||||
139
testsuites/unittest/xts/ipc/mutex/pthread_mutex_test.c
Normal file
139
testsuites/unittest/xts/ipc/mutex/pthread_mutex_test.c
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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_ipc.h"
|
||||
|
||||
LITE_TEST_SUIT(FUTEX, PthreadMutexApiTest, PthreadMutexApiTestSuite);
|
||||
|
||||
static BOOL PthreadMutexApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL PthreadMutexApiTestSuiteTearDown(void)
|
||||
{
|
||||
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 *PthreadProduce(void *arg)
|
||||
{
|
||||
int ret;
|
||||
for (int i = 0; i < g_st1.loopNum; i++) {
|
||||
ret = pthread_mutex_lock(&g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
// check full
|
||||
if ((g_st1.top + 1) % g_st1.countMax == g_st1.bottom) { /* 1, common data for test, no special meaning */
|
||||
ret = pthread_cond_wait(&g_st1.notempty, &g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
}
|
||||
// Produce
|
||||
g_st1.top = (g_st1.top + 1) % g_st1.countMax; /* 1, common data for test, no special meaning */
|
||||
g_st1.count++;
|
||||
|
||||
ret = pthread_cond_signal(&g_st1.notempty);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_mutex_unlock(&g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
usleep(10); /* 10, common data for test, no special meaning */
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
void *PthreadConsume(void *arg)
|
||||
{
|
||||
int ret;
|
||||
for (int i = 0; i < g_st1.loopNum; i++) {
|
||||
ret = pthread_mutex_lock(&g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
// check empty
|
||||
if (g_st1.top == g_st1.bottom) {
|
||||
ret = pthread_cond_wait(&g_st1.notempty, &g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
}
|
||||
// Consume
|
||||
g_st1.bottom = (g_st1.bottom + 1) % g_st1.countMax;
|
||||
g_st1.count--;
|
||||
|
||||
ret = pthread_cond_signal(&g_st1.notempty);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_mutex_unlock(&g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
usleep(10); /* 10, common data for test, no special meaning */
|
||||
}
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid[2]; /* 2, common data for test, no special meaning */
|
||||
|
||||
g_st1.count = 0;
|
||||
memset_s(tid, sizeof(tid), POSIX_IPC_NO_ERROR, sizeof(tid));
|
||||
|
||||
ret = pthread_create(&tid[0], NULL, PthreadProduce, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_create(&tid[1], NULL, PthreadConsume, NULL); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_join(tid[0], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_join(tid[1], NULL); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_st1.count, POSIX_IPC_NO_ERROR, g_st1.count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(PthreadMutexApiTestSuite);
|
||||
|
||||
void PosixFutexMutexTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testPthreadMutexCond);
|
||||
}
|
||||
195
testsuites/unittest/xts/ipc/semaphone/sem_abn_test.c
Normal file
195
testsuites/unittest/xts/ipc/semaphone/sem_abn_test.c
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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_ipc.h"
|
||||
|
||||
LITE_TEST_SUIT(IPC, SemAbnormalTestSuite, SemAbnormalTestSuite);
|
||||
|
||||
static BOOL SemAbnormalTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL SemAbnormalTestSuiteTearDown(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, SEM_VALUE_MAX);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(SEM_VALUE_MAX, semValue, SEM_VALUE_MAX);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
unsigned int gtSemMax = (unsigned int)SEM_VALUE_MAX + 1; /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_init(&sem, 0, gtSemMax);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
EXIT:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, 1); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, SEM_VALUE_MAX);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EOVERFLOW, errno, EXIT); /* -1, common data for test, no special meaning */
|
||||
|
||||
EXIT:
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts = {0};
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = time(NULL);
|
||||
ts.tv_nsec = -2; /* -2, common data for test, no special meaning */
|
||||
ret = sem_timedwait(&sem, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts = {0};
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = time(NULL);
|
||||
ts.tv_nsec = KERNEL_NS_PER_SECOND;
|
||||
ret = sem_timedwait(&sem, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
EXIT:
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(SemAbnormalTestSuite);
|
||||
|
||||
void PosixSemAbnFuncTest()
|
||||
{
|
||||
RUN_ONE_TESTCASE(testSemInitAbnormalSemvaluemax);
|
||||
RUN_ONE_TESTCASE(testSemInitAbnormalInitTwice);
|
||||
RUN_ONE_TESTCASE(testSemTimedwaitAbnormalA);
|
||||
RUN_ONE_TESTCASE(testSemTimedwaitAbnormalB);
|
||||
}
|
||||
356
testsuites/unittest/xts/ipc/semaphone/sem_test.c
Normal file
356
testsuites/unittest/xts/ipc/semaphone/sem_test.c
Normal file
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* 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_ipc.h"
|
||||
|
||||
static int g_semTestStep = 0;
|
||||
|
||||
LITE_TEST_SUIT(IPC, SemApi, IpcSemApiTestSuite);
|
||||
|
||||
static BOOL IpcSemApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IpcSemApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemInit0100, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int testValue[3] = {0, 1, 10}; /* 3, 1, 10 common data for test, no special meaning */
|
||||
|
||||
int index = (int)(sizeof(testValue) / sizeof(int));
|
||||
for (int i = 0; i < index; i++) {
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, testValue[0]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemPost0100, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemWait0100, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, 3); /* 3, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *ThreadChat(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t *)arg;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 0, g_semTestStep);
|
||||
|
||||
g_semTestStep = 1; /* 1, common data for test, no special meaning */
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_semTestStep = 2; /* 2, common data for test, no special meaning */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testThreadChat0100, Function | MediumTest | Level3)
|
||||
{
|
||||
pthread_t tid;
|
||||
sem_t sem;
|
||||
int ret;
|
||||
struct timespec req;
|
||||
g_semTestStep = 0;
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid, NULL, ThreadChat, (void *)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
req.tv_sec = 0;
|
||||
req.tv_nsec = TEN_CONT * NANO_MS;
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 1, g_semTestStep); /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 2, g_semTestStep); /* 2, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 2, g_semTestStep); /* 2, common data for test, no special meaning */
|
||||
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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;
|
||||
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
g_semTestStep = 1; /* 1, common data for test, no special meaning */
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_semTestStep = 2; /* 2, common data for test, no special meaning */
|
||||
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; /* 300, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
g_semTestStep = 3; /* 3, common data for test, no special meaning */
|
||||
|
||||
req.tv_nsec = 200 * NANO_MS; /* 200, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_semTestStep = 4; /* 4, common data for test, no special meaning */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testThreadChat0400, Function | MediumTest | Level4)
|
||||
{
|
||||
pthread_t tid1;
|
||||
pthread_t tid2;
|
||||
sem_t sem;
|
||||
int ret;
|
||||
struct timespec req;
|
||||
|
||||
req.tv_sec = 0;
|
||||
req.tv_nsec = 200 * NANO_MS; /* 200, common data for test, no special meaning */
|
||||
g_semTestStep = 0;
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid1, NULL, ThreadNThreadWait1, (void *)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid2, NULL, ThreadNThreadWait2, (void *)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 1, g_semTestStep); /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
req.tv_nsec = 20 * NANO_MS; /* 20, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 2, g_semTestStep); /* 2, common data for test, no special meaning */
|
||||
|
||||
req.tv_nsec = 200 * NANO_MS; /* 200, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 3, g_semTestStep); /* 3, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
req.tv_nsec = 20 * NANO_MS; /* 20, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 3, g_semTestStep); /* 3, common data for test, no special meaning */
|
||||
|
||||
ret = pthread_join(tid1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(tid2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 4, g_semTestStep); /* 4, common data for test, no special meaning */
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemInitAbnormal0200, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
unsigned int gtSemMax = (unsigned int)SEM_VALUE_MAX + 1; /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_init(&sem, 0, SEM_VALUE_MAX);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_init(&sem, 0, gtSemMax);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = sem_init(&sem, 0, 1); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemPostAbnormal, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, SEM_VALUE_MAX);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemTimedWaitAbnormalA, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = -2; /* -2, common data for test, no special meaning */
|
||||
ret = sem_timedwait(&sem, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemTimedWaitAbnormalB, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = time(NULL);
|
||||
ts.tv_nsec = NANO_S;
|
||||
ret = sem_timedwait(&sem, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IpcSemApiTestSuite);
|
||||
|
||||
void PosixSemFuncTest()
|
||||
{
|
||||
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);
|
||||
}
|
||||
436
testsuites/unittest/xts/ipc/semaphone/sem_xts_test.c
Normal file
436
testsuites/unittest/xts/ipc/semaphone/sem_xts_test.c
Normal file
@@ -0,0 +1,436 @@
|
||||
/*
|
||||
* 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_ipc.h"
|
||||
|
||||
LITE_TEST_SUIT(IPC, SemApi, IpcSemApiXtsTestSuite);
|
||||
|
||||
static BOOL IpcSemApiXtsTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IpcSemApiXtsTestSuiteTearDown(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
int testValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, testValue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(semValue, testValue, semValue);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
int testValue = 1; /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_init(&sem, 0, testValue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(semValue, testValue, semValue);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
int testValue = 10; /* 10, common data for test, no special meaning */
|
||||
|
||||
ret = sem_init(&sem, 0, testValue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(semValue, testValue, semValue);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 3, semValue); /* 3, common data for test, no special meaning */
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, 3); /* 3, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 3, semValue); /* 3, common data for test, no special meaning */
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 2, semValue); /* 2, common data for test, no special meaning */
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *ThreadChatF01(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t*)arg;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
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;
|
||||
int semValue = 0;
|
||||
|
||||
reInt = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
reInt = pthread_create(&tid, NULL, ThreadChatF01, (void*)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
reInt = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
reInt = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
|
||||
reInt = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
reInt = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *ThreadSemTimedWait(void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts = {0};
|
||||
sem_t *sem = (sem_t*)arg;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
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;
|
||||
usleep(50); /* 50, common data for test, no special meaning */
|
||||
ret = sem_timedwait(sem, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(100); /* 100, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
sem_t sem;
|
||||
int reInt;
|
||||
int semValue = 0;
|
||||
|
||||
reInt = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
reInt = pthread_create(&tid, NULL, ThreadSemTimedWait, (void*)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(10); /* 10, common data for test, no special meaning */
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
reInt = pthread_join(tid, NULL);
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *ThreadNThreadWaitF01(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t*)arg;
|
||||
int semValue = 0;
|
||||
|
||||
usleep(100); /* 100, common data for test, no special meaning */
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ThreadNThreadWaitF02(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t*)arg;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
usleep(300); /* 300, common data for test, no special meaning */
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
usleep(200); /* 200, common data for test, no special meaning */
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
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;
|
||||
int semValue = 0;
|
||||
|
||||
reInt = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
reInt = pthread_create(&tid1, NULL, ThreadNThreadWaitF01, (void*)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
reInt = pthread_create(&tid2, NULL, ThreadNThreadWaitF02, (void*)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(200); /* 200, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
reInt = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
usleep(200); /* 200, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
reInt = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
|
||||
reInt = pthread_join(tid1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
reInt = pthread_join(tid2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
reInt = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IpcSemApiXtsTestSuite);
|
||||
|
||||
void PosixSemXtsFuncTest()
|
||||
{
|
||||
RUN_ONE_TESTCASE(testSemInitA);
|
||||
RUN_ONE_TESTCASE(testSemInitB);
|
||||
RUN_ONE_TESTCASE(testSemInitC);
|
||||
RUN_ONE_TESTCASE(testSemPost);
|
||||
RUN_ONE_TESTCASE(testSemWait);
|
||||
RUN_ONE_TESTCASE(testSemdestroy);
|
||||
RUN_ONE_TESTCASE(testThreadChat);
|
||||
}
|
||||
42
testsuites/unittest/xts/ipc/xts_ipc.c
Normal file
42
testsuites/unittest/xts/ipc/xts_ipc.c
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
#include "xts_test.h"
|
||||
|
||||
void IpcSemApiTest(void)
|
||||
{
|
||||
PosixFutexCondTest();
|
||||
PosixFutexMutexTest();
|
||||
IpcMqExceptionFuncTest();
|
||||
IpcMqFuncTest();
|
||||
PosixSemFuncTest();
|
||||
PosixSemAbnFuncTest();
|
||||
PosixSemXtsFuncTest();
|
||||
}
|
||||
81
testsuites/unittest/xts/ipc/xts_ipc.h
Normal file
81
testsuites/unittest/xts/ipc/xts_ipc.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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_IPC_H
|
||||
#define XTS_IPC_H
|
||||
|
||||
#include "xts_test.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <securec.h>
|
||||
#include <semaphore.h>
|
||||
#include <sys/resource.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <mqueue.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#define NANO_S 1000000000
|
||||
#define NANO_MS 1000000
|
||||
#define TEN_CONT 10
|
||||
#define FIFTY_CONT 50
|
||||
#define HUNDRED_CONT 100
|
||||
#define TEST_INTP_SIZE 10
|
||||
#define TEST_SEEK_SIZE 12
|
||||
#define POSIX_IPC_NO_ERROR 0
|
||||
#define KERNEL_NS_PER_SECOND 1000000000
|
||||
#define SEM_VALUE_MAX 0xFFFE
|
||||
#define KERNEL_NS_PER_SECOND 1000000000
|
||||
#define KERNEL_100MS_BY_NS 100000000
|
||||
#define MQ_NAME_LEN 64
|
||||
#define MQ_TX_LEN 64
|
||||
#define MQ_RX_LEN 64
|
||||
#define MQ_MSG_SIZE 64
|
||||
#define MQ_MSG_PRIO 0
|
||||
#define MQ_MAX_MSG 16
|
||||
#define MQ_MAX_QN_LEN 24
|
||||
#define MAX_SIGNAL_NUMBER 64
|
||||
#define MAX_PIPE_BUFFER 1023
|
||||
#define MAX_PIPE_NUMBER 32
|
||||
#define MAX_MQ_NUMBER LOSCFG_BASE_IPC_QUEUE_LIMIT
|
||||
#define MAX_MQ_NAME_LEN 2560
|
||||
#define MAX_MQ_MSG_SIZE 65530
|
||||
#define MQ_MSG "MessageToSend"
|
||||
#define MQ_MSG_LEN sizeof(MQ_MSG)
|
||||
|
||||
#endif
|
||||
43
testsuites/unittest/xts/math/BUILD.gn
Normal file
43
testsuites/unittest/xts/math/BUILD.gn
Normal file
@@ -0,0 +1,43 @@
|
||||
# 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("math_test") {
|
||||
sources = [
|
||||
"math_api_test.c",
|
||||
"math_std_api_test.c",
|
||||
"xts_math.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
68
testsuites/unittest/xts/math/math_api_test.c
Normal file
68
testsuites/unittest/xts/math/math_api_test.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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_math.h"
|
||||
|
||||
LITE_TEST_SUIT(MATH, MathApi, MathApiTestSuite);
|
||||
|
||||
static BOOL MathApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MathApiTestSuiteTearDown(void)
|
||||
{
|
||||
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; /* 3 common data for test, no special meaning */
|
||||
float testValues[] = {3.000001, -3.000001, 0.0}; /* 3.000001, -3.000001 common data for test, no special meaning */
|
||||
float expected[] = {0, 1, 0}; /* 1 common data for test, no special meaning */
|
||||
float ret;
|
||||
for (int i = 0; i < testCount; ++i) {
|
||||
ret = signbit(testValues[i]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, expected[i], ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(MathApiTestSuite);
|
||||
|
||||
void MathApiTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testsignbit);
|
||||
}
|
||||
88
testsuites/unittest/xts/math/math_std_api_test.c
Normal file
88
testsuites/unittest/xts/math/math_std_api_test.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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_math.h"
|
||||
|
||||
LITE_TEST_SUIT(MATH, MathStdApi, MathStdApiTestSuite);
|
||||
|
||||
static BOOL MathStdApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MathStdApiTestSuiteTearDown(void)
|
||||
{
|
||||
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; /* 3 common data for test, no special meaning */
|
||||
int testValues[] = {-3, 0, 3}; /* -3, 3 common data for test, no special meaning */
|
||||
int expected[] = {3, 0, 3}; /* 3 common data for test, no special meaning */
|
||||
int ret;
|
||||
for (int i = 0; i < testCount; ++i) {
|
||||
ret = abs(testValues[i]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, expected[i], ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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; /* 3 common data for test, no special meaning */
|
||||
intmax_t testValues[] = {2147483649, -2147483649, 0}; /* 2147483649, -2147483649 common data for test, no special meaning */
|
||||
intmax_t expected[] = {2147483649, 2147483649, 0}; /* 2147483649, common data for test, no special meaning */
|
||||
|
||||
long long ret;
|
||||
for (int i = 0; i < testCount; ++i) {
|
||||
ret = llabs(testValues[i]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, expected[i], ret);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(MathStdApiTestSuite);
|
||||
|
||||
void MathStdApiTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testAbs);
|
||||
RUN_ONE_TESTCASE(testllabs);
|
||||
}
|
||||
37
testsuites/unittest/xts/math/xts_math.c
Normal file
37
testsuites/unittest/xts/math/xts_math.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 MathFuncTest(void)
|
||||
{
|
||||
MathApiTest();
|
||||
MathStdApiTest();
|
||||
}
|
||||
42
testsuites/unittest/xts/math/xts_math.h
Normal file
42
testsuites/unittest/xts/math/xts_math.h
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef XTS_MATH_H
|
||||
#define XTS_MATH_H
|
||||
|
||||
#include "xts_test.h"
|
||||
#include <float.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
#endif
|
||||
43
testsuites/unittest/xts/mem/BUILD.gn
Normal file
43
testsuites/unittest/xts/mem/BUILD.gn
Normal file
@@ -0,0 +1,43 @@
|
||||
# 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("mem_test") {
|
||||
sources = [
|
||||
"acts_mem_api_test.c",
|
||||
"mem_api_test.c",
|
||||
"xts_mem.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
89
testsuites/unittest/xts/mem/acts_mem_api_test.c
Normal file
89
testsuites/unittest/xts/mem/acts_mem_api_test.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
LITE_TEST_SUIT(MEM, ActsMemApi, ActsMemApiTestSuite);
|
||||
|
||||
static BOOL ActsMemApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL ActsMemApiTestSuiteTearDown(void)
|
||||
{
|
||||
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 = (char *)memchr(srcStr, 'a', 14); /* 14, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(pos, (char *)"a;", pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = (char *)memchr(srcStr, 'a', 4); /* 4, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(pos, 0, pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 = (char *)memchr(srcStr, 'b', 14); /* 14, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(pos, 0, pos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(ActsMemApiTestSuite);
|
||||
|
||||
void ActsMemApiTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testMemchr_0100);
|
||||
RUN_ONE_TESTCASE(testMemchr_1000);
|
||||
RUN_ONE_TESTCASE(testMemchr_1100);
|
||||
}
|
||||
|
||||
201
testsuites/unittest/xts/mem/mem_api_test.c
Normal file
201
testsuites/unittest/xts/mem/mem_api_test.c
Normal file
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
LITE_TEST_SUIT(MEM, MemApi, MemApiTestSuite);
|
||||
|
||||
static BOOL MemApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL MemApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_MEM_MEMSET_0100
|
||||
* @tc.name memset function set buffer value test
|
||||
* @tc.desc [C-L*-311]
|
||||
*/
|
||||
LITE_TEST_CASE(MemApiTestSuite, testMemset, Function | MediumTest | Level1)
|
||||
{
|
||||
char chr = 'A';
|
||||
int i, len, failure;
|
||||
len = GetRandom(1024); /* 1024, common data for test, no special meaning */
|
||||
errno_t err = EOK;
|
||||
|
||||
char buf[1024]; /* 1024, common data for test, no special meaning */
|
||||
err = memset_s(buf, sizeof(buf), chr, len);
|
||||
ICUNIT_ASSERT_EQUAL(err, 0, err);
|
||||
failure = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (buf[i] != chr) {
|
||||
failure = 1; /* 1, common data for test, no special meaning */
|
||||
break;
|
||||
}
|
||||
}
|
||||
ICUNIT_ASSERT_EQUAL(failure, 0, failure);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_MEM_MEMCPY_0100
|
||||
* @tc.name memcpy function copy buffer test
|
||||
* @tc.desc [C-L*-311]
|
||||
*/
|
||||
LITE_TEST_CASE(MemApiTestSuite, testMemcpy, Function | MediumTest | Level2)
|
||||
{
|
||||
char chr = 'A';
|
||||
int i, len, failure;
|
||||
char src[1024]; /* 1024, common data for test, no special meaning */
|
||||
char dst[1024]; /* 1024, common data for test, no special meaning */
|
||||
|
||||
len = GetRandom(1024); /* 1024, common data for test, no special meaning */
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
src[i] = chr + i % 26; /* 26, common data for test, no special meaning */
|
||||
}
|
||||
|
||||
errno_t err = memcpy_s(dst, sizeof(dst) / sizeof(dst[0]), src, len);
|
||||
ICUNIT_ASSERT_EQUAL(err, 0, err);
|
||||
failure = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (dst[i] != src[i]) {
|
||||
failure = 1; /* 1, common data for test, no special meaning */
|
||||
break;
|
||||
}
|
||||
}
|
||||
ICUNIT_ASSERT_EQUAL(failure, 0, failure);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_MEM_MEMMOVE_0100
|
||||
* @tc.name memmove function move buffer test
|
||||
* @tc.desc [C-L*-311]
|
||||
*/
|
||||
LITE_TEST_CASE(MemApiTestSuite, testMemmove, Function | MediumTest | Level2)
|
||||
{
|
||||
char chr = 'A';
|
||||
char buf[1024]; /* 1024, common data for test, no special meaning */
|
||||
int i, len, failure;
|
||||
|
||||
len = sizeof(buf);
|
||||
for (i = 0; i < len; i++) {
|
||||
buf[i] = chr + GetRandom(26); /* 26, common data for test, no special meaning */
|
||||
}
|
||||
errno_t err = memmove_s(&buf[0], sizeof(buf) / sizeof(buf[0]), &buf[len / 2], len / 2); /* 2, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(err, 0, err);
|
||||
|
||||
failure = 0;
|
||||
for (i = 0; i < len / 2; i++) { /* 2, common data for test, no special meaning */
|
||||
if (buf[i] != buf[len / 2 + i]) { /* 2, common data for test, no special meaning */
|
||||
failure = 1; /* 1, common data for test, no special meaning */
|
||||
break;
|
||||
}
|
||||
}
|
||||
ICUNIT_ASSERT_EQUAL(failure, 0, failure);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_MEM_MEMMOVE_0200
|
||||
* @tc.name memmove function overlay move buffer test
|
||||
* @tc.desc [C-L*-311]
|
||||
*/
|
||||
LITE_TEST_CASE(MemApiTestSuite, testMemmoveOverlay, Function | MediumTest | Level3)
|
||||
{
|
||||
char chr = 'A';
|
||||
char buf[1024]; /* 1024, common data for test, no special meaning */
|
||||
char backup[1024]; /* 1024, common data for test, no special meaning */
|
||||
int i, len, failure;
|
||||
|
||||
len = sizeof(buf);
|
||||
for (i = 0; i < len; i++) {
|
||||
buf[i] = chr + GetRandom(26); /* 26, common data for test, no special meaning */
|
||||
backup[i] = buf[i];
|
||||
}
|
||||
errno_t err = memmove_s(&buf[16], sizeof(buf) / sizeof(buf[0]) - 16, &buf[0], len / 2); /* 16, 2, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(err, 0, err);
|
||||
|
||||
failure = 0;
|
||||
for (i = 0; i < len / 2; i++) { /* 2, common data for test, no special meaning */
|
||||
if (buf[i + 16] != backup[i]) { /* 16, common data for test, no special meaning */
|
||||
failure = 1; /* 1, common data for test, no special meaning */
|
||||
break;
|
||||
}
|
||||
}
|
||||
ICUNIT_ASSERT_EQUAL(failure, 0, failure);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_MEM_MEMCMP_0100
|
||||
* @tc.name memmove function move buffer test
|
||||
* @tc.desc [C-L*-311]
|
||||
*/
|
||||
LITE_TEST_CASE(MemApiTestSuite, testMemcmp, Function | MediumTest | Level2)
|
||||
{
|
||||
char orign[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; /* 8, common data for test, no special meaning */
|
||||
char lt[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x77}; /* 8, common data for test, no special meaning */
|
||||
char eq[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; /* 8, common data for test, no special meaning */
|
||||
char gt[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x99}; /* 8, common data for test, no special meaning */
|
||||
|
||||
int ret;
|
||||
int len = sizeof(orign);
|
||||
|
||||
ret = memcmp(lt, orign, len);
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
|
||||
ret = memcmp(eq, orign, len);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = memcmp(gt, orign, len);
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = memcmp(gt, orign, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(MemApiTestSuite);
|
||||
|
||||
void MemApiTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testMemset);
|
||||
RUN_ONE_TESTCASE(testMemcpy);
|
||||
RUN_ONE_TESTCASE(testMemmove);
|
||||
RUN_ONE_TESTCASE(testMemmoveOverlay);
|
||||
RUN_ONE_TESTCASE(testMemcmp);
|
||||
}
|
||||
37
testsuites/unittest/xts/mem/xts_mem.c
Normal file
37
testsuites/unittest/xts/mem/xts_mem.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 MemFuncTest(void)
|
||||
{
|
||||
ActsMemApiTest();
|
||||
MemApiTest();
|
||||
}
|
||||
43
testsuites/unittest/xts/mem/xts_mem.h
Normal file
43
testsuites/unittest/xts/mem/xts_mem.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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_MEM_H
|
||||
#define XTS_MEM_H
|
||||
|
||||
#include "xts_test.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <securec.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <limits.h>
|
||||
|
||||
#endif
|
||||
40
testsuites/unittest/xts/net/BUILD.gn
Normal file
40
testsuites/unittest/xts/net/BUILD.gn
Normal file
@@ -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",
|
||||
]
|
||||
}
|
||||
419
testsuites/unittest/xts/net/acts_net_test.c
Normal file
419
testsuites/unittest/xts/net/acts_net_test.c
Normal file
@@ -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
|
||||
}
|
||||
|
||||
58
testsuites/unittest/xts/net/xts_net.h
Normal file
58
testsuites/unittest/xts/net/xts_net.h
Normal file
@@ -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 <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <securec.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <limits.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ether.h>
|
||||
#include <net/if.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include "lwip/sockets.h"
|
||||
#include <sys/socket.h>
|
||||
|
||||
#endif
|
||||
44
testsuites/unittest/xts/process/BUILD.gn
Normal file
44
testsuites/unittest/xts/process/BUILD.gn
Normal file
@@ -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("pthread_test") {
|
||||
sources = [
|
||||
"acts_process_api_test.c",
|
||||
"pthread_attr_test.c",
|
||||
"pthread_basic_api_test.c",
|
||||
"pthread_test.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
70
testsuites/unittest/xts/process/acts_process_api_test.c
Normal file
70
testsuites/unittest/xts/process/acts_process_api_test.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 "pthread_test.h"
|
||||
|
||||
LITE_TEST_SUIT(PROCESS, ProcessApi, ProcessApiTestSuite);
|
||||
|
||||
static BOOL ProcessApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL ProcessApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void *ThreadFunc(void* arg)
|
||||
{
|
||||
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 = pthread_create(&thisThread, NULL, ThreadFunc, NULL);
|
||||
returnVal = pthread_setname_np(thisThread, "funcThreadNamelongName");
|
||||
ICUNIT_ASSERT_NOT_EQUAL(returnVal, 0, returnVal);
|
||||
ICUNIT_ASSERT_EQUAL(returnVal, ERANGE, returnVal);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(ProcessApiTestSuite);
|
||||
|
||||
void ActsProcessApiTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testPthreadSetnameNp1000);
|
||||
}
|
||||
|
||||
116
testsuites/unittest/xts/process/pthread_attr_test.c
Normal file
116
testsuites/unittest/xts/process/pthread_attr_test.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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 "pthread_test.h"
|
||||
|
||||
LITE_TEST_SUIT(PROCESS, PthreadAttr, PthreadAttrTestSuite);
|
||||
|
||||
static BOOL PthreadAttrTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL PthreadAttrTestSuiteTearDown(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
pthread_attr_t attr;
|
||||
int param;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_attr_getdetachstate(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(param, PTHREAD_CREATE_DETACHED, param);
|
||||
ret = pthread_create(&tid, &attr, ThreadPublic, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_attr_getdetachstate(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(param, PTHREAD_CREATE_JOINABLE, param);
|
||||
ret = pthread_create(&tid, &attr, ThreadPublic, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
size_t stackSize;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_attr_getstacksize(&attr, &stackSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
stackSize = PTHREAD_STACK_MIN - 1; /* 1, common data for test, no special meaning */
|
||||
ret = pthread_attr_setstacksize(&attr, stackSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
ret = pthread_attr_destroy(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(PthreadAttrTestSuite);
|
||||
|
||||
void PthreadAttrTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testPthreadAttrSetdetachstate);
|
||||
RUN_ONE_TESTCASE(testPthreadAttrSetstacksizeEINVAL);
|
||||
}
|
||||
|
||||
222
testsuites/unittest/xts/process/pthread_basic_api_test.c
Normal file
222
testsuites/unittest/xts/process/pthread_basic_api_test.c
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* 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 "pthread_test.h"
|
||||
|
||||
LITE_TEST_SUIT(PROCESS, PthreadBasicApi, PthreadBasicApiTestSuite);
|
||||
|
||||
static BOOL PthreadBasicApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL PthreadBasicApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void *ThreadPthreadCreateBasic(void *arg)
|
||||
{
|
||||
char *s = (char*)arg;
|
||||
ICUNIT_ASSERT_STRING_EQUAL(s, "1234567890 !@#$%^&*()_= ZXCVBNM [];'./>?:\" +-*/qwertyuiopasdfghjklzxcvbnm", s);
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
char str[] = "1234567890 !@#$%^&*()_= ZXCVBNM [];'./>?:\" +-*/qwertyuiopasdfghjklzxcvbnm";
|
||||
ret = pthread_create(&tid, NULL, ThreadPthreadCreateBasic, (void*)str);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
int num = 4; /* 4, common data for test, no special meaning */
|
||||
void *joinRe = NULL;
|
||||
ret = pthread_create(&tid, NULL, ThreadPublic, (void*)&num);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, &joinRe);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
int *p = (int*)joinRe;
|
||||
ICUNIT_ASSERT_EQUAL(&num, p, &num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
ret = pthread_create(&tid, NULL, ThreadPublic, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
usleep(50); /* 50, common data for test, no special meaning */
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
int num = 4; /* 4, common data for test, no special meaning */
|
||||
void *joinRe = NULL;
|
||||
ret = pthread_create(&tid, NULL, ThreadPthreadExitThread, (void*)&num);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, &joinRe);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
int *p = (int*)joinRe;
|
||||
ICUNIT_ASSERT_EQUAL(&num, p, &num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
int num = 4; /* 4, common data for test, no special meaning */
|
||||
void *joinRe = NULL;
|
||||
ret = pthread_create(&tid, NULL, ThreadPthreadExitFunction, (void*)&num);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, &joinRe);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
int *p = (int*)joinRe;
|
||||
ICUNIT_ASSERT_EQUAL(&num, p, &num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
ret = pthread_create(&tid, NULL, ThreadPublic, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_detach(tid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *ThreadPthreadEqual(void *arg)
|
||||
{
|
||||
int ret;
|
||||
pthread_t *tid = (pthread_t*)arg;
|
||||
ret = pthread_equal(*tid, pthread_self());
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
|
||||
usleep(10); /* 10, common data for test, no special meaning */
|
||||
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)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
ret = pthread_create(&tid, NULL, ThreadPthreadEqual, (void*)&tid);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_equal(tid, pthread_self());
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(PthreadBasicApiTestSuite);
|
||||
|
||||
void PthreadBasicApiTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testPthreadCreateBasic);
|
||||
RUN_ONE_TESTCASE(testJoinReturn);
|
||||
RUN_ONE_TESTCASE(testJoinExited);
|
||||
RUN_ONE_TESTCASE(testPthreadExitThread);
|
||||
RUN_ONE_TESTCASE(testPthreadExitFunction);
|
||||
RUN_ONE_TESTCASE(testPthreadDetach);
|
||||
RUN_ONE_TESTCASE(testPthreadEqual);
|
||||
}
|
||||
|
||||
44
testsuites/unittest/xts/process/pthread_test.c
Normal file
44
testsuites/unittest/xts/process/pthread_test.c
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
#include "xts_test.h"
|
||||
|
||||
void *ThreadPublic(void *arg)
|
||||
{
|
||||
usleep(10); /* 10, common data for test, no special meaning */
|
||||
return arg;
|
||||
}
|
||||
|
||||
void PthreadFuncTest(void)
|
||||
{
|
||||
ActsProcessApiTest();
|
||||
PthreadAttrTest();
|
||||
PthreadBasicApiTest();
|
||||
}
|
||||
49
testsuites/unittest/xts/process/pthread_test.h
Normal file
49
testsuites/unittest/xts/process/pthread_test.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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_PROCESS_H
|
||||
#define XTS_PROCESS_H
|
||||
|
||||
#include "xts_test.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
#include <securec.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <limits.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
extern void *ThreadPublic(void *arg);
|
||||
|
||||
#endif
|
||||
43
testsuites/unittest/xts/sched/BUILD.gn
Normal file
43
testsuites/unittest/xts/sched/BUILD.gn
Normal file
@@ -0,0 +1,43 @@
|
||||
# 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("sched_test") {
|
||||
sources = [
|
||||
"process_sched_api_test.c",
|
||||
"pthread_sched_api_test.c",
|
||||
"sched_api_test.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
136
testsuites/unittest/xts/sched/process_sched_api_test.c
Normal file
136
testsuites/unittest/xts/sched/process_sched_api_test.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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 "sched_api_test.h"
|
||||
|
||||
LITE_TEST_SUIT(SCHED, ProcessSchedApi, ProcessSchedApiTestSuite);
|
||||
|
||||
static BOOL ProcessSchedApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL ProcessSchedApiTestSuiteTearDown(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int invalidPolicyVal;
|
||||
int prio;
|
||||
|
||||
invalidPolicyVal = -GetRandom(10000); /* 10000, common data for test, no special meaning */
|
||||
errno = 0;
|
||||
prio = sched_get_priority_max(invalidPolicyVal);
|
||||
ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
invalidPolicyVal = GetRandom(10000) + SCHED_DEADLINE; /* 10000, common data for test, no special meaning */
|
||||
errno = 0;
|
||||
prio = sched_get_priority_max(invalidPolicyVal);
|
||||
ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
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]);
|
||||
ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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); /* 10000, common data for test, no special meaning */
|
||||
errno = 0;
|
||||
prio = sched_get_priority_min(invalidPolicyVal);
|
||||
ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
invalidPolicyVal = GetRandom(10000) + SCHED_DEADLINE; /* 10000, common data for test, no special meaning */
|
||||
errno = 0;
|
||||
prio = sched_get_priority_min(invalidPolicyVal);
|
||||
ICUNIT_ASSERT_EQUAL(prio, -1, prio); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(ProcessSchedApiTestSuite);
|
||||
|
||||
void ProcessSchedApiTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testSchedGetPriorityMaxError0200);
|
||||
RUN_ONE_TESTCASE(testSchedGetPriorityMaxError0300);
|
||||
RUN_ONE_TESTCASE(testSchedGetPriorityMinError0200);
|
||||
RUN_ONE_TESTCASE(testSchedGetPriorityMinError0300);
|
||||
}
|
||||
243
testsuites/unittest/xts/sched/pthread_sched_api_test.c
Normal file
243
testsuites/unittest/xts/sched/pthread_sched_api_test.c
Normal file
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* 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 "sched_api_test.h"
|
||||
|
||||
LITE_TEST_SUIT(SCHED, PthreadSchedApi, PthreadSchedApiTestSuite);
|
||||
|
||||
static int g_policy = 0;
|
||||
static int g_prioriy = 0;
|
||||
|
||||
static BOOL PthreadSchedApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL PthreadSchedApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
int inheritsched = -1; /* -1, common data for test, no special meaning */
|
||||
int rt = pthread_attr_getinheritsched(&attr, &inheritsched);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
ICUNIT_ASSERT_EQUAL(inheritsched, PTHREAD_INHERIT_SCHED, inheritsched);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
int rt = pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
int inheritsched = -1; /* -1, common data for test, no special meaning */
|
||||
rt = pthread_attr_getinheritsched(&attr, &inheritsched);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
ICUNIT_ASSERT_EQUAL(inheritsched, PTHREAD_INHERIT_SCHED, inheritsched);
|
||||
|
||||
rt = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
inheritsched = -1; /* -1, common data for test, no special meaning */
|
||||
rt = pthread_attr_getinheritsched(&attr, &inheritsched);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
ICUNIT_ASSERT_EQUAL(inheritsched, PTHREAD_EXPLICIT_SCHED, inheritsched);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
int n = -GetRandom(100); /* 100, common data for test, no special meaning */
|
||||
int rt = pthread_attr_setinheritsched(&attr, n);
|
||||
ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt);
|
||||
n = 2 + GetRandom(100); /* 2, 100, common data for test, no special meaning */
|
||||
rt = pthread_attr_setinheritsched(&attr, n);
|
||||
ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
struct sched_param param = {0};
|
||||
int rt = pthread_attr_getschedparam(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
|
||||
param.sched_priority = 22; /* 22, common data for test, no special meaning */
|
||||
rt = pthread_attr_setschedparam(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
|
||||
rt = pthread_attr_getschedparam(&attr, ¶m);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
ICUNIT_ASSERT_EQUAL(param.sched_priority, 22, param.sched_priority); /* 22, common data for test, no special meaning */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
int policy = -1; /* -1, common data for test, no special meaning */
|
||||
int rt = pthread_attr_getschedpolicy(&attr, &policy);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
ICUNIT_ASSERT_EQUAL(policy, SCHED_RR, policy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
int rt;
|
||||
|
||||
int invalidPolicy[7] = {SCHED_OTHER, SCHED_BATCH, SCHED_IDLE, SCHED_DEADLINE, SCHED_RESET_ON_FORK}; /* 7, common data for test, no special meaning */
|
||||
invalidPolicy[5] = -GetRandom(10000); /* 5, 10000, common data for test, no special meaning */
|
||||
invalidPolicy[6] = GetRandom(10000) + 6; /* 6, 10000, common data for test, no special meaning */
|
||||
for (int i = 0; i < 7; i++) { /* 7, common data for test, no special meaning */
|
||||
rt = pthread_attr_setschedpolicy(&attr, invalidPolicy[i]);
|
||||
ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
int scope = -1; /* -1, common data for test, no special meaning */
|
||||
int rt = pthread_attr_getscope(&attr, &scope);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
ICUNIT_ASSERT_EQUAL(scope, PTHREAD_SCOPE_SYSTEM, scope);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
int ret;
|
||||
pthread_attr_t attr;
|
||||
ret = pthread_attr_init(&attr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
int rt = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
|
||||
ICUNIT_ASSERT_EQUAL(rt, ENOTSUP, rt);
|
||||
|
||||
rt = pthread_attr_setscope(&attr, -GetRandom(10000)); /* 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt);
|
||||
|
||||
rt = pthread_attr_setscope(&attr, GetRandom(10000) + 2); /* 2, 10000, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(rt, EINVAL, rt);
|
||||
|
||||
int scope = -1; /* -1, common data for test, no special meaning */
|
||||
rt = pthread_attr_getscope(&attr, &scope);
|
||||
ICUNIT_ASSERT_EQUAL(rt, 0, rt);
|
||||
ICUNIT_ASSERT_EQUAL(scope, PTHREAD_SCOPE_SYSTEM, scope);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(PthreadSchedApiTestSuite);
|
||||
|
||||
void PthreadSchedApiTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testAttrGetInheritsched);
|
||||
RUN_ONE_TESTCASE(testAttrSetInheritsched);
|
||||
RUN_ONE_TESTCASE(testAttrSetInheritschedError);
|
||||
RUN_ONE_TESTCASE(testAttrSetSchedParam);
|
||||
RUN_ONE_TESTCASE(testAttrGetSchedPolicy);
|
||||
RUN_ONE_TESTCASE(testAttrSetSchedPolicyError);
|
||||
RUN_ONE_TESTCASE(testAttrGetScope);
|
||||
RUN_ONE_TESTCASE(testAttrSetScope);
|
||||
}
|
||||
37
testsuites/unittest/xts/sched/sched_api_test.c
Normal file
37
testsuites/unittest/xts/sched/sched_api_test.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 SchedApiFuncTest(void)
|
||||
{
|
||||
ProcessSchedApiTest();
|
||||
PthreadSchedApiTest();
|
||||
}
|
||||
43
testsuites/unittest/xts/sched/sched_api_test.h
Normal file
43
testsuites/unittest/xts/sched/sched_api_test.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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_SCHED_H
|
||||
#define XTS_SCHED_H
|
||||
|
||||
#include "xts_test.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/resource.h>
|
||||
#include <fcntl.h>
|
||||
#include <semaphore.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#endif
|
||||
39
testsuites/unittest/xts/sys/BUILD.gn
Normal file
39
testsuites/unittest/xts/sys/BUILD.gn
Normal file
@@ -0,0 +1,39 @@
|
||||
# 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("system_test") {
|
||||
sources = [ "sys_api_test.c" ]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
43
testsuites/unittest/xts/sys/sys_api.h
Normal file
43
testsuites/unittest/xts/sys/sys_api.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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_SYS_API_H
|
||||
#define XTS_SYS_API_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <search.h>
|
||||
#include <err.h>
|
||||
#include <regex.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#endif
|
||||
65
testsuites/unittest/xts/sys/sys_api_test.c
Normal file
65
testsuites/unittest/xts/sys/sys_api_test.c
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
#include "sys_api.h"
|
||||
#include "xts_test.h"
|
||||
|
||||
LITE_TEST_SUIT(SYSTEM, SysApiTest, SysApiTestSuite);
|
||||
|
||||
static BOOL SysApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL SysApiTestSuiteTearDown(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
ICUNIT_ASSERT_STRING_EQUAL(strerror(-1), "No error information", strerror(-1)); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(strerror(0), "No error information", strerror(0));
|
||||
ICUNIT_ASSERT_STRING_EQUAL(strerror(2), "No such file or directory", strerror(2)); /* 2, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(strerror(10), "No child process", strerror(10)); /* 10, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(strerror(65536), "No error information", strerror(65536)); /* 65536, common data for test, no special meaning */
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(SysApiTestSuite);
|
||||
|
||||
void SysApiFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrerror);
|
||||
}
|
||||
44
testsuites/unittest/xts/time/BUILD.gn
Normal file
44
testsuites/unittest/xts/time/BUILD.gn
Normal file
@@ -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",
|
||||
]
|
||||
}
|
||||
75
testsuites/unittest/xts/time/alarm_test.c
Normal file
75
testsuites/unittest/xts/time/alarm_test.c
Normal file
@@ -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();
|
||||
}
|
||||
65
testsuites/unittest/xts/time/alarm_test.h
Normal file
65
testsuites/unittest/xts/time/alarm_test.h
Normal file
@@ -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 <signal.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/times.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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
|
||||
148
testsuites/unittest/xts/time/clock_time_test.c
Normal file
148
testsuites/unittest/xts/time/clock_time_test.c
Normal file
@@ -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);
|
||||
}
|
||||
128
testsuites/unittest/xts/time/sleep_test.c
Normal file
128
testsuites/unittest/xts/time/sleep_test.c
Normal file
@@ -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);
|
||||
}
|
||||
80
testsuites/unittest/xts/time/time_utils_test.c
Normal file
80
testsuites/unittest/xts/time/time_utils_test.c
Normal file
@@ -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);
|
||||
}
|
||||
53
testsuites/unittest/xts/xts_test.c
Normal file
53
testsuites/unittest/xts/xts_test.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
uint32_t GetRandom(uint32_t max)
|
||||
{
|
||||
if (max == 0 || max == 1) { /* 1, common data for test, no special meaning */
|
||||
return 1;
|
||||
}
|
||||
return (rand() % max) + 1; /* 1, common data for test, no special meaning */
|
||||
}
|
||||
|
||||
void XtsTestSuite(void)
|
||||
{
|
||||
IpcSemApiTest();
|
||||
IoFuncTest();
|
||||
MathFuncTest();
|
||||
MemFuncTest();
|
||||
ActsNetTest();
|
||||
PthreadFuncTest();
|
||||
SchedApiFuncTest();
|
||||
SysApiFuncTest();
|
||||
TimeFuncTest();
|
||||
CmsisFuncTest();
|
||||
}
|
||||
78
testsuites/unittest/xts/xts_test.h
Normal file
78
testsuites/unittest/xts/xts_test.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_TEST_H
|
||||
#define _XTS_TEST_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "iCunit.h"
|
||||
|
||||
#define TEST_STR(func) ItLos##func
|
||||
#define TEST_TO_STR(x) #x
|
||||
#define TEST_HEAD_TO_STR(x) TEST_TO_STR(x)
|
||||
#define ADD_TEST_CASE(func) \
|
||||
TEST_ADD_CASE(TEST_HEAD_TO_STR(TEST_STR(func)), func, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION)
|
||||
|
||||
#define LITE_TEST_SUIT(subsystem, module, testsuit)
|
||||
#define LITE_TEST_CASE(module, function, flag) static int function(void)
|
||||
#define RUN_TEST_SUITE(testsuit)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) \
|
||||
ICUNIT_ASSERT_EQUAL(((expected) == (actual)) || (isnan(expected) && isnan(actual)), TRUE, 0)
|
||||
|
||||
#define RUN_ONE_TESTCASE(caseName) ADD_TEST_CASE(caseName)
|
||||
#define AUTO_RUN_ONE_TESTCASEFUNC(func) UnityDefaultTestRun(func, __FILE__, __LINE__)
|
||||
|
||||
uint32_t GetRandom(uint32_t max);
|
||||
|
||||
void XtsTestSuite(void);
|
||||
|
||||
extern void IpcSemApiTest(void);
|
||||
|
||||
extern void IoFuncTest(void);
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user