From 6db0ff5b4bb49f834c7caa532a7feab228df10f9 Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Fri, 5 Jan 2018 10:59:12 +0000 Subject: COMPMID-771 Allow examples to be profiled Change-Id: I180281e796e1670b9ad391d82d66ecde0119ef78 Note: this is for internal use only which is why I think the hackiness of RunExample.cpp is acceptable. Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115154 Tested-by: Jenkins Reviewed-by: Pablo Tello Reviewed-by: Georgios Pinitas --- tests/main.cpp | 131 ++++++--------------------------------------------------- 1 file changed, 14 insertions(+), 117 deletions(-) (limited to 'tests/main.cpp') diff --git a/tests/main.cpp b/tests/main.cpp index c62de66588..1797b21114 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017, 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -30,6 +30,7 @@ #include "tests/framework/Profiler.h" #include "tests/framework/command_line/CommandLineOptions.h" #include "tests/framework/command_line/CommandLineParser.h" +#include "tests/framework/command_line/CommonOptions.h" #include "tests/framework/instruments/Instruments.h" #include "tests/framework/printers/Printers.h" @@ -73,17 +74,6 @@ int main(int argc, char **argv) framework::CommandLineParser parser; - std::set allowed_instruments - { - std::pair(framework::InstrumentType::ALL, framework::ScaleFactor::NONE), - std::pair(framework::InstrumentType::NONE, framework::ScaleFactor::NONE), - }; - - for(const auto &type : framework.available_instruments()) - { - allowed_instruments.insert(type); - } - std::set allowed_modes { framework::DatasetMode::PRECOMMIT, @@ -91,52 +81,18 @@ int main(int argc, char **argv) framework::DatasetMode::ALL }; - std::set supported_log_formats - { - framework::LogFormat::NONE, - framework::LogFormat::PRETTY, - framework::LogFormat::JSON, - }; - - std::set supported_log_levels - { - framework::LogLevel::NONE, - framework::LogLevel::CONFIG, - framework::LogLevel::TESTS, - framework::LogLevel::ERRORS, - framework::LogLevel::DEBUG, - framework::LogLevel::MEASUREMENTS, - framework::LogLevel::ALL, - }; + framework::CommonOptions options(parser); - auto help = parser.add_option("help"); - help->set_help("Show this help message"); auto dataset_mode = parser.add_option>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT); dataset_mode->set_help("For managed datasets select which group to use"); - auto instruments = parser.add_option>("instruments", allowed_instruments, std::initializer_list { std::pair(framework::InstrumentType::WALL_CLOCK_TIMER, framework::ScaleFactor::NONE) }); - instruments->set_help("Set the profiling instruments to use"); - auto iterations = parser.add_option>("iterations", 1); - iterations->set_help("Number of iterations per test case"); - auto threads = parser.add_option>("threads", 1); - threads->set_help("Number of threads to use"); - auto log_format = parser.add_option>("log-format", supported_log_formats, framework::LogFormat::PRETTY); - log_format->set_help("Output format for measurements and failures (affects only log-file)"); auto filter = parser.add_option>("filter", ".*"); filter->set_help("Regular expression to select test cases"); auto filter_id = parser.add_option>("filter-id"); filter_id->set_help("List of test ids. ... can be used to define a range."); - auto log_file = parser.add_option>("log-file"); - log_file->set_help("Write output to file instead of to the console (affected by log-format)"); - auto log_level = parser.add_option>("log-level", supported_log_levels, framework::LogLevel::ALL); - log_level->set_help("Verbosity of the output"); - auto throw_errors = parser.add_option("throw-errors"); - throw_errors->set_help("Don't catch fatal errors (useful for debugging)"); auto stop_on_error = parser.add_option("stop-on-error"); stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)"); auto seed = parser.add_option>("seed", std::random_device()()); seed->set_help("Global seed for random number generation"); - auto color_output = parser.add_option("color-output", true); - color_output->set_help("Produce colored output on the console"); auto list_tests = parser.add_option("list-tests", false); list_tests->set_help("List all test names"); auto test_instruments = parser.add_option("test-instruments", false); @@ -145,81 +101,22 @@ int main(int argc, char **argv) error_on_missing_assets->set_help("Mark a test as failed instead of skipping it when assets are missing"); auto assets = parser.add_positional_option>("assets"); assets->set_help("Path to the assets directory"); - auto pretty_console = parser.add_option("pretty-console", false); - pretty_console->set_help("Produce pretty output on the console"); - auto json_file = parser.add_option>("json-file"); - json_file->set_help("Write output to a json file."); - auto pretty_file = parser.add_option>("pretty-file"); - pretty_file->set_help("Write output to a text file"); try { parser.parse(argc, argv); - if(help->is_set() && help->value()) + if(options.help->is_set() && options.help->value()) { parser.print_help(argv[0]); return 0; } - std::vector> printers; - std::vector> log_streams; - - if(pretty_console->value() && (log_file->is_set() || log_format->value() != framework::LogFormat::PRETTY)) - { - auto pretty_printer = support::cpp14::make_unique(); - pretty_printer->set_color_output(color_output->value()); - printers.push_back(std::move(pretty_printer)); - } - - std::unique_ptr printer; - switch(log_format->value()) - { - case framework::LogFormat::JSON: - printer = support::cpp14::make_unique(); - break; - case framework::LogFormat::NONE: - break; - case framework::LogFormat::PRETTY: - default: - auto pretty_printer = support::cpp14::make_unique(); - // Don't use colours if we print to a file: - pretty_printer->set_color_output((!log_file->is_set()) && color_output->value()); - printer = std::move(pretty_printer); - break; - } - - if(log_file->is_set()) - { - log_streams.push_back(std::make_shared(log_file->value())); - if(printer != nullptr) - { - printer->set_stream(*log_streams.back().get()); - } - } - - if(printer != nullptr) - { - printers.push_back(std::move(printer)); - } - - if(json_file->is_set()) - { - printers.push_back(support::cpp14::make_unique()); - log_streams.push_back(std::make_shared(json_file->value())); - printers.back()->set_stream(*log_streams.back().get()); - } - - if(pretty_file->is_set()) - { - printers.push_back(support::cpp14::make_unique()); - log_streams.push_back(std::make_shared(pretty_file->value())); - printers.back()->set_stream(*log_streams.back().get()); - } + std::vector> printers = options.create_printers(); - Scheduler::get().set_num_threads(threads->value()); + Scheduler::get().set_num_threads(options.threads->value()); - if(log_level->value() > framework::LogLevel::NONE) + if(options.log_level->value() > framework::LogLevel::NONE) { for(auto &p : printers) { @@ -227,13 +124,13 @@ int main(int argc, char **argv) } } - if(log_level->value() >= framework::LogLevel::CONFIG) + if(options.log_level->value() >= framework::LogLevel::CONFIG) { for(auto &p : printers) { p->print_entry("Seed", support::cpp11::to_string(seed->value())); - p->print_entry("Iterations", support::cpp11::to_string(iterations->value())); - p->print_entry("Threads", support::cpp11::to_string(threads->value())); + p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value())); + p->print_entry("Threads", support::cpp11::to_string(options.threads->value())); { using support::cpp11::to_string; p->print_entry("Dataset mode", to_string(dataset_mode->value())); @@ -241,12 +138,12 @@ int main(int argc, char **argv) } } - framework.init(instruments->value(), iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), log_level->value()); + framework.init(options.instruments->value(), options.iterations->value(), dataset_mode->value(), filter->value(), filter_id->value(), options.log_level->value()); for(auto &p : printers) { framework.add_printer(p.get()); } - framework.set_throw_errors(throw_errors->value()); + framework.set_throw_errors(options.throw_errors->value()); framework.set_stop_on_error(stop_on_error->value()); framework.set_error_on_missing_assets(error_on_missing_assets->value()); @@ -285,7 +182,7 @@ int main(int argc, char **argv) success = framework.run(); - if(log_level->value() > framework::LogLevel::NONE) + if(options.log_level->value() > framework::LogLevel::NONE) { for(auto &p : printers) { @@ -299,7 +196,7 @@ int main(int argc, char **argv) { std::cerr << error.what() << "\n"; - if(throw_errors->value()) + if(options.throw_errors->value()) { throw; } -- cgit v1.2.1