summaryrefslogtreecommitdiffstats
path: root/userspace
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2018-06-27 17:45:12 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-08-10 02:11:09 -0400
commit70915d8d604965fddf79cb68c0de5b32ed2ab104 (patch)
treeaa1483ba611f5db0c70353c953691b830259bac7 /userspace
parent691bf904451bfe2e4c44ea05319149996abbbbf1 (diff)
gpu: nvgpu: unit: Sort unit tests by priority
Sort unit tests by their priority before running said unit tests. There are three available priorities: UNIT_PRIO_SELF_TEST UNIT_PRIO_POSIX_TEST UNIT_PRIO_NVGPU_TEST Which correspond to the types of testing expected to be run. In general unit tests should always just use UNIT_PRIO_NVGPU_TEST but in the case of tests for the POSIX API layer or the unit test framework the other two priorities are provided. The reason for this is that it doesn't make much sense to run a bunch of unit tests if the environment itself or the POSIX API layer is broken. By placing these tests at the front of the list of tests to run an engineer will easily be able to see if there are core problems versus nvgpu problems. This also lets users fine grain control of test order by adding or subtracting to UNIT_PRIO_NVGPU_TEST but one must be very careful about how they do this. JIRA NVGPU-525 Change-Id: I12a5b798e998f34e4d1168bb3696c579460f20b1 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1741953 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Konsta Holtta <kholtta@nvidia.com> Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'userspace')
-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: