Skip to content

Commit 7e35800

Browse files
awojasinskinashif
authored andcommitted
llext: Add filesystem based testcase to llext test suite
Extend tests with case where extension is copied from RAM buffer into filesystem and then loaded from filesystem. Signed-off-by: Adam Wojasinski <[email protected]>
1 parent 420891c commit 7e35800

File tree

6 files changed

+132
-0
lines changed

6 files changed

+132
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_FILE_SYSTEM=y
2+
CONFIG_FILE_SYSTEM_LITTLEFS=y
3+
CONFIG_FS_LITTLEFS_FMP_DEV=y
4+
CONFIG_FLASH_MAP=y
5+
CONFIG_FLASH=y
6+
CONFIG_FLASH_SIMULATOR=y
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/ {
2+
sim_flash_controller: sim_flash_controller {
3+
compatible = "zephyr,sim-flash";
4+
5+
#address-cells = <1>;
6+
#size-cells = <1>;
7+
erase-value = <0x00>;
8+
9+
flash_sim0: flash_sim@0 {
10+
compatible = "soc-nv-flash";
11+
reg = <0x00000000 0x2000>;
12+
13+
erase-block-size = <1024>;
14+
write-block-size = <4>;
15+
16+
partitions {
17+
compatible = "fixed-partitions";
18+
#address-cells = <1>;
19+
#size-cells = <1>;
20+
21+
storage_partition: partition@0 {
22+
label = "storage_partition";
23+
reg = <0x00000000 0x2000>;
24+
};
25+
};
26+
};
27+
};
28+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_FILE_SYSTEM=y
2+
CONFIG_FILE_SYSTEM_LITTLEFS=y
3+
CONFIG_FS_LITTLEFS_FMP_DEV=y
4+
CONFIG_FLASH_MAP=y
5+
CONFIG_FLASH=y
6+
CONFIG_FLASH_SIMULATOR=y
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/ {
2+
sim_flash_controller: sim_flash_controller {
3+
compatible = "zephyr,sim-flash";
4+
5+
#address-cells = <1>;
6+
#size-cells = <1>;
7+
erase-value = <0x00>;
8+
9+
flash_sim0: flash_sim@0 {
10+
compatible = "soc-nv-flash";
11+
reg = <0x00000000 0x2000>;
12+
13+
erase-block-size = <1024>;
14+
write-block-size = <4>;
15+
16+
partitions {
17+
compatible = "fixed-partitions";
18+
#address-cells = <1>;
19+
#size-cells = <1>;
20+
21+
storage_partition: partition@0 {
22+
label = "storage_partition";
23+
reg = <0x00000000 0x2000>;
24+
};
25+
};
26+
};
27+
};
28+
};

tests/subsys/llext/simple/src/test_llext_simple.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66

77
#include <zephyr/ztest.h>
88
#include <zephyr/kernel.h>
9+
#include <zephyr/fs/fs.h>
10+
#if defined(CONFIG_FILE_SYSTEM_LITTLEFS)
11+
#include <zephyr/fs/littlefs.h>
12+
#endif
913
#include <zephyr/llext/llext.h>
1014
#include <zephyr/llext/symbol.h>
1115
#include <zephyr/llext/buf_loader.h>
16+
#include <zephyr/llext/fs_loader.h>
1217
#include <zephyr/logging/log.h>
18+
#include <zephyr/storage/flash_map.h>
1319
#include <zephyr/sys/libc-hooks.h>
1420
#include "syscalls_ext.h"
1521
#include "threads_kernel_objects_ext.h"
@@ -323,6 +329,57 @@ ZTEST(llext, test_find_section)
323329
}
324330
#endif
325331

332+
#if defined(CONFIG_FILE_SYSTEM)
333+
#define LLEXT_FILE "hello_world.llext"
334+
335+
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
336+
static struct fs_mount_t mp = {
337+
.type = FS_LITTLEFS,
338+
.fs_data = &storage,
339+
.storage_dev = (void *)FIXED_PARTITION_ID(storage_partition),
340+
.mnt_point = "/lfs",
341+
};
342+
343+
ZTEST(llext, test_fs_loader)
344+
{
345+
int res;
346+
char path[UINT8_MAX];
347+
struct fs_file_t fd;
348+
349+
/* File system should be mounted before the testcase. If not mount it now. */
350+
if (!(mp.flags & FS_MOUNT_FLAG_AUTOMOUNT)) {
351+
zassert_ok(fs_mount(&mp), "Filesystem should be mounted");
352+
}
353+
354+
snprintf(path, sizeof(path), "%s/%s", mp.mnt_point, LLEXT_FILE);
355+
fs_file_t_init(&fd);
356+
357+
zassert_ok(fs_open(&fd, path, FS_O_CREATE | FS_O_TRUNC | FS_O_WRITE),
358+
"Failed opening file");
359+
360+
zassert_equal(fs_write(&fd, hello_world_ext, ARRAY_SIZE(hello_world_ext)),
361+
ARRAY_SIZE(hello_world_ext),
362+
"Full content of the buffer holding ext should be written");
363+
364+
zassert_ok(fs_close(&fd), "Failed closing file");
365+
366+
struct llext_fs_loader fs_loader = LLEXT_FS_LOADER(path);
367+
struct llext_loader *loader = &fs_loader.loader;
368+
struct llext_load_param ldr_parm = LLEXT_LOAD_PARAM_DEFAULT;
369+
struct llext *ext = NULL;
370+
371+
res = llext_load(loader, "hello_world", &ext, &ldr_parm);
372+
zassert_ok(res, "load should succeed");
373+
374+
void (*test_entry_fn)() = llext_find_sym(&ext->exp_tab, "test_entry");
375+
376+
zassert_not_null(test_entry_fn, "test_entry should be an exported symbol");
377+
378+
llext_unload(&ext);
379+
fs_unmount(&mp);
380+
}
381+
#endif
382+
326383
/*
327384
* Ensure that EXPORT_SYMBOL does indeed provide a symbol and a valid address
328385
* to it.

tests/subsys/llext/simple/testcase.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ tests:
4545
extra_configs:
4646
- CONFIG_USERSPACE=y
4747
- CONFIG_LLEXT_STORAGE_WRITABLE=n
48+
llext.simple.readonly_fs_loader:
49+
arch_allow: arm # Xtensa needs writable storage
50+
filter: not CONFIG_MPU and not CONFIG_MMU and not CONFIG_SOC_SERIES_S32ZE
51+
extra_configs:
52+
- arch:arm:CONFIG_ARM_MPU=n
53+
- arch:arm:CONFIG_ARM_AARCH32_MMU=n
54+
- CONFIG_LLEXT_STORAGE_WRITABLE=n
4855
llext.simple.writable:
4956
arch_allow: arm xtensa
5057
integration_platforms:

0 commit comments

Comments
 (0)