blob: ee12a38d1a4f456a8fb656fe69095fde80021e51 [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"
30#include "tests/framework/command_line/CommandLineOptions.h"
31#include "tests/framework/command_line/CommandLineParser.h"
32#include "tests/framework/instruments/Instruments.h"
33#include "tests/framework/printers/Printers.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010034
Anthony Barbier15d5ac82017-07-17 15:22:17 +010035#ifdef ARM_COMPUTE_CL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010036#include "arm_compute/runtime/CL/CLScheduler.h"
Anthony Barbier15d5ac82017-07-17 15:22:17 +010037#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010038#include "arm_compute/runtime/Scheduler.h"
39
40#include <fstream>
41#include <initializer_list>
42#include <iostream>
43#include <memory>
44#include <random>
45#include <utility>
46
47using namespace arm_compute;
48using namespace arm_compute::test;
49
50namespace arm_compute
51{
52namespace test
53{
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010054std::unique_ptr<AssetsLibrary> library;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010055} // namespace test
56} // namespace arm_compute
57
58int main(int argc, char **argv)
59{
Anthony Barbier15d5ac82017-07-17 15:22:17 +010060#ifdef ARM_COMPUTE_CL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010061 CLScheduler::get().default_init();
Anthony Barbier15d5ac82017-07-17 15:22:17 +010062#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010063
64 framework::Framework &framework = framework::Framework::get();
65
66 framework::CommandLineParser parser;
67
68 std::set<framework::InstrumentType> allowed_instruments
69 {
70 framework::InstrumentType::ALL,
71 framework::InstrumentType::NONE,
72 };
73
74 for(const auto &type : framework.available_instruments())
75 {
76 allowed_instruments.insert(type);
77 }
78
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010079 std::set<framework::DatasetMode> allowed_modes
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010080 {
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010081 framework::DatasetMode::PRECOMMIT,
82 framework::DatasetMode::NIGHTLY,
83 framework::DatasetMode::ALL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010084 };
85
86 std::set<framework::LogFormat> supported_log_formats
87 {
88 framework::LogFormat::NONE,
89 framework::LogFormat::PRETTY,
90 framework::LogFormat::JSON,
91 };
92
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010093 std::set<framework::LogLevel> supported_log_levels
94 {
95 framework::LogLevel::NONE,
96 framework::LogLevel::CONFIG,
97 framework::LogLevel::TESTS,
98 framework::LogLevel::ERRORS,
99 framework::LogLevel::DEBUG,
100 framework::LogLevel::MEASUREMENTS,
101 framework::LogLevel::ALL,
102 };
103
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100104 auto help = parser.add_option<framework::ToggleOption>("help");
105 help->set_help("Show this help message");
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +0100106 auto dataset_mode = parser.add_option<framework::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::ALL);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100107 dataset_mode->set_help("For managed datasets select which group to use");
108 auto instruments = parser.add_option<framework::EnumListOption<framework::InstrumentType>>("instruments", allowed_instruments, std::initializer_list<framework::InstrumentType> { framework::InstrumentType::ALL });
109 instruments->set_help("Set the profiling instruments to use");
110 auto iterations = parser.add_option<framework::SimpleOption<int>>("iterations", 1);
111 iterations->set_help("Number of iterations per test case");
112 auto threads = parser.add_option<framework::SimpleOption<int>>("threads", 1);
113 threads->set_help("Number of threads to use");
114 auto log_format = parser.add_option<framework::EnumOption<framework::LogFormat>>("log-format", supported_log_formats, framework::LogFormat::PRETTY);
115 log_format->set_help("Output format for measurements and failures");
116 auto filter = parser.add_option<framework::SimpleOption<std::string>>("filter", ".*");
117 filter->set_help("Regular expression to select test cases");
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100118 auto filter_id = parser.add_option<framework::SimpleOption<std::string>>("filter-id");
119 filter_id->set_help("List of test ids. ... can be used to define a range.");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100120 auto log_file = parser.add_option<framework::SimpleOption<std::string>>("log-file");
121 log_file->set_help("Write output to file instead of to the console");
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100122 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 +0100123 log_level->set_help("Verbosity of the output");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100124 auto throw_errors = parser.add_option<framework::ToggleOption>("throw-errors");
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100125 throw_errors->set_help("Don't catch fatal errors (useful for debugging)");
126 auto stop_on_error = parser.add_option<framework::ToggleOption>("stop-on-error");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100127 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100128 auto seed = parser.add_option<framework::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
129 seed->set_help("Global seed for random number generation");
130 auto color_output = parser.add_option<framework::ToggleOption>("color-output", true);
131 color_output->set_help("Produce colored output on the console");
132 auto list_tests = parser.add_option<framework::ToggleOption>("list-tests", false);
133 list_tests->set_help("List all test names");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100134 auto error_on_missing_assets = parser.add_option<framework::ToggleOption>("error-on-missing-assets", false);
135 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 +0100136 auto assets = parser.add_positional_option<framework::SimpleOption<std::string>>("assets");
137 assets->set_help("Path to the assets directory");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100138
139 try
140 {
141 parser.parse(argc, argv);
142
143 if(help->is_set() && help->value())
144 {
145 parser.print_help(argv[0]);
146 return 0;
147 }
148
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100149 std::unique_ptr<framework::Printer> printer;
150 std::ofstream log_stream;
151
152 switch(log_format->value())
153 {
154 case framework::LogFormat::JSON:
155 printer = support::cpp14::make_unique<framework::JSONPrinter>();
156 break;
157 case framework::LogFormat::NONE:
158 break;
159 case framework::LogFormat::PRETTY:
160 default:
161 {
162 auto pretty_printer = support::cpp14::make_unique<framework::PrettyPrinter>();
163 pretty_printer->set_color_output(color_output->value());
164 printer = std::move(pretty_printer);
165 break;
166 }
167 }
168
169 if(printer != nullptr)
170 {
171 if(log_file->is_set())
172 {
173 log_stream.open(log_file->value());
174 printer->set_stream(log_stream);
175 }
176 }
177
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100178 Scheduler::get().set_num_threads(threads->value());
179
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100180 if(log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100181 {
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100182 printer->print_global_header();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100183 }
184
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100185 if(log_level->value() >= framework::LogLevel::CONFIG)
186 {
187 printer->print_entry("Seed", support::cpp11::to_string(seed->value()));
188 printer->print_entry("Iterations", support::cpp11::to_string(iterations->value()));
189 printer->print_entry("Threads", support::cpp11::to_string(threads->value()));
190 {
191 using support::cpp11::to_string;
192 printer->print_entry("Dataset mode", to_string(dataset_mode->value()));
193 }
194 }
195
196 framework.init(instruments->value(), iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), log_level->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100197 framework.set_printer(printer.get());
198 framework.set_throw_errors(throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100199 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100200 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100201
202 bool success = true;
203
204 if(list_tests->value())
205 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100206 for(const auto &info : framework.test_infos())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100207 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100208 std::cout << "[" << info.id << ", " << info.mode << ", " << info.status << "] " << info.name << "\n";
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100209 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100210
211 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100212 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100213
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100214 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100215
216 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100217 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100218 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100219 }
220
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100221 success = framework.run();
222
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100223 if(log_level->value() > framework::LogLevel::NONE)
224 {
225 printer->print_global_footer();
226 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100227
228 return (success ? 0 : 1);
229 }
230 catch(const std::exception &error)
231 {
232 std::cerr << error.what() << "\n";
233
234 if(throw_errors->value())
235 {
236 throw;
237 }
238
239 return 1;
240 }
241
242 return 0;
243}