aboutsummaryrefslogtreecommitdiff
path: root/tests/validate_examples
diff options
context:
space:
mode:
authorAnthony Barbier <anthony.barbier@arm.com>2018-04-20 15:46:21 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:49:54 +0000
commit9fb0cac961f70d1937c5fa3eafeaee1385c89768 (patch)
tree9a8847053f65631e050c231645549adb48c92fb8 /tests/validate_examples
parentfda901f0485371e8b6a807c8dd9614560a924793 (diff)
downloadComputeLibrary-9fb0cac961f70d1937c5fa3eafeaee1385c89768.tar.gz
COMPMID-1081: Introduced test-wide instruments
Change-Id: I5831241f3fc503717cc51136453c2bf96d4b420b Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/128484 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'tests/validate_examples')
-rw-r--r--tests/validate_examples/RunExample.cpp53
-rw-r--r--tests/validate_examples/ValidateExample.h14
2 files changed, 32 insertions, 35 deletions
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<AssetsLibrary> library;
} // namespace test
namespace utils
{
-static ValidateExample *g_example = nullptr;
-template <bool validate>
+static std::unique_ptr<ValidateExample> g_example = nullptr;
+static std::vector<char *> g_example_argv = {};
+
+template <bool validate>
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<ValidateExample> example)
{
framework::CommandLineParser parser;
framework::CommonOptions options(parser);
@@ -99,43 +107,18 @@ int run_example(int argc, char **argv, ValidateExample &example)
}
std::vector<std::unique_ptr<framework::Printer>> printers = options.create_printers();
- g_example = &example;
- std::vector<char *> 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<char *>(arg.c_str())); // NOLINT
+ g_example_argv.emplace_back(const_cast<char *>(arg.c_str())); // NOLINT
}
// Set number of threads in Scheduler
Scheduler::get().set_num_threads(options.threads->value());
library = support::cpp14::make_unique<AssetsLibrary>("." /* 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<ValidateExample> example);
} // namespace utils
} // namespace arm_compute