Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | /* * Copyright (c) 2017-2018 Oticon A/S * * SPDX-License-Identifier: Apache-2.0 */ #include "init.h" #include <stdint.h> #include <string.h> #include "bs_types.h" #include "bs_tracing.h" #include "bstests.h" /* * Result of the testcase execution. * Note that the executable will return the maximum of bst_result and * {the HW model return code} to the shell and that * {the HW model return code} will be 0 unless it fails or it is * configured illegally */ enum bst_result_t bst_result; static struct bst_test_instance *current_test; static struct bst_test_list *test_list_top; __attribute__((weak)) bst_test_install_t test_installers[] = { NULL }; struct bst_test_list *bst_add_tests(struct bst_test_list *tests, const struct bst_test_instance *test_def) { int idx = 0; struct bst_test_list *tail = tests; struct bst_test_list *head = tests; if (tail) { /* First we 'run to end' */ while (tail->next) { tail = tail->next; } } else { if (test_def[idx].test_id != NULL) { head = malloc(sizeof(struct bst_test_list)); head->next = NULL; head->test_instance = (struct bst_test_instance *) &test_def[idx++]; tail = head; } } while (test_def[idx].test_id != NULL) { tail->next = malloc(sizeof(struct bst_test_list)); tail = tail->next; tail->test_instance = (struct bst_test_instance *) &test_def[idx++]; tail->next = NULL; } return head; } static struct bst_test_instance *bst_test_find(struct bst_test_list *tests, char *test_id) { struct bst_test_list *top = tests; while (top != NULL) { if (!strcmp(top->test_instance->test_id, test_id)) { /* Match found */ return top->test_instance; } top = top->next; } return NULL; } void bst_install_tests(void) { int idx = 0; if (test_list_top) { /* Tests were already installed */ return; } /* First execute installers until first test was installed */ while (!test_list_top && test_installers[idx]) { test_list_top = test_installers[idx++](test_list_top); } /* After that simply add remaining tests to list */ while (test_installers[idx]) { test_installers[idx++](test_list_top); } } /** * Print the tests list displayed with the --testslist command * line option */ void bst_print_testslist(void) { struct bst_test_list *top; /* Install tests */ bst_install_tests(); top = test_list_top; while (top) { bs_trace_raw(0, "TestID: %-10s\t%s\n", top->test_instance->test_id, top->test_instance->test_descr); top = top->next; } } /** * Select the testcase to be run from its id */ void bst_set_testapp_mode(char *test_id) { /* Install tests */ bst_install_tests(); /* By default all tests start as in progress */ bst_result = In_progress; current_test = bst_test_find(test_list_top, test_id); if (!current_test) { bs_trace_error_line("test id %s doesn't exist\n", test_id); } } /** * Pass to the testcase the command line arguments it may have * * This function is called after bst_set_testapp_mode * and before *init_f */ void bst_pass_args(int argc, char **argv) { if (current_test && current_test->test_args_f) { current_test->test_args_f(argc, argv); } } /** * Will be called before the CPU is booted */ void bst_pre_init(void) { if (current_test && current_test->test_pre_init_f) { current_test->test_pre_init_f(); } } /** * Will be called when the CPU has gone to sleep for the first time */ void bst_post_init(void) { if (current_test && current_test->test_post_init_f) { current_test->test_post_init_f(); } } /** * Will be called each time the bstest_ticker timer is triggered */ void bst_tick(bs_time_t time) { if (current_test == NULL) { return; } if (current_test->test_tick_f) { current_test->test_tick_f(time); } else if (current_test->test_id) { bs_trace_error_line("the test id %s doesn't have a tick handler" " (how come did we arrive here?)\n", current_test->test_id); } } bool bst_irq_sniffer(int irq_number) { if (current_test && current_test->test_irq_sniffer_f) { return current_test->test_irq_sniffer_f(irq_number); } else { return false; } } static int bst_fake_device_driver_pre2_init(struct device *arg) { ARG_UNUSED(arg); if (current_test && current_test->test_fake_ddriver_prekernel_f) { current_test->test_fake_ddriver_prekernel_f(); } return 0; } static int bst_fake_device_driver_post_init(struct device *arg) { ARG_UNUSED(arg); if (current_test && current_test->test_fake_ddriver_postkernel_f) { current_test->test_fake_ddriver_postkernel_f(); } return 0; } SYS_INIT(bst_fake_device_driver_pre2_init, PRE_KERNEL_1, 0); SYS_INIT(bst_fake_device_driver_post_init, POST_KERNEL, 0); void bst_main(void) { if (current_test && current_test->test_main_f) { current_test->test_main_f(); } } /** * Will be called when the device is being terminated */ uint8_t bst_delete(void) { if (current_test && current_test->test_delete_f) { current_test->test_delete_f(); } while (test_list_top) { struct bst_test_list *tmp = test_list_top->next; free(test_list_top); test_list_top = tmp; } return bst_result; } |