Skip to content

Commit 305a2fa

Browse files
aphecetchesawenzel
authored andcommitted
[O2-837] Add some usage info for ctest (#2712)
* Add some usage info for ctest
1 parent d70dd6c commit 305a2fa

File tree

1 file changed

+142
-13
lines changed

1 file changed

+142
-13
lines changed

doc/CMakeInstructions.md

Lines changed: 142 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
\\page refdocCMakeInstructions CMake Instructions
22

3-
# CMake
3+
<!-- vim-markdown-toc GFM -->
4+
5+
- [CMake and CTest tips for AliceO2](#cmake-and-ctest-tips-for-aliceo2)
6+
- [CMake](#cmake)
7+
- [Instructions for contributors (aka developers' documentation)](#instructions-for-contributors-aka-developers-documentation)
8+
- [Typical CMakeLists.txt](#typical-cmakeliststxt)
9+
- [Examples](#examples)
10+
- [Ex1 Adding a basic library](#ex1-adding-a-basic-library)
11+
- [Ex2 Adding a basic library with a Root dictionary](#ex2-adding-a-basic-library-with-a-root-dictionary)
12+
- [Ex3 Adding an executable](#ex3-adding-an-executable)
13+
- [Ex4 Adding a couple of tests](#ex4-adding-a-couple-of-tests)
14+
- [Ex5 Adding a man page](#ex5-adding-a-man-page)
15+
- [CTest](#ctest)
16+
- [Selecting/excluding by test name (-R/-E)](#selectingexcluding-by-test-name--r-e)
17+
- [Selecting/excluding by label (-L/-LE)](#selectingexcluding-by-label--l-le)
18+
- [Speeding up ctest execution](#speeding-up-ctest-execution)
19+
20+
<!-- vim-markdown-toc -->
21+
22+
# CMake and CTest tips for AliceO2
23+
24+
## CMake
425

526
> Note that this document describe the [new CMake system](CMakeMigration.md) : the one based on buckets has been discontinued.
627
7-
## Instructions for contributors (aka developers' documentation)
28+
### Instructions for contributors (aka developers' documentation)
829

930
A sub-module `CMakeLists.txt` defines one or more _targets_.
1031
A target generally corresponds to an actual build artifact like a (static or shared) library or an executable. Targets are the cornerstone of any modern cmake build system.
1132

12-
## Typical CMakeLists.txt
33+
### Typical CMakeLists.txt
1334

1435
A typical module's `CMakeLists.txt` contains
1536

16-
- a call to [o2_add_library](../cmake/O2AddLibrary.cmake) to define a library (and its dependencies)
17-
- call(s) to [o2_add_executable](../cmake/O2AddExecutable.cmake) to define one or more executables (and their dependencies)
18-
- call(s) to [o2_add_test](../cmake/O2AddTest.cmake) to define one or more tests (and their dependencies)
37+
- a call to [o2_add_library](../cmake/O2AddLibrary.cmake) to define a library (and its dependencies)
38+
- call(s) to [o2_add_executable](../cmake/O2AddExecutable.cmake) to define one or more executables (and their dependencies)
39+
- call(s) to [o2_add_test](../cmake/O2AddTest.cmake) to define one or more tests (and their dependencies)
1940

2041
Optionally it might contain a call to [o2_target_root_dictionary](../cmake/O2TargetRootDictionary.cmake) if the module's library requires a Root dictionary.
2142

@@ -25,11 +46,11 @@ Note that despite the parameter name, the `PUBLIC_LINK_LIBRARIES` should refer t
2546

2647
Note also CMakeLists.txt should be considered as code and so the same care you put into writing code (e.g. do not repeat yourself, comments, etc...) should be applied to CMakeLists.txt. Also, like the rest of our code, we can take of the formatting using the [cmake-format](https://github.com/cheshirekow/cmake_format) tool (that tool is certainly not as robust as `clang-format` but it can get most of the job done easily).
2748

28-
## Examples
49+
### Examples
2950

3051
The example outputs below are from a Mac, so the shared library extension is `dylib`. On Linux it would be `so`.
3152

32-
### [Ex1](../Examples/Ex1) Adding a basic library
53+
#### [Ex1](../Examples/Ex1) Adding a basic library
3354

3455
Using the following source dir :
3556

@@ -80,7 +101,7 @@ And upon install `cmake --build . -- install` (the lonely `--` is not a typo) th
80101
├── lib
81102
│   ├── libO2Ex1.dylib
82103

83-
### [Ex2](../Examples/Ex2) Adding a basic library with a Root dictionary
104+
#### [Ex2](../Examples/Ex2) Adding a basic library with a Root dictionary
84105

85106
Using a slightly modified version of the previous example (the [A.h](../Examples/Ex2/include/Ex2/A.h) now uses ClassDef for instance), we'll now add a Root dictionary :
86107

@@ -138,7 +159,7 @@ The include installation will be similar to Ex1 : the `LinkDef.h` file is _not_
138159
│   ├── libO2Ex2.dylib
139160
│   ├── libO2Ex2.rootmap
140161

141-
### [Ex3](../Examples/Ex3) Adding an executable
162+
#### [Ex3](../Examples/Ex3) Adding an executable
142163

143164
Adding an executable to previous example :
144165

@@ -201,7 +222,7 @@ Third, the created executable can be launched "as is" from the build tree, witho
201222

202223
That is because the [RPATH](https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling) was correctly set by CMake for the build tree. It should be set correctly also when installing.
203224

204-
### [Ex4](../Examples/Ex4) Adding a couple of tests
225+
#### [Ex4](../Examples/Ex4) Adding a couple of tests
205226

206227
Let's add two basic test2 to our previous example.
207228

@@ -232,7 +253,7 @@ Those two test executables will be under `stage/bin` with a name starting with `
232253
├── libO2Ex3.dylib
233254
└── libO2Ex4.dylib
234255

235-
By default tests are not be installed, unless the `INSTALL` option is given to `o2_add_test`. So in the installation zone only the first test will be available, under the `tests` subdirectory. So the full installation of our 4 examples would give :
256+
By default tests are _not_ installed, unless the `INSTALL` option is given to `o2_add_test`. So in the installation zone only the first test will be available, under the `tests` subdirectory. So the full installation of our 4 examples would give :
236257

237258
../install-Debug/
238259
├── bin
@@ -311,7 +332,7 @@ Tests can also be _excluded_ based on label (`-LE`) or name (`-RE`).
311332
dummy = 0.07 sec*proc (1 test)
312333
fast = 0.07 sec*proc (1 test)
313334

314-
### [Ex5](../Examples/Ex5) Adding a man page
335+
#### [Ex5](../Examples/Ex5) Adding a man page
315336

316337
If a module provides one or more executables, it might be of interest for the users of those executables to have access to a man page for them. Ex5 illustates that use case.
317338

@@ -328,3 +349,111 @@ The [man page](ManPages.md) is created using :
328349
o2_target_man_page([targetName] NAME ex5 SECTION 7)
329350

330351
where `NAME xx` refers to a file `doc/xx.[SECTION].in`, and the actual `targetName` can be found from the base target name (ex5 in that case) using the [o2_name_target](../cmake/O2NameTarget.cmake) function.
352+
353+
## CTest
354+
355+
In the build directory of O2, if you launch the `ctest` command, all the O2 tests will be ran, which is not always what you want/need, in particular during development.
356+
357+
As shown above in [Ex4](#ex4-adding-a-couple-of-tests), there are fortunately various ways to narrow the set of tests which are ran by `ctest`.
358+
359+
Note that in all the commands below, the `-N` option is used to show the list of test that would be selected, without running them. Remove that option to actually run the tests.
360+
361+
### Selecting/excluding by test name (-R/-E)
362+
363+
Probably the simplest is to select the test name, using the `-R` (regexp) option :
364+
365+
```shell
366+
> ctest -N -R test/Contour
367+
Test #269: Detectors/MUON/MCH/Contour/test/Contour.cxx
368+
Test #270: Detectors/MUON/MCH/Contour/test/ContourCreator.cxx
369+
370+
> ctest -N -R "test/Contour\.(.)"
371+
Test #269: Detectors/MUON/MCH/Contour/test/Contour.cxx
372+
373+
```
374+
375+
Instead of selecting the tests to run, you can invert the logic and exclude tests matching a regular expression using `-E` instead of `-R`.
376+
377+
### Selecting/excluding by label (-L/-LE)
378+
379+
Assuming the tests have been labelled, you can use `-L` (to include) or `-LE` (to exclude) tests based on their labels. The full list of defined labels can be shown using the `--print-labels` option.
380+
381+
```shell
382+
> ctest -N -L mch
383+
Test #268: Detectors/MUON/MCH/Contour/test/BBox.cxx
384+
Test #269: Detectors/MUON/MCH/Contour/test/Contour.cxx
385+
Test #270: Detectors/MUON/MCH/Contour/test/ContourCreator.cxx
386+
Test #271: Detectors/MUON/MCH/Contour/test/Edge.cxx
387+
Test #272: Detectors/MUON/MCH/Contour/test/Interval.cxx
388+
Test #273: Detectors/MUON/MCH/Contour/test/Polygon.cxx
389+
Test #274: Detectors/MUON/MCH/Contour/test/SegmentTree.cxx
390+
Test #275: Detectors/MUON/MCH/Contour/test/Vertex.cxx
391+
Test #276: Detectors/MUON/MCH/Simulation/macros/drawMCHGeometry.C
392+
Test #277: Detectors/MUON/MCH/Simulation/macros/drawMCHGeometry.C_compiled
393+
```
394+
395+
### Speeding up ctest execution
396+
397+
Finally, note that `ctest` can run tests in parallel (unless those that are explicitely marked as not safe to run in parallel) using the `-j n` option, where `n` is the max number of tests to run in parallel.
398+
399+
Serial execution :
400+
401+
```shell
402+
> ctest -L mch -LE long -E Raw
403+
Start 265: Detectors/MUON/MCH/Contour/test/BBox.cxx
404+
1/8 Test #265: Detectors/MUON/MCH/Contour/test/BBox.cxx ............. Passed 0.04 sec
405+
Start 266: Detectors/MUON/MCH/Contour/test/Contour.cxx
406+
2/8 Test #266: Detectors/MUON/MCH/Contour/test/Contour.cxx .......... Passed 0.05 sec
407+
Start 267: Detectors/MUON/MCH/Contour/test/ContourCreator.cxx
408+
3/8 Test #267: Detectors/MUON/MCH/Contour/test/ContourCreator.cxx ... Passed 0.05 sec
409+
Start 268: Detectors/MUON/MCH/Contour/test/Edge.cxx
410+
4/8 Test #268: Detectors/MUON/MCH/Contour/test/Edge.cxx ............. Passed 0.05 sec
411+
Start 269: Detectors/MUON/MCH/Contour/test/Interval.cxx
412+
5/8 Test #269: Detectors/MUON/MCH/Contour/test/Interval.cxx ......... Passed 0.05 sec
413+
Start 270: Detectors/MUON/MCH/Contour/test/Polygon.cxx
414+
6/8 Test #270: Detectors/MUON/MCH/Contour/test/Polygon.cxx .......... Passed 0.05 sec
415+
Start 271: Detectors/MUON/MCH/Contour/test/SegmentTree.cxx
416+
7/8 Test #271: Detectors/MUON/MCH/Contour/test/SegmentTree.cxx ...... Passed 0.05 sec
417+
Start 272: Detectors/MUON/MCH/Contour/test/Vertex.cxx
418+
8/8 Test #272: Detectors/MUON/MCH/Contour/test/Vertex.cxx ........... Passed 0.05 sec
419+
420+
100% tests passed, 0 tests failed out of 8
421+
422+
Label Time Summary:
423+
mch = 0.38 sec*proc (8 tests)
424+
muon = 0.38 sec*proc (8 tests)
425+
426+
Total Test time (real) = 0.49 sec
427+
428+
```
429+
430+
Parallel execution (on a machine with 16 cores) :
431+
432+
```shell
433+
> ctest -L mch -LE long -E Raw -j 16
434+
Start 270: Detectors/MUON/MCH/Contour/test/Polygon.cxx
435+
Start 271: Detectors/MUON/MCH/Contour/test/SegmentTree.cxx
436+
Start 268: Detectors/MUON/MCH/Contour/test/Edge.cxx
437+
Start 267: Detectors/MUON/MCH/Contour/test/ContourCreator.cxx
438+
Start 269: Detectors/MUON/MCH/Contour/test/Interval.cxx
439+
Start 266: Detectors/MUON/MCH/Contour/test/Contour.cxx
440+
Start 265: Detectors/MUON/MCH/Contour/test/BBox.cxx
441+
Start 272: Detectors/MUON/MCH/Contour/test/Vertex.cxx
442+
1/8 Test #270: Detectors/MUON/MCH/Contour/test/Polygon.cxx .......... Passed 0.08 sec
443+
2/8 Test #271: Detectors/MUON/MCH/Contour/test/SegmentTree.cxx ...... Passed 0.08 sec
444+
3/8 Test #268: Detectors/MUON/MCH/Contour/test/Edge.cxx ............. Passed 0.08 sec
445+
4/8 Test #269: Detectors/MUON/MCH/Contour/test/Interval.cxx ......... Passed 0.08 sec
446+
5/8 Test #267: Detectors/MUON/MCH/Contour/test/ContourCreator.cxx ... Passed 0.08 sec
447+
6/8 Test #266: Detectors/MUON/MCH/Contour/test/Contour.cxx .......... Passed 0.08 sec
448+
7/8 Test #265: Detectors/MUON/MCH/Contour/test/BBox.cxx ............. Passed 0.08 sec
449+
8/8 Test #272: Detectors/MUON/MCH/Contour/test/Vertex.cxx ........... Passed 0.08 sec
450+
451+
100% tests passed, 0 tests failed out of 8
452+
453+
Label Time Summary:
454+
mch = 0.65 sec*proc (8 tests)
455+
muon = 0.65 sec*proc (8 tests)
456+
457+
Total Test time (real) = 0.19 sec
458+
459+
```

0 commit comments

Comments
 (0)