blob: 4f1768509850e16beebc28ace6024d9689300f99 [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 Pflanzerd03b00a2017-07-17 13:50:12 +010024#include "framework/DatasetModes.h"
Moritz Pflanzer2ac50402017-07-24 15:52:54 +010025#include "framework/Exceptions.h"
26#include "framework/Framework.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010027#include "framework/Macros.h"
28#include "framework/command_line/CommandLineOptions.h"
29#include "framework/command_line/CommandLineParser.h"
30#include "framework/instruments/Instruments.h"
31#include "framework/printers/Printers.h"
32#include "support/ToolchainSupport.h"
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010033#include "tests/AssetsLibrary.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 Pflanzer81527bf2017-07-20 15:11:33 +0100118 auto filter_id = parser.add_option<framework::SimpleOption<int64_t>>("filter-id", -1);
119 filter_id->set_help("Test id. Only this test will be executed.");
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);
123 log_file->set_help("Verbosity of the output");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100124 auto throw_errors = parser.add_option<framework::ToggleOption>("throw-errors");
125 throw_errors->set_help("Don't catch errors (useful for debugging)");
126 auto seed = parser.add_option<framework::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
127 seed->set_help("Global seed for random number generation");
128 auto color_output = parser.add_option<framework::ToggleOption>("color-output", true);
129 color_output->set_help("Produce colored output on the console");
130 auto list_tests = parser.add_option<framework::ToggleOption>("list-tests", false);
131 list_tests->set_help("List all test names");
132 auto assets = parser.add_positional_option<framework::SimpleOption<std::string>>("assets");
133 assets->set_help("Path to the assets directory");
134 assets->set_required(true);
135
136 try
137 {
138 parser.parse(argc, argv);
139
140 if(help->is_set() && help->value())
141 {
142 parser.print_help(argv[0]);
143 return 0;
144 }
145
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100146 std::unique_ptr<framework::Printer> printer;
147 std::ofstream log_stream;
148
149 switch(log_format->value())
150 {
151 case framework::LogFormat::JSON:
152 printer = support::cpp14::make_unique<framework::JSONPrinter>();
153 break;
154 case framework::LogFormat::NONE:
155 break;
156 case framework::LogFormat::PRETTY:
157 default:
158 {
159 auto pretty_printer = support::cpp14::make_unique<framework::PrettyPrinter>();
160 pretty_printer->set_color_output(color_output->value());
161 printer = std::move(pretty_printer);
162 break;
163 }
164 }
165
166 if(printer != nullptr)
167 {
168 if(log_file->is_set())
169 {
170 log_stream.open(log_file->value());
171 printer->set_stream(log_stream);
172 }
173 }
174
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100175 Scheduler::get().set_num_threads(threads->value());
176
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100177 if(log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100178 {
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100179 printer->print_global_header();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100180 }
181
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100182 if(log_level->value() >= framework::LogLevel::CONFIG)
183 {
184 printer->print_entry("Seed", support::cpp11::to_string(seed->value()));
185 printer->print_entry("Iterations", support::cpp11::to_string(iterations->value()));
186 printer->print_entry("Threads", support::cpp11::to_string(threads->value()));
187 {
188 using support::cpp11::to_string;
189 printer->print_entry("Dataset mode", to_string(dataset_mode->value()));
190 }
191 }
192
193 framework.init(instruments->value(), iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), log_level->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100194 framework.set_printer(printer.get());
195 framework.set_throw_errors(throw_errors->value());
196
197 bool success = true;
198
199 if(list_tests->value())
200 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100201 for(const auto &info : framework.test_infos())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100202 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100203 std::cout << "[" << info.id << ", " << info.mode << ", " << info.status << "] " << info.name << "\n";
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100204 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100205
206 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100207 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100208
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100209 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100210
211 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100212 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100213 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100214 }
215
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100216 success = framework.run();
217
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100218 if(log_level->value() > framework::LogLevel::NONE)
219 {
220 printer->print_global_footer();
221 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100222
223 return (success ? 0 : 1);
224 }
225 catch(const std::exception &error)
226 {
227 std::cerr << error.what() << "\n";
228
229 if(throw_errors->value())
230 {
231 throw;
232 }
233
234 return 1;
235 }
236
237 return 0;
238}