tests: mem_protect: move partition tests

Some tests only evaluate characteristics of k_mem_partitions.
Move these to a separate C file.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2020-10-22 11:01:08 -07:00 committed by Anas Nashif
parent 44ca58181a
commit 8022aabbe8
2 changed files with 96 additions and 84 deletions

View file

@ -5,7 +5,6 @@
*/
#include "mem_protect.h"
#include <sys/mempool.h>
#include <kernel_internal.h> /* For z_main_thread */
#define ERROR_STR \
@ -35,17 +34,7 @@ static K_APP_BMEM(part1) uint8_t __aligned(MEM_REGION_ALLOC) buf1[MEM_REGION_ALL
static struct k_mem_partition *app1_parts[] = {
&part1
};
K_APPMEM_PARTITION_DEFINE(part_arch);
K_APP_BMEM(part_arch) uint8_t __aligned(MEM_REGION_ALLOC) \
buf_arc[MEM_REGION_ALLOC];
K_APPMEM_PARTITION_DEFINE(part2);
static K_APP_DMEM(part2) int part2_var = 1356;
static K_APP_BMEM(part2) int part2_zeroed_var = 20420;
static K_APP_BMEM(part2) int part2_bss_var;
SYS_MEM_POOL_DEFINE(data_pool, NULL, BLK_SIZE_MIN_MD, BLK_SIZE_MAX_MD,
BLK_NUM_MAX_MD, BLK_ALIGN_MD, K_APP_DMEM_SECTION(part2));
/****************************************************************************/
/* The mem domains needed.*/
@ -652,24 +641,6 @@ void test_mem_part_auto_determ_size(void)
k_mem_domain_add_thread(&domain1, usr_tid0);
}
/**
* @brief Test partitions sized per the constraints of the MPU hardware
*
* @details
* - Test that system automatically determine memory partition size according
* to the constraints of the platform's MPU hardware.
* - Different platforms like x86, ARM and ARC have different MPU hardware for
* memory management.
* - That test checks that MPU hardware works as expected and gives for the
* memory partition the most suitable and possible size.
*
* @ingroup kernel_memprotect_tests
*/
void test_mem_part_auto_determ_size_per_mpu(void)
{
zassert_true(part_arch.size == MEM_REGION_ALLOC, NULL);
}
static void child_thr_handler(void *p1, void *p2, void *p3)
{
ARG_UNUSED(p1);
@ -725,62 +696,7 @@ void test_mem_part_inherit_by_child_thr(void)
k_sem_take(&sync_sem_md, K_FOREVER);
}
/**
* @brief Test system provide means to obtain names of the data and BSS sections
*
* @details
* - Define memory partition and define system memory pool using macros
* SYS_MEM_POOL_DEFINE
* - Section name of the destination binary section for pool data will be
* obtained at build time by macros K_APP_DMEM_SECTION() which obtaines
* a section name.
* - Then to check that system memory pool initialized correctly by allocating
* a block from it and check that it is not NULL.
*
* @ingroup kernel_memprotect_tests
*
* @see K_APP_DMEM_SECTION()
*/
void test_macros_obtain_names_data_bss(void)
{
sys_mem_pool_init(&data_pool);
void *block;
block = sys_mem_pool_alloc(&data_pool, BLK_SIZE_MAX_MD - DESC_SIZE);
zassert_not_null(block, NULL);
}
/**
* @brief Test assigning global data and BSS variables to memory partitions
*
* @details Test that system supports application assigning global data and BSS
* variables using macros K_APP_BMEM() and K_APP_DMEM
*
* @ingroup kernel_memprotect_tests
*/
void test_mem_part_assign_bss_vars_zero(void)
{
uint32_t read_data;
/* The global variable part2_var will be inside the bounds of part2
* and be initialized with 1356 at boot.
*/
read_data = part2_var;
zassert_true(read_data == 1356, NULL);
/* The global variable part2_zeroed_var will be inside the bounds of
* part2 and must be zeroed at boot size K_APP_BMEM() was used,
* indicating a BSS variable.
*/
read_data = part2_zeroed_var;
zassert_true(read_data == 0, NULL);
/* The global variable part2_var will be inside the bounds of
* part2 and must be zeroed at boot size K_APP_BMEM() was used,
* indicating a BSS variable.
*/
read_data = part2_bss_var;
zassert_true(read_data == 0, NULL);
}
static void zzz_entry(void *p1, void *p2, void *p3)
{

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2020 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <sys/mempool.h>
#include "mem_protect.h"
K_APPMEM_PARTITION_DEFINE(part2);
static K_APP_DMEM(part2) int part2_var = 1356;
static K_APP_BMEM(part2) int part2_zeroed_var = 20420;
static K_APP_BMEM(part2) int part2_bss_var;
SYS_MEM_POOL_DEFINE(data_pool, NULL, BLK_SIZE_MIN_MD, BLK_SIZE_MAX_MD,
BLK_NUM_MAX_MD, BLK_ALIGN_MD, K_APP_DMEM_SECTION(part2));
/**
* @brief Test system provide means to obtain names of the data and BSS sections
*
* @details
* - Define memory partition and define system memory pool using macros
* SYS_MEM_POOL_DEFINE
* - Section name of the destination binary section for pool data will be
* obtained at build time by macros K_APP_DMEM_SECTION() which obtaines
* a section name.
* - Then to check that system memory pool initialized correctly by allocating
* a block from it and check that it is not NULL.
*
* @ingroup kernel_memprotect_tests
*
* @see K_APP_DMEM_SECTION()
*/
void test_macros_obtain_names_data_bss(void)
{
sys_mem_pool_init(&data_pool);
void *block;
block = sys_mem_pool_alloc(&data_pool, BLK_SIZE_MAX_MD - DESC_SIZE);
zassert_not_null(block, NULL);
}
/**
* @brief Test assigning global data and BSS variables to memory partitions
*
* @details Test that system supports application assigning global data and BSS
* variables using macros K_APP_BMEM() and K_APP_DMEM
*
* @ingroup kernel_memprotect_tests
*/
void test_mem_part_assign_bss_vars_zero(void)
{
uint32_t read_data;
/* The global variable part2_var will be inside the bounds of part2
* and be initialized with 1356 at boot.
*/
read_data = part2_var;
zassert_true(read_data == 1356, NULL);
/* The global variable part2_zeroed_var will be inside the bounds of
* part2 and must be zeroed at boot size K_APP_BMEM() was used,
* indicating a BSS variable.
*/
read_data = part2_zeroed_var;
zassert_true(read_data == 0, NULL);
/* The global variable part2_var will be inside the bounds of
* part2 and must be zeroed at boot size K_APP_BMEM() was used,
* indicating a BSS variable.
*/
read_data = part2_bss_var;
zassert_true(read_data == 0, NULL);
}
K_APPMEM_PARTITION_DEFINE(part_arch);
K_APP_BMEM(part_arch) uint8_t __aligned(MEM_REGION_ALLOC) \
buf_arc[MEM_REGION_ALLOC];
/**
* @brief Test partitions sized per the constraints of the MPU hardware
*
* @details
* - Test that system automatically determine memory partition size according
* to the constraints of the platform's MPU hardware.
* - Different platforms like x86, ARM and ARC have different MPU hardware for
* memory management.
* - That test checks that MPU hardware works as expected and gives for the
* memory partition the most suitable and possible size.
*
* @ingroup kernel_memprotect_tests
*/
void test_mem_part_auto_determ_size_per_mpu(void)
{
zassert_true(part_arch.size == MEM_REGION_ALLOC, NULL);
}