From 9fb0cac961f70d1937c5fa3eafeaee1385c89768 Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Fri, 20 Apr 2018 15:46:21 +0100 Subject: COMPMID-1081: Introduced test-wide instruments Change-Id: I5831241f3fc503717cc51136453c2bf96d4b420b Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/128484 Tested-by: Jenkins Reviewed-by: Georgios Pinitas --- tests/validate_examples/RunExample.cpp | 53 ++++++++++++------------------- tests/validate_examples/ValidateExample.h | 14 ++++++-- 2 files changed, 32 insertions(+), 35 deletions(-) (limited to 'tests/validate_examples') diff --git a/tests/validate_examples/RunExample.cpp b/tests/validate_examples/RunExample.cpp index a7b18ce555..8b1c39b844 100644 --- a/tests/validate_examples/RunExample.cpp +++ b/tests/validate_examples/RunExample.cpp @@ -57,12 +57,19 @@ std::unique_ptr library; } // namespace test namespace utils { -static ValidateExample *g_example = nullptr; -template +static std::unique_ptr g_example = nullptr; +static std::vector g_example_argv = {}; + +template class ExampleTest : public arm_compute::test::framework::TestCase { public: ExampleTest() = default; + void do_setup() override + { + ARM_COMPUTE_ERROR_ON_NULLPTR(g_example.get()); + g_example->do_setup(g_example_argv.size(), &g_example_argv[0]); + } void do_run() override { g_example->do_run(); @@ -74,10 +81,11 @@ public: g_example->do_validate(); } g_example->do_teardown(); + g_example = nullptr; } }; -int run_example(int argc, char **argv, ValidateExample &example) +int run_example(int argc, char **argv, std::unique_ptr example) { framework::CommandLineParser parser; framework::CommonOptions options(parser); @@ -99,43 +107,18 @@ int run_example(int argc, char **argv, ValidateExample &example) } std::vector> printers = options.create_printers(); - g_example = &example; - std::vector example_argv = {}; - example_argv.clear(); - example_argv.emplace_back(argv[0]); + g_example = std::move(example); + g_example_argv.clear(); + g_example_argv.emplace_back(argv[0]); for(auto &arg : example_args->value()) { - example_argv.emplace_back(const_cast(arg.c_str())); // NOLINT + g_example_argv.emplace_back(const_cast(arg.c_str())); // NOLINT } // Set number of threads in Scheduler Scheduler::get().set_num_threads(options.threads->value()); library = support::cpp14::make_unique("." /* Only using random values */, seed->value()); - // We need to do the setup here because framework.init() will need CL / GLES to be initialised - try - { - example.do_setup(example_argv.size(), &example_argv[0]); - } -#ifdef ARM_COMPUTE_CL - catch(cl::Error &err) - { - std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; - std::cerr << std::endl - << "ERROR " << err.what() << "(" << err.err() << ")" << std::endl; - std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; - return 1; - } -#endif /* ARM_COMPUTE_CL */ - catch(std::runtime_error &err) - { - std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; - std::cerr << std::endl - << "ERROR " << err.what() << " " << (errno ? strerror(errno) : "") << std::endl; - std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl; - return 1; - } - if(options.log_level->value() > framework::LogLevel::NONE) { for(auto &p : printers) @@ -153,6 +136,10 @@ int run_example(int argc, char **argv, ValidateExample &example) #ifdef ARM_COMPUTE_CL if(opencl_is_available()) { + if(!CLScheduler::get().is_initialised()) + { + CLScheduler::get().default_init(); + } p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version()); } else @@ -162,7 +149,7 @@ int run_example(int argc, char **argv, ValidateExample &example) #endif /* ARM_COMPUTE_CL */ p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value())); p->print_entry("Threads", support::cpp11::to_string(options.threads->value())); - example.print_parameters(*p); + g_example->print_parameters(*p); } } diff --git a/tests/validate_examples/ValidateExample.h b/tests/validate_examples/ValidateExample.h index cedbe3d0d9..4dd552ab10 100644 --- a/tests/validate_examples/ValidateExample.h +++ b/tests/validate_examples/ValidateExample.h @@ -40,14 +40,24 @@ namespace utils * * All examples with a validation stage have to inherit from this class. */ -class ValidateExample : public Example +class ValidateExample { public: + /** Setup the example. + * + * @param[in] argc Argument count. + * @param[in] argv Argument values. + */ + virtual void do_setup(int argc, char **argv) {}; + /** Run the example. */ + virtual void do_run() {}; /** Run reference implementation and validate against the target output */ virtual void do_validate() { } + /** Teardown the example. */ + virtual void do_teardown() {}; /** Print the example parameters * * @param[in,out] printer Printer to use to print the parameters @@ -65,7 +75,7 @@ public: * @param[in] argv Command line arguments * @param[in] example Example to run */ -int run_example(int argc, char **argv, ValidateExample &example); +int run_example(int argc, char **argv, std::unique_ptr example); } // namespace utils } // namespace arm_compute -- cgit v1.2.1