|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | /* |
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. |
10 | 11 | */ |
11 | 12 |
|
12 | 13 | #include <stdint.h> |
13 | 14 | #include <zephyr/llext/symbol.h> |
| 15 | +#include <zephyr/device.h> |
14 | 16 | #include <zephyr/kernel.h> |
15 | 17 | #include <zephyr/ztest_assert.h> |
16 | 18 |
|
17 | 19 | #include "threads_kernel_objects_ext.h" |
18 | 20 |
|
| 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 | + |
19 | 29 | void test_thread(void *arg0, void *arg1, void *arg2) |
20 | 30 | { |
21 | 31 | printk("Take semaphore from test thread\n"); |
22 | 32 | 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 |
23 | 49 | } |
24 | 50 |
|
25 | 51 | void test_entry(void) |
|
0 commit comments