@@ -51,7 +51,16 @@ struct llext_test {
5151 size_t buf_len ;
5252
5353 bool kernel_only ;
54- void (* perm_setup )(struct k_thread * llext_thread );
54+
55+ /*
56+ * Optional callbacks
57+ */
58+
59+ /* Called in kernel context before each test starts */
60+ void (* test_setup )(struct llext * ext , struct k_thread * llext_thread );
61+
62+ /* Called in kernel context after each test completes */
63+ void (* test_cleanup )(struct llext * ext );
5564};
5665
5766
@@ -99,16 +108,20 @@ K_THREAD_STACK_DEFINE(my_thread_stack, MY_THREAD_STACK_SIZE);
99108EXPORT_SYMBOL (my_thread_stack );
100109
101110#ifdef CONFIG_USERSPACE
102- /* Allow the user space test thread to access global objects */
103- static void threads_objects_perm_setup (struct k_thread * llext_thread )
111+ /* Allow the test threads to access global objects.
112+ * Note: Permissions on objects used in the test by this thread are initialized
113+ * even in supervisor mode, so that user mode descendant threads can inherit
114+ * these permissions.
115+ */
116+ static void threads_objects_test_setup (struct llext * , struct k_thread * llext_thread )
104117{
105118 k_object_access_grant (& my_sem , llext_thread );
106119 k_object_access_grant (& my_thread , llext_thread );
107120 k_object_access_grant (& my_thread_stack , llext_thread );
108121}
109122#else
110123/* No need to set up permissions for supervisor mode */
111- #define threads_objects_perm_setup NULL
124+ #define threads_objects_test_setup NULL
112125#endif /* CONFIG_USERSPACE */
113126
114127void load_call_unload (const struct llext_test * test_case )
@@ -161,17 +174,17 @@ void load_call_unload(const struct llext_test *test_case)
161174
162175 k_mem_domain_add_thread (& domain , & llext_thread );
163176
164- /* Even in supervisor mode, initialize permissions on objects used in
165- * the test by this thread, so that user mode descendant threads can
166- * inherit these permissions.
167- */
168- if (test_case -> perm_setup ) {
169- test_case -> perm_setup (& llext_thread );
177+ if (test_case -> test_setup ) {
178+ test_case -> test_setup (ext , & llext_thread );
170179 }
171180
172181 k_thread_start (& llext_thread );
173182 k_thread_join (& llext_thread , K_FOREVER );
174183
184+ if (test_case -> test_cleanup ) {
185+ test_case -> test_cleanup (ext );
186+ }
187+
175188 /* Some extensions may wish to be tried from the context
176189 * of a userspace thread along with the usual supervisor context
177190 * tried above.
@@ -184,17 +197,29 @@ void load_call_unload(const struct llext_test *test_case)
184197
185198 k_mem_domain_add_thread (& domain , & llext_thread );
186199
187- if (test_case -> perm_setup ) {
188- test_case -> perm_setup ( & llext_thread );
200+ if (test_case -> test_setup ) {
201+ test_case -> test_setup ( ext , & llext_thread );
189202 }
190203
191204 k_thread_start (& llext_thread );
192205 k_thread_join (& llext_thread , K_FOREVER );
206+
207+ if (test_case -> test_cleanup ) {
208+ test_case -> test_cleanup (ext );
209+ }
193210 }
194211
195212#else /* CONFIG_USERSPACE */
213+ if (test_case -> test_setup ) {
214+ test_case -> test_setup (ext , NULL );
215+ }
216+
196217 zassert_ok (llext_call_fn (ext , "test_entry" ),
197218 "test_entry call should succeed" );
219+
220+ if (test_case -> test_cleanup ) {
221+ test_case -> test_cleanup (ext );
222+ }
198223#endif /* CONFIG_USERSPACE */
199224
200225 llext_unload (& ext );
@@ -257,7 +282,7 @@ static LLEXT_CONST uint8_t threads_kernel_objects_ext[] ELF_ALIGN = {
257282 #include "threads_kernel_objects.inc"
258283};
259284LLEXT_LOAD_UNLOAD (threads_kernel_objects ,
260- .perm_setup = threads_objects_perm_setup ,
285+ .test_setup = threads_objects_test_setup ,
261286)
262287#endif
263288
0 commit comments