forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
llext: add threads and kernel object test case
Tests threads and kernel objects with userspace. Includes cleanups suggested by Luca Burelli. Signed-off-by: Lauren Murphy <[email protected]>
- Loading branch information
1 parent
83d879b
commit 83ccc8e
Showing
4 changed files
with
123 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/subsys/llext/simple/src/threads_kernel_objects_ext.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2023 Intel Corporation. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* | ||
* This code demonstrates the use of threads and requires object | ||
* relocation support. | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <zephyr/llext/symbol.h> | ||
#include <zephyr/kernel.h> | ||
#include "threads_kernel_objects_ext.h" | ||
|
||
void test_thread(void *arg0, void *arg1, void *arg2) | ||
{ | ||
printk("Take semaphore from test thread\n"); | ||
k_sem_take(&my_sem, K_FOREVER); | ||
} | ||
|
||
void test_entry(void) | ||
{ | ||
printk("Give semaphore from main thread\n"); | ||
k_sem_give(&my_sem); | ||
|
||
printk("Creating thread\n"); | ||
k_tid_t tid = k_thread_create(&my_thread, (k_thread_stack_t *) &my_thread_stack, | ||
MY_THREAD_STACK_SIZE, &test_thread, NULL, NULL, NULL, | ||
MY_THREAD_PRIO, MY_THREAD_OPTIONS, K_FOREVER); | ||
|
||
printk("Starting thread\n"); | ||
k_thread_start(tid); | ||
|
||
printk("Joining thread\n"); | ||
k_thread_join(&my_thread, K_FOREVER); | ||
printk("Test thread joined\n"); | ||
} | ||
LL_EXTENSION_SYMBOL(test_entry); |
22 changes: 22 additions & 0 deletions
22
tests/subsys/llext/simple/src/threads_kernel_objects_ext.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024 Intel Corporation. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/llext/symbol.h> | ||
#include <zephyr/kernel.h> | ||
|
||
extern struct k_thread my_thread; | ||
#define MY_THREAD_STACK_SIZE 1024 | ||
extern struct z_thread_stack_element my_thread_stack[]; | ||
|
||
extern struct k_sem my_sem; | ||
|
||
#ifdef CONFIG_USERSPACE | ||
#define MY_THREAD_PRIO 1 | ||
#define MY_THREAD_OPTIONS (K_USER | K_INHERIT_PERMS) | ||
#else | ||
#define MY_THREAD_PRIO 0 | ||
#define MY_THREAD_OPTIONS 0 | ||
#endif |