chore: fix typo: testsuits --> testsuites

keep testsuites the same directory name as in liteos_a

Signed-off-by: Caoruihong <crh.cao@huawei.com>
This commit is contained in:
Caoruihong
2021-10-21 21:26:54 +08:00
parent 93c1eb54a0
commit 9c69e6039e
710 changed files with 10 additions and 10 deletions

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void IsdigitFuzzTest(void)
{
int c;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], '0');
(void)isdigit(c);
}
printf("Fuzz test in line [%d] isdigit ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void IslowerFuzzTest(void)
{
int c;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], 'a');
(void)islower(c);
}
printf("Fuzz test in line [%d] islower ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void IsxdigitFuzzTest(void)
{
int c;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], '0');
(void)isxdigit(c);
}
printf("Fuzz test in line [%d] isxdigit ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int IsalnumFuzz(void)
{
int i;
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < g_iteration; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
unsigned char ctypeVal = *(unsigned char *)DT_SetGetU8(&g_element[0], 0);
(void)isalnum(ctypeVal);
}
printf("Fuzz test in line [%d] isalnum ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
if (i == g_iteration) {
}
return 0;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int IsasciiFuzz(void)
{
int i;
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < g_iteration; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
unsigned char ctypeVal = *(unsigned char *)DT_SetGetU8(&g_element[0], 0);
(void)isascii(ctypeVal);
}
printf("Fuzz test in line [%d] isascii ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
if (i == g_iteration) {
}
return 0;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int IsprintFuzz(void)
{
int i;
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < g_iteration; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
int ctypeVal = *((int *)DT_SetGetS32(&g_element[0], 0));
(void)isprint(ctypeVal);
}
printf("Fuzz test in line [%d] isprint ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
if (i == g_iteration) {
}
return 0;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int IsspaceFuzz(void)
{
int i;
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < g_iteration; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
unsigned char ctypeVal = *(unsigned char *)DT_SetGetU8(&g_element[0], 0);
(void)isspace(ctypeVal);
}
printf("Fuzz test in line [%d] isspace ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
if (i == g_iteration) {
}
return 0;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int IsupperFuzz(void)
{
int i;
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < g_iteration; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
unsigned char ctypeVal = *(unsigned char *)DT_SetGetU8(&g_element[0], 0);
(void)isupper(ctypeVal);
}
printf("Fuzz test in line [%d] isupper ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
if (i == g_iteration) {
}
return 0;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void TolowerFuzzTest(void)
{
int c;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], 'A');
(void)tolower(c);
}
printf("Fuzz test in line [%d] tolower ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void ToupperFuzzTest(void)
{
int c;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], 'a');
(void)toupper(c);
}
printf("Fuzz test in line [%d] toupper ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
void ItSuiteFuzz(void)
{
IsdigitFuzzTest();
IslowerFuzzTest();
IsxdigitFuzzTest();
TolowerFuzzTest();
ToupperFuzzTest();
AtoiFuzzTest();
AtolFuzzTest();
AtollFuzzTest();
StrtolFuzzTest();
StrtoulFuzzTest();
StrtoullFuzzTest();
StrchrFuzzTest();
StrstrFuzzTest();
IsalnumFuzz();
IsasciiFuzz();
IsprintFuzz();
IsspaceFuzz();
IsupperFuzz();
StdargFuzz();
ItSuiteRegexFuzz();
ReallocFuzzTest();
MemcmpFuzzTest();
MemcpyFuzzTest();
MemsetFuzzTest();
StrcmpFuzzTest();
StrcspnFuzzTest();
StrdupFuzzTest();
StrerrorFuzzTest();
StrlenFuzz();
StrncmpFuzz();
StrrchrFuzz();
StrncasecmpFuzz();
StrptimeFuzzTest();
AbsFuzzTest();
GettimeofdayFuzzTest();
TimesFuzzTest();
GmtimeFuzzTest();
LocaltimeFuzzTest();
LocaltimerFuzzTest();
TimeFuzzTest();
StrftimeFuzzTest();
MktimeFuzzTest();
UsleepFuzzTest();
LogFuzzTest();
PowFuzzTest();
RoundFuzzTest();
SqrtFuzzTest();
SemTimedWaitFuzzTest();
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FUZZ_POSIX_H
#define _FUZZ_POSIX_H
#define RET_FALSE (-1)
#define RET_OK 0
#define RET_TRUE 1
#define NUM_0_INDEX 0
#define NUM_1_INDEX 1
#define NUM_2_INDEX 2
#define NUM_3_INDEX 3
#define NUM_4_INDEX 4
#define NUM_5_INDEX 5
#define ELEMENT_LEN 10
void ItSuiteFuzz(void);
void IsdigitFuzzTest(void);
extern void IslowerFuzzTest(void);
extern void IsxdigitFuzzTest(void);
extern void TolowerFuzzTest(void);
extern void ToupperFuzzTest(void);
extern void AtoiFuzzTest(void);
extern void AtolFuzzTest(void);
extern void AtollFuzzTest(void);
extern void StrtolFuzzTest(void);
extern void StrtoulFuzzTest(void);
extern void StrtoullFuzzTest(void);
extern void StrchrFuzzTest(void);
extern void StrstrFuzzTest(void);
extern void NetFuzzTest(void);
extern void ItSuiteRegexFuzz(void);
extern void ItSuiteStringsFuzz(void);
extern int IsalnumFuzz(void);
extern int IsasciiFuzz(void);
extern int IsprintFuzz(void);
extern int IsspaceFuzz(void);
extern int IsupperFuzz(void);
extern int StdargFuzz(void);
extern void ReallocFuzzTest(void);
extern int MemcmpFuzzTest(void);
extern int MemcpyFuzzTest(void);
extern int MemsetFuzzTest(void);
extern int StrcmpFuzzTest(void);
extern int StrcspnFuzzTest(void);
extern int StrdupFuzzTest(void);
extern int StrerrorFuzzTest(void);
extern int StrlenFuzz(void);
extern int StrncmpFuzz(void);
extern int StrrchrFuzz(void);
extern int StrncasecmpFuzz(void);
extern int StrptimeFuzzTest(void);
extern void DirnameFuzzTest(void);
extern void LogFuzzTest(void);
extern void PowFuzzTest(void);
extern void RoundFuzzTest(void);
extern void SqrtFuzzTest(void);
extern void SemTimedWaitFuzzTest(void);
extern void ClearerrFuzzTest(void);
extern void FeofFuzzTest(void);
extern void PerrorFuzzTest(void);
extern void AbsFuzzTest(void);
extern void GettimeofdayFuzzTest(void);
extern void TimesFuzzTest(void);
extern void GmtimeFuzzTest(void);
extern void LocaltimeFuzzTest(void);
extern void LocaltimerFuzzTest(void);
extern void MktimeFuzzTest(void);
extern void StrftimeFuzzTest(void);
extern void TimeFuzzTest(void);
extern void UsleepFuzzTest(void);
#endif

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <dirent.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define DEFAULT_TIME_VALUE 0
#define STR_LEN 1
#define MAX_STR_LEN 10
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void DirnameFuzzTest(void)
{
char *dirName = NULL;
printf("Fuzz test in line [%d] dirname start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
dirName = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "test");
(void)dirname(dirName);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] dirname ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <math.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define DEFAULT_LOG_VALUE 1.0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void LogFuzzTest(void)
{
double x;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
x = *(double *)DT_SetGetDouble(&g_element[0], DEFAULT_LOG_VALUE);
(void)log(x);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] log ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <math.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define DEFAULT_POW_VALUE 1.0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void PowFuzzTest(void)
{
double x;
double y;
printf("Fuzz test in line [%d] pow start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
x = *(double *)DT_SetGetDouble(&g_element[0], DEFAULT_POW_VALUE);
y = *(double *)DT_SetGetDouble(&g_element[1], DEFAULT_POW_VALUE);
(void)pow(x, y);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] pow ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <math.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define DEFAULT_ROUND_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void RoundFuzzTest(void)
{
double x;
printf("Fuzz test in line [%d] round start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
x = *(double *)DT_SetGetDouble(&g_element[0], DEFAULT_ROUND_VALUE);
(void)round(x);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] round ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <math.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define DEFAULT_SQRT_VALUE 1.0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void SqrtFuzzTest(void)
{
double x;
printf("Fuzz test in line [%d] sqrt start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
x = *(double *)DT_SetGetDouble(&g_element[0], DEFAULT_SQRT_VALUE);
(void)sqrt(x);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] sqrt ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <regex.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define FUZZ_SYS_NAME_LEN 80
#define MAX_STR_BUF_LEN 10
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
static uint32_t RegexFuzz(void)
{
int fd;
int ret;
regex_t preg;
regmatch_t pmatch[1];
const size_t nmatch = 1;
const int initIntValue = 6;
const int initStrLen = 4;
const int maxStrLen = 5;
const int maxNumRange = 6;
const int maxNum1Range = 3;
int spid;
int num;
int num1;
char *string1 = NULL;
char str1[MAX_STR_BUF_LEN] = {0};
char *string2 = NULL;
char str2[MAX_STR_BUF_LEN] = {0};
INIT_FuzzEnvironment();
CreatPrecondForQueue();
printf("RegexFuzz starts,count=%d\n", CYCLE_TOTAL_TIMES);
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
string1 = DT_SetGetString(&g_element[NUM_0_INDEX], initStrLen, maxStrLen, "CHN");
(void)strncpy_s(str1, MAX_STR_BUF_LEN, string1, maxStrLen);
str1[MAX_STR_BUF_LEN - 1] = '\0';
string2 = DT_SetGetString(&g_element[NUM_1_INDEX], initStrLen, maxStrLen, "CHN");
(void)strncpy_s(str2, MAX_STR_BUF_LEN, string2, maxStrLen);
str2[MAX_STR_BUF_LEN - 1] = '\0';
num = *((int *)DT_SetGetS32(&g_element[NUM_2_INDEX], initIntValue));
num = num % maxNumRange;
num1 = *((UINT32 *)DT_SetGetU32(&g_element[NUM_3_INDEX], initIntValue));
num1 = num1 % maxNum1Range;
ret = regcomp(&preg, str1, num);
if (ret != 0) {
regfree(&preg);
continue;
}
regexec(&preg, str2, nmatch, pmatch, num1);
regfree(&preg);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] regcomp/regexec/regfree ok\n", __LINE__);
return 0;
}
void ItSuiteRegexFuzz(void)
{
RegexFuzz();
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <securec.h>
#include <semaphore.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define DEFAULT_SHARED_VALUE 0
#define MAX_SEM_VALUE 32
#define NSEC_MODE_VALUE 100000000
#define SEC_MODE_VALUE 2
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void SemTimedWaitFuzzTest(void)
{
const int elemSecIndex = 4;
const int elemNsecIndex = 5;
struct timespec absTimeout;
sem_t sem;
int pshared, value, getvalue;
printf("Fuzz test in line [%d] sem_timedwait start\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
absTimeout.tv_sec = (*(int *)DT_SetGetS32(&g_element[elemSecIndex], 0)) % SEC_MODE_VALUE;
absTimeout.tv_nsec = (*(int *)DT_SetGetS32(&g_element[elemNsecIndex], 0) % NSEC_MODE_VALUE);
memset_s(&sem, sizeof(sem), 0, sizeof(sem_t));
pshared = (*(int *)DT_SetGetS32(&g_element[1], DEFAULT_SHARED_VALUE));
value = (*(unsigned int *)DT_SetGetU32(&g_element[1], 0)) % MAX_SEM_VALUE;
sem_init(&sem, pshared, value);
sem_post(&sem);
sem_wait(&sem);
sem_post(&sem);
sem_post(&sem);
sem_timedwait(&sem, &absTimeout);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] sem_timedwait ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,330 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <securec.h>
#include <time.h>
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "socket.h"
#include "in.h"
#include "los_task.h"
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#ifndef TASK_PRIO_TEST
#define TASK_PRIO_TEST 2
#endif
#ifndef TASK_STACK_SIZE_TEST
#define TASK_STACK_SIZE_TEST 0x400
#endif
#define LOS_TASK_STATUS_DETACHED 0x0100
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
static UINT32 g_testTaskID01;
#define BUF_SIZE 40
static char g_udpIp[16];
static UINT16 g_udpPort;
#define UDPMSG "ABCDEEFG"
#define SLEEP_SECONDS 2
static void *SampleUdpServer()
{
int fd;
struct sockaddr_in srvAddr = { 0 };
struct sockaddr_in clnAddr = { 0 };
socklen_t clnAddrLen = sizeof(clnAddr);
char buf[BUF_SIZE] = { 0 };
int flag;
struct msghdr msg = { 0 };
struct iovec iov[2] = { };
printf("s0\r\n");
fd = socket(AF_INET, SOCK_DGRAM, 0);
printf("s1\r\n");
srvAddr.sin_family = AF_INET;
srvAddr.sin_addr.s_addr = inet_addr(g_udpIp);
srvAddr.sin_port = htons(g_udpPort);
int ret = bind(fd, (struct sockaddr *)&srvAddr, sizeof(srvAddr));
printf("s1.1, ret = %d\r\n", ret);
(void)recvfrom(fd, buf, sizeof(buf), 0x40, (struct sockaddr *)&clnAddr, &clnAddrLen);
printf("s2, buf = %s\r\n", buf);
usleep(SLEEP_SECONDS);
msg.msg_name = &clnAddr;
msg.msg_namelen = sizeof(clnAddr);
msg.msg_iov = iov;
msg.msg_iovlen = 1;
iov[0].iov_base = buf;
iov[0].iov_len = strlen(buf);
(void)sendmsg(fd, &msg, 0);
printf("s3\r\n");
close(fd);
return NULL;
}
static void *SampleUdpClient()
{
int fd = 0;
const int sleepSec = 5;
struct sockaddr_in clnAddr = { 0 };
char buf[BUF_SIZE] = { 0 };
int flag;
struct msghdr msg;
struct iovec iov[2];
printf("c1\r\n");
fd = socket(AF_INET, SOCK_DGRAM, 0);
printf("c2\r\n");
clnAddr.sin_family = AF_INET;
clnAddr.sin_addr.s_addr = inet_addr(g_udpIp);
clnAddr.sin_port = htons(g_udpPort);
printf("c3\r\n");
strcpy_s(buf, sizeof(buf), UDPMSG);
usleep(sleepSec);
printf("c4, %s, %d\r\n", buf, strlen(buf));
(void)sendto(fd, buf, strlen(buf), 0, (struct sockaddr *)&clnAddr, (socklen_t)sizeof(clnAddr));
msg.msg_name = &clnAddr;
msg.msg_namelen = sizeof(clnAddr);
msg.msg_iov = iov;
msg.msg_iovlen = 1;
iov[0].iov_base = buf;
iov[0].iov_len = sizeof(buf);
(void)recvmsg(fd, &msg, 0x40);
printf("c6\r\n");
close(fd);
return NULL;
}
static UINT32 UdpFun(VOID)
{
int i;
UINT8 num1;
UINT8 num2;
UINT8 num3;
UINT8 num4;
UINT8 num5;
INIT_FuzzEnvironment();
printf("UDPFun starts\n");
for (i = 0; i < g_iteration; i++) {
num1 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_0_INDEX], 1);
num2 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_1_INDEX], 1);
num3 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_2_INDEX], 1);
num4 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_3_INDEX], 1);
num5 = *(UINT8 *)DT_SetGetU8(&g_element[NUM_4_INDEX], 1);
(void)snprintf_s(g_udpIp, sizeof(g_udpIp), sizeof(g_udpIp) - 1, "%d.%d.%d.%d", num1, num2, num3, num4);
g_udpPort = *(UINT16 *)DT_SetGetU16(&g_element[NUM_5_INDEX], 0);
{
TSK_INIT_PARAM_S stTask1 = { 0 };
stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)SampleUdpServer;
stTask1.uwStackSize = TASK_STACK_SIZE_TEST;
stTask1.pcName = "Tsk001A";
stTask1.usTaskPrio = TASK_PRIO_TEST;
stTask1.uwResved = LOS_TASK_STATUS_DETACHED;
(void)LOS_TaskCreate(&g_testTaskID01, &stTask1);
}
{
TSK_INIT_PARAM_S stTask1 = { 0 };
stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)SampleUdpClient;
stTask1.uwStackSize = TASK_STACK_SIZE_TEST;
stTask1.pcName = "Tsk001A";
stTask1.usTaskPrio = TASK_PRIO_TEST;
stTask1.uwResved = LOS_TASK_STATUS_DETACHED;
(void)LOS_TaskCreate(&g_testTaskID01, &stTask1);
}
}
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("UDPFun end ....\n");
return 0;
}
#define LOCAL_HOST "127.0.0.1"
#define STACK_IP LOCAL_HOST
#define STACK_PORT 2277
#define PEER_PORT STACK_PORT
#define PEER_IP LOCAL_HOST
#define SRV_MSG "Hi, I am TCP server"
#define CLI_MSG "Hi, I am TCP client"
static void *SampleTcpServer()
{
char buf[BUF_SIZE + 1] = { 0 };
int sfd;
int lsfd;
struct sockaddr_in srvAddr = { 0 };
struct sockaddr_in clnAddr = { 0 };
int ret;
// socket had fuzz test in udpfun. now must create a useful fd, wwx520273
lsfd = socket(AF_INET, SOCK_STREAM, 0);
srvAddr.sin_family = AF_INET;
srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
srvAddr.sin_port = htons(STACK_PORT);
(void)bind(lsfd, (struct sockaddr *)&srvAddr, sizeof(srvAddr));
int num1 = *(int *)DT_SetGetS32(&g_element[NUM_0_INDEX], 0);
(void)listen(lsfd, num1);
int num2 = *(int *)DT_SetGetS32(&g_element[NUM_1_INDEX], 0);
sfd = accept(lsfd, (struct sockaddr *)&clnAddr, &num2);
int num3 = *(int *)DT_SetGetS32(&g_element[NUM_2_INDEX], 0);
ret = recv(lsfd, buf, sizeof(buf), num3);
int num4 = *(int *)DT_SetGetS32(&g_element[NUM_3_INDEX], 0);
ret = shutdown(sfd, num4);
if (ret != 0) {
shutdown(sfd, SHUT_RDWR);
}
close(sfd);
close(lsfd);
return (void *)(intptr_t)ret;
}
static void *SampleTcpClient()
{
char buf[BUF_SIZE + 1] = { 0 };
int sfd = -1;
struct sockaddr_in srvAddr = { 0 };
struct sockaddr_in clnAddr = { 0 };
int ret;
struct sockaddr addr;
socklen_t addrLen = sizeof(addr);
/* tcp client connection */
sfd = socket(AF_INET, SOCK_STREAM, 0);
srvAddr.sin_family = AF_INET;
srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
srvAddr.sin_port = htons(PEER_PORT);
connect(sfd, (struct sockaddr *)&srvAddr, sizeof(srvAddr));
int num1 = *(int *)DT_SetGetS32(&g_element[0], 0);
(void)getpeername(num1, &addr, &addrLen);
(void)getsockname(num1, &addr, &addrLen);
/* send */
ret = memset_s(buf, sizeof(buf), 0, BUF_SIZE);
if (err != EOK) {
return (void *)(intptr_t)ret;
}
strcpy_s(buf, sizeof(buf), CLI_MSG);
int num2 = *(int *)DT_SetGetS32(&g_element[1], 0);
send(num1, buf, strlen(CLI_MSG), num2);
ret = shutdown(sfd, SHUT_RDWR);
close(sfd);
return (void *)(intptr_t)ret;
}
static UINT32 TcpFun(VOID)
{
int i;
INIT_FuzzEnvironment();
printf("TcpFun starts\n");
for (i = 0; i < g_iteration; i++) {
{
TSK_INIT_PARAM_S stTask1 = { 0 };
stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)SampleTcpServer;
stTask1.uwStackSize = TASK_STACK_SIZE_TEST;
stTask1.pcName = "Tsk001A";
stTask1.usTaskPrio = TASK_PRIO_TEST;
stTask1.uwResved = LOS_TASK_STATUS_DETACHED;
(void)LOS_TaskCreate(&g_testTaskID01, &stTask1);
}
{
TSK_INIT_PARAM_S stTask1 = { 0 };
stTask1.pfnTaskEntry = (TSK_ENTRY_FUNC)SampleTcpClient;
stTask1.uwStackSize = TASK_STACK_SIZE_TEST;
stTask1.pcName = "Tsk001A";
stTask1.usTaskPrio = TASK_PRIO_TEST;
stTask1.uwResved = LOS_TASK_STATUS_DETACHED;
(void)LOS_TaskCreate(&g_testTaskID01, &stTask1);
}
};
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("TcpFun end ....\n");
return 0;
}
void NetFuzzTest(void)
{
DnCompFun();
UdpFun();
TcpFun();
InetFun();
ProtoentFun();
ConvertFun();
SocketFun();
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdarg.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
static int VaFunc(int argsNum, ...)
{
int sum1 = 0;
int sum2 = 0;
va_list argPtr1;
va_start(argPtr1, argsNum);
va_list argPtr2;
va_copy(argPtr2, argPtr1);
for (int i = 0; i < argsNum; i++) {
sum1 += va_arg(argPtr1, int);
sum2 += va_arg(argPtr2, int);
}
int sum = sum1 + sum2;
va_end(argPtr1);
va_end(argPtr2);
return sum;
}
int StdargFuzz(void)
{
int i;
const int initValue1 = 5;
const int initValue2 = 10;
const int initValue3 = 15;
const int argNum = 3;
const int count = 2;
printf("Fuzz test in line [%d] stdarg start\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < g_iteration; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
unsigned int stdargVal1 = *((unsigned int *)DT_SetGetU32(&g_element[NUM_0_INDEX], initValue1));
unsigned int stdargVal2 = *((unsigned int *)DT_SetGetU32(&g_element[NUM_1_INDEX], initValue2));
unsigned int stdargVal3 = *((unsigned int *)DT_SetGetU32(&g_element[NUM_2_INDEX], initValue3));
int ret = VaFunc(argNum, stdargVal1, stdargVal2, stdargVal3);
int sum = (stdargVal1 + stdargVal2 + stdargVal3) * count;
if (ret == sum) {
printf("VA_FUNC_TEST(3, %d, %d, %d) = %d", stdargVal1, stdargVal2, stdargVal3, ret);
return RET_TRUE;
}
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] va_start/va_copy/va_end ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define DEFAULT_TIME_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void ClearerrFuzzTest(void)
{
FILE *stream = NULL;
char fileName[] = "./test.txt";
printf("Fuzz test in line [%d] clearerr start\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
stream = fopen(fileName, "rw");
if (stream == NULL) {
printf("fopen(%s) fail\n", fileName);
return;
}
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
(void)clearerr(stream);
}
(void)fclose(stream);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] clearerr ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define DEFAULT_TIME_VALUE 0
#define MAX_BUFFER_SIZE 100
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void FeofFuzzTest(void)
{
FILE *stream = NULL;
char fileName[] = "./test.txt";
char str[MAX_BUFFER_SIZE] = {0};
printf("Fuzz test in line [%d] feof start\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
stream = fopen(fileName, "rw");
if (stream == NULL) {
printf("fopen(%s) fail\n", fileName);
return;
}
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
(void)fread(str, MAX_BUFFER_SIZE, 1, stream);
(void)feof(stream);
}
(void)fclose(stream);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] feof ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 1024
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void PerrorFuzzTest(void)
{
char *str = NULL;
printf("Fuzz test in line [%d] perror start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "syserror");
(void)perror(str);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] perror ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define DEFAULT_ABS_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void AbsFuzzTest(void)
{
int absNum;
dprintf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
absNum = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_ABS_VALUE);
(void)abs(absNum);
}
printf("Fuzz test in line [%d] abs ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 10
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void AtoiFuzzTest(void)
{
char *str = NULL;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1");
(void)atoi(str);
}
printf("Fuzz test in line [%d] atoi ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 10
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void AtolFuzzTest(void)
{
char *str = NULL;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1");
(void)atol(str);
}
printf("Fuzz test in line [%d] atol ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 19
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void AtollFuzzTest(void)
{
char *str = NULL;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1");
(void)atoll(str);
}
printf("Fuzz test in line [%d] atoll ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define TEST_BUF_LEN 256
#define TEST_MAX_BUF_LEN 1024
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void ReallocFuzzTest(void)
{
char *source = NULL;
int c;
printf("Fuzz test in line [%d] realloc start\n", __LINE__);
source = (char *)malloc(TEST_BUF_LEN);
if (source == NULL) {
printf("Fuzz test in line [%d] malloc fail.\n", __LINE__);
return;
}
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], TEST_BUF_LEN);
if ((c <= 0) || (c > TEST_MAX_BUF_LEN)) {
c = TEST_BUF_LEN;
}
source = (char *)realloc(source, c);
}
if (source == NULL) {
free(source);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] realloc ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 10
#define MAX_BASE_VALUE 32
#define MIN_BASE_VALUE 2
#define DEFAULT_BASE_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void StrtolFuzzTest(void)
{
int base = DEFAULT_BASE_VALUE;
char *str = NULL;
char *endPtr = NULL;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
base = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_BASE_VALUE);
if ((base > MAX_BASE_VALUE) || ((base < MIN_BASE_VALUE) && (base != DEFAULT_BASE_VALUE))) {
base = DEFAULT_BASE_VALUE;
}
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1");
(void)strtol(str, endPtr, base);
}
printf("Fuzz test in line [%d] strtol ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 10
#define MAX_BASE_VALUE 32
#define MIN_BASE_VALUE 2
#define DEFAULT_BASE_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void StrtoulFuzzTest(void)
{
int base = DEFAULT_BASE_VALUE;
char *str = NULL;
char *endPtr = NULL;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
base = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_BASE_VALUE);
if ((base > MAX_BASE_VALUE) || ((base < MIN_BASE_VALUE) && (base != DEFAULT_BASE_VALUE))) {
base = DEFAULT_BASE_VALUE;
}
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1");
(void)strtoul(str, endPtr, base);
}
printf("Fuzz test in line [%d] strtoul ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 20
#define MAX_BASE_VALUE 32
#define MIN_BASE_VALUE 2
#define DEFAULT_BASE_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void StrtoullFuzzTest(void)
{
int base = DEFAULT_BASE_VALUE;
char *str = NULL;
char *endPtr = NULL;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
base = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_BASE_VALUE);
if ((base > MAX_BASE_VALUE) || ((base < MIN_BASE_VALUE) && (base != DEFAULT_BASE_VALUE))) {
base = DEFAULT_BASE_VALUE;
}
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "1");
(void)strtoull(str, endPtr, base);
}
printf("Fuzz test in line [%d] strtoull ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int MemcmpFuzzTest(void)
{
char *source = NULL;
char *dest = NULL;
printf("Fuzz test in line [%d] memcmp start\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin");
dest = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin");
(void)memcmp(source, dest, strlen(source));
}
printf("Fuzz test in line [%d] memcmp ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return 0;
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int MemcpyFuzzTest(void)
{
char dest[MAX_STR_LEN + 1] = { 0 };
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
char *source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin");
(void)memcpy(dest, source, MAX_STR_LEN);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] memcpy ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
#define DEFAULT_S32_VALUE 0
#define DEFAULT_U8_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int MemsetFuzzTest(void)
{
char source[MAX_STR_LEN + 1] = { 0 };
char dest;
int c;
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_S32_VALUE);
if (c > MAX_STR_LEN || c < 0) {
c = MAX_STR_LEN;
}
dest = (char)(DT_SetGetU8(&g_element[0], DEFAULT_U8_VALUE));
(void)memset(source, dest, c);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] memset ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 256
#define DEFAULT_S32_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void StrchrFuzzTest(void)
{
int c;
char *str = NULL;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_S32_VALUE);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "abcdefghijklmnopqrstuvwxyz");
(void)strchr(str, c);
}
printf("Fuzz test in line [%d] strchr ok\n", __LINE__);
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
return;
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrcmpFuzzTest(void)
{
char *source = NULL;
char *dest = NULL;
printf("Fuzz test in line [%d] strcmp start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin");
dest = (char *)DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, "pin");
(void)strcmp(source, dest);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strcmp ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrcspnFuzzTest(void)
{
char *source = NULL;
char *dest = NULL;
printf("Fuzz test in line [%d] strcspn start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin");
dest = (char *)DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, "pin");
(void)strcspn(source, dest);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strcspn ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrdupFuzzTest(void)
{
char *source = NULL;
char *dest = NULL;
printf("Fuzz test in line [%d] strdup start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
source = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "pin");
dest = strdup(source);
if (dest != NULL) {
free(dest);
dest = NULL;
}
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strdup ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrerrorFuzzTest(void)
{
int c;
printf("Fuzz test in line [%d] strerror start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], 0);
(void)strerror(c);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strerror ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void StrstrFuzzTest(void)
{
char *str = NULL;
char *substr = NULL;
printf("Fuzz test in line [%d]\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "abcdefghijklmnopqrstuvwxyz");
substr = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "bcd");
(void)strstr(str, substr);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strstr ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrlenFuzz(void)
{
int i;
char *str = NULL;
printf("Fuzz test in line [%d] strlen start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "");
(void)strlen(str);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strlen ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrncmpFuzz(void)
{
int i;
char *stringVal1 = NULL;
char *stringVal2 = NULL;
printf("Fuzz test in line [%d] strncmp start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
stringVal1 = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "string");
stringVal2 = (char *)DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, "STring");
(void)strncmp(stringVal1, stringVal2, strlen(stringVal1));
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strncmp ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define STR_LEN 1
#define MAX_STR_LEN 256
#define DEFAULT_S32_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrrchrFuzz(void)
{
int i;
int c;
char *str = NULL;
printf("Fuzz test in line [%d] strrchr start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
c = *(int *)DT_SetGetS32(&g_element[0], DEFAULT_S32_VALUE);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "");
(void)strrchr(str, c);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strrchr ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include <strings.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
static uint32_t StrcasecmpFuzz(void)
{
int i;
char *lstring = NULL;
char *rstring = NULL;
INIT_FuzzEnvironment();
CreatPrecondForQueue();
printf("StrcasecmpFuzz starts\n");
for (i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
lstring = DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "");
rstring = DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, "");
(void)strcasecmp(lstring, rstring);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strcasecmp ok\n", __LINE__);
return 0;
}
void ItSuiteStringsFuzz(void)
{
StrcasecmpFuzz();
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "strings.h"
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrncasecmpFuzz(void)
{
int i;
char *stringVal1 = NULL;
char *stringVal2 = NULL;
const size_t size = 2;
printf("Fuzz test in line [%d] strncasecmp start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
stringVal1 = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "");
stringVal2 = (char *)DT_SetGetString(&g_element[1], STR_LEN, MAX_STR_LEN, "");
(void)strncasecmp(stringVal1, stringVal2, size);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strncasecmp ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#define __NEED_suseconds_t
#define __NEED_struct_timeval
#include <sys/time.h>
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void GettimeofdayFuzzTest(void)
{
struct timeval tv;
struct timezone tz;
printf("Fuzz test in line [%d] gettimeofday start\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
(void)gettimeofday(&tv, &tz);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] gettimeofday ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "time.h"
#include "times.h"
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void TimesFuzzTest(void)
{
struct tms buf;
printf("Fuzz test in line [%d] times start\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
(void)times(&buf);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] times ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define DEFAULT_TIME_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void GmtimeFuzzTest(void)
{
time_t timep;
printf("Fuzz test in line [%d] gmtime start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
timep = DT_SetGetS64(&g_element[0], DEFAULT_TIME_VALUE);
(void)gmtime(&timep);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] gmtime ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define DEFAULT_TIME_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void LocaltimeFuzzTest(void)
{
time_t timep;
printf("Fuzz test in line [%d] localtime start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
timep = DT_SetGetS64(&g_element[0], DEFAULT_TIME_VALUE);
(void)localtime(&timep);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] localtime ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define DEFAULT_TIME_VALUE 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void LocaltimerFuzzTest(void)
{
time_t timep;
struct tm result;
printf("Fuzz test in line [%d] localtime_r start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
timep = DT_SetGetS64(&g_element[0], DEFAULT_TIME_VALUE);
(void)localtime_r(&timep, &result);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] localtime_r ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define MAX_RAMD_TIME_POS 65535
#define MIN_RAMD_TIME_POS 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void MktimeFuzzTest(void)
{
struct tm *ptm = NULL;
time_t timeValue;
int c;
printf("Fuzz test in line [%d] mktime start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
(void)time(&timeValue);
ptm = localtime(&timeValue);
if (ptm == NULL) {
printf("Fuzz test in line [%d] mktime ptm == NULL,count:%d.\n", __LINE__, i);
return;
}
c = *(int *)DT_SetGetS32(&g_element[0], MIN_RAMD_TIME_POS);
if (c < MIN_RAMD_TIME_POS || (c > MAX_RAMD_TIME_POS)) {
c = MIN_RAMD_TIME_POS;
}
ptm->tm_sec += c;
(void)mktime(ptm);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] mktime ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define MAX_S_LEN 64
#define MAX_RAMD_TIME_POS 65535
#define MIN_RAMD_TIME_POS 0
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void StrftimeFuzzTest(void)
{
time_t timeValue;
struct tm *ptm = NULL;
char s[MAX_S_LEN];
int c;
printf("Fuzz test in line [%d] strftime start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
(void)time(&timeValue);
ptm = localtime(&timeValue);
if (ptm == NULL) {
printf("Fuzz test in line [%d] strftime ptm == NULL,count:%d.\n", __LINE__, i);
return;
}
c = *(int *)DT_SetGetS32(&g_element[0], MIN_RAMD_TIME_POS);
if (c < MIN_RAMD_TIME_POS || (c > MAX_RAMD_TIME_POS)) {
c = MIN_RAMD_TIME_POS;
}
ptm->tm_sec += c;
(void)strftime(s, MAX_S_LEN, "%Y-%m-%d %H:%M:%S.%f", ptm);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strftime ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
#define STR_LEN 1
#define MAX_STR_LEN 256
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
int StrptimeFuzzTest(void)
{
char *str = NULL;
struct tm tm;
printf("Fuzz test in line [%d] strptime start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
str = (char *)DT_SetGetString(&g_element[0], STR_LEN, MAX_STR_LEN, "20210304133500");
(void)strptime(str, "%Y%m%d%H%M%S", &tm);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] strptime ok\n", __LINE__);
return 0;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1024
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void TimeFuzzTest(void)
{
time_t tloc;
printf("Fuzz test in line [%d] time start.\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
(void)time(&tloc);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] time ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define __NEED_useconds_t
#include <time.h>
#include "ohos_types.h"
#include "los_config.h"
#include "Public.h"
#include "PCommon.h"
#include "fuzz_posix.h"
#define CYCLE_TOTAL_TIMES 1000
#define DEFAULT_USECONDS_VALUE 1
#define USECONDS_MODE_VALUE 500
extern S_ElementInit g_element[ELEMENT_LEN];
extern int g_iteration;
void UsleepFuzzTest(void)
{
useconds_t usec;
printf("Fuzz test in line [%d] usleep start\n", __LINE__);
INIT_FuzzEnvironment();
CreatPrecondForQueue();
for (int i = 0; i < CYCLE_TOTAL_TIMES; i++) {
hi_watchdog_feed();
heartbeatPrint(i);
usec = (*(useconds_t *)DT_SetGetS64(&g_element[0], DEFAULT_USECONDS_VALUE)) % USECONDS_MODE_VALUE;
(void)usleep(usec);
}
CleanPrecondForQueue();
DT_Clear(g_element);
CLOSE_Log();
CLEAR_FuzzEnvironment();
printf("Fuzz test in line [%d] usleep ok\n", __LINE__);
return;
}

View File

@@ -0,0 +1,71 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//test/xts/tools/lite/build/suite_lite.gni")
hctest_suite("PosixTest") {
suite_name = "acts"
sources = [
"src/ctype/ctype_func_test.c",
"src/ctype/isdigit_test.c",
"src/ctype/islower_test.c",
"src/ctype/isxdigit_test.c",
"src/ctype/tolower_test.c",
"src/ctype/toupper_test.c",
"src/errno/strerror_test.c",
"src/fs/posix_fs_func_test.c",
"src/math/math_func_test.c",
"src/mqueue/mqueue_func_test.c",
"src/pthread/pthread_cond_func_test.c",
"src/regex/regex_func_test.c",
"src/semaphore/semaphore_func_test.c",
"src/stdarg/stdarg_func_test.c",
"src/stdlib/atoi_test.c",
"src/stdlib/atol_test.c",
"src/stdlib/atoll_test.c",
"src/stdlib/strtol_test.c",
"src/stdlib/strtoul_test.c",
"src/stdlib/strtoull_test.c",
"src/string/memory_func_test.c",
"src/string/strchr_test.c",
"src/string/string_func_test_01.c",
"src/string/string_func_test_02.c",
"src/string/string_func_test_03.c",
"src/string/strstr_test.c",
"src/time/time_func_test_01.c",
]
include_dirs = [
"//test/xts/tools/hctest/include",
"//third_party/unity/src",
"src",
]
cflags = [ "-Wno-error" ]
deps = [ "//kernel/liteos_m/kal/posix" ]
}

View File

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

View File

@@ -0,0 +1,105 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KERNEL_TEST_H
#define KERNEL_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
#define TESTCOUNT_NUM_3 3
#define TESTCOUNT_NUM_4 4
#define TESTCOUNT_NUM_5 5
#define DELAY_TICKS_1 1
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30
#define THREAD_STACK_SPACE_MAX 4096
#define ICUNIT_GOTO_NOT_EQUAL(param, value, retcode, label) \
do { \
if ((param) == (value)) { \
TEST_ASSERT_NOT_EQUAL(param, value); \
printf("\nret = %d, expect = %d\n", param, value); \
goto label; \
} \
} while (0)
#define ICUNIT_GOTO_EQUAL(param, value, retcode, label) \
do { \
if ((param) != (value)) { \
TEST_ASSERT_EQUAL(param, value); \
printf("\nret = %d, expect = %d\n", param, value); \
goto label; \
} \
} while (0)
#define ICUNIT_GOTO_STRING_EQUAL(str1, str2, retcode, label) \
do { \
if (strcmp(str1, str2) != 0) { \
TEST_ASSERT_EQUAL(retcode, retcode + 1); \
goto label; \
} \
} while (0)
#define ICUNIT_ASSERT_EQUAL_VOID(param, value, retcode) \
do { \
if ((param) != (value)) { \
TEST_ASSERT_EQUAL(param, value); \
return; \
} \
} while (0)
#define ICUNIT_TRACK_EQUAL(param, value, retcode) \
do { \
if ((param) != (value)) { \
TEST_ASSERT_EQUAL(param, value); \
printf("\nret = %d, expect = %d\n", param, value); \
} \
} while (0)
#define ICUNIT_TRACK_NOT_EQUAL(param, value, retcode) \
do { \
if ((param) == (value)) { \
TEST_ASSERT_NOT_EQUAL(param, value); \
printf("\nret = %d, expect = %d\n", param, value); \
} \
} while (0)
#ifdef __cplusplus
#if __cplusplus
#endif
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,403 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#define RET_TRUE 1
#define RET_FALSE 0
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixctype, PosixCtypeFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCtypeFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCtypeFuncTestSuiteTearDown(void)
{
printf("==== [ Ctype TEST ] ====\n\n");
return TRUE;
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_001
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum001, Function | MediumTest | Level1)
{
int src = 'A';
int ret = isalnum(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_002
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum002, Function | MediumTest | Level1)
{
int src = '1';
int ret = isalnum(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_003
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum003, Function | MediumTest | Level1)
{
int src = '@';
int ret = isalnum(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_004
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum004, Function | MediumTest | Level1)
{
int src = ' ';
int ret = isalnum(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISALNUM_005
* @tc.name ctype_isalnum test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsalnum005, Function | MediumTest | Level1)
{
int src = '\f'; // 0x0c 14
int ret = isalnum(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_001
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii001, Function | MediumTest | Level1)
{
const int src = -1;
int ret = isascii(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_002
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii002, Function | MediumTest | Level1)
{
const int src = 0;
int ret = isascii(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_003
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii003, Function | MediumTest | Level1)
{
const int src = 127;
int ret = isascii(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_004
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii004, Function | MediumTest | Level1)
{
const int src = 128;
int ret = isascii(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISASCII_005
* @tc.name ctype_isascii test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsascii005, Function | MediumTest | Level1)
{
int src = '\f'; // 0x0c 14
int ret = isascii(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_001
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint001, Function | MediumTest | Level1)
{
int src = 'A';
int ret = isprint(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_002
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint002, Function | MediumTest | Level1)
{
int src = '1';
int ret = isprint(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_003
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint003, Function | MediumTest | Level1)
{
int src = '@';
int ret = isprint(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_004
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint004, Function | MediumTest | Level1)
{
int src = ' ';
int ret = isprint(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISPRINT_005
* @tc.name ctype_isprint test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsprint005, Function | MediumTest | Level1)
{
int src = '\f'; // 0x0c
int ret = isprint(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_001
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace001, Function | MediumTest | Level1)
{
int src = 'A';
int ret = isspace(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_002
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace002, Function | MediumTest | Level1)
{
int src = '1';
int ret = isspace(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_003
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace003, Function | MediumTest | Level1)
{
int src = '@';
int ret = isspace(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_004
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace004, Function | MediumTest | Level1)
{
int src = ' ';
int ret = isspace(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISSPACE_005
* @tc.name Ctype_isspace test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsspace005, Function | MediumTest | Level1)
{
int src = '\t';
int ret = isspace(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_001
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper001, Function | MediumTest | Level1)
{
int src = 'A';
int ret = isupper(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_002
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper002, Function | MediumTest | Level1)
{
int src = 'a';
int ret = isupper(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_003
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper003, Function | MediumTest | Level1)
{
const int src = 0x45;
int ret = isupper(src);
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_004
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper004, Function | MediumTest | Level1)
{
int src = ' ';
int ret = isupper(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number TEST_CTYPE_ISUPPER_005
* @tc.name Ctype_isupper test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCtypeFuncTestSuite, testCtypeIsupper005, Function | MediumTest | Level1)
{
int src = '\t';
int ret = isupper(src);
TEST_ASSERT_EQUAL_INT(0, ret);
}
RUN_TEST_SUITE(PosixCtypeFuncTestSuite);
void PosixCtypeFuncTest()
{
LOG("begin PosixCtypeFuncTest....");
RUN_ONE_TESTCASE(testCtypeIsalnum001);
RUN_ONE_TESTCASE(testCtypeIsalnum002);
RUN_ONE_TESTCASE(testCtypeIsalnum003);
RUN_ONE_TESTCASE(testCtypeIsalnum004);
RUN_ONE_TESTCASE(testCtypeIsalnum005);
RUN_ONE_TESTCASE(testCtypeIsascii001);
RUN_ONE_TESTCASE(testCtypeIsascii002);
RUN_ONE_TESTCASE(testCtypeIsascii003);
RUN_ONE_TESTCASE(testCtypeIsascii004);
RUN_ONE_TESTCASE(testCtypeIsascii005);
RUN_ONE_TESTCASE(testCtypeIsprint001);
RUN_ONE_TESTCASE(testCtypeIsprint002);
RUN_ONE_TESTCASE(testCtypeIsprint003);
RUN_ONE_TESTCASE(testCtypeIsprint004);
RUN_ONE_TESTCASE(testCtypeIsprint005);
RUN_ONE_TESTCASE(testCtypeIsspace001);
RUN_ONE_TESTCASE(testCtypeIsspace002);
RUN_ONE_TESTCASE(testCtypeIsspace003);
RUN_ONE_TESTCASE(testCtypeIsspace004);
RUN_ONE_TESTCASE(testCtypeIsspace005);
RUN_ONE_TESTCASE(testCtypeIsupper001);
RUN_ONE_TESTCASE(testCtypeIsupper002);
RUN_ONE_TESTCASE(testCtypeIsupper003);
RUN_ONE_TESTCASE(testCtypeIsupper004);
RUN_ONE_TESTCASE(testCtypeIsupper005);
return;
}

View File

@@ -0,0 +1,171 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/**
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixCTypeIsdigitTest);
/**
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIsdigitTestSetUp(void)
{
return TRUE;
}
/**
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIsdigitTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_001
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit001, Function | MediumTest | Level1)
{
int a = '0';
int ret = isdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 1:isdigit(%c) ok.\n", a);
}
else {
LOG("[DEMO] posix ctype test case 1:isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_002
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit002, Function | MediumTest | Level1)
{
int a = '5';
int ret = isdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 2:isdigit(%c) ok.\n", a);
}
else {
LOG("[DEMO] posix ctype test case 2:isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_003
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit003, Function | MediumTest | Level1)
{
int a = '9';
int ret = isdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 3:isdigit(%c) ok.\n", a);
}
else {
LOG("[DEMO] posix ctype test case 3:isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_004
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit004, Function | MediumTest | Level1)
{
int a = '0' - 1;
int ret = isdigit(a);
if (ret == 0) {
LOG("[DEMO] posix ctype test case 4(except):isdigit(%c) ok.\n", a);
}
else {
LOG("[DEMO] posix ctype test case 4(except):isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/**
* @tc.number : TEST_CTYPE_ISDIGIT_005
* @tc.name : Checks whether a parameter is a decimal digit (0-9)
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsdigitTest, testCTypeIsdigit005, Function | MediumTest | Level1)
{
int a = '9' + 1;
int ret = isdigit(a);
if (ret == 0) {
LOG("[DEMO] posix ctype test case 5(except):isdigit(%c) ok.\n", a);
}
else {
LOG("[DEMO] posix ctype test case 5(except):isdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
RUN_TEST_SUITE(PosixCTypeIsdigitTest);
void PosixIsdigitFuncTest()
{
LOG("begin PosixIsdigitFuncTest....");
RUN_ONE_TESTCASE(testCTypeIsdigit001);
RUN_ONE_TESTCASE(testCTypeIsdigit002);
RUN_ONE_TESTCASE(testCTypeIsdigit003);
RUN_ONE_TESTCASE(testCTypeIsdigit004);
RUN_ONE_TESTCASE(testCTypeIsdigit005);
return;
}

View File

@@ -0,0 +1,182 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixCTypeIslowerTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIslowerTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIslowerTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_001
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower001, Function | MediumTest | Level1)
{
int a = 'a';
int ret = islower(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 1:islower(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 1:islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_002
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower002, Function | MediumTest | Level1)
{
int a = 'z';
int ret = islower(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 2:islower(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 2:islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_003
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower003, Function | MediumTest | Level1)
{
int a = 'f';
int ret = islower(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 3:islower(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 3:islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(1, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_004
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower004, Function | MediumTest | Level1)
{
int a = 'a' - 1;
int ret = islower(a);
if (ret == 0) {
LOG("[DEMO] posix ctype test case 4(except):islower(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 4(except):islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_005
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower005, Function | MediumTest | Level1)
{
int a = 'z' + 1;
int ret = islower(a);
if (ret == 0) {
LOG("[DEMO] posix ctype test case 5(except):islower(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 5(except):islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISLOWER_006
* @tc.name : Checks whether a parameter is a lowercase letter
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIslowerTest, testCTypeIslower006, Function | MediumTest | Level1)
{
int a = 'A';
int ret = islower(a);
if (ret == 0) {
LOG("[DEMO] posix ctype test case 6(except):islower(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 6(except):islower(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
RUN_TEST_SUITE(PosixCTypeIslowerTest);
void PosixIslowerFuncTest()
{
LOG("begin PosixIslowerFuncTest....");
RUN_ONE_TESTCASE(testCTypeIslower001);
RUN_ONE_TESTCASE(testCTypeIslower002);
RUN_ONE_TESTCASE(testCTypeIslower003);
RUN_ONE_TESTCASE(testCTypeIslower004);
RUN_ONE_TESTCASE(testCTypeIslower005);
RUN_ONE_TESTCASE(testCTypeIslower006);
return;
}

View File

@@ -0,0 +1,254 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixCTypeIsxdigitTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIsxdigitTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeIsxdigitTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_001
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit001, Function | MediumTest | Level1)
{
int a = '0';
int ret = isxdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_002
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit002, Function | MediumTest | Level1)
{
int a = '5';
int ret = isxdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 2:isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 2:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_003
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit003, Function | MediumTest | Level1)
{
int a = '9';
int ret = isxdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 3:isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 3:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_004
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit004, Function | MediumTest | Level1)
{
int a = 'a';
int ret = isxdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_005
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit005, Function | MediumTest | Level1)
{
int a = 'f';
int ret = isxdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_006
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit006, Function | MediumTest | Level1)
{
int a = 'A';
int ret = isxdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_007
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit007, Function | MediumTest | Level1)
{
int a = 'F';
int ret = isxdigit(a);
if (ret != 0) {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 1:isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_NOT_EQUAL(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_008
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit008, Function | MediumTest | Level1)
{
int a = 'F' + 1;
int ret = isxdigit(a);
if (ret == 0) {
LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_009
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit009, Function | MediumTest | Level1)
{
int a = '0' - 1;
int ret = isxdigit(a);
if (ret == 0) {
LOG("[DEMO] posix ctype test case 4(except):isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 4(except):isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
/* *
* @tc.number : TEST_CTYPE_ISXDIGIT_010
* @tc.name : Checks whether a parameter is a hexadecimal digit
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeIsxdigitTest, testCTypeIsxdigit010, Function | MediumTest | Level1)
{
int a = '9' + 1;
int ret = isxdigit(a);
if (ret == 0) {
LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) ok.\n", a);
} else {
LOG("[DEMO] posix ctype test case 5(except):isxdigit(%c) fail.\n", a);
}
TEST_ASSERT_EQUAL_INT(0, ret);
}
RUN_TEST_SUITE(PosixCTypeIsxdigitTest);
void PosixIsxdigitFuncTest()
{
LOG("begin PosixIsxdigitFuncTest....");
RUN_ONE_TESTCASE(testCTypeIsxdigit001);
RUN_ONE_TESTCASE(testCTypeIsxdigit002);
RUN_ONE_TESTCASE(testCTypeIsxdigit003);
RUN_ONE_TESTCASE(testCTypeIsxdigit004);
RUN_ONE_TESTCASE(testCTypeIsxdigit005);
RUN_ONE_TESTCASE(testCTypeIsxdigit006);
RUN_ONE_TESTCASE(testCTypeIsxdigit007);
RUN_ONE_TESTCASE(testCTypeIsxdigit008);
RUN_ONE_TESTCASE(testCTypeIsxdigit009);
RUN_ONE_TESTCASE(testCTypeIsxdigit010);
return;
}

View File

@@ -0,0 +1,164 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixCTypeTolowerTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeTolowerTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeTolowerTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_001
* @tc.name : Converts an uppercase letter specified by c to its lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower001, Function | MediumTest | Level1)
{
int a = 'a';
int ret = tolower(a);
if (ret == 'a') {
LOG("[DEMO] posix ctype test case 1:tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 1:tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'a');
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_002
* @tc.name : Converts an uppercase letter specified by c to its lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower002, Function | MediumTest | Level1)
{
int a = 'A';
int ret = tolower(a);
if (ret == 'a') {
LOG("[DEMO] posix ctype test case 2:tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 2:tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'a');
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_003
* @tc.name : Converts an uppercase letter to lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower003, Function | MediumTest | Level1)
{
int a = 'z';
int ret = tolower(a);
if (ret == 'z') {
LOG("[DEMO] posix ctype test case 3:tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 3:tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'z');
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_004
* @tc.name : Converts an uppercase letter to its lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower004, Function | MediumTest | Level1)
{
int a = 'Z';
int ret = tolower(a);
if (ret == 'z') {
LOG("[DEMO] posix ctype test case 4:tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 4:tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'z');
}
/* *
* @tc.number : TEST_CTYPE_TOLOWER_005
* @tc.name : Converts an uppercase letter to its lowercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeTolowerTest, testCTypeTolower005, Function | MediumTest | Level1)
{
int a = '1';
int ret = tolower(a);
if (ret == '1') {
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 5(except):tolower(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == '1');
}
RUN_TEST_SUITE(PosixCTypeTolowerTest);
void PosixTolowerFuncTest()
{
LOG("begin PosixTolowerFuncTest....");
RUN_ONE_TESTCASE(testCTypeTolower001);
RUN_ONE_TESTCASE(testCTypeTolower002);
RUN_ONE_TESTCASE(testCTypeTolower003);
RUN_ONE_TESTCASE(testCTypeTolower004);
RUN_ONE_TESTCASE(testCTypeTolower005);
return;
}

View File

@@ -0,0 +1,164 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ctype.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixCTypeToupperTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeToupperTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixCTypeToupperTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_001
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper001, Function | MediumTest | Level1)
{
int a = 'a';
int ret = toupper(a);
if (ret == 'A') {
LOG("[DEMO] posix ctype test case 1:toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 1:toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'A');
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_002
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper002, Function | MediumTest | Level1)
{
int a = 'A';
int ret = toupper(a);
if (ret == 'A') {
LOG("[DEMO] posix ctype test case 2:toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 2:toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'A');
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_003
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper003, Function | MediumTest | Level1)
{
int a = 'z';
int ret = toupper(a);
if (ret == 'Z') {
LOG("[DEMO] posix ctype test case 3:toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 3:toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'Z');
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_004
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper004, Function | MediumTest | Level1)
{
int a = 'Z';
int ret = toupper(a);
if (ret == 'Z') {
LOG("[DEMO] posix ctype test case 4:toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 4:toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == 'Z');
}
/* *
* @tc.number : TEST_CTYPE_TOUPPER_005
* @tc.name : Converts a lowercase letter to uppercase equivalent
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixCTypeToupperTest, testCTypeToupper005, Function | MediumTest | Level1)
{
int a = '1';
int ret = toupper(a);
if (ret == '1') {
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)==%c ok.\n", a, ret);
} else {
LOG("[DEMO] posix ctype test case 5(except):toupper(%c)!=%c fail.\n", a);
}
TEST_ASSERT_TRUE(ret == '1');
}
RUN_TEST_SUITE(PosixCTypeToupperTest);
void PosixToupperFuncTest()
{
LOG("begin PosixToupperFuncTest....");
RUN_ONE_TESTCASE(testCTypeToupper001);
RUN_ONE_TESTCASE(testCTypeToupper002);
RUN_ONE_TESTCASE(testCTypeToupper003);
RUN_ONE_TESTCASE(testCTypeToupper004);
RUN_ONE_TESTCASE(testCTypeToupper005);
return;
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <errno.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is PosixSysFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixsystem, PosixSysFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixSysFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixSysFuncTestSuiteTearDown(void)
{
printf("+Hello this is a System function test+\n");
return TRUE;
}
/* *
* @tc.number : SUB_KERNEL_POSIX_strerror_OPERATION_001
* @tc.name : Memony operation for strerror test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixSysFuncTestSuite, testOsSysStrerror001, Function | MediumTest | Level1)
{
for (int i = EPERM; i < EHWPOISON; i++) {
char *s = strerror(i);
TEST_ASSERT_NOT_NULL(s);
}
LOG("strerror(-1) = %s\n", strerror(-1));
TEST_ASSERT_EQUAL_STRING("No error information", strerror(-1));
LOG("strerror(0) = %s\n", strerror(0));
TEST_ASSERT_EQUAL_STRING("No error information", strerror(0));
LOG("strerror(2) = %s\n", strerror(2));
TEST_ASSERT_EQUAL_STRING("No such file or directory", strerror(2));
LOG("strerror(10) = %s\n", strerror(10));
TEST_ASSERT_EQUAL_STRING("No child process", strerror(10));
};
RUN_TEST_SUITE(PosixSysFuncTestSuite);
void PosixStrerrorTest()
{
LOG("begin PosixStrerrorTest....");
RUN_ONE_TESTCASE(testOsSysStrerror001);
return;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KERNEL_TEST_H
#define KERNEL_TEST_H
#define TESTCOUNT_NUM_1 1
#define TESTCOUNT_NUM_2 2
#define TESTCOUNT_NUM_3 3
#define TESTCOUNT_NUM_4 4
#define TESTCOUNT_NUM_5 5
#define DELAY_TICKS_1 1
#define DELAY_TICKS_5 5
#define DELAY_TICKS_10 10
#define TEST_TASK_STACK_SIZE 0x600
#define TASK_LOOP_NUM 0x10000000
#define TEST_TIME 10
#define THREAD_COUNT_MIN 3
#define THREAD_COUNT_MAX 30
#define THREAD_STACK_SPACE_MAX 4096
#define RUN_ONE_TESTCASE(caseName) UnityDefaultTestRun(caseName##_runTest, __FILE__, __LINE__)
#define AUTO_RUN_ONE_TESTCASEFUNC(func) UnityDefaultTestRun(func, __FILE__, __LINE__)
#ifdef __cplusplus
#if __cplusplus
#endif
#endif /* __cplusplus */
#endif

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TEST_LOG
#define TEST_LOG
// define if need print debug info
#define DEBUG_LOG_OUT
#include <stdio.h>
#include <los_debug.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef DEBUG_LOG_OUT
#define LOG printf
#else
#define LOG(...)
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,353 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <float.h>
#include <math.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#define RET_OK 0
#define TEST_VALUE_X 0
#define TEST_VALUE_Y 1
#define TEST_EXPECTED 2
int DoubleEquals(double a, double b)
{
if (a == INFINITY && b == INFINITY) {
return 1;
}
if (a == -INFINITY && b == -INFINITY) {
return 1;
}
if (a == INFINITY && b != INFINITY) {
return 0;
}
if (a == -INFINITY && b != -INFINITY) {
return 0;
}
if (isnan(a) && isnan(b)) {
return 1;
}
if (isnan(a) || isnan(b)) {
return 0;
}
return fabs(a - b) < DBL_EPSILON;
}
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is PosixMathFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixmath, PosixMathFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixMathFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixMathFuncTestSuiteTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number SUB_KERNEL_MATH_ABS_001
* @tc.name test abs api
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathAbs001, Function | MediumTest | Level1)
{
const int testCount = 3;
int testValues[] = {-3, 0, 3};
int expected[] = {3, 0, 3};
int ret;
for (int i = 0; i < testCount; ++i) {
ret = abs(testValues[i]);
LOG("\n [POSIXTEST][abs]abs(%d) = %d, expected is %d", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_INT(expected[i], ret);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_ABS_002
* @tc.name test abs api for boundary value
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathAbs002, Function | MediumTest | Level1)
{
const int testCount = 3;
int testValues[] = {-2147483648, -2147483647, 2147483647};
int expected[] = {-2147483648, 2147483647, 2147483647};
int ret;
for (int i = 0; i < testCount; ++i) {
ret = abs(testValues[i]);
LOG("\n [POSIXTEST][abs]abs(%d) = %d, expected is %d", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_INT(expected[i], ret);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_LOG_001
* @tc.name log basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathLog001, Function | MediumTest | Level1)
{
const int testCount = 3;
double testValues[] = { 0.5, 5.5, 1};
double expected[] = { -0.69314718055994528623, 1.70474809223842527217, 0.00000000000000000000};
double ret;
PRINT_EMG("GZHTESTLOG PRINT_EMG: %f, %f, %f", testValues[0], testValues[1], testValues[2]);
LOG("GZHTESTLOG LOG: %f, %f, %f", testValues[0], testValues[1], testValues[2]);
for (int i = 0; i < testCount; ++i) {
ret = log(testValues[i]);
LOG("\n [POSIXTEST][log]log(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_LOG_002
* @tc.name log function test for invalid input
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathLog002, Function | MediumTest | Level1)
{
const int testCount = 4;
double testValues[] = { 0, -INFINITY, -2.0, NAN};
double expected[] = { -INFINITY, NAN, NAN, NAN};
double ret;
LOG("\n (math_errhandling & MATH_ERRNO) = %d", (math_errhandling & MATH_ERRNO));
LOG("\n (math_errhandling & MATH_ERREXCEPT) = %d", (math_errhandling & MATH_ERREXCEPT));
for (int i = 0; i < testCount; ++i) {
ret = log(testValues[i]);
LOG("\n [POSIXTEST][log]log(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_SQRT_001
* @tc.name sqrt basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathSqrt001, Function | MediumTest | Level1)
{
const int testCount = 3;
double testValues[] = { 4, 3, 10 };
double expected[] = { 2.00000000000000000000, 1.73205080756887719318, 3.16227766016837952279 };
double ret;
for (int i = 0; i < testCount; ++i) {
ret = sqrt(testValues[i]);
LOG("\n [POSIXTEST][sqrt]sqrt(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_SQRT_002
* @tc.name sqrt function test for invalid input
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathSqrt002, Function | MediumTest | Level1)
{
const int testCount = 5;
double testValues[] = { 0, INFINITY, -2.0, -INFINITY, NAN };
double expected[] = { 0.00000000000000000000, INFINITY, NAN, NAN, NAN};
double ret;
for (int i = 0; i < testCount; ++i) {
ret = sqrt(testValues[i]);
LOG("\n [POSIXTEST][sqrt]sqrt(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_POW_001
* @tc.name pow basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow001, Function | MediumTest | Level1)
{
double testValues[][TEST_EXPECTED + 1] = {
{1, 1.12, 1.00000000000000000000},
{2.8, 2.14, 9.0556199394902243682},
{3.6, 3.16, 57.26851244563656706532},
{678.88, 0, 1.00000000000000000000}
};
const int testCount = sizeof(testValues) / (sizeof(double) * 3);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]);
LOG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X],
testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]);
TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret);
TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_POW_002
* @tc.name pow basic function test for range input
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow002, Function | MediumTest | Level1)
{
double testValues[][TEST_EXPECTED + 1] = {
{1, NAN, 1.00000000000000000000},
{-1, -INFINITY, 1.00000000000000000000},
{-0.5, -INFINITY, INFINITY},
{3.5, -INFINITY, 0},
{0.5, INFINITY, 0},
{-3.5, INFINITY, INFINITY},
{-INFINITY, -5, -0.00000000000000000000},
{-INFINITY, -4.37, 0.00000000000000000000},
{-INFINITY, 7, -INFINITY},
{-INFINITY, 4, INFINITY},
{INFINITY, -4, 0.00000000000000000000},
{INFINITY, 4, INFINITY}
};
const int testCount = sizeof(testValues) / (sizeof(double) * 3);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]);
TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret);
TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret));
LOG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X],
testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]);
}
};
/* *
* @tc.number SUB_KERNEL_MATH_POW_003
* @tc.name pow basic function test for invalid input
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathPow003, Function | MediumTest | Level1)
{
double testValues[][TEST_EXPECTED + 1] = {
{0.0, -7, -HUGE_VAL},
{-0.0, -6.22, -HUGE_VAL},
{-7.23, 3.57, NAN},
{121223, 5674343, HUGE_VAL}
};
const int testCount = sizeof(testValues) / (sizeof(double) * 3);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = pow(testValues[i][TEST_VALUE_X], testValues[i][TEST_VALUE_Y]);
TEST_ASSERT_EQUAL_FLOAT(testValues[i][TEST_EXPECTED], ret);
LOG("\n [POSIXTEST][pow]pow1(%f,%f) = %f, expected is %f", testValues[i][TEST_VALUE_X],
testValues[i][TEST_VALUE_Y], ret, testValues[i][TEST_EXPECTED]);
TEST_ASSERT_TRUE(DoubleEquals(testValues[i][TEST_EXPECTED], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_ROUND_001
* @tc.name round basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathRound001, Function | MediumTest | Level1)
{
double testValues[] = { -0.5, 2.5, -3.812345679812345, -0.125, 0.125};
double expected[] = { -1.00000000000000000000, 3.00000000000000000000, -4.00000000000000000000,
0.00000000000000000000, 0.00000000000000000000};
const int testCount = sizeof(testValues) / sizeof(double);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = round(testValues[i]);
LOG("\n [POSIXTEST][round]round1(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret));
}
};
/* *
* @tc.number SUB_KERNEL_MATH_ROUND_002
* @tc.name round basic function test
* @tc.desc [C- SOFTWARE -0100]
*/
LITE_TEST_CASE(PosixMathFuncTestSuite, testMathRound002, Function | MediumTest | Level1)
{
double testValues[] = { NAN, -INFINITY, INFINITY, 0};
double expected[] = { NAN, -INFINITY, INFINITY, 0.00000000000000000000};
const int testCount = sizeof(testValues) / sizeof(double);
double ret;
for (int i = 0; i < testCount; ++i) {
ret = round(testValues[i]);
LOG("\n [POSIXTEST][round]round1(%f) = %f, expected is %f", testValues[i], ret, expected[i]);
TEST_ASSERT_EQUAL_FLOAT(expected[i], ret);
TEST_ASSERT_TRUE(DoubleEquals(expected[i], ret));
}
};
RUN_TEST_SUITE(PosixMathFuncTestSuite);
void PosixMathFuncTest()
{
LOG("begin PosixMathFuncTest....");
RUN_ONE_TESTCASE(testMathAbs001);
RUN_ONE_TESTCASE(testMathAbs002);
RUN_ONE_TESTCASE(testMathLog001);
RUN_ONE_TESTCASE(testMathLog002);
RUN_ONE_TESTCASE(testMathSqrt001);
RUN_ONE_TESTCASE(testMathSqrt002);
RUN_ONE_TESTCASE(testMathPow001);
RUN_ONE_TESTCASE(testMathPow002);
RUN_ONE_TESTCASE(testMathPow003);
RUN_ONE_TESTCASE(testMathRound001);
RUN_ONE_TESTCASE(testMathRound002);
return;
}

View File

@@ -0,0 +1,511 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <securec.h>
#include "hctest.h"
#include <mqueue.h>
#include <fcntl.h>
#include "common_test.h"
#define MQUEUE_STANDARD_NAME_LENGTH 50
#define MQUEUE_NO_ERROR 0
#define MQUEUE_SEND_STRING_TEST "mq_test"
#define MQUEUE_SHORT_ARRAY_LENGTH strlen(MQUEUE_SEND_STRING_TEST)
const int MQ_NAME_LEN = 64; // mqueue name len
const int MQ_TX_LEN = 64; // mqueue send buffer len
const int MQ_RX_LEN = 64; // mqueue receive buffer len
const int MQ_MSG_SIZE = 64; // mqueue message size
const int MQ_MSG_PRIO = 0; // mqueue message priority
const int MQ_MAX_MSG = 16; // mqueue message number
const char MQ_MSG[] = "MessageToSend"; // mqueue message to send
const int MQ_MSG_LEN = sizeof(MQ_MSG); // mqueue message len to send
const int MAX_MQ_NUMBER = 1024; // max mqueue number
const int MAX_MQ_NAME_LEN = 256; // max mqueue name length
const int MAX_MQ_MSG_SIZE = 65530; // max mqueue message size
// return n: 0 < n <= max
unsigned int GetRandom(unsigned int max)
{
if (max == 0 || max == 1) {
return 1;
}
return (rand() % max) + 1;
}
/**
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is mqueue
* @param : module name is mqueue
* @param : test suit name is MqueueFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Mqueue, MqueueFuncTestSuite);
/**
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL MqueueFuncTestSuiteSetUp(void)
{
return TRUE;
}
/**
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL MqueueFuncTestSuiteTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_001
* @tc.name : event operation for creat
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqueue001, Function | MediumTest | Level1)
{
unsigned int ret;
char msgrcd[MQUEUE_STANDARD_NAME_LENGTH] = {0};
char mqname[MQUEUE_STANDARD_NAME_LENGTH] = "";
const char *msgptr = MQUEUE_SEND_STRING_TEST;
struct mq_attr attr = { 0 };
mqd_t mqueue;
attr.mq_msgsize = MQUEUE_STANDARD_NAME_LENGTH;
attr.mq_maxmsg = 1;
snprintf_s(mqname, MQUEUE_STANDARD_NAME_LENGTH, MQUEUE_STANDARD_NAME_LENGTH - 1, "/mq002_%d", 1);
mqueue = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
ICUNIT_GOTO_NOT_EQUAL(mqueue, (mqd_t)-1, mqueue, EXIT1);
ret = mq_send(mqueue, msgptr, strlen(msgptr), 0);
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
ret = mq_receive(mqueue, msgrcd, MQUEUE_STANDARD_NAME_LENGTH, NULL);
ICUNIT_GOTO_EQUAL(ret, MQUEUE_SHORT_ARRAY_LENGTH, ret, EXIT1);
ICUNIT_GOTO_STRING_EQUAL(msgrcd, MQUEUE_SEND_STRING_TEST, msgrcd, EXIT1);
ret = mq_close(mqueue);
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT1);
ret = mq_unlink(mqname);
ICUNIT_GOTO_EQUAL(ret, MQUEUE_NO_ERROR, ret, EXIT);
return;
EXIT1:
mq_close(mqueue);
EXIT:
mq_unlink(mqname);
return;
};
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0100
* @tc.name mq_open function errno for EEXIST test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenEEXIST, Function | MediumTest | Level2)
{
char qName[MQ_NAME_LEN];
mqd_t queue, queueOther;
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqOpenEEXIST_%d", GetRandom(10000));
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
ICUNIT_GOTO_NOT_EQUAL(queue, (mqd_t)-1, queue, EXIT1);
queueOther = mq_open(qName, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, NULL);
ICUNIT_GOTO_EQUAL(queueOther, (mqd_t)-1, queueOther, EXIT1);
ICUNIT_GOTO_EQUAL(errno, EEXIST, errno, EXIT1);
EXIT1:
ret = mq_close(queue);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
EXIT:
ret = mq_unlink(qName);
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, ret);
return;
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0200
* @tc.name mq_open function errno for EINVAL test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenEINVAL, Function | MediumTest | Level2)
{
int i;
mqd_t queue;
struct mq_attr attr = {0};
char qName[MQ_NAME_LEN];
const int max = 65535;
sprintf_s(qName, MQ_NAME_LEN, "testMqOpenEINVAL_%d", GetRandom(10000));
for (i = 0; i<6; i++) {
switch (i) {
case 0:
attr.mq_msgsize = -1;
attr.mq_maxmsg = max;
break;
case 1:
/* attr.mq_msgsize > USHRT_MAX - 4 */
attr.mq_msgsize = max;
attr.mq_maxmsg = max;
break;
case 2:
attr.mq_msgsize = 10;
attr.mq_maxmsg = -1;
break;
case 3:
attr.mq_msgsize = 10;
attr.mq_maxmsg = max + 1;
break;
case 4:
attr.mq_msgsize = 0;
attr.mq_maxmsg = 16;
break;
case 5:
attr.mq_msgsize = 64;
attr.mq_maxmsg = 0;
break;
}
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
if (queue != (mqd_t)-1) {
mq_close(queue);
mq_unlink(qName);
}
/* if NOT call mq_close & mq_unlink then errno == ENOENT */
ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
}
for (i=0; i<MQ_NAME_LEN; i++) {
qName[i] = 0;
}
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0300
* @tc.name mq_open function errno for ENAMETOOLONG test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENAMETOOLONG, Function | MediumTest | Level2)
{
char qName[MAX_MQ_NAME_LEN + 10];
mqd_t queue;
int i;
for (i=0; i<MAX_MQ_NAME_LEN + 5; i++) {
qName[i] = '8';
}
qName[i] = '\0';
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
if (queue != (mqd_t)-1) {
mq_close(queue);
mq_unlink(qName);
}
ICUNIT_TRACK_EQUAL(errno, ENAMETOOLONG, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0400
* @tc.name mq_open function errno for ENOENT test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENOENT, Function | MediumTest | Level3)
{
mqd_t queue;
char qName[MQ_NAME_LEN];
sprintf_s(qName, MQ_NAME_LEN, "testMqOpenENOENT_%d", GetRandom(10000));
queue = mq_open(qName, O_RDWR, S_IRUSR | S_IWUSR, NULL);
ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
if (queue != (mqd_t)-1) {
mq_close(queue);
mq_unlink(qName);
}
ICUNIT_TRACK_EQUAL(errno, ENOENT, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0500
* @tc.name mq_open function errno for ENFILE test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENFILE, Function | MediumTest | Level3)
{
char qName[MAX_MQ_NUMBER + 1][30];
mqd_t queue[MAX_MQ_NUMBER + 1];
int flag = 0;
int i;
for (i=0; i<MAX_MQ_NUMBER + 1; i++) {
sprintf_s(qName[i], MQ_NAME_LEN, "testMqOpenENFILE_%d", i);
}
for (i=0; i<MAX_MQ_NUMBER; i++) {
queue[i] = mq_open(qName[i], O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
if (queue[i] == (mqd_t)-1) {
flag = 1;
printf("break: i = %d", i);
break;
}
ICUNIT_TRACK_EQUAL(queue[i], (mqd_t)-1, queue[i]);
}
printf("func: i = %d", i);
if (flag == 0) {
queue[i] = mq_open(qName[i], O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
}
ICUNIT_TRACK_EQUAL(queue[i], (mqd_t)-1, queue[i]);
ICUNIT_TRACK_EQUAL(errno, ENFILE, errno);
for (i=0; i<MAX_MQ_NUMBER+1; i++) {
mq_close(queue[i]);
mq_unlink(qName[i]);
}
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_OPEN_0600
* @tc.name mq_open function errno for ENOSPC test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqOpenENOSPC, Function | MediumTest | Level3)
{
mqd_t queue;
struct mq_attr setAttr = {0};
char qName[MQ_NAME_LEN];
sprintf_s(qName, MQ_NAME_LEN, "testMqOpenENOSPC_%d", GetRandom(10000));
setAttr.mq_msgsize = MAX_MQ_MSG_SIZE + 1;
setAttr.mq_maxmsg = MAX_MQ_NAME_LEN;
queue = mq_open(qName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &setAttr);
ICUNIT_TRACK_EQUAL(queue, (mqd_t)-1, queue);
if (queue != (mqd_t)-1) {
mq_close(queue);
mq_unlink(qName);
}
ICUNIT_TRACK_EQUAL(errno, ENOSPC, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_CLOSE_0100
* @tc.name mq_close function errno for EBADF test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqCloseEBADF, Function | MediumTest | Level2)
{
ICUNIT_TRACK_EQUAL(mq_close(NULL), -1, -1);
ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_SEND_0100
* @tc.name mq_send function errno for EAGAIN test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEAGAIN, Function | MediumTest | Level2)
{
mqd_t queue;
struct mq_attr attr = {0};
char qName[MQ_NAME_LEN];
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqSendEAGAIN_%d", GetRandom(10000));
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = 1;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, 0);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EAGAIN, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_SEND_0200
* @tc.name mq_send function errno for EBADF and EMSGSIZE test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEBADFEMSGSIZE, Function | MediumTest | Level2)
{
mqd_t queue;
struct mq_attr attr = {0};
char qName[MQ_NAME_LEN];
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqSendEAGAIN_%d", GetRandom(10000));
attr.mq_msgsize = 1;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(NULL, MQ_MSG, 1, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EMSGSIZE, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_ASSERT_EQUAL_VOID(ret, 0, ret);
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDONLY | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
attr.mq_flags |= O_NONBLOCK;
ret = mq_setattr(queue, &attr, NULL);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EBADF, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_SEND_0300
* @tc.name mq_send function errno for EINVAL test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqSendEINVAL, Function | MediumTest | Level3)
{
mqd_t queue;
struct mq_attr attr = {0};
char qName[MQ_NAME_LEN];
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqSendEINVAL_%d", GetRandom(10000));
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, 0, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EINVAL, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
}
/**
* @tc.number SUB_KERNEL_IPC_MQ_RECEIVE_0100
* @tc.name mq_receive function errno for EAGAIN test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(MqueueFuncTestSuite, testMqReceiveEAGAIN, Function | MediumTest | Level2)
{
mqd_t queue;
unsigned int prio;
struct mq_attr attr = {0};
struct mq_attr getAttr = {0};
char qName[MQ_NAME_LEN], rMsg[MQ_RX_LEN];
int ret;
sprintf_s(qName, MQ_NAME_LEN, "testMqReceiveEAGAIN_%d", GetRandom(10000));
attr.mq_msgsize = MQ_MSG_SIZE;
attr.mq_maxmsg = MQ_MAX_MSG;
queue = mq_open(qName, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr);
ICUNIT_ASSERT_EQUAL_VOID(queue, (mqd_t)-1, queue);
ret = mq_send(queue, MQ_MSG, MQ_MSG_LEN, MQ_MSG_PRIO);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_getattr(queue, &getAttr);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
ICUNIT_TRACK_NOT_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(prio, MQ_MSG_PRIO, prio);
ICUNIT_TRACK_EQUAL(strncmp(MQ_MSG, rMsg, MQ_MSG_LEN), 0, -1);
ret = mq_receive(queue, rMsg, getAttr.mq_msgsize, &prio);
ICUNIT_TRACK_EQUAL(ret, -1, ret);
ICUNIT_TRACK_EQUAL(errno, EAGAIN, errno);
ret = mq_close(queue);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
ret = mq_unlink(qName);
ICUNIT_TRACK_EQUAL(ret, 0, ret);
}
RUN_TEST_SUITE(MqueueFuncTestSuite);

View File

@@ -0,0 +1,532 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include <securec.h>
#include "hctest.h"
#include "los_config.h"
#include "cmsis_os2.h"
#include "common_test.h"
static UINT32 g_testCount;
/**
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is pthread
* @param : module name is pthread
* @param : test suit name is PthreadFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Pthread, PthreadFuncTestSuite);
/**
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PthreadFuncTestSuiteSetUp(void)
{
return TRUE;
}
/**
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PthreadFuncTestSuiteTearDown(void)
{
printf("+-------------------------------------------+\n");
return TRUE;
}
static VOID *pthread_join_f01(void *argument)
{
g_testCount++;
pthread_exit((void *)8); /* 8: pthread exit code */
return (void *)9; /* 9: return val */
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_001
* @tc.name : event operation for join
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PthreadFuncTestSuite, testPthread001, Function | MediumTest | Level1)
{
pthread_attr_t attr;
pthread_t newTh;
struct sched_param schedParam = { 0 };
UINT32 ret;
UINTPTR uwtemp = 1;
g_testCount = 0;
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
schedParam.sched_priority = TASK_PRIO_TEST;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_create(&newTh, &attr, pthread_join_f01, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, (void **)&uwtemp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(uwtemp, 8, uwtemp); /* 8: pthread exit code */
return LOS_OK;
};
static VOID *pthread_join_f02(void *argument)
{
g_testCount++;
return (void *)9; /* 9: return val */
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_002
* @tc.name : event operation for join
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PthreadFuncTestSuite, testPthread002, Function | MediumTest | Level1)
{
pthread_attr_t attr;
pthread_t newTh;
struct sched_param schedParam = { 0 };
UINT32 ret;
UINTPTR uwtemp = 1;
g_testCount = 0;
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
schedParam.sched_priority = TASK_PRIO_TEST;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_create(&newTh, &attr, pthread_join_f02, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, (void **)&uwtemp);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(uwtemp, 9, uwtemp); /* 9: pthread exit code */
return LOS_OK;
};
static VOID *pthread_join_f03(void *argument)
{
int ret = pthread_detach(pthread_self());
ICUNIT_GOTO_EQUAL(ret, ESRCH, ret, EXIT);
g_testCount++;
EXIT:
return NULL;
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_003
* @tc.name : event operation for deatch
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PthreadFuncTestSuite, testPthread003, Function | MediumTest | Level1)
{
pthread_attr_t attr;
pthread_t newTh;
struct sched_param schedParam = { 0 };
UINT32 ret;
g_testCount = 0;
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
schedParam.sched_priority = TASK_PRIO_TEST + 1;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_create(&newTh, &attr, pthread_join_f03, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount);
return LOS_OK;
};
static VOID *pthread_join_f04(void *argument)
{
int ret = pthread_detach(pthread_self());
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
g_testCount++;
EXIT:
return NULL;
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_004
* @tc.name : event operation for deatch
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PthreadFuncTestSuite, testPthread004, Function | MediumTest | Level1)
{
pthread_attr_t attr;
pthread_t newTh;
struct sched_param schedParam = { 0 };
UINT32 ret;
g_testCount = 0;
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
schedParam.sched_priority = TASK_PRIO_TEST - 1;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_create(&newTh, &attr, pthread_join_f04, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ICUNIT_ASSERT_EQUAL(g_testCount, 1, g_testCount);
ret = pthread_join(newTh, NULL);
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
return LOS_OK;
};
static VOID *pthread_join_f05(void *argument)
{
int ret = pthread_detach(pthread_self());
ICUNIT_GOTO_EQUAL(ret, EINVAL, ret, EXIT);
usleep(100000); /* 100000: sleep 100 ms */
EXIT:
return NULL;
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_005
* @tc.name : event operation for deatch
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PthreadFuncTestSuite, testPthread005, Function | MediumTest | Level1)
{
pthread_attr_t attr;
pthread_t newTh;
struct sched_param schedParam = { 0 };
UINT32 ret;
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
schedParam.sched_priority = TASK_PRIO_TEST - 1;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_create(&newTh, &attr, pthread_join_f05, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, NULL);
ICUNIT_ASSERT_EQUAL(ret, EINVAL, ret);
return LOS_OK;
};
static pthread_cond_t g_pthread_cond;
static pthread_mutex_t g_pthread_mutex;
#define TEST_THREAD_COUNT 5
static void *pthread_cond_func001(void *arg)
{
int ret;
struct timespec ts;
g_testCount++;
ret = pthread_mutex_lock(&g_pthread_mutex);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 60; /* 60: wait 1 minute */
ret = pthread_cond_timedwait(&g_pthread_cond, &g_pthread_mutex, &ts);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_mutex_unlock(&g_pthread_mutex);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
g_testCount++;
EXIT:
return NULL;
}
static VOID *pthread_f06(void *argument)
{
int policy;
int ret;
int i;
pthread_attr_t attr;
struct sched_param schedParam = { 0 };
pthread_t thread[TEST_THREAD_COUNT];
g_testCount = 0;
ret = pthread_attr_init(&attr);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
schedParam.sched_priority -= 1;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
for (i = 0; i < TEST_THREAD_COUNT; i++) {
ret = pthread_create(&thread[i], &attr, pthread_cond_func001, NULL);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
}
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); /* 5: Five threads */
ret = pthread_mutex_lock(&g_pthread_mutex);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_cond_broadcast(&g_pthread_cond);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_mutex_unlock(&g_pthread_mutex);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ICUNIT_GOTO_EQUAL(g_testCount, 10, g_testCount, EXIT); /* 10: Twice per thread */
for (i = 0; i < TEST_THREAD_COUNT; i++) {
ret = pthread_join(thread[i], NULL);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
}
EXIT:
return NULL;
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_006
* @tc.name : event operation for deatch
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PthreadFuncTestSuite, testPthread006, Function | MediumTest | Level1)
{
pthread_attr_t attr;
pthread_t newTh;
struct sched_param schedParam = { 0 };
UINT32 ret;
ret = pthread_mutex_init(&g_pthread_mutex, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_cond_init(&g_pthread_cond, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
schedParam.sched_priority = TASK_PRIO_TEST - 1;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_create(&newTh, &attr, pthread_f06, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
};
static void *pthread_cond_func002(void *arg)
{
int ret;
struct timespec ts;
g_testCount++;
ret = pthread_mutex_lock(&g_pthread_mutex);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 60; /* 60: wait 1 minute */
ret = pthread_cond_timedwait(&g_pthread_cond, &g_pthread_mutex, &ts);
ICUNIT_GOTO_EQUAL(ret, ETIMEDOUT, ret, EXIT);
ret = pthread_mutex_unlock(&g_pthread_mutex);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
g_testCount++;
EXIT:
return NULL;
}
static VOID *pthread_f07(void *argument)
{
int policy;
int ret;
int i;
pthread_attr_t attr;
struct sched_param schedParam = { 0 };
pthread_t thread[TEST_THREAD_COUNT];
g_testCount = 0;
ret = pthread_attr_init(&attr);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_getschedparam(pthread_self(), &policy, &schedParam);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
schedParam.sched_priority -= 1;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
for (i = 0; i < TEST_THREAD_COUNT; i++) {
ret = pthread_create(&thread[i], &attr, pthread_cond_func002, NULL);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
}
ICUNIT_GOTO_EQUAL(g_testCount, 5, g_testCount, EXIT); /* 5: Five threads */
for (i = 0; i < TEST_THREAD_COUNT; i++) {
ret = pthread_join(thread[i], NULL);
ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT);
}
ICUNIT_GOTO_EQUAL(g_testCount, 10, g_testCount, EXIT); /* 10: Twice per thread */
EXIT:
return NULL;
}
/**
* @tc.number : SUB_KERNEL_PTHREAD_OPERATION_007
* @tc.name : event operation for deatch
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PthreadFuncTestSuite, testPthread007, Function | MediumTest | Level1)
{
pthread_attr_t attr;
pthread_t newTh;
struct sched_param schedParam = { 0 };
UINT32 ret;
ret = pthread_mutex_init(&g_pthread_mutex, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_cond_init(&g_pthread_cond, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_init(&attr);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setstacksize(&attr, OS_TSK_TEST_STACK_SIZE);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
schedParam.sched_priority = TASK_PRIO_TEST - 1;
ret = pthread_attr_setschedparam(&attr, &schedParam);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_create(&newTh, &attr, pthread_f07, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
ret = pthread_join(newTh, NULL);
ICUNIT_ASSERT_EQUAL(ret, 0, ret);
return LOS_OK;
};
RUN_TEST_SUITE(PthreadFuncTestSuite);

View File

@@ -0,0 +1,191 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include <regex.h>
#include "log.h"
#define EQUAL 0
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is PosixStrCaseCmpFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixRegexTest, PosixRegexFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixRegexFuncTestSuiteSetUp(void)
{
LOG("+-------------------------------------------+\n");
LOG("+--------PosixRegexFuncTestSuiteSetUp-------+\n");
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixRegexFuncTestSuiteTearDown(void)
{
LOG("+-------------------------------------------+\n");
LOG("+-------PosixRegexFuncTestSuiteTearDown-----+\n");
LOG("+-------------------------------------------+\n");
return TRUE;
}
void TestRegex(int flag, const char *pattern, const char *buf, const int expectedStatus, const char *expectedRes)
{
regmatch_t pmatch[1];
const size_t nmatch = 1;
regex_t reg;
char res[64];
int j = 0;
regcomp(&reg, pattern, flag);
int status = regexec(&reg, buf, nmatch, pmatch, 0);
TEST_ASSERT_EQUAL_INT(status, expectedStatus);
if (status == REG_NOMATCH) {
LOG("no match");
} else if (status == 0) {
LOG("Match:");
for (int i = pmatch[0].rm_so; i < pmatch[0].rm_eo; i++) {
putchar(buf[i]);
res[j] = buf[i];
j++;
}
res[j] = 0;
LOG("\n");
TEST_ASSERT_EQUAL_STRING(res, expectedRes);
}
regfree(&reg);
}
void TestRegcomp(int flag, const char *pattern, const int expectedStatus)
{
regex_t reg;
int status = regcomp(&reg, pattern, flag);
LOG("pattern : %s ,real status : %d \n", pattern, status);
TEST_ASSERT_EQUAL_INT(status, expectedStatus);
regfree(&reg);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0100
* @tc.name test regcomp/regexec/regfree cflags = Extended
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegexExtended001, Function | MediumTest | Level1)
{
TestRegex(REG_EXTENDED, "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*$", "harmony20000925@abcdef.com", REG_OK,
"harmony20000925@abcdef.com");
TestRegex(REG_EXTENDED, "^addr=([^&]*)", "huawei123&sex=girl&age=18\r\naddr=bantian&hobby=movie", REG_NOMATCH,
NULL);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0200
* @tc.name test regcomp/regexec/regfree cflags = ICASE
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegexIcase001, Function | MediumTest | Level1)
{
TestRegex(REG_ICASE, "HARMONY[1-9]", "harmony20000925@abcdef.com", REG_OK, "harmony2");
TestRegex(REG_ICASE, "HARMONY([1-9])", "harmony20000925@abcdef.com", REG_NOMATCH, NULL);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0300
* @tc.name test regcomp/regexec/regfree cflags = NEWLINE
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegexNewline001, Function | MediumTest | Level1)
{
TestRegex(REG_EXTENDED | REG_NEWLINE, "^addr=([^&]*)", "huawei123&sex=girl&age=18\r\naddr=bantian&hobby=movie",
REG_OK, "addr=bantian");
TestRegex(REG_EXTENDED | REG_NEWLINE, "^addr=([^&]*)", "huawei123&sex=girl&age=18&addr=bantian&hobby=movie",
REG_NOMATCH, NULL);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0400
* @tc.name test regcomp/regexec/regfree cflags = NOSUB
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegexNosub001, Function | MediumTest | Level1)
{
int cflags = REG_ICASE | REG_NOSUB;
regex_t reg;
const char *buf = "harmony20000925@abcdef.com";
const char *pattern2 = "HARMONY[1-9]";
regcomp(&reg, pattern2, cflags);
int status = regexec(&reg, buf, (size_t)0, NULL, 0);
TEST_ASSERT_EQUAL_INT(status, 0);
regfree(&reg);
}
/* *
* @tc.number SUB_KERNEL_SYS_REGCOMP_0500
* @tc.name test regcomp cflags = NOSUB
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixRegexFuncTestSuite, testRegcomp001, Function | MediumTest | Level1)
{
TestRegcomp(REG_EXTENDED, "[[.]", REG_ECOLLATE);
TestRegcomp(REG_EXTENDED, "[[:class:", REG_ECTYPE);
TestRegcomp(REG_EXTENDED, "[abcdefg", REG_EBRACK);
TestRegcomp(REG_EXTENDED, "\\x{4e00-\\x{9fa5}", REG_EBRACE);
TestRegcomp(REG_EXTENDED, "*abcdefg", REG_BADRPT);
}
RUN_TEST_SUITE(PosixRegexFuncTestSuite);
void PosixRegexFuncTest()
{
LOG("begin PosixRegexFuncTest....");
RUN_ONE_TESTCASE(testRegexExtended001);
RUN_ONE_TESTCASE(testRegexIcase001);
RUN_ONE_TESTCASE(testRegexNewline001);
RUN_ONE_TESTCASE(testRegexNosub001);
RUN_ONE_TESTCASE(testRegcomp001);
return;
}

View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <time.h>
#include <semaphore.h>
#include <stdio.h>
#include <errno.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#define NANO_S 1000000000
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is PosixSemaphoreFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixSemaphore, PosixSemaphoreFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixSemaphoreFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixSemaphoreFuncTestSuiteTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
// get cur-time plus ms
struct timespec GetDelayedTime(unsigned int ms)
{
LOG("GetDelayedTime ms = %lu", ms);
struct timespec ts = { 0 };
const unsigned int nsecPerSec = 1000000000;
const unsigned int nsecPerMs = 1000000;
unsigned long long setTimeNs = ms * nsecPerMs;
struct timespec tsNow = { 0 };
clock_gettime(CLOCK_REALTIME, &tsNow);
LOG("Cur time tv_sec: %lld, tv_nsec: %ld", tsNow.tv_sec, tsNow.tv_nsec);
ts.tv_sec = tsNow.tv_sec + (tsNow.tv_nsec + setTimeNs) / nsecPerSec;
ts.tv_nsec = (tsNow.tv_nsec + setTimeNs) % nsecPerSec;
return ts;
}
// calculate time difference, in ms
int GetTimeDiff(struct timespec ts1, struct timespec ts2)
{
const int nsecPerSec = 1000000000;
const int nsecPerMs = 1000000;
int ms = (ts1.tv_sec - ts2.tv_sec) * nsecPerSec + (ts1.tv_nsec - ts2.tv_nsec);
ms = ms / nsecPerMs;
LOG("different result: %ld (ms)", ms);
return ms;
}
/* *
* @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_001
* @tc.name sem_timedwait get semaphore timeout
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait001, Function | MediumTest | Level1)
{
struct timespec ts = { 0 };
struct timespec tsNow = { 0 };
sem_t sem;
int semValue = 0;
TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 0));
ts = GetDelayedTime(100);
LOG("predicted time:%lld, %d", ts.tv_sec, ts.tv_nsec);
if (sem_timedwait((sem_t *)&sem, &ts) == -1) {
TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno);
} else {
LOG("\n> sem_timedwait return unexpected");
}
clock_gettime(CLOCK_REALTIME, &tsNow);
LOG("tsNow %lld, %d", tsNow.tv_sec, tsNow.tv_nsec);
int timeDiff = GetTimeDiff(tsNow, ts); // calculate time different
LOG("timeDiff %d", timeDiff);
TEST_ASSERT_LESS_THAN_INT(20, abs(timeDiff));
TEST_ASSERT_EQUAL_INT(0, sem_destroy((sem_t *)&sem));
}
/* *
* @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_001
* @tc.name sem_timedwait get semaphore success
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait002, Function | MediumTest | Level1)
{
struct timespec ts = { 0 };
struct timespec tsNow = { 0 };
struct timespec tsBegin = { 0 };
sem_t sem;
int semValue = 0;
TEST_ASSERT_EQUAL_INT(0, sem_init((sem_t *)&sem, 0, 1));
ts = GetDelayedTime(100);
LOG("\n ts %lld, %d", ts.tv_sec, ts.tv_nsec);
clock_gettime(CLOCK_REALTIME, &tsBegin);
int ret = sem_timedwait((sem_t *)&sem, &ts);
clock_gettime(CLOCK_REALTIME, &tsNow);
TEST_ASSERT_EQUAL_INT(0, ret);
LOG("\n tsBegin %ld, %ld, tsNow %ld, %ld", tsBegin.tv_sec, tsBegin.tv_nsec, tsNow.tv_sec, tsNow.tv_nsec);
int timeDiff = GetTimeDiff(tsNow, tsBegin); // calculate time different
LOG("\n timeDiff %d", timeDiff);
TEST_ASSERT_LESS_THAN_INT(20, timeDiff);
// try get semphore again
ts = GetDelayedTime(100);
LOG("\n ts %d, %d", ts.tv_sec, ts.tv_nsec);
ret = sem_timedwait((sem_t *)&sem, &ts);
clock_gettime(CLOCK_REALTIME, &tsNow);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(ETIMEDOUT, errno);
LOG("\n tsNow %ld, %ld", tsNow.tv_sec, tsNow.tv_nsec);
timeDiff = GetTimeDiff(tsNow, tsBegin); // calculate time different
LOG("\n wait timeDiff %d", timeDiff);
TEST_ASSERT_EQUAL_INT(0, sem_destroy((sem_t *)&sem));
}
/* *
* @tc.number SUB_KERNEL_IPC_SEM_TIMEDWAIT_003
* @tc.name {sem_timedwait} get semaphore, wait time abnormal, tv_nsec less than 0
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixSemaphoreFuncTestSuite, testIpcSem_Timedwait003, Function | MediumTest | Level3)
{
int ret;
struct timespec ts;
sem_t sem;
ts.tv_sec = 0;
ts.tv_nsec = 200000;
ret = sem_timedwait((sem_t *)&sem, &ts);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
ret = sem_init((sem_t *)&sem, 0, 0);
TEST_ASSERT_EQUAL_INT(0, ret);
ts.tv_sec = time(NULL);
ts.tv_nsec = -2;
ret = sem_timedwait((sem_t *)&sem, &ts);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
ts.tv_sec = time(NULL);
ts.tv_nsec = NANO_S;
ret = sem_timedwait((sem_t *)&sem, &ts);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
ret = sem_timedwait((sem_t *)&sem, NULL);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
ret = sem_destroy((sem_t *)&sem);
TEST_ASSERT_EQUAL_INT(0, ret);
ts.tv_sec = time(NULL);
ts.tv_nsec = 2000000;
ret = sem_timedwait(NULL, &ts);
TEST_ASSERT_EQUAL_INT(-1, ret);
TEST_ASSERT_EQUAL_INT(errno, EINVAL);
}
RUN_TEST_SUITE(PosixSemaphoreFuncTestSuite);
void PosixSemaphoreFuncTest()
{
PRINT_EMG("begin PosixSemaphoreFuncTest....");
RUN_ONE_TESTCASE(testIpcSem_Timedwait001);
RUN_ONE_TESTCASE(testIpcSem_Timedwait002);
RUN_ONE_TESTCASE(testIpcSem_Timedwait003);
return;
}

View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include <string.h>
#include <stdarg.h>
#include "log.h"
#define RET_OK 1
#define MAX_ARG_NUM 2
#define MAX_STRING_LEN 6
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStdargFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdargFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdargFuncTestSuiteTearDown(void)
{
printf("==== [ Stdarg TEST ] ====\n\n");
return TRUE;
}
int VaFunc(int argsNum, ...)
{
va_list vaP1;
(void)va_start(vaP1, argsNum);
va_list vaP2;
(void)va_copy(vaP2, vaP1);
for (int i = 0; i < argsNum; i++) {
if (i < 1) {
TEST_ASSERT_EQUAL_INT(10, va_arg(vaP2, int));
}
if (i == 1) {
TEST_ASSERT_EQUAL_INT(65, va_arg(vaP2, int));
}
if (i > 1) {
TEST_ASSERT_EQUAL_STRING("hello world", va_arg(vaP2, char *));
}
}
(void)va_end(vaP1);
(void)va_end(vaP2);
return RET_OK;
}
/* *
* @tc.number STDARG_API_TEST_001
* @tc.name stdarg api test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg001, Function | MediumTest | Level1)
{
int ret = VaFunc(1, 10);
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number STDARG_API_TEST_002
* @tc.name stdarg api test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg002, Function | MediumTest | Level1)
{
int ret = VaFunc(2, 10, 'A');
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number STDARG_API_TEST_003
* @tc.name stdarg api test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg003, Function | MediumTest | Level1)
{
int ret = VaFunc(3, 10, 'A', "hello world");
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number STDARG_API_TEST_003
* @tc.name stdarg api test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdargFuncTestSuite, testStdarg004, Function | MediumTest | Level1)
{
int ret = VaFunc(3, 10, 'A', "hello world", '\0');
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
RUN_TEST_SUITE(PosixStdargFuncTestSuite);
void PosixStdargFuncTest()
{
LOG("begin PosixStdargFuncTest....");
RUN_ONE_TESTCASE(testStdarg001);
RUN_ONE_TESTCASE(testStdarg002);
RUN_ONE_TESTCASE(testStdarg003);
RUN_ONE_TESTCASE(testStdarg004);
return;
}

View File

@@ -0,0 +1,245 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStdlibAtoiTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtoiTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtoiTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_ATOI_001
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi001, Function | MediumTest | Level1)
{
int value = atoi("2147483647");
if (value == 2147483647) {
LOG("[DEMO] posix stdlib test case 1:atoi(%d) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 1:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(2147483647, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_002
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi002, Function | MediumTest | Level1)
{
int value = atoi("-2147483648");
if (value == -2147483648) {
LOG("[DEMO] posix stdlib test case 2:atoi(%d) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 2:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(-2147483648, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_003
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi003, Function | MediumTest | Level1)
{
int value = atoi("100");
if (value == 100) {
LOG("[DEMO] posix stdlib test case 3:atoi(%d) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 3:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_004
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi004, Function | MediumTest | Level1)
{
int value = atoi("2147483648");
if (value == -2147483648) {
LOG("[DEMO] posix stdlib test case 4(except):atoi(%d) != 2147483648 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 4(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(-2147483648, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_005
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi005, Function | MediumTest | Level1)
{
int value = atoi("-2147483649");
if (value == 2147483647) {
LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(2147483647, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_006
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi006, Function | MediumTest | Level1)
{
int value = atoi("+100");
if (value == 100) {
LOG("[DEMO] posix stdlib test case 6:atoi(%d) == +100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 6:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_007
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi007, Function | MediumTest | Level1)
{
int value = atoi("-100");
if (value == -100) {
LOG("[DEMO] posix stdlib test case 7:atoi(%d) == -100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 7:atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(-100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_008
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi008, Function | MediumTest | Level1)
{
int value = atoi("+-100");
if (value == 0) {
LOG("[DEMO] posix stdlib test case 8(except):atoi(%d) == +-100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 8(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(0, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_009
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi009, Function | MediumTest | Level1)
{
int value = atoi("12+-100");
if (value == 12) {
LOG("[DEMO] posix stdlib test case 9(except):atoi(%d) ok == 12+-100.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 9(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(12, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOI_010
* @tc.name : convert string to integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtoiTest, testStdlibAtoi010, Function | MediumTest | Level1)
{
int value = atoi("21474836470");
if (value == -10) {
LOG("[DEMO] posix stdlib test case 10(except):atoi(%d) ok == 21474836470.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 10(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT(-10, value);
}
RUN_TEST_SUITE(PosixStdlibAtoiTest);
void PosixStdlibAtoiFuncTest()
{
LOG("begin PosixStdlibAtoiFuncTest....");
RUN_ONE_TESTCASE(testStdlibAtoi001);
RUN_ONE_TESTCASE(testStdlibAtoi002);
RUN_ONE_TESTCASE(testStdlibAtoi003);
RUN_ONE_TESTCASE(testStdlibAtoi004);
RUN_ONE_TESTCASE(testStdlibAtoi005);
RUN_ONE_TESTCASE(testStdlibAtoi006);
RUN_ONE_TESTCASE(testStdlibAtoi007);
RUN_ONE_TESTCASE(testStdlibAtoi008);
RUN_ONE_TESTCASE(testStdlibAtoi009);
RUN_ONE_TESTCASE(testStdlibAtoi010);
return;
}

View File

@@ -0,0 +1,228 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStdlibAtolTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtolTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtolTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_ATOL_001
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol001, Function | MediumTest | Level1)
{
const long value = atol("2147483647");
if (value == 2147483647) {
LOG("[DEMO] posix stdlib test case 1:atol(%ld) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 1:atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(2147483647, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_002
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol002, Function | MediumTest | Level1)
{
const long value = atol("-2147483648");
if (value == -2147483648) {
LOG("[DEMO] posix stdlib test case 2:atol(%ld) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 2:atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(-2147483648, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_003
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol003, Function | MediumTest | Level1)
{
const long value = atol("100");
if (value == 100) {
LOG("[DEMO] posix stdlib test case 3:atol(%ld) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 3:atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_004
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol004, Function | MediumTest | Level1)
{
const long value = atol("2147483648");
if (value != 2147483648) {
LOG("[DEMO] posix stdlib test case 4(except):atol(%ld) != 2147483648 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 4(except):atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(-2147483648, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_005
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol005, Function | MediumTest | Level1)
{
const long value = atol("-2147483649");
if (value == 2147483647) {
LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) != -2147483649 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 5(except):atoi(%d) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(2147483647, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_006
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol006, Function | MediumTest | Level1)
{
const long value = atol("+100");
if (value == 100) {
LOG("[DEMO] posix stdlib test case 6:atol(%ld) == +100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 6:atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_007
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol007, Function | MediumTest | Level1)
{
const long value = atol("-100");
if (value == -100) {
LOG("[DEMO] posix stdlib test case 7:atol(%ld) == -100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 7:atoi(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(-100, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_008
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol008, Function | MediumTest | Level1)
{
long value = atol("+-100");
if (value == 0) {
LOG("[DEMO] posix stdlib test case 8(except):atol(%ld) == +-100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 8(except):atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(0, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOL_009
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtolTest, testStdlibAtol009, Function | MediumTest | Level1)
{
long value = atol("12+-100");
if (value == 12) {
LOG("[DEMO] posix stdlib test case 9(except):atol(%ld) ok == 12+-100.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 9(except):atol(%ld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT32(12, value);
}
RUN_TEST_SUITE(PosixStdlibAtolTest);
void PosixStdlibAtolFuncTest()
{
LOG("begin PosixStdlibAtolFuncTest....");
RUN_ONE_TESTCASE(testStdlibAtol001);
RUN_ONE_TESTCASE(testStdlibAtol002);
RUN_ONE_TESTCASE(testStdlibAtol003);
RUN_ONE_TESTCASE(testStdlibAtol004);
RUN_ONE_TESTCASE(testStdlibAtol005);
RUN_ONE_TESTCASE(testStdlibAtol006);
RUN_ONE_TESTCASE(testStdlibAtol007);
RUN_ONE_TESTCASE(testStdlibAtol008);
RUN_ONE_TESTCASE(testStdlibAtol009);
return;
}

View File

@@ -0,0 +1,230 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "limits.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStdlibAtollTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtollTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibAtollTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_001
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll001, Function | MediumTest | Level1)
{
long long value = atoll("9223372036854775807");
if (value == 9223372036854775807LL) {
LOG("[DEMO] posix stdlib test case 1:atoll(%lld) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 1:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 9223372036854775807LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_002
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll002, Function | MediumTest | Level1)
{
long long value = atoll("-9223372036854775808");
if (value == -9223372036854775808LL) {
LOG("[DEMO] posix stdlib test case 2:atoll(%lld) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 2:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == -9223372036854775808LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_003
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll003, Function | MediumTest | Level1)
{
long long value = atoll("100");
if (value == 100LL) {
LOG("[DEMO] posix stdlib test case 3:atoll(%lld) ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 3:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 100LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_004
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll004, Function | MediumTest | Level1)
{
long long value = atoll("9223372036854775808");
if (value == -9223372036854775808LL) {
LOG("[DEMO] posix stdlib test case 4(except):atoll(%lld) != 9223372036854775808 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 4(except):atoll(%lld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT64(LLONG_MIN, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_005
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll005, Function | MediumTest | Level1)
{
long long value = atoll("-9223372036854775809");
if (value == 9223372036854775807LL) {
LOG("[DEMO] posix stdlib test case 5(except):atoll(%lld) != -9223372036854775809 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 5(except):atoll(%lld) fail.\n", value);
}
TEST_ASSERT_EQUAL_INT64(LLONG_MAX, value);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_006
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll006, Function | MediumTest | Level1)
{
long long value = atoll("+100");
if (value == 100LL) {
LOG("[DEMO] posix stdlib test case 6:atoll(%lld) == +100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 6:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 100LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_007
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll007, Function | MediumTest | Level1)
{
long long value = atoll("-100");
if (value == -100LL) {
LOG("[DEMO] posix stdlib test case 7:atoll(%lld) == -100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 7:atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == -100LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_008
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll008, Function | MediumTest | Level1)
{
long long value = atoll("+-100");
if (value == 0LL) {
LOG("[DEMO] posix stdlib test case 8(except):atoll(%lld) == +-100 ok.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 8(except):atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 0LL);
}
/* *
* @tc.number : TEST_STDLIB_ATOLL_009
* @tc.name : convert string to long long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibAtollTest, testStdlibAtoll009, Function | MediumTest | Level1)
{
long long value = atoll("12+-100");
if (value == 12LL) {
LOG("[DEMO] posix stdlib test case 9(except):atoll(%lld) ok == 12+-100.\n", value);
} else {
LOG("[DEMO] posix stdlib test case 9(except):atoll(%lld) fail.\n", value);
}
TEST_ASSERT_TRUE(value == 12LL);
}
RUN_TEST_SUITE(PosixStdlibAtollTest);
void PosixStdlibAtollFuncTest()
{
LOG("begin PosixStdlibAtollFuncTest....");
RUN_ONE_TESTCASE(testStdlibAtoll001);
RUN_ONE_TESTCASE(testStdlibAtoll002);
RUN_ONE_TESTCASE(testStdlibAtoll003);
RUN_ONE_TESTCASE(testStdlibAtoll004);
RUN_ONE_TESTCASE(testStdlibAtoll005);
RUN_ONE_TESTCASE(testStdlibAtoll006);
RUN_ONE_TESTCASE(testStdlibAtoll007);
RUN_ONE_TESTCASE(testStdlibAtoll008);
RUN_ONE_TESTCASE(testStdlibAtoll009);
return;
}

View File

@@ -0,0 +1,330 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStdlibStrtolTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtolTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtolTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_001
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol001, Function | MediumTest | Level1)
{
char nPtr16[] = " 10";
char *endPtr16 = NULL;
long ret = strtol(nPtr16, &endPtr16, 16);
if (ret == 16) {
LOG("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16);
} else {
LOG("[DEMO] posix stdlib test case 1:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16);
}
TEST_ASSERT_EQUAL_INT32(16, ret);
TEST_ASSERT_EQUAL_STRING(endPtr16, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_002
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol002, Function | MediumTest | Level1)
{
char nPtr16[] = "0x10";
char *endPtr16 = NULL;
long ret = strtol(nPtr16, &endPtr16, 0);
if (ret == 16) {
LOG("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr16, endPtr16);
} else {
LOG("[DEMO] posix stdlib test case 2:strtol(base=16) ret:%ld,%s fail.\n", ret, nPtr16);
}
TEST_ASSERT_EQUAL_INT32(16, ret);
TEST_ASSERT_EQUAL_STRING(endPtr16, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_003
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol003, Function | MediumTest | Level1)
{
char nPtr10[] = "10";
char *endPtr10 = NULL;
long ret = strtol(nPtr10, &endPtr10, 10);
if (ret == 10) {
LOG("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10);
} else {
LOG("[DEMO] posix stdlib test case 3:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10);
}
TEST_ASSERT_EQUAL_INT32(10, ret);
TEST_ASSERT_EQUAL_STRING(endPtr10, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_004
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol004, Function | MediumTest | Level1)
{
char nPtr10[] = "-10";
char *endPtr10 = NULL;
long ret = strtol(nPtr10, &endPtr10, 10);
if (ret == -10) {
LOG("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10, endPtr10);
} else {
LOG("[DEMO] posix stdlib test case 4:strtol(base=10) ret:%ld,%s fail.\n", ret, nPtr10);
}
TEST_ASSERT_EQUAL_INT32(-10, ret);
TEST_ASSERT_EQUAL_STRING(endPtr10, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_005
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol005, Function | MediumTest | Level1)
{
char nPtr10_3[] = "10";
char *endPtr10_3 = NULL;
long ret = strtol(nPtr10_3, &endPtr10_3, 0);
if (ret == 10) {
LOG("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr10_3, endPtr10_3);
} else {
LOG("[DEMO] posix stdlib test case 5:strtol(base=0) ret:%ld,%s fail.\n", ret, nPtr10_3);
}
TEST_ASSERT_EQUAL_INT32(10, ret);
TEST_ASSERT_EQUAL_STRING(endPtr10_3, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_006
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol006, Function | MediumTest | Level1)
{
char nPtr8[] = "10";
char *endPtr8 = NULL;
long ret = strtol(nPtr8, &endPtr8, 8);
if (ret == 8) {
LOG("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8, endPtr8);
} else {
LOG("[DEMO] posix stdlib test case 6:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8);
}
TEST_ASSERT_EQUAL_INT32(8, ret);
TEST_ASSERT_EQUAL_STRING(endPtr8, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_007
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol007, Function | MediumTest | Level1)
{
char nPtr8_2[] = "010";
char *endPtr8_2 = NULL;
long ret = strtol(nPtr8_2, &endPtr8_2, 8);
if (ret == 8) {
LOG("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_2, endPtr8_2);
} else {
LOG("[DEMO] posix stdlib test case 7:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_2);
}
TEST_ASSERT_EQUAL_INT32(8, ret);
TEST_ASSERT_EQUAL_STRING(endPtr8_2, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_008
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol008, Function | MediumTest | Level1)
{
char nPtr8_3[] = "010";
char *endPtr8_3 = NULL;
long ret = strtol(nPtr8_3, &endPtr8_3, 0);
if (ret == 8) {
LOG("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr8_3, endPtr8_3);
} else {
LOG("[DEMO] posix stdlib test case 8:strtol(base=8) ret:%ld,%s fail.\n", ret, nPtr8_3);
}
TEST_ASSERT_EQUAL_INT32(8, ret);
TEST_ASSERT_EQUAL_STRING(endPtr8_3, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_009
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol009, Function | MediumTest | Level1)
{
char nPtr2[] = "10";
char *endPtr2 = NULL;
long ret = strtol(nPtr2, &endPtr2, 2);
if (ret == 2) {
LOG("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s, endPtr:%s ok.\n", ret, nPtr2, endPtr2);
} else {
LOG("[DEMO] posix stdlib test case 9:strtol(base=2) ret:%ld,%s fail.\n", ret, nPtr2);
}
TEST_ASSERT_EQUAL_INT32(2, ret);
TEST_ASSERT_EQUAL_STRING(endPtr2, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_010
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol010, Function | MediumTest | Level1)
{
char nPtr[] = "12 0110 0XDEFE 0666 -1.6";
char *endPtr = NULL;
long ret = strtol(nPtr, &endPtr, 10);
if (ret == 12) {
LOG("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 10:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_INT32(12, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 -1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOL_011
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol011, Function | MediumTest | Level1)
{
char nPtr[] = "12 1.5";
char *endPtr = NULL;
long ret = strtol(nPtr, &endPtr, 65);
if (ret == 67) {
LOG("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 11:strtol(base=65) ret:%ld, %s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_INT32(67, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 1.5");
}
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol012, Function | MediumTest | Level1)
{
char nPtr[] = "2147483647 -2147483648";
char *endPtr = NULL;
long ret = strtol(nPtr, &endPtr, 10);
if (ret == 2147483647) {
LOG("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 12:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_INT32(2147483647, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " -2147483648");
}
/* *
* @tc.number : TEST_STDLIB_ATOL_002
* @tc.name : convert string to long integer
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtolTest, testStdlibStrtol013, Function | MediumTest | Level1)
{
char nPtr[] = " -2147483648";
char *endPtr = NULL;
long ret = strtol(nPtr, &endPtr, 10);
if (ret == -2147483648) {
LOG("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s, endPtr:%s ok.\n", ret, endPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 13:strtol(base=10) ret:%ld, %s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_INT32(-2147483648, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, "");
}
RUN_TEST_SUITE(PosixStdlibStrtolTest);
void PosixStdlibStrtolFuncTest()
{
LOG("begin PosixStdlibStrtolFuncTest....");
RUN_ONE_TESTCASE(testStdlibStrtol001);
RUN_ONE_TESTCASE(testStdlibStrtol002);
RUN_ONE_TESTCASE(testStdlibStrtol003);
RUN_ONE_TESTCASE(testStdlibStrtol004);
RUN_ONE_TESTCASE(testStdlibStrtol005);
RUN_ONE_TESTCASE(testStdlibStrtol006);
RUN_ONE_TESTCASE(testStdlibStrtol007);
RUN_ONE_TESTCASE(testStdlibStrtol008);
RUN_ONE_TESTCASE(testStdlibStrtol009);
RUN_ONE_TESTCASE(testStdlibStrtol010);
RUN_ONE_TESTCASE(testStdlibStrtol011);
RUN_ONE_TESTCASE(testStdlibStrtol012);
RUN_ONE_TESTCASE(testStdlibStrtol013);
return;
}

View File

@@ -0,0 +1,277 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"
#include "limits.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStdlibStrtoulTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtoulTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtoulTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_001
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul001, Function | MediumTest | Level1)
{
char nPtr[] = "12 0110 0XDEFE 0666 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 10);
if (ret == 12UL) {
LOG("[DEMO] posix stdlib test case 1:strtoul(base=10) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 1:strtoul(base=10) ret:%lu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_EQUAL_UINT32(12UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 4294967295 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_002
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul002, Function | MediumTest | Level1)
{
char nPtr[] = " 0110 0XDEFE 0666 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 2);
if (ret == 6UL) {
LOG("[DEMO] posix stdlib test case 2:strtoul(base=2) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 2:strtoul(base=2) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(6UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0XDEFE 0666 4294967295 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_003
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul003, Function | MediumTest | Level1)
{
char nPtr[] = " 0XDEFE 0666 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 16);
if (ret == 0XDEFEUL) {
LOG("[DEMO] posix stdlib test case 3:strtoul(base=16) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 3:strtoul(base=16) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0XDEFEUL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0666 4294967295 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_004
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul004, Function | MediumTest | Level1)
{
char nPtr[] = " 0666 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 8);
if (ret == 0666UL) {
LOG("[DEMO] posix stdlib test case 4:strtoul(base=8) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 4:strtoul(base=8) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0666UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 4294967295 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_005
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul005, Function | MediumTest | Level1)
{
char nPtr[] = " 4294967295 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 4294967295UL) {
LOG("[DEMO] posix stdlib test case 5:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 5:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(4294967295UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 4294967296 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_006
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul006, Function | MediumTest | Level1)
{
char nPtr[] = " 4294967296 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 0UL) {
LOG("[DEMO] posix stdlib test case 6:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 6:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(ULONG_MAX, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 12.34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_007
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul007, Function | MediumTest | Level1)
{
char nPtr[] = " 12.34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 65);
if (ret == 67UL) {
LOG("[DEMO] posix stdlib test case 7:strtoul(base=65) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 7:strtoul(base=65) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(67UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, ".34");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_008
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul008, Function | MediumTest | Level1)
{
char nPtr[] = ".34";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 0UL) {
LOG("[DEMO] posix stdlib test case 8:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 8:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0UL, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, ".34");
}
/**
* @tc.number : TEST_STDLIB_STRTOUL_009
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul009, Function | MediumTest | Level1)
{
char nPtr[] = "0XDEFE 0666";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 0XDEFE) {
LOG("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0XDEFE, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0666");
}
/* *
* @tc.number : TEST_STDLIB_STRTOUL_010
* @tc.name : convert string by strtoul
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoulTest, testStdlibStrtoul010, Function | MediumTest | Level1)
{
char nPtr[] = " 0666";
char *endPtr = NULL;
unsigned long ret = strtoul(nPtr, &endPtr, 0);
if (ret == 0666) {
LOG("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 9:strtoul(base=0) ret:%lu,%s fail.\n", ret, endPtr);
}
TEST_ASSERT_EQUAL_UINT32(0666, ret);
TEST_ASSERT_EQUAL_STRING(endPtr, "");
}
RUN_TEST_SUITE(PosixStdlibStrtoulTest);
void PosixStdlibStrtoulFuncTest()
{
LOG("begin PosixStdlibStrtoulFuncTest....");
RUN_ONE_TESTCASE(testStdlibStrtoul001);
RUN_ONE_TESTCASE(testStdlibStrtoul002);
RUN_ONE_TESTCASE(testStdlibStrtoul003);
RUN_ONE_TESTCASE(testStdlibStrtoul004);
RUN_ONE_TESTCASE(testStdlibStrtoul005);
RUN_ONE_TESTCASE(testStdlibStrtoul006);
RUN_ONE_TESTCASE(testStdlibStrtoul007);
RUN_ONE_TESTCASE(testStdlibStrtoul008);
RUN_ONE_TESTCASE(testStdlibStrtoul009);
RUN_ONE_TESTCASE(testStdlibStrtoul010);
return;
}

View File

@@ -0,0 +1,280 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "ctype.h"
#include "errno.h"
#include "limits.h"
#include "stdlib.h"
#include "string.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStdlibStrtoullTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtoullTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStdlibStrtoullTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_001
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull001, Function | MediumTest | Level1)
{
char nPtr[] = "12 0110 0XDEFE 0666 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 10);
if (ret == 12ULL) {
LOG("[DEMO] posix stdlib test case 1:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 1:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 12ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0110 0XDEFE 0666 1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_002
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull002, Function | MediumTest | Level1)
{
char nPtr[] = " 0110 0XDEFE 0666 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 2);
if (ret == 6ULL) {
LOG("[DEMO] posix stdlib test case 2:strtoull(base=2) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 2:strtoull(base=2) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 6ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0XDEFE 0666 1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_003
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull003, Function | MediumTest | Level1)
{
char nPtr[] = " 0XDEFE 0666 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 16);
if (ret == 0XDEFEULL) {
LOG("[DEMO] posix stdlib test case 3:strtoull(base=16) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 3:strtoull(base=16) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0XDEFEULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0666 1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_004
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull004, Function | MediumTest | Level1)
{
char nPtr[] = " 0666 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 8);
if (ret == 0666ULL) {
LOG("[DEMO] posix stdlib test case 4:strtoull(base=8) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 4:strtoull(base=8) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0666ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 1.6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_005
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull005, Function | MediumTest | Level1)
{
char nPtr[] = " 1.6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 65);
if (ret == 1ULL) {
LOG("[DEMO] posix stdlib test case 5:strtoull(base=65) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 5:strtoull(base=65) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 1ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, ".6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_006
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull006, Function | MediumTest | Level1)
{
char nPtr[] = ".6";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 0);
if (ret == 0ULL) {
LOG("[DEMO] posix stdlib test case 6:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 6:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, ".6");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_007
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull007, Function | MediumTest | Level1)
{
char nPtr[] = "18446744073709551615 18446744073709551616";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 10);
if (ret == 18446744073709551615ULL) {
LOG("[DEMO] posix stdlib test case 7:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 7:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 18446744073709551615ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 18446744073709551616");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_008
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull008, Function | MediumTest | Level1)
{
char nPtr[] = " 18446744073709551616";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 10);
if (ret == 0ULL) {
LOG("[DEMO] posix stdlib test case 8:strtoull(base=10) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 8:strtoull(base=10) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_EQUAL_UINT64(ULLONG_MAX, ret);
TEST_ASSERT_EQUAL_INT(errno, ERANGE);
TEST_ASSERT_EQUAL_STRING(endPtr, "");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_009
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull009, Function | MediumTest | Level1)
{
char nPtr[] = "0XDEFE 0666";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 0);
if (ret == 0XDEFEULL) {
LOG("[DEMO] posix stdlib test case 9:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 9:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0XDEFEULL);
TEST_ASSERT_EQUAL_STRING(endPtr, " 0666");
}
/* *
* @tc.number : TEST_STDLIB_STRTOULL_010
* @tc.name : convert string by Strtoull
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStdlibStrtoullTest, testStdlibStrtoull010, Function | MediumTest | Level1)
{
char nPtr[] = " 0666";
char *endPtr = NULL;
unsigned long long ret = strtoull(nPtr, &endPtr, 0);
if (ret == 0666ULL) {
LOG("[DEMO] posix stdlib test case 10:strtoull(base=0) ret:%llu,%s, endPtr:%s ok.\n", ret, nPtr, endPtr);
} else {
LOG("[DEMO] posix stdlib test case 10:strtoull(base=0) ret:%llu,%s fail.\n", ret, nPtr);
}
TEST_ASSERT_TRUE(ret == 0666ULL);
TEST_ASSERT_EQUAL_STRING(endPtr, "");
}
RUN_TEST_SUITE(PosixStdlibStrtoullTest);
void PosixStdlibStrtoullFuncTest()
{
LOG("begin PosixStdlibStrtoullFuncTest....");
RUN_ONE_TESTCASE(testStdlibStrtoull001);
RUN_ONE_TESTCASE(testStdlibStrtoull002);
RUN_ONE_TESTCASE(testStdlibStrtoull003);
RUN_ONE_TESTCASE(testStdlibStrtoull004);
RUN_ONE_TESTCASE(testStdlibStrtoull005);
RUN_ONE_TESTCASE(testStdlibStrtoull006);
RUN_ONE_TESTCASE(testStdlibStrtoull007);
RUN_ONE_TESTCASE(testStdlibStrtoull008);
RUN_ONE_TESTCASE(testStdlibStrtoull009);
RUN_ONE_TESTCASE(testStdlibStrtoull010);
return;
}

View File

@@ -0,0 +1,372 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <stdlib.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is PosixMemFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixMemory, PosixMemFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixMemFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixMemFuncTestSuiteTearDown(void)
{
printf("+Hello this is a memory function test+\n");
return TRUE;
}
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCPY_OPERATION_001
* @tc.name : Memony operation for memcpy test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcpy001, Function | MediumTest | Level1)
{
void *retValue = NULL;
char source[]={"This File is About Memony Operation Test , Please Carefully Check Result As Below\r\n"};
char dest[1024]={0};
retValue = memcpy(dest, source, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
retValue = memcpy(source, dest, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
TEST_ASSERT_EQUAL_STRING(dest, source);
int len;
char chr = 'A';
char buf[1024];
len = sizeof(buf) / sizeof(buf[0]);
for (int i = 0; i < len; i++) {
buf[i] = chr + rand() % 26;
}
memcpy(&buf[16], &buf[0], 16);
for (int i = 0; i < 16; i++) {
TEST_ASSERT_EQUAL_INT((int)buf[i + 16], (int)buf[i]);
if (buf[i + 16] != buf[i]) {
printf("String Copy error \r\n");
break;
}
}
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCPY_OPERATION_002
* @tc.name : Memony operation for memcpy test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcpy002, Function | MediumTest | Level1)
{
void *retValue = NULL;
char source[]={"memory refers to the computer hardware devices used to store information for"
" immediate use in a computer\r\n"};
char dest[1024]={0};
retValue = memcpy(dest, source, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
retValue = memcpy(source, dest, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
TEST_ASSERT_EQUAL_STRING(source, dest);
char chr = 'A';
int i, len, failure;
char src[1024];
char dst[1024];
len = rand() % 1024;
for (i = 0; i < len; i++) {
src[i] = chr + i % 26;
}
memcpy(dst, src, len);
failure = 0;
for (i = 0; i < len; i++) {
if (dst[i] != src[i]) {
failure = 1;
break;
}
}
TEST_ASSERT_EQUAL_INT(0, failure);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMSET_OPERATION_001
* @tc.name : Memony operation for memset test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemset001, Function | MediumTest | Level1)
{
void *retValue = NULL;
char source[1024]={"memory refers to the computer hardware devices used to store information for"
" immediate use in a computer\r\n"};
char ch = rand() % 26 + 'A';
retValue = memset(source, ch, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_NOT_NULL(retValue);
TEST_ASSERT_EQUAL_PTR(retValue, source);
for (int i = 0; i < (sizeof(source) / sizeof(source[0])); i++) {
TEST_ASSERT_EQUAL_INT((int)source[i], (int)ch);
}
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCMP_OPERATION_001
* @tc.name : Memony operation for memcmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp001, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"memory refers to the computer hardware devices used to store information for "
"immediate use in a computer\r\n"};
char dest[]={"memory refers to the computer hardware devices used to store information for "
"immediate use in a computer\r\n"};
retValue = memcmp(source, dest, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_EQUAL_INT(0, retValue);
char orign[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
char lt[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x77};
char eq[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
char gt[8] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x99};
int ret;
int len = sizeof(orign);
ret = memcmp(orign, lt, len);
TEST_ASSERT_GREATER_THAN(0, ret);
ret = memcmp(eq, orign, len);
TEST_ASSERT_EQUAL_INT(0, ret);
ret = memcmp(orign, gt, len);
TEST_ASSERT_LESS_THAN(0, ret);
ret = memcmp(gt, orign, 0);
TEST_ASSERT_EQUAL_INT(0, ret);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCMP_OPERATION_002
* @tc.name : Memony operation for memcmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp002, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"memory refers to the computer hardware devices used to store information for "
"immediate use in a computer\r\n"};
char dest[]={"Hello, Richard, how are you?\r\n"};
retValue = memcmp(source, dest, sizeof(dest) / sizeof(dest[0]));
TEST_ASSERT_GREATER_THAN(0, retValue);
int ret = memcmp(L"CBCDEFG", L"BBCDEFG", 7);
TEST_ASSERT_GREATER_THAN(0, ret);
ret = memcmp(L"ABCDEFG", L"abcdefg", 2);
TEST_ASSERT_LESS_THAN(0, ret);
ret = memcmp(L"ABCDEFG", L"ABCDEFG", 6);
TEST_ASSERT_EQUAL_INT(0, ret);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_MEMCMP_OPERATION_003
* @tc.name : Memony operation for memcmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemMemcmp003, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"00000\r\n"};
char dest[]={"memory refers to the computer hardware devices used to store information for "
"immediate use in a computer\r\n"};
retValue = memcmp(source, dest, sizeof(source) / sizeof(source[0]));
TEST_ASSERT_LESS_THAN(0, retValue);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_REALLOC_OPERATION_001
* @tc.name : Memony operation for realloc test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc001, Function | MediumTest | Level1)
{
char *source = (char *)malloc(20);
source = (char *)realloc(source, 0);
TEST_ASSERT_NULL(source);
size_t k, len, mlen, rlen;
for (int i = 0; i < 5; i++) {
char *mem = NULL;
char *data = NULL;
int failure = 0;
const char testChar = 0x36;
mlen = 10;
mem = malloc(mlen);
TEST_ASSERT_NOT_NULL(mem);
memset(mem, testChar, mlen);
rlen = rand() % (1024) + mlen;
mem = realloc(mem, rlen);
TEST_ASSERT_NOT_NULL(mem);
len = mlen <= rlen ? mlen : rlen;
data = (char *)mem;
for (k = 0; k < len; k++) {
if (data[k] != testChar) {
failure = 1;
}
}
free(mem);
TEST_ASSERT_EQUAL_INT(failure, 0);
}
};
/* *
* @tc.number : SUB_KERNEL_POSIX_REALLOC_OPERATION_002
* @tc.name : Memony operation for realloc test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc002, Function | MediumTest | Level1)
{
char *source = (char *)malloc(20);
char *newData = (char *)realloc(source, 40);
TEST_ASSERT_NOT_NULL(newData);
if (newData != NULL) {
source = newData;
}
free(source);
const size_t len = 1024;
const size_t large = 4096;
void *mem = malloc(len);
TEST_ASSERT_NOT_NULL(mem);
void *reMem = realloc(mem, large);
TEST_ASSERT_NOT_NULL(reMem);
if (reMem != NULL) {
mem = reMem;
}
free(mem);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_REALLOC_OPERATION_003
* @tc.name : Memony operation for realloc test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc003, Function | MediumTest | Level1)
{
char *retValue = NULL;
retValue = (char *)realloc(retValue, 20);
TEST_ASSERT_NOT_NULL(retValue);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_REALLOC_OPERATION_004
* @tc.name : Memony operation for realloc test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixMemFuncTestSuite, testOsMemRealloc004, Function | MediumTest | Level1)
{
char *source = (char *)malloc(20);
char *newData = (char *)realloc(source, 10);
TEST_ASSERT_NOT_NULL(newData);
if (newData != NULL) {
source = newData;
}
free(source);
};
RUN_TEST_SUITE(PosixMemFuncTestSuite);
void PosixStringMemTest03()
{
LOG("begin PosixStringMemTest03....");
RUN_ONE_TESTCASE(testOsMemMemcpy001);
RUN_ONE_TESTCASE(testOsMemMemcpy002);
RUN_ONE_TESTCASE(testOsMemMemset001);
RUN_ONE_TESTCASE(testOsMemMemcmp001);
RUN_ONE_TESTCASE(testOsMemMemcmp002);
RUN_ONE_TESTCASE(testOsMemMemcmp003);
RUN_ONE_TESTCASE(testOsMemRealloc001);
RUN_ONE_TESTCASE(testOsMemRealloc002);
RUN_ONE_TESTCASE(testOsMemRealloc003);
RUN_ONE_TESTCASE(testOsMemRealloc004);
return;
}

View File

@@ -0,0 +1,183 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "log.h"
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStringStrchrTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringStrchrTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringStrchrTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STRING_STRCHR_001
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr001, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, '!');
if (strcmp(ret, "!! world") == 0) {
LOG("[DEMO] posix string test case 1:strchr(!) %s ok.\n", src);
} else {
LOG("[DEMO] posix string test case 1:strchr(!) %s fail.\n", src);
}
TEST_ASSERT_EQUAL_STRING(ret, "!! world");
}
/* *
* @tc.number : TEST_STRING_STRCHR_002
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr002, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, 'l');
if (strcmp(ret, "llo !! world") == 0) {
LOG("[DEMO] posix string test case 2:strchr(l) %s ok.\n", src);
} else {
LOG("[DEMO] posix string test case 2:strchr(l) %s fail.\n", src);
}
TEST_ASSERT_EQUAL_STRING(ret, "llo !! world");
}
/* *
* @tc.number : TEST_STRING_STRCHR_003
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr003, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, '\0');
if (ret != NULL) {
LOG("[DEMO] posix string test case 3:strchr(\'\\0\') %s ok.\n", src);
} else {
LOG("[DEMO] posix string test case 3:strchr(\'\\0\') %s fail.\n", src);
}
TEST_ASSERT_NOT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRCHR_004
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr004, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, '?');
if (ret == NULL) {
LOG("[DEMO] posix string test case 4(except):strchr(?) %s ok.\n", src);
} else {
LOG("[DEMO] posix string test case 4(except):strchr(?) %s fail.\n", src);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRCHR_005
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr005, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, 'm');
if (ret == NULL) {
LOG("[DEMO] posix string test case 5(except):strchr(m) %s ok.\n", src);
} else {
LOG("[DEMO] posix string test case 5(except):strchr(m) %s fail.\n", src);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRCHR_005
* @tc.name : find the first occurrence of a character in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrchrTest, testStringStrchr006, Function | MediumTest | Level1)
{
char src[] = "hello !! world";
char *ret = strchr(src, 0);
if (ret != NULL) {
LOG("[DEMO] posix string test case 6(except):strchr(0) %s ok.\n", src);
} else {
LOG("[DEMO] posix string test case 6(except):strchr(0) %s fail.\n", src);
}
TEST_ASSERT_NOT_NULL(ret);
}
RUN_TEST_SUITE(PosixStringStrchrTest);
void PosixStringStrchrTest()
{
LOG("begin PosixStringStrchrTest....");
RUN_ONE_TESTCASE(testStringStrchr001);
RUN_ONE_TESTCASE(testStringStrchr002);
RUN_ONE_TESTCASE(testStringStrchr003);
RUN_ONE_TESTCASE(testStringStrchr004);
RUN_ONE_TESTCASE(testStringStrchr005);
RUN_ONE_TESTCASE(testStringStrchr006);
return;
}

View File

@@ -0,0 +1,339 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#define RET_OK 0
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStringFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringFuncTestSuiteTearDown(void)
{
printf("==== [ String TEST ] ====\n\n");
return TRUE;
}
/* *
* @tc.number TEST_STRING_STRLEN_001
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen001, Function | MediumTest | Level1)
{
char src[] = "helloworld";
int ret = strlen(src);
TEST_ASSERT_EQUAL_INT(ret, 10);
}
/* *
* @tc.number TEST_STRING_STRLEN_002
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen002, Function | MediumTest | Level1)
{
char src[] = "hello world";
int ret = strlen(src);
TEST_ASSERT_EQUAL_INT(ret, 11);
}
/* *
* @tc.number TEST_STRING_STRLEN_003
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen003, Function | MediumTest | Level1)
{
int ret = strlen("");
TEST_ASSERT_EQUAL_INT(ret, 0);
}
/* *
* @tc.number TEST_STRING_STRLEN_004
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen004, Function | MediumTest | Level1)
{
char src[] = "hello\0world";
int ret = strlen(src);
TEST_ASSERT_EQUAL_INT(ret, 5);
}
/* *
* @tc.number TEST_STRING_STRLEN_005
* @tc.name string_strlen error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrlen005, Function | MediumTest | Level1)
{
char src[] = "\0helloworld";
int ret = strlen(src);
TEST_ASSERT_EQUAL_INT(ret, 0);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_001
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp001, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "HElloworld"};
int ret = strncasecmp(src[0], src[1], 2);
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_002
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp002, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "he\0lloworld"};
int ret = strncasecmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_003
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp003, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "he lloworld"};
int ret = strncasecmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_004
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp004, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "hello World"};
int ret = strncasecmp(src[0], src[1], 3);
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCASECMP_005
* @tc.name string_strncasecmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncasecmp005, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "\0"};
int ret = strncasecmp(src[0], src[1], 1);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_001
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp001, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "HELloworld"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_002
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp002, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "he\0lloworld"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_003
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp003, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "he lloworld"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_004
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp004, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "hello World"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_EQUAL_INT(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRNCMP_005
* @tc.name string_strncmp error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrncmp005, Function | MediumTest | Level1)
{
char *src[] = {"helloworld", "\0"};
int ret = strncmp(src[0], src[1], 3);
TEST_ASSERT_GREATER_THAN(RET_OK, ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_001
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr001, Function | MediumTest | Level1)
{
char src[] = "hello world";
char *ret = strrchr(src, '!');
TEST_ASSERT_EQUAL_PTR(ret, NULL);
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_002
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr002, Function | MediumTest | Level1)
{
char src[] = "hello world";
char *ret = strrchr(src, '\0');
TEST_ASSERT_EQUAL_PTR(ret, src + 11);
TEST_ASSERT_NOT_NULL(ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_003
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr003, Function | MediumTest | Level1)
{
char src[] = "hello\0world";
char *ret = strrchr(src, '\0');
TEST_ASSERT_EQUAL_PTR(ret, src + 5);
TEST_ASSERT_NOT_NULL(ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_004
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr004, Function | MediumTest | Level1)
{
char src[] = "hello world";
char *ret = strrchr(src, ' ');
TEST_ASSERT_EQUAL_PTR(ret, src + 5);
TEST_ASSERT_NOT_NULL(ret);
}
/* *
* @tc.number TEST_STRING_STRRCHR_005
* @tc.name string_strrchr error test with not exist pid
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStringStrrchr005, Function | MediumTest | Level1)
{
char src[] = "hello\0world";
char *ret = strrchr(src, ' ');
TEST_ASSERT_EQUAL_PTR(ret, NULL);
TEST_ASSERT_NULL(ret);
}
RUN_TEST_SUITE(PosixStringFuncTestSuite);
void PosixStringFuncTest02()
{
LOG("begin PosixStringFuncTest02....");
RUN_ONE_TESTCASE(testStringStrlen001);
RUN_ONE_TESTCASE(testStringStrlen002);
RUN_ONE_TESTCASE(testStringStrlen003);
RUN_ONE_TESTCASE(testStringStrlen004);
RUN_ONE_TESTCASE(testStringStrlen005);
RUN_ONE_TESTCASE(testStringStrncasecmp001);
RUN_ONE_TESTCASE(testStringStrncasecmp002);
RUN_ONE_TESTCASE(testStringStrncasecmp003);
RUN_ONE_TESTCASE(testStringStrncasecmp004);
RUN_ONE_TESTCASE(testStringStrncasecmp005);
RUN_ONE_TESTCASE(testStringStrncmp001);
RUN_ONE_TESTCASE(testStringStrncmp002);
RUN_ONE_TESTCASE(testStringStrncmp003);
RUN_ONE_TESTCASE(testStringStrncmp004);
RUN_ONE_TESTCASE(testStringStrncmp005);
RUN_ONE_TESTCASE(testStringStrrchr001);
RUN_ONE_TESTCASE(testStringStrrchr002);
RUN_ONE_TESTCASE(testStringStrrchr003);
RUN_ONE_TESTCASE(testStringStrrchr004);
RUN_ONE_TESTCASE(testStringStrrchr005);
return;
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#define EQUAL 0
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is PosixStringsFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixStrings, PosixStringsFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringsFuncTestSuiteSetUp(void)
{
LOG("+-------------------------------------------+\n");
LOG("+------PosixStringsFuncTestSuiteSetUp-------+\n");
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringsFuncTestSuiteTearDown(void)
{
LOG("+-------------------------------------------+\n");
LOG("+-----PosixStringsFuncTestSuiteTearDown-----+\n");
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number SUB_KERNEL_IO_STRINGS_0100
* @tc.name strcasecmp basic function test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringsFuncTestSuite, testStrCaseCmp001, Function | MediumTest | Level1)
{
int ret = strcasecmp("", "");
TEST_ASSERT_EQUAL_INT(ret, EQUAL);
ret = strcasecmp("abcdefg", "abcdefg");
TEST_ASSERT_EQUAL_INT(ret, EQUAL);
ret = strcasecmp("abcdefg", "abcdEFg");
TEST_ASSERT_EQUAL_INT(ret, EQUAL);
ret = strcasecmp("abcdefg", "abcdEF");
TEST_ASSERT_NOT_EQUAL(ret, EQUAL);
ret = strcasecmp("abcdef", "abcdEFg");
TEST_ASSERT_NOT_EQUAL(ret, EQUAL);
};
RUN_TEST_SUITE(PosixStringsFuncTestSuite);
void PosixStringStrcasecmpFuncTest()
{
LOG("begin PosixStringStrcasecmpFuncTest....");
RUN_ONE_TESTCASE(testStrCaseCmp001);
return;
}

View File

@@ -0,0 +1,240 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <stdlib.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include "log.h"
#include <time.h>
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is PosixStringFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixstring, PosixStringFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringFuncTestSuiteTearDown(void)
{
printf("+Hello this is a String function test+\n");
return TRUE;
}
/* *
* @tc.number : SUB_KERNEL_POSIX_STRING_OPERATION_001
* @tc.name : Memony operation for strcmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrstrcmp001, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"Compiler exited with error"};
char dest[] ={"Compiler exited with error"};
retValue = strcmp(source, dest);
TEST_ASSERT_EQUAL_INT(retValue, 0);
int ret = strcmp("abcdef", "ABCDEF");
TEST_ASSERT_LESS_THAN(ret, 0);
ret = strcmp("123456", "654321");
TEST_ASSERT_GREATER_THAN(ret, 0);
TEST_ASSERT_EQUAL_INT(strcmp("~!@#$%^&*()_+", "~!@#$%^&*()_+"), 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strcmp_OPERATION_002
* @tc.name : Memony operation for strncmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrstrcmp002, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"Compiler exited with error"};
char dest[] ={"00000000000"};
retValue = strcmp(source, dest);
TEST_ASSERT_LESS_THAN(retValue, 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strcmp_OPERATION_003
* @tc.name : Memony operation for strncmp test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrstrcmp003, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"0000000"};
char dest[] ={"Compiler exited with error"};
retValue = strcmp(source, dest);
TEST_ASSERT_GREATER_THAN(retValue, 0);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strdup_OPERATION_001
* @tc.name : Memony operation for strdup test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrdup001, Function | MediumTest | Level1)
{
char source[]={"Compiler exited with error"};
char *dest;
dest = strdup(source);
TEST_ASSERT_NOT_NULL(dest);
printf("The Result Display :%s\r\n", dest);
TEST_ASSERT_EQUAL_CHAR_ARRAY(dest, source, sizeof(source) / sizeof(source[0]));
char src[] = "hello world !";
char *ret = strdup(src);
TEST_ASSERT_EQUAL_CHAR_ARRAY(ret, src, sizeof(src) / sizeof(src[0]));
char srcS[] = "This is String1";
ret = strdup(srcS);
TEST_ASSERT_EQUAL_CHAR_ARRAY(ret, "This is String1", sizeof(srcS) / sizeof(srcS[0]));
free(ret);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strdup_OPERATION_002
* @tc.name : Memony operation for strdup test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrdup002, Function | MediumTest | Level1)
{
char source[]={"export MY_TEST_PATH=/opt/hadoop-2.6.5"};
char *dest;
dest = strdup(source);
TEST_ASSERT_NOT_NULL(dest);
printf("The Result Display :%s\r\n", dest);
TEST_ASSERT_EQUAL_CHAR_ARRAY(dest, source, sizeof(source) / sizeof(source[0]));
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strcspn_OPERATION_001
* @tc.name : Memony operation for strcspn test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrcspn001, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"export MY_TEST_PATH=/opt/hadoop-2.6.5"};
char dest1[] ={"H"};
retValue = strcspn(source, dest1);
TEST_ASSERT_EQUAL_INT(18U, retValue);
const char dest[] = "hello world !";
const char src[] = "!";
size_t ret = strcspn(dest, src);
TEST_ASSERT_EQUAL_INT(12U, ret);
const char srcS[] = "a";
ret = strcspn(dest, srcS);
TEST_ASSERT_EQUAL_INT(13U, ret);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strcspn_OPERATION_002
* @tc.name : Memony operation for strcspn test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrcspn002, Function | MediumTest | Level1)
{
int retValue = 0;
char source[]={"Compiler exited with error"};
char dest[] ={"or"};
retValue = strcspn(source, dest);
TEST_ASSERT_EQUAL_INT(1, retValue);
};
/* *
* @tc.number : SUB_KERNEL_POSIX_strptime_OPERATION_001
* @tc.name : Memony operation for strptime test
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringFuncTestSuite, testStrStrptime001, Function | MediumTest | Level1)
{
struct tm tmData;
memset_s(&tmData, sizeof(struct tm), 0, sizeof(struct tm));
char *ret = strptime("2020-10-29 21:24:00abc", "%Y-%m-%d %H:%M:%S", &tmData);
TEST_ASSERT_EQUAL_CHAR_ARRAY(ret, "abc", 3);
TEST_ASSERT_EQUAL_INT(tmData.tm_year, 120);
TEST_ASSERT_EQUAL_INT(tmData.tm_mon, 9);
TEST_ASSERT_EQUAL_INT(tmData.tm_mday, 29);
TEST_ASSERT_EQUAL_INT(tmData.tm_hour, 21);
TEST_ASSERT_EQUAL_INT(tmData.tm_min, 24);
}
RUN_TEST_SUITE(PosixStringFuncTestSuite);
void PosixStringFuncTest03()
{
LOG("begin PosixStringFuncTest03....");
RUN_ONE_TESTCASE(testStrstrcmp001);
RUN_ONE_TESTCASE(testStrstrcmp002);
RUN_ONE_TESTCASE(testStrstrcmp003);
RUN_ONE_TESTCASE(testStrStrdup001);
RUN_ONE_TESTCASE(testStrStrdup002);
RUN_ONE_TESTCASE(testStrStrcspn001);
RUN_ONE_TESTCASE(testStrStrcspn002);
RUN_ONE_TESTCASE(testStrStrptime001);
return;
}

View File

@@ -0,0 +1,313 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "kernel_test.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, Posixtimer, PosixStringStrStrTest);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringStrStrTestSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixStringStrStrTestTearDown(void)
{
LOG("+-------------------------------------------+\n");
return TRUE;
}
/* *
* @tc.number : TEST_STRING_STRSTR_001
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr001, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcS[] = "string";
char *ret = strstr(destS, srcS);
if (strcmp(ret, destS) == 0) {
LOG("[DEMO] posix string test case 1:strstr(%s) %s ok.\n", srcS, destS);
} else {
LOG("[DEMO] posix string test case 1:strstr(%s) %s fail.\n", srcS, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, destS);
}
/* *
* @tc.number : TEST_STRING_STRSTR_002
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr002, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcS[] = "this is";
char *ret = strstr(destS, srcS);
if (strcmp(ret, "this is string") == 0) {
LOG("[DEMO] posix string test case 2:strstr(%s) %s ok.\n", srcS, destS);
} else {
LOG("[DEMO] posix string test case 2:strstr(%s) %s fail.\n", srcS, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_003
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr003, Function | MediumTest | Level1)
{
const char dest[] = "hello world !";
const char srcT[] = "\0hello";
char *ret = strstr(dest, srcT);
if (strcmp(ret, dest) == 0) {
LOG("[DEMO] posix string test case 3:strstr(%s) %s ok.\n", srcT, dest);
} else {
LOG("[DEMO] posix string test case 3:strstr(%s) %s fail.\n", srcT, dest);
}
TEST_ASSERT_EQUAL_STRING(ret, dest);
}
/* *
* @tc.number : TEST_STRING_STRSTR_004
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr004, Function | MediumTest | Level1)
{
const char dest[] = "hello world !";
const char src[] = "heAlo";
char *ret = strstr(dest, src);
if (ret == NULL) {
LOG("[DEMO] posix string test case 4(except):strstr(%s) %s ok.\n", src, dest);
} else {
LOG("[DEMO] posix string test case 4(except):strstr(%s) %s fail.\n", src, dest);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_005
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr005, Function | MediumTest | Level1)
{
const char dest[] = "hello world !";
const char src[] = "hellm";
char *ret = strstr(dest, src);
if (ret == NULL) {
LOG("[DEMO] posix string test case 5(except):strstr(%s) %s ok.\n", src, dest);
} else {
LOG("[DEMO] posix string test case 5(except):strstr(%s) %s fail.\n", src, dest);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_006
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr006, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcOne[] = "t"; // one byte
char *ret = strstr(destS, srcOne);
if (strcmp(ret, "tring this is string") == 0) {
LOG("[DEMO] posix string test case 6:strstr(%s) %s ok.\n", srcOne, destS);
} else {
LOG("[DEMO] posix string test case 6:strstr(%s) %s fail.\n", srcOne, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "tring this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_007
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr007, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcOne[] = "m"; // one byte
char *ret = strstr(destS, srcOne);
if (ret == NULL) {
LOG("[DEMO] posix string test case 7(except):strstr(%s) %s ok.\n", srcOne, destS);
} else {
LOG("[DEMO] posix string test case 7(except):strstr(%s) %s fail.\n", srcOne, destS);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_008
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr008, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcTwo[] = "th"; // two byte
char *ret = strstr(destS, srcTwo);
if (strcmp(ret, "this is string") == 0) {
LOG("[DEMO] posix string test case 8:strstr(%s) %s ok.\n", srcTwo, destS);
} else {
LOG("[DEMO] posix string test case 8:strstr(%s) %s fail.\n", srcTwo, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_009
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr009, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcTwo2[] = "tm"; // two byte
char *ret = strstr(destS, srcTwo2);
if (ret == NULL) {
LOG("[DEMO] posix string test case 9(except):strstr(%s) %s ok.\n", srcTwo2, destS);
} else {
LOG("[DEMO] posix string test case 9(except):strstr(%s) %s fail.\n", srcTwo2, destS);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_010
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr010, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcThree[] = "thi"; // three byte
char *ret = strstr(destS, srcThree);
if (strcmp(ret, "this is string") == 0) {
LOG("[DEMO] posix string test case 10:strstr(%s) %s ok.\n", srcThree, destS);
} else {
LOG("[DEMO] posix string test case 10:strstr(%s) %s fail.\n", srcThree, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_011
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr011, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcThree[] = "thm"; // three byte
char *ret = strstr(destS, srcThree);
if (ret == NULL) {
LOG("[DEMO] posix string test case 11(except):strstr(%s) %s ok.\n", srcThree, destS);
} else {
LOG("[DEMO] posix string test case 11(except):strstr(%s) %s fail.\n", srcThree, destS);
}
TEST_ASSERT_NULL(ret);
}
/* *
* @tc.number : TEST_STRING_STRSTR_012
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr012, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcFour[] = "this"; // four byte
char *ret = strstr(destS, srcFour);
if (strcmp(ret, "this is string") == 0) {
LOG("[DEMO] posix string test case 12:strstr(%s) %s ok.\n", srcFour, destS);
} else {
LOG("[DEMO] posix string test case 12:strstr(%s) %s fail.\n", srcFour, destS);
}
TEST_ASSERT_EQUAL_STRING(ret, "this is string");
}
/* *
* @tc.number : TEST_STRING_STRSTR_013
* @tc.name : find the first occurrence of sub-string in a string
* @tc.desc : [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixStringStrStrTest, testStringStrStr013, Function | MediumTest | Level1)
{
const char destS[] = "string this is string";
const char srcFour[] = "thim"; // four byte
char *ret = strstr(destS, srcFour);
if (ret == NULL) {
LOG("[DEMO] posix string test case 13(except):strstr(%s) %s ok.\n", srcFour, destS);
} else {
LOG("[DEMO] posix string test case 13(except):strstr(%s) %s fail.\n", srcFour, destS);
}
TEST_ASSERT_NULL(ret);
}
RUN_TEST_SUITE(PosixStringStrStrTest);

View File

@@ -0,0 +1,566 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/time.h>
#include <sys/times.h>
#include <time.h>
#include <errno.h>
#include <limits.h>
#include "ohos_types.h"
#include "hctest.h"
#include "los_config.h"
#include "securec.h"
#include "kernel_test.h"
#include "log.h"
#define RET_OK 0
#define SLEEP_ACCURACY 21000 // 20 ms, with 1ms deviation
#define ACCURACY_TEST_LOOPS 3 // loops for accuracy test, than count average value
#define MILLISECONDS_PER_SECOND 1000
#define NANOSECONDS_PER_MILLISECOND 1000000
#define TM_BASE_YEAR 1900
#define TIME_STR_LEN 100
#define INIT_TM(tmSt, year, mon, day, hour, min, sec, wday) \
do { \
(tmSt).tm_sec = (sec); \
(tmSt).tm_min = (min); \
(tmSt).tm_hour = (hour); \
(tmSt).tm_mday = (day); \
(tmSt).tm_mon = (mon); \
(tmSt).tm_year = (year) - 1900; \
(tmSt).tm_wday = wday; \
(tmSt).__tm_gmtoff = 0; \
(tmSt).__tm_zone = ""; \
} while (0)
/* *
* @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
* @param : subsystem name is utils
* @param : module name is utilsFile
* @param : test suit name is CmsisTaskFuncTestSuite
*/
LITE_TEST_SUIT(Posix, PosixTime, PosixTimeFuncTestSuite);
/* *
* @tc.setup : setup for all testcases
* @return : setup result, TRUE is success, FALSE is fail
*/
static BOOL PosixTimeFuncTestSuiteSetUp(void)
{
return TRUE;
}
/* *
* @tc.teardown : teardown for all testcases
* @return : teardown result, TRUE is success, FALSE is fail
*/
static BOOL PosixTimeFuncTestSuiteTearDown(void)
{
return TRUE;
}
static int KeepRun(int msec)
{
struct timespec time1 = { 0, 0 };
struct timespec time2 = { 0, 0 };
clock_gettime(CLOCK_MONOTONIC, &time1);
LOG("KeepRun start : tv_sec=%ld, tv_nsec=%ld\n", time1.tv_sec, time1.tv_nsec);
int loop = 0;
int runned = 0;
while (runned < msec) {
++loop;
clock_gettime(CLOCK_MONOTONIC, &time2);
runned = (time2.tv_sec - time1.tv_sec) * MILLISECONDS_PER_SECOND;
runned += (time2.tv_nsec - time1.tv_nsec) / NANOSECONDS_PER_MILLISECOND;
}
LOG("KeepRun end : tv_sec=%ld, tv_nsec=%ld\n", time2.tv_sec, time2.tv_nsec);
return loop;
}
static int CheckValueClose(double target, double actual, double accuracy)
{
double diff = actual - target;
double pct;
if (diff < 0) {
diff = -diff;
}
if (actual == 0) {
return 0;
} else {
pct = diff / actual;
}
return (pct <= accuracy);
}
static char *TmToStr(const struct tm *stm, char *timeStr, unsigned len)
{
if (stm == NULL || timeStr == NULL) {
return "";
}
sprintf_s(timeStr, len, "%ld/%d/%d %02d:%02d:%02d WEEK(%d)", stm->tm_year + TM_BASE_YEAR, stm->tm_mon + 1,
stm->tm_mday, stm->tm_hour, stm->tm_min, stm->tm_sec, stm->tm_wday);
return timeStr;
}
/* *
* @tc.number SUB_KERNEL_TIME_USLEEP_001
* @tc.name usleep accuracy test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep001, Function | MediumTest | Level1)
{
// wifiiot无法支持10ms以下的sleep
int interval[] = {15*1000, 20*1000, 30*1000, 300*1000};
for (unsigned int j = 0; j < sizeof(interval) / sizeof(int); j++) {
LOG("\ntest interval:%d\n", interval[j]);
struct timespec time1 = { 0 }, time2 = { 0 };
long duration; // unit: us
double d = 0.0;
for (int i = 1; i <= ACCURACY_TEST_LOOPS; i++) {
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = usleep(interval[j]);
clock_gettime(CLOCK_MONOTONIC, &time2);
TEST_ASSERT_EQUAL_INT(RET_OK, rt);
duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000;
LOG("testloop %d, actual usleep duration: %ld us\n", i, duration);
d += duration;
}
d = d / ACCURACY_TEST_LOOPS; // average
LOG("interval:%u, average duration: %.2f\n", interval[j], d);
TEST_ASSERT_GREATER_OR_EQUAL(interval[j], d);
TEST_ASSERT_INT32_WITHIN(SLEEP_ACCURACY, interval[j], d);
}
}
/* *
* @tc.number SUB_KERNEL_TIME_USLEEP_002
* @tc.name usleep test for special delay
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeUSleep002, Function | MediumTest | Level1)
{
struct timespec time1 = { 0 };
struct timespec time2 = { 0 };
clock_gettime(CLOCK_MONOTONIC, &time1);
int rt = usleep(0);
clock_gettime(CLOCK_MONOTONIC, &time2);
TEST_ASSERT_EQUAL_INT(RET_OK, rt);
long long duration = (time2.tv_sec - time1.tv_sec) * 1000000 + (time2.tv_nsec - time1.tv_nsec) / 1000;
LOG("\n usleep(0), actual usleep duration: %lld us\n", duration);
TEST_ASSERT_LESS_OR_EQUAL_INT64(1000, duration);
}
/* *
* @tc.number SUB_KERNEL_TIME_GMTIME_001
* @tc.name test gmtime api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeGmtime001, Function | MediumTest | Level1)
{
time_t time1 = 18880;
char timeStr[TIME_STR_LEN] = {0};
LOG("\nsizeof(time_t) = %d, sizeof(struct tm) = %d", sizeof(time_t), sizeof(struct tm));
struct tm *stm = gmtime(&time1);
TEST_ASSERT_EQUAL_STRING("1970/1/1 05:14:40 WEEK(4)", TmToStr(stm, timeStr, TIME_STR_LEN));
time1 = LONG_MAX;
stm = gmtime(&time1);
LOG("\n LONG_MAX = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:07 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN));
time1 = LONG_MAX - 1;
stm = gmtime(&time1);
LOG("\n LONG_MAX - 1 = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("2038/1/19 03:14:06 WEEK(2)", TmToStr(stm, timeStr, TIME_STR_LEN));
time1 = LONG_MIN;
stm = gmtime(&time1);
LOG("\n LONG_MIN = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:52 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN));
time1 = LONG_MIN + 1;
stm = gmtime(&time1);
LOG("\n LONG_MIN + 1 = %lld, cvt result : %s", time1, TmToStr(stm, timeStr, TIME_STR_LEN));
TEST_ASSERT_EQUAL_STRING("1901/12/13 20:45:53 WEEK(5)", TmToStr(stm, timeStr, TIME_STR_LEN));
};
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIME_001
* @tc.name test localtime api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime001, Function | MediumTest | Level1)
{
char cTime[32];
time_t tStart;
time_t tEnd;
struct timeval timeSet = {
.tv_sec = 86399,
.tv_usec = 0
};
int ret = settimeofday(&timeSet, NULL);
time(&tStart);
sleep(2);
time(&tEnd);
TEST_ASSERT_EQUAL_INT(0, ret);
struct tm *tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
struct tm *tmEnd = localtime(&tEnd);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmEnd);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
LOG("\n time_t=%lld, first time:%s", tEnd, cTime);
}
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIME_002
* @tc.name test localtime api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltime002, Function | MediumTest | Level1)
{
char cTime[32];
time_t tStart = LONG_MAX;
struct tm *tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("38-01-19 11:14:07", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
tStart = LONG_MIN;
tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("01-12-14 04:45:52", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
tStart = 0;
tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("70-01-01 08:00:00", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
tStart = -1;
tmStart = localtime(&tStart);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("70-01-01 07:59:59", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
}
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIMER_001
* @tc.name localtime_r api base test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer001, Function | MediumTest | Level1)
{
char cTime[32];
time_t tStart;
time_t tEnd;
struct tm tmrStart = { 0 };
struct tm tmrEnd = { 0 };
struct timeval tSet = {
.tv_sec = 86399,
.tv_usec = 0
};
int ret = settimeofday(&tSet, NULL);
time(&tStart);
sleep(2);
time(&tEnd);
TEST_ASSERT_EQUAL_INT(0, ret);
struct tm *tmrStartPtr = localtime_r(&tStart, &tmrStart);
struct tm *tmrEndPtr = localtime_r(&tEnd, &tmrEnd);
strftime(cTime, sizeof(cTime), "%H:%M:%S", &tmrStart);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmrStartPtr);
TEST_ASSERT_EQUAL_STRING("23:59:59", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", &tmrEnd);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
strftime(cTime, sizeof(cTime), "%H:%M:%S", tmrEndPtr);
TEST_ASSERT_EQUAL_STRING("00:00:01", cTime);
}
/* *
* @tc.number SUB_KERNEL_TIME_LOCALTIMER_002
* @tc.name test localtime_r api for range
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeLocaltimer002, Function | MediumTest | Level1)
{
char cTime[32];
struct tm tmrResult = { 0 };
time_t tStart = LONG_MAX;
struct tm *tmStart = localtime_r(&tStart, &tmrResult);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("38-01-19 11:14:07", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
tStart = LONG_MIN;
tmStart = localtime_r(&tStart, &tmrResult);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("01-12-14 04:45:52", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
tStart = 0;
tmStart = localtime_r(&tStart, &tmrResult);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("70-01-01 08:00:00", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
tStart = -1;
tmStart = localtime_r(&tStart, &tmrResult);
strftime(cTime, sizeof(cTime), "%y-%m-%d %H:%M:%S", tmStart);
TEST_ASSERT_EQUAL_STRING("70-01-01 07:59:59", cTime);
LOG("\n time_t=%lld, first time:%s", tStart, cTime);
}
/* *
* @tc.number SUB_KERNEL_TIME_MKTIME_001
* @tc.name mktime api base test
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime001, Function | MediumTest | Level1)
{
// default time zone east 8
struct tm timeptr = { 0 };
time_t testTime = 18880;
char timeStr[TIME_STR_LEN] = {0};
INIT_TM(timeptr, 2020, 7, 9, 18, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
LOG("\n 2020-7-9 18:10:00, mktime Ret = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(1596967800, timeRet);
INIT_TM(timeptr, 1970, 0, 1, 8, 0, 0, 0);
timeRet = mktime(&timeptr);
LOG("\n 1970-1-1 08:00:00, mktime Ret = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(0, timeRet);
struct tm *stm = localtime(&testTime);
LOG("\n testTime 18880, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
TEST_ASSERT_EQUAL_INT(18880, timeRet);
LOG("\n input 18880, mktime Ret = %lld", timeRet);
testTime = LONG_MAX;
stm = localtime(&testTime);
LOG("\n testTime LONG_MAX, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
TEST_ASSERT_EQUAL_INT(LONG_MAX, timeRet);
LOG("\n input LONG_MAX, mktime Ret = %lld", timeRet);
testTime = 0;
stm = localtime(&testTime);
LOG("\n testTime 0, tm : %s", TmToStr(stm, timeStr, TIME_STR_LEN));
timeRet = mktime(stm);
TEST_ASSERT_EQUAL_INT(0, timeRet);
LOG("\n input 0, mktime Ret = %lld", timeRet);
}
/* *
* @tc.number SUB_KERNEL_TIME_MKTIME_002
* @tc.name mktime api test for invalid input
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeMktime002, Function | MediumTest | Level1)
{
struct tm timeptr = { 0 };
LOG("\n sizeof(time_t) = %d", sizeof(time_t));
INIT_TM(timeptr, 1969, 7, 9, 10, 10, 0, 7);
time_t timeRet = mktime(&timeptr);
LOG("\n 1800-8-9 10:10:00, mktime Ret lld = %lld", timeRet);
TEST_ASSERT_EQUAL_INT(0, timeRet);
}
/* *
* @tc.number SUB_KERNEL_TIME_STRFTIME_001
* @tc.name test strftime api
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime001, Function | MediumTest | Level3)
{
char buffer[80];
time_t mtime = 0;
size_t ftime = 0;
mtime = LONG_MAX;
ftime = strftime(buffer, 80, "%y-%m-%d %H:%M:%S", localtime(&mtime));
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("38-01-19 11:14:07", buffer);
LOG("\nresult: %s, expected : %s", buffer, "38-01-19 11:14:07");
mtime = LONG_MIN;
ftime = strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localtime(&mtime));
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("1901-12-14 04:45:52", buffer);
LOG("\nresult: %s, expected : %s", buffer, "1901-12-14 04:45:52");
mtime = 18880;
ftime = strftime(buffer, 80, "%F %T", localtime(&mtime));
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("1970-01-01 13:14:40", buffer);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
mtime = 18880;
ftime = strftime(buffer, 80, "%D %w %H:%M:%S", localtime(&mtime));
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("01/01/70 4 13:14:40", buffer);
LOG("\nresult: %s, expected : %s", buffer, "01/01/70 4 13:14:40");
};
/* *
* @tc.number SUB_KERNEL_TIME_STRFTIME_002
* @tc.name test strftime api base case
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime002, Function | MediumTest | Level3)
{
char buffer[80];
time_t mtime = 18880;
size_t ftime = 0;
struct tm *tmTime = localtime(&mtime);
ftime = strftime(buffer, 80, "%Ex %EX %A", tmTime);
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("01/01/70 13:14:40 Thursday", buffer);
LOG("\nresult: %s, expected : %s", buffer, "01/01/70 13:14:40 Thursday");
ftime = strftime(buffer, 80, "%x %X", tmTime);
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("01/01/70 13:14:40", buffer);
LOG("\nresult: %s, expected : %s", buffer, "01/01/70 13:14:40");
ftime = strftime(buffer, 80, "%D %A %H:%M:%S", tmTime);
TEST_ASSERT_GREATER_THAN_INT(0, ftime);
TEST_ASSERT_EQUAL_STRING("01/01/70 Thursday 13:14:40", buffer);
LOG("\nresult: %s, expected : %s", buffer, "01/01/70 Thursday 13:14:40");
};
/* *
* @tc.number SUB_KERNEL_TIME_STRFTIME_003
* @tc.name test strftime api for abnormal input
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimeStrftime003, Function | MediumTest | Level3)
{
char buffer[80];
time_t mtime = 18880;
size_t ftime = 0;
struct tm *tmTime = localtime(&mtime);
ftime = strftime(buffer, 12, "%Y-%m-%d %H:%M:%S", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
ftime = strftime(buffer, 80, "", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
ftime = strftime(buffer, 19, "%Y-%m-%d %H:%M:%S", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
ftime = strftime(buffer, 20, "%Y-%m-%d %H:%M:%S", tmTime);
TEST_ASSERT_EQUAL_INT(19, ftime);
TEST_ASSERT_EQUAL_STRING("1970-01-01 13:14:40", buffer);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
ftime = strftime(buffer, 80, "%F %T %Z", tmTime);
TEST_ASSERT_EQUAL_INT(0, ftime);
LOG("\nresult: %s, expected : %s", buffer, "1970-01-01 13:14:40");
};
/* *
* @tc.number SUB_KERNEL_TIME_API_TIMES_0100
* @tc.name test times basic
* @tc.desc [C- SOFTWARE -0200]
*/
LITE_TEST_CASE(PosixTimeFuncTestSuite, testTimes, Function | MediumTest | Level1)
{
const int testClockt = 100;
const int msPerClock = 10;
struct tms start = { 0 };
struct tms end = { 0 };
clock_t stTime = times(&start);
LOG("start_clock: stTime: %ld", stTime);
LOG("start_clock: tms_utime: %ld, tms_stime: %ld, tms_cutime:%ld, tms_cstime:%ld", start.tms_utime,
start.tms_stime, start.tms_cutime, start.tms_cstime);
KeepRun(testClockt * msPerClock);
clock_t endTime = times(&end);
LOG("end_clock: endTime: %ld", endTime);
LOG("end_clock: tms_utime: %ld, tms_stime: %ld, tms_cutime:%ld, tms_cstime:%ld", end.tms_utime, end.tms_stime,
end.tms_cutime, end.tms_cstime);
LOG("Real Time: %ld, User Time %ld, System Time %ld\n", (long)(endTime - stTime),
(long)(end.tms_utime - start.tms_utime), (long)(end.tms_stime - start.tms_stime));
if (!CheckValueClose((end.tms_utime - start.tms_utime), testClockt, 0.02)) {
TEST_FAIL();
}
if (!CheckValueClose((endTime - stTime), testClockt, 0.02)) {
TEST_FAIL();
}
}
RUN_TEST_SUITE(PosixTimeFuncTestSuite);
void PosixTimeFuncTest()
{
LOG("begin PosixTimeFuncTest....");
RUN_ONE_TESTCASE(testTimeUSleep001);
RUN_ONE_TESTCASE(testTimeUSleep002);
RUN_ONE_TESTCASE(testTimeGmtime001);
RUN_ONE_TESTCASE(testTimeLocaltime001);
RUN_ONE_TESTCASE(testTimeLocaltime002);
RUN_ONE_TESTCASE(testTimeLocaltimer001);
RUN_ONE_TESTCASE(testTimeLocaltimer002);
RUN_ONE_TESTCASE(testTimeMktime001);
RUN_ONE_TESTCASE(testTimeMktime002);
RUN_ONE_TESTCASE(testTimeStrftime001);
RUN_ONE_TESTCASE(testTimeStrftime002);
RUN_ONE_TESTCASE(testTimeStrftime003);
return;
}