blob: 5bdd665068acd91afe57920c196a3f9528ace116 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010024#include "support/ToolchainSupport.h"
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010025#include "tests/AssetsLibrary.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010026#include "tests/framework/DatasetModes.h"
27#include "tests/framework/Exceptions.h"
28#include "tests/framework/Framework.h"
29#include "tests/framework/Macros.h"
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +010030#include "tests/framework/Profiler.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/framework/command_line/CommandLineOptions.h"
32#include "tests/framework/command_line/CommandLineParser.h"
33#include "tests/framework/instruments/Instruments.h"
34#include "tests/framework/printers/Printers.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010035
Anthony Barbier15d5ac82017-07-17 15:22:17 +010036#ifdef ARM_COMPUTE_CL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010037#include "arm_compute/runtime/CL/CLScheduler.h"
Anthony Barbier15d5ac82017-07-17 15:22:17 +010038#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010039#include "arm_compute/runtime/Scheduler.h"
40
41#include <fstream>
42#include <initializer_list>
43#include <iostream>
44#include <memory>
45#include <random>
46#include <utility>
47
48using namespace arm_compute;
49using namespace arm_compute::test;
50
51namespace arm_compute
52{
53namespace test
54{
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010055std::unique_ptr<AssetsLibrary> library;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010056} // namespace test
57} // namespace arm_compute
58
59int main(int argc, char **argv)
60{
Anthony Barbier15d5ac82017-07-17 15:22:17 +010061#ifdef ARM_COMPUTE_CL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010062 CLScheduler::get().default_init();
Anthony Barbier15d5ac82017-07-17 15:22:17 +010063#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010064
65 framework::Framework &framework = framework::Framework::get();
66
67 framework::CommandLineParser parser;
68
69 std::set<framework::InstrumentType> allowed_instruments
70 {
71 framework::InstrumentType::ALL,
72 framework::InstrumentType::NONE,
73 };
74
75 for(const auto &type : framework.available_instruments())
76 {
77 allowed_instruments.insert(type);
78 }
79
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010080 std::set<framework::DatasetMode> allowed_modes
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010081 {
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010082 framework::DatasetMode::PRECOMMIT,
83 framework::DatasetMode::NIGHTLY,
84 framework::DatasetMode::ALL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010085 };
86
87 std::set<framework::LogFormat> supported_log_formats
88 {
89 framework::LogFormat::NONE,
90 framework::LogFormat::PRETTY,
91 framework::LogFormat::JSON,
92 };
93
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010094 std::set<framework::LogLevel> supported_log_levels
95 {
96 framework::LogLevel::NONE,
97 framework::LogLevel::CONFIG,
98 framework::LogLevel::TESTS,
99 framework::LogLevel::ERRORS,
100 framework::LogLevel::DEBUG,
101 framework::LogLevel::MEASUREMENTS,
102 framework::LogLevel::ALL,
103 };
104
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100105 auto help = parser.add_option<framework::ToggleOption>("help");
106 help->set_help("Show this help message");
Anthony Barbier144d2ff2017-09-29 10:46:08 +0100107 auto dataset_mode = parser.add_option<framework::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100108 dataset_mode->set_help("For managed datasets select which group to use");
Anthony Barbier76310212017-10-11 14:08:03 +0100109 auto instruments = parser.add_option<framework::EnumListOption<framework::InstrumentType>>("instruments", allowed_instruments, std::initializer_list<framework::InstrumentType> { framework::InstrumentType::WALL_CLOCK_TIMER });
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100110 instruments->set_help("Set the profiling instruments to use");
111 auto iterations = parser.add_option<framework::SimpleOption<int>>("iterations", 1);
112 iterations->set_help("Number of iterations per test case");
113 auto threads = parser.add_option<framework::SimpleOption<int>>("threads", 1);
114 threads->set_help("Number of threads to use");
115 auto log_format = parser.add_option<framework::EnumOption<framework::LogFormat>>("log-format", supported_log_formats, framework::LogFormat::PRETTY);
116 log_format->set_help("Output format for measurements and failures");
117 auto filter = parser.add_option<framework::SimpleOption<std::string>>("filter", ".*");
118 filter->set_help("Regular expression to select test cases");
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100119 auto filter_id = parser.add_option<framework::SimpleOption<std::string>>("filter-id");
120 filter_id->set_help("List of test ids. ... can be used to define a range.");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100121 auto log_file = parser.add_option<framework::SimpleOption<std::string>>("log-file");
122 log_file->set_help("Write output to file instead of to the console");
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100123 auto log_level = parser.add_option<framework::EnumOption<framework::LogLevel>>("log-level", supported_log_levels, framework::LogLevel::ALL);
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100124 log_level->set_help("Verbosity of the output");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100125 auto throw_errors = parser.add_option<framework::ToggleOption>("throw-errors");
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100126 throw_errors->set_help("Don't catch fatal errors (useful for debugging)");
127 auto stop_on_error = parser.add_option<framework::ToggleOption>("stop-on-error");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100128 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100129 auto seed = parser.add_option<framework::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
130 seed->set_help("Global seed for random number generation");
131 auto color_output = parser.add_option<framework::ToggleOption>("color-output", true);
132 color_output->set_help("Produce colored output on the console");
133 auto list_tests = parser.add_option<framework::ToggleOption>("list-tests", false);
134 list_tests->set_help("List all test names");
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100135 auto test_instruments = parser.add_option<framework::ToggleOption>("test-instruments", false);
136 test_instruments->set_help("Test if the instruments work on the platform");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100137 auto error_on_missing_assets = parser.add_option<framework::ToggleOption>("error-on-missing-assets", false);
138 error_on_missing_assets->set_help("Mark a test as failed instead of skipping it when assets are missing");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100139 auto assets = parser.add_positional_option<framework::SimpleOption<std::string>>("assets");
140 assets->set_help("Path to the assets directory");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100141
142 try
143 {
144 parser.parse(argc, argv);
145
146 if(help->is_set() && help->value())
147 {
148 parser.print_help(argv[0]);
149 return 0;
150 }
151
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100152 std::unique_ptr<framework::Printer> printer;
153 std::ofstream log_stream;
154
155 switch(log_format->value())
156 {
157 case framework::LogFormat::JSON:
158 printer = support::cpp14::make_unique<framework::JSONPrinter>();
159 break;
160 case framework::LogFormat::NONE:
161 break;
162 case framework::LogFormat::PRETTY:
163 default:
164 {
165 auto pretty_printer = support::cpp14::make_unique<framework::PrettyPrinter>();
166 pretty_printer->set_color_output(color_output->value());
167 printer = std::move(pretty_printer);
168 break;
169 }
170 }
171
172 if(printer != nullptr)
173 {
174 if(log_file->is_set())
175 {
176 log_stream.open(log_file->value());
177 printer->set_stream(log_stream);
178 }
179 }
180
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100181 Scheduler::get().set_num_threads(threads->value());
182
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100183 if(log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100184 {
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100185 printer->print_global_header();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100186 }
187
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100188 if(log_level->value() >= framework::LogLevel::CONFIG)
189 {
190 printer->print_entry("Seed", support::cpp11::to_string(seed->value()));
191 printer->print_entry("Iterations", support::cpp11::to_string(iterations->value()));
192 printer->print_entry("Threads", support::cpp11::to_string(threads->value()));
193 {
194 using support::cpp11::to_string;
195 printer->print_entry("Dataset mode", to_string(dataset_mode->value()));
196 }
197 }
198
199 framework.init(instruments->value(), iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), log_level->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100200 framework.set_printer(printer.get());
201 framework.set_throw_errors(throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100202 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100203 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100204
205 bool success = true;
206
207 if(list_tests->value())
208 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100209 for(const auto &info : framework.test_infos())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100210 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100211 std::cout << "[" << info.id << ", " << info.mode << ", " << info.status << "] " << info.name << "\n";
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100212 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100213
214 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100215 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100216
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100217 if(test_instruments->value())
218 {
219 framework::Profiler profiler = framework.get_profiler();
220 profiler.start();
221 profiler.stop();
222 if(printer != nullptr)
223 {
224 printer->print_measurements(profiler.measurements());
225 }
226 return 0;
227 }
228
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100229 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100230
231 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100232 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100233 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100234 }
235
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100236 success = framework.run();
237
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100238 if(log_level->value() > framework::LogLevel::NONE)
239 {
240 printer->print_global_footer();
241 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100242
243 return (success ? 0 : 1);
244 }
245 catch(const std::exception &error)
246 {
247 std::cerr << error.what() << "\n";
248
249 if(throw_errors->value())
250 {
251 throw;
252 }
253
254 return 1;
255 }
256
257 return 0;
258}