| 1 |
Building the code |
| 2 |
----------------- |
| 3 |
|
| 4 |
By default, the code is built in release mode. To build a debug version, use |
| 5 |
|
| 6 |
$ mkdir builddebug |
| 7 |
$ cd builddebug |
| 8 |
$ cmake -DCMAKE_BUILD_TYPE=debug .. |
| 9 |
$ make |
| 10 |
|
| 11 |
For a release version, use -DCMAKE_BUILD_TYPE=release |
| 12 |
|
| 13 |
Running the tests |
| 14 |
----------------- |
| 15 |
|
| 16 |
$ make |
| 17 |
$ make test |
| 18 |
|
| 19 |
Note that "make test" alone is dangerous because it does not rebuild |
| 20 |
any tests if either the library or the test files themselves need |
| 21 |
rebuilding. It's not possible to fix this with cmake because cmake cannot |
| 22 |
add build dependencies to built-in targets. To make sure that everything |
| 23 |
is up-to-date, run "make" before running "make test"! |
| 24 |
|
| 25 |
To run the tests with valgrind: |
| 26 |
|
| 27 |
$ make valgrind |
| 28 |
|
| 29 |
It doesn't make sense for some tests to run them with valgrind. For |
| 30 |
example, the header compilation tests don't need valgrind because |
| 31 |
we'd just be testing that Python doesn't leak. There are also some |
| 32 |
tests that run too slow and time out under valgrind and, occasionally, |
| 33 |
valgrind crashes for a particular test. |
| 34 |
|
| 35 |
There are two ways to suppress tests: |
| 36 |
|
| 37 |
You can add a test name to CTestCustom.cmake.in to suppress that |
| 38 |
test completely. That makes sense for the header compilation tests, |
| 39 |
for example. |
| 40 |
|
| 41 |
If a specific test case in a test program causes a valgrind problem, |
| 42 |
you can selectively disable a section of code like this: |
| 43 |
|
| 44 |
#include <valgrind/valgrind.h> |
| 45 |
|
| 46 |
if (!RUNNING_ON_VALGRIND) |
| 47 |
{ |
| 48 |
// Code here crashes valgrind... |
| 49 |
} |
| 50 |
|
| 51 |
That way, the test will still be run as part of the normal "make test" |
| 52 |
target, but will be ommitted when running "make valgrind". |
| 53 |
|
| 54 |
Coverage |
| 55 |
-------- |
| 56 |
|
| 57 |
To build with the flags for coverage testing enabled and get coverage: |
| 58 |
|
| 59 |
$ mkdir buildcoverage |
| 60 |
$ cd buildcoverage |
| 61 |
$ cmake -DCMAKE_BUILD_TYPE=coverage |
| 62 |
$ make |
| 63 |
$ make test |
| 64 |
$ make coverage |
| 65 |
|
| 66 |
Unfortunately, it is not possible to get 100% coverage for some files, |
| 67 |
mainly due to gcc's generation of two destructors for dynamic and non- |
| 68 |
dynamic instances. For abstract base classes and for classes that |
| 69 |
prevent stack and static allocation, this causes one of the destructors |
| 70 |
to be reported as uncovered. |
| 71 |
|
| 72 |
There are also issues with some functions in header files that are |
| 73 |
incorrectly reported as uncovered due to inlining, as well as |
| 74 |
the impossibility of covering defensive assert(false) statements, |
| 75 |
such as an assert in the default branch of a switch, where the |
| 76 |
switch is meant to handle all possible cases explicitly. |
| 77 |
|
| 78 |
If you run a binary and get lots of warnings about a "merge mismatch for summaries", |
| 79 |
this is caused by having made changes to the source that add or remove code |
| 80 |
that was previously run, so the new coverage output cannot sensibly be merged |
| 81 |
into the old coverage output. You can get rid of this problem by running |
| 82 |
|
| 83 |
$ make clean-coverage |
| 84 |
|
| 85 |
This deletes all the .gcda files, allowing the merge to (sometimes) succeed again. |
| 86 |
If this doesn't work either, the only remedy is to do a clean build. |
| 87 |
|
| 88 |
Code style |
| 89 |
---------- |
| 90 |
|
| 91 |
Please maintain the existing coding style. For details |
| 92 |
on the style, see lp:canonical-client-development-guidelines. |
| 93 |
|
| 94 |
We use a format tool that fixes a whole lot of issues |
| 95 |
regarding code style. See the HACKING file of lp:unity-scopes-api |
| 96 |
for details on the tool. |
| 97 |
|
| 98 |
Thread and address sanitizer |
| 99 |
---------------------------- |
| 100 |
|
| 101 |
Set SANITIZER to "thread" or "address" to build with the |
| 102 |
corresponding sanitizer enabled. |
| 103 |
|
| 104 |
Some libraries cause a cause a large number of warnings from |
| 105 |
thread sanitizer. The tsan-suppress file supresses the benign |
| 106 |
race conditions we currently know about. To run the tests |
| 107 |
(from the build directory) with these suppressions |
| 108 |
enabled, use: |
| 109 |
|
| 110 |
$ TSAN_OPTIONS="suppressions=../tsan-suppress" make test |
| 111 |
|
| 112 |
If a test runs too slowly under address sanitizer, you can |
| 113 |
hide a section of code from address sanitzer with: |
| 114 |
|
| 115 |
#if defined(__has_feature) |
| 116 |
#if !__has_feature(address_sanitizer) |
| 117 |
|
| 118 |
// Code here takes forever under address sanitizer... |
| 119 |
|
| 120 |
#endif |
| 121 |
#endif |