summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--userspace/include/unit/unit.h24
-rw-r--r--userspace/src/module.c20
2 files changed, 43 insertions, 1 deletions
diff --git a/userspace/include/unit/unit.h b/userspace/include/unit/unit.h
index 9438d4d9..2f93bab5 100644
--- a/userspace/include/unit/unit.h
+++ b/userspace/include/unit/unit.h
@@ -68,19 +68,41 @@ struct unit_module {
68 unsigned long nr_tests; 68 unsigned long nr_tests;
69 69
70 /* 70 /*
71 * Run priority. Currently 3 defined:
72 *
73 * UNIT_PRIO_SELF_TEST
74 * UNIT_PRIO_POSIX_TEST
75 * UNIT_PRIO_NVGPU_TEST
76 *
77 * These let us run environment and POSIX API wrapper tests before the
78 * rest of the unit tests run.
79 */
80 unsigned int prio;
81
82 /*
71 * For the core FW to use. Not for modules!!! 83 * For the core FW to use. Not for modules!!!
72 */ 84 */
73 void *lib_handle; 85 void *lib_handle;
74 struct unit_fw *fw; 86 struct unit_fw *fw;
75}; 87};
76 88
77#define UNIT_MODULE(__name, __tests) \ 89/*
90 * Zero is the higest priority. Increasing the prio value decreases priority to
91 * run.
92 */
93#define UNIT_PRIO_SELF_TEST 0U
94#define UNIT_PRIO_POSIX_TEST 50U
95#define UNIT_PRIO_NVGPU_TEST 100U
96
97#define UNIT_MODULE(__name, __tests, __prio) \
78 struct unit_module __unit_module__ = { \ 98 struct unit_module __unit_module__ = { \
79 .name = #__name, \ 99 .name = #__name, \
80 .tests = __tests, \ 100 .tests = __tests, \
81 .nr_tests = (sizeof(__tests) / \ 101 .nr_tests = (sizeof(__tests) / \
82 sizeof(struct unit_module_test)), \ 102 sizeof(struct unit_module_test)), \
103 .prio = __prio, \
83 .lib_handle = NULL, \ 104 .lib_handle = NULL, \
105 .fw = NULL, \
84 } 106 }
85 107
86#define UNIT_TEST(__name, __fn, __args) \ 108#define UNIT_TEST(__name, __fn, __args) \
diff --git a/userspace/src/module.c b/userspace/src/module.c
index c111c6cb..779c52d3 100644
--- a/userspace/src/module.c
+++ b/userspace/src/module.c
@@ -99,6 +99,23 @@ static struct unit_module *load_one_module(struct unit_fw *fw,
99 return mod; 99 return mod;
100} 100}
101 101
102static int cmp_module_prio(const void *__mod_a, const void *__mod_b)
103{
104 const struct unit_module *mod_a = __mod_a;
105 const struct unit_module *mod_b = __mod_b;
106
107 return mod_a->prio > mod_b->prio;
108}
109
110/*
111 * Sort the module list according to prio.
112 */
113static void sort_modules_by_prio(struct unit_module **modules, int nr)
114{
115 qsort(modules, (size_t)nr, sizeof(struct unit_module *),
116 cmp_module_prio);
117}
118
102/* 119/*
103 * Load all the modules we can from the module load path. Return the list of 120 * Load all the modules we can from the module load path. Return the list of
104 * loaded module as an array of pointers to modules. The returned list of 121 * loaded module as an array of pointers to modules. The returned list of
@@ -159,6 +176,9 @@ struct unit_module **core_load_modules(struct unit_fw *fw)
159 } 176 }
160 177
161 modules[i] = NULL; 178 modules[i] = NULL;
179
180 sort_modules_by_prio(modules, i);
181
162 return modules; 182 return modules;
163 183
164err: 184err: