add l0 testsuits
Change-Id: I523269c97053f484d5cb0d94397269e41eaae86c
This commit is contained in:
50
testsuits/sample/kernel/mem/BUILD.gn
Normal file
50
testsuits/sample/kernel/mem/BUILD.gn
Normal file
@@ -0,0 +1,50 @@
|
||||
# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||
|
||||
static_library("test_mem") {
|
||||
|
||||
sources = [
|
||||
"It_los_list_001.c",
|
||||
"It_los_mem_001.c",
|
||||
"It_los_mem_002.c",
|
||||
"It_los_mem_003.c",
|
||||
"It_los_mem_004.c",
|
||||
"It_los_mem_005.c",
|
||||
"It_los_mem_006.c",
|
||||
"It_los_mem_007.c",
|
||||
"It_los_mem_008.c",
|
||||
"It_los_mem_009.c",
|
||||
"It_los_mem_010.c",
|
||||
"It_los_mem_011.c",
|
||||
"It_los_mem_012.c",
|
||||
"It_los_mem_013.c",
|
||||
"It_los_mem_014.c",
|
||||
"It_los_mem_015.c",
|
||||
"It_los_mem_016.c",
|
||||
"It_los_mem_017.c",
|
||||
"It_los_mem_018.c",
|
||||
"It_los_mem_019.c",
|
||||
"It_los_mem_020.c",
|
||||
"It_los_mem_035.c",
|
||||
"It_los_mem_036.c",
|
||||
"It_los_mem_037.c",
|
||||
"It_los_mem_038.c",
|
||||
"It_los_mem_040.c",
|
||||
"It_los_mem_045.c",
|
||||
"it_los_mem.c",
|
||||
"It_los_tick_001.c",
|
||||
"LLT_los_tick_001.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"It_los_mem.h",
|
||||
"../../../include/",
|
||||
"//kernel/liteos_m/kernel/include",
|
||||
"//kernel/liteos_m/kernel/base/include",
|
||||
"//build/compiler/arm-none-eabi/linux/arm-none-eabi/include",
|
||||
"//build/compiler/arm-none-eabi/linux/lib/gcc/arm-none-eabi/5.4.1/include/",
|
||||
"//build/compiler/arm-none-eabi/linux/lib/gcc/arm-none-eabi/5.4.1/include-fixed/",
|
||||
"//kernel/liteos_m/arch/arm/cortex-m/include",
|
||||
"//kernel/liteos_m/components/cmsis",
|
||||
"//vendor/huawei/watchgt/devkit/hal/include",
|
||||
]
|
||||
}
|
||||
202
testsuits/sample/kernel/mem/It_los_mem.h
Normal file
202
testsuits/sample/kernel/mem/It_los_mem.h
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* 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_MEM_H
|
||||
#define IT_LOS_MEM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#include "osTest.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_config.h"
|
||||
#include "iCunit.h"
|
||||
#include "math.h"
|
||||
|
||||
#define OS_MEM_WATERLINE YES
|
||||
|
||||
#ifdef OS_MEM_WATERLINE
|
||||
#define TEST_MEM_MINIUSE (LOS_DLNK_HEAD_SIZE + LOS_DLNK_NODE_HEAD_SIZE + sizeof(LOS_MEM_POOL_INFO))
|
||||
#endif
|
||||
|
||||
#define TEST_MEM_SIZE 0x2000
|
||||
|
||||
#define IS_ALIGNED_SIZE(value, alignSize) (0 == ((UINT32)(value) & (UINT32)((alignSize) - 1)))
|
||||
|
||||
#define TEST_POOL_SIZE (1 * 8 * 1024)
|
||||
|
||||
#define RANDOM(x) (rand() % (x))
|
||||
|
||||
#define LOS_INIT_MEM LOS_MemInit
|
||||
#define LOS_ALLOC_MEM LOS_MemAlloc
|
||||
#define LOS_REALLOC_MEM LOS_MemRealloc
|
||||
#define LOS_FREE_MEM LOS_MemFree
|
||||
|
||||
/* Supposing a Second Level Index: SLI = 3. */
|
||||
#define OS_MEM_SLI 3
|
||||
/* Giving 1 free list for each small bucket: 4, 8, 12, up to 124. */
|
||||
#define OS_MEM_SMALL_BUCKET_COUNT 31
|
||||
#define OS_MEM_SMALL_BUCKET_MAX_SIZE 128
|
||||
/* Giving OS_MEM_FREE_LIST_NUM free lists for each large bucket. */
|
||||
#define OS_MEM_LARGE_BUCKET_COUNT 24
|
||||
#define OS_MEM_FREE_LIST_NUM (1 << OS_MEM_SLI)
|
||||
/* OS_MEM_SMALL_BUCKET_MAX_SIZE to the power of 2 is 7. */
|
||||
#define OS_MEM_LARGE_START_BUCKET 7
|
||||
|
||||
/* The count of free list. */
|
||||
#define OS_MEM_FREE_LIST_COUNT (OS_MEM_SMALL_BUCKET_COUNT + (OS_MEM_LARGE_BUCKET_COUNT << OS_MEM_SLI))
|
||||
/* The bitmap is used to indicate whether the free list is empty, 1: not empty, 0: empty. */
|
||||
#define OS_MEM_BITMAP_WORDS ((OS_MEM_FREE_LIST_COUNT >> 5) + 1)
|
||||
|
||||
struct TestMemNodeHead {
|
||||
#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1)
|
||||
UINT32 magic;
|
||||
#endif
|
||||
#if (LOSCFG_MEM_LEAKCHECK == 1)
|
||||
UINTPTR linkReg[LOS_RECORD_LR_CNT];
|
||||
#endif
|
||||
union {
|
||||
struct TestMemNodeHead *prev; /* The prev is used for current node points to the previous node */
|
||||
struct TestMemNodeHead *next; /* The next is used for sentinel node points to the expand node */
|
||||
} ptr;
|
||||
#if (LOSCFG_MEM_FREE_BY_TASKID == 1)
|
||||
UINT32 taskID : 6;
|
||||
UINT32 sizeAndFlag : 26;
|
||||
#else
|
||||
UINT32 sizeAndFlag;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct TestMemUsedNodeHead {
|
||||
struct TestMemNodeHead header;
|
||||
};
|
||||
|
||||
struct TestMemFreeNodeHead {
|
||||
struct TestMemNodeHead header;
|
||||
struct TestMemFreeNodeHead *prev;
|
||||
struct TestMemFreeNodeHead *next;
|
||||
};
|
||||
|
||||
struct TestMemPoolInfo {
|
||||
VOID *pool;
|
||||
UINT32 totalSize;
|
||||
UINT32 attr;
|
||||
#if (LOSCFG_MEM_WATERLINE == 1)
|
||||
UINT32 waterLine; /* Maximum usage size in a memory pool */
|
||||
UINT32 curUsedSize; /* Current usage size in a memory pool */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct TestMemPoolHead {
|
||||
struct TestMemPoolInfo info;
|
||||
UINT32 freeListBitmap[OS_MEM_BITMAP_WORDS];
|
||||
struct TestMemFreeNodeHead *freeList[OS_MEM_FREE_LIST_COUNT];
|
||||
#if (LOSCFG_MEM_MUL_POOL == 1)
|
||||
VOID *nextPool;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define LOS_MEM_NODE_HEAD_SIZE sizeof(struct TestMemUsedNodeHead)
|
||||
#define MIN_MEM_POOL_SIZE (LOS_MEM_NODE_HEAD_SIZE + sizeof(struct TestMemPoolHead))
|
||||
#define LOS_MEM_POOL_SIZE sizeof(struct TestMemPoolHead)
|
||||
|
||||
extern void *g_memPool;
|
||||
extern void *g_testPool;
|
||||
|
||||
extern void MemStart(void);
|
||||
extern void MemEnd(void);
|
||||
extern void MemInit(void);
|
||||
extern void MemFree(void);
|
||||
extern UINT32 MemGetFreeSize(void *pool);
|
||||
extern UINT32 CalPow(UINT32 exp);
|
||||
|
||||
VOID ItLosMem001(void);
|
||||
VOID ItLosMem002(void);
|
||||
VOID ItLosMem003(void);
|
||||
VOID ItLosMem004(void);
|
||||
VOID ItLosMem005(void);
|
||||
VOID ItLosMem006(void);
|
||||
VOID ItLosMem007(void);
|
||||
VOID ItLosMem008(void);
|
||||
VOID ItLosMem009(void);
|
||||
VOID ItLosMem010(void);
|
||||
VOID ItLosMem011(void);
|
||||
VOID ItLosMem012(void);
|
||||
VOID ItLosMem013(void);
|
||||
VOID ItLosMem014(void);
|
||||
VOID ItLosMem015(void);
|
||||
VOID ItLosMem016(void);
|
||||
VOID ItLosMem017(void);
|
||||
VOID ItLosMem018(void);
|
||||
VOID ItLosMem019(void);
|
||||
VOID ItLosMem020(void);
|
||||
VOID ItLosMem021(void);
|
||||
VOID ItLosMem022(void);
|
||||
VOID ItLosMem023(void);
|
||||
VOID ItLosMem024(void);
|
||||
VOID ItLosMem025(void);
|
||||
VOID ItLosMem026(void);
|
||||
VOID ItLosMem027(void);
|
||||
VOID ItLosMem028(void);
|
||||
VOID ItLosMem029(void);
|
||||
VOID ItLosMem030(void);
|
||||
VOID ItLosMem031(void);
|
||||
VOID ItLosMem032(void);
|
||||
VOID ItLosMem033(void);
|
||||
VOID ItLosMem035(void);
|
||||
VOID ItLosMem036(void);
|
||||
VOID ItLosMem037(void);
|
||||
VOID ItLosMem038(void);
|
||||
VOID ItLosMem039(void);
|
||||
VOID ItLosMem040(void);
|
||||
VOID ItLosMem041(void);
|
||||
VOID ItLosMem042(void);
|
||||
VOID ItLosMem043(void);
|
||||
VOID ItLosMem044(void);
|
||||
VOID ItLosMem045(void);
|
||||
VOID ItLosMem046(void);
|
||||
VOID ItLosMem047(void);
|
||||
VOID ItLosMem058(void);
|
||||
VOID ItLosMem063(void);
|
||||
VOID ItLosMem064(void);
|
||||
VOID ItLosMem065(void);
|
||||
VOID ItLosTick001(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#endif /* IT_LOS_MEM_H */
|
||||
68
testsuits/sample/kernel/mem/It_los_mem_001.c
Normal file
68
testsuits/sample/kernel/mem/It_los_mem_001.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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size;
|
||||
void *p = NULL;
|
||||
|
||||
size = 0x100;
|
||||
p = LOS_MemAlloc((void *)LOSCFG_SYS_HEAP_ADDR, size);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
|
||||
|
||||
(void)memset_s(p, size, 1, size);
|
||||
|
||||
ret = LOS_MemFree((void *)LOSCFG_SYS_HEAP_ADDR, p);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, 0);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem001(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem001", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
70
testsuits/sample/kernel/mem/It_los_mem_002.c
Normal file
70
testsuits/sample/kernel/mem/It_los_mem_002.c
Normal 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 "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size;
|
||||
void *p = NULL;
|
||||
|
||||
MemStart();
|
||||
|
||||
size = 0;
|
||||
p = LOS_MemAlloc((void *)LOSCFG_SYS_HEAP_ADDR, size);
|
||||
ICUNIT_ASSERT_EQUAL(p, NULL, p);
|
||||
|
||||
size = 0xffffffff;
|
||||
p = LOS_MemAlloc((void *)LOSCFG_SYS_HEAP_ADDR, size);
|
||||
ICUNIT_ASSERT_EQUAL(p, NULL, p);
|
||||
|
||||
MemEnd();
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem002(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem002", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
66
testsuits/sample/kernel/mem/It_los_mem_003.c
Normal file
66
testsuits/sample/kernel/mem/It_los_mem_003.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size;
|
||||
void *p = NULL;
|
||||
|
||||
size = 0x1;
|
||||
p = LOS_MemAlloc((void *)LOSCFG_SYS_HEAP_ADDR, size);
|
||||
ICUNIT_ASSERT_NOT_EQUAL(p, NULL, 0);
|
||||
|
||||
ret = LOS_MemFree((void *)LOSCFG_SYS_HEAP_ADDR, p);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, 0);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem003(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem003", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
63
testsuits/sample/kernel/mem/It_los_mem_004.c
Normal file
63
testsuits/sample/kernel/mem/It_los_mem_004.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
ret = LOS_MemInit(NULL, TEST_MEM_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, OS_ERROR, ret);
|
||||
|
||||
ret = LOS_MemInit(g_memPool, MIN_MEM_POOL_SIZE - 1);
|
||||
ICUNIT_ASSERT_EQUAL(ret, OS_ERROR, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem004(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem004", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
70
testsuits/sample/kernel/mem/It_los_mem_005.c
Normal file
70
testsuits/sample/kernel/mem/It_los_mem_005.c
Normal 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 "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
void *pool = NULL;
|
||||
UINT32 ret;
|
||||
ret = LOS_MemInit(g_memPool, TEST_MEM_SIZE);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
pool = (void *)((UINT32)(UINTPTR)g_memPool + MIN_DLNK_POOL_SIZE - LOS_DLNK_NODE_HEAD_SIZE);
|
||||
|
||||
ret = LOS_MemInit(pool, MIN_DLNK_POOL_SIZE + 1000); // 1000, Initialize the appropriate memory pool space。
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = LOS_MemDeInit(pool);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_MemDeInit(g_memPool);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem005(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem005", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
78
testsuits/sample/kernel/mem/It_los_mem_006.c
Normal file
78
testsuits/sample/kernel/mem/It_los_mem_006.c
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.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size;
|
||||
void *p0 = NULL;
|
||||
|
||||
MemInit();
|
||||
|
||||
size = 0x400;
|
||||
while (1) {
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
if (p0 == NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, 0, EXIT);
|
||||
}
|
||||
|
||||
size = size;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, NULL, p0, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem006(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem006", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
89
testsuits/sample/kernel/mem/It_los_mem_007.c
Normal file
89
testsuits/sample/kernel/mem/It_los_mem_007.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size = 0x500;
|
||||
|
||||
void *p[(TEST_MEM_SIZE) / 0x500] = {NULL};
|
||||
void *p0 = NULL;
|
||||
int i = 0;
|
||||
int j;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[0]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, p[0], 0, EXIT);
|
||||
|
||||
for (j = 0; j > i - 1; j++) {
|
||||
ret = LOS_MemFree(g_memPool, p[j]);
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem007(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem007", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
85
testsuits/sample/kernel/mem/It_los_mem_008.c
Normal file
85
testsuits/sample/kernel/mem/It_los_mem_008.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size = 0x500;
|
||||
|
||||
void *p[(TEST_MEM_SIZE) / 0x500] = {NULL};
|
||||
void *p0 = NULL;
|
||||
int i = 0;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[i / 2]); // 2, release a memory node.
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
// 2, assert the point to new node is equal to the one has been released
|
||||
ICUNIT_GOTO_EQUAL(p0, p[i / 2], p0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem008(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem008", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
84
testsuits/sample/kernel/mem/It_los_mem_009.c
Normal file
84
testsuits/sample/kernel/mem/It_los_mem_009.c
Normal 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 "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size = 0x500;
|
||||
|
||||
void *p[(TEST_MEM_SIZE) / 0x500] = {NULL};
|
||||
void *p0 = NULL;
|
||||
int i = 0;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[i - 1]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, p[i - 1], 0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[i - 1]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem009(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem009", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
88
testsuits/sample/kernel/mem/It_los_mem_010.c
Normal file
88
testsuits/sample/kernel/mem/It_los_mem_010.c
Normal 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 "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define LOOP_NUM 2
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size;
|
||||
|
||||
void *p[LOOP_NUM] = {NULL};
|
||||
void *d[LOOP_NUM] = {NULL};
|
||||
void *p0 = NULL;
|
||||
int i;
|
||||
|
||||
MemInit();
|
||||
|
||||
size = 0x300;
|
||||
for (i = 0; i < LOOP_NUM; i++) {
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, 0, EXIT);
|
||||
p[i] = p0;
|
||||
}
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[0]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
size = 0x150;
|
||||
for (i = 0; i < LOOP_NUM; i++) {
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, 0, EXIT);
|
||||
d[i] = p0;
|
||||
}
|
||||
if (!((UINT32)(UINTPTR)g_memPool < (UINT32)(UINTPTR)d[0] < (UINT32)(UINTPTR)d[1] < (UINT32)(UINTPTR)p[1]))
|
||||
ICUNIT_GOTO_EQUAL(1, 0, 0, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem010(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem010", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
77
testsuits/sample/kernel/mem/It_los_mem_011.c
Normal file
77
testsuits/sample/kernel/mem/It_los_mem_011.c
Normal 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 "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
void *p0 = NULL;
|
||||
|
||||
MemInit();
|
||||
|
||||
ret = LOS_MemFree(NULL, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
p0 = (void *)((char *)g_memPool - 4); // 4, Get an illegal memory node address.
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
p0 = (void *)((char *)g_memPool + TEST_MEM_SIZE + 4); // 4, Get an illegal memory node address.
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem011(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem011", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
74
testsuits/sample/kernel/mem/It_los_mem_012.c
Normal file
74
testsuits/sample/kernel/mem/It_los_mem_012.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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size;
|
||||
|
||||
void *p0 = NULL;
|
||||
|
||||
MemInit();
|
||||
|
||||
size = 0x1000;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, p0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem012(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem012", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
89
testsuits/sample/kernel/mem/It_los_mem_013.c
Normal file
89
testsuits/sample/kernel/mem/It_los_mem_013.c
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size;
|
||||
|
||||
void *p0 = NULL;
|
||||
|
||||
MemInit();
|
||||
|
||||
size = 0x1000;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, 0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, (void *)((char *)p0 + 16)); // 16, Get an illegal memory node address.
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, (void *)((char *)p0 + 16)); // 16, Get an illegal memory node address.
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, 0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, (void *)((char *)p0 - 16)); // 16, Get an illegal memory node address.
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, (void *)((char *)p0 - 16)); // 16, Get an illegal memory node address.
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem013(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem013", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
103
testsuits/sample/kernel/mem/It_los_mem_014.c
Normal file
103
testsuits/sample/kernel/mem/It_los_mem_014.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size = 0x500;
|
||||
|
||||
void *p[(TEST_MEM_SIZE) / 0x500] = {NULL};
|
||||
void *p0 = NULL;
|
||||
int i = 0;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
size = size * 2; // 2, Set new size to twice the previous one.
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, NULL, p0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[0]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[1]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, p[0], p0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[2]); // 2, release the secend node.
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[3]); // 3, release the third node.
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, p[2], p0, EXIT); // 2, assert the adderess of new node is same as the released one.
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[0]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[2]); // 2, release the new node .
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem014(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem014", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
94
testsuits/sample/kernel/mem/It_los_mem_015.c
Normal file
94
testsuits/sample/kernel/mem/It_los_mem_015.c
Normal 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 "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size = 0x500;
|
||||
|
||||
void *p[(TEST_MEM_SIZE) / 0x500] = {NULL};
|
||||
void *p0 = NULL;
|
||||
int i = 0;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[0]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[2]); // 2, release the secend node.
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
size = size * 3; // 3, Set new size to 3 times the previous one.
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, NULL, p0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[1]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, p[0], p0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem015(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem015", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
70
testsuits/sample/kernel/mem/It_los_mem_016.c
Normal file
70
testsuits/sample/kernel/mem/It_los_mem_016.c
Normal 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 "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size;
|
||||
void *p0 = NULL;
|
||||
|
||||
MemInit();
|
||||
|
||||
size = 0x500;
|
||||
p0 = LOS_MemRealloc(g_memPool, NULL, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, p0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem016(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem016", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
85
testsuits/sample/kernel/mem/It_los_mem_017.c
Normal file
85
testsuits/sample/kernel/mem/It_los_mem_017.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size;
|
||||
void *p0 = NULL;
|
||||
void *p[2] = {NULL};
|
||||
|
||||
MemInit();
|
||||
|
||||
size = 0x500;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, p0, EXIT);
|
||||
p[0] = p0;
|
||||
|
||||
size = 0;
|
||||
p0 = LOS_MemRealloc(g_memPool, p0, size);
|
||||
ICUNIT_GOTO_EQUAL(p0, NULL, p0, EXIT);
|
||||
|
||||
size = 0x500;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, p0, EXIT);
|
||||
p[1] = p0;
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
if (p[0] != p[1]) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, 0, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem017(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem017", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
84
testsuits/sample/kernel/mem/It_los_mem_018.c
Normal file
84
testsuits/sample/kernel/mem/It_los_mem_018.c
Normal 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 "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size = 0x500;
|
||||
void *p0 = NULL;
|
||||
void *f0 = NULL;
|
||||
void *p[(TEST_MEM_SIZE) / 0x500] = {NULL};
|
||||
int i = 0;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
p0 = LOS_MemRealloc(g_memPool, p[0], size / 2); // 2, The reallocated memory size is half of its previous size.
|
||||
ICUNIT_GOTO_EQUAL(p0, p[0], p0, EXIT);
|
||||
|
||||
f0 = LOS_MemAlloc(g_memPool, size / 4); // 4, The reallocated memory size is a quarter of its previous size.
|
||||
ICUNIT_GOTO_NOT_EQUAL(f0, NULL, f0, EXIT);
|
||||
|
||||
if (!((UINT32)(UINTPTR)p[0] < (UINT32)(UINTPTR)f0 < (UINT32)(UINTPTR)p[1])) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, 0, EXIT);
|
||||
}
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem018(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem018", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
76
testsuits/sample/kernel/mem/It_los_mem_019.c
Normal file
76
testsuits/sample/kernel/mem/It_los_mem_019.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 size = 0x500;
|
||||
void *p0 = NULL;
|
||||
void *p[(TEST_MEM_SIZE) / 0x500] = {NULL};
|
||||
int i = 0;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
p0 = LOS_MemRealloc(g_memPool, p[0], size);
|
||||
ICUNIT_GOTO_EQUAL(p0, p[0], p0, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem019(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem019", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
85
testsuits/sample/kernel/mem/It_los_mem_020.c
Normal file
85
testsuits/sample/kernel/mem/It_los_mem_020.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "osTest.h"
|
||||
#include "It_los_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size = 0x500;
|
||||
void *p0 = NULL;
|
||||
void *p[(TEST_MEM_SIZE) / 0x500] = {NULL};
|
||||
int i = 0;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= size + LOS_MEM_NODE_HEAD_SIZE + LOS_MEM_POOL_SIZE) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
// 1.5, The reallocated memory size is 1.5 times of its previous size.
|
||||
p0 = LOS_MemRealloc(g_memPool, p[0], (UINT32)(size * 1.5));
|
||||
ICUNIT_GOTO_EQUAL(p0, NULL, p0, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, p[1]);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
// 1.5, The reallocated memory size is 1.5 times of its previous size.
|
||||
p0 = LOS_MemRealloc(g_memPool, p[0], (UINT32)(size * 1.5));
|
||||
ICUNIT_GOTO_EQUAL(p0, p[0], p0, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem020(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem020", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
138
testsuits/sample/kernel/mem/It_los_mem_035.c
Normal file
138
testsuits/sample/kernel/mem/It_los_mem_035.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define LOOP_NUM 10
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
void *p0 = NULL;
|
||||
void *f0 = NULL;
|
||||
UINT32 size;
|
||||
int count;
|
||||
int i, j;
|
||||
|
||||
MemInit();
|
||||
|
||||
size = 0x8;
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size), f0 = p0, i = 0; p0 != NULL; i++) {
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_DLNK_NODE_HEAD_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
f0 = (void *)((char *)f0 + ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE));
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size), i = 0; p0 != NULL; i++) {
|
||||
f0 = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_DLNK_NODE_HEAD_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
f0 = (void *)((char *)f0 - ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE));
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size), f0 = p0, i = 0; p0 != NULL; i++) {
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_DLNK_NODE_HEAD_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
p0 = f0;
|
||||
for (j = 0; j < i; j++) {
|
||||
if (!(j % 2)) { // 2, judge j is even number or not.
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
f0 = (void *)((char *)f0 + 2 * ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE)); // 2, set new size.
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
f0 = (void *)((char *)p0 + ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE));
|
||||
for (j = 0; j < i; j++) {
|
||||
if (j % 2) { // 2, judge j is odd number or not.
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
f0 = (void *)((char *)f0 + 2 * ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE)); // 2, set new size.
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem035(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem035", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL3, TEST_PRESSURE);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
211
testsuits/sample/kernel/mem/It_los_mem_036.c
Normal file
211
testsuits/sample/kernel/mem/It_los_mem_036.c
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define LOOP_NUM 500
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
void *p0 = NULL;
|
||||
void *f0 = NULL;
|
||||
UINT32 size;
|
||||
int count;
|
||||
int i, j, k;
|
||||
int sizeadd;
|
||||
|
||||
MemInit();
|
||||
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
i = 0;
|
||||
sizeadd = 4; // 4, init sizeadd.
|
||||
size = 1 << sizeadd;
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size), f0 = p0; p0 != NULL; i++) {
|
||||
if ((sizeadd += 1) == 9) { // 9, the limit of sizeadd.
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
}
|
||||
size = 1 << sizeadd;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_DLNK_NODE_HEAD_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
size = 1 << sizeadd;
|
||||
for (j = 0; j < i; j++) {
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
f0 = (void *)((char *)f0 + ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE));
|
||||
|
||||
if ((sizeadd += 1) == 9) { // 9, the limit of sizeadd.
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
}
|
||||
|
||||
size = 1 << sizeadd;
|
||||
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
i = 0;
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
size = 1 << sizeadd;
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size); p0 != NULL; i++) {
|
||||
f0 = p0;
|
||||
if ((sizeadd += 1) == 9) { // 9, the limit of sizeadd.
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
}
|
||||
size = 1 << sizeadd;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_DLNK_NODE_HEAD_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
if (sizeadd == 4) { // 4, when sizeadd == 4, set 8 to sizeadd.
|
||||
sizeadd = 8; // 8, set 8 to sizeadd.
|
||||
size = 1 << sizeadd;
|
||||
} else {
|
||||
sizeadd--;
|
||||
size = 1 << sizeadd;
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
|
||||
if ((sizeadd -= 1) == 3) { // 3, when (sizeadd -= 1) == 3, set 8 to sizeadd.
|
||||
sizeadd = 8; // 8, set 8 to sizeadd.
|
||||
}
|
||||
|
||||
size = 1 << sizeadd;
|
||||
f0 = (void *)((char *)f0 - ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE));
|
||||
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
i = 0;
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
size = 1 << sizeadd;
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size), f0 = p0; p0 != NULL; i++) {
|
||||
if ((sizeadd += 1) == 9) { // 9, the limit of sizeadd.
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
}
|
||||
size = 1 << sizeadd;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_DLNK_NODE_HEAD_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
p0 = f0;
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
size = 1 << sizeadd;
|
||||
k = 0;
|
||||
for (j = 0; j < i; j++) {
|
||||
if (!(k % 2)) { // 2, judge k is even number or not.
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
}
|
||||
|
||||
f0 = (void *)((char *)f0 + ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE));
|
||||
if ((sizeadd += 1) == 9) { // 9, the limit of sizeadd.
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
}
|
||||
|
||||
size = 1 << sizeadd;
|
||||
|
||||
if ((k += 1) == 5) { // 5, judge k
|
||||
k = 0;
|
||||
}
|
||||
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
|
||||
f0 = p0;
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
size = 1 << sizeadd;
|
||||
k = 0;
|
||||
for (j = 0; j < i; j++) {
|
||||
if ((k % 2)) { // 2, judge k is odd number or not.
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
}
|
||||
|
||||
f0 = (void *)((char *)f0 + ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE));
|
||||
if ((sizeadd += 1) == 9) { // 9, the limit of sizeadd.
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
}
|
||||
|
||||
size = 1 << sizeadd;
|
||||
|
||||
if ((k += 1) == 5) { // 5, judge k
|
||||
k = 0;
|
||||
}
|
||||
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem036(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem036", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL3, TEST_PRESSURE);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
132
testsuits/sample/kernel/mem/It_los_mem_037.c
Normal file
132
testsuits/sample/kernel/mem/It_los_mem_037.c
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define LOOP_NUM 500
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
void *p0 = NULL;
|
||||
void *f0 = NULL;
|
||||
UINT32 size, sizeadd;
|
||||
int count;
|
||||
UINT32 freesize[2] = {0}; // 2, array size.
|
||||
|
||||
MemInit();
|
||||
|
||||
freesize[0] = MemGetFreeSize(g_memPool);
|
||||
|
||||
size = 0x8;
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, count, EXIT);
|
||||
|
||||
f0 = LOS_MemRealloc(g_memPool, p0, size / 2); // 2, The reallocated memory is half of its previous size.
|
||||
ICUNIT_GOTO_NOT_EQUAL(f0, NULL, count, EXIT);
|
||||
|
||||
f0 = LOS_MemRealloc(g_memPool, p0, size * 2); // 2, The reallocated memory is 2 times of its previous size.
|
||||
ICUNIT_GOTO_NOT_EQUAL(f0, NULL, count, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
}
|
||||
|
||||
freesize[1] = MemGetFreeSize(g_memPool);
|
||||
ICUNIT_GOTO_EQUAL(freesize[1], freesize[0], freesize[1], EXIT);
|
||||
|
||||
size = 0x800;
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, count, EXIT);
|
||||
|
||||
f0 = LOS_MemRealloc(g_memPool, p0, size / 2); // 2, The reallocated memory is half of its previous size.
|
||||
ICUNIT_GOTO_NOT_EQUAL(f0, NULL, count, EXIT);
|
||||
|
||||
f0 = LOS_MemRealloc(g_memPool, p0, size * 2); // 2, The reallocated memory is 2 times of its previous size.
|
||||
ICUNIT_GOTO_NOT_EQUAL(f0, NULL, count, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
}
|
||||
|
||||
freesize[1] = MemGetFreeSize(g_memPool);
|
||||
ICUNIT_GOTO_EQUAL(freesize[1], freesize[0], freesize[1], EXIT);
|
||||
|
||||
sizeadd = 4; // 4, set 4 to sizeadd.
|
||||
while (1) {
|
||||
size = 1 << sizeadd;
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p0, NULL, count, EXIT);
|
||||
|
||||
f0 = LOS_MemRealloc(g_memPool, p0, size / 2); // 2, The reallocated memory is half of its previous size.
|
||||
ICUNIT_GOTO_NOT_EQUAL(f0, NULL, count, EXIT);
|
||||
|
||||
f0 = LOS_MemRealloc(g_memPool, p0, size * 2); // 2, The reallocated memory is 2 times of its previous size.
|
||||
ICUNIT_GOTO_NOT_EQUAL(f0, NULL, count, EXIT);
|
||||
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
}
|
||||
|
||||
sizeadd++;
|
||||
if (sizeadd == 9) { // 9, the limit of sizeadd.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
freesize[1] = MemGetFreeSize(g_memPool);
|
||||
ICUNIT_GOTO_EQUAL(freesize[1], freesize[0], freesize[1], EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem037(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem037", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL3, TEST_PRESSURE);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
136
testsuits/sample/kernel/mem/It_los_mem_038.c
Normal file
136
testsuits/sample/kernel/mem/It_los_mem_038.c
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#define LOOP_NUM 500
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
void *p0 = NULL;
|
||||
void* p[TEST_MEM_SIZE / 0X300] = {NULL};
|
||||
void *f0 = NULL;
|
||||
UINT32 size;
|
||||
int count;
|
||||
int i, j;
|
||||
|
||||
MemInit();
|
||||
|
||||
size = 0x300;
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
i = 0;
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size), f0 = p0; p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_DLNK_NODE_HEAD_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
p0 = LOS_MemRealloc(g_memPool, p[j], size / 2); // 2, The reallocated memory is half of its previous size.
|
||||
if (p0 == NULL) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
f0 = (void *)((char *)f0 + ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE));
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (count = 0; count < LOOP_NUM; count++) {
|
||||
i = 0;
|
||||
for (p0 = LOS_MemAlloc(g_memPool, size), f0 = p0; p0 != NULL; i++) {
|
||||
p[i] = p0;
|
||||
p0 = LOS_MemAlloc(g_memPool, size);
|
||||
}
|
||||
|
||||
if (MemGetFreeSize(g_memPool) >= (size + LOS_DLNK_NODE_HEAD_SIZE)) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, i, EXIT);
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
if (j % 2) { // 2, judge j is odd number or not.
|
||||
ret = LOS_MemFree(g_memPool, p[j]);
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j = 0; j < i; j++) {
|
||||
if (!(j % 2)) { // 2, judge j is even number or not.
|
||||
p0 = LOS_MemRealloc(g_memPool, p[j], size * 2);
|
||||
if (p0 == NULL) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < i; j++) {
|
||||
if (!(j % 2)) { // 2, judge j is even number or not.
|
||||
ret = LOS_MemFree(g_memPool, f0);
|
||||
f0 = (void *)((char *)f0 + 2 * ((UINT32)size + LOS_DLNK_NODE_HEAD_SIZE)); // 2, set new size.
|
||||
if (ret != LOS_OK) {
|
||||
ICUNIT_GOTO_EQUAL(1, 0, j, EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem038(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem038", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL3, TEST_PRESSURE);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
96
testsuits/sample/kernel/mem/It_los_mem_040.c
Normal file
96
testsuits/sample/kernel/mem/It_los_mem_040.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 memused0, memused1, memused2, tempsize;
|
||||
UINT32 size = 0x100;
|
||||
void *p = NULL;
|
||||
void *p1 = NULL;
|
||||
|
||||
MemStart();
|
||||
|
||||
MemInit();
|
||||
|
||||
memused2 = memused0 = LOS_MemTotalUsedGet(g_memPool);
|
||||
|
||||
p = LOS_MemAlloc((void *)g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p, NULL, p, EXIT);
|
||||
|
||||
memused1 = LOS_MemTotalUsedGet(g_memPool);
|
||||
|
||||
tempsize = memused1 - memused0;
|
||||
ICUNIT_GOTO_EQUAL(tempsize, size + LOS_MEM_NODE_HEAD_SIZE, tempsize, EXIT);
|
||||
|
||||
memused0 = LOS_MemTotalUsedGet(g_memPool);
|
||||
|
||||
p1 = LOS_MemAlloc((void *)g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p, NULL, p, EXIT);
|
||||
|
||||
memused1 = LOS_MemTotalUsedGet(g_memPool);
|
||||
tempsize = memused1 - memused0;
|
||||
ICUNIT_GOTO_EQUAL(tempsize, size + LOS_MEM_NODE_HEAD_SIZE, tempsize, EXIT);
|
||||
|
||||
ret = LOS_MemFree((void *)g_memPool, p);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree((void *)g_memPool, p1);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
memused1 = LOS_MemTotalUsedGet(g_memPool);
|
||||
ICUNIT_GOTO_EQUAL(memused1, memused2, memused1, EXIT);
|
||||
|
||||
EXIT:
|
||||
MemFree();
|
||||
MemEnd();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem040(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem040", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
80
testsuits/sample/kernel/mem/It_los_mem_045.c
Normal file
80
testsuits/sample/kernel/mem/It_los_mem_045.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
UINT32 size = 0x100;
|
||||
void *p = NULL;
|
||||
|
||||
MemStart();
|
||||
|
||||
MemInit();
|
||||
|
||||
ret = LOS_MemIntegrityCheck(g_memPool);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
p = LOS_MemAlloc((void *)g_memPool, size);
|
||||
ICUNIT_GOTO_NOT_EQUAL(p, NULL, p, EXIT);
|
||||
|
||||
ret = LOS_MemIntegrityCheck(g_memPool);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemFree((void *)g_memPool, p);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
|
||||
ret = LOS_MemIntegrityCheck(g_memPool);
|
||||
ICUNIT_GOTO_EQUAL(ret, LOS_OK, ret, EXIT);
|
||||
EXIT:
|
||||
MemFree();
|
||||
MemEnd();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosMem045(void)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosMem045", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
65
testsuits/sample/kernel/mem/It_los_tick_001.c
Normal file
65
testsuits/sample/kernel/mem/It_los_tick_001.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
|
||||
#include "It_los_mem.h"
|
||||
|
||||
static UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT64 tickcnt1, tickcnt2;
|
||||
UINT32 temp;
|
||||
|
||||
tickcnt1 = LOS_TickCountGet();
|
||||
|
||||
LOS_TaskDelay(30); // 30, set delay time
|
||||
|
||||
tickcnt2 = LOS_TickCountGet();
|
||||
temp = tickcnt2 - tickcnt1;
|
||||
|
||||
ICUNIT_ASSERT_EQUAL(temp, 30, temp); // 30, assert temp is equal to 30.
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosTick001(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosTick001", TestCase, TEST_LOS, TEST_TASK, TEST_LEVEL1, TEST_FUNCTION);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cpluscplus */
|
||||
#endif /* __cpluscplus */
|
||||
110
testsuits/sample/kernel/mem/it_los_mem.c
Normal file
110
testsuits/sample/kernel/mem/it_los_mem.c
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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_mem.h"
|
||||
|
||||
void *g_memPool = NULL;
|
||||
void *g_testPool = NULL;
|
||||
|
||||
void MemStart(void)
|
||||
{
|
||||
g_memPool = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, TEST_MEM_SIZE);
|
||||
g_testPool = LOS_MemAlloc(LOSCFG_SYS_HEAP_ADDR, TEST_POOL_SIZE);
|
||||
|
||||
if ((g_memPool == NULL) || (g_testPool == NULL)) {
|
||||
PRINT_ERR("alloc failed , mem TestCase would be failed!!!!%x !!! %x", g_memPool, g_testPool);
|
||||
}
|
||||
}
|
||||
|
||||
void MemEnd(void)
|
||||
{
|
||||
LOS_MemFree(LOSCFG_SYS_HEAP_ADDR, g_memPool);
|
||||
LOS_MemFree(LOSCFG_SYS_HEAP_ADDR, g_testPool);
|
||||
}
|
||||
|
||||
void MemInit(void)
|
||||
{
|
||||
(void)LOS_MemInit(g_memPool, TEST_MEM_SIZE);
|
||||
}
|
||||
|
||||
void MemFree(void)
|
||||
{
|
||||
(void)memset_s(g_memPool, TEST_MEM_SIZE, 0, TEST_MEM_SIZE);
|
||||
(void)LOS_MemDeInit(g_memPool);
|
||||
}
|
||||
|
||||
UINT32 MemGetFreeSize(void *pool)
|
||||
{
|
||||
return LOS_MemPoolSizeGet(pool) - LOS_MemTotalUsedGet(pool);
|
||||
}
|
||||
|
||||
UINT32 CalPow(UINT32 exp)
|
||||
{
|
||||
UINT32 pw = 1;
|
||||
pw <<= exp;
|
||||
return pw;
|
||||
}
|
||||
|
||||
VOID ItSuiteLosMem(void)
|
||||
{
|
||||
MemStart();
|
||||
|
||||
ItLosMem001();
|
||||
ItLosMem002();
|
||||
ItLosMem003();
|
||||
ItLosMem004();
|
||||
ItLosMem006();
|
||||
ItLosMem007();
|
||||
ItLosMem008();
|
||||
ItLosMem009();
|
||||
ItLosMem010();
|
||||
ItLosMem011();
|
||||
ItLosMem012();
|
||||
ItLosMem013();
|
||||
ItLosMem014();
|
||||
ItLosMem015();
|
||||
ItLosMem016();
|
||||
ItLosMem017();
|
||||
ItLosMem018();
|
||||
ItLosMem019();
|
||||
ItLosMem020();
|
||||
#if (LOSCFG_TEST_MUCH_LOG == 1) // when open this, Too many logs will printed
|
||||
ItLosMem035();
|
||||
ItLosMem036();
|
||||
ItLosMem037();
|
||||
ItLosMem038();
|
||||
#endif
|
||||
ItLosMem040();
|
||||
ItLosMem045();
|
||||
ItLosTick001();
|
||||
|
||||
MemEnd();
|
||||
}
|
||||
Reference in New Issue
Block a user