blob: 4a8a82d4908faf48b29ac1b00804b161e1adbcee [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 Barbier847864d2018-03-07 11:35:53 +0000133#ifdef ARM_COMPUTE_CL
134 if(opencl_is_available())
135 {
136 p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
137 }
138 else
139 {
140 p->print_entry("CL_DEVICE_VERSION", "Unavailable");
141 }
142#endif /* ARM_COMPUTE_CL */
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000143 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
144 p->print_entry("Threads", support::cpp11::to_string(options.threads->value()));
Giorgio Arenac5d54392017-10-31 15:18:49 +0000145 {
146 using support::cpp11::to_string;
147 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
148 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100149 }
150 }
151
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000152 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 +0000153 for(auto &p : printers)
154 {
155 framework.add_printer(p.get());
156 }
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000157 framework.set_throw_errors(options.throw_errors->value());
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100158 framework.set_stop_on_error(stop_on_error->value());
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100159 framework.set_error_on_missing_assets(error_on_missing_assets->value());
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100160
161 bool success = true;
162
163 if(list_tests->value())
164 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000165 for(auto &p : printers)
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100166 {
Anthony Barbierdbfb31c2017-11-24 11:24:45 +0000167 p->print_list_tests(framework.test_infos());
168 p->print_global_footer();
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100169 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100170
171 return 0;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100172 }
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100173
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100174 if(test_instruments->value())
175 {
176 framework::Profiler profiler = framework.get_profiler();
177 profiler.start();
178 profiler.stop();
Giorgio Arenac5d54392017-10-31 15:18:49 +0000179 for(auto &p : printers)
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100180 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000181 p->print_measurements(profiler.measurements());
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100182 }
Giorgio Arenac5d54392017-10-31 15:18:49 +0000183
Anthony Barbiere1f8f9b2017-10-03 14:01:05 +0100184 return 0;
185 }
186
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100187 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100188
189 if(!parser.validate())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100190 {
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100191 return 1;
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100192 }
193
Moritz Pflanzeraab43542017-07-18 13:15:39 +0100194 success = framework.run();
195
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000196 if(options.log_level->value() > framework::LogLevel::NONE)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100197 {
Giorgio Arenac5d54392017-10-31 15:18:49 +0000198 for(auto &p : printers)
199 {
200 p->print_global_footer();
201 }
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100202 }
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100203
Michalis Spyrou84f3ae82018-01-15 11:15:26 +0000204#ifdef ARM_COMPUTE_CL
205 CLScheduler::get().sync();
206#endif /* ARM_COMPUTE_CL */
207
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100208 return (success ? 0 : 1);
209 }
210 catch(const std::exception &error)
211 {
212 std::cerr << error.what() << "\n";
213
Anthony Barbier6db0ff52018-01-05 10:59:12 +0000214 if(options.throw_errors->value())
Moritz Pflanzeree493ae2017-07-05 10:52:21 +0100215 {
216 throw;
217 }
218
219 return 1;
220 }
221
222 return 0;
223}