diff --git a/userspace/include/unit/unit.h b/userspace/include/unit/unit.h index 9438d4d95..2f93bab56 100644 --- a/userspace/include/unit/unit.h +++ b/userspace/include/unit/unit.h @@ -67,6 +67,18 @@ struct unit_module { struct unit_module_test *tests; unsigned long nr_tests; + /* + * Run priority. Currently 3 defined: + * + * UNIT_PRIO_SELF_TEST + * UNIT_PRIO_POSIX_TEST + * UNIT_PRIO_NVGPU_TEST + * + * These let us run environment and POSIX API wrapper tests before the + * rest of the unit tests run. + */ + unsigned int prio; + /* * For the core FW to use. Not for modules!!! */ @@ -74,13 +86,23 @@ struct unit_module { struct unit_fw *fw; }; -#define UNIT_MODULE(__name, __tests) \ +/* + * Zero is the higest priority. Increasing the prio value decreases priority to + * run. + */ +#define UNIT_PRIO_SELF_TEST 0U +#define UNIT_PRIO_POSIX_TEST 50U +#define UNIT_PRIO_NVGPU_TEST 100U + +#define UNIT_MODULE(__name, __tests, __prio) \ struct unit_module __unit_module__ = { \ .name = #__name, \ .tests = __tests, \ .nr_tests = (sizeof(__tests) / \ sizeof(struct unit_module_test)), \ + .prio = __prio, \ .lib_handle = NULL, \ + .fw = NULL, \ } #define UNIT_TEST(__name, __fn, __args) \ diff --git a/userspace/src/module.c b/userspace/src/module.c index c111c6cbb..779c52d3c 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, return mod; } +static int cmp_module_prio(const void *__mod_a, const void *__mod_b) +{ + const struct unit_module *mod_a = __mod_a; + const struct unit_module *mod_b = __mod_b; + + return mod_a->prio > mod_b->prio; +} + +/* + * Sort the module list according to prio. + */ +static void sort_modules_by_prio(struct unit_module **modules, int nr) +{ + qsort(modules, (size_t)nr, sizeof(struct unit_module *), + cmp_module_prio); +} + /* * Load all the modules we can from the module load path. Return the list of * 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) } modules[i] = NULL; + + sort_modules_by_prio(modules, i); + return modules; err: