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 | /* * Copyright (c) 2020 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr.h> #include <device.h> #include <init.h> #include <ztest.h> /** * @brief Test cases to device driver initialization * */ #define MY_DRIVER_LV_1 "my_driver_level_1" #define MY_DRIVER_LV_2 "my_driver_level_2" #define MY_DRIVER_LV_3 "my_driver_level_3" #define MY_DRIVER_LV_4 "my_driver_level_4" #define MY_DRIVER_PRI_1 "my_driver_priority_1" #define MY_DRIVER_PRI_2 "my_driver_priority_2" #define MY_DRIVER_PRI_3 "my_driver_priority_3" #define MY_DRIVER_PRI_4 "my_driver_priority_4" #define LEVEL_PRE_KERNEL_1 1 #define LEVEL_PRE_KERNEL_2 2 #define LEVEL_POST_KERNEL 3 #define LEVEL_APPLICATION 4 #define PRIORITY_1 1 #define PRIORITY_2 2 #define PRIORITY_3 3 #define PRIORITY_4 4 /* this is for storing sequence during initializtion */ int init_level_sequence[4] = {0}; int init_priority_sequence[4] = {0}; unsigned int seq_level_cnt; unsigned int seq_priority_cnt; /* define driver type 1: for testing initialize levels and priorites */ typedef int (*my_api_configure_t)(const struct device *dev, int dev_config); struct my_driver_api { my_api_configure_t configure; }; static int my_configure(const struct device *dev, int config) { return 0; } static const struct my_driver_api funcs_my_drivers = { .configure = my_configure, }; /* driver init function of testing level */ static int my_driver_lv_1_init(const struct device *dev) { init_level_sequence[seq_level_cnt] = LEVEL_PRE_KERNEL_1; seq_level_cnt++; return 0; } static int my_driver_lv_2_init(const struct device *dev) { init_level_sequence[seq_level_cnt] = LEVEL_PRE_KERNEL_2; seq_level_cnt++; return 0; } static int my_driver_lv_3_init(const struct device *dev) { init_level_sequence[seq_level_cnt] = LEVEL_POST_KERNEL; seq_level_cnt++; return 0; } static int my_driver_lv_4_init(const struct device *dev) { init_level_sequence[seq_level_cnt] = LEVEL_APPLICATION; seq_level_cnt++; return 0; } /* driver init function of testing priority */ static int my_driver_pri_1_init(const struct device *dev) { init_priority_sequence[seq_priority_cnt] = PRIORITY_1; seq_priority_cnt++; return 0; } static int my_driver_pri_2_init(const struct device *dev) { init_priority_sequence[seq_priority_cnt] = PRIORITY_2; seq_priority_cnt++; return 0; } static int my_driver_pri_3_init(const struct device *dev) { init_priority_sequence[seq_priority_cnt] = PRIORITY_3; seq_priority_cnt++; return 0; } static int my_driver_pri_4_init(const struct device *dev) { init_priority_sequence[seq_priority_cnt] = PRIORITY_4; seq_priority_cnt++; return 0; } /** * @brief Test providing control device driver initialization order * * @details Test that kernel shall provide control over device driver * initalization order, using initialization level and priority for each * instance. We use DEVICE_DEFINE to define device instances and set * it's level and priority here, then we run check function later after * all of this instance finish their initialization. * * @ingroup kernel_device_tests */ DEVICE_DEFINE(my_driver_level_1, MY_DRIVER_LV_1, &my_driver_lv_1_init, NULL, NULL, NULL, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &funcs_my_drivers); DEVICE_DEFINE(my_driver_level_2, MY_DRIVER_LV_2, &my_driver_lv_2_init, NULL, NULL, NULL, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &funcs_my_drivers); DEVICE_DEFINE(my_driver_level_3, MY_DRIVER_LV_3, &my_driver_lv_3_init, NULL, NULL, NULL, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &funcs_my_drivers); DEVICE_DEFINE(my_driver_level_4, MY_DRIVER_LV_4, &my_driver_lv_4_init, NULL, NULL, NULL, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &funcs_my_drivers); /* We use priority value of 20 to create a possible sorting conflict with * priority value of 2. So if the linker sorting isn't woring correctly * we'll find out. */ DEVICE_DEFINE(my_driver_priority_4, MY_DRIVER_PRI_4, &my_driver_pri_4_init, NULL, NULL, NULL, POST_KERNEL, 20, &funcs_my_drivers); DEVICE_DEFINE(my_driver_priority_1, MY_DRIVER_PRI_1, &my_driver_pri_1_init, NULL, NULL, NULL, POST_KERNEL, 1, &funcs_my_drivers); DEVICE_DEFINE(my_driver_priority_2, MY_DRIVER_PRI_2, &my_driver_pri_2_init, NULL, NULL, NULL, POST_KERNEL, 2, &funcs_my_drivers); DEVICE_DEFINE(my_driver_priority_3, MY_DRIVER_PRI_3, &my_driver_pri_3_init, NULL, NULL, NULL, POST_KERNEL, 3, &funcs_my_drivers); |