xref: /dpdk/doc/guides/contributing/unit_test.rst (revision f5c5ab7ef83938d50c067009fde28afc3ca6a28e)
1959710f1SAaron Conole.. SPDX-License-Identifier: BSD-3-Clause
2959710f1SAaron Conole   Copyright 2021 The DPDK contributors
3959710f1SAaron Conole
4959710f1SAaron ConoleDPDK Unit Testing Guidelines
5959710f1SAaron Conole============================
6959710f1SAaron Conole
7959710f1SAaron ConoleThis document outlines the guidelines for running and adding new
8959710f1SAaron Conoletests to the in-tree DPDK test suites.
9959710f1SAaron Conole
10959710f1SAaron ConoleThe DPDK test suite model is loosely based on the xUnit model,
11959710f1SAaron Conolewhere tests are grouped into test suites, and suites are run by runners.
12959710f1SAaron ConoleFor a basic overview, see the basic Wikipedia article on `xUnit
13959710f1SAaron Conole<https://en.wikipedia.org/wiki/XUnit>`_.
14959710f1SAaron Conole
15959710f1SAaron Conole
16959710f1SAaron ConoleBackground
17959710f1SAaron Conole----------
18959710f1SAaron Conole
19959710f1SAaron ConoleThe in-tree testing infrastructure for DPDK consists of
20959710f1SAaron Conolemultiple applications and support tools.
21959710f1SAaron ConoleThe primary tools are the `dpdk-test` application,
22959710f1SAaron Conoleand the ``meson test`` infrastructure.
23959710f1SAaron ConoleThese two are the primary ways through which
24959710f1SAaron Conolea user will interact with the DPDK testing infrastructure.
25959710f1SAaron Conole
26959710f1SAaron ConoleThere exists a bit of confusion with the test suite and test case separation
27959710f1SAaron Conolewith respect to `dpdk-test` and ``meson test``.
28959710f1SAaron ConoleBoth have a concept of test suite and test case.
29959710f1SAaron ConoleIn both, the concept is similar.
30959710f1SAaron ConoleA test suite is a group of test cases,
31959710f1SAaron Conoleand a test case represents the steps needed to test a particular set of code.
32959710f1SAaron ConoleWhere needed, they will be disambiguated by the word `Meson`
33959710f1SAaron Conoleto denote a Meson test suite / case.
34959710f1SAaron Conole
35959710f1SAaron Conole
36959710f1SAaron ConoleRunning a test
37959710f1SAaron Conole--------------
38959710f1SAaron Conole
39959710f1SAaron ConoleDPDK tests are run via the main test runner, the `dpdk-test` app.
40959710f1SAaron ConoleThe `dpdk-test` app is a command-line interface that facilitates
41959710f1SAaron Conolerunning various tests or test suites.
42959710f1SAaron Conole
43959710f1SAaron ConoleThere are three modes of operation.
44959710f1SAaron ConoleThe first mode is as an interactive command shell
45959710f1SAaron Conolethat allows launching specific test suites.
46959710f1SAaron ConoleThis is the default operating mode of `dpdk-test` and can be done by::
47959710f1SAaron Conole
48959710f1SAaron Conole   $ ./build/app/test/dpdk-test --dpdk-options-here
49959710f1SAaron Conole   EAL: Detected 4 lcore(s)
50959710f1SAaron Conole   EAL: Detected 1 NUMA nodes
51959710f1SAaron Conole   EAL: Static memory layout is selected, amount of reserved memory...
52959710f1SAaron Conole   EAL: Multi-process socket /run/user/26934/dpdk/rte/mp_socket
53959710f1SAaron Conole   EAL: Selected IOVA mode 'VA'
54959710f1SAaron Conole   EAL: Probing VFIO support...
55959710f1SAaron Conole   EAL: PCI device 0000:00:1f.6 on NUMA socket -1
56959710f1SAaron Conole   EAL:   Invalid NUMA socket, default to 0
57959710f1SAaron Conole   EAL:   probe driver: 8086:15d7 net_e1000_em
58959710f1SAaron Conole   APP: HPET is not enabled, using TSC as default timer
59959710f1SAaron Conole   RTE>>
60959710f1SAaron Conole
61959710f1SAaron ConoleAt the prompt, simply type the name of the test suite you wish to run
62959710f1SAaron Conoleand it will execute.
63959710f1SAaron Conole
64959710f1SAaron ConoleThe second form is useful for a scripting environment,
65959710f1SAaron Conoleand is used by the DPDK Meson build system.
66959710f1SAaron ConoleThis mode is invoked by
67959710f1SAaron Conoleassigning a specific test suite name to the environment variable ``DPDK_TEST``
68959710f1SAaron Conolebefore invoking the `dpdk-test` command, such as::
69959710f1SAaron Conole
70959710f1SAaron Conole   $ DPDK_TEST=version_autotest ./build/app/test/dpdk-test --dpdk-options-here
71959710f1SAaron Conole   EAL: Detected 4 lcore(s)
72959710f1SAaron Conole   EAL: Detected 1 NUMA nodes
73959710f1SAaron Conole   EAL: Static memory layout is selected, amount of reserved memory can be...
74959710f1SAaron Conole   EAL: Multi-process socket /run/user/26934/dpdk/rte/mp_socket
75959710f1SAaron Conole   EAL: Selected IOVA mode 'VA'
76959710f1SAaron Conole   EAL: Probing VFIO support...
77959710f1SAaron Conole   EAL: PCI device 0000:00:1f.6 on NUMA socket -1
78959710f1SAaron Conole   EAL:   Invalid NUMA socket, default to 0
79959710f1SAaron Conole   EAL:   probe driver: 8086:15d7 net_e1000_em
80959710f1SAaron Conole   APP: HPET is not enabled, using TSC as default timer
81959710f1SAaron Conole   RTE>>version_autotest
82959710f1SAaron Conole   Version string: 'DPDK 20.02.0-rc0'
83959710f1SAaron Conole   Test OK
84959710f1SAaron Conole   RTE>>$
85959710f1SAaron Conole
86959710f1SAaron ConoleThe above shows running a specific test case.
87959710f1SAaron ConoleOn success, the return code will be '0',
88959710f1SAaron Conoleotherwise it will be set to some error value (such as '255', or a negative value).
89959710f1SAaron Conole
90959710f1SAaron ConoleThe third form is an alternative
91959710f1SAaron Conoleto providing the test suite name in an environment variable.
92959710f1SAaron ConoleThe unit test app can accept test suite names via command line arguments::
93959710f1SAaron Conole
94959710f1SAaron Conole   $ ./build/app/test/dpdk-test --dpdk-options-here version_autotest version_autotest
95959710f1SAaron Conole   EAL: Detected 8 lcore(s)
96959710f1SAaron Conole   EAL: Detected 1 NUMA nodes
97959710f1SAaron Conole   EAL: Static memory layout is selected, amount of reserved memory can be...
98959710f1SAaron Conole   EAL: Detected static linkage of DPDK
99959710f1SAaron Conole   EAL: Multi-process socket /run/user/26934/dpdk/rte/mp_socket
100959710f1SAaron Conole   EAL: Selected IOVA mode 'VA'
101959710f1SAaron Conole   APP: HPET is not enabled, using TSC as default timer
102959710f1SAaron Conole   RTE>>version_autotest
103959710f1SAaron Conole   Version string: 'DPDK 21.08.0-rc0'
104959710f1SAaron Conole   Test OK
105959710f1SAaron Conole   RTE>>version_autotest
106959710f1SAaron Conole   Version string: 'DPDK 21.08.0-rc0'
107959710f1SAaron Conole   Test OK
108959710f1SAaron Conole   RTE>>
109959710f1SAaron Conole
110959710f1SAaron ConoleThe primary benefit here is specifying multiple test names,
111959710f1SAaron Conolewhich is not possible with the ``DPDK_TEST`` environment variable.
112959710f1SAaron Conole
113959710f1SAaron ConoleAdditionally, it is possible to specify additional test parameters
114959710f1SAaron Conolevia the ``DPDK_TEST_PARAMS`` argument,
115959710f1SAaron Conolein case some tests need additional configuration.
116959710f1SAaron ConoleThis isn't currently used in the Meson test suites.
117959710f1SAaron Conole
118959710f1SAaron Conole
119959710f1SAaron ConoleRunning test cases via Meson
120959710f1SAaron Conole----------------------------
121959710f1SAaron Conole
122959710f1SAaron ConoleIn order to allow developers to quickly execute all the standard internal tests
123959710f1SAaron Conolewithout needing to remember or look up each test suite name,
124959710f1SAaron Conolethe build system includes a standard way of executing the Meson test suites.
125959710f1SAaron ConoleAfter building via ``ninja``, the ``meson test`` command
126959710f1SAaron Conolewith no arguments will execute the Meson test suites.
127959710f1SAaron Conole
128*96c0d4dfSBruce RichardsonThere are a number of pre-configured Meson test suites.
129959710f1SAaron ConoleThe first is the **fast** test suite, which is the largest group of test cases.
130959710f1SAaron ConoleThese are the bulk of the unit tests to validate functional blocks.
131959710f1SAaron ConoleThe second is the **perf** tests.
132959710f1SAaron ConoleThese test suites can take longer to run and do performance evaluations.
133959710f1SAaron ConoleThe third is the **driver** test suite,
134959710f1SAaron Conolewhich is mostly for special hardware related testing (such as `cryptodev`).
135*96c0d4dfSBruce RichardsonThe fourth, and currently the last, suite is the **debug** suite.
136959710f1SAaron ConoleThese tests mostly are used to dump system information.
137959710f1SAaron Conole
138959710f1SAaron ConoleThe Meson test suites can be selected by adding the ``--suite`` option
139959710f1SAaron Conoleto the ``meson test`` command.
140959710f1SAaron ConoleEx: ``meson test --suite fast-tests``::
141959710f1SAaron Conole
142959710f1SAaron Conole   $ meson test -C build --suite fast-tests
143959710f1SAaron Conole   ninja: Entering directory `/home/aconole/git/dpdk/build'
144959710f1SAaron Conole   [2543/2543] Linking target app/test/dpdk-test.
145959710f1SAaron Conole   1/60 DPDK:fast-tests / acl_autotest          OK       3.17 s
146959710f1SAaron Conole   2/60 DPDK:fast-tests / bitops_autotest       OK       0.22 s
147959710f1SAaron Conole   3/60 DPDK:fast-tests / byteorder_autotest    OK       0.22 s
148959710f1SAaron Conole   4/60 DPDK:fast-tests / cmdline_autotest      OK       0.28 s
149959710f1SAaron Conole   5/60 DPDK:fast-tests / common_autotest       OK       0.57 s
150959710f1SAaron Conole   6/60 DPDK:fast-tests / cpuflags_autotest     OK       0.27 s
151959710f1SAaron Conole   ...
152959710f1SAaron Conole
153959710f1SAaron ConoleThe ``meson test`` command can also execute individual Meson test cases
154959710f1SAaron Conolevia the command line by adding the test names as an argument::
155959710f1SAaron Conole
156959710f1SAaron Conole   $ meson test -C build version_autotest
157959710f1SAaron Conole   ninja: Entering directory `/home/aconole/git/dpdk/build'
158959710f1SAaron Conole   [2543/2543] Linking target app/test/dpdk-test.
159959710f1SAaron Conole   1/1 DPDK:fast-tests / version_autotest OK             0.17s
160959710f1SAaron Conole   ...
161959710f1SAaron Conole
162959710f1SAaron ConoleNote that these test cases must be known to Meson
163959710f1SAaron Conolefor the ``meson test`` command to run them.
164959710f1SAaron ConoleSimply adding a new test to the `dpdk-test` application isn't enough.
165959710f1SAaron ConoleSee the section `Adding a suite or test case to Meson`_ for more details.
166959710f1SAaron Conole
167959710f1SAaron Conole
168959710f1SAaron ConoleAdding tests to dpdk-test application
169959710f1SAaron Conole-------------------------------------
170959710f1SAaron Conole
171959710f1SAaron ConoleUnit tests should be added to the system
172959710f1SAaron Conolewhenever we introduce new functionality to DPDK,
173959710f1SAaron Conoleas well as whenever a bug is resolved.
174959710f1SAaron ConoleThis helps the DPDK project to catch regressions as they are introduced.
175959710f1SAaron Conole
176959710f1SAaron ConoleThe DPDK test application supports two layers of tests:
177959710f1SAaron Conole   #. *test cases* which are individual tests
178959710f1SAaron Conole   #. *test suites* which are groups of test cases
179959710f1SAaron Conole
180959710f1SAaron ConoleTo add a new test suite to the DPDK test application,
181959710f1SAaron Conolecreate a new test file for that suite
182959710f1SAaron Conole(ex: see *app/test/test_version.c* for the ``version_autotest`` test suite).
183959710f1SAaron ConoleThere are two important functions for interacting with the test harness:
184959710f1SAaron Conole
185*96c0d4dfSBruce Richardson   ``REGISTER_<MESON_SUITE>_TEST(command_name, function_to_execute)``
186959710f1SAaron Conole      Registers a test command with the name `command_name`
187*96c0d4dfSBruce Richardson      and which runs the function `function_to_execute` when `command_name` is invoked.
188*96c0d4dfSBruce Richardson      The test is automatically added to the Meson test suite `<MESON_SUITE>` by this macro.
189*96c0d4dfSBruce Richardson      Examples would be ``REGISTER_DRIVER_TEST``, or ``REGISTER_PERF_TEST``.
190*96c0d4dfSBruce Richardson      **NOTE:** The ``REGISTER_FAST_TEST`` macro is slightly different,
191*96c0d4dfSBruce Richardson      in that it takes two additional parameters,
192*96c0d4dfSBruce Richardson      specifying whether the test can be run using ``--no-huge``,
193*96c0d4dfSBruce Richardson      and whether the test can be run using Address Sanitization (ASAN)
194959710f1SAaron Conole
195959710f1SAaron Conole   ``unit_test_suite_runner(struct unit_test_suite *)``
196959710f1SAaron Conole      Returns a runner for a full test suite object,
197959710f1SAaron Conole      which contains a test suite name, setup, tear down,
198bcafd173SCiara Power      a pointer to a list of sub-testsuites,
199959710f1SAaron Conole      and vector of unit test cases.
200959710f1SAaron Conole
201959710f1SAaron ConoleEach test suite has a setup and tear down function
202959710f1SAaron Conolethat runs at the beginning and end of the test suite execution.
203959710f1SAaron ConoleEach unit test has a similar function for test case setup and tear down.
204959710f1SAaron Conole
205bcafd173SCiara PowerEach test suite may use a nested list of sub-testsuites,
206bcafd173SCiara Powerwhich are iterated by the ``unit_test_suite_runner``.
207bcafd173SCiara PowerThis support allows for better granularity when designing test suites.
208bcafd173SCiara PowerThe sub-testsuites list can also be used in parallel with the vector of test cases,
209bcafd173SCiara Powerin this case the test cases will be run,
210bcafd173SCiara Powerand then each sub-testsuite is executed.
211bcafd173SCiara PowerTo see an example of a test suite using sub-testsuites,
212bcafd173SCiara Powersee *app/test/test_cryptodev.c*.
213bcafd173SCiara Power
214959710f1SAaron ConoleTest cases are added to the ``.unit_test_cases`` element
215959710f1SAaron Conoleof the appropriate unit test suite structure.
216959710f1SAaron ConoleAn example of both a test suite and a case:
217959710f1SAaron Conole
218959710f1SAaron Conole.. code-block:: c
219959710f1SAaron Conole   :linenos:
220959710f1SAaron Conole
221959710f1SAaron Conole   #include <time.h>
222959710f1SAaron Conole
223959710f1SAaron Conole   #include <rte_common.h>
224959710f1SAaron Conole   #include <rte_cycles.h>
225959710f1SAaron Conole   #include <rte_hexdump.h>
226959710f1SAaron Conole   #include <rte_random.h>
227959710f1SAaron Conole
228959710f1SAaron Conole   #include "test.h"
229959710f1SAaron Conole
230959710f1SAaron Conole   static int testsuite_setup(void) { return TEST_SUCCESS; }
231959710f1SAaron Conole   static void testsuite_teardown(void) { }
232959710f1SAaron Conole
233959710f1SAaron Conole   static int ut_setup(void) { return TEST_SUCCESS; }
234959710f1SAaron Conole   static void ut_teardown(void) { }
235959710f1SAaron Conole
236959710f1SAaron Conole   static int test_case_first(void) { return TEST_SUCCESS; }
237959710f1SAaron Conole
238959710f1SAaron Conole   static struct unit_test_suite example_testsuite = {
239959710f1SAaron Conole          .suite_name = "EXAMPLE TEST SUITE",
240959710f1SAaron Conole          .setup = testsuite_setup,
241959710f1SAaron Conole          .teardown = testsuite_teardown,
242959710f1SAaron Conole          .unit_test_cases = {
243959710f1SAaron Conole               TEST_CASE_ST(ut_setup, ut_teardown, test_case_first),
244959710f1SAaron Conole
245959710f1SAaron Conole               TEST_CASES_END(), /**< NULL terminate unit test array */
246959710f1SAaron Conole          },
247959710f1SAaron Conole   };
248959710f1SAaron Conole
249959710f1SAaron Conole   static int example_tests()
250959710f1SAaron Conole   {
251959710f1SAaron Conole       return unit_test_suite_runner(&example_testsuite);
252959710f1SAaron Conole   }
253959710f1SAaron Conole
254*96c0d4dfSBruce Richardson   REGISTER_PERF_TEST(example_autotest, example_tests);
255959710f1SAaron Conole
256959710f1SAaron ConoleThe above code block is a small example
257959710f1SAaron Conolethat can be used to create a complete test suite with test case.
258959710f1SAaron Conole
259bcafd173SCiara PowerSub-testsuites can be added to the ``.unit_test_suites`` element
260bcafd173SCiara Powerof the unit test suite structure, for example:
261bcafd173SCiara Power
262bcafd173SCiara Power.. code-block:: c
263bcafd173SCiara Power   :linenos:
264bcafd173SCiara Power
265bcafd173SCiara Power   static int testsuite_setup(void) { return TEST_SUCCESS; }
266bcafd173SCiara Power   static void testsuite_teardown(void) { }
267bcafd173SCiara Power
268bcafd173SCiara Power   static int ut_setup(void) { return TEST_SUCCESS; }
269bcafd173SCiara Power   static void ut_teardown(void) { }
270bcafd173SCiara Power
271bcafd173SCiara Power   static int test_case_first(void) { return TEST_SUCCESS; }
272bcafd173SCiara Power
273bcafd173SCiara Power   static struct unit_test_suite example_parent_testsuite = {
274bcafd173SCiara Power          .suite_name = "EXAMPLE PARENT TEST SUITE",
275bcafd173SCiara Power          .setup = testsuite_setup,
276bcafd173SCiara Power          .teardown = testsuite_teardown,
277bcafd173SCiara Power          .unit_test_cases = {TEST_CASES_END()}
278bcafd173SCiara Power   };
279bcafd173SCiara Power
280bcafd173SCiara Power   static int sub_testsuite_setup(void) { return TEST_SUCCESS; }
281bcafd173SCiara Power   static void sub_testsuite_teardown(void) { }
282bcafd173SCiara Power
283bcafd173SCiara Power   static struct unit_test_suite example_sub_testsuite = {
284bcafd173SCiara Power          .suite_name = "EXAMPLE SUB TEST SUITE",
285bcafd173SCiara Power          .setup = sub_testsuite_setup,
286bcafd173SCiara Power          .teardown = sub_testsuite_teardown,
287bcafd173SCiara Power          .unit_test_cases = {
288bcafd173SCiara Power               TEST_CASE_ST(ut_setup, ut_teardown, test_case_first),
289bcafd173SCiara Power
290bcafd173SCiara Power               TEST_CASES_END(), /**< NULL terminate unit test array */
291bcafd173SCiara Power          },
292bcafd173SCiara Power   };
293bcafd173SCiara Power
294bcafd173SCiara Power   static struct unit_test_suite end_testsuite = {
295bcafd173SCiara Power          .suite_name = NULL,
296bcafd173SCiara Power          .setup = NULL,
297bcafd173SCiara Power          .teardown = NULL,
298bcafd173SCiara Power          .unit_test_suites = NULL
299bcafd173SCiara Power   };
300bcafd173SCiara Power
301bcafd173SCiara Power   static int example_tests()
302bcafd173SCiara Power   {
303bcafd173SCiara Power       uint8_t ret, i = 0;
304bcafd173SCiara Power       struct unit_test_suite *sub_suites[] = {
305bcafd173SCiara Power              &example_sub_testsuite,
306bcafd173SCiara Power              &end_testsuite /**< NULL test suite to indicate end of list */
307bcafd173SCiara Power        };
308bcafd173SCiara Power
309bcafd173SCiara Power       example_parent_testsuite.unit_test_suites =
310bcafd173SCiara Power               malloc(sizeof(struct unit_test_suite *) * RTE_DIM(sub_suites));
311bcafd173SCiara Power
312bcafd173SCiara Power       for (i = 0; i < RTE_DIM(sub_suites); i++)
313bcafd173SCiara Power           example_parent_testsuite.unit_test_suites[i] = sub_suites[i];
314bcafd173SCiara Power
315bcafd173SCiara Power       ret = unit_test_suite_runner(&example_parent_testsuite);
316bcafd173SCiara Power       free(example_parent_testsuite.unit_test_suites);
317bcafd173SCiara Power
318bcafd173SCiara Power       return ret;
319bcafd173SCiara Power   }
320bcafd173SCiara Power
321*96c0d4dfSBruce Richardson   REGISTER_FAST_TEST(example_autotest, true /*no-huge*/, false /*ASan*/, example_tests);
322bcafd173SCiara Power
323959710f1SAaron Conole
324959710f1SAaron ConoleDesigning a test
325959710f1SAaron Conole----------------
326959710f1SAaron Conole
327959710f1SAaron ConoleTest cases have multiple ways of indicating an error has occurred,
328959710f1SAaron Conolein order to reflect failure state back to the runner.
329959710f1SAaron ConoleUsing the various methods of indicating errors can assist
330959710f1SAaron Conolein not only validating the requisite functionality is working,
331959710f1SAaron Conolebut also to help debug when a change in environment or code
332959710f1SAaron Conolehas caused things to go wrong.
333959710f1SAaron Conole
334959710f1SAaron ConoleThe first way to indicate a generic error is
335959710f1SAaron Conoleby returning a test result failure, using the ``TEST_FAILED`` error code.
336959710f1SAaron ConoleThis is the most basic way of indicating that an error
337959710f1SAaron Conolehas occurred in a test routine.
338959710f1SAaron ConoleIt isn't very informative to the user, so it should really be used in cases
339959710f1SAaron Conolewhere the test has catastrophically failed.
340959710f1SAaron Conole
341959710f1SAaron ConoleThe preferred method of indicating an error is
342959710f1SAaron Conolevia the ``RTE_TEST_ASSERT`` family of macros,
343959710f1SAaron Conolewhich will immediately return ``TEST_FAILED`` error condition,
344959710f1SAaron Conolebut will also log details about the failure.
345959710f1SAaron ConoleThe basic form is:
346959710f1SAaron Conole
347959710f1SAaron Conole.. code-block:: c
348959710f1SAaron Conole
349959710f1SAaron Conole   RTE_TEST_ASSERT(cond, msg, ...)
350959710f1SAaron Conole
351959710f1SAaron ConoleIn the above macro, *cond* is the condition to evaluate to **true**.
352959710f1SAaron ConoleAny generic condition can go here.
353959710f1SAaron ConoleThe *msg* parameter will be a message to display if *cond* evaluates to **false**.
354959710f1SAaron ConoleSome specialized macros already exist.
355959710f1SAaron ConoleSee `lib/librte_eal/include/rte_test.h` for a list of defined test assertions.
356959710f1SAaron Conole
357959710f1SAaron ConoleSometimes it is important to indicate that a test needs to be skipped,
358959710f1SAaron Conoleeither because the environment isn't able to support running the test,
359959710f1SAaron Conoleor because some requisite functionality isn't available.
360959710f1SAaron ConoleThe test suite supports returning a result of ``TEST_SKIPPED``
361959710f1SAaron Conoleduring test case setup, or during test case execution
362959710f1SAaron Conoleto indicate that the preconditions of the test aren't available.
363959710f1SAaron ConoleExample::
364959710f1SAaron Conole
365959710f1SAaron Conole   $ meson test -C build --suite fast-tests
366959710f1SAaron Conole   ninja: Entering directory `/home/aconole/git/dpdk/build
367959710f1SAaron Conole   [2543/2543] Linking target app/test/dpdk-test.
368959710f1SAaron Conole   1/60 DPDK:fast-tests / acl_autotest          OK       3.17 s
369959710f1SAaron Conole   2/60 DPDK:fast-tests / bitops_autotest       OK       0.22 s
370959710f1SAaron Conole   3/60 DPDK:fast-tests / byteorder_autotest    OK       0.22 s
371959710f1SAaron Conole   ...
372959710f1SAaron Conole   46/60 DPDK:fast-tests / ipsec_autotest       SKIP     0.22 s
373959710f1SAaron Conole   ...
374959710f1SAaron Conole
375959710f1SAaron Conole
376959710f1SAaron ConoleChecking code coverage
377959710f1SAaron Conole----------------------
378959710f1SAaron Conole
379959710f1SAaron ConoleThe Meson build system supports generating a code coverage report
380959710f1SAaron Conolevia the ``-Db_coverage=true`` option,
381959710f1SAaron Conolein conjunction with a package like **lcov**,
382959710f1SAaron Conoleto generate an HTML code coverage report.
383959710f1SAaron ConoleExample::
384959710f1SAaron Conole
385959710f1SAaron Conole   $ meson setup build -Db_coverage=true
386959710f1SAaron Conole   $ meson test -C build --suite fast-tests
387959710f1SAaron Conole   $ ninja coverage-html -C build
388959710f1SAaron Conole
389959710f1SAaron ConoleThe above will generate an HTML report
390959710f1SAaron Conolein the `build/meson-logs/coveragereport/` directory
391959710f1SAaron Conolethat can be explored for detailed code covered information.
392959710f1SAaron ConoleThis can be used to assist in test development.
393959710f1SAaron Conole
394959710f1SAaron Conole
395959710f1SAaron ConoleAdding a suite or test case to Meson
396959710f1SAaron Conole------------------------------------
397959710f1SAaron Conole
398*96c0d4dfSBruce RichardsonAdding to one of the Meson test suites involves using the appropriate macro
399*96c0d4dfSBruce Richardsonto register the test in dpdk-test, as described above.
400*96c0d4dfSBruce RichardsonFor example,
401*96c0d4dfSBruce Richardsondefining the test command using ``REGISTER_PERF_TEST`` automatically
402*96c0d4dfSBruce Richardsonadds the test to the perf-test meson suite.
403959710f1SAaron ConoleOnce added, the new test will be run
404959710f1SAaron Conoleas part of the appropriate class (fast, perf, driver, etc.).
405959710f1SAaron Conole
406959710f1SAaron ConoleA user or developer can confirm that a test is known to Meson
407959710f1SAaron Conoleby using the ``--list`` option::
408959710f1SAaron Conole
409959710f1SAaron Conole   $ meson test -C build --list
410959710f1SAaron Conole   DPDK:fast-tests / acl_autotest
411959710f1SAaron Conole   DPDK:fast-tests / bitops_autotest
412959710f1SAaron Conole   ...
413959710f1SAaron Conole
414959710f1SAaron ConoleSome of these test suites are run during continuous integration tests,
415959710f1SAaron Conolemaking regression checking automatic for new patches submitted to the project.
416959710f1SAaron Conole
417*96c0d4dfSBruce Richardson.. note::
418bcafd173SCiara Power
419*96c0d4dfSBruce Richardson   The use of the old ``REGISTER_TEST_COMMAND`` macro
420*96c0d4dfSBruce Richardson   to add a command without adding it to a meson test suite is deprecated.
421*96c0d4dfSBruce Richardson   All new tests must be added to a test suite
422*96c0d4dfSBruce Richardson   using the appropriate ``REGISTER_<SUITE>_TEST`` macro.
423bcafd173SCiara Power
424bcafd173SCiara PowerRunning cryptodev tests
425bcafd173SCiara Power-----------------------
426bcafd173SCiara Power
427bcafd173SCiara PowerWhen running cryptodev tests, the user must create any required virtual device
428bcafd173SCiara Powervia EAL arguments, as this is not automatically done by the test::
429bcafd173SCiara Power
430bcafd173SCiara Power   $ ./build/app/test/dpdk-test --vdev crypto_aesni_mb
431bcafd173SCiara Power   $ meson test -C build --suite driver-tests \
432bcafd173SCiara Power                --test-args="--vdev crypto_aesni_mb"
433bcafd173SCiara Power
434bcafd173SCiara Power.. note::
435bcafd173SCiara Power
436bcafd173SCiara Power   The ``cryptodev_scheduler_autotest`` is the only exception to this.
437bcafd173SCiara Power   This vdev will be created automatically by the test app,
438bcafd173SCiara Power   as it requires a more complex setup than other vdevs.
439