diff options
Diffstat (limited to 'userspace/include/unit/unit.h')
-rw-r--r-- | userspace/include/unit/unit.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/userspace/include/unit/unit.h b/userspace/include/unit/unit.h new file mode 100644 index 00000000..9438d4d9 --- /dev/null +++ b/userspace/include/unit/unit.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | * copy of this software and associated documentation files (the "Software"), | ||
6 | * to deal in the Software without restriction, including without limitation | ||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | * and/or sell copies of the Software, and to permit persons to whom the | ||
9 | * Software is furnished to do so, subject to the following conditions: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | * DEALINGS IN THE SOFTWARE. | ||
21 | */ | ||
22 | |||
23 | #ifndef __UNIT_UNIT_H__ | ||
24 | #define __UNIT_UNIT_H__ | ||
25 | |||
26 | struct gk20a; | ||
27 | |||
28 | struct unit_module; | ||
29 | typedef int (*module_test_fn)(struct unit_module *m, | ||
30 | struct gk20a *g, void *args); | ||
31 | |||
32 | #define UNIT_SUCCESS 0 | ||
33 | #define UNIT_FAIL -1 | ||
34 | |||
35 | struct unit_module_test { | ||
36 | /* | ||
37 | * Name of the test. | ||
38 | */ | ||
39 | const char *name; | ||
40 | |||
41 | /* | ||
42 | * Function to call to execute the test. | ||
43 | */ | ||
44 | module_test_fn fn; | ||
45 | |||
46 | /* | ||
47 | * A void pointer to arbitrary arguments. Lets the same unit test | ||
48 | * function perform multiple tests. This gets passed into the | ||
49 | * module_test_fn as @args. | ||
50 | */ | ||
51 | void *args; | ||
52 | }; | ||
53 | |||
54 | /* | ||
55 | * Interface to the unit test framework module loader. Each unit test module | ||
56 | * will have exactly one of these. | ||
57 | */ | ||
58 | struct unit_module { | ||
59 | /* | ||
60 | * Name of the module. | ||
61 | */ | ||
62 | const char *name; | ||
63 | |||
64 | /* | ||
65 | * NULL terminated list of tests within the module. | ||
66 | */ | ||
67 | struct unit_module_test *tests; | ||
68 | unsigned long nr_tests; | ||
69 | |||
70 | /* | ||
71 | * For the core FW to use. Not for modules!!! | ||
72 | */ | ||
73 | void *lib_handle; | ||
74 | struct unit_fw *fw; | ||
75 | }; | ||
76 | |||
77 | #define UNIT_MODULE(__name, __tests) \ | ||
78 | struct unit_module __unit_module__ = { \ | ||
79 | .name = #__name, \ | ||
80 | .tests = __tests, \ | ||
81 | .nr_tests = (sizeof(__tests) / \ | ||
82 | sizeof(struct unit_module_test)), \ | ||
83 | .lib_handle = NULL, \ | ||
84 | } | ||
85 | |||
86 | #define UNIT_TEST(__name, __fn, __args) \ | ||
87 | { \ | ||
88 | .name = #__name, \ | ||
89 | .fn = __fn, \ | ||
90 | .args = __args, \ | ||
91 | } | ||
92 | |||
93 | #define unit_return_fail(m, msg, ...) \ | ||
94 | do { \ | ||
95 | unit_err(m, "%s():%d " msg, \ | ||
96 | __func__, __LINE__, ##__VA_ARGS__); \ | ||
97 | return UNIT_FAIL; \ | ||
98 | } while (0) | ||
99 | |||
100 | #endif | ||