blob: 1797b21114c716d0112fa311d08a9bf31f7fc134 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
Anthony Barbier6db0ff52018-01-05 10:59:12 +00002 * Copyright (c) 2017, 2018 ARM Limited.
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01003 *
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"
Anthony Barbier6db0ff52018-01-05 10:59:12 +000033#include "tests/framework/command_line/CommonOptions.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010034#include "tests/framework/instruments/Instruments.h"
35#include "tests/framework/printers/Printers.h"
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010036
Anthony Barbier15d5ac82017-07-17 15:22:17 +010037#ifdef ARM_COMPUTE_CL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010038#include "arm_compute/runtime/CL/CLScheduler.h"
Anthony Barbier15d5ac82017-07-17 15:22:17 +010039#endif /* ARM_COMPUTE_CL */
Anthony Barbier7068f992017-10-26 15:23:08 +010040#ifdef ARM_COMPUTE_GC
41#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
42#endif /* ARM_COMPUTE_GC */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010043#include "arm_compute/runtime/Scheduler.h"
44
45#include <fstream>
46#include <initializer_list>
47#include <iostream>
48#include <memory>
49#include <random>
50#include <utility>
51
52using namespace arm_compute;
53using namespace arm_compute::test;
54
55namespace arm_compute
56{
57namespace test
58{
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010059std::unique_ptr<AssetsLibrary> library;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010060} // namespace test
61} // namespace arm_compute
62
63int main(int argc, char **argv)
64{
Anthony Barbier15d5ac82017-07-17 15:22:17 +010065#ifdef ARM_COMPUTE_CL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010066 CLScheduler::get().default_init();
Anthony Barbier15d5ac82017-07-17 15:22:17 +010067#endif /* ARM_COMPUTE_CL */
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010068
Anthony Barbier7068f992017-10-26 15:23:08 +010069#ifdef ARM_COMPUTE_GC
70 GCScheduler::get().default_init();
Giorgio Arenace58a9f2017-10-31 17:59:17 +000071#endif /* ARM_COMPUTE_GC */
Anthony Barbier7068f992017-10-26 15:23:08 +010072
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010073 framework::Framework &framework = framework::Framework::get();
74
75 framework::CommandLineParser parser;
76
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010077 std::set<framework::DatasetMode> allowed_modes
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010078 {
Moritz Pflanzerd03b00a2017-07-17 13:50:12 +010079 framework::DatasetMode::PRECOMMIT,
80 framework::DatasetMode::NIGHTLY,
81 framework::DatasetMode::ALL
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010082 };
83
Anthony Barbier6db0ff52018-01-05 10:59:12 +000084 framework::CommonOptions options(parser);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010085
Anthony Barbier144d2ff2017-09-29 10:46:08 +010086 auto dataset_mode = parser.add_option<framework::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010087 dataset_mode->set_help("For managed datasets select which group to use");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010088 auto filter = parser.add_option<framework::SimpleOption<std::string>>("filter", ".*");
89 filter->set_help("Regular expression to select test cases");
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +010090 auto filter_id = parser.add_option<framework::SimpleOption<std::string>>("filter-id");
91 filter_id->set_help("List of test ids. ... can be used to define a range.");
Moritz Pflanzerfa811652017-07-26 17:00:37 +010092 auto stop_on_error = parser.add_option<framework::ToggleOption>("stop-on-error");
Anthony Barbierf6705ec2017-09-28 12:01:10 +010093 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010094 auto seed = parser.add_option<framework::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
95 seed->set_help("Global seed for random number generation");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +010096 auto list_tests = parser.add_option<framework::ToggleOption>("list-tests", false);
97 list_tests->set_help("List all test names");
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +010098 auto test_instruments = parser.add_option<framework::ToggleOption>("test-instruments", false);
99 test_instruments->set_help("Test if the instruments work on the platform");
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100100 auto error_on_missing_assets = parser.add_option<framework::ToggleOption>("error-on-missing-assets", false);
101 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 +0100102 auto assets = parser.add_positional_option<framework::SimpleOption<std::string>>("assets");
103 assets->set_help("Path to the assets directory");
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100104
105 try
106 {
107 parser.parse(argc, argv);
108
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000109 if(options.help->is_set() && options.help->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100110 {
111 parser.print_help(argv[0]);
112 return 0;
113 }
114
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000115 std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100116
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000117 Scheduler::get().set_num_threads(options.threads->value());
Giorgio Arenac5d54392017-10-31 15:18:49 +0000118
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000119 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100120 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000121 for(auto &p : printers)
122 {
123 p->print_global_header();
124 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100125 }
126
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000127 if(options.log_level->value() >= framework::LogLevel::CONFIG)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100128 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000129 for(auto &p : printers)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100130 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000131 p->print_entry("Seed", support::cpp11::to_string(seed->value()));
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000132 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
133 p->print_entry("Threads", support::cpp11::to_string(options.threads->value()));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000134 {
135 using support::cpp11::to_string;
136 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
137 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100138 }
139 }
140
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000141 framework.init(options.instruments->value(), options.iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), options.log_level->value());
Giorgio Arenac5d54392017-10-31 15:18:49 +0000142 for(auto &p : printers)
143 {
144 framework.add_printer(p.get());
145 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000146 framework.set_throw_errors(options.throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100147 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100148 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100149
150 bool success = true;
151
152 if(list_tests->value())
153 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000154 for(auto &p : printers)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100155 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000156 p->print_list_tests(framework.test_infos());
157 p->print_global_footer();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100158 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100159
160 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100161 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100162
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100163 if(test_instruments->value())
164 {
165 framework::Profiler profiler = framework.get_profiler();
166 profiler.start();
167 profiler.stop();
Giorgio Arenac5d54392017-10-31 15:18:49 +0000168 for(auto &p : printers)
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100169 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000170 p->print_measurements(profiler.measurements());
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100171 }
Giorgio Arenac5d54392017-10-31 15:18:49 +0000172
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100173 return 0;
174 }
175
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100176 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100177
178 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100179 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100180 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100181 }
182
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100183 success = framework.run();
184
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000185 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100186 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000187 for(auto &p : printers)
188 {
189 p->print_global_footer();
190 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100191 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100192
193 return (success ? 0 : 1);
194 }
195 catch(const std::exception &error)
196 {
197 std::cerr << error.what() << "\n";
198
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000199 if(options.throw_errors->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100200 {
201 throw;
202 }
203
204 return 1;
205 }
206
207 return 0;
208}