add l0 testsuits

Change-Id: I523269c97053f484d5cb0d94397269e41eaae86c
This commit is contained in:
x_xiny
2021-04-07 11:19:43 +08:00
parent 4fc4b8c9c1
commit 449f27d5cb
605 changed files with 65396 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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("//test/xts/tools/lite/build/suite_lite.gni")
hctest_suite("PosixTest") {
suite_name = "acts"
sources = [
"src/mqueue/mqueue_func_test.c",
"src/pthread/pthread_cond_func_test.c",
"src/semaphore/semaphore_func_test.c",
"src/ctype/isdigit_test.c",
"src/ctype/islower_test.c",
"src/ctype/isxdigit_test.c",
"src/ctype/ctype_func_test.c",
"src/ctype/tolower_test.c",
"src/ctype/toupper_test.c",
"src/math/math_func_test.c",
"src/regex/regex_func_test.c",
"src/stdarg/stdarg_func_test.c",
"src/stdlib/atoi_test.c",
"src/stdlib/atoll_test.c",
"src/stdlib/atol_test.c",
"src/stdlib/strtol_test.c",
"src/stdlib/strtoull_test.c",
"src/stdlib/strtoul_test.c",
"src/string/memory_func_test.c",
"src/string/string_func_test_01.c",
"src/string/string_func_test_02.c",
"src/string/strchr_test.c",
"src/string/strstr_test.c",
"src/time/time_func_test_01.c",
"src/fs/posix_fs_func_test.c",
"src/string/string_func_test_03.c",
"src/errno/strerror_test.c",
]
include_dirs = [
"//test/xts/tools/hctest/include",
"//third_party/unity/src",
"src",
"//kernel/liteos_m/kal",
"//kernel/liteos_m/kal/posix/include",
"//kernel/liteos_m/kal/posix/musl_src/errno",
]
cflags = [ "-Wno-error" ]
}

View File

@@ -0,0 +1,19 @@
{
"description": "Config for $module test cases",
"environment": [
{
"type": "device",
"label": "wifiiot"
}
],
"kits": [
{
"type": "DeployKit",
"timeout": "20000",
"burn_file": "$subsystem/$module.bin"
}
],
"driver": {
"type": "CTestLite"
}
}

View File

@@ -0,0 +1,105 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 KERNEL_TEST_H
#define KERNEL_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
#define TESTCOUNT_NUM_3 3
#define TESTCOUNT_NUM_4 4
#define TESTCOUNT_NUM_5 5
#define DELAY_TICKS_1 1
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30
#define THREAD_STACK_SPACE_MAX 4096
#define ICUNIT_GOTO_NOT_EQUAL(param, value, retcode, label) \
do { \
if ((param) == (value)) { \
TEST_ASSERT_NOT_EQUAL(param, value); \
printf("\nret = %d, expect = %d\n", param, value); \
goto label; \
} \
} while (0)
#define ICUNIT_GOTO_EQUAL(param, value, retcode, label) \
do { \
if ((param) != (value)) { \
TEST_ASSERT_EQUAL(param, value); \
printf("\nret = %d, expect = %d\n", param, value); \
goto label; \
} \
} while (0)
#define ICUNIT_GOTO_STRING_EQUAL(str1, str2, retcode, label) \
do { \
if (strcmp(str1, str2) != 0) { \
TEST_ASSERT_EQUAL(retcode, retcode + 1); \
goto label; \
} \
} while (0)
#define ICUNIT_ASSERT_EQUAL_VOID(param, value, retcode) \
do { \
if ((param) != (value)) { \
TEST_ASSERT_EQUAL(param, value); \
return; \
} \
} while (0)
#define ICUNIT_TRACK_EQUAL(param, value, retcode) \
do { \
if ((param) != (value)) { \
TEST_ASSERT_EQUAL(param, value); \
printf("\nret = %d, expect = %d\n", param, value); \
} \
} while (0)
#define ICUNIT_TRACK_NOT_EQUAL(param, value, retcode) \
do { \
if ((param) == (value)) { \
TEST_ASSERT_NOT_EQUAL(param, value); \
printf("\nret = %d, expect = %d\n", param, value); \
} \
} while (0)
#ifdef __cplusplus
#if __cplusplus
#endif
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,403 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#define RET_TRUE 1
#define RET_FALSE 0
/* *
* @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(Posix, Posixctype, PosixCtypeFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCtypeFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCtypeFuncTestSuiteTearDown(void)
{
printf("==== [ Ctype TEST ] ====\n\n");
return TRUE;
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_001
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum001, Function | MediumTest | Level1)
{
int src = 'A';
int ret = isalnum(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_002
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum002, Function | MediumTest | Level1)
{
int src = '1';
int ret = isalnum(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_003
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum003, Function | MediumTest | Level1)
{
int src = '@';
int ret = isalnum(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_004
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum004, Function | MediumTest | Level1)
{
int src = ' ';
int ret = isalnum(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_005
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum005, Function | MediumTest | Level1)
{
int src = '\f'; // 0x0c 14
int ret = isalnum(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_001
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii001, Function | MediumTest | Level1)
{
const int src = -1;
int ret = isascii(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_002
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii002, Function | MediumTest | Level1)
{
const int src = 0;
int ret = isascii(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_003
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii003, Function | MediumTest | Level1)
{
const int src = 127;
int ret = isascii(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_004
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii004, Function | MediumTest | Level1)
{
const int src = 128;
int ret = isascii(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_005
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii005, Function | MediumTest | Level1)
{
int src = '\f'; // 0x0c 14
int ret = isascii(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_001
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint001, Function | MediumTest | Level1)
{
int src = 'A';
int ret = isprint(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_002
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint002, Function | MediumTest | Level1)
{
int src = '1';
int ret = isprint(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_003
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint003, Function | MediumTest | Level1)
{
int src = '@';
int ret = isprint(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_004
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint004, Function | MediumTest | Level1)
{
int src = ' ';
int ret = isprint(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_005
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint005, Function | MediumTest | Level1)
{
int src = '\f'; // 0x0c
int ret = isprint(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_001
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace001, Function | MediumTest | Level1)
{
int src = 'A';
int ret = isspace(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_002
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace002, Function | MediumTest | Level1)
{
int src = '1';
int ret = isspace(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_003
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace003, Function | MediumTest | Level1)
{
int src = '@';
int ret = isspace(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_004
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace004, Function | MediumTest | Level1)
{
int src = ' ';
int ret = isspace(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_005
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace005, Function | MediumTest | Level1)
{
int src = '\t';
int ret = isspace(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_001
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper001, Function | MediumTest | Level1)
{
int src = 'A';
int ret = isupper(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_002
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper002, Function | MediumTest | Level1)
{
int src = 'a';
int ret = isupper(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_003
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper003, Function | MediumTest | Level1)
{
const int src = 0x45;
int ret = isupper(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_004
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper004, Function | MediumTest | Level1)
{
int src = ' ';
int ret = isupper(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_005
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper005, Function | MediumTest | Level1)
{
int src = '\t';
int ret = isupper(src);
TEST_ASSERT_EQUAL_INT(RET_TRUE, ret);
}
RUN_TEST_SUITE(PosixCtypeFuncTestSuite);
void PosixCtypeFuncTest()
{
LOG("begin PosixCtypeFuncTest....");
RUN_ONE_TESTCASE(testCtypeIsalnum001);
RUN_ONE_TESTCASE(testCtypeIsalnum002);
RUN_ONE_TESTCASE(testCtypeIsalnum003);
RUN_ONE_TESTCASE(testCtypeIsalnum004);
RUN_ONE_TESTCASE(testCtypeIsalnum005);
RUN_ONE_TESTCASE(testCtypeIsascii001);
RUN_ONE_TESTCASE(testCtypeIsascii002);
RUN_ONE_TESTCASE(testCtypeIsascii003);
RUN_ONE_TESTCASE(testCtypeIsascii004);
RUN_ONE_TESTCASE(testCtypeIsascii005);
RUN_ONE_TESTCASE(testCtypeIsprint001);
RUN_ONE_TESTCASE(testCtypeIsprint002);
RUN_ONE_TESTCASE(testCtypeIsprint003);
RUN_ONE_TESTCASE(testCtypeIsprint004);
RUN_ONE_TESTCASE(testCtypeIsprint005);
RUN_ONE_TESTCASE(testCtypeIsspace001);
RUN_ONE_TESTCASE(testCtypeIsspace002);
RUN_ONE_TESTCASE(testCtypeIsspace003);
RUN_ONE_TESTCASE(testCtypeIsspace004);
RUN_ONE_TESTCASE(testCtypeIsspace005);
RUN_ONE_TESTCASE(testCtypeIsupper001);
RUN_ONE_TESTCASE(testCtypeIsupper002);
RUN_ONE_TESTCASE(testCtypeIsupper003);
RUN_ONE_TESTCASE(testCtypeIsupper004);
RUN_ONE_TESTCASE(testCtypeIsupper005);
return;
}

View File

@@ -0,0 +1,171 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/**
* @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(Posix, Posixtimer, PosixCTypeIsdigitTest);
/**
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIsdigitTestSetUp(void)
{
return TRUE;
}
/**
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIsdigitTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_001
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit001, Function | MediumTest | Level1)
{
int a = '0';
int ret = isdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 1:isdigit(%c) ok.\n", a);
}
else {
printf("[DEMO] posix ctype test case 1:isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_002
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit002, Function | MediumTest | Level1)
{
int a = '5';
int ret = isdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 2:isdigit(%c) ok.\n", a);
}
else {
printf("[DEMO] posix ctype test case 2:isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_003
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit003, Function | MediumTest | Level1)
{
int a = '9';
int ret = isdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 3:isdigit(%c) ok.\n", a);
}
else {
printf("[DEMO] posix ctype test case 3:isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_004
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit004, Function | MediumTest | Level1)
{
int a = '0' - 1;
int ret = isdigit(a);
if (ret == 0) {
printf("[DEMO] posix ctype test case 4(except):isdigit(%c) ok.\n", a);
}
else {
printf("[DEMO] posix ctype test case 4(except):isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_005
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit005, Function | MediumTest | Level1)
{
int a = '9' + 1;
int ret = isdigit(a);
if (ret == 0) {
printf("[DEMO] posix ctype test case 5(except):isdigit(%c) ok.\n", a);
}
else {
printf("[DEMO] posix ctype test case 5(except):isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
RUN_TEST_SUITE(PosixCTypeIsdigitTest);
void PosixIsdigitFuncTest()
{
LOG("begin PosixIsdigitFuncTest....");
RUN_ONE_TESTCASE(testCTypeIsdigit001);
RUN_ONE_TESTCASE(testCTypeIsdigit002);
RUN_ONE_TESTCASE(testCTypeIsdigit003);
RUN_ONE_TESTCASE(testCTypeIsdigit004);
RUN_ONE_TESTCASE(testCTypeIsdigit005);
return;
}

View File

@@ -0,0 +1,182 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixCTypeIslowerTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIslowerTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIslowerTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_001
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower001, Function | MediumTest | Level1)
{
int a = 'a';
int ret = islower(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 1:islower(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 1:islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_002
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower002, Function | MediumTest | Level1)
{
int a = 'z';
int ret = islower(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 2:islower(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 2:islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_003
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower003, Function | MediumTest | Level1)
{
int a = 'f';
int ret = islower(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 3:islower(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 3:islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_004
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower004, Function | MediumTest | Level1)
{
int a = 'a' - 1;
int ret = islower(a);
if (ret == 0) {
printf("[DEMO] posix ctype test case 4(except):islower(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 4(except):islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_005
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower005, Function | MediumTest | Level1)
{
int a = 'z' + 1;
int ret = islower(a);
if (ret == 0) {
printf("[DEMO] posix ctype test case 5(except):islower(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 5(except):islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_006
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower006, Function | MediumTest | Level1)
{
int a = 'A';
int ret = islower(a);
if (ret == 0) {
printf("[DEMO] posix ctype test case 6(except):islower(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 6(except):islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
RUN_TEST_SUITE(PosixCTypeIslowerTest);
void PosixIslowerFuncTest()
{
LOG("begin PosixIslowerFuncTest....");
RUN_ONE_TESTCASE(testCTypeIslower001);
RUN_ONE_TESTCASE(testCTypeIslower002);
RUN_ONE_TESTCASE(testCTypeIslower003);
RUN_ONE_TESTCASE(testCTypeIslower004);
RUN_ONE_TESTCASE(testCTypeIslower005);
RUN_ONE_TESTCASE(testCTypeIslower006);
return;
}

View File

@@ -0,0 +1,254 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixCTypeIsxdigitTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIsxdigitTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIsxdigitTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_001
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit001, Function | MediumTest | Level1)
{
int a = '0';
int ret = isxdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_002
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit002, Function | MediumTest | Level1)
{
int a = '5';
int ret = isxdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 2:isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 2:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_003
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit003, Function | MediumTest | Level1)
{
int a = '9';
int ret = isxdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 3:isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 3:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_004
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit004, Function | MediumTest | Level1)
{
int a = 'a';
int ret = isxdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_005
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit005, Function | MediumTest | Level1)
{
int a = 'f';
int ret = isxdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_006
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit006, Function | MediumTest | Level1)
{
int a = 'A';
int ret = isxdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_007
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit007, Function | MediumTest | Level1)
{
int a = 'F';
int ret = isxdigit(a);
if (ret != 0) {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_008
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit008, Function | MediumTest | Level1)
{
int a = 'F' + 1;
int ret = isxdigit(a);
if (ret == 0) {
printf("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_009
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit009, Function | MediumTest | Level1)
{
int a = '0' - 1;
int ret = isxdigit(a);
if (ret == 0) {
printf("[DEMO] posix ctype test case 4(except):isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 4(except):isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_010
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit010, Function | MediumTest | Level1)
{
int a = '9' + 1;
int ret = isxdigit(a);
if (ret == 0) {
printf("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a);
} else {
printf("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
RUN_TEST_SUITE(PosixCTypeIsxdigitTest);
void PosixIsxdigitFuncTest()
{
LOG("begin PosixIsxdigitFuncTest....");
RUN_ONE_TESTCASE(testCTypeIsxdigit001);
RUN_ONE_TESTCASE(testCTypeIsxdigit002);
RUN_ONE_TESTCASE(testCTypeIsxdigit003);
RUN_ONE_TESTCASE(testCTypeIsxdigit004);
RUN_ONE_TESTCASE(testCTypeIsxdigit005);
RUN_ONE_TESTCASE(testCTypeIsxdigit006);
RUN_ONE_TESTCASE(testCTypeIsxdigit007);
RUN_ONE_TESTCASE(testCTypeIsxdigit008);
RUN_ONE_TESTCASE(testCTypeIsxdigit009);
RUN_ONE_TESTCASE(testCTypeIsxdigit010);
return;
}

View File

@@ -0,0 +1,164 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixCTypeTolowerTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeTolowerTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeTolowerTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_001
* @tc.name : Converts an uppercase letter specified by c to its lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower001, Function | MediumTest | Level1)
{
int a = 'a';
int ret = tolower(a);
if (ret == 'a') {
printf("[DEMO] posix ctype test case 1:tolower(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'a');
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_002
* @tc.name : Converts an uppercase letter specified by c to its lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower002, Function | MediumTest | Level1)
{
int a = 'A';
int ret = tolower(a);
if (ret == 'a') {
printf("[DEMO] posix ctype test case 2:tolower(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'a');
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_003
* @tc.name : Converts an uppercase letter to lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower003, Function | MediumTest | Level1)
{
int a = 'z';
int ret = tolower(a);
if (ret == 'z') {
printf("[DEMO] posix ctype test case 3:tolower(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'z');
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_004
* @tc.name : Converts an uppercase letter to its lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower004, Function | MediumTest | Level1)
{
int a = 'Z';
int ret = tolower(a);
if (ret == 'z') {
printf("[DEMO] posix ctype test case 4:tolower(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'z');
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_005
* @tc.name : Converts an uppercase letter to its lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower005, Function | MediumTest | Level1)
{
int a = '1';
int ret = tolower(a);
if (ret == '1') {
printf("[DEMO] posix ctype test case 5(except):tolower(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == '1');
}
RUN_TEST_SUITE(PosixCTypeTolowerTest);
void PosixTolowerFuncTest()
{
LOG("begin PosixTolowerFuncTest....");
RUN_ONE_TESTCASE(testCTypeTolower001);
RUN_ONE_TESTCASE(testCTypeTolower002);
RUN_ONE_TESTCASE(testCTypeTolower003);
RUN_ONE_TESTCASE(testCTypeTolower004);
RUN_ONE_TESTCASE(testCTypeTolower005);
return;
}

View File

@@ -0,0 +1,164 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixCTypeToupperTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeToupperTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeToupperTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_001
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper001, Function | MediumTest | Level1)
{
int a = 'a';
int ret = toupper(a);
if (ret == 'A') {
printf("[DEMO] posix ctype test case 1:toupper(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 1:toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'A');
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_002
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper002, Function | MediumTest | Level1)
{
int a = 'A';
int ret = toupper(a);
if (ret == 'A') {
printf("[DEMO] posix ctype test case 2:toupper(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 2:toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'A');
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_003
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper003, Function | MediumTest | Level1)
{
int a = 'z';
int ret = toupper(a);
if (ret == 'Z') {
printf("[DEMO] posix ctype test case 3:toupper(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 3:toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'Z');
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_004
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper004, Function | MediumTest | Level1)
{
int a = 'Z';
int ret = toupper(a);
if (ret == 'Z') {
printf("[DEMO] posix ctype test case 4:toupper(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 4:toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'Z');
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_005
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper005, Function | MediumTest | Level1)
{
int a = '1';
int ret = toupper(a);
if (ret == '1') {
printf("[DEMO] posix ctype test case 5(except):toupper(%c)==%c ok.\n", a, ret);
} else {
printf("[DEMO] posix ctype test case 5(except):toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == '1');
}
RUN_TEST_SUITE(PosixCTypeToupperTest);
void PosixToupperFuncTest()
{
LOG("begin PosixToupperFuncTest....");
RUN_ONE_TESTCASE(testCTypeToupper001);
RUN_ONE_TESTCASE(testCTypeToupper002);
RUN_ONE_TESTCASE(testCTypeToupper003);
RUN_ONE_TESTCASE(testCTypeToupper004);
RUN_ONE_TESTCASE(testCTypeToupper005);
return;
}

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <stdlib.h>
#include <errno.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#undef E
#define E(a, b) b "\0"
static const char G_ERRMSG[] = {
#include "__strerror.h"
}
;
/* *
* @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 PosixSysFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixsystem, PosixSysFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixSysFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixSysFuncTestSuiteTearDown(void)
{
printf("+Hello this is a System function test+\n");
return TRUE;
}
/* *
* @tc.number : SUB_KERNEL_POSIX_strerror_OPERATION_001
* @tc.name : Memony operation for strerror test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixSysFuncTestSuite, testOsSysStrerror001, Function | MediumTest | Level1)
{
for (int i = 0; i < sizeof(G_ERRMSG) / sizeof(G_ERRMSG[0]); i++) {
char *s = strerror(i);
TEST_ASSERT_NOT_NULL(s);
TEST_ASSERT_EQUAL_STRING(G_ERRMSG[i], s);
if (NULL != s) {
printf("Test Result :%s\r\n", s);
}
}
TEST_ASSERT_EQUAL_STRING("No error information", strerror(-1));
TEST_ASSERT_EQUAL_STRING("No error information", strerror(0));
TEST_ASSERT_EQUAL_STRING("No such file or directory", strerror(2));
TEST_ASSERT_EQUAL_STRING("No child process", strerror(10));
};
RUN_TEST_SUITE(PosixSysFuncTestSuite);
void PosixStrerrorTest()
{
LOG("begin PosixStrerrorTest....");
RUN_ONE_TESTCASE(testOsSysStrerror001);
return;
}

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 KERNEL_TEST_H
#define KERNEL_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
#define TESTCOUNT_NUM_3 3
#define TESTCOUNT_NUM_4 4
#define TESTCOUNT_NUM_5 5
#define DELAY_TICKS_1 1
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30
#define THREAD_STACK_SPACE_MAX 4096
#define RUN_ONE_TESTCASE(caseName) UnityDefaultTestRun(caseName##_runTest, __FILE__, __LINE__)
#define AUTO_RUN_ONE_TESTCASEFUNC(func) UnityDefaultTestRun(func, __FILE__, __LINE__)
#ifdef __cplusplus
#if __cplusplus
#endif
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 TEST_LOG
#define TEST_LOG
#include <stdio.h>
#include <los_debug.h>
#ifdef __cplusplus
extern "C" {
#endif
#define LOG(fmt, args...) PRINT_EMG(fmt, ##args)
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,371 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <float.h>
#include <math.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "los_debug.h"
#define RET_OK 0
#define TEST_VALUE_X 0
#define TEST_VALUE_Y 1
#define TEST_EXPECTED 2
int DoubleEquals(double a, double b)
{
if (a == INFINITY && b == INFINITY) {
return 1;
}
if (a == -INFINITY && b == -INFINITY) {
return 1;
}
if (a == INFINITY && b != INFINITY) {
return 0;
}
if (a == -INFINITY && b != -INFINITY) {
return 0;
}
if (isnan(a) && isnan(b)) {
return 1;
}
if (isnan(a) || isnan(b)) {
return 0;
}
return fabs(a - b) < DBL_EPSILON;
}
/* *
* @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 PosixMathFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixmath, PosixMathFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixMathFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixMathFuncTestSuiteTearDown(void)
{
PRINT_EMG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number SUB_KERNEL_MATH_ABS_001
* @tc.name test abs api
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathAbs001, Function | MediumTest | Level1)
{
const int testCount = 3;
int testValues[] = {-3, 0, 3};
int expected[] = {3, 0, 3};
int ret;
for (int i = 0; i < testCount; ++i) {
ret = abs(testValues[i]);
PRINT_EMG("\n [POSIXTEST][abs]abs(%d) = %d, expected is %d", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_INT(expected[i], ret);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_ABS_002
* @tc.name test abs api for boundary value
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathAbs002, Function | MediumTest | Level1)
{
const int testCount = 3;
int testValues[] = {-2147483648, -2147483647, 2147483647};
int expected[] = {-2147483648, 2147483647, 2147483647};
int ret;
for (int i = 0; i < testCount; ++i) {
ret = abs(testValues[i]);
PRINT_EMG("\n [POSIXTEST][abs]abs(%d) = %d, expected is %d", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_INT(expected[i], ret);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_LOG_001
* @tc.name log basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathLog001, Function | MediumTest | Level1)
{
const int testCount = 3;
double testValues[] = { 0.5, 5.5, 1};
double expected[] = { -0.69314718055994528623, 1.70474809223842527217, 0.00000000000000000000};
double ret;
for (int i = 0; i < testCount; ++i) {
ret = log(testValues[i]);
PRINT_EMG("\n [POSIXTEST][log]log(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_LOG_002
* @tc.name log function test for invalid input
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathLog002, Function | MediumTest | Level1)
{
const int testCount = 4;
double testValues[] = { 0, -INFINITY, -2.0, NAN};
double expected[] = { -INFINITY, NAN, NAN, NAN};
double ret;
PRINT_EMG("\n (math_errhandling & MATH_ERRNO) = %d", (math_errhandling & MATH_ERRNO));
PRINT_EMG("\n (math_errhandling & MATH_ERREXCEPT) = %d", (math_errhandling & MATH_ERREXCEPT));
for (int i = 0; i < testCount; ++i) {
ret = log(testValues[i]);
PRINT_EMG("\n [POSIXTEST][log]log(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_SQRT_001
* @tc.name sqrt basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathSqrt001, Function | MediumTest | Level1)
{
const int testCount = 3;
double testValues[] = { 4, 3, 10 };
double expected[] = { 2.00000000000000000000, 1.73205080756887719318, 3.16227766016837952279 };
double ret;
for (int i = 0; i < testCount; ++i) {
ret = sqrt(testValues[i]);
PRINT_EMG("\n [POSIXTEST][sqrt]sqrt(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_SQRT_002
* @tc.name sqrt function test for invalid input
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathSqrt002, Function | MediumTest | Level1)
{
const int testCount = 5;
double testValues[] = { 0, INFINITY, -2.0, -INFINITY, NAN };
double expected[] = { 0.00000000000000000000, INFINITY, NAN, NAN, NAN};
double ret;
for (int i = 0; i < testCount; ++i) {
ret = sqrt(testValues[i]);
PRINT_EMG("\n [POSIXTEST][sqrt]sqrt(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_POW_001
* @tc.name pow basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow001, Function | MediumTest | Level1)
{
double testValues[][TEST_EXPECTED + 1] = {
{1, 1.12, 1.00000000000000000000},
{2.8, 2.14, 9.0556199394902243682},
{3.6, 3.16, 57.26851244563656706532},
{678.88, 0, 1.00000000000000000000}
};
const int testCount = sizeof(testValues) / (sizeof(double) * 3);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]);
PRINT_EMG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X],
testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]);
TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret);
TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_POW_002
* @tc.name pow basic function test for range input
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow002, Function | MediumTest | Level1)
{
double testValues[][TEST_EXPECTED + 1] = {
{1, NAN, 1.00000000000000000000},
{-1, -INFINITY, 1.00000000000000000000},
{-0.5, -INFINITY, INFINITY},
{3.5, -INFINITY, 0},
{0.5, INFINITY, 0},
{-3.5, INFINITY, INFINITY},
{-INFINITY, -5, -0.00000000000000000000},
{-INFINITY, -4.37, 0.00000000000000000000},
{-INFINITY, 7, -INFINITY},
{-INFINITY, 4, INFINITY},
{INFINITY, -4, 0.00000000000000000000},
{INFINITY, 4, INFINITY}
};
const int testCount = sizeof(testValues) / (sizeof(double) * 3);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]);
TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret);
TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret));
PRINT_EMG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X],
testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_POW_003
* @tc.name pow basic function test for invalid input
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow003, Function | MediumTest | Level1)
{
double testValues[][TEST_EXPECTED + 1] = {
{0.0, -7, HUGE_VAL},
{-0.0, -6.22, HUGE_VAL},
{-7.23, 3.57, NAN},
{121223, 5674343, HUGE_VAL}
};
const int testCount = sizeof(testValues) / (sizeof(double) * 3);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]);
TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret);
PRINT_EMG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X],
testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]);
TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_ROUND_001
* @tc.name round basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathRound001, Function | MediumTest | Level1)
{
double testValues[] = { -0.5, 2.5, -3.812345679812345, -0.125, 0.125};
double expected[] = { -1.00000000000000000000, 3.00000000000000000000, -4.00000000000000000000,
0.00000000000000000000, 0.00000000000000000000};
const int testCount = sizeof(testValues) / sizeof(double);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = round(testValues[i]);
PRINT_EMG("\n [POSIXTEST][round]round1(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_ROUND_002
* @tc.name round basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathRound002, Function | MediumTest | Level1)
{
double testValues[] = { NAN, -INFINITY, INFINITY, 0};
double expected[] = { NAN, -INFINITY, INFINITY, 0.00000000000000000000};
const int testCount = sizeof(testValues) / sizeof(double);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = round(testValues[i]);
PRINT_EMG("\n [POSIXTEST][round]round1(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_ROUND_002
* @tc.name round basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathRound003, Function | MediumTest | Level1)
{
double testValues[] = { NAN, -INFINITY, INFINITY, 0};
double expected[] = { NAN, -INFINITY, INFINITY, 0.00000000000000000000};
const int testCount = sizeof(testValues) / sizeof(double);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = round(testValues[i]);
PRINT_EMG("\n [POSIXTEST][round]round1_fortest(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_FALSE(DoubleEquals(expected[i], ret));
}
};
RUN_TEST_SUITE(PosixMathFuncTestSuite);
void PosixMathFuncTest()
{
PRINT_EMG("begin PosixMathFuncTest....");
RUN_ONE_TESTCASE(testMathAbs001);
RUN_ONE_TESTCASE(testMathAbs002);
RUN_ONE_TESTCASE(testMathLog001);
RUN_ONE_TESTCASE(testMathLog002);
RUN_ONE_TESTCASE(testMathSqrt001);
RUN_ONE_TESTCASE(testMathSqrt002);
RUN_ONE_TESTCASE(testMathPow001);
RUN_ONE_TESTCASE(testMathPow002);
RUN_ONE_TESTCASE(testMathPow003);
RUN_ONE_TESTCASE(testMathRound001);
RUN_ONE_TESTCASE(testMathRound002);
RUN_ONE_TESTCASE(testMathRound003);
return;
}

View File

@@ -0,0 +1,511 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <securec.h>
#include "hctest.h"
#include <mqueue.h>
#include <fcntl.h>
#include "common_test.h"
#define MQUEUE_STANDARD_NAME_LENGTH 50
#define MQUEUE_NO_ERROR 0
#define MQUEUE_SEND_STRING_TEST "mq_test"
#define MQUEUE_SHORT_ARRAY_LENGTH strlen(MQUEUE_SEND_STRING_TEST)
const int MQ_NAME_LEN = 64; // mqueue name len
const int MQ_TX_LEN = 64; // mqueue send buffer len
const int MQ_RX_LEN = 64; // mqueue receive buffer len
const int MQ_MSG_SIZE = 64; // mqueue message size
const int MQ_MSG_PRIO = 0; // mqueue message priority
const int MQ_MAX_MSG = 16; // mqueue message number
const char MQ_MSG[] = "MessageToSend"; // mqueue message to send
const int MQ_MSG_LEN = sizeof(MQ_MSG); // mqueue message len to send
const int MAX_MQ_NUMBER = 1024; // max mqueue number
const int MAX_MQ_NAME_LEN = 256; // max mqueue name length
const int MAX_MQ_MSG_SIZE = 65530; // max mqueue message size
// return n: 0 < n <= max
unsigned int GetRandom(unsigned int max)
{
if (max == 0 || max == 1) {
return 1;
}
return (rand() % max) + 1;
}
/**
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is mqueue
* @param : module name is mqueue
* @param : test suit name is MqueueFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Mqueue, MqueueFuncTestSuite);
/**
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL MqueueFuncTestSuiteSetUp(void)
{
return TRUE;
}
/**
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL MqueueFuncTestSuiteTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_001
* @tc.name : event operation for creat
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqueue001, Function | MediumTest | Level1)
{
unsigned int ret;
char msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0};
char mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
const char *msgptr = MQUEUE_SEND_STRING_TEST;
struct mq_attr attr = { 0 };
mqd_t mqueue;
attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH;
attr.mq_maxmsg = 1;
snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, "/mq002_%d", 1);
mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT1);
ret = mq_send(mqueue, msgptr, strlen(msgptr), 0);
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
ret = mq_receive(mqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL);
ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT1);
ICUNIT_GOTO_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd, EXIT1);
ret = mq_close(mqueue);
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
ret = mq_unlink(mqname);
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT);
return;
EXIT1:
mq_close(mqueue);
EXIT:
mq_unlink(mqname);
return;
};
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0100
* @tc.name mq_open function errno for EEXIST test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenEEXIST, Function | MediumTest | Level2)
{
char qName[MQ_NAME_LEN];
mqd_t queue, queueOther;
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqOpenEEXIST_%d", GetRandom(10000));
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
ICUNIT_GOTO_NOT_EQUAL(queue, (mqd_t)-1, queue, EXIT1);
queueOther = mq_open(qName, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, NULL);
ICUNIT_GOTO_EQUAL(queueOther, (mqd_t)-1, queueOther, EXIT1);
ICUNIT_GOTO_EQUAL(errno, EEXIST, errno, EXIT1);
EXIT1:
ret = mq_close(queue);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
EXIT:
ret = mq_unlink(qName);
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, ret);
return;
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0200
* @tc.name mq_open function errno for EINVAL test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenEINVAL, Function | MediumTest | Level2)
{
int i;
mqd_t queue;
struct mq_attr attr = {0};
char qName[MQ_NAME_LEN];
const int max = 65535;
sprintf_s(qName, MQ_NAME_LEN, "testMqOpenEINVAL_%d", GetRandom(10000));
for (i = 0; i<6; i++) {
switch (i) {
case 0:
attr.mq_msgsize = -1;
attr.mq_maxmsg = max;
break;
case 1:
/* attr.mq_msgsize > USHRT_MAX - 4 */
attr.mq_msgsize = max;
attr.mq_maxmsg = max;
break;
case 2:
attr.mq_msgsize = 10;
attr.mq_maxmsg = -1;
break;
case 3:
attr.mq_msgsize = 10;
attr.mq_maxmsg = max + 1;
break;
case 4:
attr.mq_msgsize = 0;
attr.mq_maxmsg = 16;
break;
case 5:
attr.mq_msgsize = 64;
attr.mq_maxmsg = 0;
break;
}
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
if (queue != (mqd_t)-1) {
mq_close(queue);
mq_unlink(qName);
}
/* if NOT call mq_close & mq_unlink then errno == ENOENT */
ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
}
for (i=0; i<MQ_NAME_LEN; i++) {
qName[i] = 0;
}
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0300
* @tc.name mq_open function errno for ENAMETOOLONG test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENAMETOOLONG, Function | MediumTest | Level2)
{
char qName[MAX_MQ_NAME_LEN + 10];
mqd_t queue;
int i;
for (i=0; i<MAX_MQ_NAME_LEN + 5; i++) {
qName[i] = '8';
}
qName[i] = '\0';
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
if (queue != (mqd_t)-1) {
mq_close(queue);
mq_unlink(qName);
}
ICUNIT_TRACK_EQUAL(errno, ENAMETOOLONG, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0400
* @tc.name mq_open function errno for ENOENT test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENOENT, Function | MediumTest | Level3)
{
mqd_t queue;
char qName[MQ_NAME_LEN];
sprintf_s(qName, MQ_NAME_LEN, "testMqOpenENOENT_%d", GetRandom(10000));
queue = mq_open(qName, O_RDWR, S_IRUSR | S_IWUSR, NULL);
ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
if (queue != (mqd_t)-1) {
mq_close(queue);
mq_unlink(qName);
}
ICUNIT_TRACK_EQUAL(errno, ENOENT, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0500
* @tc.name mq_open function errno for ENFILE test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENFILE, Function | MediumTest | Level3)
{
char qName[MAX_MQ_NUMBER + 1][30];
mqd_t queue[MAX_MQ_NUMBER + 1];
int flag = 0;
int i;
for (i=0; i<MAX_MQ_NUMBER + 1; i++) {
sprintf_s(qName[i], MQ_NAME_LEN, "testMqOpenENFILE_%d", i);
}
for (i=0; i<MAX_MQ_NUMBER; i++) {
queue[i] = mq_open(qName[i], O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
if (queue[i] == (mqd_t)-1) {
flag = 1;
printf("break: i = %d", i);
break;
}
ICUNIT_TRACK_EQUAL(queue[i], (mqd_t)-1, queue[i]);
}
printf("func: i = %d", i);
if (flag == 0) {
queue[i] = mq_open(qName[i], O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
}
ICUNIT_TRACK_EQUAL(queue[i], (mqd_t)-1, queue[i]);
ICUNIT_TRACK_EQUAL(errno, ENFILE, errno);
for (i=0; i<MAX_MQ_NUMBER+1; i++) {
mq_close(queue[i]);
mq_unlink(qName[i]);
}
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0600
* @tc.name mq_open function errno for ENOSPC test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENOSPC, Function | MediumTest | Level3)
{
mqd_t queue;
struct mq_attr setAttr = {0};
char qName[MQ_NAME_LEN];
sprintf_s(qName, MQ_NAME_LEN, "testMqOpenENOSPC_%d", GetRandom(10000));
setAttr.mq_msgsize = MAX_MQ_MSG_SIZE + 1;
setAttr.mq_maxmsg = MAX_MQ_NAME_LEN;
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr);
ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
if (queue != (mqd_t)-1) {
mq_close(queue);
mq_unlink(qName);
}
ICUNIT_TRACK_EQUAL(errno, ENOSPC, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_CLOSE_0100
* @tc.name mq_close function errno for EBADF test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqCloseEBADF, Function | MediumTest | Level2)
{
ICUNIT_TRACK_EQUAL(mq_close(NULL), -1, -1);
ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_SEND_0100
* @tc.name mq_send function errno for EAGAIN test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEAGAIN, Function | MediumTest | Level2)
{
mqd_t queue;
struct mq_attr attr = {0};
char qName[MQ_NAME_LEN];
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqSendEAGAIN_%d", GetRandom(10000));
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = 1;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EAGAIN, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_SEND_0200
* @tc.name mq_send function errno for EBADF and EMSGSIZE test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEBADFEMSGSIZE, Function | MediumTest | Level2)
{
mqd_t queue;
struct mq_attr attr = {0};
char qName[MQ_NAME_LEN];
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqSendEAGAIN_%d", GetRandom(10000));
attr.mq_msgsize = 1;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(NULL, MQ_MSG, 1, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EMSGSIZE, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_ASSERT_EQUAL_VOID(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_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
attr.mq_flags |= O_NONBLOCK;
ret = mq_setattr(queue, &attr, NULL);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_SEND_0300
* @tc.name mq_send function errno for EINVAL test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEINVAL, Function | MediumTest | Level3)
{
mqd_t queue;
struct mq_attr attr = {0};
char qName[MQ_NAME_LEN];
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqSendEINVAL_%d", GetRandom(10000));
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, 0, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_RECEIVE_0100
* @tc.name mq_receive function errno for EAGAIN test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqReceiveEAGAIN, Function | MediumTest | Level2)
{
mqd_t queue;
unsigned int prio;
struct mq_attr attr = {0};
struct mq_attr getAttr = {0};
char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN];
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEAGAIN_%d", GetRandom(10000));
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_getattr(queue, &getAttr);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
ICUNIT_TRACK_NOT_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(prio, MQ_MSG_PRIO, prio);
ICUNIT_TRACK_EQUAL(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN), 0, -1);
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EAGAIN, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
}
RUN_TEST_SUITE(MqueueFuncTestSuite);

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include <securec.h>
#include "hctest.h"
#include "los_config.h"
#include "cmsis_os2.h"
#include "common_test.h"
/**
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is pthread
* @param : module name is pthread
* @param : test suit name is PthreadFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Pthread, PthreadFuncTestSuite);
/**
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PthreadFuncTestSuiteSetUp(void)
{
return TRUE;
}
/**
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PthreadFuncTestSuiteTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_001
* @tc.name : event operation for creat
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PthreadFuncTestSuite, testPthread001, Function | MediumTest | Level1)
{
};
RUN_TEST_SUITE(PthreadFuncTestSuite);

View File

@@ -0,0 +1,191 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "los_debug.h"
#include "kernel_test.h"
#include <regex.h>
#define EQUAL 0
/* *
* @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 PosixStrCaseCmpFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixRegexTest, PosixRegexFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixRegexFuncTestSuiteSetUp(void)
{
PRINT_EMG("+-------------------------------------------+\n");
PRINT_EMG("+--------PosixRegexFuncTestSuiteSetUp-------+\n");
PRINT_EMG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixRegexFuncTestSuiteTearDown(void)
{
PRINT_EMG("+-------------------------------------------+\n");
PRINT_EMG("+-------PosixRegexFuncTestSuiteTearDown-----+\n");
PRINT_EMG("+-------------------------------------------+\n");
return TRUE;
}
void TestRegex(int flag, const char *pattern, const char *buf, const int expectedStatus, const char *expectedRes)
{
regmatch_t pmatch[1];
const size_t nmatch = 1;
regex_t reg;
char res[64];
int j = 0;
regcomp(&reg, pattern, flag);
int status = regexec(&reg, buf, nmatch, pmatch, 0);
TEST_ASSERT_EQUAL_INT(status, expectedStatus);
if (status == REG_NOMATCH) {
PRINT_EMG("no match");
} else if (status == 0) {
PRINT_EMG("Match:");
for (int i = pmatch[0].rm_so; i < pmatch[0].rm_eo; i++) {
putchar(buf[i]);
res[j] = buf[i];
j++;
}
res[j] = 0;
PRINT_EMG("\n");
TEST_ASSERT_EQUAL_STRING(res, expectedRes);
}
regfree(&reg);
}
void TestRegcomp(int flag, const char *pattern, const int expectedStatus)
{
regex_t reg;
int status = regcomp(&reg, pattern, flag);
PRINT_EMG("pattern : %s ,real status : %d \n", pattern, status);
TEST_ASSERT_EQUAL_INT(status, expectedStatus);
regfree(&reg);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0100
* @tc.name test regcomp/regexec/regfree cflags = Extended
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegexExtended001, Function | MediumTest | Level1)
{
TestRegex(REG_EXTENDED, "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*$", "harmony20000925@abcdef.com", REG_OK,
"harmony20000925@abcdef.com");
TestRegex(REG_EXTENDED, "^addr=([^&]*)", "huawei123&sex=girl&age=18\r\naddr=bantian&hobby=movie", REG_NOMATCH,
NULL);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0200
* @tc.name test regcomp/regexec/regfree cflags = ICASE
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegexIcase001, Function | MediumTest | Level1)
{
TestRegex(REG_ICASE, "HARMONY[1-9]", "harmony20000925@abcdef.com", REG_OK, "harmony2");
TestRegex(REG_ICASE, "HARMONY([1-9])", "harmony20000925@abcdef.com", REG_NOMATCH, NULL);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0300
* @tc.name test regcomp/regexec/regfree cflags = NEWLINE
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegexNewline001, Function | MediumTest | Level1)
{
TestRegex(REG_EXTENDED | REG_NEWLINE, "^addr=([^&]*)", "huawei123&sex=girl&age=18\r\naddr=bantian&hobby=movie",
REG_OK, "addr=bantian");
TestRegex(REG_EXTENDED | REG_NEWLINE, "^addr=([^&]*)", "huawei123&sex=girl&age=18&addr=bantian&hobby=movie",
REG_NOMATCH, NULL);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0400
* @tc.name test regcomp/regexec/regfree cflags = NOSUB
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegexNosub001, Function | MediumTest | Level1)
{
int cflags = REG_ICASE | REG_NOSUB;
regex_t reg;
const char *buf = "harmony20000925@abcdef.com";
const char *pattern2 = "HARMONY[1-9]";
regcomp(&reg, pattern2, cflags);
int status = regexec(&reg, buf, (size_t)0, NULL, 0);
TEST_ASSERT_EQUAL_INT(status, 0);
regfree(&reg);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0500
* @tc.name test regcomp cflags = NOSUB
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegcomp001, Function | MediumTest | Level1)
{
TestRegcomp(REG_EXTENDED, "[[.]", REG_ECOLLATE);
TestRegcomp(REG_EXTENDED, "[[:class:", REG_ECTYPE);
TestRegcomp(REG_EXTENDED, "[abcdefg", REG_EBRACK);
TestRegcomp(REG_EXTENDED, "\\x{4e00-\\x{9fa5}", REG_EBRACE);
TestRegcomp(REG_EXTENDED, "*abcdefg", REG_BADRPT);
}
RUN_TEST_SUITE(PosixRegexFuncTestSuite);
void PosixRegexFuncTest()
{
PRINT_EMG("begin PosixRegexFuncTest....");
RUN_ONE_TESTCASE(testRegexExtended001);
RUN_ONE_TESTCASE(testRegexIcase001);
RUN_ONE_TESTCASE(testRegexNewline001);
RUN_ONE_TESTCASE(testRegexNosub001);
RUN_ONE_TESTCASE(testRegcomp001);
return;
}

View File

@@ -0,0 +1,226 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <time.h>
#include <semaphore.h>
#include <stdio.h>
#include <errno.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#define NANO_S 1000000000
/* *
* @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 PosixSemaphoreFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixSemaphore, PosixSemaphoreFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixSemaphoreFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixSemaphoreFuncTestSuiteTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
// get cur-time plus ms
struct timespec GetDelayedTime(unsigned int ms)
{
struct timespec ts = { 0 };
const unsigned int nsecPerSec = 1000000000;
const unsigned int nsecPerMs = 1000000;
unsigned int setTimeNs = ms * nsecPerMs;
struct timespec tsNow = { 0 };
clock_gettime(CLOCK_REALTIME, &tsNow);
ts.tv_sec = tsNow.tv_sec + (tsNow.tv_nsec + setTimeNs) / nsecPerSec;
ts.tv_nsec = (tsNow.tv_nsec + setTimeNs) % nsecPerSec;
return ts;
}
// calculate time difference, in ms
int GetTimeDiff(struct timespec ts1, struct timespec ts2)
{
const unsigned int nsecPerSec = 1000000000;
const unsigned int nsecPerMs = 1000000;
int ms = (ts1.tv_sec - ts2.tv_sec) * nsecPerSec + (ts1.tv_nsec - ts2.tv_nsec);
ms = ms / nsecPerMs;
return ms;
}
/* *
* @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_001
* @tc.name sem_timedwait get semaphore timeout
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait001, Function | MediumTest | Level1)
{
struct timespec ts = { 0 };
struct timespec tsNow = { 0 };
sem_t sem;
int semValue = 0;
TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 0));
ts = GetDelayedTime(100);
LOG("\n ts %d, %d", ts.tv_sec, ts.tv_nsec);
if (sem_timedwait((sem_t *)&sem, &ts) == -1) {
TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno);
} else {
LOG("\n> sem_timedwait return unexpected");
}
clock_gettime(CLOCK_REALTIME, &tsNow);
LOG("\n tsNow %d, %d", tsNow.tv_sec, tsNow.tv_nsec);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
LOG("\n timeDiff %d", timeDiff);
TEST_ASSERT_GREATER_THAN_INT(0, timeDiff);
TEST_ASSERT_LESS_THAN_INT(20, timeDiff);
TEST_ASSERT_EQUAL_INT(0, sem_destroy((sem_t *)&sem));
}
/* *
* @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_001
* @tc.name sem_timedwait get semaphore success
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait002, Function | MediumTest | Level1)
{
struct timespec ts = { 0 };
struct timespec tsNow = { 0 };
struct timespec tsBegin = { 0 };
sem_t sem;
int semValue = 0;
TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 1));
ts = GetDelayedTime(100);
LOG("\n ts %d, %d", ts.tv_sec, ts.tv_nsec);
clock_gettime(CLOCK_REALTIME, &tsBegin);
int ret = sem_timedwait((sem_t *)&sem, &ts);
clock_gettime(CLOCK_REALTIME, &tsNow);
TEST_ASSERT_EQUAL_INT(0, ret);
LOG("\n tsBegin %ld, %ld, tsNow %ld, %ld", tsBegin.tv_sec, tsBegin.tv_nsec, tsNow.tv_sec, tsNow.tv_nsec);
int timeDiff = GetTimeDiff(tsNow, tsBegin); // calculate time different
LOG("\n timeDiff %d", timeDiff);
TEST_ASSERT_LESS_THAN_INT(20, timeDiff);
// try get semphore again
ts = GetDelayedTime(100);
LOG("\n ts %d, %d", ts.tv_sec, ts.tv_nsec);
ret = sem_timedwait((sem_t *)&sem, &ts);
clock_gettime(CLOCK_REALTIME, &tsNow);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno);
LOG("\n tsNow %ld, %ld", tsNow.tv_sec, tsNow.tv_nsec);
timeDiff = GetTimeDiff(tsNow, tsBegin); // calculate time different
LOG("\n wait timeDiff %d", timeDiff);
TEST_ASSERT_EQUAL_INT(0, sem_destroy((sem_t *)&sem));
}
/* *
* @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_003
* @tc.name {sem_timedwait} get semaphore, wait time abnormal, tv_nsec less than 0
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait003, Function | MediumTest | Level3)
{
int ret;
struct timespec ts;
sem_t sem;
ts.tv_sec = 0;
ts.tv_nsec = 200000;
ret = sem_timedwait((sem_t *)&sem, &ts);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
ret = sem_init((sem_t *)&sem, 0, 0);
TEST_ASSERT_EQUAL_INT(0, ret);
ts.tv_sec = time(NULL);
ts.tv_nsec = -2;
ret = sem_timedwait((sem_t *)&sem, &ts);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
ts.tv_sec = time(NULL);
ts.tv_nsec = NANO_S;
ret = sem_timedwait((sem_t *)&sem, &ts);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
ret = sem_timedwait((sem_t *)&sem, NULL);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
ret = sem_destroy((sem_t *)&sem);
TEST_ASSERT_EQUAL_INT(0, ret);
ts.tv_sec = time(NULL);
ts.tv_nsec = 2000000;
ret = sem_timedwait(NULL, &ts);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
}
RUN_TEST_SUITE(PosixSemaphoreFuncTestSuite);
void PosixSemaphoreFuncTest()
{
PRINT_EMG("begin PosixSemaphoreFuncTest....");
RUN_ONE_TESTCASE(testIpcSem_Timedwait001);
RUN_ONE_TESTCASE(testIpcSem_Timedwait002);
RUN_ONE_TESTCASE(testIpcSem_Timedwait003);
return;
}

View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include <string.h>
#include <stdarg.h>
#include "log.h"
#define RET_OK 1
#define MAX_ARG_NUM 2
#define MAX_STRING_LEN 6
/* *
* @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(Posix, Posixtimer, PosixStdargFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdargFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdargFuncTestSuiteTearDown(void)
{
printf("==== [ Stdarg TEST ] ====\n\n");
return TRUE;
}
int VaFunc(int argsNum, ...)
{
va_list vaP1;
(void)va_start(vaP1, argsNum);
va_list vaP2;
(void)va_copy(vaP2, vaP1);
for (int i = 0; i < argsNum; i++) {
if (i < 1) {
TEST_ASSERT_EQUAL_INT(10, va_arg(vaP2, int));
}
if (i == 1) {
TEST_ASSERT_EQUAL_INT(65, va_arg(vaP2, int));
}
if (i > 1) {
TEST_ASSERT_EQUAL_STRING("hello world", va_arg(vaP2, char *));
}
}
(void)va_end(vaP1);
(void)va_end(vaP2);
return RET_OK;
}
/* *
* @tc.number STDARG_API_TEST_001
* @tc.name stdarg api test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg001, Function | MediumTest | Level1)
{
int ret = VaFunc(1, 10);
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number STDARG_API_TEST_002
* @tc.name stdarg api test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg002, Function | MediumTest | Level1)
{
int ret = VaFunc(2, 10, 'A');
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number STDARG_API_TEST_003
* @tc.name stdarg api test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg003, Function | MediumTest | Level1)
{
int ret = VaFunc(3, 10, 'A', "hello world");
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number STDARG_API_TEST_003
* @tc.name stdarg api test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg004, Function | MediumTest | Level1)
{
int ret = VaFunc(3, 10, 'A', "hello world", '\0');
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
RUN_TEST_SUITE(PosixStdargFuncTestSuite);
void PosixStdargFuncTest()
{
LOG("begin PosixStdargFuncTest....");
RUN_ONE_TESTCASE(testStdarg001);
RUN_ONE_TESTCASE(testStdarg002);
RUN_ONE_TESTCASE(testStdarg003);
RUN_ONE_TESTCASE(testStdarg004);
return;
}

View File

@@ -0,0 +1,245 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixStdlibAtoiTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtoiTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtoiTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_ATOI_001
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi001, Function | MediumTest | Level1)
{
int value = atoi("2147483647");
if (value == 2147483647) {
printf("[DEMO] posix stdlib test case 1:atoi(%d) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 1:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(2147483647, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_002
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi002, Function | MediumTest | Level1)
{
int value = atoi("-2147483648");
if (value == -2147483648) {
printf("[DEMO] posix stdlib test case 2:atoi(%d) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 2:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(-2147483648, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_003
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi003, Function | MediumTest | Level1)
{
int value = atoi("100");
if (value == 100) {
printf("[DEMO] posix stdlib test case 3:atoi(%d) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 3:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_004
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi004, Function | MediumTest | Level1)
{
int value = atoi("2147483648");
if (value == -2147483648) {
printf("[DEMO] posix stdlib test case 4(except):atoi(%d) != 2147483648 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 4(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(-2147483648, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_005
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi005, Function | MediumTest | Level1)
{
int value = atoi("-2147483649");
if (value == 2147483647) {
printf("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(2147483647, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_006
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi006, Function | MediumTest | Level1)
{
int value = atoi("+100");
if (value == 100) {
printf("[DEMO] posix stdlib test case 6:atoi(%d) == +100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 6:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_007
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi007, Function | MediumTest | Level1)
{
int value = atoi("-100");
if (value == -100) {
printf("[DEMO] posix stdlib test case 7:atoi(%d) == -100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 7:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(-100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_008
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi008, Function | MediumTest | Level1)
{
int value = atoi("+-100");
if (value == 0) {
printf("[DEMO] posix stdlib test case 8(except):atoi(%d) == +-100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 8(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(0, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_009
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi009, Function | MediumTest | Level1)
{
int value = atoi("12+-100");
if (value == 12) {
printf("[DEMO] posix stdlib test case 9(except):atoi(%d) ok == 12+-100.\n", value);
} else {
printf("[DEMO] posix stdlib test case 9(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(12, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_010
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi010, Function | MediumTest | Level1)
{
int value = atoi("21474836470");
if (value == -10) {
printf("[DEMO] posix stdlib test case 10(except):atoi(%d) ok == 21474836470.\n", value);
} else {
printf("[DEMO] posix stdlib test case 10(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(-10, value);
}
RUN_TEST_SUITE(PosixStdlibAtoiTest);
void PosixStdlibAtoiFuncTest()
{
LOG("begin PosixStdlibAtoiFuncTest....");
RUN_ONE_TESTCASE(testStdlibAtoi001);
RUN_ONE_TESTCASE(testStdlibAtoi002);
RUN_ONE_TESTCASE(testStdlibAtoi003);
RUN_ONE_TESTCASE(testStdlibAtoi004);
RUN_ONE_TESTCASE(testStdlibAtoi005);
RUN_ONE_TESTCASE(testStdlibAtoi006);
RUN_ONE_TESTCASE(testStdlibAtoi007);
RUN_ONE_TESTCASE(testStdlibAtoi008);
RUN_ONE_TESTCASE(testStdlibAtoi009);
RUN_ONE_TESTCASE(testStdlibAtoi010);
return;
}

View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixStdlibAtolTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtolTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtolTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_ATOL_001
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol001, Function | MediumTest | Level1)
{
const long value = atol("2147483647");
if (value == 2147483647) {
printf("[DEMO] posix stdlib test case 1:atol(%ld) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 1:atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(2147483647, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_002
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol002, Function | MediumTest | Level1)
{
const long value = atol("-2147483648");
if (value == -2147483648) {
printf("[DEMO] posix stdlib test case 2:atol(%ld) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 2:atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(-2147483648, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_003
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol003, Function | MediumTest | Level1)
{
const long value = atol("100");
if (value == 100) {
printf("[DEMO] posix stdlib test case 3:atol(%ld) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 3:atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_004
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol004, Function | MediumTest | Level1)
{
const long value = atol("2147483648");
if (value != 2147483648) {
printf("[DEMO] posix stdlib test case 4(except):atol(%ld) != 2147483648 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 4(except):atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(-2147483648, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_005
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol005, Function | MediumTest | Level1)
{
const long value = atol("-2147483649");
if (value == 2147483647) {
printf("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(2147483647, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_006
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol006, Function | MediumTest | Level1)
{
const long value = atol("+100");
if (value == 100) {
printf("[DEMO] posix stdlib test case 6:atol(%ld) == +100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 6:atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_007
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol007, Function | MediumTest | Level1)
{
const long value = atol("-100");
if (value == -100) {
printf("[DEMO] posix stdlib test case 7:atol(%ld) == -100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 7:atoi(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(-100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_008
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol008, Function | MediumTest | Level1)
{
long value = atol("+-100");
if (value == 0) {
printf("[DEMO] posix stdlib test case 8(except):atol(%ld) == +-100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 8(except):atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(0, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_009
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol009, Function | MediumTest | Level1)
{
long value = atol("12+-100");
if (value == 12) {
printf("[DEMO] posix stdlib test case 9(except):atol(%ld) ok == 12+-100.\n", value);
} else {
printf("[DEMO] posix stdlib test case 9(except):atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(12, value);
}
RUN_TEST_SUITE(PosixStdlibAtolTest);
void PosixStdlibAtolFuncTest()
{
LOG("begin PosixStdlibAtolFuncTest....");
RUN_ONE_TESTCASE(testStdlibAtol001);
RUN_ONE_TESTCASE(testStdlibAtol002);
RUN_ONE_TESTCASE(testStdlibAtol003);
RUN_ONE_TESTCASE(testStdlibAtol004);
RUN_ONE_TESTCASE(testStdlibAtol005);
RUN_ONE_TESTCASE(testStdlibAtol006);
RUN_ONE_TESTCASE(testStdlibAtol007);
RUN_ONE_TESTCASE(testStdlibAtol008);
RUN_ONE_TESTCASE(testStdlibAtol009);
return;
}

View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixStdlibAtollTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtollTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtollTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_001
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll001, Function | MediumTest | Level1)
{
long long value = atoll("9223372036854775807");
if (value == 9223372036854775807LL) {
printf("[DEMO] posix stdlib test case 1:atoll(%lld) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 1:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 9223372036854775807LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_002
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll002, Function | MediumTest | Level1)
{
long long value = atoll("-9223372036854775808");
if (value == -9223372036854775808LL) {
printf("[DEMO] posix stdlib test case 2:atoll(%lld) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 2:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == -9223372036854775808LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_003
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll003, Function | MediumTest | Level1)
{
long long value = atoll("100");
if (value == 100LL) {
printf("[DEMO] posix stdlib test case 3:atoll(%lld) ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 3:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 100LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_004
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll004, Function | MediumTest | Level1)
{
long long value = atoll("9223372036854775808");
if (value == -9223372036854775808LL) {
printf("[DEMO] posix stdlib test case 4(except):atoll(%lld) != 9223372036854775808 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 4(except):atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == -9223372036854775808LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_005
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll005, Function | MediumTest | Level1)
{
long long value = atoll("-9223372036854775809");
if (value == 9223372036854775807LL) {
printf("[DEMO] posix stdlib test case 5(except):atoll(%lld) != -9223372036854775809 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 5(except):atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 9223372036854775807LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_006
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll006, Function | MediumTest | Level1)
{
long long value = atoll("+100");
if (value == 100LL) {
printf("[DEMO] posix stdlib test case 6:atoll(%lld) == +100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 6:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 100LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_007
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll007, Function | MediumTest | Level1)
{
long long value = atoll("-100");
if (value == -100LL) {
printf("[DEMO] posix stdlib test case 7:atoll(%lld) == -100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 7:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == -100LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_008
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll008, Function | MediumTest | Level1)
{
long long value = atoll("+-100");
if (value == 0LL) {
printf("[DEMO] posix stdlib test case 8(except):atoll(%lld) == +-100 ok.\n", value);
} else {
printf("[DEMO] posix stdlib test case 8(except):atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 0LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_009
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll009, Function | MediumTest | Level1)
{
long long value = atoll("12+-100");
if (value == 12LL) {
printf("[DEMO] posix stdlib test case 9(except):atoll(%lld) ok == 12+-100.\n", value);
} else {
printf("[DEMO] posix stdlib test case 9(except):atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 12LL);
}
RUN_TEST_SUITE(PosixStdlibAtollTest);
void PosixStdlibAtollFuncTest()
{
LOG("begin PosixStdlibAtollFuncTest....");
RUN_ONE_TESTCASE(testStdlibAtoll001);
RUN_ONE_TESTCASE(testStdlibAtoll002);
RUN_ONE_TESTCASE(testStdlibAtoll003);
RUN_ONE_TESTCASE(testStdlibAtoll004);
RUN_ONE_TESTCASE(testStdlibAtoll005);
RUN_ONE_TESTCASE(testStdlibAtoll006);
RUN_ONE_TESTCASE(testStdlibAtoll007);
RUN_ONE_TESTCASE(testStdlibAtoll008);
RUN_ONE_TESTCASE(testStdlibAtoll009);
return;
}

View File

@@ -0,0 +1,330 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixStdlibStrtolTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtolTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtolTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_001
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol001, Function | MediumTest | Level1)
{
char nPtr16[] = " 10";
char *endPtr16 = NULL;
long ret = strtol(nPtr16, &endPtr16, 16);
if (ret == 16) {
printf("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16);
} else {
printf("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16);
}
TEST_ASSERT_EQUAL_INT32(16, ret);
TEST_ASSERT_EQUAL_STRING(endPtr16, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_002
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol002, Function | MediumTest | Level1)
{
char nPtr16[] = "0x10";
char *endPtr16 = NULL;
long ret = strtol(nPtr16, &endPtr16, 0);
if (ret == 16) {
printf("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16);
} else {
printf("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16);
}
TEST_ASSERT_EQUAL_INT32(16, ret);
TEST_ASSERT_EQUAL_STRING(endPtr16, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_003
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol003, Function | MediumTest | Level1)
{
char nPtr10[] = "10";
char *endPtr10 = NULL;
long ret = strtol(nPtr10, &endPtr10, 10);
if (ret == 10) {
printf("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10);
} else {
printf("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10);
}
TEST_ASSERT_EQUAL_INT32(10, ret);
TEST_ASSERT_EQUAL_STRING(endPtr10, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_004
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol004, Function | MediumTest | Level1)
{
char nPtr10[] = "-10";
char *endPtr10 = NULL;
long ret = strtol(nPtr10, &endPtr10, 10);
if (ret == -10) {
printf("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10);
} else {
printf("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10);
}
TEST_ASSERT_EQUAL_INT32(-10, ret);
TEST_ASSERT_EQUAL_STRING(endPtr10, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_005
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol005, Function | MediumTest | Level1)
{
char nPtr10_3[] = "10";
char *endPtr10_3 = NULL;
long ret = strtol(nPtr10_3, &endPtr10_3, 0);
if (ret == 10) {
printf("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10_3, endPtr10_3);
} else {
printf("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s fail.\n", ret, nPtr10_3);
}
TEST_ASSERT_EQUAL_INT32(10, ret);
TEST_ASSERT_EQUAL_STRING(endPtr10_3, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_006
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol006, Function | MediumTest | Level1)
{
char nPtr8[] = "10";
char *endPtr8 = NULL;
long ret = strtol(nPtr8, &endPtr8, 8);
if (ret == 8) {
printf("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8, endPtr8);
} else {
printf("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8);
}
TEST_ASSERT_EQUAL_INT32(8, ret);
TEST_ASSERT_EQUAL_STRING(endPtr8, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_007
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol007, Function | MediumTest | Level1)
{
char nPtr8_2[] = "010";
char *endPtr8_2 = NULL;
long ret = strtol(nPtr8_2, &endPtr8_2, 8);
if (ret == 8) {
printf("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_2, endPtr8_2);
} else {
printf("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_2);
}
TEST_ASSERT_EQUAL_INT32(8, ret);
TEST_ASSERT_EQUAL_STRING(endPtr8_2, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_008
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol008, Function | MediumTest | Level1)
{
char nPtr8_3[] = "010";
char *endPtr8_3 = NULL;
long ret = strtol(nPtr8_3, &endPtr8_3, 0);
if (ret == 8) {
printf("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_3, endPtr8_3);
} else {
printf("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_3);
}
TEST_ASSERT_EQUAL_INT32(8, ret);
TEST_ASSERT_EQUAL_STRING(endPtr8_3, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_009
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol009, Function | MediumTest | Level1)
{
char nPtr2[] = "10";
char *endPtr2 = NULL;
long ret = strtol(nPtr2, &endPtr2, 2);
if (ret == 2) {
printf("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr2, endPtr2);
} else {
printf("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s fail.\n", ret, nPtr2);
}
TEST_ASSERT_EQUAL_INT32(2, ret);
TEST_ASSERT_EQUAL_STRING(endPtr2, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_010
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol010, Function | MediumTest | Level1)
{
char nPtr[] = "12 0110 0XDEFE 0666 -1.6";
char *endPtr = NULL;
long ret = strtol(nPtr, &endPtr, 10);
if (ret == 12) {
printf("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_INT32(12, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 -1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_011
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol011, Function | MediumTest | Level1)
{
char nPtr[] = "12 1.5";
char *endPtr = NULL;
long ret = strtol(nPtr, &endPtr, 65);
if (ret == 67) {
printf("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_INT32(67, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 1.5");
}
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol012, Function | MediumTest | Level1)
{
char nPtr[] = "2147483647 -2147483648";
char *endPtr = NULL;
long ret = strtol(nPtr, &endPtr, 10);
if (ret == 2147483647) {
printf("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_INT32(2147483647, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " -2147483648");
}
/* *
* @tc.number : TEST_STDLIB_ATOL_002
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol013, Function | MediumTest | Level1)
{
char nPtr[] = " -2147483648";
char *endPtr = NULL;
long ret = strtol(nPtr, &endPtr, 10);
if (ret == -2147483648) {
printf("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_INT32(-2147483648, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, "");
}
RUN_TEST_SUITE(PosixStdlibStrtolTest);
void PosixStdlibStrtolFuncTest()
{
LOG("begin PosixStdlibStrtolFuncTest....");
RUN_ONE_TESTCASE(testStdlibStrtol001);
RUN_ONE_TESTCASE(testStdlibStrtol002);
RUN_ONE_TESTCASE(testStdlibStrtol003);
RUN_ONE_TESTCASE(testStdlibStrtol004);
RUN_ONE_TESTCASE(testStdlibStrtol005);
RUN_ONE_TESTCASE(testStdlibStrtol006);
RUN_ONE_TESTCASE(testStdlibStrtol007);
RUN_ONE_TESTCASE(testStdlibStrtol008);
RUN_ONE_TESTCASE(testStdlibStrtol009);
RUN_ONE_TESTCASE(testStdlibStrtol010);
RUN_ONE_TESTCASE(testStdlibStrtol011);
RUN_ONE_TESTCASE(testStdlibStrtol012);
RUN_ONE_TESTCASE(testStdlibStrtol013);
return;
}

View File

@@ -0,0 +1,275 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixStdlibStrtoulTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtoulTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtoulTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_001
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul001, Function | MediumTest | Level1)
{
char nPtr[] = "12 0110 0XDEFE 0666 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 10);
if (ret == 12UL) {
printf("[DEMO] posix stdlib test case 1:strtoul(base=10) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 1:strtoul(base=10) ret:%lu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_EQUAL_UINT32(12UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 4294967295 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_002
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul002, Function | MediumTest | Level1)
{
char nPtr[] = " 0110 0XDEFE 0666 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 2);
if (ret == 6UL) {
printf("[DEMO] posix stdlib test case 2:strtoul(base=2) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 2:strtoul(base=2) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(6UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0XDEFE 0666 4294967295 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_003
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul003, Function | MediumTest | Level1)
{
char nPtr[] = " 0XDEFE 0666 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 16);
if (ret == 0XDEFEUL) {
printf("[DEMO] posix stdlib test case 3:strtoul(base=16) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 3:strtoul(base=16) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0XDEFEUL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0666 4294967295 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_004
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul004, Function | MediumTest | Level1)
{
char nPtr[] = " 0666 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 8);
if (ret == 0666UL) {
printf("[DEMO] posix stdlib test case 4:strtoul(base=8) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 4:strtoul(base=8) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0666UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 4294967295 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_005
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul005, Function | MediumTest | Level1)
{
char nPtr[] = " 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 4294967295UL) {
printf("[DEMO] posix stdlib test case 5:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 5:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(4294967295UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_006
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul006, Function | MediumTest | Level1)
{
char nPtr[] = " 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 0UL) {
printf("[DEMO] posix stdlib test case 6:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 6:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_007
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul007, Function | MediumTest | Level1)
{
char nPtr[] = " 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 65);
if (ret == 67UL) {
printf("[DEMO] posix stdlib test case 7:strtoul(base=65) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 7:strtoul(base=65) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(67UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, ".34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_008
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul008, Function | MediumTest | Level1)
{
char nPtr[] = ".34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 0UL) {
printf("[DEMO] posix stdlib test case 8:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 8:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, ".34");
}
/**
* @tc.number : TEST_STDLIB_STRTOUL_009
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul009, Function | MediumTest | Level1)
{
char nPtr[] = "0XDEFE 0666";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 0XDEFE) {
printf("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0XDEFE, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0666");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_010
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul010, Function | MediumTest | Level1)
{
char nPtr[] = " 0666";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 0666) {
printf("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0666, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, "");
}
RUN_TEST_SUITE(PosixStdlibStrtoulTest);
void PosixStdlibStrtoulFuncTest()
{
LOG("begin PosixStdlibStrtoulFuncTest....");
RUN_ONE_TESTCASE(testStdlibStrtoul001);
RUN_ONE_TESTCASE(testStdlibStrtoul002);
RUN_ONE_TESTCASE(testStdlibStrtoul003);
RUN_ONE_TESTCASE(testStdlibStrtoul004);
RUN_ONE_TESTCASE(testStdlibStrtoul005);
RUN_ONE_TESTCASE(testStdlibStrtoul006);
RUN_ONE_TESTCASE(testStdlibStrtoul007);
RUN_ONE_TESTCASE(testStdlibStrtoul008);
RUN_ONE_TESTCASE(testStdlibStrtoul009);
RUN_ONE_TESTCASE(testStdlibStrtoul010);
return;
}

View File

@@ -0,0 +1,276 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixStdlibStrtoullTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtoullTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtoullTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_001
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull001, Function | MediumTest | Level1)
{
char nPtr[] = "12 0110 0XDEFE 0666 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 10);
if (ret == 12ULL) {
printf("[DEMO] posix stdlib test case 1:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 1:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 12ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_002
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull002, Function | MediumTest | Level1)
{
char nPtr[] = " 0110 0XDEFE 0666 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 2);
if (ret == 6ULL) {
printf("[DEMO] posix stdlib test case 2:strtoull(base=2) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 2:strtoull(base=2) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 6ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0XDEFE 0666 1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_003
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull003, Function | MediumTest | Level1)
{
char nPtr[] = " 0XDEFE 0666 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 16);
if (ret == 0XDEFEULL) {
printf("[DEMO] posix stdlib test case 3:strtoull(base=16) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 3:strtoull(base=16) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0XDEFEULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0666 1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_004
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull004, Function | MediumTest | Level1)
{
char nPtr[] = " 0666 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 8);
if (ret == 0666ULL) {
printf("[DEMO] posix stdlib test case 4:strtoull(base=8) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 4:strtoull(base=8) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0666ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_005
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull005, Function | MediumTest | Level1)
{
char nPtr[] = " 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 65);
if (ret == 1ULL) {
printf("[DEMO] posix stdlib test case 5:strtoull(base=65) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 5:strtoull(base=65) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 1ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, ".6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_006
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull006, Function | MediumTest | Level1)
{
char nPtr[] = ".6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 0);
if (ret == 0ULL) {
printf("[DEMO] posix stdlib test case 6:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 6:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, ".6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_007
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull007, Function | MediumTest | Level1)
{
char nPtr[] = "18446744073709551615 18446744073709551616";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 10);
if (ret == 18446744073709551615ULL) {
printf("[DEMO] posix stdlib test case 7:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 7:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 18446744073709551615ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 18446744073709551616");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_008
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull008, Function | MediumTest | Level1)
{
char nPtr[] = " 18446744073709551616";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 10);
if (ret == 0ULL) {
printf("[DEMO] posix stdlib test case 8:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 8:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_009
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull009, Function | MediumTest | Level1)
{
char nPtr[] = "0XDEFE 0666";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 0);
if (ret == 0XDEFEULL) {
printf("[DEMO] posix stdlib test case 9:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 9:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0XDEFEULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0666");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_010
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull010, Function | MediumTest | Level1)
{
char nPtr[] = " 0666";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 0);
if (ret == 0666ULL) {
printf("[DEMO] posix stdlib test case 10:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
printf("[DEMO] posix stdlib test case 10:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0666ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, "");
}
RUN_TEST_SUITE(PosixStdlibStrtoullTest);
void PosixStdlibStrtoullFuncTest()
{
LOG("begin PosixStdlibStrtoullFuncTest....");
RUN_ONE_TESTCASE(testStdlibStrtoull001);
RUN_ONE_TESTCASE(testStdlibStrtoull002);
RUN_ONE_TESTCASE(testStdlibStrtoull003);
RUN_ONE_TESTCASE(testStdlibStrtoull004);
RUN_ONE_TESTCASE(testStdlibStrtoull005);
RUN_ONE_TESTCASE(testStdlibStrtoull006);
RUN_ONE_TESTCASE(testStdlibStrtoull007);
RUN_ONE_TESTCASE(testStdlibStrtoull008);
RUN_ONE_TESTCASE(testStdlibStrtoull009);
RUN_ONE_TESTCASE(testStdlibStrtoull010);
return;
}

View File

@@ -0,0 +1,374 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <string.h>
#include <stdlib.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @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 PosixMemFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixMemory, PosixMemFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixMemFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixMemFuncTestSuiteTearDown(void)
{
printf("+Hello this is a memory function test+\n");
return TRUE;
}
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCPY_OPERATION_001
* @tc.name : Memony operation for memcpy test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcpy001, Function | MediumTest | Level1)
{
void *retValue = NULL;
char source[]={"This File is About Memony Operation Test , Please Carefully Check Result As Below\r\n"};
char dest[1024]={0};
retValue = memcpy(dest, source, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
retValue = memcpy(source, dest, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
TEST_ASSERT_EQUAL_STRING(dest, source);
int len;
char chr = 'A';
char buf[1024];
len = sizeof(buf) / sizeof(buf[0]);
for (int i = 0; i < len; i++) {
buf[i] = chr + rand() % 26;
}
memcpy(&buf[16], &buf[0], 16);
for (int i = 0; i < 16; i++) {
TEST_ASSERT_EQUAL_INT((int)buf[i + 16], (int)buf[i]);
if (buf[i + 16] != buf[i]) {
printf("String Copy error \r\n");
break;
}
}
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCPY_OPERATION_002
* @tc.name : Memony operation for memcpy test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcpy002, Function | MediumTest | Level1)
{
void *retValue = NULL;
char source[]={"memory refers to the computer hardware devices used to store information for"
" immediate use in a computer\r\n"};
char dest[1024]={0};
retValue = memcpy(dest, source, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
retValue = memcpy(source, dest, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
TEST_ASSERT_EQUAL_STRING(source, dest);
char chr = 'A';
int i, len, failure;
char src[1024];
char dst[1024];
len = rand() % 1024;
for (i = 0; i < len; i++) {
src[i] = chr + i % 26;
}
memcpy(dst, src, len);
failure = 0;
for (i = 0; i < len; i++) {
if (dst[i] != src[i]) {
failure = 1;
break;
}
}
TEST_ASSERT_EQUAL_INT(failure, 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMSET_OPERATION_001
* @tc.name : Memony operation for memset test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemset001, Function | MediumTest | Level1)
{
void *retValue = NULL;
char source[1024]={"memory refers to the computer hardware devices used to store information for"
" immediate use in a computer\r\n"};
char ch = rand() % 26 + 'A';
retValue = memset(source, ch, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
TEST_ASSERT_EQUAL_PTR(retValue, source);
for (int i = 0; i < (sizeof(source) / sizeof(source[0])); i++) {
TEST_ASSERT_EQUAL_INT((int)source[i], (int)ch);
}
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCMP_OPERATION_001
* @tc.name : Memony operation for memcmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp001, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"memory refers to the computer hardware devices used to store information for "
"immediate use in a computer\r\n"};
char dest[]={"memory refers to the computer hardware devices used to store information for "
"immediate use in a computer\r\n"};
TEST_ASSERT_EQUAL_STRING(source, dest);
retValue = memcmp(source, dest, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_EQUAL_INT(retValue, 0);
char orign[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
char lt[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x77};
char eq[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
char gt[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x99};
int ret;
int len = sizeof(orign);
ret = memcmp(orign, lt, len);
TEST_ASSERT_LESS_THAN(ret, 0);
ret = memcmp(eq, orign, len);
TEST_ASSERT_EQUAL_INT(ret, 0);
ret = memcmp(orign, gt, len);
TEST_ASSERT_GREATER_THAN(ret, 0);
ret = memcmp(gt, orign, 0);
TEST_ASSERT_EQUAL_INT(ret, 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCMP_OPERATION_002
* @tc.name : Memony operation for memcmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp002, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"memory refers to the computer hardware devices used to store information for "
"immediate use in a computer\r\n"};
char dest[]={"Hello, Richard, how are you?\r\n"};
retValue = memcmp(source, dest, sizeof(dest) / sizeof(dest[0]));
TEST_ASSERT_EQUAL_INT(retValue, 1);
int ret = memcmp(L"CBCDEFG", L"BBCDEFG", 7);
TEST_ASSERT_LESS_THAN(ret, 0);
ret = memcmp(L"ABCDEFG", L"abcdefg", 2);
TEST_ASSERT_GREATER_THAN(ret, 0);
ret = memcmp(L"ABCDEFG", L"ABCDEFG", 6);
TEST_ASSERT_EQUAL_INT(ret, 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCMP_OPERATION_003
* @tc.name : Memony operation for memcmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp003, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"00000\r\n"};
char dest[]={"memory refers to the computer hardware devices used to store information for "
"immediate use in a computer\r\n"};
retValue = memcmp(source, dest, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_EQUAL_INT(retValue, -1);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_REALLOC_OPERATION_001
* @tc.name : Memony operation for realloc test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc001, Function | MediumTest | Level1)
{
char *source = (char *)malloc(20);
source = (char *)realloc(source, 0);
TEST_ASSERT_NULL(source);
size_t k, len, mlen, rlen;
for (int i = 0; i < 5; i++) {
char *mem = NULL;
char *data = NULL;
int failure = 0;
const char testChar = 0x36;
mlen = 10;
mem = malloc(mlen);
TEST_ASSERT_NOT_NULL(mem);
memset(mem, testChar, mlen);
rlen = rand() % (1024) + mlen;
mem = realloc(mem, rlen);
TEST_ASSERT_NOT_NULL(mem);
len = mlen <= rlen ? mlen : rlen;
data = (char *)mem;
for (k = 0; k < len; k++) {
if (data[k] != testChar) {
failure = 1;
}
}
free(mem);
TEST_ASSERT_EQUAL_INT(failure, 0);
}
};
/* *
* @tc.number : SUB_KERNEL_POSIX_REALLOC_OPERATION_002
* @tc.name : Memony operation for realloc test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc002, Function | MediumTest | Level1)
{
char *source = (char *)malloc(20);
char *newData = (char *)realloc(source, 40);
TEST_ASSERT_NOT_NULL(newData);
if (newData != NULL) {
source = newData;
}
free(source);
const size_t len = 1024;
const size_t large = 4096;
void *mem = malloc(len);
TEST_ASSERT_NOT_NULL(mem);
void *reMem = realloc(mem, large);
TEST_ASSERT_NOT_NULL(reMem);
if (reMem != NULL) {
mem = reMem;
}
free(mem);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_REALLOC_OPERATION_003
* @tc.name : Memony operation for realloc test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc003, Function | MediumTest | Level1)
{
char *retValue = NULL;
retValue = (char *)realloc(retValue, 20);
TEST_ASSERT_NOT_NULL(retValue);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_REALLOC_OPERATION_004
* @tc.name : Memony operation for realloc test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc004, Function | MediumTest | Level1)
{
char *source = (char *)malloc(20);
char *newData = (char *)realloc(source, 10);
TEST_ASSERT_NOT_NULL(newData);
if (newData != NULL) {
source = newData;
}
free(source);
};
RUN_TEST_SUITE(PosixMemFuncTestSuite);
void PosixStringMemTest03()
{
LOG("begin PosixStringMemTest03....");
RUN_ONE_TESTCASE(testOsMemMemcpy001);
RUN_ONE_TESTCASE(testOsMemMemcpy002);
RUN_ONE_TESTCASE(testOsMemMemset001);
RUN_ONE_TESTCASE(testOsMemMemcmp001);
RUN_ONE_TESTCASE(testOsMemMemcmp002);
RUN_ONE_TESTCASE(testOsMemMemcmp003);
RUN_ONE_TESTCASE(testOsMemRealloc001);
RUN_ONE_TESTCASE(testOsMemRealloc002);
RUN_ONE_TESTCASE(testOsMemRealloc003);
RUN_ONE_TESTCASE(testOsMemRealloc004);
return;
}

View File

@@ -0,0 +1,183 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "log.h"
/* *
* @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(Posix, Posixtimer, PosixStringStrchrTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringStrchrTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringStrchrTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STRING_STRCHR_001
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr001, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, '!');
if (strcmp(ret, "!! world") == 0) {
printf("[DEMO] posix string test case 1:strchr(!) %s ok.\n", src);
} else {
printf("[DEMO] posix string test case 1:strchr(!) %s fail.\n", src);
}
TEST_ASSERT_EQUAL_STRING(ret, "!! world");
}
/* *
* @tc.number : TEST_STRING_STRCHR_002
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr002, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, 'l');
if (strcmp(ret, "llo !! world") == 0) {
printf("[DEMO] posix string test case 2:strchr(l) %s ok.\n", src);
} else {
printf("[DEMO] posix string test case 2:strchr(l) %s fail.\n", src);
}
TEST_ASSERT_EQUAL_STRING(ret, "llo !! world");
}
/* *
* @tc.number : TEST_STRING_STRCHR_003
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr003, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, '\0');
if (ret != NULL) {
printf("[DEMO] posix string test case 3:strchr(\'\\0\') %s ok.\n", src);
} else {
printf("[DEMO] posix string test case 3:strchr(\'\\0\') %s fail.\n", src);
}
TEST_ASSERT_NOT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRCHR_004
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr004, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, '?');
if (ret == NULL) {
printf("[DEMO] posix string test case 4(except):strchr(?) %s ok.\n", src);
} else {
printf("[DEMO] posix string test case 4(except):strchr(?) %s fail.\n", src);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRCHR_005
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr005, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, 'm');
if (ret == NULL) {
printf("[DEMO] posix string test case 5(except):strchr(m) %s ok.\n", src);
} else {
printf("[DEMO] posix string test case 5(except):strchr(m) %s fail.\n", src);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRCHR_005
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr006, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, 0);
if (ret != NULL) {
printf("[DEMO] posix string test case 6(except):strchr(0) %s ok.\n", src);
} else {
printf("[DEMO] posix string test case 6(except):strchr(0) %s fail.\n", src);
}
TEST_ASSERT_NOT_NULL(ret);
}
RUN_TEST_SUITE(PosixStringStrchrTest);
void PosixStringStrchrTest()
{
LOG("begin PosixStringStrchrTest....");
RUN_ONE_TESTCASE(testStringStrchr001);
RUN_ONE_TESTCASE(testStringStrchr002);
RUN_ONE_TESTCASE(testStringStrchr003);
RUN_ONE_TESTCASE(testStringStrchr004);
RUN_ONE_TESTCASE(testStringStrchr005);
RUN_ONE_TESTCASE(testStringStrchr006);
return;
}

View File

@@ -0,0 +1,339 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#define RET_OK 0
/* *
* @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(Posix, Posixtimer, PosixStringFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringFuncTestSuiteTearDown(void)
{
printf("==== [ String TEST ] ====\n\n");
return TRUE;
}
/* *
* @tc.number TEST_STRING_STRLEN_001
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen001, Function | MediumTest | Level1)
{
char src[] = "helloworld";
int ret = strlen(src);
TEST_ASSERT_EQUAL_INT(ret, 10);
}
/* *
* @tc.number TEST_STRING_STRLEN_002
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen002, Function | MediumTest | Level1)
{
char src[] = "hello world";
int ret = strlen(src);
TEST_ASSERT_EQUAL_INT(ret, 11);
}
/* *
* @tc.number TEST_STRING_STRLEN_003
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen003, Function | MediumTest | Level1)
{
int ret = strlen("");
TEST_ASSERT_EQUAL_INT(ret, 0);
}
/* *
* @tc.number TEST_STRING_STRLEN_004
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen004, Function | MediumTest | Level1)
{
char src[] = "hello\0world";
int ret = strlen(src);
TEST_ASSERT_EQUAL_INT(ret, 5);
}
/* *
* @tc.number TEST_STRING_STRLEN_005
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen005, Function | MediumTest | Level1)
{
char src[] = "\0helloworld";
int ret = strlen(src);
TEST_ASSERT_EQUAL_INT(ret, 0);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_001
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp001, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "HElloworld"};
int ret = strncasecmp(src[0], src[1], 2);
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_002
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp002, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "he\0lloworld"};
int ret = strncasecmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_003
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp003, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "he lloworld"};
int ret = strncasecmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_004
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp004, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "hello World"};
int ret = strncasecmp(src[0], src[1], 3);
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_005
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp005, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "\0"};
int ret = strncasecmp(src[0], src[1], 1);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_001
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp001, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "HELloworld"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_002
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp002, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "he\0lloworld"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_003
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp003, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "he lloworld"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_004
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp004, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "hello World"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_005
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp005, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "\0"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_001
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr001, Function | MediumTest | Level1)
{
char src[] = "hello world";
char *ret = strrchr(src, '!');
TEST_ASSERT_EQUAL_PTR(ret, NULL);
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_002
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr002, Function | MediumTest | Level1)
{
char src[] = "hello world";
char *ret = strrchr(src, '\0');
TEST_ASSERT_EQUAL_PTR(ret, src + 11);
TEST_ASSERT_NOT_NULL(ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_003
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr003, Function | MediumTest | Level1)
{
char src[] = "hello\0world";
char *ret = strrchr(src, '\0');
TEST_ASSERT_EQUAL_PTR(ret, src + 5);
TEST_ASSERT_NOT_NULL(ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_004
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr004, Function | MediumTest | Level1)
{
char src[] = "hello world";
char *ret = strrchr(src, ' ');
TEST_ASSERT_EQUAL_PTR(ret, src + 5);
TEST_ASSERT_NOT_NULL(ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_005
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr005, Function | MediumTest | Level1)
{
char src[] = "hello\0world";
char *ret = strrchr(src, ' ');
TEST_ASSERT_EQUAL_PTR(ret, NULL);
TEST_ASSERT_NULL(ret);
}
RUN_TEST_SUITE(PosixStringFuncTestSuite);
void PosixStringFuncTest02()
{
LOG("begin PosixStringFuncTest02....");
RUN_ONE_TESTCASE(testStringStrlen001);
RUN_ONE_TESTCASE(testStringStrlen002);
RUN_ONE_TESTCASE(testStringStrlen003);
RUN_ONE_TESTCASE(testStringStrlen004);
RUN_ONE_TESTCASE(testStringStrlen005);
RUN_ONE_TESTCASE(testStringStrncasecmp001);
RUN_ONE_TESTCASE(testStringStrncasecmp002);
RUN_ONE_TESTCASE(testStringStrncasecmp003);
RUN_ONE_TESTCASE(testStringStrncasecmp004);
RUN_ONE_TESTCASE(testStringStrncasecmp005);
RUN_ONE_TESTCASE(testStringStrncmp001);
RUN_ONE_TESTCASE(testStringStrncmp002);
RUN_ONE_TESTCASE(testStringStrncmp003);
RUN_ONE_TESTCASE(testStringStrncmp004);
RUN_ONE_TESTCASE(testStringStrncmp005);
RUN_ONE_TESTCASE(testStringStrrchr001);
RUN_ONE_TESTCASE(testStringStrrchr002);
RUN_ONE_TESTCASE(testStringStrrchr003);
RUN_ONE_TESTCASE(testStringStrrchr004);
RUN_ONE_TESTCASE(testStringStrrchr005);
return;
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "los_debug.h"
#include "kernel_test.h"
#define EQUAL 0
/* *
* @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 PosixStringsFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixStrings, PosixStringsFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringsFuncTestSuiteSetUp(void)
{
PRINT_EMG("+-------------------------------------------+\n");
PRINT_EMG("+------PosixStringsFuncTestSuiteSetUp-------+\n");
PRINT_EMG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringsFuncTestSuiteTearDown(void)
{
PRINT_EMG("+-------------------------------------------+\n");
PRINT_EMG("+-----PosixStringsFuncTestSuiteTearDown-----+\n");
PRINT_EMG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number SUB_KERNEL_IO_STRINGS_0100
* @tc.name strcasecmp basic function test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringsFuncTestSuite, testStrCaseCmp001, Function | MediumTest | Level1)
{
int ret = strcasecmp("", "");
TEST_ASSERT_EQUAL_INT(ret, EQUAL);
ret = strcasecmp("abcdefg", "abcdefg");
TEST_ASSERT_EQUAL_INT(ret, EQUAL);
ret = strcasecmp("abcdefg", "abcdEFg");
TEST_ASSERT_EQUAL_INT(ret, EQUAL);
ret = strcasecmp("abcdefg", "abcdEF");
TEST_ASSERT_NOT_EQUAL(ret, EQUAL);
ret = strcasecmp("abcdef", "abcdEFg");
TEST_ASSERT_NOT_EQUAL(ret, EQUAL);
};
RUN_TEST_SUITE(PosixStringsFuncTestSuite);
void PosixStringStrcasecmpFuncTest()
{
PRINT_EMG("begin PosixStringStrcasecmpFuncTest....");
RUN_ONE_TESTCASE(testStrCaseCmp001);
return;
}

View File

@@ -0,0 +1,240 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 <string.h>
#include <stdlib.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#include <time.h>
/* *
* @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 PosixStringFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixstring, PosixStringFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringFuncTestSuiteTearDown(void)
{
printf("+Hello this is a String function test+\n");
return TRUE;
}
/* *
* @tc.number : SUB_KERNEL_POSIX_STRING_OPERATION_001
* @tc.name : Memony operation for strcmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrstrcmp001, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"Compiler exited with error"};
char dest[] ={"Compiler exited with error"};
retValue = strcmp(source, dest);
TEST_ASSERT_EQUAL_INT(retValue, 0);
int ret = strcmp("abcdef", "ABCDEF");
TEST_ASSERT_LESS_THAN(ret, 0);
ret = strcmp("123456", "654321");
TEST_ASSERT_GREATER_THAN(ret, 0);
TEST_ASSERT_EQUAL_INT(strcmp("~!@#$%^&*()_+", "~!@#$%^&*()_+"), 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strcmp_OPERATION_002
* @tc.name : Memony operation for strncmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrstrcmp002, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"Compiler exited with error"};
char dest[] ={"00000000000"};
retValue = strcmp(source, dest);
TEST_ASSERT_LESS_THAN(retValue, 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strcmp_OPERATION_003
* @tc.name : Memony operation for strncmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrstrcmp003, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"0000000"};
char dest[] ={"Compiler exited with error"};
retValue = strcmp(source, dest);
TEST_ASSERT_GREATER_THAN(retValue, 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strdup_OPERATION_001
* @tc.name : Memony operation for strdup test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrdup001, Function | MediumTest | Level1)
{
char source[]={"Compiler exited with error"};
char *dest;
dest = strdup(source);
TEST_ASSERT_NOT_NULL(dest);
printf("The Result Display :%s\r\n", dest);
TEST_ASSERT_EQUAL_CHAR_ARRAY(dest, source, sizeof(source) / sizeof(source[0]));
char src[] = "hello world !";
char *ret = strdup(src);
TEST_ASSERT_EQUAL_CHAR_ARRAY(ret, src, sizeof(src) / sizeof(src[0]));
char srcS[] = "This is String1";
ret = strdup(srcS);
TEST_ASSERT_EQUAL_CHAR_ARRAY(ret, "This is String1", sizeof(srcS) / sizeof(srcS[0]));
free(ret);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strdup_OPERATION_002
* @tc.name : Memony operation for strdup test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrdup002, Function | MediumTest | Level1)
{
char source[]={"export MY_TEST_PATH=/opt/hadoop-2.6.5"};
char *dest;
dest = strdup(source);
TEST_ASSERT_NOT_NULL(dest);
printf("The Result Display :%s\r\n", dest);
TEST_ASSERT_EQUAL_CHAR_ARRAY(dest, source, sizeof(source) / sizeof(source[0]));
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strcspn_OPERATION_001
* @tc.name : Memony operation for strcspn test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrcspn001, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"export MY_TEST_PATH=/opt/hadoop-2.6.5"};
char dest1[] ={"H"};
retValue = strcspn(source, dest1);
TEST_ASSERT_EQUAL_INT(retValue, 19U);
const char dest[] = "hello world !";
const char src[] = "!";
size_t ret = strcspn(dest, src);
TEST_ASSERT_EQUAL_INT(ret, 12U);
const char srcS[] = "a";
ret = strcspn(dest, srcS);
TEST_ASSERT_EQUAL_INT(ret, 13U);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strcspn_OPERATION_002
* @tc.name : Memony operation for strcspn test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrcspn002, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"Compiler exited with error"};
char dest[] ={"or"};
retValue = strcspn(source, dest);
TEST_ASSERT_LESS_OR_EQUAL(retValue, 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strptime_OPERATION_001
* @tc.name : Memony operation for strptime test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrptime001, Function | MediumTest | Level1)
{
struct tm tmData;
memset_s(&tmData, sizeof(struct tm), 0, sizeof(struct tm));
char *ret = strptime("2020-10-29 21:24:00abc", "%Y-%m-%d %H:%M:%S", &tmData);
TEST_ASSERT_EQUAL_CHAR_ARRAY(ret, "abc", 3);
TEST_ASSERT_EQUAL_INT(tmData.tm_year, 120);
TEST_ASSERT_EQUAL_INT(tmData.tm_mon, 9);
TEST_ASSERT_EQUAL_INT(tmData.tm_mday, 29);
TEST_ASSERT_EQUAL_INT(tmData.tm_hour, 21);
TEST_ASSERT_EQUAL_INT(tmData.tm_min, 24);
}
RUN_TEST_SUITE(PosixStringFuncTestSuite);
void PosixStringFuncTest03()
{
LOG("begin PosixStringFuncTest03....");
RUN_ONE_TESTCASE(testStrstrcmp001);
RUN_ONE_TESTCASE(testStrstrcmp002);
RUN_ONE_TESTCASE(testStrstrcmp003);
RUN_ONE_TESTCASE(testStrStrdup001);
RUN_ONE_TESTCASE(testStrStrdup002);
RUN_ONE_TESTCASE(testStrStrcspn001);
RUN_ONE_TESTCASE(testStrStrcspn002);
RUN_ONE_TESTCASE(testStrStrptime001);
return;
}

View File

@@ -0,0 +1,313 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
/* *
* @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(Posix, Posixtimer, PosixStringStrStrTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringStrStrTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringStrStrTestTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STRING_STRSTR_001
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr001, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcS[] = "string";
char *ret = strstr(destS, srcS);
if (strcmp(ret, destS) == 0) {
printf("[DEMO] posix string test case 1:strstr(%s) %s ok.\n", srcS, destS);
} else {
printf("[DEMO] posix string test case 1:strstr(%s) %s fail.\n", srcS, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, destS);
}
/* *
* @tc.number : TEST_STRING_STRSTR_002
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr002, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcS[] = "this is";
char *ret = strstr(destS, srcS);
if (strcmp(ret, "this is string") == 0) {
printf("[DEMO] posix string test case 2:strstr(%s) %s ok.\n", srcS, destS);
} else {
printf("[DEMO] posix string test case 2:strstr(%s) %s fail.\n", srcS, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_003
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr003, Function | MediumTest | Level1)
{
const char dest[] = "hello world !";
const char srcT[] = "\0hello";
char *ret = strstr(dest, srcT);
if (strcmp(ret, dest) == 0) {
printf("[DEMO] posix string test case 3:strstr(%s) %s ok.\n", srcT, dest);
} else {
printf("[DEMO] posix string test case 3:strstr(%s) %s fail.\n", srcT, dest);
}
TEST_ASSERT_EQUAL_STRING(ret, dest);
}
/* *
* @tc.number : TEST_STRING_STRSTR_004
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr004, Function | MediumTest | Level1)
{
const char dest[] = "hello world !";
const char src[] = "heAlo";
char *ret = strstr(dest, src);
if (ret == NULL) {
printf("[DEMO] posix string test case 4(except):strstr(%s) %s ok.\n", src, dest);
} else {
printf("[DEMO] posix string test case 4(except):strstr(%s) %s fail.\n", src, dest);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_005
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr005, Function | MediumTest | Level1)
{
const char dest[] = "hello world !";
const char src[] = "hellm";
char *ret = strstr(dest, src);
if (ret == NULL) {
printf("[DEMO] posix string test case 5(except):strstr(%s) %s ok.\n", src, dest);
} else {
printf("[DEMO] posix string test case 5(except):strstr(%s) %s fail.\n", src, dest);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_006
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr006, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcOne[] = "t"; // one byte
char *ret = strstr(destS, srcOne);
if (strcmp(ret, "tring this is string") == 0) {
printf("[DEMO] posix string test case 6:strstr(%s) %s ok.\n", srcOne, destS);
} else {
printf("[DEMO] posix string test case 6:strstr(%s) %s fail.\n", srcOne, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "tring this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_007
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr007, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcOne[] = "m"; // one byte
char *ret = strstr(destS, srcOne);
if (ret == NULL) {
printf("[DEMO] posix string test case 7(except):strstr(%s) %s ok.\n", srcOne, destS);
} else {
printf("[DEMO] posix string test case 7(except):strstr(%s) %s fail.\n", srcOne, destS);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_008
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr008, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcTwo[] = "th"; // two byte
char *ret = strstr(destS, srcTwo);
if (strcmp(ret, "this is string") == 0) {
printf("[DEMO] posix string test case 8:strstr(%s) %s ok.\n", srcTwo, destS);
} else {
printf("[DEMO] posix string test case 8:strstr(%s) %s fail.\n", srcTwo, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_009
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr009, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcTwo2[] = "tm"; // two byte
char *ret = strstr(destS, srcTwo2);
if (ret == NULL) {
printf("[DEMO] posix string test case 9(except):strstr(%s) %s ok.\n", srcTwo2, destS);
} else {
printf("[DEMO] posix string test case 9(except):strstr(%s) %s fail.\n", srcTwo2, destS);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_010
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr010, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcThree[] = "thi"; // three byte
char *ret = strstr(destS, srcThree);
if (strcmp(ret, "this is string") == 0) {
printf("[DEMO] posix string test case 10:strstr(%s) %s ok.\n", srcThree, destS);
} else {
printf("[DEMO] posix string test case 10:strstr(%s) %s fail.\n", srcThree, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_011
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr011, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcThree[] = "thm"; // three byte
char *ret = strstr(destS, srcThree);
if (ret == NULL) {
printf("[DEMO] posix string test case 11(except):strstr(%s) %s ok.\n", srcThree, destS);
} else {
printf("[DEMO] posix string test case 11(except):strstr(%s) %s fail.\n", srcThree, destS);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_012
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr012, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcFour[] = "this"; // four byte
char *ret = strstr(destS, srcFour);
if (strcmp(ret, "this is string") == 0) {
printf("[DEMO] posix string test case 12:strstr(%s) %s ok.\n", srcFour, destS);
} else {
printf("[DEMO] posix string test case 12:strstr(%s) %s fail.\n", srcFour, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_013
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr013, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcFour[] = "thim"; // four byte
char *ret = strstr(destS, srcFour);
if (ret == NULL) {
printf("[DEMO] posix string test case 13(except):strstr(%s) %s ok.\n", srcFour, destS);
} else {
printf("[DEMO] posix string test case 13(except):strstr(%s) %s fail.\n", srcFour, destS);
}
TEST_ASSERT_NULL(ret);
}
RUN_TEST_SUITE(PosixStringStrStrTest);

View File

@@ -0,0 +1,606 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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/time.h>
#include <sys/times.h>
#include <time.h>
#include <errno.h>
#include <limits.h>
#include <los_debug.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "securec.h"
#include "kernel_test.h"
#define RET_OK 0
#define SLEEP_ACCURACY 21000 // 20 ms, with 1ms deviation
#define ACCURACY_TEST_LOOPS 3 // loops for accuracy test, than count average value
#define MILLISECONDS_PER_SECOND 1000
#define NANOSECONDS_PER_MILLISECOND 1000000
#define TM_BASE_YEAR 1900
#define TIME_STR_LEN 100
#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 = 7; \
} while (0)
/* *
* @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(Posix, PosixTime, PosixTimeFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixTimeFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixTimeFuncTestSuiteTearDown(void)
{
return TRUE;
}
static int KeepRun(int msec)
{
struct timespec time1 = { 0, 0 };
struct timespec time2 = { 0, 0 };
clock_gettime(CLOCK_MONOTONIC, &time1);
PRINT_EMG("KeepRun start : tv_sec=%ld, tv_nsec=%ld\n", time1.tv_sec, time1.tv_nsec);
int loop = 0;
int runned = 0;
while (runned < msec) {
++loop;
clock_gettime(CLOCK_MONOTONIC, &time2);
runned = (time2.tv_sec - time1.tv_sec) * MILLISECONDS_PER_SECOND;
runned += (time2.tv_nsec - time1.tv_nsec) / NANOSECONDS_PER_MILLISECOND;
}
PRINT_EMG("KeepRun end : tv_sec=%ld, tv_nsec=%ld\n", time2.tv_sec, time2.tv_nsec);
return loop;
}
static int CheckValueClose(double target, double actual, double accuracy)
{
double diff = actual - target;
double pct;
if (diff < 0) {
diff = -diff;
}
if (actual == 0) {
return 0;
} else {
pct = diff / actual;
}
return (pct <= accuracy);
}
static char *TmToStr(const struct tm *stm, char *timeStr, unsigned len)
{
if (stm == NULL || timeStr == NULL) {
return "";
}
sprintf_s(timeStr, len, "%ld/%d/%d %02d:%02d:%02d WEEK(%d)", stm->tm_year + TM_BASE_YEAR, stm->tm_mon + 1,
stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec, stm->tm_wday);
return timeStr;
}
/* *
* @tc.number SUB_KERNEL_TIME_USLEEP_001
* @tc.name usleep accuracy test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep001, Function | MediumTest | Level1)
{
// wifiiot无法支持10ms以下的sleep
int interval[] = {15*1000, 20*1000, 30*1000, 300*1000};
for (unsigned int j = 0; j < sizeof(interval) / sizeof(int); j++) {
PRINT_EMG("\ntest interval:%d\n", interval[j]);
struct timespec time1 = { 0 }, time2 = { 0 };
long duration; // unit: us
double d = 0.0;
for (int i = 1; i <= ACCURACY_TEST_LOOPS; i++) {
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = usleep(interval[j]);
clock_gettime(CLOCK_MONOTONIC, &time2);
TEST_ASSERT_EQUAL_INT(RET_OK, rt);
duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000;
PRINT_EMG("testloop %d, actual usleep duration: %ld us\n", i, duration);
d += duration;
}
d = d / ACCURACY_TEST_LOOPS; // average
PRINT_EMG("interval:%u, average duration: %.2f\n", interval[j], d);
TEST_ASSERT_GREATER_OR_EQUAL(interval[j], d);
TEST_ASSERT_INT32_WITHIN(SLEEP_ACCURACY, interval[j], d);
}
}
/* *
* @tc.number SUB_KERNEL_TIME_USLEEP_002
* @tc.name usleep test for special delay
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep002, Function | MediumTest | Level1)
{
struct timespec time1 = { 0 };
struct timespec time2 = { 0 };
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = usleep(0);
clock_gettime(CLOCK_MONOTONIC, &time2);
TEST_ASSERT_EQUAL_INT(RET_OK, rt);
long duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000;
PRINT_EMG("\n usleep(0), actual usleep duration: %ld us\n", duration);
TEST_ASSERT_LESS_OR_EQUAL_UINT32(1000, duration);
}
/* *
* @tc.number SUB_KERNEL_TIME_USLEEP_003
* @tc.name usleep test for invlid delay
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep003, Function | MediumTest | Level1)
{
struct timespec time1 = { 0 };
struct timespec time2 = { 0 };
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = usleep(1000000);
clock_gettime(CLOCK_MONOTONIC, &time2);
TEST_ASSERT_NOT_EQUAL(RET_OK, rt);
TEST_ASSERT_EQUAL_INT(EINVAL, errno);
long duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000;
PRINT_EMG("\n usleep(1000000), actual usleep duration: %ld us\n", duration);
TEST_ASSERT_LESS_OR_EQUAL_UINT32(1000, duration);
}
/* *
* @tc.number SUB_KERNEL_TIME_GMTIME_001
* @tc.name test gmtime api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeGmtime001, Function | MediumTest | Level1)
{
time_t time1 = 18880;
char timeStr[TIME_STR_LEN] = {0};
PRINT_EMG("\nsizeof(time_t) = %d", sizeof(time_t));
struct tm *stm = gmtime(&time1);
TEST_ASSERT_EQUAL_STRING("1970/1/1 05:14:40 WEEK(4)", TmToStr(stm, timeStr, TIME_STR_LEN));
time1 = LONG_MAX;
stm = gmtime(&time1);
PRINT_EMG("\n LONG_MAX = %ld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:07 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN));
time1 = LONG_MAX - 1;
stm = gmtime(&time1);
PRINT_EMG("\n LONG_MAX - 1 = %ld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:06 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN));
time1 = LONG_MIN;
stm = gmtime(&time1);
PRINT_EMG("\n LONG_MIN = %ld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:52 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN));
time1 = LONG_MIN + 1;
stm = gmtime(&time1);
PRINT_EMG("\n LONG_MIN + 1 = %ld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:53 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN));
};
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIME_001
* @tc.name test localtime api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime001, Function | MediumTest | Level1)
{
char cTime[32];
time_t tStart;
time_t tEnd;
struct timeval timeSet = {
.tv_sec = 86399,
.tv_usec = 0
};
int ret = settimeofday(&timeSet, NULL);
time(&tStart);
sleep(2);
time(&tEnd);
TEST_ASSERT_EQUAL_INT(ret, 0);
struct tm *tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
struct tm *tmEnd = localtime(&tEnd);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmEnd);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tEnd, cTime);
}
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIME_002
* @tc.name test localtime api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime002, Function | MediumTest | Level1)
{
char cTime[32];
time_t tStart = LONG_MAX;
struct tm *tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("38-01-19 03:14:07", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
tStart = LONG_MIN;
tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("01-12-13 20:45:52", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
tStart = 0;
tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("70-01-01 00:00:00", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
tStart = -1;
tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("69-12-31 23:59:59", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
}
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIMER_001
* @tc.name localtime_r api base test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer001, Function | MediumTest | Level1)
{
char cTime[32];
time_t tStart;
time_t tEnd;
struct tm tmrStart = { 0 };
struct tm tmrEnd = { 0 };
struct timeval tSet = {
.tv_sec = 86399,
.tv_usec = 0
};
int ret = settimeofday(&tSet, NULL);
time(&tStart);
sleep(2);
time(&tEnd);
TEST_ASSERT_EQUAL_INT(ret, 0);
struct tm *tmrStartPtr = localtime_r(&tStart, &tmrStart);
struct tm *tmrEndPtr = localtime_r(&tEnd, &tmrEnd);
strftime(cTime, sizeof(cTime), "%H:%M:%S", &tmrStart);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmrStartPtr);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", &tmrEnd);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmrEndPtr);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
}
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIMER_002
* @tc.name test localtime_r api for range
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer002, Function | MediumTest | Level1)
{
char cTime[32];
struct tm tmrResult = { 0 };
time_t tStart = LONG_MAX;
struct tm *tmStart = localtime_r(&tStart, &tmrResult);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("38-01-19 03:14:07", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
tStart = LONG_MIN;
tmStart = localtime_r(&tStart, &tmrResult);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("01-12-13 20:45:52", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
tStart = 0;
tmStart = localtime_r(&tStart, &tmrResult);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("70-01-01 00:00:00", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
tStart = -1;
tmStart = localtime_r(&tStart, &tmrResult);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("69-12-31 23:59:59", cTime);
PRINT_EMG("\n time_t=%ld, first time:%s", tStart, cTime);
}
/* *
* @tc.number SUB_KERNEL_TIME_MKTIME_001
* @tc.name mktime api base test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest | Level1)
{
struct tm timeptr = { 0 };
time_t testTime = 18880;
INIT_TM(timeptr, 2020, 7, 9, 10, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
TEST_ASSERT_EQUAL_INT(1596967800, timeRet);
INIT_TM(timeptr, 1970, 0, 1, 0, 0, 0, 0);
timeRet = mktime(&timeptr);
PRINT_EMG("\n 1970-1-1 00:00:00, mktime Ret = %ld", timeRet);
TEST_ASSERT_EQUAL_INT(0, timeRet);
timeRet = mktime(localtime(&testTime));
TEST_ASSERT_EQUAL_INT(18880, timeRet);
testTime = LONG_MAX;
timeRet = mktime(localtime(&testTime));
TEST_ASSERT_EQUAL_INT(LONG_MAX, timeRet);
testTime = LONG_MIN;
timeRet = mktime(localtime(&testTime));
TEST_ASSERT_EQUAL_INT(LONG_MIN, timeRet);
testTime = 0;
timeRet = mktime(localtime(&testTime));
TEST_ASSERT_EQUAL_INT(0, timeRet);
}
/* *
* @tc.number SUB_KERNEL_TIME_MKTIME_002
* @tc.name mktime api test for invalid input
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime002, Function | MediumTest | Level1)
{
struct tm timeptr = { 0 };
INIT_TM(timeptr, 1800, 7, 9, 10, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
PRINT_EMG("\n 1800-8-9 10:10:00, mktime Ret = %ld", timeRet);
TEST_ASSERT_EQUAL_INT(-1, timeRet);
TEST_ASSERT_EQUAL_INT(EOVERFLOW, errno);
INIT_TM(timeptr, 2800, 1, 1, 1, 10, 0, 7);
timeRet = mktime(&timeptr);
PRINT_EMG("\n 2800-1-1 01:10:00, mktime Ret = %ld", timeRet);
TEST_ASSERT_EQUAL_INT(-1, timeRet);
TEST_ASSERT_EQUAL_INT(EOVERFLOW, errno);
// for LONG_MAX + 1 DATETIME
INIT_TM(timeptr, 2038, 0, 19, 3, 14, 8, 2);
timeRet = mktime(&timeptr);
PRINT_EMG("\n 2038-1-19 03:14:08, mktime Ret = %ld", timeRet);
TEST_ASSERT_EQUAL_INT(-1, timeRet);
TEST_ASSERT_EQUAL_INT(EOVERFLOW, errno);
// for LONG_MIN - 1 DATETIME
INIT_TM(timeptr, 1901, 11, 13, 20, 45, 51, 5);
timeRet = mktime(&timeptr);
PRINT_EMG("\n 1901-12-13 20:45:51, mktime Ret = %ld", timeRet);
TEST_ASSERT_EQUAL_INT(-1, timeRet);
TEST_ASSERT_EQUAL_INT(EOVERFLOW, errno);
}
/* *
* @tc.number SUB_KERNEL_TIME_STRFTIME_001
* @tc.name test strftime api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime001, Function | MediumTest | Level3)
{
char buffer[80];
time_t mtime = 0;
size_t ftime = 0;
mtime = LONG_MAX;
ftime = strftime(buffer, 80, "%y-%m-%d %H:%M:%S", localtime(&mtime));
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("38-01-19 03:14:07", buffer);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "38-01-19 03:14:07");
mtime = LONG_MIN;
ftime = strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localtime(&mtime));
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("1901-12-13 20:45:52", buffer);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1901-12-13 20:45:52");
mtime = 18880;
ftime = strftime(buffer, 80, "%F %T", localtime(&mtime));
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("1970-01-01 05:14:40", buffer);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
mtime = 18880;
ftime = strftime(buffer, 80, "%D %w %H:%M:%S", localtime(&mtime));
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("01/01/70 4 05:14:40", buffer);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "01/01/70 4 05:14:40");
};
/* *
* @tc.number SUB_KERNEL_TIME_STRFTIME_002
* @tc.name test strftime api for unsupport param
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime002, Function | MediumTest | Level3)
{
char buffer[80];
time_t mtime = 18880;
size_t ftime = 0;
struct tm *tmTime = localtime(&mtime);
ftime = strftime(buffer, 80, "%Ex %EX %A", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(buffer, 80, "%x %X", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(buffer, 80, "%D %A %H:%M:%S", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(buffer, 80, "%F %T %Z", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
};
/* *
* @tc.number SUB_KERNEL_TIME_STRFTIME_003
* @tc.name test strftime api for abnormal input
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime003, Function | MediumTest | Level3)
{
char buffer[80];
time_t mtime = 18880;
size_t ftime = 0;
struct tm *tmTime = localtime(&mtime);
ftime = strftime(buffer, 12, "%Y-%m-%d %H:%M:%S", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(NULL, 80, "%Y-%m-%d %H:%M:%S", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(buffer, 80, "", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(buffer, 80, NULL, tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", NULL);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(buffer, 19, "%Y-%m-%d %H:%M:%S", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
ftime = strftime(buffer, 20, "%Y-%m-%d %H:%M:%S", tmTime);
TEST_ASSERT_EQUAL_INT(19, ftime);
TEST_ASSERT_EQUAL_STRING("1970-01-01 05:14:40", buffer);
PRINT_EMG("\nresult: %s, expected : %s", buffer, "1970-01-01 05:14:40");
};
/* *
* @tc.number SUB_KERNEL_TIME_API_TIMES_0100
* @tc.name test times basic
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimes, Function | MediumTest | Level1)
{
const int testClockt = 100;
const int msPerClock = 10;
struct tms start = { 0 };
struct tms end = { 0 };
clock_t stTime = times(&start);
PRINT_EMG("start_clock: stTime: %ld", stTime);
PRINT_EMG("start_clock: tms_utime: %ld, tms_stime: %ld, tms_cutime:%ld, tms_cstime:%ld", start.tms_utime,
start.tms_stime, start.tms_cutime, start.tms_cstime);
KeepRun(testClockt * msPerClock);
clock_t endTime = times(&end);
PRINT_EMG("end_clock: endTime: %ld", endTime);
PRINT_EMG("end_clock: tms_utime: %ld, tms_stime: %ld, tms_cutime:%ld, tms_cstime:%ld", end.tms_utime, end.tms_stime,
end.tms_cutime, end.tms_cstime);
PRINT_EMG("Real Time: %ld, User Time %ld, System Time %ld\n", (long)(endTime - stTime),
(long)(end.tms_utime - start.tms_utime), (long)(end.tms_stime - start.tms_stime));
if (!CheckValueClose((end.tms_utime - start.tms_utime), testClockt, 0.02)) {
TEST_FAIL();
}
if (!CheckValueClose((endTime - stTime), testClockt, 0.02)) {
TEST_FAIL();
}
}
RUN_TEST_SUITE(PosixTimeFuncTestSuite);
void PosixTimeFuncTest()
{
PRINT_EMG("begin PosixTimeFuncTest....");
RUN_ONE_TESTCASE(testTimeUSleep001);
RUN_ONE_TESTCASE(testTimeUSleep002);
RUN_ONE_TESTCASE(testTimeUSleep003);
RUN_ONE_TESTCASE(testTimeGmtime001);
RUN_ONE_TESTCASE(testTimeLocaltime001);
RUN_ONE_TESTCASE(testTimeLocaltime002);
RUN_ONE_TESTCASE(testTimeLocaltimer001);
RUN_ONE_TESTCASE(testTimeLocaltimer002);
RUN_ONE_TESTCASE(testTimeMktime001);
RUN_ONE_TESTCASE(testTimeMktime002);
RUN_ONE_TESTCASE(testTimeStrftime001);
RUN_ONE_TESTCASE(testTimeStrftime002);
RUN_ONE_TESTCASE(testTimeStrftime003);
RUN_ONE_TESTCASE(testTimes);
return;
}