1 /*
2  * Copyright (c) 2024 Trackunit Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * This test is designed to test linking global symbols, which for some architectures
9  * like ARM generate relative jumps rather than jumping to absolute addresses. Multiple
10  * global functions are created to hopefully generate both positive and negative relative
11  * jumps.
12  */
13 
14 #include <stdint.h>
15 #include <zephyr/llext/symbol.h>
16 #include <zephyr/sys/printk.h>
17 #include <zephyr/ztest_assert.h>
18 
19 static int test_var;
20 
21 void test_relative_jump_1(void);
22 void test_relative_jump_2(void);
23 void test_relative_jump_3(void);
24 void test_relative_jump_4(void);
25 void test_relative_jump_5(void);
26 
test_relative_jump_5(void)27 void test_relative_jump_5(void)
28 {
29 	printk("relative jump 5\n");
30 	test_var = 1;
31 }
32 
test_relative_jump_4(void)33 void test_relative_jump_4(void)
34 {
35 	printk("relative jump 4\n");
36 	test_relative_jump_5();
37 }
38 
test_relative_jump_2(void)39 void test_relative_jump_2(void)
40 {
41 	printk("relative jump 2\n");
42 	test_relative_jump_3();
43 }
44 
test_relative_jump_1(void)45 void test_relative_jump_1(void)
46 {
47 	printk("relative jump 1\n");
48 	test_relative_jump_2();
49 }
50 
test_relative_jump_3(void)51 void test_relative_jump_3(void)
52 {
53 	printk("relative jump 3\n");
54 	test_relative_jump_4();
55 }
56 
test_entry(void)57 void test_entry(void)
58 {
59 	printk("enter\n");
60 	test_var = 0;
61 	test_relative_jump_1();
62 	printk("exit\n");
63 	zassert_equal(test_var, 1, "relative jump test failed");
64 }
65 EXPORT_SYMBOL(test_entry);
66