add testsuites

Change-Id: Ice1193d1ae7f2e0d12a2a38a306a6399407f5037
This commit is contained in:
lnlan
2021-04-25 12:37:35 +08:00
parent dc90400456
commit 778c5e17c3
2720 changed files with 335022 additions and 0 deletions
+73
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("//build/lite/config/test.gni")
unittest("liteos_a_sys_unittest") {
output_extension = "bin"
output_dir = "$root_out_dir/test/unittest/kernel"
include_dirs = [
"../common/include",
"../sys",
]
sources = [
"../common/osTest.cpp",
"smoke/sys_test_001.cpp",
"smoke/sys_test_004.cpp",
"smoke/sys_test_005.cpp",
"smoke/sys_test_006.cpp",
"smoke/sys_test_007.cpp",
"smoke/sys_test_008.cpp",
"smoke/sys_test_009.cpp",
"smoke/sys_test_010.cpp",
"smoke/sys_test_012.cpp",
"smoke/sys_test_013.cpp",
"smoke/sys_test_014.cpp",
"smoke/sys_test_015.cpp",
"smoke/sys_test_016.cpp",
"smoke/sys_test_017.cpp",
"smoke/sys_test_018.cpp",
"smoke/sys_test_019.cpp",
"smoke/sys_test_020.cpp",
"smoke/sys_test_021.cpp",
"smoke/sys_test_022.cpp",
"smoke/sys_test_023.cpp",
"smoke/sys_test_024.cpp",
"smoke/sys_test_025.cpp",
"smoke/sys_test_026.cpp",
"smoke/sys_test_027.cpp",
"smoke/sys_test_028.cpp",
"smoke/sys_test_029.cpp",
"smoke/sys_test_030.cpp",
"smoke/sys_test_031.cpp",
"sys_unit_test.cpp",
]
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
configs = [ "..:public_config" ]
}
+85
View File
@@ -0,0 +1,85 @@
/*
* 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 _IT_TEST_SYS_H
#define _IT_TEST_SYS_H
#include "libgen.h"
#include "setjmp.h"
#include "fenv.h"
#include "float.h"
#include "math.h"
#include "regex.h"
#include "locale.h"
#include "pwd.h"
#include "osTest.h"
#define FE_INVALID 1
#define FE_DIVBYZERO 4
#define FE_OVERFLOW 8
#define FE_UNDERFLOW 16
#define FE_INEXACT 32
#define FE_ALL_EXCEPT 0
#define FE_TONEAREST 0
#define FE_DOWNWARD 0x400
#define FE_UPWARD 0x800
#define FE_TOWARDZERO 0xc00
extern VOID ItTestSys001(VOID);
extern VOID IT_TEST_SYS_002(VOID);
extern VOID IT_TEST_SYS_003(VOID);
extern VOID ItTestSys004(VOID);
extern VOID ItTestSys005(VOID);
extern VOID ItTestSys006(VOID);
extern VOID ItTestSys007(VOID);
extern VOID ItTestSys008(VOID);
extern VOID ItTestSys009(VOID);
extern VOID ItTestSys010(VOID);
extern VOID IT_TEST_SYS_011(VOID);
extern VOID ItTestSys012(VOID);
extern VOID ItTestSys013(VOID);
extern VOID ItTestSys014(VOID);
extern VOID ItTestSys015(VOID);
extern VOID ItTestSys016(VOID);
extern VOID ItTestSys017(VOID);
extern VOID ItTestSys018(VOID);
extern VOID ItTestSys019(VOID);
extern VOID ItTestSys020(VOID);
extern VOID ItTestSys021(VOID);
extern VOID ItTestSys022(VOID);
extern VOID ItTestSys023(VOID);
extern VOID ItTestSys024(VOID);
extern VOID ItTestSys025(VOID);
extern VOID ItTestSys026(VOID);
extern VOID ItTestSys027(VOID);
extern VOID IT_TEST_SYS_028(VOID);
extern VOID ItTestSys029(VOID);
extern VOID IT_TEST_SYS_030(VOID);
extern VOID IT_TEST_SYS_031(VOID);
#endif
@@ -0,0 +1,76 @@
/*
* 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 "It_test_sys.h"
static jmp_buf g_buf;
static UINT32 First(VOID)
{
int val = 2;
int ret = setjmp(g_buf);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, val, ret);
goto OUT1;
}
longjmp(g_buf, val);
OUT1:
return 0;
}
static UINT32 Sencond(VOID)
{
int ret = setjmp(g_buf);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
goto OUT2;
}
longjmp(g_buf, 0);
OUT2:
return 0;
}
static UINT32 TestCase(VOID)
{
int ret = First();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = Sencond();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
VOID ItTestSys001(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_024", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,54 @@
/*
* 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 "It_test_sys.h"
#define MAX_NRAND48 0x80000000
static UINT32 TestCase(VOID)
{
long x;
short unsigned int seed[3] = {1, 2, 3};
x = nrand48(seed);
if ((x < 0) || (x > MAX_NRAND48)) {
printf("[IN %s][line %d] x = %d\n", __FUNCTION__, __LINE__, x);
goto EXIT;
}
return 0;
EXIT:
return -1;
}
VOID ItTestSys004(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,53 @@
/*
* 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 "It_test_sys.h"
#define MAX_RANDOM 0x80000000
static UINT32 TestCase(VOID)
{
long x;
x = random();
if (x > labs(MAX_RANDOM - 1)) {
printf("[IN %s][line %d] x = %d\n", __FUNCTION__, __LINE__, x);
goto EXIT;
}
return 0;
EXIT:
return -1;
}
VOID ItTestSys005(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,57 @@
/*
* 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 "It_test_sys.h"
#define MAX_RANDOM 0x80000000
static unsigned int g_seed = 123;
static UINT32 TestCase(VOID)
{
int x;
unsigned *pseed = &g_seed;
x = rand_r(pseed);
printf("x= %d\n", x);
if (x > abs(int(MAX_RANDOM - 1))) {
printf("[IN %s][line %d] x = %d\n", __FUNCTION__, __LINE__, x);
goto EXIT;
}
return 0;
EXIT:
return -1;
}
VOID ItTestSys006(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,56 @@
/*
* 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 "It_test_sys.h"
#define MAX_RANDOM 0x80000000
static unsigned short g_seed = 123;
static UINT32 TestCase(VOID)
{
double x;
unsigned short *pseed = &g_seed;
unsigned short *p = NULL;
p = seed48(pseed);
ICUNIT_GOTO_NOT_EQUAL(p, NULL, p, EXIT);
x = drand48();
printf("x= %d\n", x);
return 0;
EXIT:
return -1;
}
VOID ItTestSys007(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,74 @@
/*
* 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 "It_test_sys.h"
#define BUF_SIZE 256
static UINT32 TestCase(VOID)
{
char ebuff[BUF_SIZE];
int ret;
int cflags;
regex_t reg;
char *a = NULL;
char *b = (char *)"No error";
char *testStr = (char *)"Hello World";
char *regStr = (char *)"H.*";
cflags = REG_EXTENDED | REG_ICASE | REG_NOSUB;
ret = regcomp(&reg, regStr, cflags);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = regexec(&reg, testStr, 0, NULL, 0);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
regerror(ret, &reg, ebuff, BUF_SIZE);
a = ebuff;
ret = strcmp(a, b);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
regfree(&reg);
return 0;
EXIT:
regerror(ret, &reg, ebuff, BUF_SIZE);
fprintf(stderr, "%s\n", ebuff);
regfree(&reg);
return -1;
}
VOID ItTestSys008(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,63 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
char *val = NULL;
const char *name = (char *)"ABC";
char *env = (char *)"test-test";
int ret;
val = getenv(name);
ICUNIT_GOTO_EQUAL(val, NULL, val, EXIT);
setenv(name, env, 1);
val = getenv(name);
ret = strcmp(val, env);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = unsetenv("ABC");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
val = getenv(name);
ICUNIT_GOTO_EQUAL(val, NULL, val, EXIT);
return 0;
EXIT:
return -1;
}
VOID ItTestSys009(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,51 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
char *plocale = NULL;
char *buffer = (char *)"C";
int ret;
plocale = setlocale(LC_ALL, NULL);
ret = strcmp(plocale, buffer);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
return 0;
EXIT:
return -1;
}
VOID ItTestSys010(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,67 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
char *val = NULL;
char *val2 = NULL;
const char *name = (char *)"ABC";
char *env = (char *)"test-test";
int ret;
val = getenv(name);
ICUNIT_GOTO_EQUAL(val, NULL, val, EXIT);
setenv(name, env, 1);
val = getenv(name);
val2 = secure_getenv(name);
ret = strcmp(val2, env);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = strcmp(val, env);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = unsetenv("ABC");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
val = getenv(name);
ICUNIT_GOTO_EQUAL(val, NULL, val, EXIT);
return 0;
EXIT:
return -1;
}
VOID ItTestSys012(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,83 @@
/*
* 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 "It_test_sys.h"
struct q {
struct q *n;
struct q *p;
int i;
};
static struct q *New(int i)
{
struct q *q = (struct q *)malloc(sizeof *q);
q->i = i;
return q;
}
static UINT32 TestCase(VOID)
{
struct q *q = New(0);
struct q *p = NULL;
int i;
insque(q, 0);
for (i = 1; i < 10; i++) {
insque(New(i), q);
q = q->n;
}
p = q;
while (q) {
if (q->i != --i) {
printf("[IN %s][line %d]walking queue: got %d, wanted %d\n", __FUNCTION__, __LINE__, q->i, i);
goto EXIT;
}
q = q->p;
}
remque(p->p);
if (p->p->i != p->i - 2) {
printf("[IN %s][line %d]remque: got %d, wanted %d\n", __FUNCTION__, __LINE__, p->p->i, p->i - 2);
goto EXIT;
}
if (p->p->n->i != p->i) {
printf("[IN %s][line %d]remque: got %d, wanted %d\n", __FUNCTION__, __LINE__, p->p->n->i, p->i);
goto EXIT;
}
return 0;
EXIT:
return -1;
}
VOID ItTestSys013(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,92 @@
/*
* 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 "It_test_sys.h"
static void ShowFeExceptions(void)
{
printf("current exceptions raised: ");
if (fetestexcept(FE_DIVBYZERO)) {
printf(" FE_DIVBYZERO");
}
if (fetestexcept(FE_INEXACT)) {
printf(" FE_INEXACT");
}
if (fetestexcept(FE_INVALID)) {
printf(" FE_INVALID");
}
if (fetestexcept(FE_OVERFLOW)) {
printf(" FE_OVERFLOW");
}
if (fetestexcept(FE_UNDERFLOW)) {
printf(" FE_UNDERFLOW");
}
if (fetestexcept(FE_ALL_EXCEPT) == 0) {
printf(" none");
}
printf("\n");
}
static double X2(double x) /* times two */
{
fenv_t currExcepts;
/* Save and clear current f-p environment. */
feholdexcept(&currExcepts);
/* Raise inexact and overflow exceptions. */
printf("In x2(): x = %f\n", x = x * 2.0);
ShowFeExceptions();
feclearexcept(FE_INEXACT); /* hide inexact exception from caller */
/* Merge caller's exceptions (FE_INVALID) */
/* with remaining x2's exceptions (FE_OVERFLOW). */
feupdateenv(&currExcepts);
return x;
}
static UINT32 TestCase(VOID)
{
feclearexcept(FE_ALL_EXCEPT);
feraiseexcept(FE_INVALID); /* some computation with invalid argument */
ShowFeExceptions();
printf("x2(DBL_MAX) = %f\n", X2(DBL_MAX));
ShowFeExceptions();
return 0;
EXIT:
return -1;
}
VOID ItTestSys014(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,55 @@
/*
* 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 "It_test_sys.h"
#define TEST_NUM 123
static UINT32 TestCase(VOID)
{
long a = TEST_NUM;
long b = 0;
char *pstr = NULL;
pstr = l64a(a);
ICUNIT_GOTO_NOT_EQUAL(pstr, NULL, pstr, EXIT);
b = a64l(pstr);
ICUNIT_GOTO_EQUAL(b, a, b, EXIT);
return 0;
EXIT:
return -1;
}
VOID ItTestSys015(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,66 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
char *ptr = NULL;
int ret;
ptr = basename((char *)".");
ret = strcmp(ptr, ".");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ptr = basename("..");
ret = strcmp(ptr, "..");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ptr = basename("/");
ret = strcmp(ptr, "/");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ptr = basename("test1");
ret = strcmp(ptr, "test1");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ptr = basename("/test1/test2");
ret = strcmp(ptr, "test2");
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
return 0;
EXIT:
return -1;
}
VOID ItTestSys016(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,66 @@
/*
* 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 "It_test_sys.h"
#define TEST_PASSWORD (char *)"test1234"
static UINT32 TestCase(VOID)
{
char *passwd1 = NULL;
char *passwd2 = NULL;
char *key = NULL;
char slat[2];
int ret;
key = TEST_PASSWORD;
slat[0] = key[0];
slat[1] = key[1];
passwd1 = crypt(key, slat);
ICUNIT_GOTO_NOT_EQUAL(passwd1, NULL, passwd1, EXIT);
key = TEST_PASSWORD;
slat[0] = passwd1[0];
slat[1] = passwd1[1];
passwd2 = crypt(key, slat);
ICUNIT_GOTO_NOT_EQUAL(passwd2, NULL, passwd2, EXIT);
ret = strcmp(passwd1, passwd2);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
return 0;
EXIT:
return -1;
}
VOID ItTestSys017(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,83 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
user1 = getpwnam("root");
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
user2 = getpwnam("daemon");
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
user3 = getpwnam("bin");
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
user4 = getpwnam("lyw");
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
user4 = getpwnam("");
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
return 0;
}
VOID ItTestSys018(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,101 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd pwd;
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
struct passwd *user5 = nullptr;
char buf1[1024] = { 0 };
char buf2[2] = { 0 };
int ret;
ret = getpwnam_r("root", &pwd, buf1, sizeof(buf1), &user1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1);
ret = getpwnam_r("daemon", &pwd, buf1, sizeof(buf1), &user2);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ret = getpwnam_r("bin", &pwd, buf1, sizeof(buf1), &user3);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
ret = getpwnam_r("root", &pwd, buf2, sizeof(buf2), &user4);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ret = getpwnam_r(nullptr, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(ret, 0, -1);
ret = getpwnam_r("", &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwnam_r("sssssss", &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
return 0;
}
VOID ItTestSys019(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,85 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
user1 = getpwuid(0);
ICUNIT_ASSERT_NOT_EQUAL(user1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
user2 = getpwuid(1);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
user3 = getpwuid(2);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
user4 = getpwuid(200);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
user4 = getpwuid(-100);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
user4 = getpwuid(100000);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
return 0;
}
VOID ItTestSys020(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,109 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd pwd;
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
struct passwd *user3 = nullptr;
struct passwd *user4 = nullptr;
struct passwd *user5 = nullptr;
char buf1[1024] = { 0 };
char buf2[2] = { 0 };
int ret;
ret = getpwuid_r(0, &pwd, buf1, sizeof(buf1), &user1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(pwd.pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(pwd.pw_shell, "/bin/bash", -1);
ret = getpwuid_r(1, &pwd, buf1, sizeof(buf1), &user2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user2->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user2->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_shell, "/usr/sbin/nologin", -1);
ret = getpwuid_r(2, &pwd, buf1, sizeof(buf1), &user3);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(user3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user3->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user3->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user3->pw_shell, "/usr/sbin/nologin", -1);
ret = getpwuid_r(0, &pwd, buf2, sizeof(buf2), &user4);
ICUNIT_ASSERT_EQUAL(ret, ERANGE, ret);
ICUNIT_ASSERT_EQUAL(user4, nullptr, -1);
ret = getpwuid_r(200, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwuid_r(100000, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
ret = getpwuid_r(-100, &pwd, buf1, sizeof(buf1), &user5);
ICUNIT_ASSERT_EQUAL(user5, nullptr, -1);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, -1);
return 0;
}
VOID ItTestSys021(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,79 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
struct passwd *user1 = nullptr;
struct passwd *user2 = nullptr;
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 0, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 0, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/root", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/bin/bash", -1);
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 1, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 1, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/usr/sbin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1);
user1 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user1, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(user1->pw_uid, 2, -1);
ICUNIT_ASSERT_EQUAL(user1->pw_gid, 2, -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_gecos, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_dir, "/bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(user1->pw_shell, "/usr/sbin/nologin", -1);
setpwent();
user2 = getpwent();
ICUNIT_ASSERT_NOT_EQUAL(user2, NULL, -1);
ICUNIT_ASSERT_STRING_EQUAL(user2->pw_name, user1->pw_name, -1);
return 0;
}
VOID ItTestSys022(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,70 @@
/*
* 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 "It_test_sys.h"
#include "grp.h"
static UINT32 TestCase(VOID)
{
struct group *grp1 = nullptr;
struct group *grp2 = nullptr;
struct group *grp3 = nullptr;
struct group *grp4 = nullptr;
grp1 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp1, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, "root", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp1->gr_gid, 0, -1);
grp2 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp2, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp2->gr_name, "daemon", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp2->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp2->gr_gid, 1, -1);
grp3 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp3, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp3->gr_name, "bin", -1);
ICUNIT_ASSERT_STRING_EQUAL(grp3->gr_passwd, "x", -1);
ICUNIT_ASSERT_EQUAL(grp3->gr_gid, 2, -1);
setgrent();
grp4 = getgrent();
ICUNIT_ASSERT_NOT_EQUAL(grp4, nullptr, -1);
ICUNIT_ASSERT_STRING_EQUAL(grp1->gr_name, grp4->gr_name, -1);
return 0;
}
VOID ItTestSys023(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -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.
*/
#include "It_test_sys.h"
static jmp_buf g_buf;
static UINT32 First(VOID)
{
int ret = _setjmp(g_buf);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, 2, ret);
goto OUT1;
}
_longjmp(g_buf, 2);
OUT1:
return 0;
}
static UINT32 Sencond(VOID)
{
int ret = _setjmp(g_buf);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, 1, ret);
goto OUT2;
}
_longjmp(g_buf, 0);
OUT2:
return 0;
}
static UINT32 TestCase(VOID)
{
int ret = First();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = Sencond();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
VOID ItTestSys024(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_024", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,145 @@
/*
* 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 "It_test_sys.h"
#include <grp.h>
#define GROUPFILE "/etc/group"
static int TestCase0(void)
{
struct group getNam1 = { nullptr };
struct group *getNam2 = nullptr;
struct group getData1 = { nullptr };
struct group *getData2 = nullptr;
struct group *groupRet = nullptr;
char buf[1000];
size_t len = 1000;
int ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(getNam2, nullptr, getNam2);
ICUNIT_ASSERT_STRING_EQUAL(getNam2->gr_name, "root", getNam2->gr_name);
ICUNIT_ASSERT_STRING_EQUAL(getNam2->gr_passwd, "x", getNam2->gr_passwd);
ICUNIT_ASSERT_EQUAL(getNam2->gr_gid, 0, getNam2->gr_gid);
groupRet = getgrgid(0);
ICUNIT_ASSERT_NOT_EQUAL(groupRet, nullptr, groupRet);
ICUNIT_ASSERT_STRING_EQUAL(groupRet->gr_name, "root", groupRet->gr_name);
ICUNIT_ASSERT_STRING_EQUAL(groupRet->gr_passwd, "x", groupRet->gr_passwd);
ICUNIT_ASSERT_EQUAL(groupRet->gr_gid, 0, groupRet->gr_gid);
groupRet = getgrnam("root");
ICUNIT_ASSERT_NOT_EQUAL(groupRet, nullptr, groupRet);
ICUNIT_ASSERT_STRING_EQUAL(groupRet->gr_name, "root", groupRet->gr_name);
ICUNIT_ASSERT_STRING_EQUAL(groupRet->gr_passwd, "x", groupRet->gr_passwd);
ICUNIT_ASSERT_EQUAL(groupRet->gr_gid, 0, groupRet->gr_gid);
ret = getgrnam_r("root", &getData1, buf, len, &getData2);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_NOT_EQUAL(getData2, nullptr, getData2);
ICUNIT_ASSERT_STRING_EQUAL(getData2->gr_name, "root", getData2->gr_name);
ICUNIT_ASSERT_STRING_EQUAL(getData2->gr_passwd, "x", getData2->gr_passwd);
ICUNIT_ASSERT_EQUAL(getData2->gr_gid, 0, getData2->gr_gid);
return 0;
}
static int TestCase1(void)
{
int len = 1000;
char buf[1000];
struct group getNam1 = { nullptr };
struct group *getNam2 = nullptr;
struct group getData1 = { nullptr };
struct group *getData2 = nullptr;
struct group *groupRet = nullptr;
int ret = getgrgid_r(-1, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
groupRet = getgrgid(-1);
ICUNIT_ASSERT_EQUAL(groupRet, 0, groupRet);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
groupRet = getgrnam("null");
ICUNIT_ASSERT_EQUAL(groupRet, nullptr, groupRet);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
ret = getgrnam_r("null", &getData1, buf, len, &getData2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, EAFNOSUPPORT, errno);
errno = 0;
remove(GROUPFILE);
ret = getgrgid_r(0, &getNam1, buf, len, &getNam2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
groupRet = getgrgid(0);
ICUNIT_ASSERT_EQUAL(groupRet, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
groupRet = getgrnam("root");
ICUNIT_ASSERT_EQUAL(groupRet, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
ret = getgrnam_r("root", &getData1, buf, len, &getData2);
ICUNIT_ASSERT_NOT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
return 0;
}
static int TestCase(void)
{
int ret = TestCase0();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = TestCase1();
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return 0;
}
VOID ItTestSys025(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_025", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,60 @@
/*
* 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 "It_test_sys.h"
static int TestCase(void)
{
char *name = getlogin();
ICUNIT_ASSERT_NOT_EQUAL(name, "USER1", NULL);
int ret = getlogin_r(name, sizeof(name));
ICUNIT_ASSERT_EQUAL(ret, 6, ret);
ret = setenv("LOGNAME", "USER1", 1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
name = getlogin();
ICUNIT_ASSERT_STRING_EQUAL(name, "USER1", name);
ret = getlogin_r(name, strlen(name) + 1);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = getlogin_r(name, 1);
ICUNIT_ASSERT_EQUAL(ret, 34, ret);
ret = unsetenv("LOGNAME");
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
name = getlogin();
ICUNIT_ASSERT_EQUAL(name, nullptr, name);
return 0;
}
VOID ItTestSys026(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_026", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,70 @@
/*
* 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 "It_test_sys.h"
#include "fcntl.h"
#include <sys/ipc.h>
static UINT32 TestCase(VOID)
{
int fd;
int ret1;
int ret2;
int id1 = 1;
int id2 = 2;
char *str1 = "/storage/1.txt";
char *str2 = "/storage/2.txt";
fd = open(str1, O_CREAT);
if (fd < 0) {
return -1;
}
fd = open(str2, O_CREAT);
if (fd < 0) {
return -1;
}
ret1 = ftok(str1, id1);
ICUNIT_ASSERT_NOT_EQUAL(ret1, -1, ret1);
ret2 = ftok(str1, id2);
ICUNIT_ASSERT_NOT_EQUAL(ret1, -1, ret2);
ICUNIT_ASSERT_NOT_EQUAL(ret1, ret2, -1);
ret2 = ftok(str1, id1);
ICUNIT_ASSERT_EQUAL(ret1, ret2, -1);
ret2 = ftok(str2, id1);
ICUNIT_ASSERT_NOT_EQUAL(ret2, -1, ret2);
ICUNIT_ASSERT_NOT_EQUAL(ret1, ret2, -1);
return 0;
}
VOID ItTestSys027(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,50 @@
/* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
int ret;
pid_t pid = fork();
if (pid == 0) {
ret = nice(0);
ICUNIT_ASSERT_EQUAL(ret, 15, ret);
} else {
ret = nice(-15);
ICUNIT_ASSERT_EQUAL(ret, -1, ret);
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
}
return 0;
}
VOID IT_TEST_SYS_028(VOID)
{
TEST_ADD_CASE(IT_TEST_SYS_028, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,58 @@
/*
* 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 "It_test_sys.h"
#include <sys/ipc.h>
static UINT32 TestCase(VOID)
{
int ret1;
int id = 1;
char *str1 = "/storage/1";
char str2[] = { 0 };
errno = 0;
ret1 = ftok(str1, id);
ICUNIT_ASSERT_EQUAL(ret1, -1, ret1);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
errno = 0;
ret1 = ftok(str2, id);
ICUNIT_ASSERT_EQUAL(ret1, -1, ret1);
ICUNIT_ASSERT_EQUAL(errno, ENOENT, errno);
return 0;
}
VOID ItTestSys029(VOID)
{
TEST_ADD_CASE(__FUNCTION__, TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,63 @@
/*
* 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 "It_test_sys.h"
sigjmp_buf jmp_env;
int val = 2;
static void sig_alarm(int signum)
{
siglongjmp(jmp_env, val);
}
static UINT32 TestCase(VOID)
{
#if 0
int alarm_time = 1;
int ret;
signal(SIGALRM, sig_alarm);
alarm(alarm_time);
ret = sigsetjmp(jmp_env, 1);
if (ret) {
ICUNIT_ASSERT_EQUAL(ret, val, ret);
}
sleep(3);
#endif
return 0;
}
VOID IT_TEST_SYS_030(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_030", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
@@ -0,0 +1,50 @@
/*
* 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 "It_test_sys.h"
static UINT32 TestCase(VOID)
{
char buf1[100] = { 0 };
char *str = nullptr;
ctermid(buf1);
ICUNIT_ASSERT_STRING_EQUAL(buf1, "/dev/tty", -1);
str = ctermid(nullptr);
ICUNIT_ASSERT_STRING_EQUAL(str, "/dev/tty", -1);
return 0;
}
VOID IT_TEST_SYS_031(VOID)
{
TEST_ADD_CASE("IT_TEST_SYS_031", TestCase, TEST_POSIX, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
}
+220
View File
@@ -0,0 +1,220 @@
/*
* 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 "stdio.h"
#include <climits>
#include <gtest/gtest.h>
#include "It_test_sys.h"
using namespace testing::ext;
namespace OHOS {
class SysTest : public testing::Test {
public:
static void SetUpTestCase(void) {}
static void TearDownTestCase(void) {}
};
/* *
* @tc.name: IT_TEST_SYS_004
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys004, TestSize.Level0)
{
ItTestSys004();
}
/* *
* @tc.name: IT_TEST_SYS_005
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys005, TestSize.Level0)
{
ItTestSys005();
}
/* *
* @tc.name: IT_TEST_SYS_006
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys006, TestSize.Level0)
{
ItTestSys006();
}
/* *
* @tc.name: IT_TEST_SYS_007
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys007, TestSize.Level0)
{
ItTestSys007();
}
/* *
* @tc.name: IT_TEST_SYS_008
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys008, TestSize.Level0)
{
ItTestSys008();
}
/* *
* @tc.name: IT_TEST_SYS_009
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys009, TestSize.Level0)
{
ItTestSys009();
}
/* *
* @tc.name: IT_TEST_SYS_010
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys010, TestSize.Level0)
{
ItTestSys010();
}
/* *
* @tc.name: IT_TEST_SYS_012
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys012, TestSize.Level0)
{
ItTestSys012();
}
/* *
* @tc.name: IT_TEST_SYS_013
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys013, TestSize.Level0)
{
ItTestSys013();
}
/* *
* @tc.name: IT_TEST_SYS_014
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys014, TestSize.Level0)
{
ItTestSys014();
}
/* *
* @tc.name: IT_TEST_SYS_015
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys015, TestSize.Level0)
{
ItTestSys015();
}
/* *
* @tc.name: IT_TEST_SYS_016
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys016, TestSize.Level0)
{
ItTestSys016();
}
/* *
* @tc.name: IT_TEST_SYS_017
* @tc.desc: function for SysTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys017, TestSize.Level0)
{
ItTestSys017();
}
/* *
* @tc.name: IT_TEST_SYS_029
* @tc.desc: function for ftok exception test
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, ItTestSys029, TestSize.Level0)
{
ItTestSys029();
}
/* *
* @tc.name: IT_TEST_SYS_030
* @tc.desc: function for sigsetjmp siglongjmp test
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, IT_TEST_SYS_030, TestSize.Level0)
{
IT_TEST_SYS_030();
}
/* *
* @tc.name: IT_TEST_SYS_031
* @tc.desc: function for ctermid test
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(SysTest, IT_TEST_SYS_031, TestSize.Level0)
{
IT_TEST_SYS_031();
}
} // namespace OHOS