1 /*
2  * Copyright (c) 2018 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef _BSTESTS_ENTRY_H
7 #define _BSTESTS_ENTRY_H
8 
9 #include "bs_types.h"
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 /**
16  * TEST HOOKS:
17  *
18  * You may register some of these functions in your testbench
19  *
20  * Note that you can overwrite this function pointers on the fly
21  */
22 /*
23  * Will be called with the command line arguments for the testcase.
24  * This is BEFORE any SW has run, and before the HW has been initialized
25  * This is also before a possible initialization delay.
26  * Note that this function can be used for test pre-initialization steps
27  * like opening the back-channels. But you should not interact yet with the
28  * test ticker or other HW models.
29  */
30 typedef void (*bst_test_args_t)(int, char**);
31 /* It will be called (in the HW models thread) before the CPU is booted,
32  * after the HW models have been initialized. Note that a possible delayed
33  * initialization may delay the execution of this function vs other devices
34  * tests pre-initialization
35  */
36 typedef void (*bst_test_pre_init_t)(void);
37 /*
38  * It will be called (in the HW models thread) when the CPU goes to sleep
39  * for the first time
40  */
41 typedef void (*bst_test_post_init_t)(void);
42 /* It will be called (in the HW models thread) each time the bst_timer ticks */
43 typedef void (*bst_test_tick_t)(bs_time_t time);
44 /*
45  * It will be called (in the HW models thread) when the execution is being
46  * terminated (clean up memory and close your files here)
47  */
48 typedef void (*bst_test_delete_t)(void);
49 /*
50  * It will be called (in SW context) when a HW interrupt is raised.
51  * If it returns true, the normal interrupt handler will NOT be called and
52  *  Zephyr will only see a spurious wake
53  * Note: Use this only to perform special tasks, like sniffing interrupts,
54  * or any other interrupt related cheat, but not as a normal interrupt handler
55  */
56 typedef bool (*bst_test_irq_sniffer_t)(int irq_number);
57 /*
58  * This function will be called (in SW context) as a Zephyr PRE_KERNEL_1
59  * device driver initialization function
60  * Note that the app's main() has not executed yet, and the kernel is not yet
61  * fully ready => You canNOT spawn new threads without wait time yet (or it
62  * will crash)
63  */
64 typedef void (*bst_test_fake_ddriver_prekernel_t)(void);
65 /*
66  * This function will be called (in SW context) as a Zephyr POST_KERNEL
67  * device driver initialization function
68  * You may spawn any test threads you may need here.
69  * Note that the app main() has not executed yet.
70  */
71 typedef void (*bst_test_fake_ddriver_postkernel_t)(void);
72 /*
73  * This function will be called (in SW context) as the Zephyr application main
74  */
75 typedef void (*bst_test_main_t)(void);
76 
77 struct bst_test_instance {
78 	char *test_id;
79 	char *test_descr;
80 	bst_test_args_t                    test_args_f;
81 	bst_test_pre_init_t                test_pre_init_f;
82 	bst_test_post_init_t               test_post_init_f;
83 	bst_test_tick_t                    test_tick_f;
84 	bst_test_delete_t                  test_delete_f;
85 	bst_test_irq_sniffer_t             test_irq_sniffer_f;
86 	bst_test_fake_ddriver_prekernel_t  test_fake_ddriver_prekernel_f;
87 	bst_test_fake_ddriver_postkernel_t test_fake_ddriver_postkernel_f;
88 	bst_test_main_t                    test_main_f;
89 };
90 
91 #define BSTEST_END_MARKER \
92 {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
93 
94 struct bst_test_list {
95 	struct bst_test_instance  *test_instance;
96 	struct bst_test_list    *next;
97 };
98 
99 typedef struct bst_test_list *(*bst_test_install_t)(struct bst_test_list
100 							*test_tail);
101 
102 struct bst_test_list *bst_add_tests(struct bst_test_list *tests,
103 				    const struct bst_test_instance *test_def);
104 void bst_set_testapp_mode(char *test_id);
105 void bst_pass_args(int argc, char **argv);
106 void bst_pre_init(void);
107 void bst_post_init(void);
108 void bst_main(void);
109 void bst_tick(bs_time_t Absolute_device_time);
110 bool bst_irq_sniffer(int irq_number);
111 uint8_t bst_delete(void);
112 
113 /* These return codes need to fit in a uint8_t (0..255), where 0 = successful */
114 enum bst_result_t {Passed = 0, In_progress = 1, Failed = 2};
115 
116 void bst_print_testslist(void);
117 
118 /**
119  * Interface for the fake HW device (timer) dedicated to the tests
120  */
121 void bst_ticker_set_period(bs_time_t tick_period);
122 void bst_ticker_set_next_tick_absolute(bs_time_t absolute_time);
123 void bst_ticker_set_next_tick_delta(bs_time_t absolute_time);
124 void bst_awake_cpu_asap(void);
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #endif
131