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 <awojasinski@baylibre.com>
This commit is contained in:
parent
420891cedb
commit
7e3580070f
6 changed files with 132 additions and 0 deletions
6
tests/subsys/llext/simple/boards/qemu_cortex_a9.conf
Normal file
6
tests/subsys/llext/simple/boards/qemu_cortex_a9.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
CONFIG_FS_LITTLEFS_FMP_DEV=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_SIMULATOR=y
|
28
tests/subsys/llext/simple/boards/qemu_cortex_a9.overlay
Normal file
28
tests/subsys/llext/simple/boards/qemu_cortex_a9.overlay
Normal file
|
@ -0,0 +1,28 @@
|
|||
/ {
|
||||
sim_flash_controller: sim_flash_controller {
|
||||
compatible = "zephyr,sim-flash";
|
||||
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
erase-value = <0x00>;
|
||||
|
||||
flash_sim0: flash_sim@0 {
|
||||
compatible = "soc-nv-flash";
|
||||
reg = <0x00000000 0x2000>;
|
||||
|
||||
erase-block-size = <1024>;
|
||||
write-block-size = <4>;
|
||||
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
storage_partition: partition@0 {
|
||||
label = "storage_partition";
|
||||
reg = <0x00000000 0x2000>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
6
tests/subsys/llext/simple/boards/qemu_cortex_r5.conf
Normal file
6
tests/subsys/llext/simple/boards/qemu_cortex_r5.conf
Normal file
|
@ -0,0 +1,6 @@
|
|||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
CONFIG_FS_LITTLEFS_FMP_DEV=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_SIMULATOR=y
|
28
tests/subsys/llext/simple/boards/qemu_cortex_r5.overlay
Normal file
28
tests/subsys/llext/simple/boards/qemu_cortex_r5.overlay
Normal file
|
@ -0,0 +1,28 @@
|
|||
/ {
|
||||
sim_flash_controller: sim_flash_controller {
|
||||
compatible = "zephyr,sim-flash";
|
||||
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
erase-value = <0x00>;
|
||||
|
||||
flash_sim0: flash_sim@0 {
|
||||
compatible = "soc-nv-flash";
|
||||
reg = <0x00000000 0x2000>;
|
||||
|
||||
erase-block-size = <1024>;
|
||||
write-block-size = <4>;
|
||||
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
storage_partition: partition@0 {
|
||||
label = "storage_partition";
|
||||
reg = <0x00000000 0x2000>;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
|
@ -6,10 +6,16 @@
|
|||
|
||||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/fs/fs.h>
|
||||
#if defined(CONFIG_FILE_SYSTEM_LITTLEFS)
|
||||
#include <zephyr/fs/littlefs.h>
|
||||
#endif
|
||||
#include <zephyr/llext/llext.h>
|
||||
#include <zephyr/llext/symbol.h>
|
||||
#include <zephyr/llext/buf_loader.h>
|
||||
#include <zephyr/llext/fs_loader.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/storage/flash_map.h>
|
||||
#include <zephyr/sys/libc-hooks.h>
|
||||
#include "syscalls_ext.h"
|
||||
#include "threads_kernel_objects_ext.h"
|
||||
|
@ -323,6 +329,57 @@ ZTEST(llext, test_find_section)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_FILE_SYSTEM)
|
||||
#define LLEXT_FILE "hello_world.llext"
|
||||
|
||||
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
|
||||
static struct fs_mount_t mp = {
|
||||
.type = FS_LITTLEFS,
|
||||
.fs_data = &storage,
|
||||
.storage_dev = (void *)FIXED_PARTITION_ID(storage_partition),
|
||||
.mnt_point = "/lfs",
|
||||
};
|
||||
|
||||
ZTEST(llext, test_fs_loader)
|
||||
{
|
||||
int res;
|
||||
char path[UINT8_MAX];
|
||||
struct fs_file_t fd;
|
||||
|
||||
/* File system should be mounted before the testcase. If not mount it now. */
|
||||
if (!(mp.flags & FS_MOUNT_FLAG_AUTOMOUNT)) {
|
||||
zassert_ok(fs_mount(&mp), "Filesystem should be mounted");
|
||||
}
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", mp.mnt_point, LLEXT_FILE);
|
||||
fs_file_t_init(&fd);
|
||||
|
||||
zassert_ok(fs_open(&fd, path, FS_O_CREATE | FS_O_TRUNC | FS_O_WRITE),
|
||||
"Failed opening file");
|
||||
|
||||
zassert_equal(fs_write(&fd, hello_world_ext, ARRAY_SIZE(hello_world_ext)),
|
||||
ARRAY_SIZE(hello_world_ext),
|
||||
"Full content of the buffer holding ext should be written");
|
||||
|
||||
zassert_ok(fs_close(&fd), "Failed closing file");
|
||||
|
||||
struct llext_fs_loader fs_loader = LLEXT_FS_LOADER(path);
|
||||
struct llext_loader *loader = &fs_loader.loader;
|
||||
struct llext_load_param ldr_parm = LLEXT_LOAD_PARAM_DEFAULT;
|
||||
struct llext *ext = NULL;
|
||||
|
||||
res = llext_load(loader, "hello_world", &ext, &ldr_parm);
|
||||
zassert_ok(res, "load should succeed");
|
||||
|
||||
void (*test_entry_fn)() = llext_find_sym(&ext->exp_tab, "test_entry");
|
||||
|
||||
zassert_not_null(test_entry_fn, "test_entry should be an exported symbol");
|
||||
|
||||
llext_unload(&ext);
|
||||
fs_unmount(&mp);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Ensure that EXPORT_SYMBOL does indeed provide a symbol and a valid address
|
||||
* to it.
|
||||
|
|
|
@ -45,6 +45,13 @@ tests:
|
|||
extra_configs:
|
||||
- CONFIG_USERSPACE=y
|
||||
- CONFIG_LLEXT_STORAGE_WRITABLE=n
|
||||
llext.simple.readonly_fs_loader:
|
||||
arch_allow: arm # Xtensa needs writable storage
|
||||
filter: not CONFIG_MPU and not CONFIG_MMU and not CONFIG_SOC_SERIES_S32ZE
|
||||
extra_configs:
|
||||
- arch:arm:CONFIG_ARM_MPU=n
|
||||
- arch:arm:CONFIG_ARM_AARCH32_MMU=n
|
||||
- CONFIG_LLEXT_STORAGE_WRITABLE=n
|
||||
llext.simple.writable:
|
||||
arch_allow: arm xtensa
|
||||
integration_platforms:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue