Skip to content

Commit 5ec5f24

Browse files
pillo79carlescufi
authored andcommitted
llext: test exporting DT devices to extensions
Add a new test to the simple llext test suite that verifies that DT devices are properly exported to extensions. This is done by obtaining a device handle from the DT and then trying to get the same handle at runtime using the device_get_binding() API. This test is optional because the current qemu_xtensa platform does not have any usable DT devices to test with. The LLEXT heap size is also increased to 64 kbytes to avoid heap exhaustion when running the new test on mps2_an385. Signed-off-by: Luca Burelli <[email protected]>
1 parent db451f2 commit 5ec5f24

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

tests/subsys/llext/simple/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ CONFIG_ZTEST=y
22
CONFIG_ZTEST_STACK_SIZE=4096
33
CONFIG_LOG=y
44
CONFIG_LLEXT=y
5-
CONFIG_LLEXT_HEAP_SIZE=32
5+
CONFIG_LLEXT_HEAP_SIZE=64
6+
CONFIG_LLEXT_EXPORT_DEVICES=y
67
CONFIG_LLEXT_LOG_LEVEL_DBG=y
78

89
CONFIG_APPLICATION_DEFINED_SYSCALL=y

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <zephyr/ztest.h>
8+
#include <zephyr/device.h>
89
#include <zephyr/kernel.h>
910
#include <zephyr/fs/fs.h>
1011
#if defined(CONFIG_FILE_SYSTEM_LITTLEFS)
@@ -108,6 +109,9 @@ static void threads_objects_test_setup(struct llext *, struct k_thread *llext_th
108109
k_object_access_grant(&my_sem, llext_thread);
109110
k_object_access_grant(&my_thread, llext_thread);
110111
k_object_access_grant(&my_thread_stack, llext_thread);
112+
#if DT_HAS_CHOSEN(zephyr_console)
113+
k_object_access_grant(DEVICE_DT_GET(DT_CHOSEN(zephyr_console)), llext_thread);
114+
#endif
111115
}
112116
#else
113117
/* No need to set up permissions for supervisor mode */

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,47 @@
55
*/
66

77
/*
8-
* This code demonstrates the use of threads and requires object
9-
* relocation support.
8+
* This code checks the functionality of threads, synchronization primitives
9+
* and device access from extensions.
10+
* This test should be valid from both user and privileged modes.
1011
*/
1112

1213
#include <stdint.h>
1314
#include <zephyr/llext/symbol.h>
15+
#include <zephyr/device.h>
1416
#include <zephyr/kernel.h>
1517
#include <zephyr/ztest_assert.h>
1618

1719
#include "threads_kernel_objects_ext.h"
1820

21+
/*
22+
* Some platforms do not define any usable DT devices (not even the console).
23+
* In those cases the device API test can't be executed.
24+
*/
25+
#if DT_HAS_CHOSEN(zephyr_console)
26+
#define CONSOLE_DT_NODE DT_CHOSEN(zephyr_console)
27+
#endif
28+
1929
void test_thread(void *arg0, void *arg1, void *arg2)
2030
{
2131
printk("Take semaphore from test thread\n");
2232
k_sem_take(&my_sem, K_FOREVER);
33+
34+
#ifdef CONSOLE_DT_NODE
35+
const struct device *const console_dev = DEVICE_DT_GET(CONSOLE_DT_NODE);
36+
const char *const console_name = DEVICE_DT_NAME(CONSOLE_DT_NODE);
37+
const struct device *binding_dev;
38+
39+
/* Ensure the console device was properly obtained at compile time */
40+
zassert_not_null(console_dev);
41+
42+
/* Try to get the same handle at runtime and verify they match */
43+
binding_dev = device_get_binding(console_name);
44+
zassert_equal(binding_dev, console_dev);
45+
46+
/* Verify device API functionality, console must be ready in CI tests */
47+
zassert_true(device_is_ready(console_dev));
48+
#endif
2349
}
2450

2551
void test_entry(void)

0 commit comments

Comments
 (0)