Skip to content

Commit

Permalink
llext: test exporting DT devices to extensions
Browse files Browse the repository at this point in the history
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 <l.burelli@arduino.cc>
  • Loading branch information
pillo79 committed Sep 19, 2024
1 parent bb03ef4 commit 14fb69f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/subsys/llext/simple/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ CONFIG_ZTEST=y
CONFIG_ZTEST_STACK_SIZE=4096
CONFIG_LOG=y
CONFIG_LLEXT=y
CONFIG_LLEXT_HEAP_SIZE=32
CONFIG_LLEXT_HEAP_SIZE=64
CONFIG_LLEXT_EXPORT_DEVICES=y
CONFIG_LLEXT_LOG_LEVEL_DBG=y

CONFIG_APPLICATION_DEFINED_SYSCALL=y
4 changes: 4 additions & 0 deletions tests/subsys/llext/simple/src/test_llext_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <zephyr/ztest.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/fs/fs.h>
#if defined(CONFIG_FILE_SYSTEM_LITTLEFS)
Expand Down Expand Up @@ -108,6 +109,9 @@ static void threads_objects_test_setup(struct llext *, struct k_thread *llext_th
k_object_access_grant(&my_sem, llext_thread);
k_object_access_grant(&my_thread, llext_thread);
k_object_access_grant(&my_thread_stack, llext_thread);
#if DT_HAS_CHOSEN(zephyr_console)
k_object_access_grant(DEVICE_DT_GET(DT_CHOSEN(zephyr_console)), llext_thread);
#endif
}
#else
/* No need to set up permissions for supervisor mode */
Expand Down
30 changes: 28 additions & 2 deletions tests/subsys/llext/simple/src/threads_kernel_objects_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,47 @@
*/

/*
* This code demonstrates the use of threads and requires object
* relocation support.
* This code checks the functionality of threads (including synchronization
* primitives) and device access from extensions.
* This test should be valid from both user and privileged modes.
*/

#include <stdint.h>
#include <zephyr/llext/symbol.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/ztest_assert.h>

#include "threads_kernel_objects_ext.h"

/*
* This optional check is required because the current qemu_xtensa platform
* does not have any usable DT devices to test with.
*/
#if DT_HAS_CHOSEN(zephyr_console)
#define CONSOLE_DT_NODE DT_CHOSEN(zephyr_console)
#endif

void test_thread(void *arg0, void *arg1, void *arg2)
{
printk("Take semaphore from test thread\n");
k_sem_take(&my_sem, K_FOREVER);

#ifdef CONSOLE_DT_NODE
const struct device *const console_dev = DEVICE_DT_GET(CONSOLE_DT_NODE);
const char *const console_name = DEVICE_DT_NAME(CONSOLE_DT_NODE);
const struct device *binding_dev;

/* Ensure the console device was properly obtained at compile time */
zassert_not_null(console_dev);

/* Try to get the same handle at runtime and verify they match */
binding_dev = device_get_binding(console_name);
zassert_equal(binding_dev, console_dev);

/* Verify device API functionality, console must be ready in CI tests */
zassert_true(device_is_ready(console_dev));
#endif
}

void test_entry(void)
Expand Down

0 comments on commit 14fb69f

Please sign in to comment.