Compare commits
6 Commits
weekly_202
...
weekly_202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b37358cb47 | ||
|
|
b73eb72ba6 | ||
|
|
e98de4489f | ||
|
|
4cfb20d7e9 | ||
|
|
9248d46457 | ||
|
|
808b9de5b8 |
@@ -43,7 +43,7 @@
|
||||
"third_party": [
|
||||
"bounds_checking_function",
|
||||
"cmsis",
|
||||
"fatfs",
|
||||
"FatFs",
|
||||
"littlefs",
|
||||
"lwip",
|
||||
"musl"
|
||||
|
||||
@@ -48,7 +48,10 @@ kernel_module("test_init") {
|
||||
"src/osTest.c",
|
||||
]
|
||||
|
||||
include_dirs = [ "unittest/posix/src" ]
|
||||
include_dirs = [
|
||||
"unittest/posix/src",
|
||||
"unittest/xts",
|
||||
]
|
||||
|
||||
configs += [ ":include" ]
|
||||
}
|
||||
@@ -69,6 +72,7 @@ group("testsuites") {
|
||||
"sample/kernel/task:test_task",
|
||||
"sample/posix:test_posix",
|
||||
"unittest/posix:posix_test",
|
||||
"unittest/xts:xts_test",
|
||||
]
|
||||
if (defined(LOSCFG_DYNLINK)) {
|
||||
deps += [ "sample/kernel/dynlink:test_dynlink" ]
|
||||
|
||||
@@ -96,6 +96,7 @@ extern "C" {
|
||||
#define LOS_KERNEL_LMK_TEST 0
|
||||
#define LOS_KERNEL_SIGNAL_TEST 0
|
||||
|
||||
#define LOS_XTS_TEST 1
|
||||
#define LOS_POSIX_TEST 1
|
||||
#define LOS_CMSIS_TEST 1
|
||||
#define LOS_CMSIS2_CORE_TASK_TEST 0
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
#if (LOS_POSIX_TEST == 1)
|
||||
#include "posix_test.h"
|
||||
#endif
|
||||
#if (LOS_XTS_TEST == 1)
|
||||
#include "xts_test.h"
|
||||
#endif
|
||||
|
||||
UINT32 volatile g_testCount;
|
||||
UINT32 g_testTskHandle;
|
||||
@@ -246,6 +249,10 @@ VOID TestTaskEntry(VOID)
|
||||
CmsisFuncTestSuite();
|
||||
#endif
|
||||
|
||||
#if(LOS_XTS_TEST == 1)
|
||||
XtsTestSuite();
|
||||
#endif
|
||||
|
||||
/* The log is used for testing entrance guard, please do not make any changes. */
|
||||
PRINTF("\nfailed count:%d, success count:%d\n", g_failResult, g_passResult);
|
||||
PRINTF("--- Test End ---\n");
|
||||
|
||||
38
testsuites/unittest/xts/BUILD.gn
Normal file
38
testsuites/unittest/xts/BUILD.gn
Normal file
@@ -0,0 +1,38 @@
|
||||
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
static_library("xts_test") {
|
||||
sources = [ "xts_test.c" ]
|
||||
deps = [
|
||||
"io:io_test",
|
||||
"ipc:ipc_test",
|
||||
]
|
||||
configs += [ "$LITEOSTOPDIR/testsuites:include" ]
|
||||
}
|
||||
46
testsuites/unittest/xts/io/BUILD.gn
Normal file
46
testsuites/unittest/xts/io/BUILD.gn
Normal file
@@ -0,0 +1,46 @@
|
||||
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
static_library("io_test") {
|
||||
sources = [
|
||||
"xts_io.c",
|
||||
"xts_io_other_test.c",
|
||||
"xts_io_stdio_test.c",
|
||||
"xts_io_stdlib_test.c",
|
||||
"xts_io_string_test.c",
|
||||
"xts_io_strings_test.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
40
testsuites/unittest/xts/io/xts_io.c
Normal file
40
testsuites/unittest/xts/io/xts_io.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_test.h"
|
||||
|
||||
void IoFuncTest(void)
|
||||
{
|
||||
XtsIoOtherTest();
|
||||
XtsIoStdioFuncTest();
|
||||
XtsIoStdlibFuncTest();
|
||||
XtsIoStringFuncTest();
|
||||
XtsIoStringsFuncTest();
|
||||
}
|
||||
51
testsuites/unittest/xts/io/xts_io.h
Normal file
51
testsuites/unittest/xts/io/xts_io.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef XTS_IO_H
|
||||
#define XTS_IO_H
|
||||
|
||||
#include "xts_test.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <securec.h>
|
||||
#include <sys/uio.h>
|
||||
#include <grp.h>
|
||||
#include <shadow.h>
|
||||
#include <pwd.h>
|
||||
#include <inttypes.h>
|
||||
#include <iconv.h>
|
||||
#include <stdarg.h>
|
||||
#include <err.h>
|
||||
#include <threads.h>
|
||||
|
||||
#endif
|
||||
78
testsuites/unittest/xts/io/xts_io_other_test.c
Normal file
78
testsuites/unittest/xts/io/xts_io_other_test.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoOther, IoOtherTestSuite);
|
||||
|
||||
static BOOL IoOtherTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoOtherTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_OTHER_0900
|
||||
* @tc.name strptime basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoOtherTestSuite, testStrptime, Function | MediumTest | Level1)
|
||||
{
|
||||
struct tm tm;
|
||||
memset_s(&tm, sizeof(struct tm), 0, sizeof(struct tm));
|
||||
char *ret = strptime("2020-10-29 21:24:00abc", "%Y-%m-%d %H:%M:%S", &tm);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "abc", ret);
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_year, 120, tm.tm_year); /* 120 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_mon, 9, tm.tm_mon); /* 9 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_mday, 29, tm.tm_mday); /* 29 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_hour, 21, tm.tm_hour); /* 21 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_min, 24, tm.tm_min); /* 24 common data for test, no special meaning */
|
||||
|
||||
ret = strptime("14 Oct October 20 09:24:00 Sat Saturday 363", "%d %b %B %y %I:%M:%S %a %A %j", &tm);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "", ret);
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_year, 120, tm.tm_year); /* 120 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_mon, 9, tm.tm_mon); /* 9 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_mday, 14, tm.tm_mday); /* 14 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_hour, 9, tm.tm_hour); /* 9 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_wday, 6, tm.tm_wday); /* 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(tm.tm_yday, 362, tm.tm_yday); /* 362 common data for test, no special meaning */
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoOtherTestSuite);
|
||||
|
||||
void XtsIoOtherTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrptime);
|
||||
}
|
||||
75
testsuites/unittest/xts/io/xts_io_stdio_test.c
Normal file
75
testsuites/unittest/xts/io/xts_io_stdio_test.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoStdio, IoStdioTestSuite);
|
||||
|
||||
static BOOL IoStdioTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoStdioTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int FormatVsnptf(char *format, ...)
|
||||
{
|
||||
va_list vArgList;
|
||||
va_start(vArgList, format);
|
||||
char str[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
int ret = vsnprintf_s(str, sizeof(str), sizeof(str), format, vArgList);
|
||||
va_end(vArgList);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STDIO_2100
|
||||
* @tc.name vsnprintf basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStdioTestSuite, testVsnprintf, Function | MediumTest | Level1)
|
||||
{
|
||||
int ret = FormatVsnptf((char *)"%s has %d words", "hello world", 11); /* 11 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 24, ret); /* 24 common data for test, no special meaning */
|
||||
|
||||
ret = FormatVsnptf((char *)"%f and %c as well as %ld\n", 2.2, 'c', 6); /* 2.2, 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 28, ret); /* 28 common data for test, no special meaning */
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoStdioTestSuite);
|
||||
|
||||
void XtsIoStdioFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testVsnprintf);
|
||||
}
|
||||
282
testsuites/unittest/xts/io/xts_io_stdlib_test.c
Normal file
282
testsuites/unittest/xts/io/xts_io_stdlib_test.c
Normal file
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoStdlibApi, IoStdlibApiTestSuite);
|
||||
|
||||
static BOOL IoStdlibApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoStdlibApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STDLIB_0400
|
||||
* @tc.name strtof basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtof, Function | MediumTest | Level1)
|
||||
{
|
||||
char *endPtr = NULL;
|
||||
float ret = strtof(" -3.40E+38 hello", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, (float)(-3.40E+38), ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " hello", endPtr);
|
||||
|
||||
ret = strtof(" 3.40E+38 ===", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, (float)(3.40E+38), ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " ===", endPtr);
|
||||
|
||||
ret = strtof("-9.6e17 this 123", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, (float)(-9.6e17), ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " this 123", endPtr);
|
||||
|
||||
ret = strtof("this is string", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "this is string", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STDLIB_0500
|
||||
* @tc.name strtod basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtod, Function | MediumTest | Level1)
|
||||
{
|
||||
char *endPtr = NULL;
|
||||
double ret = strtod(" -1.79E+308 hello", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1.79E+308, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " hello", endPtr);
|
||||
|
||||
ret = strtod("1.79E+308 ===", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 1.79E+308, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " ===", endPtr);
|
||||
|
||||
ret = strtod("-9.6e17 this 123", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -9.6e17, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " this 123", endPtr);
|
||||
|
||||
ret = strtod("this is string", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "this is string", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STDLIB_0600
|
||||
* @tc.name strtold basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtold, Function | MediumTest | Level1)
|
||||
{
|
||||
char *endPtr = NULL;
|
||||
long double ret = strtold(" 2.22507e-308 hello", &endPtr);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " hello", endPtr);
|
||||
|
||||
ret = strtold(" 1.79769e+308 ===", &endPtr);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " ===", endPtr);
|
||||
|
||||
ret = strtold("-9.6e17 this 123", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -9.6e17, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " this 123", endPtr);
|
||||
|
||||
ret = strtold("this is string", &endPtr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "this is string", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STDLIB_0700
|
||||
* @tc.name strtol basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtol, Function | MediumTest | Level1)
|
||||
{
|
||||
char nPtr[] = "12 0110 0XDEFE 0666 -1.6";
|
||||
char *endPtr = NULL;
|
||||
long ret = strtol(nPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12, ret); /* 12 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0110 0XDEFE 0666 -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 2); /* 2 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 6, ret); /* 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0XDEFE 0666 -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 16); /* 16 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0XDEFE, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0666 -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 8); /* 8 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0666, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 65); /* 65 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -1.6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".6", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".6", endPtr);
|
||||
|
||||
char nPtr1[] = "2147483647 2147483648 -2147483648 -2147483649";
|
||||
ret = strtol(nPtr1, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 2147483647, ret); /* 2147483647 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 2147483648 -2147483648 -2147483649", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 2147483647, ret); /* 2147483647 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -2147483648 -2147483649", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, -2147483648, ret); /* -2147483648 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " -2147483649", endPtr);
|
||||
|
||||
ret = strtol(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, -2147483648, ret); /* -2147483648 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STDLIB_0800
|
||||
* @tc.name strtoul basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtoul, Function | MediumTest | Level1)
|
||||
{
|
||||
char nPtr[] = "12 0110 0XDEFE 0666 4294967295 4294967296 12.34";
|
||||
char *endPtr = NULL;
|
||||
unsigned long ret = strtoul(nPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0110 0XDEFE 0666 4294967295 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 2); /* 2 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 6UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0XDEFE 0666 4294967295 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 16); /* 16 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0XDEFEUL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0666 4294967295 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 8); /* 8 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0666UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 4294967295 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 4294967295UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 4294967296 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 4294967295UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 65); /* 65 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 12.34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".34", endPtr);
|
||||
|
||||
ret = strtoul(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0UL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".34", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STDLIB_1000
|
||||
* @tc.name strtoull basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStdlibApiTestSuite, testStrtoull, Function | MediumTest | Level1)
|
||||
{
|
||||
char nPtr[] = "12 0110 0XDEFE 0666 1.6";
|
||||
char *endPtr = NULL;
|
||||
unsigned long long ret = strtoull(nPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0110 0XDEFE 0666 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 2); /* 2 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 6ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0XDEFE 0666 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 16); /* 16 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0XDEFEULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 0666 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 8); /* 8 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0666ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 65); /* 65 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 1.6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 1ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".6", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, ".6", endPtr);
|
||||
|
||||
char nPtr1[] = "18446744073709551615 18446744073709551616";
|
||||
ret = strtoull(nPtr1, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 18446744073709551615ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, " 18446744073709551616", endPtr);
|
||||
|
||||
ret = strtoull(endPtr, &endPtr, 10); /* 10 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 18446744073709551615ULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(endPtr, "", endPtr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoStdlibApiTestSuite);
|
||||
|
||||
void XtsIoStdlibFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrtof);
|
||||
RUN_ONE_TESTCASE(testStrtod);
|
||||
RUN_ONE_TESTCASE(testStrtold);
|
||||
RUN_ONE_TESTCASE(testStrtol);
|
||||
RUN_ONE_TESTCASE(testStrtoul);
|
||||
RUN_ONE_TESTCASE(testStrtoull);
|
||||
}
|
||||
374
testsuites/unittest/xts/io/xts_io_string_test.c
Normal file
374
testsuites/unittest/xts/io/xts_io_string_test.c
Normal file
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoStringApi, IoStringApiTestSuite);
|
||||
|
||||
static BOOL IoStringApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoStringApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_0300
|
||||
* @tc.name strcmp basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrcmp, Function | MediumTest | Level1)
|
||||
{
|
||||
int ret = strcmp("abcdef", "ABCDEF");
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = strcmp("123456", "654321");
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
|
||||
ret = strcmp("~!@#$%^&*()_+", "~!@#$%^&*()_+");
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_0400
|
||||
* @tc.name strncmp basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrncmp, Function | MediumTest | Level1)
|
||||
{
|
||||
const char dest[] = "abcdef";
|
||||
const char src[] = "ABCDEF";
|
||||
int ret = strncmp(dest, src, 1); /* 1 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = strncmp("123456", "654321", 6); /* 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
|
||||
ret = strncmp("~!@#$%^&*()_+", "~!@#$%^&*()_+", 8); /* 8 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_0700
|
||||
* @tc.name stpcpy basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStpcpy, Function | MediumTest | Level1)
|
||||
{
|
||||
const char *src = "hello world !";
|
||||
char dest[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
char *ret = stpcpy(dest, src);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(dest, src, dest);
|
||||
|
||||
const char *srcT = "~!@#$%%^&*()_+";
|
||||
char destT[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
ret = stpcpy(destT, srcT);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, NULL, ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(destT, srcT, destT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_0800
|
||||
* @tc.name stpncpy basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStpncpy, Function | MediumTest | Level1)
|
||||
{
|
||||
char src[] = "hello world !";
|
||||
char dest[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
char *ret = stpncpy(dest, src, 5); /* 5 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "", ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(dest, "hello", dest);
|
||||
|
||||
char srcT[] = "~!@#$%%^&*()_+";
|
||||
char destT[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
ret = stpncpy(destT, srcT, 15); /* 15 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "", ret);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(destT, "~!@#$%%^&*()_+", destT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_1000
|
||||
* @tc.name strcpy basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrcpy, Function | MediumTest | Level1)
|
||||
{
|
||||
char src[] = "hello world !";
|
||||
char dest[20] = {0}; /* 20 common data for test, no special meaning */
|
||||
int ret = strcpy_s(dest, sizeof(dest), src);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
char srcT[] = "This is String1";
|
||||
char destT[20] = {0}; /* 20 common data for test, no special meaning */
|
||||
ret = strcpy_s(destT, sizeof(destT), srcT);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_1100
|
||||
* @tc.name strncpy basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrncpy, Function | MediumTest | Level1)
|
||||
{
|
||||
char src[] = "hello world !";
|
||||
char dest[20] = {0};
|
||||
int ret = strncpy_s(dest, sizeof(dest), src, 6); /* 6 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
char destT[] = "~!@#$%^&*()_+";
|
||||
ret = strncpy_s(destT, sizeof(destT), "hello world", 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_1400
|
||||
* @tc.name strcat basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrcat, Function | MediumTest | Level1)
|
||||
{
|
||||
char dest[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
int ret = strcat_s(dest, sizeof(dest), "hello world !");
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
char destT[50] = "hello world ! || "; /* 50 common data for test, no special meaning */
|
||||
ret = strcat_s(destT, sizeof(destT), "This is String1");
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_1500
|
||||
* @tc.name strncat basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrncat, Function | MediumTest | Level1)
|
||||
{
|
||||
char dest[50] = "hello world || "; /* 50 common data for test, no special meaning */
|
||||
int ret = strncat_s(dest, sizeof(dest), "This is String1", 7); /* 7 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
char destT[20] = "|/*"; /* 20 common data for test, no special meaning */
|
||||
ret = strncat_s(destT, sizeof(destT), "~!@#$%^&*()_+", 13); /* 13 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_1600
|
||||
* @tc.name strchr basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrchr, Function | MediumTest | Level1)
|
||||
{
|
||||
char src[] = "hello !! world";
|
||||
char *ret = strchr(src, '!');
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "!! world", ret);
|
||||
|
||||
ret = strchr(src, '?');
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, NULL, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_1700
|
||||
* @tc.name strrchr basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrrchr, Function | MediumTest | Level1)
|
||||
{
|
||||
char src[] = "hello world & HEELO & WORLD";
|
||||
char *ret = strrchr(src, '&');
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "& WORLD", ret);
|
||||
|
||||
ret = strrchr(src, '?');
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, NULL, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_1800
|
||||
* @tc.name strnlen basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrnlen, Function | MediumTest | Level1)
|
||||
{
|
||||
char src[] = "hello world !";
|
||||
unsigned int ltSrcSize = strlen(src) - 2; /* 2 common data for test, no special meaning */
|
||||
unsigned int gtSrcSize = strlen(src) + 2; /* 2 common data for test, no special meaning */
|
||||
|
||||
size_t ret = strnlen(src, ltSrcSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, ltSrcSize, ret);
|
||||
|
||||
ret = strnlen(src, gtSrcSize);
|
||||
ICUNIT_ASSERT_EQUAL(ret, strlen(src), ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_1900
|
||||
* @tc.name strtok basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrtok, Function | MediumTest | Level1)
|
||||
{
|
||||
char src[] = "hello world & This is-String1";
|
||||
char *ret = strtok(src, "&");
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, src, ret);
|
||||
|
||||
ret = strtok(NULL, "-");
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, " This is", ret);
|
||||
|
||||
char srcS[] = "hello world !";
|
||||
ret = strtok(srcS, "?");
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, srcS, ret);
|
||||
|
||||
char srcT[50] = {0}; /* 50 common data for test, no special meaning */
|
||||
ret = strtok(srcT, "~");
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, NULL, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_2200
|
||||
* @tc.name strdup basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrdup, Function | MediumTest | Level1)
|
||||
{
|
||||
char src[] = "hello world !";
|
||||
char *ret = strdup(src);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, src, ret);
|
||||
|
||||
char srcS[] = "This is String1";
|
||||
ret = strdup(srcS);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "This is String1", ret);
|
||||
free(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_2500
|
||||
* @tc.name strcspn basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrcspn, Function | MediumTest | Level1)
|
||||
{
|
||||
const char dest[] = "hello world !";
|
||||
const char src[] = "!";
|
||||
size_t ret = strcspn(dest, src);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 12U, ret);
|
||||
|
||||
const char srcS[] = "a";
|
||||
ret = strcspn(dest, srcS);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 13U, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_2600
|
||||
* @tc.name strspn basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrspn, Function | MediumTest | Level1)
|
||||
{
|
||||
const char dest[] = "hello world !";
|
||||
const char src[] = "heAlo";
|
||||
size_t ret = strspn(dest, src);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 5U, ret);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 5U, ret);
|
||||
|
||||
const char destS[] = "this is string";
|
||||
const char srcS[] = "abc";
|
||||
ret = strspn(destS, srcS);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0U, ret);
|
||||
|
||||
const char srcT[] = "helo\0 wal";
|
||||
ret = strspn(dest, srcT);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 5U, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRING_2700
|
||||
* @tc.name strstr basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringApiTestSuite, testStrstr, Function | MediumTest | Level1)
|
||||
{
|
||||
const char dest[] = "hello world !";
|
||||
const char src[] = "heAlo";
|
||||
const char *ret = strstr(dest, src);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, NULL, ret);
|
||||
|
||||
const char destS[] = "string this is string";
|
||||
const char srcS[] = "string";
|
||||
ret = strstr(destS, srcS);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "string this is string", ret);
|
||||
|
||||
const char srcT[] = "\0hello";
|
||||
ret = strstr(dest, srcT);
|
||||
ICUNIT_ASSERT_STRING_EQUAL(ret, "hello world !", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoStringApiTestSuite);
|
||||
|
||||
void XtsIoStringFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrcmp);
|
||||
RUN_ONE_TESTCASE(testStrncmp);
|
||||
RUN_ONE_TESTCASE(testStpcpy);
|
||||
RUN_ONE_TESTCASE(testStpncpy);
|
||||
RUN_ONE_TESTCASE(testStrcpy);
|
||||
RUN_ONE_TESTCASE(testStrncpy);
|
||||
RUN_ONE_TESTCASE(testStrcat);
|
||||
RUN_ONE_TESTCASE(testStrncat);
|
||||
RUN_ONE_TESTCASE(testStrchr);
|
||||
RUN_ONE_TESTCASE(testStrrchr);
|
||||
RUN_ONE_TESTCASE(testStrnlen);
|
||||
RUN_ONE_TESTCASE(testStrtok);
|
||||
RUN_ONE_TESTCASE(testStrdup);
|
||||
RUN_ONE_TESTCASE(testStrcspn);
|
||||
RUN_ONE_TESTCASE(testStrspn);
|
||||
RUN_ONE_TESTCASE(testStrstr);
|
||||
}
|
||||
87
testsuites/unittest/xts/io/xts_io_strings_test.c
Normal file
87
testsuites/unittest/xts/io/xts_io_strings_test.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_io.h"
|
||||
|
||||
LITE_TEST_SUIT(IO, IoStringsApi, IoStringsApiTestSuite);
|
||||
|
||||
static BOOL IoStringsApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IoStringsApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRINGS_0200
|
||||
* @tc.name strncasecmp basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringsApiTestSuite, testStrncasecmp, Function | MediumTest | Level1)
|
||||
{
|
||||
int ret = strncasecmp("abcdefg", "abcdEFg", 7); /* 7 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = strncasecmp("abcdefg", "abcdEF", 7); /* 7 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = strncasecmp("abcdef", "abcdEFg", 7); /* 7 common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IO_STRINGS_0300
|
||||
* @tc.name strcasecmp basic function test
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IoStringsApiTestSuite, testStrcasecmp, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret = strcasecmp("abcdefg", "abcdEFg");
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = strcasecmp("abcdefg", "abcdEF");
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, 0, INT_MAX, ret);
|
||||
|
||||
ret = strcasecmp("abcdef", "abcdEFg");
|
||||
ICUNIT_ASSERT_WITHIN_EQUAL(ret, INT_MIN, 0, ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IoStringsApiTestSuite);
|
||||
|
||||
void XtsIoStringsFuncTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testStrncasecmp);
|
||||
RUN_ONE_TESTCASE(testStrcasecmp);
|
||||
}
|
||||
46
testsuites/unittest/xts/ipc/BUILD.gn
Normal file
46
testsuites/unittest/xts/ipc/BUILD.gn
Normal file
@@ -0,0 +1,46 @@
|
||||
# Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
static_library("ipc_test") {
|
||||
sources = [
|
||||
"cond/pthread_cond_test.c",
|
||||
"mutex/pthread_mutex_test.c",
|
||||
"semaphone/sem_abn_test.c",
|
||||
"semaphone/sem_test.c",
|
||||
"semaphone/sem_xts_test.c",
|
||||
"xts_ipc.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"$LITEOSTOPDIR/testsuites/include",
|
||||
"$LITEOSTOPDIR/testsuites/unittest/xts",
|
||||
]
|
||||
}
|
||||
192
testsuites/unittest/xts/ipc/cond/pthread_cond_test.c
Normal file
192
testsuites/unittest/xts/ipc/cond/pthread_cond_test.c
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_ipc.h"
|
||||
|
||||
pthread_mutex_t g_mtx3 = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_cond_t g_cond3 = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
LITE_TEST_SUIT(FUTEX, PthreadCondApiTest, PthreadCondApiTestSuite);
|
||||
|
||||
static BOOL PthreadCondApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL PthreadCondApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_PTHREAD_COND_INIT_0100
|
||||
* @tc.name pthread_cond_init initializes condition variables
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PthreadCondApiTestSuite, testPthreadCondInit, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
pthread_condattr_t condAttr;
|
||||
|
||||
ret = pthread_condattr_init(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond1;
|
||||
ret = pthread_cond_init(&cond1, &condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond2;
|
||||
ret = pthread_cond_init(&cond2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_PTHREAD_COND_DESTROY_0100
|
||||
* @tc.name pthread_cond_destroy destroy condition variables
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PthreadCondApiTestSuite, testPthreadCondDestroy, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
pthread_condattr_t condAttr;
|
||||
ret = pthread_condattr_init(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond1;
|
||||
ret = pthread_cond_init(&cond1, &condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_cond_destroy(&cond1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond2;
|
||||
ret = pthread_cond_init(&cond2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_cond_destroy(&cond2);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
pthread_cond_t cond3 = PTHREAD_COND_INITIALIZER;
|
||||
ret =pthread_cond_destroy(&cond3);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_PTHREAD_CONDATTR_INIT_0100
|
||||
* @tc.name Init and destroy operations
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PthreadCondApiTestSuite, testPthreadCondattrInit, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
pthread_condattr_t condAttr;
|
||||
|
||||
ret = pthread_condattr_init(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret =pthread_condattr_destroy(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_condattr_init(&condAttr);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
}
|
||||
|
||||
// pthread_cond_broadcast
|
||||
void *ThreadPthreadCondBroadcast1(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int *testIntP = (int *)arg;
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
ret = pthread_mutex_lock(&g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
*testIntP = TEST_INTP_SIZE;
|
||||
ret = pthread_cond_broadcast(&g_cond3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
ret = pthread_mutex_unlock(&g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
return arg;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// pthread_cond_wait
|
||||
void *ThreadPthreadCondBroadcast2(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int *testIntP = (int *)arg;
|
||||
ret = pthread_mutex_lock(&g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
ret = pthread_cond_wait(&g_cond3, &g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
(*testIntP)++;
|
||||
ret = pthread_mutex_unlock(&g_mtx3);
|
||||
ICUNIT_GOTO_EQUAL(ret, POSIX_IPC_NO_ERROR, ret, EXIT);
|
||||
return arg;
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_PTHREAD_COND_BROADCAST_0100
|
||||
* @tc.name Use pthread_cond_broadcast to release conditional semaphore
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PthreadCondApiTestSuite, testPthreadCondBroadcast, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid[3]; /* 3, common data for test, no special meaning */
|
||||
int testInt = 0;
|
||||
|
||||
ret = pthread_create(&tid[0], NULL, ThreadPthreadCondBroadcast1, (void*)&testInt);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_create(&tid[1], NULL, ThreadPthreadCondBroadcast2, (void*)&testInt); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_create(&tid[2], NULL, ThreadPthreadCondBroadcast2, (void*)&testInt); /* 2, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
usleep(100); /* 100, common data for test, no special meaning */
|
||||
int index = (int)(sizeof(tid) / sizeof(tid[0]));
|
||||
for (int i = 0; i < index; i++) {
|
||||
ret = pthread_join(tid[i], NULL);
|
||||
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
|
||||
}
|
||||
EXIT:
|
||||
ret = pthread_cond_destroy(&g_cond3);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_mutex_destroy(&g_mtx3);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ICUNIT_ASSERT_EQUAL(testInt, TEST_SEEK_SIZE, testInt);
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(PthreadCondApiTestSuite);
|
||||
|
||||
void PosixFutexCondTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testPthreadCondInit);
|
||||
RUN_ONE_TESTCASE(testPthreadCondDestroy);
|
||||
RUN_ONE_TESTCASE(testPthreadCondattrInit);
|
||||
RUN_ONE_TESTCASE(testPthreadCondBroadcast);
|
||||
}
|
||||
138
testsuites/unittest/xts/ipc/mutex/pthread_mutex_test.c
Normal file
138
testsuites/unittest/xts/ipc/mutex/pthread_mutex_test.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_ipc.h"
|
||||
|
||||
LITE_TEST_SUIT(FUTEX, PthreadMutexApiTest, PthreadMutexApiTestSuite);
|
||||
|
||||
static BOOL PthreadMutexApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL PthreadMutexApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/********************************************* Test case dividing line ***********************************************/
|
||||
|
||||
struct PthreadMutexCond {
|
||||
int loopNum;
|
||||
int countMax;
|
||||
int count;
|
||||
int top;
|
||||
int bottom;
|
||||
pthread_cond_t notfull;
|
||||
pthread_cond_t notempty;
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
struct PthreadMutexCond g_st1;
|
||||
|
||||
void *PthreadProduce(void *arg)
|
||||
{
|
||||
int ret;
|
||||
for (int i = 0; i < g_st1.loopNum; i++) {
|
||||
ret = pthread_mutex_lock(&g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
// check full
|
||||
if ((g_st1.top + 1) % g_st1.countMax == g_st1.bottom) { /* 1, common data for test, no special meaning */
|
||||
ret = pthread_cond_wait(&g_st1.notempty, &g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
}
|
||||
// Produce
|
||||
g_st1.top = (g_st1.top + 1) % g_st1.countMax; /* 1, common data for test, no special meaning */
|
||||
g_st1.count++;
|
||||
|
||||
ret = pthread_cond_signal(&g_st1.notempty);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_mutex_unlock(&g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
usleep(10); /* 10, common data for test, no special meaning */
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
void *PthreadConsume(void *arg)
|
||||
{
|
||||
int ret;
|
||||
for (int i = 0; i < g_st1.loopNum; i++) {
|
||||
ret = pthread_mutex_lock(&g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
// check empty
|
||||
if (g_st1.top == g_st1.bottom) {
|
||||
ret = pthread_cond_wait(&g_st1.notempty, &g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
}
|
||||
// Consume
|
||||
g_st1.bottom = (g_st1.bottom + 1) % g_st1.countMax;
|
||||
g_st1.count--;
|
||||
|
||||
ret = pthread_cond_signal(&g_st1.notempty);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_mutex_unlock(&g_st1.mutex);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
|
||||
usleep(10); /* 10, common data for test, no special meaning */
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_FUTEX_MUTEX_ALL_0300
|
||||
* @tc.name test pthread_mutex with condition variable, produce and consume
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(PthreadMutexApiTestSuite, testPthreadMutexCond, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid[2]; /* 2, common data for test, no special meaning */
|
||||
|
||||
g_st1.count = 0;
|
||||
memset_s(tid, sizeof(tid), POSIX_IPC_NO_ERROR, sizeof(tid));
|
||||
|
||||
ret = pthread_create(&tid[0], NULL, PthreadProduce, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_create(&tid[1], NULL, PthreadConsume, NULL); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_join(tid[0], NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ret = pthread_join(tid[1], NULL); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, POSIX_IPC_NO_ERROR, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_st1.count, POSIX_IPC_NO_ERROR, g_st1.count);
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(PthreadMutexApiTestSuite);
|
||||
|
||||
void PosixFutexMutexTest(void)
|
||||
{
|
||||
RUN_ONE_TESTCASE(testPthreadMutexCond);
|
||||
}
|
||||
190
testsuites/unittest/xts/ipc/semaphone/sem_abn_test.c
Normal file
190
testsuites/unittest/xts/ipc/semaphone/sem_abn_test.c
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_ipc.h"
|
||||
|
||||
LITE_TEST_SUIT(IPC, SemAbnormalTestSuite, SemAbnormalTestSuite);
|
||||
|
||||
static BOOL SemAbnormalTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL SemAbnormalTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_INIT_0200
|
||||
* @tc.name Use sem_init initialized value when value is SEM_VALUE_MAX
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(SemAbnormalTestSuite, testSemInitAbnormalSemvaluemax, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, SEM_VALUE_MAX);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(SEM_VALUE_MAX, semValue, SEM_VALUE_MAX);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_INIT_0210
|
||||
* @tc.name Use sem_init initialized value when value is greater than SEM_VALUE_MAX
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(SemAbnormalTestSuite, testSemInitAbnormalGtsemvaluemax, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
unsigned int gtSemMax = (unsigned int)SEM_VALUE_MAX + 1; /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_init(&sem, 0, gtSemMax);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
EXIT:
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_INIT_0220
|
||||
* @tc.name Use sem_init initialized value twice
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(SemAbnormalTestSuite, testSemInitAbnormalInitTwice, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, 1); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_POST_0200
|
||||
* @tc.name sem_post increases the semaphore count near the maximum value
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(SemAbnormalTestSuite, testSemPostAbnormal, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, SEM_VALUE_MAX);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT);
|
||||
ICUNIT_GOTO_EQUAL(errno, EOVERFLOW, errno, EXIT); /* -1, common data for test, no special meaning */
|
||||
|
||||
EXIT:
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_0200
|
||||
* @tc.name sem_timedwait get semaphore, wait time abnormal, tv_nsec less than 0
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(SemAbnormalTestSuite, testSemTimedwaitAbnormalA, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts = {0};
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = time(NULL);
|
||||
ts.tv_nsec = -2; /* -2, common data for test, no special meaning */
|
||||
ret = sem_timedwait(&sem, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
|
||||
EXIT:
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_0300
|
||||
* @tc.name sem_timedwait get semaphore, wait time abnormal
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(SemAbnormalTestSuite, testSemTimedwaitAbnormalB, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts = {0};
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = time(NULL);
|
||||
ts.tv_nsec = KERNEL_NS_PER_SECOND;
|
||||
ret = sem_timedwait(&sem, &ts);
|
||||
ICUNIT_GOTO_EQUAL(ret, -1, ret, EXIT); /* -1, common data for test, no special meaning */
|
||||
ICUNIT_GOTO_EQUAL(errno, EINVAL, errno, EXIT);
|
||||
EXIT:
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(SemAbnormalTestSuite);
|
||||
|
||||
void PosixSemAbnFuncTest()
|
||||
{
|
||||
RUN_ONE_TESTCASE(testSemInitAbnormalSemvaluemax);
|
||||
RUN_ONE_TESTCASE(testSemInitAbnormalInitTwice);
|
||||
RUN_ONE_TESTCASE(testSemTimedwaitAbnormalA);
|
||||
RUN_ONE_TESTCASE(testSemTimedwaitAbnormalB);
|
||||
}
|
||||
347
testsuites/unittest/xts/ipc/semaphone/sem_test.c
Normal file
347
testsuites/unittest/xts/ipc/semaphone/sem_test.c
Normal file
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_ipc.h"
|
||||
|
||||
static int g_semTestStep = 0;
|
||||
|
||||
LITE_TEST_SUIT(IPC, SemApi, IpcSemApiTestSuite);
|
||||
|
||||
static BOOL IpcSemApiTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IpcSemApiTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemInit0100, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int testValue[3] = {0, 1, 10}; /* 3, 1, 10 common data for test, no special meaning */
|
||||
|
||||
int index = (int)(sizeof(testValue) / sizeof(int));
|
||||
for (int i = 0; i < index; i++) {
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, testValue[0]);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemPost0100, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemWait0100, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, 3); /* 3, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
void *ThreadChat(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t *)arg;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 0, g_semTestStep);
|
||||
|
||||
g_semTestStep = 1; /* 1, common data for test, no special meaning */
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_semTestStep = 2; /* 2, common data for test, no special meaning */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testThreadChat0100, Function | MediumTest | Level3)
|
||||
{
|
||||
pthread_t tid;
|
||||
sem_t sem;
|
||||
int ret;
|
||||
struct timespec req;
|
||||
g_semTestStep = 0;
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid, NULL, ThreadChat, (void *)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
req.tv_sec = 0;
|
||||
req.tv_nsec = TEN_CONT * NANO_MS;
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 1, g_semTestStep); /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 2, g_semTestStep); /* 2, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 2, g_semTestStep); /* 2, common data for test, no special meaning */
|
||||
|
||||
ret = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
void *ThreadNThreadWait1(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t *)arg;
|
||||
struct timespec req;
|
||||
|
||||
req.tv_sec = 0;
|
||||
req.tv_nsec = HUNDRED_CONT * NANO_MS;
|
||||
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
g_semTestStep = 1; /* 1, common data for test, no special meaning */
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_semTestStep = 2; /* 2, common data for test, no special meaning */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ThreadNThreadWait2(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t *)arg;
|
||||
struct timespec req;
|
||||
|
||||
req.tv_sec = 0;
|
||||
req.tv_nsec = 300 * NANO_MS; /* 300, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
g_semTestStep = 3; /* 3, common data for test, no special meaning */
|
||||
|
||||
req.tv_nsec = 200 * NANO_MS; /* 200, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
g_semTestStep = 4; /* 4, common data for test, no special meaning */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testThreadChat0400, Function | MediumTest | Level4)
|
||||
{
|
||||
pthread_t tid1;
|
||||
pthread_t tid2;
|
||||
sem_t sem;
|
||||
int ret;
|
||||
struct timespec req;
|
||||
|
||||
req.tv_sec = 0;
|
||||
req.tv_nsec = 200 * NANO_MS; /* 200, common data for test, no special meaning */
|
||||
g_semTestStep = 0;
|
||||
|
||||
ret = sem_init((sem_t *)&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid1, NULL, ThreadNThreadWait1, (void *)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_create(&tid2, NULL, ThreadNThreadWait2, (void *)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 1, g_semTestStep); /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
req.tv_nsec = 20 * NANO_MS; /* 20, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 2, g_semTestStep); /* 2, common data for test, no special meaning */
|
||||
|
||||
req.tv_nsec = 200 * NANO_MS; /* 200, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 3, g_semTestStep); /* 3, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
req.tv_nsec = 20 * NANO_MS; /* 20, common data for test, no special meaning */
|
||||
ret = nanosleep(&req, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 3, g_semTestStep); /* 3, common data for test, no special meaning */
|
||||
|
||||
ret = pthread_join(tid1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = pthread_join(tid2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(g_semTestStep, 4, g_semTestStep); /* 4, common data for test, no special meaning */
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemInitAbnormal0200, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
unsigned int gtSemMax = (unsigned int)SEM_VALUE_MAX + 1; /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_init(&sem, 0, SEM_VALUE_MAX);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_init(&sem, 0, gtSemMax);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = sem_init(&sem, 0, 1); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemPostAbnormal, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, SEM_VALUE_MAX);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemTimedWaitAbnormalA, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = -2; /* -2, common data for test, no special meaning */
|
||||
ret = sem_timedwait(&sem, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
LITE_TEST_CASE(IpcSemApiTestSuite, testSemTimedWaitAbnormalB, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ts.tv_sec = time(NULL);
|
||||
ts.tv_nsec = NANO_S;
|
||||
ret = sem_timedwait(&sem, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(errno, EINVAL, errno);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IpcSemApiTestSuite);
|
||||
|
||||
void PosixSemFuncTest()
|
||||
{
|
||||
RUN_ONE_TESTCASE(testSemInit0100);
|
||||
RUN_ONE_TESTCASE(testSemPost0100);
|
||||
RUN_ONE_TESTCASE(testSemWait0100);
|
||||
RUN_ONE_TESTCASE(testThreadChat0100);
|
||||
RUN_ONE_TESTCASE(testThreadChat0400);
|
||||
RUN_ONE_TESTCASE(testSemInitAbnormal0200);
|
||||
RUN_ONE_TESTCASE(testSemPostAbnormal);
|
||||
RUN_ONE_TESTCASE(testSemTimedWaitAbnormalA);
|
||||
RUN_ONE_TESTCASE(testSemTimedWaitAbnormalB);
|
||||
}
|
||||
427
testsuites/unittest/xts/ipc/semaphone/sem_xts_test.c
Normal file
427
testsuites/unittest/xts/ipc/semaphone/sem_xts_test.c
Normal file
@@ -0,0 +1,427 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_ipc.h"
|
||||
|
||||
LITE_TEST_SUIT(IPC, SemApi, IpcSemApiXtsTestSuite);
|
||||
|
||||
static BOOL IpcSemApiXtsTestSuiteSetUp(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL IpcSemApiXtsTestSuiteTearDown(void)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_INIT_0100
|
||||
* @tc.name Use sem_init initialize the semaphore with 0
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemInitA, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
int testValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, testValue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(semValue, testValue, semValue);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_INIT_0110
|
||||
* @tc.name Use sem_init initialize the semaphore with 1
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemInitB, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
int testValue = 1; /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_init(&sem, 0, testValue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(semValue, testValue, semValue);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_INIT_0120
|
||||
* @tc.name Use sem_init initialize the semaphore with 100
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemInitC, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
int testValue = 10; /* 10, common data for test, no special meaning */
|
||||
|
||||
ret = sem_init(&sem, 0, testValue);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(semValue, testValue, semValue);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_POST_0100
|
||||
* @tc.name sem_post increases the semaphore count
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemPost, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 3, semValue); /* 3, common data for test, no special meaning */
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_WAIT_0100
|
||||
* @tc.name sem_wait get semaphore
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemWait, Function | MediumTest | Level2)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_init(&sem, 0, 3); /* 3, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, -1, ret); /* -1, common data for test, no special meaning */
|
||||
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 3, semValue); /* 3, common data for test, no special meaning */
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 2, semValue); /* 2, common data for test, no special meaning */
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_wait(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_DESTROY_0100
|
||||
* @tc.name check sem_destroy function
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testSemdestroy, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
sem_t sem;
|
||||
|
||||
ret = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
void *ThreadChatF01(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t*)arg;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_CHAT_0100
|
||||
* @tc.name Inter-thread communication, check sem_wait function
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testThreadChat, Function | MediumTest | Level3)
|
||||
{
|
||||
pthread_t tid;
|
||||
sem_t sem;
|
||||
int reInt;
|
||||
int semValue = 0;
|
||||
|
||||
reInt = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
reInt = pthread_create(&tid, NULL, ThreadChatF01, (void*)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
reInt = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
reInt = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
|
||||
reInt = pthread_join(tid, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
reInt = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
}
|
||||
|
||||
void *ThreadSemTimedWait(void *arg)
|
||||
{
|
||||
int ret;
|
||||
struct timespec ts = {0};
|
||||
sem_t *sem = (sem_t*)arg;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
ts.tv_sec = ts.tv_sec + (ts.tv_nsec + KERNEL_100MS_BY_NS) / KERNEL_NS_PER_SECOND;
|
||||
ts.tv_nsec = (ts.tv_nsec + KERNEL_100MS_BY_NS) % KERNEL_NS_PER_SECOND;
|
||||
usleep(50); /* 50, common data for test, no special meaning */
|
||||
ret = sem_timedwait(sem, &ts);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
usleep(100); /* 100, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_CHAT_0300
|
||||
* @tc.name Inter-thread communication, check sem_timedwait function
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testThreadSemTimedWait, Function | MediumTest | Level3)
|
||||
{
|
||||
int ret;
|
||||
pthread_t tid;
|
||||
sem_t sem;
|
||||
int reInt;
|
||||
int semValue = 0;
|
||||
|
||||
reInt = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
reInt = pthread_create(&tid, NULL, ThreadSemTimedWait, (void*)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(10); /* 10, common data for test, no special meaning */
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ret = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
|
||||
reInt = pthread_join(tid, NULL);
|
||||
ret = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ret = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
}
|
||||
|
||||
void *ThreadNThreadWaitF01(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t*)arg;
|
||||
int semValue = 0;
|
||||
|
||||
usleep(100); /* 100, common data for test, no special meaning */
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *ThreadNThreadWaitF02(void *arg)
|
||||
{
|
||||
int ret;
|
||||
sem_t *sem = (sem_t*)arg;
|
||||
int semValue = 0;
|
||||
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
usleep(300); /* 300, common data for test, no special meaning */
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
usleep(200); /* 200, common data for test, no special meaning */
|
||||
ret = sem_getvalue(sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
ret = sem_wait(sem);
|
||||
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number SUB_KERNEL_IPC_SEM_CHAT_0400
|
||||
* @tc.name N threads wait, main thread post
|
||||
* @tc.desc [C- SOFTWARE -0200]
|
||||
*/
|
||||
LITE_TEST_CASE(IpcSemApiXtsTestSuite, testNThreadWait, Function | MediumTest | Level4)
|
||||
{
|
||||
pthread_t tid1;
|
||||
pthread_t tid2;
|
||||
sem_t sem;
|
||||
int reInt;
|
||||
int semValue = 0;
|
||||
|
||||
reInt = sem_init(&sem, 0, 0);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
reInt = pthread_create(&tid1, NULL, ThreadNThreadWaitF01, (void*)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
reInt = pthread_create(&tid2, NULL, ThreadNThreadWaitF02, (void*)&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(200); /* 200, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
reInt = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
|
||||
usleep(200); /* 200, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 0, semValue);
|
||||
reInt = sem_post(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
|
||||
usleep(20); /* 20, common data for test, no special meaning */
|
||||
reInt = sem_getvalue(&sem, &semValue);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
ICUNIT_ASSERT_EQUAL(semValue, 1, semValue); /* 1, common data for test, no special meaning */
|
||||
|
||||
reInt = pthread_join(tid1, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
reInt = pthread_join(tid2, NULL);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
reInt = sem_destroy(&sem);
|
||||
ICUNIT_ASSERT_EQUAL(reInt, 0, reInt);
|
||||
}
|
||||
|
||||
RUN_TEST_SUITE(IpcSemApiXtsTestSuite);
|
||||
|
||||
void PosixSemXtsFuncTest()
|
||||
{
|
||||
RUN_ONE_TESTCASE(testSemInitA);
|
||||
RUN_ONE_TESTCASE(testSemInitB);
|
||||
RUN_ONE_TESTCASE(testSemInitC);
|
||||
RUN_ONE_TESTCASE(testSemPost);
|
||||
RUN_ONE_TESTCASE(testSemWait);
|
||||
RUN_ONE_TESTCASE(testSemdestroy);
|
||||
RUN_ONE_TESTCASE(testThreadChat);
|
||||
}
|
||||
43
testsuites/unittest/xts/ipc/xts_ipc.c
Normal file
43
testsuites/unittest/xts/ipc/xts_ipc.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_test.h"
|
||||
|
||||
void IpcSemApiTest(void)
|
||||
{
|
||||
PosixFutexCondTest();
|
||||
PosixFutexMutexTest();
|
||||
|
||||
PosixSemFuncTest();
|
||||
PosixSemAbnFuncTest();
|
||||
PosixSemXtsFuncTest();
|
||||
|
||||
return;
|
||||
}
|
||||
64
testsuites/unittest/xts/ipc/xts_ipc.h
Normal file
64
testsuites/unittest/xts/ipc/xts_ipc.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef XTS_IPC_H
|
||||
#define XTS_IPC_H
|
||||
|
||||
#include "xts_test.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <securec.h>
|
||||
#include <semaphore.h>
|
||||
#include <sys/resource.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define NANO_S 1000000000
|
||||
#define NANO_MS 1000000
|
||||
|
||||
#define TEN_CONT 10
|
||||
#define FIFTY_CONT 50
|
||||
#define HUNDRED_CONT 100
|
||||
|
||||
#define TEST_INTP_SIZE 10
|
||||
#define TEST_SEEK_SIZE 12
|
||||
#define POSIX_IPC_NO_ERROR 0
|
||||
|
||||
#define KERNEL_NS_PER_SECOND 1000000000
|
||||
#define SEM_VALUE_MAX 0xFFFE
|
||||
|
||||
#define KERNEL_NS_PER_SECOND 1000000000
|
||||
#define KERNEL_100MS_BY_NS 100000000
|
||||
|
||||
#endif
|
||||
37
testsuites/unittest/xts/xts_test.c
Normal file
37
testsuites/unittest/xts/xts_test.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "xts_test.h"
|
||||
|
||||
void XtsTestSuite(void)
|
||||
{
|
||||
IpcSemApiTest();
|
||||
IoFuncTest();
|
||||
}
|
||||
59
testsuites/unittest/xts/xts_test.h
Normal file
59
testsuites/unittest/xts/xts_test.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _XTS_TEST_H
|
||||
#define _XTS_TEST_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "iCunit.h"
|
||||
|
||||
#define TEST_STR(func) ItLos##func
|
||||
#define TEST_TO_STR(x) #x
|
||||
#define TEST_HEAD_TO_STR(x) TEST_TO_STR(x)
|
||||
#define ADD_TEST_CASE(func) \
|
||||
TEST_ADD_CASE(TEST_HEAD_TO_STR(TEST_STR(func)), func, TEST_LOS, TEST_TASK, TEST_LEVEL0, TEST_FUNCTION)
|
||||
|
||||
#define LITE_TEST_SUIT(subsystem, module, testsuit)
|
||||
#define LITE_TEST_CASE(module, function, flag) static int function(void)
|
||||
#define RUN_TEST_SUITE(testsuit)
|
||||
|
||||
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) \
|
||||
ICUNIT_ASSERT_EQUAL(((expected) == (actual)) || (isnan(expected) && isnan(actual)), TRUE, 0)
|
||||
|
||||
#define RUN_ONE_TESTCASE(caseName) ADD_TEST_CASE(caseName)
|
||||
#define AUTO_RUN_ONE_TESTCASEFUNC(func) UnityDefaultTestRun(func, __FILE__, __LINE__)
|
||||
|
||||
void XtsTestSuite(void);
|
||||
|
||||
extern void IpcSemApiTest(void);
|
||||
|
||||
extern void IoFuncTest(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user