@@ -11,74 +11,150 @@ Running OVSP4RT Unit Tests
11
11
Building the Unit Tests
12
12
=======================
13
13
14
+ This guide explains how to build and run the ovsp4rt unit tests, and
15
+ how generate a code coverage report for them.
16
+
17
+ .. note ::
18
+
19
+ To keep things simple, the examples in this guide assume that you are
20
+ using presets to configure cmake. You may substitute any of the other
21
+ methods, if you wish.
22
+
14
23
Full build
15
24
----------
16
25
17
- The ovsp4rt unit tests are automatically built along with the rest of P4
18
- Control Plane. If you're doing a full build, no other steps are necessary.
26
+ The ovsp4rt unit tests are included when you do a full build.
19
27
20
- Directed build
28
+ Targeted build
21
29
--------------
22
30
23
- If you're working on ovsp4rt or its tests, you probably don't want to
24
- do a full build every time you make a change. In this case, you can build
25
- just ovsp4rt and its dependencies.
26
-
27
- Configuring cmake
28
- ~~~~~~~~~~~~~~~~~
29
-
30
- The first step is to configure the build. If you've already done this step,
31
- there's generally no need to repeat it.
31
+ If you're actively working on ovsp4rt or its tests, you may not want
32
+ to do full builds all the time. This section shows how to build just
33
+ the ovsp4rt tests and their dependencies.
32
34
33
- There are a number of ways to configure cmake. We're using a combination
34
- of environment variables (SDE_INSTALL, DEPEND_INSTALL) and command-line
35
- parameters.
35
+ The first step is to configure the build.
36
36
37
37
.. code-block :: bash
38
38
39
- cmake -B build -DTDI_TARGET=dpdk -DOVS_INSTALL_DIR=ovs/install
39
+ cmake --preset dpdk
40
40
41
- cmake can also be configured using a preload file, a preset, or a helper
42
- script such as ``make-all.sh ``.
43
-
44
- Building the tests
45
- ~~~~~~~~~~~~~~~~~~
46
-
47
- The second step is to build the ovsp4rt unit tests.
41
+ Then build the unit tests.
48
42
49
43
.. code-block :: bash
50
44
51
45
cmake --build build -j5 --target ovsp4rt-unit-tests
52
46
53
- Note the use of the ``ovsp4rt-unit-tests `` build target.
54
-
55
- CMake will build the ovsp4rt unit tests, with their dependencies.
47
+ The ``ovsp4rt-unit-tests `` target builds the ovsp4rt unit tests plus
48
+ their dependencies.
56
49
57
50
Running the Unit Tests
58
51
======================
59
52
60
- Tests are executed via the ``ctest `` command, which must be run from the
61
- build directory. We're going to do this in a nested subshell.
53
+ Tests are executed via the ``ctest `` command. This must be done in the
54
+ build directory. One way to do this is with a nested subshell.
62
55
63
56
.. code-block :: bash
64
57
65
58
(cd build; ctest -L ovsp4rt --output-on-failure)
66
59
67
- The options we're using here are:
60
+ The options used here are:
68
61
69
62
``-L ovsp4rt ``
70
- By default, ctest runs all the tests defined within the project,
71
- which in this case would include the krnlmon tests. We use the
72
- ``-L `` option to specify a *test label * (``ovsp4rt ``), instructing
73
- ctest to run only those tests that have that label.
63
+ By default, ctest runs all the tests in the project, including
64
+ the krnlmon tests. The ``-L `` option specifies a *test label *
65
+ that limits the selection to the ovsp4rt tests.
74
66
75
67
``--output-on-failure ``
76
- Normally, ctest writes a summary of the tests run, with an indication
77
- of whether each test passed or failed. If a test fails, you will have
78
- to locate the logfile to obtain any details. This option tells ctest
79
- to dump the log of the failing test to the console.
68
+ Normally, ctest displays a summary of the tests that were run, with an
69
+ indication of which passed and which failed. If a test fails, you will
70
+ need to check the logfile to determine what the failure was.
71
+
72
+ This option instructs ctest to write the output of failing tests
73
+ to the console.
74
+
75
+ Unit test logs are written to the **build/Testing/Temporary ** folder.
76
+ The most recent log is in **LastTest.log **.
80
77
81
78
Measuring Test Coverage
82
79
=======================
83
80
84
- TBD
81
+ Build with coverage enabled
82
+ ---------------------------
83
+
84
+ To measure unit test code coverage, you must enable the TEST_COVERAGE
85
+ option when you configure the build.
86
+
87
+ .. code-block :: bash
88
+
89
+ cmake --preset dpdk -DTEST_COVERAGE=ON
90
+ cmake --build build -j5 --target ovsp4rt-unit-tests
91
+
92
+ Measure coverage and generate report
93
+ ------------------------------------
94
+
95
+ The ``scripts `` directory contains a set of bash scripts to run the tests,
96
+ analyze the coverage measurements, and generate an HTML report for each
97
+ (target, test label) combination:
98
+
99
+ - scripts/es2k/report-ovsp4rt-coverage.sh
100
+ - scripts/es2k/report-krnlmon-coverage.sh
101
+ - scripts/dpdk/report-ovsp4rt-coverage.sh
102
+ - scripts/dpdk/report-krnlmon-coverage.sh
103
+
104
+ To generate the report:
105
+
106
+ .. code-block :: bash
107
+
108
+ ./scripts/dpdk/report-ovsp4rt-coverage.sh
109
+
110
+ Sample output:
111
+
112
+ .. code-block :: text
113
+
114
+ Site: baggins
115
+ Build name: Linux-c++
116
+ Create new tag: 20241104-1018 - Experimental
117
+ Test project /home/bilbo/work/latest/build
118
+ Start 6: encode_host_port_value_test
119
+ 1/6 Test #6: encode_host_port_value_test ...... Passed 0.02 sec
120
+ Start 7: dpdk_fdb_rx_vlan_test
121
+ 2/6 Test #7: dpdk_fdb_rx_vlan_test ............ Passed 0.03 sec
122
+ Start 8: dpdk_fdb_tx_vlan_test
123
+ 3/6 Test #8: dpdk_fdb_tx_vlan_test ............ Passed 0.03 sec
124
+ Start 9: dpdk_fdb_tx_vxlan_test
125
+ 4/6 Test #9: dpdk_fdb_tx_vxlan_test ........... Passed 0.03 sec
126
+ Start 10: dpdk_tunnel_term_test
127
+ 5/6 Test #10: dpdk_tunnel_term_test ............ Passed 0.03 sec
128
+ Start 11: dpdk_vxlan_encap_test
129
+ 6/6 Test #11: dpdk_vxlan_encap_test ............ Passed 0.03 sec
130
+
131
+ 100% tests passed, 0 tests failed out of 6
132
+ .
133
+ .
134
+ Overall coverage rate:
135
+ lines......: 61.1% (802 of 1312 lines)
136
+ functions..: 62.6% (97 of 155 functions)
137
+ Coverage report is in build/Coverage/ovsp4rt/dpdk.
138
+
139
+ View the coverage report
140
+ ------------------------
141
+
142
+ Use a browser to open **build/Coverage/ovsp4rt/dpdk/index.html **.
143
+
144
+ |image1 |
145
+
146
+ To see the summary report for the **ovs-p4rt/sidecar ** folder, click on
147
+ its link.
148
+
149
+ |image2 |
150
+
151
+ To see the detailed report for **ovsp4rt.cc **, click on its link.
152
+
153
+ |image3 |
154
+
155
+ Scroll down the file page to see which parts of the file are covered by
156
+ the unit test (in blue), and which parts are not covered (in orange).
157
+
158
+ .. |image1 | image :: images/ovsp4rt-coverage-report.png
159
+ .. |image2 | image :: images/ovsp4rt-sidecar-page.png
160
+ .. |image3 | image :: images/ovsp4rt-file-page.png
0 commit comments