blob: 318f9b1d4c9837c99528921b97baf09130e6b0e2 [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 Pflanzer0ce08442017-09-16 11:11:27 +0100168 ARM_COMPUTE_ERROR_ON(_current_test_info == nullptr);
169 ARM_COMPUTE_ERROR_ON(_current_test_result == nullptr);
170
171 const bool is_expected_failure = _current_test_info->status == TestCaseFactory::Status::EXPECTED_FAILURE;
172
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100173 if(_log_level >= error.level() && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100174 {
Moritz Pflanzer0ce08442017-09-16 11:11:27 +0100175 _printer->print_error(error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100176 }
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100177
Moritz Pflanzer0ce08442017-09-16 11:11:27 +0100178 _current_test_result->status = TestResult::Status::FAILED;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100179}
180
steniu01172c58d2017-08-31 13:49:08 +0100181void Framework::log_info(const std::string &info)
182{
183 if(_log_level >= LogLevel::DEBUG && _printer != nullptr)
184 {
185 _printer->print_info(info);
186 }
187}
188
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100189int Framework::num_iterations() const
190{
191 return _num_iterations;
192}
193
194void Framework::set_num_iterations(int num_iterations)
195{
196 _num_iterations = num_iterations;
197}
198
199void Framework::set_throw_errors(bool throw_errors)
200{
201 _throw_errors = throw_errors;
202}
203
204bool Framework::throw_errors() const
205{
206 return _throw_errors;
207}
208
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100209void Framework::set_stop_on_error(bool stop_on_error)
210{
211 _stop_on_error = stop_on_error;
212}
213
214bool Framework::stop_on_error() const
215{
216 return _stop_on_error;
217}
218
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100219void Framework::set_error_on_missing_assets(bool error_on_missing_assets)
220{
221 _error_on_missing_assets = error_on_missing_assets;
222}
223
224bool Framework::error_on_missing_assets() const
225{
226 return _error_on_missing_assets;
227}
228
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100229void Framework::run_test(const TestInfo &info, TestCaseFactory &test_factory)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100230{
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100231 if(test_factory.status() == TestCaseFactory::Status::DISABLED)
232 {
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100233 log_test_skipped(info);
234 set_test_result(info, TestResult(TestResult::Status::DISABLED));
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100235 return;
236 }
237
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100238 log_test_start(info);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100239
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100240 Profiler profiler = get_profiler();
Moritz Pflanzere33eb642017-07-31 14:48:45 +0100241 TestResult result(TestResult::Status::NOT_RUN);
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100242
Moritz Pflanzer0ce08442017-09-16 11:11:27 +0100243 _current_test_info = &info;
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100244 _current_test_result = &result;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100245
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100246 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
247 {
248 _printer->print_errors_header();
249 }
250
Moritz Pflanzer0ce08442017-09-16 11:11:27 +0100251 const bool is_expected_failure = info.status == TestCaseFactory::Status::EXPECTED_FAILURE;
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100252
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100253 try
254 {
255 std::unique_ptr<TestCase> test_case = test_factory.make();
256
257 try
258 {
259 test_case->do_setup();
260
261 for(int i = 0; i < _num_iterations; ++i)
262 {
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100263 profiler.start();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100264 test_case->do_run();
Anthony Barbierbf959222017-07-19 17:01:42 +0100265#ifdef ARM_COMPUTE_CL
266 if(opencl_is_available())
267 {
268 CLScheduler::get().sync();
269 }
270#endif /* ARM_COMPUTE_CL */
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100271 profiler.stop();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100272 }
273
274 test_case->do_teardown();
Moritz Pflanzere33eb642017-07-31 14:48:45 +0100275
276 // Change status to success if no error has happend
277 if(result.status == TestResult::Status::NOT_RUN)
278 {
279 result.status = TestResult::Status::SUCCESS;
280 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100281 }
Anthony Barbierf6705ec2017-09-28 12:01:10 +0100282 catch(const FileNotFound &error)
283 {
284 if(_error_on_missing_assets)
285 {
286 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
287 {
288 TestError test_error(error.what(), LogLevel::ERRORS);
289 _printer->print_error(test_error, is_expected_failure);
290 }
291
292 result.status = TestResult::Status::FAILED;
293
294 if(_throw_errors)
295 {
296 throw;
297 }
298 }
299 else
300 {
301 if(_log_level >= LogLevel::DEBUG && _printer != nullptr)
302 {
303 _printer->print_info(error.what());
304 }
305
306 result.status = TestResult::Status::NOT_RUN;
307 }
308 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100309 catch(const TestError &error)
310 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100311 if(_log_level >= error.level() && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100312 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100313 _printer->print_error(error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100314 }
315
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100316 result.status = TestResult::Status::FAILED;
317
318 if(_throw_errors)
319 {
320 throw;
321 }
322 }
Moritz Pflanzer47752c92017-07-18 13:38:47 +0100323#ifdef ARM_COMPUTE_CL
324 catch(const ::cl::Error &error)
325 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100326 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100327 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100328 std::stringstream stream;
329 stream << "Error code: " << error.err();
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100330 TestError test_error(error.what(), LogLevel::ERRORS, stream.str());
331 _printer->print_error(test_error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100332 }
333
Moritz Pflanzer47752c92017-07-18 13:38:47 +0100334 result.status = TestResult::Status::FAILED;
335
336 if(_throw_errors)
337 {
338 throw;
339 }
340 }
341#endif /* ARM_COMPUTE_CL */
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100342 catch(const std::exception &error)
343 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100344 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100345 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100346 _printer->print_error(error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100347 }
348
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100349 result.status = TestResult::Status::CRASHED;
350
351 if(_throw_errors)
352 {
353 throw;
354 }
355 }
356 catch(...)
357 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100358 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100359 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100360 _printer->print_error(TestError("Received unknown exception"), is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100361 }
362
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100363 result.status = TestResult::Status::CRASHED;
364
365 if(_throw_errors)
366 {
367 throw;
368 }
369 }
370 }
371 catch(const std::exception &error)
372 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100373 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100374 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100375 _printer->print_error(error, is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100376 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100377
Moritz Pflanzere33eb642017-07-31 14:48:45 +0100378 result.status = TestResult::Status::CRASHED;
379
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100380 if(_throw_errors)
381 {
382 throw;
383 }
384 }
385 catch(...)
386 {
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100387 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100388 {
Moritz Pflanzer5b61fd32017-09-12 15:51:33 +0100389 _printer->print_error(TestError("Received unknown exception"), is_expected_failure);
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100390 }
391
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100392 result.status = TestResult::Status::CRASHED;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100393
394 if(_throw_errors)
395 {
396 throw;
397 }
398 }
399
Moritz Pflanzer24a82462017-08-04 11:34:44 +0100400 if(_log_level >= LogLevel::ERRORS && _printer != nullptr)
401 {
402 _printer->print_errors_footer();
403 }
404
Moritz Pflanzer0ce08442017-09-16 11:11:27 +0100405 _current_test_info = nullptr;
Moritz Pflanzere1103a82017-07-18 12:20:45 +0100406 _current_test_result = nullptr;
407
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100408 if(result.status == TestResult::Status::FAILED)
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100409 {
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100410 if(info.status == TestCaseFactory::Status::EXPECTED_FAILURE)
411 {
412 result.status = TestResult::Status::EXPECTED_FAILURE;
413 }
Moritz Pflanzere33eb642017-07-31 14:48:45 +0100414 }
415
416 if(result.status == TestResult::Status::FAILED || result.status == TestResult::Status::CRASHED)
417 {
418 if(_stop_on_error)
Moritz Pflanzerfa811652017-07-26 17:00:37 +0100419 {
420 throw std::runtime_error("Abort on first error.");
421 }
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100422 }
423
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100424 result.measurements = profiler.measurements();
425
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100426 set_test_result(info, result);
427 log_test_end(info);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100428}
429
430bool Framework::run()
431{
432 // Clear old test results
433 _test_results.clear();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100434
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100435 if(_printer != nullptr && _log_level >= LogLevel::TESTS)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100436 {
437 _printer->print_run_header();
438 }
439
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100440 const std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100441
442 int id = 0;
443
444 for(auto &test_factory : _test_factories)
445 {
446 const std::string test_case_name = test_factory->name();
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100447 const TestInfo test_info{ id, test_case_name, test_factory->mode(), test_factory->status() };
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100448
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100449 if(_test_filter.is_selected(test_info))
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100450 {
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100451 run_test(test_info, *test_factory);
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100452 }
453
454 ++id;
455 }
456
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100457 const std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100458
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100459 if(_printer != nullptr && _log_level >= LogLevel::TESTS)
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100460 {
461 _printer->print_run_footer();
462 }
463
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100464 auto runtime = std::chrono::duration_cast<std::chrono::seconds>(end - start);
465 std::map<TestResult::Status, int> results = count_test_results();
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100466
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100467 if(_log_level > LogLevel::NONE)
468 {
Moritz Pflanzer8df3faf2017-07-28 13:57:53 +0100469 std::cout << "Executed " << _test_results.size() << " test(s) ("
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100470 << results[TestResult::Status::SUCCESS] << " passed, "
471 << results[TestResult::Status::EXPECTED_FAILURE] << " expected failures, "
472 << results[TestResult::Status::FAILED] << " failed, "
473 << results[TestResult::Status::CRASHED] << " crashed, "
474 << results[TestResult::Status::DISABLED] << " disabled) in " << runtime.count() << " second(s)\n";
Moritz Pflanzer2ac50402017-07-24 15:52:54 +0100475 }
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100476
steniu013e05e4e2017-08-25 17:18:01 +0100477 int num_successful_tests = results[TestResult::Status::SUCCESS] + results[TestResult::Status::EXPECTED_FAILURE] + results[TestResult::Status::DISABLED];
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100478
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100479 return (static_cast<unsigned int>(num_successful_tests) == _test_results.size());
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100480}
481
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100482void Framework::set_test_result(TestInfo info, TestResult result)
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100483{
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100484 _test_results.emplace(std::move(info), std::move(result));
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100485}
486
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100487void Framework::print_test_results(Printer &printer) const
488{
489 printer.print_run_header();
490
491 for(const auto &test : _test_results)
492 {
493 printer.print_test_header(test.first);
494 printer.print_measurements(test.second.measurements);
495 printer.print_test_footer();
496 }
497
498 printer.print_run_footer();
499}
500
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100501Profiler Framework::get_profiler() const
502{
503 Profiler profiler;
504
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100505 const bool all_instruments = std::any_of(
506 _instruments.begin(),
507 _instruments.end(),
508 [](InstrumentType type) -> bool { return type == InstrumentType::ALL; });
509
510 auto is_selected = [&](InstrumentType instrument) -> bool
511 {
512 return std::find_if(_instruments.begin(), _instruments.end(), [&](InstrumentType type) -> bool {
513 const auto group = static_cast<InstrumentType>(static_cast<uint64_t>(type) & 0xFF00);
514 return group == instrument;
515 })
516 != _instruments.end();
517 };
518
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100519 for(const auto &instrument : _available_instruments)
520 {
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100521 if(all_instruments || is_selected(instrument.first))
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100522 {
523 profiler.add(instrument.second());
524 }
525 }
526
527 return profiler;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100528}
529
Moritz Pflanzer80fffae2017-07-05 11:02:37 +0100530void Framework::set_printer(Printer *printer)
531{
532 _printer = printer;
533}
534
Moritz Pflanzer542002c2017-07-26 16:03:58 +0100535std::vector<TestInfo> Framework::test_infos() const
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100536{
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100537 std::vector<TestInfo> ids;
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100538
539 int id = 0;
540
541 for(const auto &factory : _test_factories)
542 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100543 TestInfo test_info{ id, factory->name(), factory->mode(), factory->status() };
544
Moritz Pflanzerec2de0f2017-07-27 14:43:46 +0100545 if(_test_filter.is_selected(test_info))
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100546 {
Moritz Pflanzerbf234e02017-07-24 15:04:14 +0100547 ids.emplace_back(std::move(test_info));
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100548 }
549
550 ++id;
551 }
552
553 return ids;
554}
steniu01172c58d2017-08-31 13:49:08 +0100555
556LogLevel Framework::log_level() const
557{
558 return _log_level;
559}
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +0100560} // namespace framework
561} // namespace test
562} // namespace arm_compute