blob: 70c7b6cb6dca749a468256676e212702a4afd94e [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 */
Anthony Barbier7068f992017-10-26 15:23:08 +010039#ifdef ARM_COMPUTE_GC
40#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
41#endif /* ARM_COMPUTE_GC */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010042#include "arm_compute/runtime/Scheduler.h"
43
44#include <fstream>
45#include <initializer_list>
46#include <iostream>
47#include <memory>
48#include <random>
49#include <utility>
50
51using namespace arm_compute;
52using namespace arm_compute::test;
53
54namespace arm_compute
55{
56namespace test
57{
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010058std::unique_ptr<AssetsLibrary> library;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010059} // namespace test
60} // namespace arm_compute
61
62int main(int argc, char **argv)
63{
Anthony Barbier15d5ac82017-07-17 15:22:17 +010064#ifdef ARM_COMPUTE_CL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010065 CLScheduler::get().default_init();
Anthony Barbier15d5ac82017-07-17 15:22:17 +010066#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010067
Anthony Barbier7068f992017-10-26 15:23:08 +010068#ifdef ARM_COMPUTE_GC
69 GCScheduler::get().default_init();
70#endif /* ARM_COMPUTE_CL */
71
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010072 framework::Framework &framework = framework::Framework::get();
73
74 framework::CommandLineParser parser;
75
76 std::set<framework::InstrumentType> allowed_instruments
77 {
78 framework::InstrumentType::ALL,
79 framework::InstrumentType::NONE,
80 };
81
82 for(const auto &type : framework.available_instruments())
83 {
84 allowed_instruments.insert(type);
85 }
86
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010087 std::set<framework::DatasetMode> allowed_modes
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010088 {
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010089 framework::DatasetMode::PRECOMMIT,
90 framework::DatasetMode::NIGHTLY,
91 framework::DatasetMode::ALL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010092 };
93
94 std::set<framework::LogFormat> supported_log_formats
95 {
96 framework::LogFormat::NONE,
97 framework::LogFormat::PRETTY,
98 framework::LogFormat::JSON,
99 };
100
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100101 std::set<framework::LogLevel> supported_log_levels
102 {
103 framework::LogLevel::NONE,
104 framework::LogLevel::CONFIG,
105 framework::LogLevel::TESTS,
106 framework::LogLevel::ERRORS,
107 framework::LogLevel::DEBUG,
108 framework::LogLevel::MEASUREMENTS,
109 framework::LogLevel::ALL,
110 };
111
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100112 auto help = parser.add_option<framework::ToggleOption>("help");
113 help->set_help("Show this help message");
Anthony Barbier144d2ff2017-09-29 10:46:08 +0100114 auto dataset_mode = parser.add_option<framework::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100115 dataset_mode->set_help("For managed datasets select which group to use");
Anthony Barbier76310212017-10-11 14:08:03 +0100116 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 +0100117 instruments->set_help("Set the profiling instruments to use");
118 auto iterations = parser.add_option<framework::SimpleOption<int>>("iterations", 1);
119 iterations->set_help("Number of iterations per test case");
120 auto threads = parser.add_option<framework::SimpleOption<int>>("threads", 1);
121 threads->set_help("Number of threads to use");
122 auto log_format = parser.add_option<framework::EnumOption<framework::LogFormat>>("log-format", supported_log_formats, framework::LogFormat::PRETTY);
Giorgio Arenac5d54392017-10-31 15:18:49 +0000123 log_format->set_help("Output format for measurements and failures (affects only log-file)");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100124 auto filter = parser.add_option<framework::SimpleOption<std::string>>("filter", ".*");
125 filter->set_help("Regular expression to select test cases");
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100126 auto filter_id = parser.add_option<framework::SimpleOption<std::string>>("filter-id");
127 filter_id->set_help("List of test ids. ... can be used to define a range.");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100128 auto log_file = parser.add_option<framework::SimpleOption<std::string>>("log-file");
Giorgio Arenac5d54392017-10-31 15:18:49 +0000129 log_file->set_help("Write output to file instead of to the console (affected by log-format)");
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100130 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 +0100131 log_level->set_help("Verbosity of the output");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100132 auto throw_errors = parser.add_option<framework::ToggleOption>("throw-errors");
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100133 throw_errors->set_help("Don't catch fatal errors (useful for debugging)");
134 auto stop_on_error = parser.add_option<framework::ToggleOption>("stop-on-error");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100135 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100136 auto seed = parser.add_option<framework::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
137 seed->set_help("Global seed for random number generation");
138 auto color_output = parser.add_option<framework::ToggleOption>("color-output", true);
139 color_output->set_help("Produce colored output on the console");
140 auto list_tests = parser.add_option<framework::ToggleOption>("list-tests", false);
141 list_tests->set_help("List all test names");
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100142 auto test_instruments = parser.add_option<framework::ToggleOption>("test-instruments", false);
143 test_instruments->set_help("Test if the instruments work on the platform");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100144 auto error_on_missing_assets = parser.add_option<framework::ToggleOption>("error-on-missing-assets", false);
145 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 +0100146 auto assets = parser.add_positional_option<framework::SimpleOption<std::string>>("assets");
147 assets->set_help("Path to the assets directory");
Giorgio Arenac5d54392017-10-31 15:18:49 +0000148 auto pretty_console = parser.add_option<framework::ToggleOption>("pretty-console", true);
149 pretty_console->set_help("Produce pretty output on the console");
150 auto json_file = parser.add_option<framework::SimpleOption<std::string>>("json-file");
151 json_file->set_help("Write output to a json file.");
152 auto pretty_file = parser.add_option<framework::SimpleOption<std::string>>("pretty-file");
153 pretty_file->set_help("Write output to a text file");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100154
155 try
156 {
157 parser.parse(argc, argv);
158
159 if(help->is_set() && help->value())
160 {
161 parser.print_help(argv[0]);
162 return 0;
163 }
164
Giorgio Arenac5d54392017-10-31 15:18:49 +0000165 std::vector<std::unique_ptr<framework::Printer>> printers;
166 std::vector<std::shared_ptr<std::ofstream>> log_streams;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100167
Giorgio Arenac5d54392017-10-31 15:18:49 +0000168 if(pretty_console->value() && !(log_file->is_set() || log_format->value() != framework::LogFormat::PRETTY))
169 {
170 auto pretty_printer = support::cpp14::make_unique<framework::PrettyPrinter>();
171 pretty_printer->set_color_output(color_output->value());
172 printers.push_back(std::move(pretty_printer));
173 }
174
175 std::unique_ptr<framework::Printer> printer;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100176 switch(log_format->value())
177 {
178 case framework::LogFormat::JSON:
179 printer = support::cpp14::make_unique<framework::JSONPrinter>();
180 break;
181 case framework::LogFormat::NONE:
182 break;
183 case framework::LogFormat::PRETTY:
184 default:
Giorgio Arenac5d54392017-10-31 15:18:49 +0000185 printer = support::cpp14::make_unique<framework::PrettyPrinter>();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100186 break;
Giorgio Arenac5d54392017-10-31 15:18:49 +0000187 }
188
189 if(log_file->is_set())
190 {
191 log_streams.push_back(std::make_shared<std::ofstream>(log_file->value()));
192 if(printer != nullptr)
193 {
194 printer->set_stream(*log_streams.back().get());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100195 }
196 }
197
198 if(printer != nullptr)
199 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000200 printers.push_back(std::move(printer));
201 }
202
203 if(json_file->is_set())
204 {
205 printers.push_back(support::cpp14::make_unique<framework::JSONPrinter>());
206 log_streams.push_back(std::make_shared<std::ofstream>(json_file->value()));
207 printers.back()->set_stream(*log_streams.back().get());
208 }
209
210 if(pretty_file->is_set())
211 {
212 printers.push_back(support::cpp14::make_unique<framework::PrettyPrinter>());
213 log_streams.push_back(std::make_shared<std::ofstream>(pretty_file->value()));
214 printers.back()->set_stream(*log_streams.back().get());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100215 }
216
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100217 Scheduler::get().set_num_threads(threads->value());
218
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100219 if(log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100220 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000221 for(auto &p : printers)
222 {
223 p->print_global_header();
224 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100225 }
226
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100227 if(log_level->value() >= framework::LogLevel::CONFIG)
228 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000229 for(auto &p : printers)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100230 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000231 p->print_entry("Seed", support::cpp11::to_string(seed->value()));
232 p->print_entry("Iterations", support::cpp11::to_string(iterations->value()));
233 p->print_entry("Threads", support::cpp11::to_string(threads->value()));
234 {
235 using support::cpp11::to_string;
236 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
237 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100238 }
239 }
240
241 framework.init(instruments->value(), iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), log_level->value());
Giorgio Arenac5d54392017-10-31 15:18:49 +0000242 for(auto &p : printers)
243 {
244 framework.add_printer(p.get());
245 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100246 framework.set_throw_errors(throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100247 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100248 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100249
250 bool success = true;
251
252 if(list_tests->value())
253 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100254 for(const auto &info : framework.test_infos())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100255 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100256 std::cout << "[" << info.id << ", " << info.mode << ", " << info.status << "] " << info.name << "\n";
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100257 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100258
259 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100260 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100261
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100262 if(test_instruments->value())
263 {
264 framework::Profiler profiler = framework.get_profiler();
265 profiler.start();
266 profiler.stop();
Giorgio Arenac5d54392017-10-31 15:18:49 +0000267 for(auto &p : printers)
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100268 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000269 p->print_measurements(profiler.measurements());
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100270 }
Giorgio Arenac5d54392017-10-31 15:18:49 +0000271
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100272 return 0;
273 }
274
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100275 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100276
277 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100278 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100279 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100280 }
281
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100282 success = framework.run();
283
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100284 if(log_level->value() > framework::LogLevel::NONE)
285 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000286 for(auto &p : printers)
287 {
288 p->print_global_footer();
289 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100290 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100291
292 return (success ? 0 : 1);
293 }
294 catch(const std::exception &error)
295 {
296 std::cerr << error.what() << "\n";
297
298 if(throw_errors->value())
299 {
300 throw;
301 }
302
303 return 1;
304 }
305
306 return 0;
307}