6 @page tests Validation and benchmarks tests
10 @section tests_overview Overview
12 Benchmark and validation tests are based on the same framework to setup and run
13 the tests. In addition to running simple, self-contained test functions the
14 framework supports fixtures and data test cases. The former allows to share
15 common setup routines between various backends thus reducing the amount of
16 duplicated code. The latter can be used to parameterize tests or fixtures with
17 different inputs, e.g. different tensor shapes. One limitation is that
18 tests/fixtures cannot be parameterized based on the data type if static type
19 information is needed within the test (e.g. to validate the results).
21 @note By default tests are not built. To enable them you need to add validation_tests=1 and / or benchmark_tests=1 to your SCons line.
23 @note Tests are not included in the pre-built binary archive, you have to build them from sources.
25 @subsection tests_overview_structure Directory structure
28 `-- tests <- Top level test directory. All files in here are shared among validation and benchmark.
29 |-- framework <- Underlying test framework.
31 |-- NEON -> Backend specific files with helper functions etc.
32 |-- benchmark <- Top level directory for the benchmarking files.
33 | |-- fixtures <- Fixtures for benchmark tests.
34 | |-- CL <- OpenCL backend test cases on a function level.
35 | | `-- SYSTEM <- OpenCL system tests, e.g. whole networks
36 | `-- NEON <- Same for NEON
38 |-- datasets <- Datasets for benchmark and validation tests.
39 |-- main.cpp <- Main entry point for the tests. Currently shared between validation and benchmarking.
40 |-- networks <- Network classes for system level tests.
41 `-- validation -> Top level directory for validation files.
42 |-- CPP -> C++ reference code
44 |-- NEON -> Backend specific test cases
45 `-- fixtures -> Fixtures shared among all backends. Used to setup target function and tensors.
47 @subsection tests_overview_fixtures Fixtures
49 Fixtures can be used to share common setup, teardown or even run tasks among
50 multiple test cases. For that purpose a fixture can define a `setup`,
51 `teardown` and `run` method. Additionally the constructor and destructor might
54 An instance of the fixture is created immediately before the actual test is
55 executed. After construction the @ref framework::Fixture::setup method is called. Then the test
56 function or the fixtures `run` method is invoked. After test execution the
57 @ref framework::Fixture::teardown method is called and lastly the fixture is destructed.
59 @subsubsection tests_overview_fixtures_fixture Fixture
61 Fixtures for non-parameterized test are straightforward. The custom fixture
62 class has to inherit from @ref framework::Fixture and choose to implement any of the
63 `setup`, `teardown` or `run` methods. None of the methods takes any arguments
66 class CustomFixture : public framework::Fixture
75 ARM_COMPUTE_ASSERT(_ptr != nullptr);
86 @subsubsection tests_overview_fixtures_data_fixture Data fixture
88 The advantage of a parameterized fixture is that arguments can be passed to the setup method at runtime. To make this possible the setup method has to be a template with a type parameter for every argument (though the template parameter doesn't have to be used). All other methods remain the same.
90 class CustomFixture : public framework::Fixture
92 #ifdef ALTERNATIVE_DECLARATION
93 template <typename ...>
94 void setup(size_t size)
108 ARM_COMPUTE_ASSERT(_ptr != nullptr);
119 @subsection tests_overview_test_cases Test cases
121 All following commands can be optionally prefixed with `EXPECTED_FAILURE_` or
124 @subsubsection tests_overview_test_cases_test_case Test case
126 A simple test case function taking no inputs and having no (shared) state.
128 - First argument is the name of the test case (has to be unique within the
129 enclosing test suite).
130 - Second argument is the dataset mode in which the test will be active.
133 TEST_CASE(TestCaseName, DatasetMode::PRECOMMIT)
135 ARM_COMPUTE_ASSERT_EQUAL(1 + 1, 2);
138 @subsubsection tests_overview_test_cases_fixture_fixture_test_case Fixture test case
140 A simple test case function taking no inputs that inherits from a fixture. The
141 test case will have access to all public and protected members of the fixture.
142 Only the setup and teardown methods of the fixture will be used. The body of
143 this function will be used as test function.
145 - First argument is the name of the test case (has to be unique within the
146 enclosing test suite).
147 - Second argument is the class name of the fixture.
148 - Third argument is the dataset mode in which the test will be active.
151 class FixtureName : public framework::Fixture
154 void setup() override
163 FIXTURE_TEST_CASE(TestCaseName, FixtureName, DatasetMode::PRECOMMIT)
165 ARM_COMPUTE_ASSERT_EQUAL(_one + 1, 2);
168 @subsubsection tests_overview_test_cases_fixture_register_fixture_test_case Registering a fixture as test case
170 Allows to use a fixture directly as test case. Instead of defining a new test
171 function the run method of the fixture will be executed.
173 - First argument is the name of the test case (has to be unique within the
174 enclosing test suite).
175 - Second argument is the class name of the fixture.
176 - Third argument is the dataset mode in which the test will be active.
179 class FixtureName : public framework::Fixture
182 void setup() override
189 ARM_COMPUTE_ASSERT_EQUAL(_one + 1, 2);
196 REGISTER_FIXTURE_TEST_CASE(TestCaseName, FixtureName, DatasetMode::PRECOMMIT);
199 @subsubsection tests_overview_test_cases_data_test_case Data test case
201 A parameterized test case function that has no (shared) state. The dataset will
202 be used to generate versions of the test case with different inputs.
204 - First argument is the name of the test case (has to be unique within the
205 enclosing test suite).
206 - Second argument is the dataset mode in which the test will be active.
207 - Third argument is the dataset.
208 - Further arguments specify names of the arguments to the test function. The
209 number must match the arity of the dataset.
212 DATA_TEST_CASE(TestCaseName, DatasetMode::PRECOMMIT, framework::make("Numbers", {1, 2, 3}), num)
214 ARM_COMPUTE_ASSERT(num < 4);
217 @subsubsection tests_overview_test_cases_fixture_data_test_case Fixture data test case
219 A parameterized test case that inherits from a fixture. The test case will have
220 access to all public and protected members of the fixture. Only the setup and
221 teardown methods of the fixture will be used. The setup method of the fixture
222 needs to be a template and has to accept inputs from the dataset as arguments.
223 The body of this function will be used as test function. The dataset will be
224 used to generate versions of the test case with different inputs.
226 - First argument is the name of the test case (has to be unique within the
227 enclosing test suite).
228 - Second argument is the class name of the fixture.
229 - Third argument is the dataset mode in which the test will be active.
230 - Fourth argument is the dataset.
233 class FixtureName : public framework::Fixture
236 template <typename T>
246 FIXTURE_DATA_TEST_CASE(TestCaseName, FixtureName, DatasetMode::PRECOMMIT, framework::make("Numbers", {1, 2, 3}))
248 ARM_COMPUTE_ASSERT(_num < 4);
251 @subsubsection tests_overview_test_cases_register_fixture_data_test_case Registering a fixture as data test case
253 Allows to use a fixture directly as parameterized test case. Instead of
254 defining a new test function the run method of the fixture will be executed.
255 The setup method of the fixture needs to be a template and has to accept inputs
256 from the dataset as arguments. The dataset will be used to generate versions of
257 the test case with different inputs.
259 - First argument is the name of the test case (has to be unique within the
260 enclosing test suite).
261 - Second argument is the class name of the fixture.
262 - Third argument is the dataset mode in which the test will be active.
263 - Fourth argument is the dataset.
266 class FixtureName : public framework::Fixture
269 template <typename T>
277 ARM_COMPUTE_ASSERT(_num < 4);
284 REGISTER_FIXTURE_DATA_TEST_CASE(TestCaseName, FixtureName, DatasetMode::PRECOMMIT, framework::make("Numbers", {1, 2, 3}));
286 @section writing_tests Writing validation tests
288 Before starting a new test case have a look at the existing ones. They should
289 provide a good overview how test cases are structured.
291 - The C++ reference needs to be added to `tests/validation/CPP/`. The
292 reference function is typically a template parameterized by the underlying
293 value type of the `SimpleTensor`. This makes it easy to specialise for
294 different data types.
295 - If all backends have a common interface it makes sense to share the setup
296 code. This can be done by adding a fixture in
297 `tests/validation/fixtures/`. Inside of the `setup` method of a fixture
298 the tensors can be created and initialised and the function can be configured
299 and run. The actual test will only have to validate the results. To be shared
300 among multiple backends the fixture class is usually a template that accepts
301 the specific types (data, tensor class, function class etc.) as parameters.
302 - The actual test cases need to be added for each backend individually.
303 Typically the will be multiple tests for different data types and for
304 different execution modes, e.g. precommit and nightly.
306 @section tests_running_tests Running tests
307 @subsection tests_running_tests_benchmarking Benchmarking
308 @subsubsection tests_running_tests_benchmarking_filter Filter tests
309 All tests can be run by invoking
311 ./arm_compute_benchmark ./data
313 where `./data` contains the assets needed by the tests.
315 If only a subset of the tests has to be executed the `--filter` option takes a
316 regular expression to select matching tests.
318 ./arm_compute_benchmark --filter='^NEON/.*AlexNet' ./data
320 @note Filtering will be much faster if the regular expression starts from the start ("^") or end ("$") of the line.
322 Additionally each test has a test id which can be used as a filter, too.
323 However, the test id is not guaranteed to be stable when new tests are added.
324 Only for a specific build the same the test will keep its id.
326 ./arm_compute_benchmark --filter-id=10 ./data
328 All available tests can be displayed with the `--list-tests` switch.
330 ./arm_compute_benchmark --list-tests
332 More options can be found in the `--help` message.
334 @subsubsection tests_running_tests_benchmarking_runtime Runtime
335 By default every test is run once on a single thread. The number of iterations
336 can be controlled via the `--iterations` option and the number of threads via
339 @subsubsection tests_running_tests_benchmarking_output Output
340 By default the benchmarking results are printed in a human readable format on
341 the command line. The colored output can be disabled via `--no-color-output`.
342 As an alternative output format JSON is supported and can be selected via
343 `--log-format=json`. To write the output to a file instead of stdout the
344 `--log-file` option can be used.
346 @subsubsection tests_running_tests_benchmarking_mode Mode
347 Tests contain different datasets of different sizes, some of which will take several hours to run.
348 You can select which datasets to use by using the `--mode` option, we recommed you use `--mode=precommit` to start with.
350 @subsubsection tests_running_tests_benchmarking_instruments Instruments
351 You can use the `--instruments` option to select one or more instruments to measure the execution time of the benchmark tests.
353 `PMU` will try to read the CPU PMU events from the kernel (They need to be enabled on your platform)
355 `MALI` will try to collect Mali hardware performance counters. (You need to have a recent enough Mali driver)
357 `WALL_CLOCK_TIMER` will measure time using `gettimeofday`: this should work on all platforms.
359 You can pass a combinations of these instruments: `--instruments=PMU,MALI,WALL_CLOCK_TIMER`
361 @note You need to make sure the instruments have been selected at compile time using the `pmu=1` or `mali=1` scons options.
363 @subsubsection tests_running_examples Examples
365 To run all the precommit validation tests:
367 LD_LIBRARY_PATH=. ./arm_compute_validation --mode=precommit
369 To run the OpenCL precommit validation tests:
371 LD_LIBRARY_PATH=. ./arm_compute_validation --mode=precommit --filter="^CL.*"
373 To run the NEON precommit benchmark tests with PMU and Wall Clock timer in miliseconds instruments enabled:
375 LD_LIBRARY_PATH=. ./arm_compute_benchmark --mode=precommit --filter="^NEON.*" --instruments="pmu,wall_clock_timer_ms" --iterations=10
377 To run the OpenCL precommit benchmark tests with OpenCL kernel timers in miliseconds enabled:
379 LD_LIBRARY_PATH=. ./arm_compute_benchmark --mode=precommit --filter="^CL.*" --instruments="opencl_timer_ms" --iterations=10
382 } // namespace arm_compute