blob: 1f3c365c03a89f3d941dafb2c012a7d7d07d6905 [file] [log] [blame]
Moritz Pflanzeree493ae2017-07-05 10:52:21 +01001/*
Michalis Spyrou84f3ae82018-01-15 11:15:26 +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 {
Anthony Barbier4b9c58a2018-01-10 14:34:00 +0000131 p->print_entry("Version", build_information());
Giorgio Arenac5d54392017-10-31 15:18:49 +0000132 p->print_entry("Seed", support::cpp11::to_string(seed->value()));
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000133 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
134 p->print_entry("Threads", support::cpp11::to_string(options.threads->value()));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000135 {
136 using support::cpp11::to_string;
137 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
138 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100139 }
140 }
141
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000142 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 +0000143 for(auto &p : printers)
144 {
145 framework.add_printer(p.get());
146 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000147 framework.set_throw_errors(options.throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100148 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100149 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100150
151 bool success = true;
152
153 if(list_tests->value())
154 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000155 for(auto &p : printers)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100156 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000157 p->print_list_tests(framework.test_infos());
158 p->print_global_footer();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100159 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100160
161 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100162 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100163
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100164 if(test_instruments->value())
165 {
166 framework::Profiler profiler = framework.get_profiler();
167 profiler.start();
168 profiler.stop();
Giorgio Arenac5d54392017-10-31 15:18:49 +0000169 for(auto &p : printers)
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100170 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000171 p->print_measurements(profiler.measurements());
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100172 }
Giorgio Arenac5d54392017-10-31 15:18:49 +0000173
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100174 return 0;
175 }
176
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100177 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100178
179 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100180 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100181 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100182 }
183
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100184 success = framework.run();
185
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000186 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100187 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000188 for(auto &p : printers)
189 {
190 p->print_global_footer();
191 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100192 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100193
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000194#ifdef ARM_COMPUTE_CL
195 CLScheduler::get().sync();
196#endif /* ARM_COMPUTE_CL */
197
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100198 return (success ? 0 : 1);
199 }
200 catch(const std::exception &error)
201 {
202 std::cerr << error.what() << "\n";
203
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000204 if(options.throw_errors->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100205 {
206 throw;
207 }
208
209 return 1;
210 }
211
212 return 0;
213}