-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: demand_paging: add a test for on-demand sections
Exercises linker placement, the ondemand backing store, demand paging. Signed-off-by: Nicolas Pitre <[email protected]>
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
tests/kernel/mem_protect/demand_paging/ondemand_section/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(ondemand_section) | ||
|
||
target_include_directories(app PRIVATE | ||
${ZEPHYR_BASE}/kernel/include | ||
${ZEPHYR_BASE}/arch/${ARCH}/include | ||
) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
6 changes: 6 additions & 0 deletions
6
tests/kernel/mem_protect/demand_paging/ondemand_section/prj.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CONFIG_ZTEST=y | ||
CONFIG_DEMAND_PAGING=y | ||
CONFIG_DEMAND_PAGING_ALLOW_IRQ=y | ||
CONFIG_DEMAND_PAGING_STATS=y | ||
CONFIG_DEMAND_MAPPING=y | ||
CONFIG_LINKER_USE_ONDEMAND_SECTION=y |
62 changes: 62 additions & 0 deletions
62
tests/kernel/mem_protect/demand_paging/ondemand_section/src/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2024 BayLibre SAS | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/ztest.h> | ||
#include <zephyr/kernel/mm.h> | ||
#include <zephyr/kernel/mm/demand_paging.h> | ||
#include <zephyr/linker/sections.h> | ||
#include <mmu.h> | ||
|
||
static const char __ondemand_rodata message[] = "was evicted"; | ||
|
||
static void __ondemand_func evictable_function(void) | ||
{ | ||
static int count; | ||
|
||
printk("This %s code, count=%d\n", message, ++count); | ||
} | ||
|
||
ZTEST(ondemand_section, test_ondemand_basic) | ||
{ | ||
unsigned long faults_before, faults_after; | ||
void *addr = (void *)ROUND_DOWN(&evictable_function, CONFIG_MMU_PAGE_SIZE); | ||
|
||
printk("About to call unpaged code\n"); | ||
faults_before = k_mem_num_pagefaults_get(); | ||
evictable_function(); | ||
faults_after = k_mem_num_pagefaults_get(); | ||
zassert_not_equal(faults_before, faults_after, "should have faulted"); | ||
|
||
printk("Code should be resident on second call\n"); | ||
faults_before = k_mem_num_pagefaults_get(); | ||
evictable_function(); | ||
faults_after = k_mem_num_pagefaults_get(); | ||
zassert_equal(faults_before, faults_after, "should not have faulted"); | ||
|
||
printk("Forcefully evicting it from memory\n"); | ||
zassert_ok(k_mem_page_out(addr, CONFIG_MMU_PAGE_SIZE), ""); | ||
|
||
printk("Calling it again\n"); | ||
faults_before = k_mem_num_pagefaults_get(); | ||
evictable_function(); | ||
faults_after = k_mem_num_pagefaults_get(); | ||
zassert_not_equal(faults_before, faults_after, "should have faulted"); | ||
|
||
printk("Forcefully evicting it from memory again\n"); | ||
zassert_ok(k_mem_page_out(addr, CONFIG_MMU_PAGE_SIZE), ""); | ||
|
||
printk("Preemptively fetching it back in\n"); | ||
/* strangely, k_mem_page_in() returns void */ | ||
k_mem_page_in(addr, CONFIG_MMU_PAGE_SIZE); | ||
|
||
printk("Code should be resident\n"); | ||
faults_before = k_mem_num_pagefaults_get(); | ||
evictable_function(); | ||
faults_after = k_mem_num_pagefaults_get(); | ||
zassert_equal(faults_before, faults_after, "should not have faulted"); | ||
} | ||
|
||
ZTEST_SUITE(ondemand_section, NULL, NULL, NULL, NULL, NULL); |
12 changes: 12 additions & 0 deletions
12
tests/kernel/mem_protect/demand_paging/ondemand_section/testcase.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
common: | ||
tags: | ||
- kernel | ||
- mmu | ||
- demand_paging | ||
tests: | ||
kernel.demand_paging.ondemand_section.arm64_semihost: | ||
platform_allow: | ||
- qemu_cortex_a53 | ||
extra_configs: | ||
- CONFIG_SEMIHOST=y | ||
- CONFIG_BACKING_STORE_ONDEMAND_SEMIHOST=y |