tests/llext: refactor: simplify test case definition

This patch refactors the macro for test case definition to simplify the
generic case. By using variable macro arguments and default-0 fields,
the most common case does not require arguments at all and tests that
have special requirements can be defined with only the necessary fields.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This commit is contained in:
Luca Burelli 2024-08-22 16:28:33 +02:00 committed by Fabio Baltieri
commit 2d322725d3

View file

@ -46,11 +46,11 @@ LOG_MODULE_REGISTER(test_llext_simple);
struct llext_test { struct llext_test {
const char *name; const char *name;
bool try_userspace;
size_t buf_len;
LLEXT_CONST uint8_t *buf; LLEXT_CONST uint8_t *buf;
size_t buf_len;
bool kernel_only;
void (*perm_setup)(struct k_thread *llext_thread); void (*perm_setup)(struct k_thread *llext_thread);
}; };
@ -111,7 +111,7 @@ static void threads_objects_perm_setup(struct k_thread *llext_thread)
#define threads_objects_perm_setup NULL #define threads_objects_perm_setup NULL
#endif /* CONFIG_USERSPACE */ #endif /* CONFIG_USERSPACE */
void load_call_unload(struct llext_test *test_case) void load_call_unload(const struct llext_test *test_case)
{ {
struct llext_buf_loader buf_loader = struct llext_buf_loader buf_loader =
LLEXT_BUF_LOADER(test_case->buf, test_case->buf_len); LLEXT_BUF_LOADER(test_case->buf, test_case->buf_len);
@ -176,7 +176,7 @@ void load_call_unload(struct llext_test *test_case)
* of a userspace thread along with the usual supervisor context * of a userspace thread along with the usual supervisor context
* tried above. * tried above.
*/ */
if (test_case->try_userspace) { if (!test_case->kernel_only) {
k_thread_create(&llext_thread, llext_stack, k_thread_create(&llext_thread, llext_stack,
K_THREAD_STACK_SIZEOF(llext_stack), K_THREAD_STACK_SIZEOF(llext_stack),
&llext_entry, test_entry_fn, NULL, NULL, &llext_entry, test_entry_fn, NULL, NULL,
@ -206,15 +206,14 @@ void load_call_unload(struct llext_test *test_case)
* unloading each extension which may itself excercise various APIs provided by * unloading each extension which may itself excercise various APIs provided by
* Zephyr. * Zephyr.
*/ */
#define LLEXT_LOAD_UNLOAD(_name, _userspace, _perm_setup) \ #define LLEXT_LOAD_UNLOAD(_name, extra_args...) \
ZTEST(llext, test_load_unload_##_name) \ ZTEST(llext, test_load_unload_##_name) \
{ \ { \
struct llext_test test_case = { \ const struct llext_test test_case = { \
.name = STRINGIFY(_name), \ .name = STRINGIFY(_name), \
.try_userspace = _userspace, \
.buf_len = ARRAY_SIZE(_name ## _ext), \
.buf = _name ## _ext, \ .buf = _name ## _ext, \
.perm_setup = _perm_setup, \ .buf_len = ARRAY_SIZE(_name ## _ext), \
extra_args \
}; \ }; \
load_call_unload(&test_case); \ load_call_unload(&test_case); \
} }
@ -229,40 +228,44 @@ void load_call_unload(struct llext_test *test_case)
static LLEXT_CONST uint8_t hello_world_ext[] ELF_ALIGN = { static LLEXT_CONST uint8_t hello_world_ext[] ELF_ALIGN = {
#include "hello_world.inc" #include "hello_world.inc"
}; };
LLEXT_LOAD_UNLOAD(hello_world, false, NULL) LLEXT_LOAD_UNLOAD(hello_world,
.kernel_only = true
)
static LLEXT_CONST uint8_t logging_ext[] ELF_ALIGN = { static LLEXT_CONST uint8_t logging_ext[] ELF_ALIGN = {
#include "logging.inc" #include "logging.inc"
}; };
LLEXT_LOAD_UNLOAD(logging, true, NULL) LLEXT_LOAD_UNLOAD(logging)
static LLEXT_CONST uint8_t relative_jump_ext[] ELF_ALIGN = { static LLEXT_CONST uint8_t relative_jump_ext[] ELF_ALIGN = {
#include "relative_jump.inc" #include "relative_jump.inc"
}; };
LLEXT_LOAD_UNLOAD(relative_jump, true, NULL) LLEXT_LOAD_UNLOAD(relative_jump)
static LLEXT_CONST uint8_t object_ext[] ELF_ALIGN = { static LLEXT_CONST uint8_t object_ext[] ELF_ALIGN = {
#include "object.inc" #include "object.inc"
}; };
LLEXT_LOAD_UNLOAD(object, true, NULL) LLEXT_LOAD_UNLOAD(object)
#ifndef CONFIG_LLEXT_TYPE_ELF_RELOCATABLE #ifndef CONFIG_LLEXT_TYPE_ELF_RELOCATABLE
static LLEXT_CONST uint8_t syscalls_ext[] ELF_ALIGN = { static LLEXT_CONST uint8_t syscalls_ext[] ELF_ALIGN = {
#include "syscalls.inc" #include "syscalls.inc"
}; };
LLEXT_LOAD_UNLOAD(syscalls, true, NULL) LLEXT_LOAD_UNLOAD(syscalls)
static LLEXT_CONST uint8_t threads_kernel_objects_ext[] ELF_ALIGN = { static LLEXT_CONST uint8_t threads_kernel_objects_ext[] ELF_ALIGN = {
#include "threads_kernel_objects.inc" #include "threads_kernel_objects.inc"
}; };
LLEXT_LOAD_UNLOAD(threads_kernel_objects, true, threads_objects_perm_setup) LLEXT_LOAD_UNLOAD(threads_kernel_objects,
.perm_setup = threads_objects_perm_setup,
)
#endif #endif
#ifndef CONFIG_LLEXT_TYPE_ELF_OBJECT #ifndef CONFIG_LLEXT_TYPE_ELF_OBJECT
static LLEXT_CONST uint8_t multi_file_ext[] ELF_ALIGN = { static LLEXT_CONST uint8_t multi_file_ext[] ELF_ALIGN = {
#include "multi_file.inc" #include "multi_file.inc"
}; };
LLEXT_LOAD_UNLOAD(multi_file, true, NULL) LLEXT_LOAD_UNLOAD(multi_file)
#endif #endif
#if defined(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE) && defined(CONFIG_XTENSA) #if defined(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE) && defined(CONFIG_XTENSA)