summaryrefslogtreecommitdiffstats
path: root/userspace/include
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2018-06-27 17:45:07 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-08-10 02:11:06 -0400
commit691bf904451bfe2e4c44ea05319149996abbbbf1 (patch)
tree0fe66bd37989f9d619234b7f4d2be1df6ed61c85 /userspace/include
parent6e746a97cc7ee2bc5a3adee04dd9c65b3921eee5 (diff)
gpu: nvgpu: unit: Add unit testing FW
Full documentation for this is in the unit testing confluence page. JIRA NVGPU-525 Bug 2261555 Change-Id: I463e6267eb0eb12b7313f8b275266e8faabe5ccf Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1683915 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/include')
-rw-r--r--userspace/include/unit/args.h58
-rw-r--r--userspace/include/unit/core.h63
-rw-r--r--userspace/include/unit/io.h88
-rw-r--r--userspace/include/unit/module.h31
-rw-r--r--userspace/include/unit/results.h70
-rw-r--r--userspace/include/unit/unit.h100
6 files changed, 410 insertions, 0 deletions
diff --git a/userspace/include/unit/args.h b/userspace/include/unit/args.h
new file mode 100644
index 00000000..def84a29
--- /dev/null
+++ b/userspace/include/unit/args.h
@@ -0,0 +1,58 @@
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_ARGS_H__
24#define __UNIT_ARGS_H__
25
26#include <stdbool.h>
27
28/*
29 * Allow defaults to be changed at compile time.
30 */
31#define __stringify(x) #x
32#define stringify(x) __stringify(x)
33
34#ifndef __DEFAULT_ARG_UNIT_LOAD_PATH
35#define __DEFAULT_ARG_UNIT_LOAD_PATH build/units
36#endif
37#define DEFAULT_ARG_UNIT_LOAD_PATH stringify(__DEFAULT_ARG_UNIT_LOAD_PATH)
38
39struct unit_fw;
40
41struct unit_fw_args {
42 bool help;
43 int verbose_lvl;
44 bool no_color;
45
46 const char *unit_name;
47 const char *unit_load_path;
48};
49
50int core_parse_args(struct unit_fw *fw, int argc, char **argv);
51void core_print_help(struct unit_fw *fw);
52
53/*
54 * Convenience for getting the args struct pointer.
55 */
56#define args(fw) ((fw)->args)
57
58#endif
diff --git a/userspace/include/unit/core.h b/userspace/include/unit/core.h
new file mode 100644
index 00000000..d9d119db
--- /dev/null
+++ b/userspace/include/unit/core.h
@@ -0,0 +1,63 @@
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_CORE_H__
24#define __UNIT_CORE_H__
25
26struct unit_fw_args;
27struct unit_modules;
28struct unit_results;
29
30struct gk20a;
31
32/*
33 * The core unit testing framework data structure. Keeps track of global state
34 * for the unit test app.
35 */
36struct unit_fw {
37 struct unit_fw_args *args;
38
39 struct unit_module **modules;
40
41 struct unit_results *results;
42
43 /*
44 * nvgpu-drv interface. Currently the only two directly referenced
45 * functions are:
46 *
47 * nvgpu_posix_probe()
48 * nvgpu_posix_cleanup()
49 *
50 * There will get populated so that we can call them before/after each
51 * module.
52 */
53 void *nvgpu_so;
54 struct {
55 struct gk20a *(*nvgpu_posix_probe)(void);
56 void (*nvgpu_posix_cleanup)(struct gk20a *g);
57 } nvgpu;
58};
59
60int core_load_nvgpu(struct unit_fw *fw);
61int core_exec(struct unit_fw *fw);
62
63#endif
diff --git a/userspace/include/unit/io.h b/userspace/include/unit/io.h
new file mode 100644
index 00000000..1fd0fa43
--- /dev/null
+++ b/userspace/include/unit/io.h
@@ -0,0 +1,88 @@
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_IO_H__
24#define __UNIT_IO_H__
25
26struct unit_fw;
27struct unit_module;
28
29/*
30 * necessary for args(fw) macro. IO will always, in general, depend on args
31 * since the args will specify where IO should be directed to.
32 */
33#include <unit/args.h>
34
35#define core_msg(fw, msg, ...) \
36 core_vbs(fw, 0, msg, ##__VA_ARGS__)
37#define core_msg_color(fw, color, msg, ...) \
38 core_vbs_color(fw, color, 0, msg, ##__VA_ARGS__)
39
40#define core_vbs_color(fw, color, lvl, msg, ...) \
41 do { \
42 if ((lvl) > args(fw)->verbose_lvl) \
43 continue; \
44 \
45 /* Print if verbosity level is high enough. */ \
46 __core_print_stdout(fw, color, msg, ##__VA_ARGS__); \
47 } while (0)
48#define core_vbs(fw, lvl, msg, ...) \
49 core_vbs_color(fw, NULL, lvl, msg, ##__VA_ARGS__)
50
51#define core_err(fw, msg, ...) \
52 __core_print_stderr(fw, "(%s:%d) " msg, \
53 __func__, __LINE__, ##__VA_ARGS__)
54
55/*
56 * Output macro for unit tests to use.
57 */
58#define unit_info(unit, msg, ...) \
59 __unit_info_color(unit, NULL, msg, ##__VA_ARGS__)
60#define unit_err(unit, msg, ...) \
61 __unit_info_color(unit, C_RED, msg, ##__VA_ARGS__)
62
63/*
64 * Don't go overboard with these!!!
65 */
66#define C_RED "\x1B[31m"
67#define C_GREEN "\x1B[32m"
68#define C_YELLOW "\x1B[33m"
69#define C_BLUE "\x1B[34m"
70#define C_MAGENTA "\x1B[35m"
71#define C_CYAN "\x1B[36m"
72#define C_WHITE "\x1B[37m"
73#define C_RESET "\x1B[0m"
74
75/*
76 * Printing functions. Do not use these directly. Instead use the provided
77 * macros.
78 */
79__attribute__((format (printf, 3, 4)))
80void __core_print_stdout(struct unit_fw *fw, const char *color,
81 const char *fmt, ...);
82__attribute__((format (printf, 2, 3)))
83void __core_print_stderr(struct unit_fw *fw, const char *fmt, ...);
84__attribute__((format (printf, 3, 4)))
85void __unit_info_color(struct unit_module *unit, const char *color,
86 const char *fmt, ...);
87
88#endif
diff --git a/userspace/include/unit/module.h b/userspace/include/unit/module.h
new file mode 100644
index 00000000..79737d61
--- /dev/null
+++ b/userspace/include/unit/module.h
@@ -0,0 +1,31 @@
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_MODULE_H__
24#define __UNIT_MODULE_H__
25
26struct unit_fw;
27struct unit_module;
28
29struct unit_module **core_load_modules(struct unit_fw *fw);
30
31#endif
diff --git a/userspace/include/unit/results.h b/userspace/include/unit/results.h
new file mode 100644
index 00000000..fb88e59d
--- /dev/null
+++ b/userspace/include/unit/results.h
@@ -0,0 +1,70 @@
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_RESULTS_H__
24#define __UNIT_RESULTS_H__
25
26/*
27 * Keep track of the the results of a set of unit tests. This is effectively
28 * just a single linked list of records for each test.
29 */
30
31struct unit_test_record {
32 /*
33 * Let's us determine the name of the test.
34 */
35 struct unit_module *mod;
36 struct unit_module_test *test;
37
38 /*
39 * True for pass, false for fail.
40 */
41 bool status;
42
43 struct unit_test_record *next;
44};
45
46struct unit_test_list {
47 struct unit_test_record *head;
48 struct unit_test_record *last;
49};
50
51struct unit_results {
52 struct unit_test_list passing;
53 struct unit_test_list failing;
54
55 int nr_tests;
56 int nr_passing;
57};
58
59#define for_record_in_test_list(__test_list, __test) \
60 for ((__test) = (__test_list)->head; \
61 (__test) != NULL; \
62 (__test) = (__test)->next)
63
64int core_add_test_record(struct unit_fw *fw,
65 struct unit_module *mod,
66 struct unit_module_test *test,
67 bool success);
68void core_print_test_status(struct unit_fw *fw);
69
70#endif
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
26struct gk20a;
27
28struct unit_module;
29typedef 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
35struct 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 */
58struct 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