1 /*
2  * Copyright (c) 2024 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * This code demonstrates object relocation support.
9  */
10 
11 #include <stdint.h>
12 #include <zephyr/llext/symbol.h>
13 #include <zephyr/kernel.h>
14 #include <zephyr/ztest_assert.h>
15 
16 /* Test non-static global object relocation */
17 int number = 42;
18 const char *string = "hello";
19 
20 int run_id = 41;
21 
test_entry(void)22 void test_entry(void)
23 {
24 	switch (run_id) {
25 	case 41:
26 		/* initial run: test variable initialization */
27 		break;
28 	case 42:
29 		/* user-mode run: reinit number */
30 		number = 42;
31 		break;
32 	default:
33 		/* possible llext loader issue */
34 		zassert_unreachable("unexpected run_id %d", run_id);
35 		return;
36 	}
37 
38 	printk("number: %d\n", number);
39 	zassert_equal(number, 42);
40 	number = 0;
41 	printk("number, updated: %d\n", number);
42 	zassert_equal(number, 0);
43 	printk("string: %s\n", string);
44 	zassert_ok(strcmp(string, "hello"));
45 
46 	run_id += 1;
47 }
48 EXPORT_SYMBOL(test_entry);
49