aboutsummaryrefslogtreecommitdiff
path: root/tests/main.cpp
diff options
context:
space:
mode:
authorAnthony Barbier <anthony.barbier@arm.com>2018-01-05 10:59:12 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:42:33 +0000
commit6db0ff5b4bb49f834c7caa532a7feab228df10f9 (patch)
tree36c32ab3e94a86752d6b73c4a3503b191431d586 /tests/main.cpp
parentfde97fb84943d0328c2c532d117e9b875149f27e (diff)
downloadComputeLibrary-6db0ff5b4bb49f834c7caa532a7feab228df10f9.tar.gz
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 <bsgcomp@arm.com> Reviewed-by: Pablo Tello <pablo.tello@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'tests/main.cpp')
-rw-r--r--tests/main.cpp131
1 files changed, 14 insertions, 117 deletions
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<framework::InstrumentsDescription> allowed_instruments
- {
- std::pair<framework::InstrumentType, framework::ScaleFactor>(framework::InstrumentType::ALL, framework::ScaleFactor::NONE),
- std::pair<framework::InstrumentType, framework::ScaleFactor>(framework::InstrumentType::NONE, framework::ScaleFactor::NONE),
- };
-
- for(const auto &type : framework.available_instruments())
- {
- allowed_instruments.insert(type);
- }
-
std::set<framework::DatasetMode> allowed_modes
{
framework::DatasetMode::PRECOMMIT,
@@ -91,52 +81,18 @@ int main(int argc, char **argv)
framework::DatasetMode::ALL
};
- std::set<framework::LogFormat> supported_log_formats
- {
- framework::LogFormat::NONE,
- framework::LogFormat::PRETTY,
- framework::LogFormat::JSON,
- };
-
- std::set<framework::LogLevel> 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<framework::ToggleOption>("help");
- help->set_help("Show this help message");
auto dataset_mode = parser.add_option<framework::EnumOption<framework::DatasetMode>>("mode", allowed_modes, framework::DatasetMode::PRECOMMIT);
dataset_mode->set_help("For managed datasets select which group to use");
- auto instruments = parser.add_option<framework::EnumListOption<framework::InstrumentsDescription>>("instruments", allowed_instruments, std::initializer_list<framework::InstrumentsDescription> { std::pair<framework::InstrumentType, framework::ScaleFactor>(framework::InstrumentType::WALL_CLOCK_TIMER, framework::ScaleFactor::NONE) });
- instruments->set_help("Set the profiling instruments to use");
- auto iterations = parser.add_option<framework::SimpleOption<int>>("iterations", 1);
- iterations->set_help("Number of iterations per test case");
- auto threads = parser.add_option<framework::SimpleOption<int>>("threads", 1);
- threads->set_help("Number of threads to use");
- auto log_format = parser.add_option<framework::EnumOption<framework::LogFormat>>("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<framework::SimpleOption<std::string>>("filter", ".*");
filter->set_help("Regular expression to select test cases");
auto filter_id = parser.add_option<framework::SimpleOption<std::string>>("filter-id");
filter_id->set_help("List of test ids. ... can be used to define a range.");
- auto log_file = parser.add_option<framework::SimpleOption<std::string>>("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<framework::EnumOption<framework::LogLevel>>("log-level", supported_log_levels, framework::LogLevel::ALL);
- log_level->set_help("Verbosity of the output");
- auto throw_errors = parser.add_option<framework::ToggleOption>("throw-errors");
- throw_errors->set_help("Don't catch fatal errors (useful for debugging)");
auto stop_on_error = parser.add_option<framework::ToggleOption>("stop-on-error");
stop_on_error->set_help("Abort execution after the first failed test (useful for debugging)");
auto seed = parser.add_option<framework::SimpleOption<std::random_device::result_type>>("seed", std::random_device()());
seed->set_help("Global seed for random number generation");
- auto color_output = parser.add_option<framework::ToggleOption>("color-output", true);
- color_output->set_help("Produce colored output on the console");
auto list_tests = parser.add_option<framework::ToggleOption>("list-tests", false);
list_tests->set_help("List all test names");
auto test_instruments = parser.add_option<framework::ToggleOption>("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<framework::SimpleOption<std::string>>("assets");
assets->set_help("Path to the assets directory");
- auto pretty_console = parser.add_option<framework::ToggleOption>("pretty-console", false);
- pretty_console->set_help("Produce pretty output on the console");
- auto json_file = parser.add_option<framework::SimpleOption<std::string>>("json-file");
- json_file->set_help("Write output to a json file.");
- auto pretty_file = parser.add_option<framework::SimpleOption<std::string>>("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<std::unique_ptr<framework::Printer>> printers;
- std::vector<std::shared_ptr<std::ofstream>> log_streams;
-
- if(pretty_console->value() && (log_file->is_set() || log_format->value() != framework::LogFormat::PRETTY))
- {
- auto pretty_printer = support::cpp14::make_unique<framework::PrettyPrinter>();
- pretty_printer->set_color_output(color_output->value());
- printers.push_back(std::move(pretty_printer));
- }
-
- std::unique_ptr<framework::Printer> printer;
- switch(log_format->value())
- {
- case framework::LogFormat::JSON:
- printer = support::cpp14::make_unique<framework::JSONPrinter>();
- break;
- case framework::LogFormat::NONE:
- break;
- case framework::LogFormat::PRETTY:
- default:
- auto pretty_printer = support::cpp14::make_unique<framework::PrettyPrinter>();
- // 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<std::ofstream>(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<framework::JSONPrinter>());
- log_streams.push_back(std::make_shared<std::ofstream>(json_file->value()));
- printers.back()->set_stream(*log_streams.back().get());
- }
-
- if(pretty_file->is_set())
- {
- printers.push_back(support::cpp14::make_unique<framework::PrettyPrinter>());
- log_streams.push_back(std::make_shared<std::ofstream>(pretty_file->value()));
- printers.back()->set_stream(*log_streams.back().get());
- }
+ std::vector<std::unique_ptr<framework::Printer>> 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;
}