Skip to content

Commit f5bacd6

Browse files
committed
tests: subsys: llext: Add test for LLEXT_RODATA_NO_RELOC.
Test extension for CONFIG_LLEXT_RODATA_NO_RELOC feature. Signed-off-by: Ibrahim Abdalkader <[email protected]>
1 parent 5204679 commit f5bacd6

File tree

4 files changed

+77
-2
lines changed

4 files changed

+77
-2
lines changed

tests/subsys/llext/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ if(NOT CONFIG_LLEXT_TYPE_ELF_SHAREDLIB)
4747
list(APPEND ext_names init_fini)
4848
endif()
4949

50+
#if(CONFIG_LLEXT_RODATA_NO_RELOC)
51+
list(APPEND ext_names rodata_no_reloc)
52+
#endif()
53+
5054
# generate extension targets for each extension in 'ext_names'
5155
foreach(ext_name ${ext_names})
5256
set(ext_src ${PROJECT_SOURCE_DIR}/src/${ext_name}_ext.c)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2025 Arduino SA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Test extension for CONFIG_LLEXT_RODATA_NO_RELOC feature.
9+
*/
10+
11+
#include <stdint.h>
12+
#include <zephyr/llext/symbol.h>
13+
#include <zephyr/sys/printk.h>
14+
#include <zephyr/ztest_assert.h>
15+
16+
/* rodata with a relocation - forces copy to RAM */
17+
Z_GENERIC_SECTION(.rodata)
18+
static const void *reloc_rodata[] = {
19+
&printk
20+
};
21+
22+
/* rodata with no relocation - stays in flash */
23+
Z_GENERIC_SECTION(.rodata.noreloc)
24+
static const uint32_t flash_rodata[] = {
25+
0x12345678, 0x9ABCDEF0, 0xCAFEBABE, 0xFEEDFACE,
26+
};
27+
28+
void test_entry(void)
29+
{
30+
uintptr_t reloc_addr = (uintptr_t)&reloc_rodata;
31+
uintptr_t flash_addr = (uintptr_t)&flash_rodata;
32+
33+
printk("reloc_rodata at %p\n", (void *)reloc_addr);
34+
printk("flash_rodata at %p\n", (void *)flash_addr);
35+
36+
uintptr_t sram_start = CONFIG_SRAM_BASE_ADDRESS;
37+
uintptr_t sram_end = sram_start + CONFIG_SRAM_SIZE * 1024UL;
38+
39+
printk("SRAM range: 0x%lx - 0x%lx\n", (unsigned long)sram_start, (unsigned long)sram_end);
40+
41+
#if defined(CONFIG_LLEXT_RODATA_NO_RELOC) && !defined(CONFIG_CPU_CORTEX_A9)
42+
/* flash_rodata should stay in flash */
43+
zassert_true(flash_addr < sram_start || flash_addr >= sram_end,
44+
"flash_rodata should NOT be in SRAM");
45+
#else
46+
/* flash_rodata should be relocated to RAM */
47+
zassert_true(flash_addr >= sram_start || flash_addr < sram_end,
48+
"flash_rodata in SRAM");
49+
#endif
50+
/* reloc_rodata should be relocated to RAM */
51+
zassert_true(reloc_addr >= sram_start && reloc_addr < sram_end,
52+
"reloc_rodata in SRAM");
53+
}
54+
EXPORT_SYMBOL(test_entry);

tests/subsys/llext/src/test_llext.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ static LLEXT_CONST uint8_t align_ext[] ELF_ALIGN = {
323323
};
324324
LLEXT_LOAD_UNLOAD(align)
325325

326+
#if defined(CONFIG_LLEXT_RODATA_NO_RELOC)
327+
static LLEXT_CONST uint8_t rodata_no_reloc_ext[] ELF_ALIGN = {
328+
#include "rodata_no_reloc.inc"
329+
};
330+
LLEXT_LOAD_UNLOAD(rodata_no_reloc)
331+
#endif
332+
326333
static LLEXT_CONST uint8_t inspect_ext[] ELF_ALIGN = {
327334
#include "inspect.inc"
328335
};

tests/subsys/llext/testcase.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ tests:
6464
extra_configs:
6565
- CONFIG_LLEXT_HEAP_SIZE=128 # qemu_cortex_a9 requires larger heap
6666
- CONFIG_LLEXT_STORAGE_WRITABLE=n
67+
llext.rodata_no_reloc:
68+
arch_allow:
69+
- arm
70+
- riscv
71+
- arc
72+
- x86
73+
filter: not CONFIG_MPU and not CONFIG_MMU
74+
extra_conf_files: ['no_mem_protection.conf']
75+
extra_configs:
76+
- CONFIG_LLEXT_HEAP_SIZE=128
77+
- CONFIG_LLEXT_STORAGE_WRITABLE=n
78+
- CONFIG_LLEXT_RODATA_NO_RELOC=y
6779
llext.writable:
6880
arch_allow:
6981
- arm
@@ -80,10 +92,8 @@ tests:
8092
llext.writable_relocatable:
8193
arch_allow:
8294
- arm
83-
- xtensa
8495
- riscv
8596
- arc
86-
- x86
8797
platform_exclude:
8898
- qemu_arc/qemu_arc_hs5x # See #80949
8999
- nsim/nsim_hs5x # See #80949

0 commit comments

Comments
 (0)