blob: 853ea251c32faf1012cb7e11908d53cf401afeb4 [file] [log] [blame]
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +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 */
24#include "Framework.h"
25
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010026#include "support/ToolchainSupport.h"
27
Moritz Pflanzer47752c92017-07-18 13:38:47 +010028#ifdef ARM_COMPUTE_CL
29#include "arm_compute/core/CL/OpenCL.h"
Anthony Barbierbf959222017-07-19 17:01:42 +010030#include "arm_compute/runtime/CL/CLScheduler.h"
Moritz Pflanzer47752c92017-07-18 13:38:47 +010031#endif /* ARM_COMPUTE_CL */
32
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010033#include <chrono>
34#include <iostream>
35#include <sstream>
36#include <type_traits>
37
38namespace arm_compute
39{
40namespace test
41{
42namespace framework
43{
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010044Framework::Framework()
45{
46 _available_instruments.emplace(InstrumentType::WALL_CLOCK_TIMER, Instrument::make_instrument<WallClockTimer>);
47#ifdef PMU_ENABLED
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010048 _available_instruments.emplace(InstrumentType::PMU, Instrument::make_instrument<PMUCounter>);
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010049#endif /* PMU_ENABLED */
Moritz Pflanzer45634b42017-08-30 12:48:18 +010050#ifdef MALI_ENABLED
51 _available_instruments.emplace(InstrumentType::MALI, Instrument::make_instrument<MaliCounter>);
52#endif /* MALI_ENABLED */
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010053}
54
55std::set<InstrumentType> Framework::available_instruments() const
56{
57 std::set<InstrumentType> types;
58
59 for(const auto &instrument : _available_instruments)
60 {
61 types.emplace(instrument.first);
62 }
63
64 return types;
65}
66
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010067std::map<TestResult::Status, int> Framework::count_test_results() const
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010068{
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010069 std::map<TestResult::Status, int> counts;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010070
71 for(const auto &test : _test_results)
72 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010073 ++counts[test.second.status];
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010074 }
75
Moritz Pflanzerbf234e02017-07-24 15:04:14 +010076 return counts;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010077}
78
79Framework &Framework::get()
80{
81 static Framework instance;
82 return instance;
83}
84
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +010085void Framework::init(const std::vector<InstrumentType> &instruments, int num_iterations, DatasetMode mode, const std::string &name_filter, const std::string &id_filter, LogLevel log_level)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010086{
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +010087 _test_filter = TestFilter(mode, name_filter, id_filter);
88 _num_iterations = num_iterations;
89 _log_level = log_level;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010090
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010091 _instruments = std::set<InstrumentType>(instruments.begin(), instruments.end());
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +010092}
93
94std::string Framework::current_suite_name() const
95{
96 return join(_test_suite_name.cbegin(), _test_suite_name.cend(), "/");
97}
98
99void Framework::push_suite(std::string name)
100{
101 _test_suite_name.emplace_back(std::move(name));
102}
103
104void Framework::pop_suite()
105{
106 _test_suite_name.pop_back();
107}
108
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100109void Framework::add_test_info(std::string info)
110{
111 _test_info.emplace_back(std::move(info));
112}
113
114void Framework::clear_test_info()
115{
116 _test_info.clear();
117}
118
119bool Framework::has_test_info() const
120{
121 return !_test_info.empty();
122}
123
124void Framework::print_test_info(std::ostream &os) const
125{
Moritz Pflanzer8df3faf2017-07-28 13:57:53 +0100126 if(!_test_info.empty())
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100127 {
Moritz Pflanzer8df3faf2017-07-28 13:57:53 +0100128 os << "CONTEXT:\n";
129
130 for(const auto &str : _test_info)
131 {
132 os << " " << str << "\n";
133 }
Moritz Pflanzerc7d15032017-07-18 16:21:16 +0100134 }
135}
136
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100137void Framework::log_test_start(const TestInfo &info)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100138{
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100139 if(_printer != nullptr && _log_level >= LogLevel::TESTS)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100140 {
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100141 _printer->print_test_header(info);
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100142 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100143}
144
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100145void Framework::log_test_skipped(const TestInfo &info)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100146{
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100147 static_cast<void>(info);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100148}
149
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100150void Framework::log_test_end(const TestInfo &info)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100151{
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100152 if(_printer != nullptr)
153 {
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100154 if(_log_level >= LogLevel::MEASUREMENTS)
155 {
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100156 _printer->print_measurements(_test_results.at(info).measurements);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100157 }
158
159 if(_log_level >= LogLevel::TESTS)
160 {
161 _printer->print_test_footer();
162 }
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100163 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100164}
165
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100166void Framework::log_failed_expectation(const TestError &error)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100167{
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100168 if(_log_level >= error.level() && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100169 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100170 constexpr bool expected_error = true;
171 _printer->print_error(error, expected_error);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100172 }
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100173
174 if(_current_test_result != nullptr)
175 {
176 _current_test_result->status = TestResult::Status::FAILED;
177 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100178}
179
steniu01172c58d2017-08-31 13:49:08 +0100180void Framework::log_info(const std::string &info)
181{
182 if(_log_level >= LogLevel::DEBUG && _printer != nullptr)
183 {
184 _printer->print_info(info);
185 }
186}
187
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100188int Framework::num_iterations() const
189{
190 return _num_iterations;
191}
192
193void Framework::set_num_iterations(int num_iterations)
194{
195 _num_iterations = num_iterations;
196}
197
198void Framework::set_throw_errors(bool throw_errors)
199{
200 _throw_errors = throw_errors;
201}
202
203bool Framework::throw_errors() const
204{
205 return _throw_errors;
206}
207
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100208void Framework::set_stop_on_error(bool stop_on_error)
209{
210 _stop_on_error = stop_on_error;
211}
212
213bool Framework::stop_on_error() const
214{
215 return _stop_on_error;
216}
217
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100218void Framework::run_test(const TestInfo &info, TestCaseFactory &test_factory)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100219{
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100220 if(test_factory.status() == TestCaseFactory::Status::DISABLED)
221 {
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100222 log_test_skipped(info);
223 set_test_result(info, TestResult(TestResult::Status::DISABLED));
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100224 return;
225 }
226
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100227 log_test_start(info);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100228
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100229 Profiler profiler = get_profiler();
Moritz Pflanzere33eb642017-07-31 14:48:45 +0100230 TestResult result(TestResult::Status::NOT_RUN);
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100231
232 _current_test_result = &result;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100233
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100234 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
235 {
236 _printer->print_errors_header();
237 }
238
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100239 const bool is_expected_failure = test_factory.status() == TestCaseFactory::Status::EXPECTED_FAILURE;
240
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100241 try
242 {
243 std::unique_ptr<TestCase> test_case = test_factory.make();
244
245 try
246 {
247 test_case->do_setup();
248
249 for(int i = 0; i < _num_iterations; ++i)
250 {
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100251 profiler.start();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100252 test_case->do_run();
Anthony Barbierbf959222017-07-19 17:01:42 +0100253#ifdef ARM_COMPUTE_CL
254 if(opencl_is_available())
255 {
256 CLScheduler::get().sync();
257 }
258#endif /* ARM_COMPUTE_CL */
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100259 profiler.stop();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100260 }
261
262 test_case->do_teardown();
Moritz Pflanzere33eb642017-07-31 14:48:45 +0100263
264 // Change status to success if no error has happend
265 if(result.status == TestResult::Status::NOT_RUN)
266 {
267 result.status = TestResult::Status::SUCCESS;
268 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100269 }
270 catch(const TestError &error)
271 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100272 if(_log_level >= error.level() && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100273 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100274 _printer->print_error(error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100275 }
276
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100277 result.status = TestResult::Status::FAILED;
278
279 if(_throw_errors)
280 {
281 throw;
282 }
283 }
Moritz Pflanzer47752c92017-07-18 13:38:47 +0100284#ifdef ARM_COMPUTE_CL
285 catch(const ::cl::Error &error)
286 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100287 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100288 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100289 std::stringstream stream;
290 stream << "Error code: " << error.err();
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100291 TestError test_error(error.what(), LogLevel::ERRORS, stream.str());
292 _printer->print_error(test_error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100293 }
294
Moritz Pflanzer47752c92017-07-18 13:38:47 +0100295 result.status = TestResult::Status::FAILED;
296
297 if(_throw_errors)
298 {
299 throw;
300 }
301 }
302#endif /* ARM_COMPUTE_CL */
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100303 catch(const std::exception &error)
304 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100305 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100306 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100307 _printer->print_error(error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100308 }
309
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100310 result.status = TestResult::Status::CRASHED;
311
312 if(_throw_errors)
313 {
314 throw;
315 }
316 }
317 catch(...)
318 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100319 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100320 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100321 _printer->print_error(TestError("Received unknown exception"), is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100322 }
323
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100324 result.status = TestResult::Status::CRASHED;
325
326 if(_throw_errors)
327 {
328 throw;
329 }
330 }
331 }
332 catch(const std::exception &error)
333 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100334 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100335 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100336 _printer->print_error(error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100337 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100338
Moritz Pflanzere33eb642017-07-31 14:48:45 +0100339 result.status = TestResult::Status::CRASHED;
340
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100341 if(_throw_errors)
342 {
343 throw;
344 }
345 }
346 catch(...)
347 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100348 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100349 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100350 _printer->print_error(TestError("Received unknown exception"), is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100351 }
352
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100353 result.status = TestResult::Status::CRASHED;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100354
355 if(_throw_errors)
356 {
357 throw;
358 }
359 }
360
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100361 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
362 {
363 _printer->print_errors_footer();
364 }
365
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100366 _current_test_result = nullptr;
367
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100368 if(result.status == TestResult::Status::FAILED)
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100369 {
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100370 if(info.status == TestCaseFactory::Status::EXPECTED_FAILURE)
371 {
372 result.status = TestResult::Status::EXPECTED_FAILURE;
373 }
Moritz Pflanzere33eb642017-07-31 14:48:45 +0100374 }
375
376 if(result.status == TestResult::Status::FAILED || result.status == TestResult::Status::CRASHED)
377 {
378 if(_stop_on_error)
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100379 {
380 throw std::runtime_error("Abort on first error.");
381 }
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100382 }
383
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100384 result.measurements = profiler.measurements();
385
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100386 set_test_result(info, result);
387 log_test_end(info);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100388}
389
390bool Framework::run()
391{
392 // Clear old test results
393 _test_results.clear();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100394
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100395 if(_printer != nullptr && _log_level >= LogLevel::TESTS)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100396 {
397 _printer->print_run_header();
398 }
399
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100400 const std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100401
402 int id = 0;
403
404 for(auto &test_factory : _test_factories)
405 {
406 const std::string test_case_name = test_factory->name();
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100407 const TestInfo test_info{ id, test_case_name, test_factory->mode(), test_factory->status() };
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100408
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100409 if(_test_filter.is_selected(test_info))
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100410 {
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100411 run_test(test_info, *test_factory);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100412 }
413
414 ++id;
415 }
416
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100417 const std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100418
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100419 if(_printer != nullptr && _log_level >= LogLevel::TESTS)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100420 {
421 _printer->print_run_footer();
422 }
423
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100424 auto runtime = std::chrono::duration_cast<std::chrono::seconds>(end - start);
425 std::map<TestResult::Status, int> results = count_test_results();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100426
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100427 if(_log_level > LogLevel::NONE)
428 {
Moritz Pflanzer8df3faf2017-07-28 13:57:53 +0100429 std::cout << "Executed " << _test_results.size() << " test(s) ("
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100430 << results[TestResult::Status::SUCCESS] << " passed, "
431 << results[TestResult::Status::EXPECTED_FAILURE] << " expected failures, "
432 << results[TestResult::Status::FAILED] << " failed, "
433 << results[TestResult::Status::CRASHED] << " crashed, "
434 << results[TestResult::Status::DISABLED] << " disabled) in " << runtime.count() << " second(s)\n";
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100435 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100436
steniu013e05e4e2017-08-25 17:18:01 +0100437 int num_successful_tests = results[TestResult::Status::SUCCESS] + results[TestResult::Status::EXPECTED_FAILURE] + results[TestResult::Status::DISABLED];
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100438
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100439 return (static_cast<unsigned int>(num_successful_tests) == _test_results.size());
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100440}
441
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100442void Framework::set_test_result(TestInfo info, TestResult result)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100443{
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100444 _test_results.emplace(std::move(info), std::move(result));
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100445}
446
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100447void Framework::print_test_results(Printer &printer) const
448{
449 printer.print_run_header();
450
451 for(const auto &test : _test_results)
452 {
453 printer.print_test_header(test.first);
454 printer.print_measurements(test.second.measurements);
455 printer.print_test_footer();
456 }
457
458 printer.print_run_footer();
459}
460
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100461Profiler Framework::get_profiler() const
462{
463 Profiler profiler;
464
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100465 const bool all_instruments = std::any_of(
466 _instruments.begin(),
467 _instruments.end(),
468 [](InstrumentType type) -> bool { return type == InstrumentType::ALL; });
469
470 auto is_selected = [&](InstrumentType instrument) -> bool
471 {
472 return std::find_if(_instruments.begin(), _instruments.end(), [&](InstrumentType type) -> bool {
473 const auto group = static_cast<InstrumentType>(static_cast<uint64_t>(type) & 0xFF00);
474 return group == instrument;
475 })
476 != _instruments.end();
477 };
478
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100479 for(const auto &instrument : _available_instruments)
480 {
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100481 if(all_instruments || is_selected(instrument.first))
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100482 {
483 profiler.add(instrument.second());
484 }
485 }
486
487 return profiler;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100488}
489
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100490void Framework::set_printer(Printer *printer)
491{
492 _printer = printer;
493}
494
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100495std::vector<TestInfo> Framework::test_infos() const
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100496{
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100497 std::vector<TestInfo> ids;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100498
499 int id = 0;
500
501 for(const auto &factory : _test_factories)
502 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100503 TestInfo test_info{ id, factory->name(), factory->mode(), factory->status() };
504
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100505 if(_test_filter.is_selected(test_info))
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100506 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100507 ids.emplace_back(std::move(test_info));
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100508 }
509
510 ++id;
511 }
512
513 return ids;
514}
steniu01172c58d2017-08-31 13:49:08 +0100515
516LogLevel Framework::log_level() const
517{
518 return _log_level;
519}
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100520} // namespace framework
521} // namespace test
522} // namespace arm_compute