diff options
Diffstat (limited to 'userspace/src/results.c')
-rw-r--r-- | userspace/src/results.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/userspace/src/results.c b/userspace/src/results.c new file mode 100644 index 00000000..ae077b82 --- /dev/null +++ b/userspace/src/results.c | |||
@@ -0,0 +1,128 @@ | |||
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 | #include <string.h> | ||
25 | |||
26 | #include <unit/io.h> | ||
27 | #include <unit/core.h> | ||
28 | #include <unit/unit.h> | ||
29 | #include <unit/results.h> | ||
30 | |||
31 | static int __init_results(struct unit_fw *fw) | ||
32 | { | ||
33 | struct unit_results *results; | ||
34 | |||
35 | if (fw->results != NULL) | ||
36 | return 0; | ||
37 | |||
38 | results = malloc(sizeof(*results)); | ||
39 | if (results == NULL) | ||
40 | return -1; | ||
41 | |||
42 | memset(results, 0, sizeof(*results)); | ||
43 | |||
44 | fw->results = results; | ||
45 | |||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | static void add_record(struct unit_test_list *list, | ||
50 | struct unit_test_record *tr) | ||
51 | { | ||
52 | /* | ||
53 | * First entry. | ||
54 | */ | ||
55 | if (list->head == NULL) { | ||
56 | list->head = tr; | ||
57 | list->last = tr; | ||
58 | return; | ||
59 | } | ||
60 | |||
61 | /* | ||
62 | * Add to the end of the list and update the pointer to the last entry | ||
63 | * in the list. This gives us O(1) add time. | ||
64 | */ | ||
65 | list->last->next = tr; | ||
66 | list->last = tr; | ||
67 | } | ||
68 | |||
69 | int core_add_test_record(struct unit_fw *fw, | ||
70 | struct unit_module *mod, | ||
71 | struct unit_module_test *test, | ||
72 | bool success) | ||
73 | { | ||
74 | struct unit_test_record *tr; | ||
75 | |||
76 | /* | ||
77 | * Dones nothing if results are already inited. | ||
78 | */ | ||
79 | if (__init_results(fw) != 0) | ||
80 | return -1; | ||
81 | |||
82 | tr = malloc(sizeof(*tr)); | ||
83 | if (tr == NULL) | ||
84 | return -1; | ||
85 | |||
86 | tr->mod = mod; | ||
87 | tr->test = test; | ||
88 | tr->status = success; | ||
89 | tr->next = NULL; | ||
90 | |||
91 | if (success) | ||
92 | add_record(&fw->results->passing, tr); | ||
93 | else | ||
94 | add_record(&fw->results->failing, tr); | ||
95 | |||
96 | fw->results->nr_tests += 1; | ||
97 | if (success) | ||
98 | fw->results->nr_passing += 1; | ||
99 | |||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | void core_print_test_status(struct unit_fw *fw) | ||
104 | { | ||
105 | struct unit_test_list *failing_tests = &fw->results->failing; | ||
106 | struct unit_test_record *rec; | ||
107 | |||
108 | /* | ||
109 | * Print stats for the tests. | ||
110 | */ | ||
111 | core_msg(fw, "\n"); | ||
112 | core_msg(fw, "Test results:\n"); | ||
113 | core_msg(fw, "-------------\n"); | ||
114 | core_msg(fw, "\n"); | ||
115 | core_msg(fw, " Passing: %d\n", fw->results->nr_passing); | ||
116 | core_msg(fw, " Failing: %d\n", | ||
117 | fw->results->nr_tests - fw->results->nr_passing); | ||
118 | core_msg(fw, " Total: %d\n", fw->results->nr_tests); | ||
119 | core_msg(fw, "\n"); | ||
120 | core_msg(fw, "Failing tests:\n"); | ||
121 | core_msg(fw, "\n"); | ||
122 | |||
123 | for_record_in_test_list(failing_tests, rec) { | ||
124 | core_msg(fw, " %s.%s\n", | ||
125 | rec->mod->name, | ||
126 | rec->test->name); | ||
127 | } | ||
128 | } | ||