@@ -262,12 +262,72 @@ It patches their CMake to correctly import its dependencies.
262
262
generator. Pass `--help` to see the rest of the command line options.
263
263
264
264
265
+ ## Coverage report
266
+
267
+ The coverage report is intended for developers using compilers GCC
268
+ or Clang (including Apple Clang). It is generated by the build target `coverage`,
269
+ which is only enabled when the `coverage` option is set, e.g. with
270
+ `--options coverage=True` in `conan` or `-Dcoverage=ON` variable in `cmake`
271
+
272
+ Prerequisites for the coverage report:
273
+
274
+ - [gcovr tool][gcovr] (can be installed e.g. with [pip][python-pip])
275
+ - `gcov` for GCC (installed with the compiler by default) or
276
+ - `llvm-cov` for Clang (installed with the compiler by default)
277
+ - `Debug` build type
278
+
279
+ A coverage report is created when the following steps are completed, in order:
280
+
281
+ 1. `rippled` binary built with instrumentation data, enabled by the `coverage`
282
+ option mentioned above
283
+ 2. completed run of unit tests, which populates coverage capture data
284
+ 3. completed run of the `gcovr` tool (which internally invokes either `gcov` or `llvm-cov`)
285
+ to assemble both instrumentation data and the coverage capture data into a coverage report
286
+
287
+ The above steps are automated into a single target `coverage`. The instrumented
288
+ `rippled` binary can also be used for regular development or testing work, at
289
+ the cost of extra disk space utilization and a small performance hit
290
+ (to store coverage capture). In case of a spurious failure of unit tests, it is
291
+ possible to re-run the `coverage` target without rebuilding the `rippled` binary
292
+ (since it is simply a dependency of the coverage report target). It is also possible
293
+ to select only specific tests for the purpose of the coverage report, by setting
294
+ the `coverage_test` variable in `cmake`
295
+
296
+ The default coverage report format is `html-details`, but the user
297
+ can override it to any of the formats listed in `Builds/CMake/CodeCoverage.cmake`
298
+ by setting the `coverage_format` variable in `cmake`. It is also possible
299
+ to generate more than one format at a time by setting the `coverage_extra_args`
300
+ variable in `cmake`. The specific command line used to run the `gcovr` tool will be
301
+ displayed if the `CODE_COVERAGE_VERBOSE` variable is set.
302
+
303
+ By default, the code coverage tool runs parallel unit tests with `--unittest-jobs`
304
+ set to the number of available CPU cores. This may cause spurious test
305
+ errors on Apple. Developers can override the number of unit test jobs with
306
+ the `coverage_test_parallelism` variable in `cmake`.
307
+
308
+ Example use with some cmake variables set:
309
+
310
+ ```
311
+ cd .build
312
+ conan install .. --output-folder . --build missing --settings build_type=Debug
313
+ cmake -DCMAKE_BUILD_TYPE=Debug -Dcoverage=ON -Dcoverage_test_parallelism=2 -Dcoverage_format=html-details -Dcoverage_extra_args="--json coverage.json" -DCMAKE_TOOLCHAIN_FILE: FILEPATH =build/generators/conan_toolchain.cmake ..
314
+ cmake --build . --target coverage
315
+ ```
316
+
317
+ After the `coverage` target is completed, the generated coverage report will be
318
+ stored inside the build directory, as either of:
319
+
320
+ - file named `coverage.`_extension_ , with a suitable extension for the report format, or
321
+ - directory named `coverage`, with the `index.html` and other files inside, for the `html-details` or `html-nested` report formats.
322
+
323
+
265
324
## Options
266
325
267
326
| Option | Default Value | Description |
268
327
| --- | ---| ---|
269
328
| `assert` | OFF | Enable assertions.
270
329
| `reporting` | OFF | Build the reporting mode feature. |
330
+ | `coverage` | OFF | Prepare the coverage report. |
271
331
| `tests` | ON | Build tests. |
272
332
| `unity` | ON | Configure a unity build. |
273
333
| `san` | N/A | Enable a sanitizer with Clang. Choices are `thread` and `address`. |
@@ -362,6 +422,8 @@ If you want to experiment with a new package, follow these steps:
362
422
[5]: https://en.wikipedia.org/wiki/Unity_build
363
423
[6]: https://github.com/boostorg/beast/issues/2648
364
424
[7]: https://github.com/boostorg/beast/issues/2661
425
+ [gcovr]: https://gcovr.com/en/stable/getting-started.html
426
+ [python-pip]: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/
365
427
[build_type]: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
366
428
[runtime]: https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
367
429
[toolchain]: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
0 commit comments