2 * Copyright (c) 2017-2018 ARM Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
24 #include "support/ToolchainSupport.h"
25 #include "tests/AssetsLibrary.h"
26 #include "tests/framework/DatasetModes.h"
27 #include "tests/framework/Exceptions.h"
28 #include "tests/framework/Framework.h"
29 #include "tests/framework/Macros.h"
30 #include "tests/framework/Profiler.h"
31 #include "tests/framework/command_line/CommandLineOptions.h"
32 #include "tests/framework/command_line/CommandLineParser.h"
33 #include "tests/framework/command_line/CommonOptions.h"
34 #include "tests/framework/instruments/Instruments.h"
35 #include "tests/framework/printers/Printers.h"
38 #include "arm_compute/runtime/CL/CLScheduler.h"
39 #endif /* ARM_COMPUTE_CL */
41 #include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h"
42 #endif /* ARM_COMPUTE_GC */
43 #include "arm_compute/runtime/Scheduler.h"
46 #include <initializer_list>
52 using namespace arm_compute;
53 using namespace arm_compute::test;
59 std::unique_ptr<AssetsLibrary> library;
61 } // namespace arm_compute
63 int main(int argc, char **argv)
66 CLScheduler::get().default_init();
67 #endif /* ARM_COMPUTE_CL */
70 GCScheduler::get().default_init();
71 #endif /* ARM_COMPUTE_GC */
73 framework::Framework &framework = framework::Framework::get();
75 framework::CommandLineParser parser;
77 std::set<framework::DatasetMode> allowed_modes
79 framework::DatasetMode::PRECOMMIT,
80 framework::DatasetMode::NIGHTLY,
81 framework::DatasetMode::ALL
84 framework::CommonOptions options(parser);
86 auto dataset_mode = parser.add_option<framework::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
87 dataset_mode->set_help("For managed datasets select which group to use");
88 auto filter = parser.add_option<framework::SimpleOption<std::string>>("filter", ".*");
89 filter->set_help("Regular expression to select test cases");
90 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.");
92 auto stop_on_error = parser.add_option<framework::ToggleOption>("stop-on-error");
93 stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
94 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");
96 auto list_tests = parser.add_option<framework::ToggleOption>("list-tests", false);
97 list_tests->set_help("List all test names");
98 auto test_instruments = parser.add_option<framework::ToggleOption>("test-instruments", false);
99 test_instruments->set_help("Test if the instruments work on the platform");
100 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");
102 auto assets = parser.add_positional_option<framework::SimpleOption<std::string>>("assets");
103 assets->set_help("Path to the assets directory");
107 parser.parse(argc, argv);
109 if(options.help->is_set() && options.help->value())
111 parser.print_help(argv[0]);
115 std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
117 Scheduler::get().set_num_threads(options.threads->value());
119 if(options.log_level->value() > framework::LogLevel::NONE)
121 for(auto &p : printers)
123 p->print_global_header();
127 if(options.log_level->value() >= framework::LogLevel::CONFIG)
129 for(auto &p : printers)
131 p->print_entry("Version", build_information());
132 p->print_entry("Seed", support::cpp11::to_string(seed->value()));
133 #ifdef ARM_COMPUTE_CL
134 if(opencl_is_available())
136 p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version());
140 p->print_entry("CL_DEVICE_VERSION", "Unavailable");
142 #endif /* ARM_COMPUTE_CL */
143 p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value()));
144 p->print_entry("Threads", support::cpp11::to_string(options.threads->value()));
146 using support::cpp11::to_string;
147 p->print_entry("Dataset mode", to_string(dataset_mode->value()));
152 framework.init(options.instruments->value(), options.iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), options.log_level->value());
153 for(auto &p : printers)
155 framework.add_printer(p.get());
157 framework.set_throw_errors(options.throw_errors->value());
158 framework.set_stop_on_error(stop_on_error->value());
159 framework.set_error_on_missing_assets(error_on_missing_assets->value());
163 if(list_tests->value())
165 for(auto &p : printers)
167 p->print_list_tests(framework.test_infos());
168 p->print_global_footer();
174 if(test_instruments->value())
176 framework::Profiler profiler = framework.get_profiler();
179 for(auto &p : printers)
181 p->print_measurements(profiler.measurements());
187 library = support::cpp14::make_unique<AssetsLibrary>(assets->value(), seed->value());
189 if(!parser.validate())
194 success = framework.run();
196 if(options.log_level->value() > framework::LogLevel::NONE)
198 for(auto &p : printers)
200 p->print_global_footer();
204 #ifdef ARM_COMPUTE_CL
205 CLScheduler::get().sync();
206 #endif /* ARM_COMPUTE_CL */
208 return (success ? 0 : 1);
210 catch(const std::exception &error)
212 std::cerr << error.what() << "\n";
214 if(options.throw_errors->value())