blob: 27e84059cce7efe95bf848342c90f5ba2ca98e16 [file] [log] [blame]
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +00001///
2/// Copyright (c) 2017-2018 ARM Limited.
3///
4/// SPDX-License-Identifier: MIT
5///
6/// Permission is hereby granted, free of charge, to any person obtaining a copy
7/// of this software and associated documentation files (the "Software"), to
8/// deal in the Software without restriction, including without limitation the
9/// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10/// sell copies of the Software, and to permit persons to whom the Software is
11/// furnished to do so, subject to the following conditions:
12///
13/// The above copyright notice and this permission notice shall be included in all
14/// copies or substantial portions of the Software.
15///
16/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22/// SOFTWARE.
23///
Moritz Pflanzere3e73452017-08-11 15:40:16 +010024namespace arm_compute
25{
26namespace test
27{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028/**
Anthony Barbier79c61782017-06-23 11:48:24 +010029@page tests Validation and benchmarks tests
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
31@tableofcontents
32
Moritz Pflanzere3e73452017-08-11 15:40:16 +010033@section tests_overview Overview
34
35Benchmark and validation tests are based on the same framework to setup and run
36the tests. In addition to running simple, self-contained test functions the
37framework supports fixtures and data test cases. The former allows to share
38common setup routines between various backends thus reducing the amount of
39duplicated code. The latter can be used to parameterize tests or fixtures with
40different inputs, e.g. different tensor shapes. One limitation is that
41tests/fixtures cannot be parameterized based on the data type if static type
42information is needed within the test (e.g. to validate the results).
43
Anthony Barbiercc0a80b2017-12-15 11:37:29 +000044@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.
45
46@note Tests are not included in the pre-built binary archive, you have to build them from sources.
47
Moritz Pflanzere3e73452017-08-11 15:40:16 +010048@subsection tests_overview_structure Directory structure
49
50 .
51 |-- computer_vision <- Legacy tests. No new test must be added. <!-- FIXME: Remove before release -->
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010052 `-- tests <- Top level test directory. All files in here are shared among validation and benchmark.
53 |-- framework <- Underlying test framework.
Moritz Pflanzere3e73452017-08-11 15:40:16 +010054 |-- CL \
55 |-- NEON -> Backend specific files with helper functions etc.
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010056 |-- VX / <!-- FIXME: Remove VX -->
57 |-- benchmark <- Top level directory for the benchmarking files.
58 | |-- fixtures <- Fixtures for benchmark tests.
59 | |-- CL <- OpenCL backend test cases on a function level.
Moritz Pflanzere3e73452017-08-11 15:40:16 +010060 | | `-- SYSTEM <- OpenCL system tests, e.g. whole networks
61 | `-- NEON <- Same for NEON
62 | `-- SYSTEM
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010063 |-- datasets <- Datasets for benchmark and validation tests.
Moritz Pflanzere3e73452017-08-11 15:40:16 +010064 |-- main.cpp <- Main entry point for the tests. Currently shared between validation and benchmarking.
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010065 |-- networks <- Network classes for system level tests.
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010066 `-- validation -> Top level directory for validation files.
Moritz Pflanzere3e73452017-08-11 15:40:16 +010067 |-- CPP -> C++ reference code
68 |-- CL \
69 |-- NEON -> Backend specific test cases
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010070 |-- VX / <!-- FIXME: Remove VX -->
Moritz Pflanzere3e73452017-08-11 15:40:16 +010071 `-- fixtures -> Fixtures shared among all backends. Used to setup target function and tensors.
72
73@subsection tests_overview_fixtures Fixtures
74
75Fixtures can be used to share common setup, teardown or even run tasks among
76multiple test cases. For that purpose a fixture can define a `setup`,
77`teardown` and `run` method. Additionally the constructor and destructor might
78also be customized.
79
80An instance of the fixture is created immediately before the actual test is
81executed. After construction the @ref framework::Fixture::setup method is called. Then the test
82function or the fixtures `run` method is invoked. After test execution the
83@ref framework::Fixture::teardown method is called and lastly the fixture is destructed.
84
85@subsubsection tests_overview_fixtures_fixture Fixture
86
87Fixtures for non-parameterized test are straightforward. The custom fixture
88class has to inherit from @ref framework::Fixture and choose to implement any of the
89`setup`, `teardown` or `run` methods. None of the methods takes any arguments
90or returns anything.
91
92 class CustomFixture : public framework::Fixture
93 {
94 void setup()
95 {
96 _ptr = malloc(4000);
97 }
98
99 void run()
100 {
101 ARM_COMPUTE_ASSERT(_ptr != nullptr);
102 }
103
104 void teardown()
105 {
106 free(_ptr);
107 }
108
109 void *_ptr;
110 };
111
112@subsubsection tests_overview_fixtures_data_fixture Data fixture
113
114The 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.
115
116 class CustomFixture : public framework::Fixture
117 {
118 #ifdef ALTERNATIVE_DECLARATION
119 template <typename ...>
120 void setup(size_t size)
121 {
122 _ptr = malloc(size);
123 }
124 #else
125 template <typename T>
126 void setup(T size)
127 {
128 _ptr = malloc(size);
129 }
130 #endif
131
132 void run()
133 {
134 ARM_COMPUTE_ASSERT(_ptr != nullptr);
135 }
136
137 void teardown()
138 {
139 free(_ptr);
140 }
141
142 void *_ptr;
143 };
144
145@subsection tests_overview_test_cases Test cases
146
147All following commands can be optionally prefixed with `EXPECTED_FAILURE_` or
148`DISABLED_`.
149
150@subsubsection tests_overview_test_cases_test_case Test case
151
152A simple test case function taking no inputs and having no (shared) state.
153
154- First argument is the name of the test case (has to be unique within the
155 enclosing test suite).
156- Second argument is the dataset mode in which the test will be active.
157
158
159 TEST_CASE(TestCaseName, DatasetMode::PRECOMMIT)
160 {
161 ARM_COMPUTE_ASSERT_EQUAL(1 + 1, 2);
162 }
163
164@subsubsection tests_overview_test_cases_fixture_fixture_test_case Fixture test case
165
166A simple test case function taking no inputs that inherits from a fixture. The
167test case will have access to all public and protected members of the fixture.
168Only the setup and teardown methods of the fixture will be used. The body of
169this function will be used as test function.
170
171- First argument is the name of the test case (has to be unique within the
172 enclosing test suite).
173- Second argument is the class name of the fixture.
174- Third argument is the dataset mode in which the test will be active.
175
176
177 class FixtureName : public framework::Fixture
178 {
179 public:
180 void setup() override
181 {
182 _one = 1;
183 }
184
185 protected:
186 int _one;
187 };
188
189 FIXTURE_TEST_CASE(TestCaseName, FixtureName, DatasetMode::PRECOMMIT)
190 {
191 ARM_COMPUTE_ASSERT_EQUAL(_one + 1, 2);
192 }
193
194@subsubsection tests_overview_test_cases_fixture_register_fixture_test_case Registering a fixture as test case
195
196Allows to use a fixture directly as test case. Instead of defining a new test
197function the run method of the fixture will be executed.
198
199- First argument is the name of the test case (has to be unique within the
200 enclosing test suite).
201- Second argument is the class name of the fixture.
202- Third argument is the dataset mode in which the test will be active.
203
204
205 class FixtureName : public framework::Fixture
206 {
207 public:
208 void setup() override
209 {
210 _one = 1;
211 }
212
213 void run() override
214 {
215 ARM_COMPUTE_ASSERT_EQUAL(_one + 1, 2);
216 }
217
218 protected:
219 int _one;
220 };
221
222 REGISTER_FIXTURE_TEST_CASE(TestCaseName, FixtureName, DatasetMode::PRECOMMIT);
223
224
225@subsubsection tests_overview_test_cases_data_test_case Data test case
226
227A parameterized test case function that has no (shared) state. The dataset will
228be used to generate versions of the test case with different inputs.
229
230- First argument is the name of the test case (has to be unique within the
231 enclosing test suite).
232- Second argument is the dataset mode in which the test will be active.
233- Third argument is the dataset.
234- Further arguments specify names of the arguments to the test function. The
235 number must match the arity of the dataset.
236
237
238 DATA_TEST_CASE(TestCaseName, DatasetMode::PRECOMMIT, framework::make("Numbers", {1, 2, 3}), num)
239 {
240 ARM_COMPUTE_ASSERT(num < 4);
241 }
242
243@subsubsection tests_overview_test_cases_fixture_data_test_case Fixture data test case
244
245A parameterized test case that inherits from a fixture. The test case will have
246access to all public and protected members of the fixture. Only the setup and
247teardown methods of the fixture will be used. The setup method of the fixture
248needs to be a template and has to accept inputs from the dataset as arguments.
249The body of this function will be used as test function. The dataset will be
250used to generate versions of the test case with different inputs.
251
252- First argument is the name of the test case (has to be unique within the
253 enclosing test suite).
254- Second argument is the class name of the fixture.
255- Third argument is the dataset mode in which the test will be active.
256- Fourth argument is the dataset.
257
258
259 class FixtureName : public framework::Fixture
260 {
261 public:
262 template <typename T>
263 void setup(T num)
264 {
265 _num = num;
266 }
267
268 protected:
269 int _num;
270 };
271
272 FIXTURE_DATA_TEST_CASE(TestCaseName, FixtureName, DatasetMode::PRECOMMIT, framework::make("Numbers", {1, 2, 3}))
273 {
274 ARM_COMPUTE_ASSERT(_num < 4);
275 }
276
277@subsubsection tests_overview_test_cases_register_fixture_data_test_case Registering a fixture as data test case
278
279Allows to use a fixture directly as parameterized test case. Instead of
280defining a new test function the run method of the fixture will be executed.
281The setup method of the fixture needs to be a template and has to accept inputs
282from the dataset as arguments. The dataset will be used to generate versions of
283the test case with different inputs.
284
285- First argument is the name of the test case (has to be unique within the
286 enclosing test suite).
287- Second argument is the class name of the fixture.
288- Third argument is the dataset mode in which the test will be active.
289- Fourth argument is the dataset.
290
291
292 class FixtureName : public framework::Fixture
293 {
294 public:
295 template <typename T>
296 void setup(T num)
297 {
298 _num = num;
299 }
300
301 void run() override
302 {
303 ARM_COMPUTE_ASSERT(_num < 4);
304 }
305
306 protected:
307 int _num;
308 };
309
310 REGISTER_FIXTURE_DATA_TEST_CASE(TestCaseName, FixtureName, DatasetMode::PRECOMMIT, framework::make("Numbers", {1, 2, 3}));
311
312@section writing_tests Writing validation tests
313
314Before starting a new test case have a look at the existing ones. They should
315provide a good overview how test cases are structured.
316
Anthony Barbier144d2ff2017-09-29 10:46:08 +0100317- The C++ reference needs to be added to `tests/validation/CPP/`. The
Moritz Pflanzere3e73452017-08-11 15:40:16 +0100318 reference function is typically a template parameterized by the underlying
319 value type of the `SimpleTensor`. This makes it easy to specialise for
320 different data types.
321- If all backends have a common interface it makes sense to share the setup
322 code. This can be done by adding a fixture in
Anthony Barbier144d2ff2017-09-29 10:46:08 +0100323 `tests/validation/fixtures/`. Inside of the `setup` method of a fixture
Moritz Pflanzere3e73452017-08-11 15:40:16 +0100324 the tensors can be created and initialised and the function can be configured
325 and run. The actual test will only have to validate the results. To be shared
326 among multiple backends the fixture class is usually a template that accepts
327 the specific types (data, tensor class, function class etc.) as parameters.
328- The actual test cases need to be added for each backend individually.
329 Typically the will be multiple tests for different data types and for
330 different execution modes, e.g. precommit and nightly.
331
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100332@section tests_running_tests Running tests
Anthony Barbier38e7f1f2018-05-21 13:37:47 +0100333@subsection tests_running_tests_benchmark_and_validation Benchmarking and validation suites
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100334@subsubsection tests_running_tests_benchmarking_filter Filter tests
335All tests can be run by invoking
336
Moritz Pflanzer2b26b852017-07-21 10:09:30 +0100337 ./arm_compute_benchmark ./data
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100338
339where `./data` contains the assets needed by the tests.
340
Moritz Pflanzer2b26b852017-07-21 10:09:30 +0100341If only a subset of the tests has to be executed the `--filter` option takes a
342regular expression to select matching tests.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100343
Anthony Barbiercc0a80b2017-12-15 11:37:29 +0000344 ./arm_compute_benchmark --filter='^NEON/.*AlexNet' ./data
345
346@note Filtering will be much faster if the regular expression starts from the start ("^") or end ("$") of the line.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100347
Moritz Pflanzer2b26b852017-07-21 10:09:30 +0100348Additionally each test has a test id which can be used as a filter, too.
349However, the test id is not guaranteed to be stable when new tests are added.
350Only for a specific build the same the test will keep its id.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100351
Moritz Pflanzer2b26b852017-07-21 10:09:30 +0100352 ./arm_compute_benchmark --filter-id=10 ./data
353
354All available tests can be displayed with the `--list-tests` switch.
355
356 ./arm_compute_benchmark --list-tests
357
358More options can be found in the `--help` message.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100359
360@subsubsection tests_running_tests_benchmarking_runtime Runtime
Moritz Pflanzer2b26b852017-07-21 10:09:30 +0100361By default every test is run once on a single thread. The number of iterations
362can be controlled via the `--iterations` option and the number of threads via
363`--threads`.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100364
Moritz Pflanzer2b26b852017-07-21 10:09:30 +0100365@subsubsection tests_running_tests_benchmarking_output Output
366By default the benchmarking results are printed in a human readable format on
367the command line. The colored output can be disabled via `--no-color-output`.
368As an alternative output format JSON is supported and can be selected via
369`--log-format=json`. To write the output to a file instead of stdout the
370`--log-file` option can be used.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100371
Anthony Barbier144d2ff2017-09-29 10:46:08 +0100372@subsubsection tests_running_tests_benchmarking_mode Mode
373Tests contain different datasets of different sizes, some of which will take several hours to run.
374You can select which datasets to use by using the `--mode` option, we recommed you use `--mode=precommit` to start with.
375
376@subsubsection tests_running_tests_benchmarking_instruments Instruments
377You can use the `--instruments` option to select one or more instruments to measure the execution time of the benchmark tests.
378
379`PMU` will try to read the CPU PMU events from the kernel (They need to be enabled on your platform)
380
381`MALI` will try to collect Mali hardware performance counters. (You need to have a recent enough Mali driver)
382
Anthony Barbiercc0a80b2017-12-15 11:37:29 +0000383`WALL_CLOCK_TIMER` will measure time using `gettimeofday`: this should work on all platforms.
Anthony Barbier144d2ff2017-09-29 10:46:08 +0100384
Anthony Barbiercc0a80b2017-12-15 11:37:29 +0000385You can pass a combinations of these instruments: `--instruments=PMU,MALI,WALL_CLOCK_TIMER`
Anthony Barbier144d2ff2017-09-29 10:46:08 +0100386
387@note You need to make sure the instruments have been selected at compile time using the `pmu=1` or `mali=1` scons options.
388
Anthony Barbiercc0a80b2017-12-15 11:37:29 +0000389@subsubsection tests_running_examples Examples
390
391To run all the precommit validation tests:
392
393 LD_LIBRARY_PATH=. ./arm_compute_validation --mode=precommit
394
395To run the OpenCL precommit validation tests:
396
397 LD_LIBRARY_PATH=. ./arm_compute_validation --mode=precommit --filter="^CL.*"
398
399To run the NEON precommit benchmark tests with PMU and Wall Clock timer in miliseconds instruments enabled:
400
401 LD_LIBRARY_PATH=. ./arm_compute_benchmark --mode=precommit --filter="^NEON.*" --instruments="pmu,wall_clock_timer_ms" --iterations=10
402
403To run the OpenCL precommit benchmark tests with OpenCL kernel timers in miliseconds enabled:
404
405 LD_LIBRARY_PATH=. ./arm_compute_benchmark --mode=precommit --filter="^CL.*" --instruments="opencl_timer_ms" --iterations=10
406
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100407*/
Moritz Pflanzere3e73452017-08-11 15:40:16 +0100408} // namespace test
409} // namespace arm_compute