Line | Branch | Exec | Source |
---|---|---|---|
1 | /* -*- c++ -*- */ | ||
2 | /* | ||
3 | * Copyright 2012-2014 Free Software Foundation, Inc. | ||
4 | * | ||
5 | * This file is part of VOLK | ||
6 | * | ||
7 | * SPDX-License-Identifier: LGPL-3.0-or-later | ||
8 | */ | ||
9 | |||
10 | #include <stdbool.h> // for bool, false, true | ||
11 | #include <fstream> // IWYU pragma: keep | ||
12 | #include <iostream> // for operator<<, basic_ostream, endl, char... | ||
13 | #include <map> // for map, map<>::iterator, _Rb_tree_iterator | ||
14 | #include <string> // for string, operator<< | ||
15 | #include <utility> // for pair | ||
16 | #include <vector> // for vector | ||
17 | |||
18 | #include "kernel_tests.h" // for init_test_list | ||
19 | #include "qa_utils.h" // for volk_test_case_t, volk_test_results_t | ||
20 | #include "volk/volk_complex.h" // for lv_32fc_t | ||
21 | #include <volk/volk.h> | ||
22 | |||
23 | void print_qa_xml(std::vector<volk_test_results_t> results, unsigned int nfails); | ||
24 | |||
25 | 282 | int main(int argc, char* argv[]) | |
26 | { | ||
27 | 282 | bool qa_ret_val = 0; | |
28 | |||
29 | 282 | float def_tol = 1e-6; | |
30 | 282 | lv_32fc_t def_scalar = 327.0; | |
31 | 282 | int def_iter = 1; | |
32 | 282 | int def_vlen = 131071; | |
33 | 282 | bool def_benchmark_mode = true; | |
34 |
1/2✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
|
282 | std::string def_kernel_regex = ""; |
35 | |||
36 | volk_test_params_t test_params( | ||
37 |
2/4✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 282 times.
✗ Branch 5 not taken.
|
282 | def_tol, def_scalar, def_vlen, def_iter, def_benchmark_mode, def_kernel_regex); |
38 |
2/4✓ Branch 1 taken 282 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 282 times.
✗ Branch 5 not taken.
|
282 | std::vector<volk_test_case_t> test_cases = init_test_list(test_params); |
39 | 282 | std::vector<volk_test_results_t> results; | |
40 | |||
41 |
1/2✓ Branch 0 taken 282 times.
✗ Branch 1 not taken.
|
282 | if (argc > 1) { |
42 |
2/2✓ Branch 1 taken 19470 times.
✓ Branch 2 taken 46 times.
|
19516 | for (unsigned int ii = 0; ii < test_cases.size(); ++ii) { |
43 |
4/6✓ Branch 2 taken 19470 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 19470 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 236 times.
✓ Branch 11 taken 19234 times.
|
58410 | if (std::string(argv[1]) == test_cases[ii].name()) { |
44 |
1/2✓ Branch 2 taken 236 times.
✗ Branch 3 not taken.
|
236 | volk_test_case_t test_case = test_cases[ii]; |
45 |
1/2✓ Branch 3 taken 236 times.
✗ Branch 4 not taken.
|
236 | if (run_volk_tests(test_case.desc(), |
46 | test_case.kernel_ptr(), | ||
47 |
1/2✓ Branch 1 taken 236 times.
✗ Branch 2 not taken.
|
472 | test_case.name(), |
48 |
1/2✓ Branch 1 taken 236 times.
✗ Branch 2 not taken.
|
472 | test_case.test_parameters(), |
49 | &results, | ||
50 |
2/4✓ Branch 1 taken 236 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 236 times.
|
472 | test_case.puppet_master_name())) { |
51 | ✗ | return 1; | |
52 | } else { | ||
53 | 236 | return 0; | |
54 | } | ||
55 | 236 | } | |
56 | } | ||
57 |
4/8✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 46 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 46 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 46 times.
✗ Branch 11 not taken.
|
138 | std::cerr << "Did not run a test for kernel: " << std::string(argv[1]) << " !" |
58 |
1/2✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
|
46 | << std::endl; |
59 | 46 | return 0; | |
60 | |||
61 | } else { | ||
62 | ✗ | std::vector<std::string> qa_failures; | |
63 | // Test every kernel reporting failures when they occur | ||
64 | ✗ | for (unsigned int ii = 0; ii < test_cases.size(); ++ii) { | |
65 | ✗ | bool qa_result = false; | |
66 | ✗ | volk_test_case_t test_case = test_cases[ii]; | |
67 | try { | ||
68 | ✗ | qa_result = run_volk_tests(test_case.desc(), | |
69 | test_case.kernel_ptr(), | ||
70 | ✗ | test_case.name(), | |
71 | ✗ | test_case.test_parameters(), | |
72 | &results, | ||
73 | ✗ | test_case.puppet_master_name()); | |
74 | ✗ | } catch (...) { | |
75 | // TODO: what exceptions might we need to catch and how do we handle them? | ||
76 | ✗ | std::cerr << "Exception found on kernel: " << test_case.name() | |
77 | ✗ | << std::endl; | |
78 | ✗ | qa_result = false; | |
79 | ✗ | } | |
80 | |||
81 | ✗ | if (qa_result) { | |
82 | ✗ | std::cerr << "Failure on " << test_case.name() << std::endl; | |
83 | ✗ | qa_failures.push_back(test_case.name()); | |
84 | } | ||
85 | ✗ | } | |
86 | |||
87 | // Generate XML results | ||
88 | ✗ | print_qa_xml(results, qa_failures.size()); | |
89 | |||
90 | // Summarize QA results | ||
91 | ✗ | std::cerr << "Kernel QA finished: " << qa_failures.size() << " failures out of " | |
92 | ✗ | << test_cases.size() << " tests." << std::endl; | |
93 | ✗ | if (qa_failures.size() > 0) { | |
94 | ✗ | std::cerr << "The following kernels failed QA:" << std::endl; | |
95 | ✗ | for (unsigned int ii = 0; ii < qa_failures.size(); ++ii) { | |
96 | ✗ | std::cerr << " " << qa_failures[ii] << std::endl; | |
97 | } | ||
98 | ✗ | qa_ret_val = 1; | |
99 | } | ||
100 | ✗ | } | |
101 | |||
102 | ✗ | return qa_ret_val; | |
103 | 282 | } | |
104 | |||
105 | /* | ||
106 | * This function prints qa results as XML output similar to output | ||
107 | * from Junit. For reference output see http://llg.cubic.org/docs/junit/ | ||
108 | */ | ||
109 | ✗ | void print_qa_xml(std::vector<volk_test_results_t> results, unsigned int nfails) | |
110 | { | ||
111 | ✗ | std::ofstream qa_file; | |
112 | ✗ | qa_file.open(".unittest/kernels.xml"); | |
113 | |||
114 | ✗ | qa_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; | |
115 | qa_file << "<testsuites name=\"kernels\" " | ||
116 | ✗ | << "tests=\"" << results.size() << "\" " | |
117 | ✗ | << "failures=\"" << nfails << "\" id=\"1\">" << std::endl; | |
118 | |||
119 | // Results are in a vector by kernel. Each element has a result | ||
120 | // map containing time and arch name with test result | ||
121 | ✗ | for (unsigned int ii = 0; ii < results.size(); ++ii) { | |
122 | ✗ | volk_test_results_t result = results[ii]; | |
123 | ✗ | qa_file << " <testsuite name=\"" << result.name << "\">" << std::endl; | |
124 | |||
125 | ✗ | std::map<std::string, volk_test_time_t>::iterator kernel_time_pair; | |
126 | ✗ | for (kernel_time_pair = result.results.begin(); | |
127 | ✗ | kernel_time_pair != result.results.end(); | |
128 | ✗ | ++kernel_time_pair) { | |
129 | ✗ | volk_test_time_t test_time = kernel_time_pair->second; | |
130 | qa_file << " <testcase name=\"" << test_time.name << "\" " | ||
131 | << "classname=\"" << result.name << "\" " | ||
132 | ✗ | << "time=\"" << test_time.time << "\">" << std::endl; | |
133 | ✗ | if (!test_time.pass) | |
134 | qa_file << " <failure " | ||
135 | << "message=\"fail on arch " << test_time.name << "\">" | ||
136 | ✗ | << "</failure>" << std::endl; | |
137 | ✗ | qa_file << " </testcase>" << std::endl; | |
138 | ✗ | } | |
139 | ✗ | qa_file << " </testsuite>" << std::endl; | |
140 | ✗ | } | |
141 | |||
142 | |||
143 | ✗ | qa_file << "</testsuites>" << std::endl; | |
144 | ✗ | qa_file.close(); | |
145 | ✗ | } | |
146 |