From 2ac5040c9b21734610b51b232ddac5a9067aa2c2 Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Mon, 24 Jul 2017 15:52:54 +0100 Subject: COMPMID-415: Add log level Change-Id: I93f49198ab2c32f52b4723a0624d588683a92451 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/81446 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- framework/Framework.cpp | 78 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 21 deletions(-) (limited to 'framework/Framework.cpp') diff --git a/framework/Framework.cpp b/framework/Framework.cpp index 73e2e8cf7a..8f605e3e8b 100644 --- a/framework/Framework.cpp +++ b/framework/Framework.cpp @@ -23,7 +23,6 @@ */ #include "Framework.h" -#include "Exceptions.h" #include "support/ToolchainSupport.h" #ifdef ARM_COMPUTE_CL @@ -81,12 +80,13 @@ Framework &Framework::get() return instance; } -void Framework::init(const std::vector &instruments, int num_iterations, DatasetMode mode, const std::string &name_filter, int64_t id_filter) +void Framework::init(const std::vector &instruments, int num_iterations, DatasetMode mode, const std::string &name_filter, int64_t id_filter, LogLevel log_level) { _test_name_filter = std::regex{ name_filter }; _test_id_filter = id_filter; _num_iterations = num_iterations; _dataset_mode = mode; + _log_level = log_level; _instruments = InstrumentType::NONE; @@ -138,7 +138,7 @@ void Framework::print_test_info(std::ostream &os) const void Framework::log_test_start(const std::string &test_name) { - if(_printer != nullptr) + if(_printer != nullptr && _log_level >= LogLevel::TESTS) { _printer->print_test_header(test_name); } @@ -153,14 +153,24 @@ void Framework::log_test_end(const std::string &test_name) { if(_printer != nullptr) { - _printer->print_measurements(_test_results.at(test_name).measurements); - _printer->print_test_footer(); + if(_log_level >= LogLevel::MEASUREMENTS) + { + _printer->print_measurements(_test_results.at(test_name).measurements); + } + + if(_log_level >= LogLevel::TESTS) + { + _printer->print_test_footer(); + } } } -void Framework::log_failed_expectation(const std::string &msg) +void Framework::log_failed_expectation(const std::string &msg, LogLevel level) { - std::cerr << "ERROR: " << msg << "\n"; + if(_log_level >= level) + { + std::cerr << "ERROR: " << msg << "\n"; + } if(_current_test_result != nullptr) { @@ -251,7 +261,11 @@ void Framework::run_test(TestCaseFactory &test_factory) } catch(const TestError &error) { - std::cerr << "FATAL ERROR: " << error.what() << "\n"; + if(_log_level >= error.level()) + { + std::cerr << "FATAL ERROR: " << error.what() << "\n"; + } + result.status = TestResult::Status::FAILED; if(_throw_errors) @@ -262,7 +276,11 @@ void Framework::run_test(TestCaseFactory &test_factory) #ifdef ARM_COMPUTE_CL catch(const ::cl::Error &error) { - std::cerr << "FATAL CL ERROR: " << error.what() << " with code " << error.err() << "\n"; + if(_log_level >= LogLevel::ERRORS) + { + std::cerr << "FATAL CL ERROR: " << error.what() << " with code " << error.err() << "\n"; + } + result.status = TestResult::Status::FAILED; if(_throw_errors) @@ -273,7 +291,11 @@ void Framework::run_test(TestCaseFactory &test_factory) #endif /* ARM_COMPUTE_CL */ catch(const std::exception &error) { - std::cerr << "FATAL ERROR: Received unhandled error: '" << error.what() << "'\n"; + if(_log_level >= LogLevel::ERRORS) + { + std::cerr << "FATAL ERROR: Received unhandled error: '" << error.what() << "'\n"; + } + result.status = TestResult::Status::CRASHED; if(_throw_errors) @@ -283,7 +305,11 @@ void Framework::run_test(TestCaseFactory &test_factory) } catch(...) { - std::cerr << "FATAL ERROR: Received unhandled exception\n"; + if(_log_level >= LogLevel::ERRORS) + { + std::cerr << "FATAL ERROR: Received unhandled exception\n"; + } + result.status = TestResult::Status::CRASHED; if(_throw_errors) @@ -294,7 +320,10 @@ void Framework::run_test(TestCaseFactory &test_factory) } catch(const std::exception &error) { - std::cerr << "FATAL ERROR: Received unhandled error during fixture creation: '" << error.what() << "'\n"; + if(_log_level >= LogLevel::ERRORS) + { + std::cerr << "FATAL ERROR: Received unhandled error during fixture creation: '" << error.what() << "'\n"; + } if(_throw_errors) { @@ -303,7 +332,11 @@ void Framework::run_test(TestCaseFactory &test_factory) } catch(...) { - std::cerr << "FATAL ERROR: Received unhandled exception during fixture creation\n"; + if(_log_level >= LogLevel::ERRORS) + { + std::cerr << "FATAL ERROR: Received unhandled exception during fixture creation\n"; + } + result.status = TestResult::Status::CRASHED; if(_throw_errors) @@ -331,7 +364,7 @@ bool Framework::run() _test_results.clear(); _runtime = std::chrono::seconds{ 0 }; - if(_printer != nullptr) + if(_printer != nullptr && _log_level >= LogLevel::TESTS) { _printer->print_run_header(); } @@ -355,7 +388,7 @@ bool Framework::run() const auto end = std::chrono::high_resolution_clock::now(); - if(_printer != nullptr) + if(_printer != nullptr && _log_level >= LogLevel::TESTS) { _printer->print_run_footer(); } @@ -364,12 +397,15 @@ bool Framework::run() auto test_results = count_test_results(); - std::cout << "Executed " << _test_results.size() << " test(s) (" - << test_results[TestResult::Status::SUCCESS] << " passed, " - << test_results[TestResult::Status::EXPECTED_FAILURE] << " expected failures, " - << test_results[TestResult::Status::FAILED] << " failed, " - << test_results[TestResult::Status::CRASHED] << " crashed, " - << test_results[TestResult::Status::DISABLED] << " disabled) in " << _runtime.count() << " second(s)\n"; + if(_log_level > LogLevel::NONE) + { + std::cout << "Executed " << _test_results.size() << " test(s) (" + << test_results[TestResult::Status::SUCCESS] << " passed, " + << test_results[TestResult::Status::EXPECTED_FAILURE] << " expected failures, " + << test_results[TestResult::Status::FAILED] << " failed, " + << test_results[TestResult::Status::CRASHED] << " crashed, " + << test_results[TestResult::Status::DISABLED] << " disabled) in " << _runtime.count() << " second(s)\n"; + } int num_successful_tests = test_results[TestResult::Status::SUCCESS] + test_results[TestResult::Status::EXPECTED_FAILURE]; -- cgit v1.2.1