feat: 支持Lms
1.【需求描述】: 支持内核态堆内存非法访问检测,包括:越界访问、double free、释放后使用;支持libc常用高频函数内存检测;支持安全函数内存检测;读写检测可配可裁剪。 2.【方案描述】: (1).影子内存映射与标记 (2).编译器使能-fsanitize=kernel-address 自动插桩检测点 (3).实时校验影子内存的合法性; (4).错误访问打印回溯栈 BREAKING CHANGE: 新增支持API: LOS_LmsCheckPoolAdd使能检测指定内存池 LOS_LmsCheckPoolDel不检测指定内存池 LOS_LmsAddrProtect为指定内存段上锁,不允许访问 LOS_LmsAddrDisableProtect去能指定内存段的访问保护 Close #I4HYBG Signed-off-by: LiteOS2021 <dinglu@huawei.com> Change-Id: Ia356a003088b9df37df667ea8ba91c80f5a41967
This commit is contained in:
@@ -69,6 +69,9 @@ group("testsuites") {
|
||||
if (defined(LOSCFG_DYNLINK)) {
|
||||
deps += [ "sample/kernel/dynlink:test_dynlink" ]
|
||||
}
|
||||
if (defined(LOSCFG_KERNEL_LMS)) {
|
||||
deps += [ "sample/kernel/lms:test_lms" ]
|
||||
}
|
||||
if (!module_switch) {
|
||||
deps = []
|
||||
}
|
||||
|
||||
@@ -162,6 +162,7 @@ typedef enum {
|
||||
#endif
|
||||
TEST_DRIVERBASE,
|
||||
TEST_DYNLINK,
|
||||
TEST_LMS,
|
||||
} LiteOS_test_module;
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -85,6 +85,7 @@ extern "C" {
|
||||
#define LOS_KERNEL_DYNLINK_TEST 0
|
||||
#define LOS_KERNEL_TICKLESS_TEST 0
|
||||
#define LOS_KERNEL_PM_TEST 1
|
||||
#define LOS_KERNEL_LMS_TEST 0
|
||||
|
||||
#define LITEOS_CMSIS_TEST 0
|
||||
#define LOS_CMSIS2_CORE_TASK_TEST 0
|
||||
|
||||
78
testsuites/sample/kernel/lms/BUILD.gn
Normal file
78
testsuites/sample/kernel/lms/BUILD.gn
Normal 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.
|
||||
|
||||
static_library("test_lms") {
|
||||
sources = [
|
||||
"It_los_lms.c",
|
||||
"It_los_lms_001.c",
|
||||
"It_los_lms_002.c",
|
||||
"It_los_lms_003.c",
|
||||
"It_los_lms_004.c",
|
||||
"It_los_lms_005.c",
|
||||
"It_los_lms_006.c",
|
||||
"It_los_lms_007.c",
|
||||
"It_los_lms_008.c",
|
||||
"It_los_lms_009.c",
|
||||
"It_los_lms_010.c",
|
||||
"It_los_lms_011.c",
|
||||
"It_los_lms_012.c",
|
||||
"It_los_lms_013.c",
|
||||
"It_los_lms_014.c",
|
||||
"It_los_lms_015.c",
|
||||
"It_los_lms_016.c",
|
||||
"It_los_lms_017.c",
|
||||
"It_los_lms_018.c",
|
||||
"It_los_lms_019.c",
|
||||
"It_los_lms_020.c",
|
||||
"It_los_lms_021.c",
|
||||
"It_los_lms_022.c",
|
||||
"It_los_lms_023.c",
|
||||
"It_los_lms_024.c",
|
||||
]
|
||||
|
||||
if ("$ohos_build_compiler_specified" == "gcc") {
|
||||
cflags_c = [
|
||||
"-O0",
|
||||
"-fsanitize=kernel-address",
|
||||
]
|
||||
} else {
|
||||
cflags_c = [
|
||||
"-O0",
|
||||
"-fsanitize=kernel-address",
|
||||
"-mllvm",
|
||||
"-asan-instrumentation-with-call-threshold=0",
|
||||
"-mllvm",
|
||||
"-asan-stack=0",
|
||||
"-mllvm",
|
||||
"-asan-globals=0",
|
||||
]
|
||||
}
|
||||
|
||||
configs += [ "//kernel/liteos_m/testsuites:include" ]
|
||||
}
|
||||
72
testsuites/sample/kernel/lms/It_los_lms.c
Normal file
72
testsuites/sample/kernel/lms/It_los_lms.c
Normal 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 "It_los_lms.h"
|
||||
|
||||
char g_testLmsPool[2 * PAGE_SIZE];
|
||||
|
||||
STATIC VOID testPoolInit(void)
|
||||
{
|
||||
UINT32 ret = LOS_MemInit(g_testLmsPool, 2 * PAGE_SIZE);
|
||||
if (ret != 0) {
|
||||
PRINT_ERR("%s failed, ret = 0x%x\n", __FUNCTION__, ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
VOID ItSuiteLosLms(void)
|
||||
{
|
||||
testPoolInit();
|
||||
ItLosLms001();
|
||||
ItLosLms002();
|
||||
ItLosLms003();
|
||||
ItLosLms004();
|
||||
ItLosLms005();
|
||||
ItLosLms006();
|
||||
ItLosLms007();
|
||||
ItLosLms008();
|
||||
ItLosLms009();
|
||||
ItLosLms010();
|
||||
ItLosLms011();
|
||||
ItLosLms012();
|
||||
ItLosLms013();
|
||||
ItLosLms014();
|
||||
ItLosLms015();
|
||||
ItLosLms016();
|
||||
ItLosLms017();
|
||||
ItLosLms018();
|
||||
ItLosLms019();
|
||||
ItLosLms020();
|
||||
ItLosLms021();
|
||||
ItLosLms022();
|
||||
ItLosLms023();
|
||||
ItLosLms024();
|
||||
}
|
||||
82
testsuites/sample/kernel/lms/It_los_lms.h
Normal file
82
testsuites/sample/kernel/lms/It_los_lms.h
Normal 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.
|
||||
*/
|
||||
|
||||
#ifndef IT_LOS_LMS_H
|
||||
#define IT_LOS_LMS_H
|
||||
|
||||
#include "osTest.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_config.h"
|
||||
#include "iCunit.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define INDEX_MAX 20
|
||||
#define PAGE_SIZE (0x1000U)
|
||||
|
||||
extern char g_testLmsPool[2 * PAGE_SIZE];
|
||||
|
||||
VOID ItLosLms001(void);
|
||||
VOID ItLosLms002(void);
|
||||
VOID ItLosLms003(void);
|
||||
VOID ItLosLms004(void);
|
||||
VOID ItLosLms005(void);
|
||||
VOID ItLosLms006(void);
|
||||
VOID ItLosLms007(void);
|
||||
VOID ItLosLms008(void);
|
||||
VOID ItLosLms009(void);
|
||||
VOID ItLosLms010(void);
|
||||
VOID ItLosLms011(void);
|
||||
VOID ItLosLms012(void);
|
||||
VOID ItLosLms013(void);
|
||||
VOID ItLosLms014(void);
|
||||
VOID ItLosLms015(void);
|
||||
VOID ItLosLms016(void);
|
||||
VOID ItLosLms017(void);
|
||||
VOID ItLosLms018(void);
|
||||
VOID ItLosLms019(void);
|
||||
VOID ItLosLms020(void);
|
||||
VOID ItLosLms021(void);
|
||||
VOID ItLosLms022(void);
|
||||
VOID ItLosLms023(void);
|
||||
VOID ItLosLms024(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* IT_LOS_LMS_H */
|
||||
54
testsuites/sample/kernel/lms/It_los_lms_001.c
Normal file
54
testsuites/sample/kernel/lms/It_los_lms_001.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 i;
|
||||
char *str = (char*)LOS_MemAlloc(g_testLmsPool, INDEX_MAX);
|
||||
for (i = 0; i < INDEX_MAX + 1; i++) {
|
||||
if (i % 4 == 0) {
|
||||
PRINTK("\n");
|
||||
}
|
||||
PRINTK("str[%2d]=0x%2x ", i, str[i]);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestOsmallocOverflow */
|
||||
VOID ItLosLms001(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms001", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
58
testsuites/sample/kernel/lms/It_los_lms_002.c
Normal file
58
testsuites/sample/kernel/lms/It_los_lms_002.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 boundary;
|
||||
CHAR *str = NULL;
|
||||
UINT32 i;
|
||||
UINT32 size = 20; /* mem size 20 */
|
||||
for (i = 2; i < 8; i++) { /* boundary loop from 2 to 8 */
|
||||
boundary = 1 << i;
|
||||
str = (CHAR *)LOS_MemAllocAlign(m_aucSysMem0, size, boundary);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINTK("str = 0x%x, boundary = %d\n", str, boundary);
|
||||
PRINTK("0x%x\n", str[size + 1]); /* trigger read overflow at size + 1 */
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, str);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemAlignOverflow */
|
||||
VOID ItLosLms002(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms002", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
59
testsuites/sample/kernel/lms/It_los_lms_003.c
Normal file
59
testsuites/sample/kernel/lms/It_los_lms_003.c
Normal 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.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 boundary;
|
||||
CHAR *str = NULL;
|
||||
UINT32 i;
|
||||
UINT32 size = 0x8 + 0x2; /* mem size 0x8 + 0x2 */
|
||||
for (i = 2; i < 8; i++) { /* boundary loop from 2 to 8 */
|
||||
boundary = 1 << i;
|
||||
str = (CHAR *)LOS_MemAllocAlign(m_aucSysMem0, size, boundary);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINTK("str = 0x%x, boundary = %d\n", str, boundary);
|
||||
PRINTK("0x%x\n", str[size + 1]); /* not trigger read overflow at size + 1 */
|
||||
PRINTK("0x%x\n", str[size + 2]); /* trigger read overflow at size + 2 */
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, str);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemAlignOverflow_Not4Align */
|
||||
VOID ItLosLms003(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms003", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
72
testsuites/sample/kernel/lms/It_los_lms_004.c
Normal file
72
testsuites/sample/kernel/lms/It_los_lms_004.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
#define PTR_NUM 100
|
||||
#define SIZE_NUM 2
|
||||
CHAR *str[PTR_NUM] = {NULL};
|
||||
UINT32 size[SIZE_NUM] = {20, 10}; /* mem size 20, 10 */
|
||||
UINT32 index;
|
||||
UINT32 i, j, k;
|
||||
UINT32 boundary;
|
||||
for (k = 0; k < SIZE_NUM; k++) {
|
||||
index = 0;
|
||||
for (j = 0; j < 10; j++) { /* loop 10 times each size */
|
||||
for (i = 2; i < 8; i++, index++) { /* boundary loop from 2 to 8 */
|
||||
boundary = 1 << i;
|
||||
PRINT_DEBUG("size = %d, boundary = %d\n", size[k], boundary);
|
||||
str[index] = (char *)LOS_MemAllocAlign(m_aucSysMem0, size[k], boundary);
|
||||
ICUNIT_GOTO_NOT_EQUAL(str[index], NULL, str[index], EXIT);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < index; i++) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
EXIT:
|
||||
for (i = 0; i < index; i++) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, str[i]);
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemAlignFree */
|
||||
VOID ItLosLms004(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms004", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
61
testsuites/sample/kernel/lms/It_los_lms_005.c
Normal file
61
testsuites/sample/kernel/lms/It_los_lms_005.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size = 20; /* mem size 20 */
|
||||
|
||||
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINT_DEBUG("str = 0x%x\n", str);
|
||||
(VOID)memset_s(str, size, 0xca, size);
|
||||
|
||||
/* oldSize - newsize < OS_MEM_NODE_HEAD_SIZE + OS_MEM_ALIGN_SIZE */
|
||||
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size - 4); /* mem size - 4 */
|
||||
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT);
|
||||
|
||||
PRINTK("newPtr = 0x%x\n", newPtr[size - 4]); /* trigger read overflow at size - 4 */
|
||||
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
|
||||
return LOS_OK;
|
||||
EXIT:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestReallocTest1 */
|
||||
VOID ItLosLms005(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms005", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
61
testsuites/sample/kernel/lms/It_los_lms_006.c
Normal file
61
testsuites/sample/kernel/lms/It_los_lms_006.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size = 20 * 3; /* mem size 20 * 3 */
|
||||
|
||||
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINT_DEBUG("str = 0x%x\n", str);
|
||||
(VOID)memset_s(str, size, 0xca, size);
|
||||
|
||||
/* oldSize - newSize >= OS_MEM_NODE_HEAD_SIZE + OS_MEM_ALIGN_SIZE */
|
||||
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size - 32); /* mem size - 32 */
|
||||
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT);
|
||||
|
||||
PRINTK("newPtr = 0x%x\n", newPtr[size - 30]); /* trigger read overflow at size - 30 */
|
||||
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
|
||||
return LOS_OK;
|
||||
EXIT:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestReallocTest2 */
|
||||
VOID ItLosLms006(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms006", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
81
testsuites/sample/kernel/lms/It_los_lms_007.c
Normal file
81
testsuites/sample/kernel/lms/It_los_lms_007.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size = 20; /* mem size 20 */
|
||||
|
||||
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINT_DEBUG("str = 0x%x\n", str);
|
||||
|
||||
CHAR *bigger = (CHAR *)LOS_MemAlloc(g_testLmsPool, size * 3); /* mem size * 3 */
|
||||
ICUNIT_GOTO_NOT_EQUAL(bigger, NULL, bigger, EXIT);
|
||||
PRINT_DEBUG("bigger addr = 0x%x, %d\n", bigger, __LINE__);
|
||||
|
||||
CHAR *tmp = (CHAR *)LOS_MemAlloc(g_testLmsPool, size); /* do not release */
|
||||
ICUNIT_GOTO_NOT_EQUAL(tmp, NULL, tmp, EXIT1);
|
||||
PRINT_DEBUG("tmp addr = 0x%x,%d\n", tmp, __LINE__);
|
||||
|
||||
(VOID)LOS_MemFree(g_testLmsPool, bigger);
|
||||
|
||||
/* resize < size + next size && split node */
|
||||
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size * 2); /* mem size * 2 */
|
||||
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT2);
|
||||
|
||||
PRINTK("0x%x\n", newPtr[size * 2]); /* trigger read overflow at size * 2 */
|
||||
|
||||
(VOID)LOS_MemFree(g_testLmsPool, tmp);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
|
||||
return LOS_OK;
|
||||
|
||||
EXIT:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
return LOS_OK;
|
||||
EXIT1:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, bigger);
|
||||
return LOS_OK;
|
||||
EXIT2:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, tmp);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestReallocTest3 */
|
||||
VOID ItLosLms007(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms007", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
81
testsuites/sample/kernel/lms/It_los_lms_008.c
Normal file
81
testsuites/sample/kernel/lms/It_los_lms_008.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size = 20; /* mem size 20 */
|
||||
|
||||
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINT_DEBUG("str = 0x%x\n", str);
|
||||
|
||||
CHAR *bigger = (CHAR *)LOS_MemAlloc(g_testLmsPool, size * 3); /* mem size * 3 */
|
||||
ICUNIT_GOTO_NOT_EQUAL(bigger, NULL, bigger, EXIT);
|
||||
PRINT_DEBUG("bigger = 0x%x,%d\n", bigger, __LINE__);
|
||||
|
||||
CHAR *tmp = (CHAR *)LOS_MemAlloc(g_testLmsPool, size); /* do not release */
|
||||
ICUNIT_GOTO_NOT_EQUAL(tmp, NULL, tmp, EXIT1);
|
||||
PRINT_DEBUG("tmp = 0x%x,%d\n", tmp, __LINE__);
|
||||
|
||||
(VOID)LOS_MemFree(g_testLmsPool, bigger);
|
||||
|
||||
/* resize < size + next size && not split node */
|
||||
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size * 4 + 8); /* mem size * 4 - 8 */
|
||||
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT2);
|
||||
PRINT_DEBUG("newPtr = 0x%x,%d\n", newPtr, __LINE__);
|
||||
PRINTK("0x%x\n", newPtr[size * 4 + 8]); /* trigger read overflow at size * 4 - 8 */
|
||||
|
||||
(VOID)LOS_MemFree(g_testLmsPool, tmp);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
|
||||
|
||||
return LOS_OK;
|
||||
EXIT:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
return LOS_OK;
|
||||
EXIT1:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, bigger);
|
||||
return LOS_OK;
|
||||
EXIT2:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, tmp);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestReallocTest4 */
|
||||
VOID ItLosLms008(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms008", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
81
testsuites/sample/kernel/lms/It_los_lms_009.c
Normal file
81
testsuites/sample/kernel/lms/It_los_lms_009.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size = 20; /* mem size 20 */
|
||||
|
||||
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINT_DEBUG("str = 0x%x,%d\n", str, __LINE__);
|
||||
|
||||
CHAR *bigger = (CHAR *)LOS_MemAlloc(g_testLmsPool, size * 3); /* mem size * 3 */
|
||||
ICUNIT_GOTO_NOT_EQUAL(bigger, NULL, bigger, EXIT);
|
||||
PRINT_DEBUG("bigger = 0x%x,%d\n", bigger, __LINE__);
|
||||
|
||||
CHAR *tmp = (CHAR *)LOS_MemAlloc(g_testLmsPool, size); /* do not release */
|
||||
ICUNIT_GOTO_NOT_EQUAL(tmp, NULL, tmp, EXIT1);
|
||||
PRINT_DEBUG("tmp = 0x%x,%d\n", tmp, __LINE__);
|
||||
|
||||
(VOID)LOS_MemFree(g_testLmsPool, bigger);
|
||||
|
||||
/* resize > size + next size */
|
||||
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, size * 6); /* mem size * 6 */
|
||||
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT2);
|
||||
PRINT_DEBUG("newPtr = 0x%x,%d\n", newPtr, __LINE__);
|
||||
PRINTK("0x%x\n", newPtr[size * 6]); /* trigger overflow at size * 6 */
|
||||
|
||||
(VOID)LOS_MemFree(g_testLmsPool, tmp);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
|
||||
|
||||
return LOS_OK;
|
||||
EXIT:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
return LOS_OK;
|
||||
EXIT1:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, bigger);
|
||||
return LOS_OK;
|
||||
EXIT2:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
(VOID)LOS_MemFree(g_testLmsPool, tmp);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestReallocTest5 */
|
||||
VOID ItLosLms009(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms009", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
79
testsuites/sample/kernel/lms/It_los_lms_010.c
Normal file
79
testsuites/sample/kernel/lms/It_los_lms_010.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size = 20; /* mem size 20 */
|
||||
CHAR *backStr;
|
||||
|
||||
CHAR *str = (CHAR *)LOS_MemAlloc(g_testLmsPool, size);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINT_DEBUG("str = 0x%x,%d\n", str, __LINE__);
|
||||
|
||||
CHAR *newPtr = LOS_MemRealloc(g_testLmsPool, str, 0x8+0x2); /* reaSize 0x2 is not 4Align */
|
||||
ICUNIT_GOTO_NOT_EQUAL(newPtr, NULL, newPtr, EXIT);
|
||||
PRINT_DEBUG("newPtr = 0x%x,%d\n", newPtr, __LINE__);
|
||||
|
||||
PRINTK("0x%x\n", newPtr[0x8+0x3]); /* not trigger overflow at newPtr[0x3] */
|
||||
|
||||
PRINTK("Trigger write overflow\n");
|
||||
newPtr[0x8+0x4] = 0x01; /* write 0x1,trigger overflow at newPtr[0x4] */
|
||||
|
||||
PRINTK("Trigger read overflow\n");
|
||||
PRINTK("0x%x\n", newPtr[0x8+0x4]); /* trigger read overflow at newPtr[0x4] */
|
||||
|
||||
backStr = (CHAR *)(newPtr - 1); /* Add offset -1 */
|
||||
PRINTK("Trigger back offset write overflow\n");
|
||||
*backStr = 0x01;
|
||||
|
||||
PRINTK("Trigger back offset read overflow\n");
|
||||
PRINTK("0x%x\n", *backStr); /* trigger overflow */
|
||||
|
||||
PRINTK("Trigger read overflow\n"); /* trigger read overflow */
|
||||
PRINTK("0x%x\n", newPtr[0x8+0x5]); /* trigger overflow at newPtr[0x5] */
|
||||
|
||||
(VOID)LOS_MemFree(g_testLmsPool, newPtr);
|
||||
|
||||
return LOS_OK;
|
||||
EXIT:
|
||||
(VOID)LOS_MemFree(g_testLmsPool, str);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestReallocTest6 */
|
||||
VOID ItLosLms010(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms010", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
56
testsuites/sample/kernel/lms/It_los_lms_011.c
Normal file
56
testsuites/sample/kernel/lms/It_los_lms_011.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 i;
|
||||
char *str = (char*)LOS_MemAlloc(m_aucSysMem0, INDEX_MAX);
|
||||
for (i = 0; i < INDEX_MAX; i++) {
|
||||
if (i % 4 == 0) {
|
||||
PRINTK("\n");
|
||||
}
|
||||
PRINTK("str[%2d]=0x%2x ", i, str[i]);
|
||||
}
|
||||
LOS_MemFree(m_aucSysMem0, str);
|
||||
PRINTK("str[%2d]=0x%2x ", 0, str[0]);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestUseAfterFree */
|
||||
VOID ItLosLms011(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms011", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
56
testsuites/sample/kernel/lms/It_los_lms_012.c
Normal file
56
testsuites/sample/kernel/lms/It_los_lms_012.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 i;
|
||||
char *str = (char*)LOS_MemAlloc(m_aucSysMem0, INDEX_MAX);
|
||||
for (i = 0; i < INDEX_MAX; i++) {
|
||||
if (i % 4 == 0) {
|
||||
PRINTK("\n");
|
||||
}
|
||||
PRINTK("str[%2d]=0x%2x ", i, str[i]);
|
||||
}
|
||||
LOS_MemFree(m_aucSysMem0, str);
|
||||
LOS_MemFree(m_aucSysMem0, str);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestDoubleFree */
|
||||
VOID ItLosLms012(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms012", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
56
testsuites/sample/kernel/lms/It_los_lms_013.c
Normal file
56
testsuites/sample/kernel/lms/It_los_lms_013.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 i;
|
||||
char str2[INDEX_MAX + 1] = "1234567890abcdefghij";
|
||||
char *str = (char*)LOS_MemAlloc(m_aucSysMem0, INDEX_MAX);
|
||||
memcpy(str, str2, INDEX_MAX + 1);
|
||||
for (i = 0; i < INDEX_MAX + 1; i++) {
|
||||
if (i % 4 == 0) {
|
||||
PRINTK("\n");
|
||||
}
|
||||
PRINTK("str[%2d]=0x%2x ", i, str[i]);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemcpyOverflow */
|
||||
VOID ItLosLms013(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms013", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
55
testsuites/sample/kernel/lms/It_los_lms_014.c
Normal file
55
testsuites/sample/kernel/lms/It_los_lms_014.c
Normal 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.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 i;
|
||||
char *str = (char*)LOS_MemAlloc(m_aucSysMem0, INDEX_MAX);
|
||||
memset(str, 0xca, INDEX_MAX + 1);
|
||||
for (i = 0; i < INDEX_MAX + 1; i++) {
|
||||
if (i % 4 == 0) {
|
||||
PRINTK("\n");
|
||||
}
|
||||
PRINTK("str[%2d]=0x%2x ", i, str[i]);
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemsetSOverflow */
|
||||
VOID ItLosLms014(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms014", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
54
testsuites/sample/kernel/lms/It_los_lms_015.c
Normal file
54
testsuites/sample/kernel/lms/It_los_lms_015.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
#define SIZEE 100
|
||||
CHAR src[SIZEE + 1] = {0};
|
||||
CHAR *p = (CHAR *)LOS_MemAlloc(m_aucSysMem0, SIZEE);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
|
||||
|
||||
memmove(p, src, SIZEE);
|
||||
PRINTK("p[0] = %d\n", p[0]);
|
||||
memmove(p, src, SIZEE + 1); /* trigger overflow */
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemmoveOverflow */
|
||||
VOID ItLosLms015(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms015", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
68
testsuites/sample/kernel/lms/It_los_lms_016.c
Normal file
68
testsuites/sample/kernel/lms/It_los_lms_016.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR *string = "LMS_TestCase";
|
||||
CHAR *src;
|
||||
CHAR *buf;
|
||||
CHAR *str;
|
||||
UINT32 ret;
|
||||
|
||||
src = LOS_MemAlloc(m_aucSysMem0, strlen(string));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
|
||||
|
||||
buf = LOS_MemAlloc(m_aucSysMem0, (strlen(string) + 10)); /* mem size 10 */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
|
||||
|
||||
str = strcpy(src, string); /* write overflow */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
|
||||
(VOID)strcpy(buf, src); /* Check LMS detection information when the strcpy src overflows. */
|
||||
|
||||
ret = LOS_MemFree(m_aucSysMem0, buf);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
|
||||
|
||||
ret = LOS_MemFree(m_aucSysMem0, src);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestStrcpyOverflow */
|
||||
VOID ItLosLms016(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms016", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
71
testsuites/sample/kernel/lms/It_los_lms_017.c
Normal file
71
testsuites/sample/kernel/lms/It_los_lms_017.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR *string = "LMS_TestCase";
|
||||
CHAR *src;
|
||||
CHAR *buf;
|
||||
CHAR *str;
|
||||
UINT32 ret;
|
||||
|
||||
src = LOS_MemAlloc(m_aucSysMem0, (strlen(string) + 1)); /* mem size 1 */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
|
||||
|
||||
str = strcpy(src, string);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
|
||||
buf = LOS_MemAlloc(m_aucSysMem0, (strlen(string) + 4)); /* mem size 10 */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
|
||||
(VOID)memset(buf, 0, (strlen(string) + 4)); /* memset size 10 */
|
||||
|
||||
(VOID)strcat(buf, src); /* no overflows. */
|
||||
(VOID)strcat(buf, "123"); /* no overflows. */
|
||||
(VOID)strcat(buf, "4"); /* write overflows. */
|
||||
|
||||
ret = LOS_MemFree(m_aucSysMem0, buf);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
|
||||
|
||||
ret = LOS_MemFree(m_aucSysMem0, src);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestStrcatOverflow */
|
||||
VOID ItLosLms017(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms017", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
74
testsuites/sample/kernel/lms/It_los_lms_018.c
Normal file
74
testsuites/sample/kernel/lms/It_los_lms_018.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR *src;
|
||||
CHAR *buf;
|
||||
|
||||
src = LOS_MemAlloc(m_aucSysMem0, 9);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
|
||||
|
||||
(VOID)memset(src, 0, 9);
|
||||
src[0] = 49;
|
||||
src[1] = 50;
|
||||
src[2] = 51;
|
||||
src[3] = 52;
|
||||
src[4] = 53;
|
||||
src[5] = 54;
|
||||
src[6] = 55;
|
||||
src[7] = 56;
|
||||
PRINTK("strlen(src) = %d\n", strlen(src));
|
||||
|
||||
buf = LOS_MemAlloc(m_aucSysMem0, 7);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
|
||||
buf[0] = 0;
|
||||
strncat(buf, src, 8); /* trigger buf overflow */
|
||||
buf[0] = 0;
|
||||
strncat(buf, src, 9); /* trigger buf overflow */
|
||||
buf[0] = 0;
|
||||
strncat(buf, src, 20); /* trigger buf overflow */
|
||||
buf[0] = 0;
|
||||
strncat(buf, src, 21); /* trigger buf overflow */
|
||||
PRINTK("\n######%s stop ######\n", __FUNCTION__);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestStrncatOverflow */
|
||||
VOID ItLosLms018(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms018", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
72
testsuites/sample/kernel/lms/It_los_lms_019.c
Normal file
72
testsuites/sample/kernel/lms/It_los_lms_019.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR *src;
|
||||
CHAR *buf;
|
||||
|
||||
src = LOS_MemAlloc(m_aucSysMem0, 9);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
|
||||
|
||||
(VOID)memset(src, 0, 9);
|
||||
src[0] = 49;
|
||||
src[1] = 50;
|
||||
src[2] = 51;
|
||||
src[3] = 52;
|
||||
src[4] = 53;
|
||||
src[5] = 54;
|
||||
src[6] = 55;
|
||||
src[7] = 56;
|
||||
PRINTK("strlen(src) = %d\n", strlen(src));
|
||||
|
||||
buf = LOS_MemAlloc(m_aucSysMem0, 20);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
|
||||
buf[0] = 0;
|
||||
(VOID)strncpy(buf, src, 8); /* no trigger overflow */
|
||||
buf[0] = 0;
|
||||
(VOID)strncpy(buf, src, 9); /* no trigger overflow */
|
||||
buf[0] = 0;
|
||||
(VOID)strncpy(buf, src, 20); /* no trigger overflow */
|
||||
buf[0] = 0;
|
||||
(VOID)strncpy(buf, src, 21); /* trigger buf overflow */
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestStrncpyOverflow */
|
||||
VOID ItLosLms019(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms019", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
51
testsuites/sample/kernel/lms/It_los_lms_020.c
Normal file
51
testsuites/sample/kernel/lms/It_los_lms_020.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR *p = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
|
||||
memset_s(p, INDEX_MAX, 0, INDEX_MAX + 1);
|
||||
PRINTK("p[0] = %d\n", p[0]);
|
||||
memset_s(p, INDEX_MAX + 1, 0, INDEX_MAX + 1); /* trigger overflow */
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemset_sOverflow */
|
||||
VOID ItLosLms020(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms020", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
53
testsuites/sample/kernel/lms/It_los_lms_021.c
Normal file
53
testsuites/sample/kernel/lms/It_los_lms_021.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR src[INDEX_MAX + 1] = {0};
|
||||
CHAR *p = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
|
||||
|
||||
memcpy_s(p, INDEX_MAX, src, INDEX_MAX + 1);
|
||||
PRINTK("p[0] = %d\n", p[0]);
|
||||
memcpy_s(p, INDEX_MAX + 1, 0, INDEX_MAX + 1); /* trigger overflow */
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemcpy_sOverflow */
|
||||
VOID ItLosLms021(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms021", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
52
testsuites/sample/kernel/lms/It_los_lms_022.c
Normal file
52
testsuites/sample/kernel/lms/It_los_lms_022.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR *p = (CHAR *)LOS_MemAlloc(g_testLmsPool, INDEX_MAX);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
|
||||
|
||||
memmove_s(p, INDEX_MAX, 0, INDEX_MAX + 1);
|
||||
PRINTK("p[0] = %d\n", p[0]);
|
||||
memmove_s(p, INDEX_MAX + 1, 0, INDEX_MAX + 1); /* trigger overflow */
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestMemmove_sOverflow */
|
||||
VOID ItLosLms022(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms022", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
71
testsuites/sample/kernel/lms/It_los_lms_023.c
Normal file
71
testsuites/sample/kernel/lms/It_los_lms_023.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR *string = "LMS_TestCase";
|
||||
CHAR *src;
|
||||
CHAR *buf;
|
||||
CHAR *str;
|
||||
UINT32 ret;
|
||||
src = LOS_MemAlloc(g_testLmsPool, (strlen(string) + 1));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
|
||||
PRINTK("%d\n", __LINE__);
|
||||
(VOID)__memset(src, 0, (strlen(string) + 1));
|
||||
|
||||
PRINTK("%d\n", __LINE__);
|
||||
str = __strcpy(src, string);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINTK("%d\n", __LINE__);
|
||||
|
||||
buf = LOS_MemAlloc(g_testLmsPool, 8); /* mem size 8 */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
|
||||
buf[7] = '\0'; /* end index 7 */
|
||||
PRINTK("%d\n", __LINE__);
|
||||
ret = strcat_s(buf, 100, src); /* Check LMS detection information when the strcat dest max set 100 overflows. */
|
||||
PRINTK("%d\n", __LINE__);
|
||||
ret = LOS_MemFree(g_testLmsPool, buf);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
|
||||
ret = LOS_MemFree(g_testLmsPool, src);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestStrcat_sOverflow */
|
||||
VOID ItLosLms023(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms023", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
71
testsuites/sample/kernel/lms/It_los_lms_024.c
Normal file
71
testsuites/sample/kernel/lms/It_los_lms_024.c
Normal 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 "osTest.h"
|
||||
#include "It_los_lms.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
CHAR *string = "LMS_TestCase";
|
||||
CHAR *src;
|
||||
CHAR *buf;
|
||||
CHAR *str;
|
||||
UINT32 ret;
|
||||
src = LOS_MemAlloc(g_testLmsPool, strlen(string));
|
||||
ICUNIT_ASSERT_NOT_EQUAL(src, NULL, src);
|
||||
(VOID)__memset(src, 0, strlen(string));
|
||||
|
||||
PRINTK("%d\n", __LINE__);
|
||||
str = __strcpy(src, string);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(str, NULL, str);
|
||||
PRINTK("%d\n", __LINE__);
|
||||
|
||||
buf = LOS_MemAlloc(g_testLmsPool, 8); /* mem size 8 */
|
||||
ICUNIT_ASSERT_NOT_EQUAL(buf, NULL, buf);
|
||||
buf[7] = '\0'; /* end index 7 */
|
||||
PRINTK("%d\n", __LINE__);
|
||||
ret = strcpy_s(buf, 100, src); /* Check LMS detection information when the strcpy_s dest max set 100 overflows. */
|
||||
PRINTK("%d\n", __LINE__);
|
||||
|
||||
ret = LOS_MemFree(g_testLmsPool, buf);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
|
||||
ret = LOS_MemFree(g_testLmsPool, src);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(ret, LOS_NOK, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* LmsTestStrcpy_sOverflow */
|
||||
VOID ItLosLms024(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLms024", TestCase, TEST_LOS, TEST_LMS, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
@@ -130,6 +130,10 @@ void TestKernel(void)
|
||||
ItSuiteLosDynlink();
|
||||
#endif
|
||||
|
||||
#if (LOS_KERNEL_LMS_TEST == 1)
|
||||
ItSuiteLosLms();
|
||||
#endif
|
||||
|
||||
#if (LOS_KERNEL_PM_TEST == 1)
|
||||
ItSuiteLosPm();
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user