Skip to content

Commit 574b584

Browse files
committed
test: mpu: Add arm_mpu_regions test
A a test for the new DT-configured memory regions. Signed-off-by: Carlo Caione <[email protected]>
1 parent e632f7d commit 574b584

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(arm_mpu_regions)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2021 Carlo Caione <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
/delete-node/ memory@20000000;
9+
10+
sram0: memory@20000000 {
11+
compatible = "mmio-sram";
12+
reg = <0x20000000 0x200000>;
13+
};
14+
15+
sram_cache: memory@20200000 {
16+
compatible = "zephyr,memory-region", "mmio-sram";
17+
reg = <0x20200000 0x100000>;
18+
zephyr,memory-region = "SRAM_CACHE";
19+
zephyr,memory-region-mpu = "RAM";
20+
};
21+
22+
sram_no_cache: memory@20300000 {
23+
compatible = "zephyr,memory-region", "mmio-sram";
24+
reg = <0x20300000 0x100000>;
25+
zephyr,memory-region = "SRAM_NO_CACHE";
26+
zephyr,memory-region-mpu = "RAM_NOCACHE";
27+
};
28+
29+
sram_dtcm_fake: memory@abcdabcd {
30+
compatible = "zephyr,memory-region", "arm,dtcm";
31+
reg = <0xabcdabcd 0x100000>;
32+
zephyr,memory-region = "SRAM_DTCM_FAKE";
33+
zephyr,memory-region-mpu = "RAM";
34+
};
35+
36+
sram_no_mpu: memory@deaddead {
37+
compatible = "zephyr,memory-region", "mmio-sram";
38+
reg = <0xdeaddead 0x100000>;
39+
zephyr,memory-region = "SRAM_NO_MPU";
40+
};
41+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ZTEST=y
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2021 Carlo Caione <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <linker/linker-defs.h>
9+
#include <sys/slist.h>
10+
#include <arch/arm/aarch32/mpu/arm_mpu.h>
11+
#include <ztest.h>
12+
#include <string.h>
13+
14+
extern const struct arm_mpu_config mpu_config;
15+
16+
static arm_mpu_region_attr_t cacheable = REGION_RAM_ATTR(REGION_1M);
17+
static arm_mpu_region_attr_t noncacheable = REGION_RAM_NOCACHE_ATTR(REGION_1M);
18+
19+
static void test_regions(void)
20+
{
21+
int cnt = 0;
22+
23+
for (size_t i = 0; i < mpu_config.num_regions; i++) {
24+
const struct arm_mpu_region *r = &mpu_config.mpu_regions[i];
25+
26+
if (!strcmp(r->name, "SRAM_CACHE")) {
27+
zassert_equal(r->base, 0x20200000, "Wrong base");
28+
zassert_equal(r->attr.rasr, cacheable.rasr,
29+
"Wrong attr for SRAM_CACHE");
30+
cnt++;
31+
} else if (!strcmp(r->name, "SRAM_NO_CACHE")) {
32+
zassert_equal(r->base, 0x20300000, "Wrong base");
33+
zassert_equal(r->attr.rasr, noncacheable.rasr,
34+
"Wrong attr for SRAM_NO_CACHE");
35+
cnt++;
36+
} else if (!strcmp(r->name, "SRAM_DTCM_FAKE")) {
37+
zassert_equal(r->base, 0xabcdabcd, "Wrong base");
38+
zassert_equal(r->attr.rasr, cacheable.rasr,
39+
"Wrong attr for SRAM_DTCM_FAKE");
40+
cnt++;
41+
}
42+
}
43+
44+
if (cnt != 3) {
45+
/*
46+
* SRAM0 and SRAM_NO_MPU should not create any MPU region.
47+
* Check that.
48+
*/
49+
ztest_test_fail();
50+
}
51+
}
52+
53+
void test_main(void)
54+
{
55+
ztest_test_suite(test_c_arm_mpu_regions,
56+
ztest_unit_test(test_regions)
57+
);
58+
59+
ztest_run_test_suite(test_c_arm_mpu_regions);
60+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
tests:
2+
misc.arm_mpu_regions:
3+
platform_allow: mps2_an385
4+
tags: sample board sram mpu

0 commit comments

Comments
 (0)