source: branches/gcc/UNIT_TESTER/README.txt

Last change on this file was 19810, checked in by westram, 3 weeks ago
File size: 8.9 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 expectation (TEST_EXPECT) 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   Post conditions:
46
47      If a unit defines one or more tests called
48         void TEST_POSTCOND_xxx()
49      each of these post condition tests will be run after EACH single unit test.
50
51      These post condition tests are intended to check for unwanted global side-effects of
52      test-functions. Such side effects often let other (unrelated) test-functions fail
53      unexpectedly. Use them to undo these side-effects.
54
55      If the post-condition fails, the test itself will be reported as failure.
56
57      If the test itself has failed for other reasons, post condition tests will nevertheless
58      be executed (and may do their cleanups), but their failures will not be shown in the log.
59
60
61   Failing tests:
62
63      If you have some broken behavior that you cannot fix now, please do NOT leave
64      the test as "failing". Instead change TEST_EXPECT into
65
66          TEST_EXPECT__BROKEN(failing_condition);
67
68      That will print a warning as reminder as long as the condition fails.
69      When the behavior was fixed (so that the condition is fulfilled now),
70      it will abort the test as failed!
71      Just change TEST_EXPECT__BROKEN back into TEST_EXPECT then.
72
73      Note: there are many different flavors of broken expectation macros.
74            All these macros have the term '__BROKEN' as part of their name.
75
76      Control warnings:
77
78             In Makefile.setup.local you may change WARN_LEVEL to
79             - 0 to disable warnings.
80             - 1 to hide broken test warnings, but show rest.
81             - 2 to show all warnings.
82
83      Random failures:
84
85             Some tests tend to fail randomly if started from inside jenkins (due to
86             parallel builds), whereas they behave proper and provide safety during
87             normal development. You should disable such tests for jenkins by enclosing
88             the whole test with:
89
90                #if !defined(DEVEL_JENKINS)
91                #endif
92
93             One example for such a test is ../CORE/arb_cs.cxx@TEST_open_socket
94
95             Another possibility to handle random failures is to allow multiple tries.
96             This can be done using the macro TEST_ALLOW_RETRY(count). If called from
97             testcode this will allow the test to run 'count' times, failing only if
98             all 'count' calls of the test function result in failure.
99             Note: TEST_ALLOW_RETRY has no effect if a test already gets retried!
100
101   Missing tests:
102
103      You may drop a reminder like
104
105          MISSING_TEST(describe what is missing);
106
107      which will appear as warning during test run.
108
109
110   Disabled tests:
111
112      To disable test TEST_method() rename it into NOTEST_method().
113      This will print a warning until the test is enabled again.
114      To avoid that warning rename it into NONOTEST_method().
115
116   Order of tests:
117
118      Tests are executed in the order they appear in the code.
119      Multiple Files are sorted alphabethically.
120
121      Exceptions:
122      - If test name starts with 'TEST_###' (where ### are digits), it declares a test with priority ###.
123        The default priority is 100. Lower numbers mean higher priority, i.e. start more early.
124      - Other predefined priorities are
125        - TEST_BASIC_       (=20)
126        - TEST_EARLY_       (=50)
127        - TEST_             (=100 default)
128        - TEST_LATE_        (=200)
129        - TEST_SLOW_        (=900)
130        - TEST_AFTER_SLOW_  (=910)
131
132        TEST_SLOW_... is meant to indicate "slow" tests (i.e. tests which need more than
133        a second to execute).
134
135   Order of test units:
136
137      Tests from each unit (aka library) run consecutive.
138      Tests of different units are executed asynchronously.
139
140   Code differences when compiled with UNIT_TESTS=1
141
142      Some unit tests require differences in production code, e.g.
143      - to inspect class internals
144      - to provoke special conditions (e.g. reduce some buffer size to simulate big
145        amount of processed data)
146
147      Such differences should be marked with a comment containing 'UT_DIFF'.
148
149
1503. Valgrinding test code
151
152   Note: valgrind was not used for some time and might have rotten.
153         I've completely switched to using sanitizers -> see ../config.makefile
154
155
156   If you set
157
158      VALGRIND=A
159
160   in UNIT_TESTER/Makefile.setup.local, valgrind will be started on the test-binary after the normal
161   unit tests passed with success.
162   Valgrind errors/warnings will not raise an error or abort testing.
163
164
165   If you set
166
167      VALGRIND=B
168
169   valgrind will be started BEFORE running tests.
170   Useful if test fail unexpectedly and you suspect a memory bug.
171
172   See also ENABLE_CRASH_TESTS in test_unit.h (all crash tests are reported by valgrind)
173
174
175   If you set
176
177      VALGRIND=E
178
179   some external tools like arb_pt_server will be spawned valgrinded and the generated
180   reports will be printed on test termination.
181
182   Any combination of the above works as well.
183
1844. Check test-coverage
185
186   set 'COVERAGE=1' in config.makefile and 'make rebuild'
187
188   - prints out uncovered code to compile log
189   - leaves info for partly covered code files in yourcode.cxx.cov
190
191   Note:
192        You can silence lines which are never reached while testing
193        with a comment containing 'NEED_NO_COV'.
194
195   call 'make clean_coverage_results' to get rid of .cov files
196
197   (see also showCoverageForAll in gcov2msg.pl)
198
1995. Define which tests shall run
200
201   [look into Makefile.setup.local for examples]
202
203   a. Restrict tests to one or several libraries:
204
205      Set 'RESTRICT_LIB=lib1[:libN]*' to run only tests defined in the
206      specified libraries.
207
208      Set 'RESTRICT_LIB=' to test all libraries.
209
210   b. Restrict tests to specific modules:
211
212      Set "RESTRICT_MODULE='regexpr'" to run only tests located in
213      matching modules. Use '.' to match any modules.
214      Prefix whole regexpr with '!' to match all but listed modules.
215
216   c. Restrict tests by name:
217
218      Set "RESTRICT_FUN='regexpr'" to run only tests whose function-name
219      matches the regexpr. Use '.' to match any test.
220      Prefix whole regexpr with '!' to match all but listed tests.
221
222   d. Restrict test frequency:
223
224      Set 'SKIP_SLOW=min' to restrict frequency of "slow tests". Slow tests
225      are all tests named 'TEST_SLOW_.*'. These tests will not run more often
226      than the specified amount of minutes.
227      Set 'SKIP_SLOW=0' to always run all tests (default).
228
229   e. Run unchanged tests:
230
231      By default only changed unit-tests will run. Set 'ONLY_CHANGED_TESTS=0'
232      to force testing unchanged code.
233
234      Tests will re-run if ..
235      - the test code was changed,
236      - any needed library was changed or if
237      - Makefile.setup.local or anything in the UnitTester itself was changed.
238
239      Calling 'make clean' in $ARBHOME will also force all tests to re-run.
240
241
2426. Global test environments
243
244   Environments provide a test situation which takes some reasonable time
245   for startup.
246
247   Multiple tests will be permitted to use one environment, but they will
248   be serialized (even if tests are running in multiple processes).
249
250   These environments have to be coded directly in TestEnvironment.cxx
251   (for existing environments see TestEnvironment.cxx@ExistingEnvironments)
252
253   If you write a test that wishes to use one of the environments simply write
254      TEST_SETUP_GLOBAL_ENVIRONMENT("name"); // starts environment 'name'
255
256
2577. Auto-patch generation
258
259   Whenever unit tests complete successfully, a patch (svn diff) is generated and
260   stored inside $ARBHOME/patches.arb/
261
262   After PATCHES_KEEP_HOURS seconds the patch will be deleted automatically
263   (see Makefile.setup.local), considering at least PATCHES_MIN_KEPT patches remain.
264
2658. Building tests
266
267   To build and execute a test-executable for a previously untested subdir
268   the following steps are necessary:
269
270   - add the test to the list of performed tests in ../Makefile@UNITS_TESTED
271   - if the test subject is a shared library, be sure to mention it a Makefile.test@SHAREDLIBS
272   - 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.