feat: 低内存资源回收low memory killer
低内存资源回收特性,支持维护可杀低重要任务,当高内存任务申请不到足够内存时,临时释放低重要性的任务来释放内存来满足高内存任务正常运行; 当高内存任务退出运行时,自动恢复被杀的低重要性任务。设计文档归档位置 https://gitee.com/rtos_yuan/lmk/tree/design/ BREAKING CHANGE: 增加低内存资源回收注册相关接口LOS_LmkOpsNodeRegister、LOS_LmkOpsNodeUnregister和内存资源释放和任务恢复接口LOS_LmkTasksKill和LOS_LmkTasksRestore. close #I4ID0M Signed-off-by: kenneth <zhushangyuan@huawei.com>
This commit is contained in:
parent
16259a955e
commit
ab886d848a
15
Kconfig
15
Kconfig
|
@ -352,6 +352,21 @@ config PLATFORM_EXC
|
|||
depends on KERNEL_EXTKERNEL
|
||||
select DEBUG_HOOK
|
||||
|
||||
config KERNEL_LMK
|
||||
bool "Enable Low Memory Killer"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
help
|
||||
Configuration item for low momery killer tailoring.
|
||||
If you wish to build LiteOS with support for low memory killer.
|
||||
|
||||
config KERNEL_LMK_DEBUG
|
||||
bool "Low Memory Killer Debug"
|
||||
default n
|
||||
depends on KERNEL_LMK
|
||||
help
|
||||
Configuration item forlow memory killer debug tailoring.
|
||||
|
||||
######################### config options of trace #########################
|
||||
source "components/trace/Kconfig"
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ group("components") {
|
|||
"dynlink",
|
||||
"exchook",
|
||||
"fs",
|
||||
"lmk",
|
||||
"lms",
|
||||
"net",
|
||||
"power",
|
||||
|
@ -57,6 +58,7 @@ config("public") {
|
|||
"power:public",
|
||||
"shell:public",
|
||||
"trace:public",
|
||||
"lmk:public",
|
||||
"lms:public",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_KERNEL_LMK)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [ "los_lmk.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
* 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 "los_lmk.h"
|
||||
#include "los_interrupt.h"
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
#include "los_debug.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
STATIC LosLmkOps g_losLmkOps;
|
||||
|
||||
STATIC BOOL OsIsLmkOpsNodeRegistered(LosLmkOpsNode *lmkNode)
|
||||
{
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
|
||||
if (LOS_ListEmpty(&g_losLmkOps.lmkOpsList)) {
|
||||
return FALSE;
|
||||
}
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
if (lmkNode == opsNode) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
|
||||
if (lmkNode == NULL) {
|
||||
return LOS_ERRNO_LMK_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (OsIsLmkOpsNodeRegistered(lmkNode)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_LMK_ALREADY_REGISTERED;
|
||||
}
|
||||
if (LOS_ListEmpty(&g_losLmkOps.lmkOpsList)) {
|
||||
LOS_ListHeadInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
// the priority of registered node <= the first node
|
||||
opsNode = LOS_DL_LIST_ENTRY(g_losLmkOps.lmkOpsList.pstNext, LosLmkOpsNode, node);
|
||||
if (lmkNode->priority <= opsNode->priority) {
|
||||
LOS_ListHeadInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
// the priority of registered node > the last node
|
||||
opsNode = LOS_DL_LIST_ENTRY(g_losLmkOps.lmkOpsList.pstPrev, LosLmkOpsNode, node);
|
||||
if (lmkNode->priority >= opsNode->priority) {
|
||||
LOS_ListTailInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
// the priority of registered node > the first node and < the last node
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
if (lmkNode->priority < opsNode->priority) {
|
||||
LOS_ListHeadInsert((&opsNode->node)->pstPrev, &lmkNode->node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmkOpsNodeUnregister(LosLmkOpsNode *lmkNode)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (lmkNode == NULL) {
|
||||
return LOS_ERRNO_LMK_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (LOS_ListEmpty(&g_losLmkOps.lmkOpsList) || !OsIsLmkOpsNodeRegistered(lmkNode)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_LMK_NOT_REGISTERED;
|
||||
}
|
||||
LOS_ListDelete(&lmkNode->node);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmkTasksKill(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
FreeMemByKillingTask freeMem = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
// if tasks already killed, no need to do it again.
|
||||
if (g_losLmkOps.isMemFreed) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_LMK_MEMORY_ALREADY_FREED;
|
||||
} else {
|
||||
g_losLmkOps.isMemFreed = TRUE;
|
||||
}
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
freeMem = opsNode->freeMem;
|
||||
LOS_IntRestore(intSave);
|
||||
if (freeMem != NULL) {
|
||||
ret = freeMem();
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_ERRNO_LMK_FREE_MEMORY_FAILURE;
|
||||
}
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmkTasksRestore(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
RestoreKilledTask restore = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
// if no tasks killed, no need to restore.
|
||||
if (!g_losLmkOps.isMemFreed) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_LMK_RESTORE_NOT_NEEDED;
|
||||
} else {
|
||||
g_losLmkOps.isMemFreed = FALSE;
|
||||
}
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
restore = opsNode->restoreTask;
|
||||
LOS_IntRestore(intSave);
|
||||
if (restore != NULL) {
|
||||
ret = restore();
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE;
|
||||
}
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
VOID LOS_LmkOpsNodeInfoShow(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
PRINTK("Priority: %-4u Free:0x%-8x Restore:0x%-8x\n", opsNode->priority,
|
||||
(UINT32)(UINTPTR)opsNode->freeMem, (UINT32)(UINTPTR)opsNode->restoreTask);
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
#endif
|
||||
|
||||
VOID OsLmkInit(VOID)
|
||||
{
|
||||
g_losLmkOps.isMemFreed = FALSE;
|
||||
LOS_ListInit(&g_losLmkOps.lmkOpsList);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* 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 _LOS_LMK_H
|
||||
#define _LOS_LMK_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_list.h"
|
||||
#include "los_error.h"
|
||||
|
||||
typedef UINT32 (*FreeMemByKillingTask)(VOID);
|
||||
typedef UINT32 (*RestoreKilledTask)(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: Invalid parameter.
|
||||
*
|
||||
* Value: 0x02002101
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_INVALID_PARAMETER LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: LosLmkOpsNode already registered.
|
||||
*
|
||||
* Value: 0x02002102
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_ALREADY_REGISTERED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: LosLmkOpsNode not yet registered.
|
||||
*
|
||||
* Value: 0x02002103
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_NOT_REGISTERED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: Failed to free memory by invoking the registered functions.
|
||||
*
|
||||
* Value: 0x02002104
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_FREE_MEMORY_FAILURE LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: The registered free memory functions have been invoked.
|
||||
*
|
||||
* Value: 0x02002105
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_MEMORY_ALREADY_FREED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: Failed to restore the killed tasks by invoking the registered functions.
|
||||
*
|
||||
* Value: 0x02002106
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: No need to restore when no free memory functions have been invoked.
|
||||
*
|
||||
* Value: 0x02002107
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_RESTORE_NOT_NEEDED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x07)
|
||||
|
||||
typedef struct {
|
||||
UINT32 priority; /**< The priority in the LMK list, the higher priority with a smaller number. */
|
||||
UINT32 (*freeMem)(VOID); /**< Release the memory of tasks in the LMK list. Return LOS_OK for a successful release. */
|
||||
UINT32 (*restoreTask)(VOID); /**< Restore the tasks killed by freeMem(). Return LOS_OK for a successful restore. */
|
||||
LOS_DL_LIST node; /**< LosLmkOpsNode node. */
|
||||
} LosLmkOpsNode;
|
||||
|
||||
typedef struct {
|
||||
LOS_DL_LIST lmkOpsList; /**< The registered LosLmkOpsNode will be inserted in this list. */
|
||||
BOOL isMemFreed; /**< Flag that if LOS_LmkTasksKill has been invoked. */
|
||||
} LosLmkOps;
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Register a low memory killer node.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to register a low memory killer node. A LosLmkOpsNode node
|
||||
* can be registered only once.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param lmkNode [IN] The LosLmkOpsNode node to be registered.
|
||||
*
|
||||
* @retval LOS_OK The LosLmkOpsNode node is registered successfully.
|
||||
* @retval LOS_ERRNO_LMK_INVALID_PARAMETER The paramter is invalid.
|
||||
* @retval LOS_ERRNO_LMK_ALREADY_REGISTERED The LosLmkOpsNode node already registered.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Unregister a low memory killer node.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to unregister a low memory killer node.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param lmkNode [IN] The LosLmkOpsNode node to be registered.
|
||||
*
|
||||
* @retval LOS_OK The LosLmkOpsNode node is unregistered successfully.
|
||||
* @retval LOS_ERRNO_LMK_NOT_REGISTERED The LosLmkOpsNode node is not yet registered.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 LOS_LmkOpsNodeUnregister(LosLmkOpsNode *lmkNode);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Initialize low memory killer framework.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the low memory killer framework.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
VOID OsLmkInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Restore the tasks killed by the task which triggers low memory killer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to restore the tasks killed by the task which triggers low memory killer.
|
||||
* This function will be invoked by the developer as needed.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval LOS_OK All the restore killed tasks functions are invoked successfully.
|
||||
* @retval LOS_ERRNO_LMK_RESTORE_NOT_NEEDED No need to restore since no tasks killed to free memory.
|
||||
* @retval LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE Failed to restore the killed tasks by invoking the registered functions.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 LOS_LmkTasksRestore(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Kill the tasks to release the used memory.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to kill the tasks to release the used memory when low memory killer is triggered.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval LOS_OK All the free memory functions are invoked successfully.
|
||||
* @retval LOS_ERRNO_LMK_MEMORY_ALREADY_FREED The registered free memory functions have been invoked.
|
||||
* @retval LOS_ERRNO_LMK_FREE_MEMORY_FAILURE Failed to free memory by invoking the registered functions.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 LOS_LmkTasksKill(VOID);
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Output the low memory killer node priorities.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to output the low memory killer node priorities.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
VOID LOS_LmkOpsNodeInfoShow(VOID);
|
||||
#endif
|
||||
#endif
|
|
@ -70,6 +70,10 @@
|
|||
#include "los_lms_pri.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
#include "los_lmk.h"
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
Function : LOS_Reboot
|
||||
Description : system exception, die in here, wait for watchdog.
|
||||
|
@ -213,6 +217,10 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
OsLmkInit();
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
OsExcMsgDumpInit();
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,9 @@
|
|||
#ifdef LOSCFG_KERNEL_LMS
|
||||
#include "los_lms_pri.h"
|
||||
#endif
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
#include "los_lmk.h"
|
||||
#endif
|
||||
|
||||
/* Used to cut non-essential functions. */
|
||||
#define OS_MEM_EXPAND_ENABLE 0
|
||||
|
@ -1103,7 +1106,7 @@ STATIC INLINE VOID *OsMemAlloc(struct OsMemPoolHead *pool, UINT32 size, UINT32 i
|
|||
#endif
|
||||
|
||||
UINT32 allocSize = OS_MEM_ALIGN(size + OS_MEM_NODE_HEAD_SIZE, OS_MEM_ALIGN_SIZE);
|
||||
#if OS_MEM_EXPAND_ENABLE
|
||||
#if OS_MEM_EXPAND_ENABLE || (LOSCFG_KERNEL_LMK == 1)
|
||||
retry:
|
||||
#endif
|
||||
allocNode = OsMemFreeNodeGet(pool, allocSize);
|
||||
|
@ -1116,6 +1119,13 @@ retry:
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
UINT32 killRet = LOS_LmkTasksKill();
|
||||
if (killRet == LOS_OK) {
|
||||
goto retry;
|
||||
}
|
||||
#endif
|
||||
PRINT_ERR("---------------------------------------------------"
|
||||
"--------------------------------------------------------\n");
|
||||
MEM_UNLOCK(pool, intSave);
|
||||
|
|
|
@ -72,6 +72,9 @@ group("testsuites") {
|
|||
if (defined(LOSCFG_KERNEL_LMS)) {
|
||||
deps += [ "sample/kernel/lms:test_lms" ]
|
||||
}
|
||||
if (defined(LOSCFG_KERNEL_LMK)) {
|
||||
deps += [ "sample/kernel/lmk:test_lmk" ]
|
||||
}
|
||||
if (!module_switch) {
|
||||
deps = []
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ extern "C" {
|
|||
#define LOS_KERNEL_TICKLESS_TEST 0
|
||||
#define LOS_KERNEL_PM_TEST 1
|
||||
#define LOS_KERNEL_LMS_TEST 0
|
||||
#define LOS_KERNEL_LMK_TEST 0
|
||||
|
||||
#define LITEOS_CMSIS_TEST 0
|
||||
#define LOS_CMSIS2_CORE_TASK_TEST 0
|
||||
|
@ -331,6 +332,7 @@ extern VOID ItSuiteLosMem(void);
|
|||
extern VOID ItSuiteLosDynlink(void);
|
||||
extern VOID ItSuite_Los_FatFs(void);
|
||||
extern VOID ItSuiteLosPm(void);
|
||||
extern VOID ItSuiteLosLmk(void);
|
||||
|
||||
extern VOID ItSuite_Cmsis_Lostask(void);
|
||||
extern VOID ItSuite_Cmsis_Lostask_add(void);
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
# Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
static_library("test_lmk") {
|
||||
sources = [
|
||||
"It_los_lmk.c",
|
||||
"It_los_lmk_001.c",
|
||||
"It_los_lmk_002.c",
|
||||
"It_los_lmk_003.c",
|
||||
"It_los_lmk_004.c",
|
||||
]
|
||||
|
||||
include_dirs = [ "//kernel/liteos_m/components/lmk" ]
|
||||
|
||||
configs += [ "//kernel/liteos_m/testsuites:include" ]
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2021-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_lmk.h"
|
||||
|
||||
VOID ItSuiteLosLmk(VOID)
|
||||
{
|
||||
ItLosLmk001();
|
||||
ItLosLmk002();
|
||||
ItLosLmk003();
|
||||
ItLosLmk004();
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2021-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 "los_lmk.h"
|
||||
|
||||
#ifndef IT_LOS_LMK_H
|
||||
#define IT_LOS_LMK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define LMK_PRIORITY_HIGH 1
|
||||
#define LMK_PRIORITY_MEDIUM 3
|
||||
#define LMK_PRIORITY_LOW 5
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
extern VOID ItLosLmk001(VOID);
|
||||
extern VOID ItLosLmk002(VOID);
|
||||
extern VOID ItLosLmk003(VOID);
|
||||
extern VOID ItLosLmk004(VOID);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* IT_LOS_LMK_H */
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2021-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_lmk.h"
|
||||
#include "los_list.h"
|
||||
|
||||
STATIC UINT32 release(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 restore(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
LosLmkOpsNode firstOpsNode = {
|
||||
.priority = LMK_PRIORITY_LOW,
|
||||
.freeMem = NULL,
|
||||
.restoreTask = restore,
|
||||
};
|
||||
|
||||
LosLmkOpsNode anotherOpsNode = {
|
||||
.priority = LMK_PRIORITY_MEDIUM,
|
||||
.freeMem = release,
|
||||
.restoreTask = restore,
|
||||
};
|
||||
|
||||
LosLmkOpsNode thirdOpsNode = {
|
||||
.priority = LMK_PRIORITY_HIGH,
|
||||
.freeMem = release,
|
||||
.restoreTask = restore,
|
||||
};
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_INVALID_PARAMETER, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_ALREADY_REGISTERED, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_ALREADY_REGISTERED, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_ALREADY_REGISTERED, ret);
|
||||
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosLmk001(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLmk001", TestCase, TEST_LOS, TEST_COMP, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2021-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_lmk.h"
|
||||
#include "los_list.h"
|
||||
|
||||
STATIC UINT32 release(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 restore(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
LosLmkOpsNode firstOpsNode = {
|
||||
.priority = LMK_PRIORITY_LOW,
|
||||
.freeMem = release,
|
||||
.restoreTask = restore,
|
||||
};
|
||||
|
||||
LosLmkOpsNode anotherOpsNode = {
|
||||
.priority = LMK_PRIORITY_MEDIUM,
|
||||
.freeMem = release,
|
||||
.restoreTask = restore,
|
||||
};
|
||||
|
||||
LosLmkOpsNode thirdOpsNode = {
|
||||
.priority = LMK_PRIORITY_HIGH,
|
||||
.freeMem = release,
|
||||
.restoreTask = restore,
|
||||
};
|
||||
|
||||
ret = LOS_LmkOpsNodeUnregister(NULL);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_INVALID_PARAMETER, ret);
|
||||
ret = LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_NOT_REGISTERED, ret);
|
||||
ret = LOS_LmkOpsNodeUnregister(&anotherOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_NOT_REGISTERED, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_NOT_REGISTERED, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeUnregister(&thirdOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosLmk002(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLmk002", TestCase, TEST_LOS, TEST_COMP, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2021-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_lmk.h"
|
||||
#include "los_list.h"
|
||||
|
||||
STATIC UINT32 release_OK(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 release_NOK(VOID)
|
||||
{
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
STATIC UINT32 restore_OK(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 restore_NOK(VOID)
|
||||
{
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
LosLmkOpsNode firstOpsNode = {
|
||||
.priority = LMK_PRIORITY_LOW,
|
||||
.freeMem = release_NOK,
|
||||
.restoreTask = restore_NOK,
|
||||
};
|
||||
|
||||
LosLmkOpsNode anotherOpsNode = {
|
||||
.priority = LMK_PRIORITY_MEDIUM,
|
||||
.freeMem = release_NOK,
|
||||
.restoreTask = restore_NOK,
|
||||
};
|
||||
|
||||
LosLmkOpsNode thirdOpsNode = {
|
||||
.priority = LMK_PRIORITY_HIGH,
|
||||
.freeMem = release_OK,
|
||||
.restoreTask = restore_OK,
|
||||
};
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
ret = LOS_LmkTasksKill();
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_FREE_MEMORY_FAILURE, ret);
|
||||
ret = LOS_LmkTasksRestore();
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE, ret);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkTasksKill();
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_FREE_MEMORY_FAILURE, ret);
|
||||
ret = LOS_LmkTasksKill();
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_MEMORY_ALREADY_FREED, ret);
|
||||
ret = LOS_LmkTasksRestore();
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE, ret);
|
||||
ret = LOS_LmkTasksRestore();
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_ERRNO_LMK_RESTORE_NOT_NEEDED, ret);
|
||||
|
||||
firstOpsNode.freeMem = release_OK;
|
||||
firstOpsNode.restoreTask =restore_OK;
|
||||
anotherOpsNode.freeMem = release_OK;
|
||||
anotherOpsNode.restoreTask =restore_OK;
|
||||
ret = LOS_LmkTasksKill();
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkTasksRestore();
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosLmk003(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLmk003", TestCase, TEST_LOS, TEST_COMP, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 2021-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_lmk.h"
|
||||
#include "los_list.h"
|
||||
|
||||
STATIC UINT32 release_OK_First(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 restore_OK_First(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 release_OK_Another(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 restore_OK_Another(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 release_OK_Third(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 restore_OK_Third(VOID)
|
||||
{
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 TestCase(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
LosLmkOpsNode firstOpsNode = {
|
||||
.priority = LMK_PRIORITY_LOW,
|
||||
.freeMem = release_OK_First,
|
||||
.restoreTask = restore_OK_First,
|
||||
};
|
||||
|
||||
LosLmkOpsNode anotherOpsNode = {
|
||||
.priority = LMK_PRIORITY_MEDIUM,
|
||||
.freeMem = release_OK_Another,
|
||||
.restoreTask = restore_OK_Another,
|
||||
};
|
||||
|
||||
LosLmkOpsNode thirdOpsNode = {
|
||||
.priority = LMK_PRIORITY_HIGH,
|
||||
.freeMem = release_OK_Third,
|
||||
.restoreTask = restore_OK_Third,
|
||||
};
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
(VOID)LOS_LmkOpsNodeInfoShow();
|
||||
#endif
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
(VOID)LOS_LmkOpsNodeInfoShow();
|
||||
#endif
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
|
||||
|
||||
ret = LOS_LmkOpsNodeRegister(&anotherOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeRegister(&thirdOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
ret = LOS_LmkOpsNodeRegister(&firstOpsNode);
|
||||
ICUNIT_ASSERT_EQUAL(ret, LOS_OK, ret);
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
(VOID)LOS_LmkOpsNodeInfoShow();
|
||||
#endif
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&firstOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&anotherOpsNode);
|
||||
(VOID)LOS_LmkOpsNodeUnregister(&thirdOpsNode);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ItLosLmk004(VOID)
|
||||
{
|
||||
TEST_ADD_CASE("ItLosLmk004", TestCase, TEST_LOS, TEST_COMP, TEST_LEVEL0, TEST_FUNCTION);
|
||||
}
|
|
@ -171,6 +171,10 @@ void TestKernel(void)
|
|||
#if (LOS_KERNEL_PM_TEST == 1)
|
||||
ItSuiteLosPm();
|
||||
#endif
|
||||
|
||||
#if (LOS_KERNEL_LMK_TEST == 1)
|
||||
ItSuiteLosLmk();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -200,6 +200,7 @@ enum LOS_MODULE_ID {
|
|||
LOS_MOD_CPUP = 0x1e,
|
||||
LOS_MOD_HOOK = 0x1f,
|
||||
LOS_MOD_PM = 0x20,
|
||||
LOS_MOD_LMK = 0x21,
|
||||
LOS_MOD_SHELL = 0x31,
|
||||
LOS_MOD_BUTT
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue