1 /*
2 * Copyright (c) 2022, Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/ztest.h>
8 #include <zephyr/devicetree.h>
9 #include <zephyr/device.h>
10
11 #include <zephyr/linker/devicetree_regions.h>
12
13 #define TEST_SRAM_NODE DT_NODELABEL(test_sram)
14 #define TEST_SRAM_SECT LINKER_DT_NODE_REGION_NAME(TEST_SRAM_NODE)
15 #define TEST_SRAM_ADDR DT_REG_ADDR(TEST_SRAM_NODE)
16 #define TEST_SRAM_SIZE DT_REG_SIZE(TEST_SRAM_NODE)
17
18 uint8_t var_in_test_sram[TEST_SRAM_SIZE] Z_GENERIC_SECTION(TEST_SRAM_SECT);
19
20 extern char __SRAM_REGION_start[];
21 extern char __SRAM_REGION_end[];
22 extern char __SRAM_REGION_size[];
23 extern char __SRAM_REGION_load_start[];
24
ZTEST(devicetree_memory_region,test_memory_region)25 ZTEST(devicetree_memory_region, test_memory_region)
26 {
27 zassert_true(!strcmp(LINKER_DT_NODE_REGION_NAME(TEST_SRAM_NODE), "SRAM_REGION"), "");
28
29 zassert_equal_ptr(var_in_test_sram, TEST_SRAM_ADDR, "");
30
31 zassert_equal_ptr(__SRAM_REGION_start, TEST_SRAM_ADDR, "");
32 zassert_equal_ptr(__SRAM_REGION_end, TEST_SRAM_ADDR + TEST_SRAM_SIZE, "");
33 zassert_equal_ptr(__SRAM_REGION_load_start, TEST_SRAM_ADDR, "");
34
35 zassert_equal((unsigned long) __SRAM_REGION_size, TEST_SRAM_SIZE, "");
36 }
37
38 ZTEST_SUITE(devicetree_memory_region, NULL, NULL, NULL, NULL, NULL);
39