From ce243944375e46e94346bfb3dcbe8c499fc4996b Mon Sep 17 00:00:00 2001 From: Lauren Murphy Date: Mon, 11 Mar 2024 13:20:41 -0700 Subject: [PATCH] llext: add object test case Adds a case to the simple llext test testing global non-static object relocation. Signed-off-by: Lauren Murphy --- tests/subsys/llext/simple/CMakeLists.txt | 2 +- tests/subsys/llext/simple/src/object_ext.c | 26 +++++++++++++++++++ .../llext/simple/src/test_llext_simple.c | 5 ++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/subsys/llext/simple/src/object_ext.c diff --git a/tests/subsys/llext/simple/CMakeLists.txt b/tests/subsys/llext/simple/CMakeLists.txt index e39f4f8900..4a9f311d8f 100644 --- a/tests/subsys/llext/simple/CMakeLists.txt +++ b/tests/subsys/llext/simple/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories(app PRIVATE ) # generate extension targets foreach extension given by name -foreach(ext_name hello_world logging relative_jump) +foreach(ext_name hello_world logging relative_jump object) set(ext_src ${PROJECT_SOURCE_DIR}/src/${ext_name}_ext.c) set(ext_bin ${ZEPHYR_BINARY_DIR}/${ext_name}.llext) set(ext_inc ${ZEPHYR_BINARY_DIR}/include/generated/${ext_name}.inc) diff --git a/tests/subsys/llext/simple/src/object_ext.c b/tests/subsys/llext/simple/src/object_ext.c new file mode 100644 index 0000000000..dd2f925022 --- /dev/null +++ b/tests/subsys/llext/simple/src/object_ext.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * This code demonstrates object relocation support. + */ + +#include +#include +#include + +/* Test non-static global object relocation */ +int number = 42; +const char *string = "hello"; + +void test_entry(void) +{ + printk("number: %d\n", number); + number = 0; + printk("number, updated: %d\n", number); + printk("string: %s\n", string); +} +LL_EXTENSION_SYMBOL(test_entry); diff --git a/tests/subsys/llext/simple/src/test_llext_simple.c b/tests/subsys/llext/simple/src/test_llext_simple.c index 14d224f477..dcb31ac9e4 100644 --- a/tests/subsys/llext/simple/src/test_llext_simple.c +++ b/tests/subsys/llext/simple/src/test_llext_simple.c @@ -152,6 +152,11 @@ static LLEXT_CONST uint8_t relative_jump_ext[] __aligned(4) = { }; LLEXT_LOAD_UNLOAD(relative_jump, true) +static LLEXT_CONST uint8_t object_ext[] __aligned(4) = { + #include "object.inc" +}; +LLEXT_LOAD_UNLOAD(object, true) + /* * Ensure that EXPORT_SYMBOL does indeed provide a symbol and a valid address * to it.