source: tags/svn.1.5.4/UNIT_TESTER/README.txt

Last change on this file was 8104, checked in by westram, 13 years ago

merge from ptpan_back [8085] [8088] [8091]

  • avoid shadow warnings from some TEST_ASSERTions
  • patch name shows whether tests were valgrinded
  • added template IGNORE_RESULT(), to ignore results tagged with __ATTR__USERESULT
File size: 4.6 KB
Line 
1
2How to use ARB unit testing
3---------------------------
4
51. Invocation
6
7   Edit config.makefile. Set UNIT_TESTS to 1
8
9   cd $ARBHOME
10   make unit_tests
11
12   'make all' runs tests as well ('make build' doesn't)
13
142. Add unit test code
15
16   Go to the unit containing your_function() and add something like
17   the following to the end of the file.
18
19       #if (UNIT_TESTS == 1)
20
21       #include <test_unit.h>
22
23       void TEST_your_function() {
24       }
25
26       #endif
27
28   The names of the test functions are important:
29       - they have to start with 'TEST_' and
30       - need to be visible at global scope.
31
32   (see also 'Building tests' at end of file)
33
34
35   Test result:
36
37      If TEST_your_function() does nothing special, it is assumed the unit test passed "ok".
38
39      If your function fails an assertion (TEST_ASSERT) or raises SIGSEGV in any other manner,
40      it is assumed the unit test failed and an error message is printed to the console.
41
42      (Any other test function in the same unit will nevertheless get called.)
43
44
45   Failing tests:
46
47      If you have some broken behavior that you cannot fix now, please do NOT leave
48      the test as "failing". Instead change TEST_ASSERT into
49
50          TEST_ASSERT_BROKEN(failing_condition);
51
52      That will print a warning as reminder as long as the condition fails.
53      When the behavior was fixed (so that the condition is fulfilled now),
54      it will abort the test as failed!
55      Just change TEST_ASSERT_BROKEN back into TEST_ASSERT then.
56
57      Set WARN_LEVEL to 0 in Makefile.setup.local to disable warnings.
58
59
60   Missing tests:
61
62      You may drop a reminder like
63
64          MISSING_TEST(describe what is missing);
65
66      which will appear as warning during test run.
67
68
69   Order of tests:
70
71      Tests are executed in the order they appear in the code.
72      Multiple Files are sorted alphabethically.
73
74      Exceptions:
75      - If test name starts with 'TEST_###' (where ### are digits), it declares a test with priority ###.
76        The default priority is 100. Lower numbers mean higher priority, i.e. start more early.
77      - Other predefined priorities are
78        - TEST_BASIC_ (=20)
79        - TEST_EARLY_ (=50)
80        - TEST_SLOW_  (=900)
81
82        TEST_SLOW_... is meant to indicate "slow" tests (i.e. tests which need more than
83        a second to execute).
84
85   Order of test units:
86
87      Tests from each unit (aka library) run consecutive.
88      The order of the units is defined in ARB Makefile.
89
90
913. Valgrinding test code
92
93   If you set
94
95      VALGRIND=A
96
97   in UNIT_TESTER/Makefile.setup.local, valgrind will be started on the test-binary after the normal
98   unit tests passed with success.
99   Valgrind errors/warnings will not raise an error or abort testing.
100
101
102   If you set
103
104      VALGRIND=B
105
106   valgrind will be started BEFORE running tests.
107   Useful if test fail unexpectedly and you suspect a memory bug.
108
109   See also ENABLE_CRASH_TESTS in test_unit.h (all crash tests are reported by valgrind)
110
111
112   If you set
113
114      VALGRIND=E
115
116   some external tools like arb_pt_server will be spawned valgrinded and the generated
117   reports will be printed on test termination.
118
119   Any combination of the above works as well.
120
1214. Check test-coverage
122
123   set 'COVERAGE=1' in config.makefile and 'make rebuild'
124
125   - prints out uncovered code to compile log
126   - leaves info for partly covered code files in yourcode.cxx.cov
127
128   Note:
129        You can silence lines which are never reached while testing
130        with a comment containing 'NEED_NO_COV'.
131
132   call 'make clean_coverage_results' to get rid of .cov files
133
134   (see also showCoverageForAll in gcov2msg.pl)
135
1365. Running only some tests
137
138   Set 'RESTRICT=expr' to '.' to run all tests.
139
140   Set it to sth else to run only tests for matching source files.
141   This is helpful if you'd like to check test-coverage.
142
143   Set 'RESTRICT_LIB=lib1:lib2' to test only a few libs.
144
145
146   Slow tests ('TEST_SLOW_...'; see above) will only run every 15 minutes.
147
148
1496. Global test environment
150
151   @@@ Not in SVN yet
152
153
1547. Auto-patch generation
155
156   Whenever unit tests complete successfully, a patch (svn diff) is generated and
157   stored inside $ARBHOME/patches.arb/
158
159   After PATCHES_KEEP_HOURS seconds the patch will be deleted automatically
160   (see Makefile.setup.local), considering at least PATCHES_MIN_KEPT patches remain.
161
1628. Building tests
163
164   To build and execute a test-executable for a previously untested subdir
165   the following steps are necessary:
166
167   - add the test to the list of performed tests in ../Makefile@UNITS_TESTED
168   - if the test subject is a shared library, be sure to mention it a Makefile.test@SHAREDLIBS
169   - if the test subject is an executable, be sure to mention it a Makefile.test@EXEOBJDIRS
Note: See TracBrowser for help on using the repository browser.