1 /*
2 * Copyright (c) 2018 Oticon A/S
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "soc.h"
8 #include "kernel.h"
9 #include "posix_board_if.h"
10
11 /**
12 * @brief Test NATIVE_TASK hook for native builds
13 *
14 * Verify that the NATIVE_TASK hooks are registered and called.
15 * Note that the ztest framework cannot be used as we are testing
16 * functionality which executes before and after all Zephyr threads have been
17 * terminated.
18 */
test_check(int hook)19 static void test_check(int hook)
20 {
21 static int call_nbr;
22 static int failed;
23 static int expected_order[8] = {1, 2, 3, 8, 6, 5, 4, 7};
24
25 if (failed) {
26 return;
27 }
28
29 posix_print_trace("test_hook%i called\n", hook);
30
31 if (expected_order[call_nbr] != hook) {
32 failed = 1;
33 posix_print_trace("PROJECT EXECUTION FAILED\n");
34 }
35
36 if (call_nbr++ == 7) {
37 posix_print_trace("PROJECT EXECUTION SUCCESSFUL\n");
38 }
39 }
40
41 #define TEST_HOOK(n) \
42 static void test_hook##n(void) \
43 { \
44 test_check(n); \
45 }
46
47 TEST_HOOK(1);
48 TEST_HOOK(2);
49 TEST_HOOK(3);
50 TEST_HOOK(4);
51 TEST_HOOK(5);
52 TEST_HOOK(6);
53 TEST_HOOK(7);
54 TEST_HOOK(8);
55
56 NATIVE_TASK(test_hook1, PRE_BOOT_1, 1);
57 NATIVE_TASK(test_hook2, PRE_BOOT_2, 200);
58 NATIVE_TASK(test_hook3, PRE_BOOT_3, 20);
59 NATIVE_TASK(test_hook8, FIRST_SLEEP, 5);
60 NATIVE_TASK(test_hook4, ON_EXIT, 200);
61 NATIVE_TASK(test_hook5, ON_EXIT, 20);
62 NATIVE_TASK(test_hook6, ON_EXIT, 1);
63 NATIVE_TASK(test_hook7, ON_EXIT, 310);
64
main(void)65 void main(void)
66 {
67 k_sleep(K_MSEC(100));
68 posix_exit(0);
69 }
70