blob: 1f1f33a156feea214edf34fcfabfb12e041562cc [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);
123 log_format->set_help("Output format for measurements and failures");
124 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");
129 log_file->set_help("Write output to file instead of to the console");
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");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100148
149 try
150 {
151 parser.parse(argc, argv);
152
153 if(help->is_set() && help->value())
154 {
155 parser.print_help(argv[0]);
156 return 0;
157 }
158
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100159 std::unique_ptr<framework::Printer> printer;
160 std::ofstream log_stream;
161
162 switch(log_format->value())
163 {
164 case framework::LogFormat::JSON:
165 printer = support::cpp14::make_unique<framework::JSONPrinter>();
166 break;
167 case framework::LogFormat::NONE:
168 break;
169 case framework::LogFormat::PRETTY:
170 default:
171 {
172 auto pretty_printer = support::cpp14::make_unique<framework::PrettyPrinter>();
173 pretty_printer->set_color_output(color_output->value());
174 printer = std::move(pretty_printer);
175 break;
176 }
177 }
178
179 if(printer != nullptr)
180 {
181 if(log_file->is_set())
182 {
183 log_stream.open(log_file->value());
184 printer->set_stream(log_stream);
185 }
186 }
187
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100188 Scheduler::get().set_num_threads(threads->value());
189
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100190 if(log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100191 {
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100192 printer->print_global_header();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100193 }
194
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100195 if(log_level->value() >= framework::LogLevel::CONFIG)
196 {
197 printer->print_entry("Seed", support::cpp11::to_string(seed->value()));
198 printer->print_entry("Iterations", support::cpp11::to_string(iterations->value()));
199 printer->print_entry("Threads", support::cpp11::to_string(threads->value()));
200 {
201 using support::cpp11::to_string;
202 printer->print_entry("Dataset mode", to_string(dataset_mode->value()));
203 }
204 }
205
206 framework.init(instruments->value(), iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), log_level->value());
Giorgio Arena2d099932017-10-25 15:47:08 +0100207 framework.add_printer(printer.get());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100208 framework.set_throw_errors(throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100209 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100210 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100211
212 bool success = true;
213
214 if(list_tests->value())
215 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100216 for(const auto &info : framework.test_infos())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100217 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100218 std::cout << "[" << info.id << ", " << info.mode << ", " << info.status << "] " << info.name << "\n";
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100219 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100220
221 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100222 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100223
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100224 if(test_instruments->value())
225 {
226 framework::Profiler profiler = framework.get_profiler();
227 profiler.start();
228 profiler.stop();
229 if(printer != nullptr)
230 {
231 printer->print_measurements(profiler.measurements());
232 }
233 return 0;
234 }
235
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100236 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100237
238 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100239 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100240 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100241 }
242
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100243 success = framework.run();
244
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100245 if(log_level->value() > framework::LogLevel::NONE)
246 {
247 printer->print_global_footer();
248 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100249
250 return (success ? 0 : 1);
251 }
252 catch(const std::exception &error)
253 {
254 std::cerr << error.what() << "\n";
255
256 if(throw_errors->value())
257 {
258 throw;
259 }
260
261 return 1;
262 }
263
264 return 0;
265}