eec78d9f5d
* [utest/mm] add testcase for create/init format codes of create/init in components/mm * [libcpu/aarch64] fix user stack check routine * [kservice] export API for utest * [utest/mm] testcase for aspace_map format & modify the files under components/mm related with aspace_map * [lwp/user_mm] add user_map_varea for mmap feature * [mm] rename rt_mm_fault_try_fix to rt_aspace_fault_try_fix * [utest/mm] testcase for synchronization * [mm] modify unmap api to improve throughput * [utest/mm] testcases for cache and varea map * [format] remove extra space * [utest/mm] fix testcase problem in header * [lwp] extend map_user_varea with a flag * [utest/mm] testcase for lwp_map_user_varea * [libcpu/arm/cortex-a] fix kernel space layout * [utest/mm] adjust for armv7 arch
117 lines
3.2 KiB
C
117 lines
3.2 KiB
C
/*
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2023-03-27 WangXiaoyao testcase for lwp
|
|
*/
|
|
|
|
#include "common.h"
|
|
#include <lwp.h>
|
|
#include "lwp_arch.h"
|
|
#include "lwp_user_mm.h"
|
|
#include "mm_aspace.h"
|
|
#include "mmu.h"
|
|
|
|
/**
|
|
* @brief user map API
|
|
* rt_varea_t lwp_map_user_varea(struct rt_lwp *lwp, void *map_va, size_t map_size);
|
|
* rt_varea_t lwp_map_user_varea_ext(struct rt_lwp *lwp, void *map_va, size_t map_size, size_t flags);
|
|
*/
|
|
#if 1 /* make it clear to identify the block :) */
|
|
/* for testing on _aspace_traverse */
|
|
static void *_prev_end;
|
|
static size_t _count;
|
|
static int _test_increase(rt_varea_t varea, void *param)
|
|
{
|
|
uassert_true(varea->start >= _prev_end);
|
|
_prev_end = varea->start + varea->size;
|
|
_count += 1;
|
|
return 0;
|
|
}
|
|
#define TEST_VAREA_INSERT(statement, aspace) do {\
|
|
size_t _prev_count; \
|
|
_count = 0; \
|
|
_prev_end = 0; \
|
|
rt_aspace_traversal((aspace), _test_increase, NULL);\
|
|
_prev_count = _count; \
|
|
statement; \
|
|
_count = 0; \
|
|
_prev_end = 0; \
|
|
rt_aspace_traversal((aspace), _test_increase, NULL);\
|
|
uassert_true(_prev_count + 1 == _count); \
|
|
} while (0)
|
|
#endif
|
|
|
|
static void test_user_map_varea(void)
|
|
{
|
|
const size_t buf_sz = ARCH_PAGE_SIZE * 4;
|
|
struct rt_lwp *lwp;
|
|
rt_varea_t varea;
|
|
lwp = lwp_new();
|
|
|
|
uassert_true(!!lwp);
|
|
uassert_true(!lwp_user_space_init(lwp, 0));
|
|
|
|
TEST_VAREA_INSERT(
|
|
varea = lwp_map_user_varea(lwp, 0, buf_sz),
|
|
lwp->aspace);
|
|
uassert_true(!!varea);
|
|
uassert_true(varea->attr == (MMU_MAP_U_RWCB));
|
|
uassert_true(varea->size == buf_sz);
|
|
uassert_true(varea->aspace == lwp->aspace);
|
|
uassert_true(varea->flag == 0);
|
|
uassert_true(varea->start != 0);
|
|
uassert_true(varea->start >= (void *)USER_VADDR_START && varea->start < (void *)USER_VADDR_TOP);
|
|
|
|
uassert_true(!lwp_ref_dec(lwp));
|
|
}
|
|
|
|
static void test_user_map_varea_ext(void)
|
|
{
|
|
const size_t buf_sz = ARCH_PAGE_SIZE * 4;
|
|
struct rt_lwp *lwp;
|
|
rt_varea_t varea;
|
|
lwp = lwp_new();
|
|
|
|
uassert_true(!!lwp);
|
|
uassert_true(!lwp_user_space_init(lwp, 0));
|
|
|
|
TEST_VAREA_INSERT(
|
|
varea = lwp_map_user_varea_ext(lwp, 0, buf_sz, LWP_MAP_FLAG_NOCACHE),
|
|
lwp->aspace);
|
|
uassert_true(!!varea);
|
|
uassert_true(varea->attr == (MMU_MAP_U_RW));
|
|
uassert_true(varea->size == buf_sz);
|
|
uassert_true(varea->aspace == lwp->aspace);
|
|
uassert_true(varea->flag == 0);
|
|
uassert_true(varea->start != 0);
|
|
uassert_true(varea->start >= (void *)USER_VADDR_START && varea->start < (void *)USER_VADDR_TOP);
|
|
|
|
uassert_true(!lwp_ref_dec(lwp));
|
|
}
|
|
|
|
static void user_map_varea_tc(void)
|
|
{
|
|
CONSIST_HEAP(test_user_map_varea());
|
|
CONSIST_HEAP(test_user_map_varea_ext());
|
|
}
|
|
|
|
static rt_err_t utest_tc_init(void)
|
|
{
|
|
return RT_EOK;
|
|
}
|
|
|
|
static rt_err_t utest_tc_cleanup(void)
|
|
{
|
|
return RT_EOK;
|
|
}
|
|
|
|
static void testcase(void)
|
|
{
|
|
UTEST_UNIT_RUN(user_map_varea_tc);
|
|
}
|
|
UTEST_TC_EXPORT(testcase, "testcases.lwp.mm_tc", utest_tc_init, utest_tc_cleanup, 20);
|