diff options
Diffstat (limited to 'userspace/src/exec.c')
-rw-r--r-- | userspace/src/exec.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/userspace/src/exec.c b/userspace/src/exec.c new file mode 100644 index 00000000..b9ba1336 --- /dev/null +++ b/userspace/src/exec.c | |||
@@ -0,0 +1,90 @@ | |||
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 | #include <stdlib.h> | ||
24 | |||
25 | #include <unit/io.h> | ||
26 | #include <unit/core.h> | ||
27 | #include <unit/unit.h> | ||
28 | #include <unit/module.h> | ||
29 | #include <unit/results.h> | ||
30 | |||
31 | #include <nvgpu/posix/probe.h> | ||
32 | |||
33 | /* | ||
34 | * Execute a module and all its subtests. This function builds a gk20a for the | ||
35 | * test to use by executing nvgpu_posix_probe() and nvgpu_posix_cleanup(); | ||
36 | */ | ||
37 | static int core_exec_module(struct unit_fw *fw, | ||
38 | struct unit_module *module) | ||
39 | { | ||
40 | unsigned int i; | ||
41 | struct gk20a *g = fw->nvgpu.nvgpu_posix_probe(); | ||
42 | |||
43 | if (!g) | ||
44 | return -1; | ||
45 | |||
46 | core_vbs(fw, 1, "Execing module: %s\n", module->name); | ||
47 | |||
48 | /* | ||
49 | * Execute each test within the module. No reinit is done between tests. | ||
50 | * Thats up to the module itself to handle. Any setup/teardown between | ||
51 | * unit tests must be handled within the module. | ||
52 | */ | ||
53 | for (i = 0; i < module->nr_tests; i++) { | ||
54 | struct unit_module_test *t = module->tests + i; | ||
55 | int test_status; | ||
56 | |||
57 | core_msg(fw, "Running %s.%s\n", module->name, t->name); | ||
58 | test_status = t->fn(module, g, t->args); | ||
59 | |||
60 | if (test_status != UNIT_SUCCESS) | ||
61 | core_msg_color(fw, C_RED, | ||
62 | " Unit error! Test %s.%s FAILED!\n", | ||
63 | module->name, t->name); | ||
64 | |||
65 | core_add_test_record(fw, module, t, | ||
66 | test_status == UNIT_SUCCESS); | ||
67 | } | ||
68 | |||
69 | fw->nvgpu.nvgpu_posix_cleanup(g); | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | /* | ||
75 | * Execute all modules loaded by the unit test framework. | ||
76 | */ | ||
77 | int core_exec(struct unit_fw *fw) | ||
78 | { | ||
79 | int ret; | ||
80 | struct unit_module **modules; | ||
81 | |||
82 | for (modules = fw->modules; *modules != NULL; modules++) { | ||
83 | ret = core_exec_module(fw, *modules); | ||
84 | |||
85 | if (ret != 0) | ||
86 | return ret; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||