source: branches/gcc/UNIT_TESTER/UnitTester.hxx

Last change on this file was 19810, checked in by westram, 3 weeks ago
File size: 3.2 KB
Line 
1// ================================================================ //
2//                                                                  //
3//   File      : UnitTester.hxx                                     //
4//   Purpose   : unit testing - test one unit                       //
5//                                                                  //
6//   Coded by Ralf Westram (coder@reallysoft.de) in February 2010   //
7//   Institute of Microbiology (Technical University Munich)        //
8//   http://www.arb-home.de/                                        //
9//                                                                  //
10// ================================================================ //
11
12#ifndef UNITTESTER_HXX
13#define UNITTESTER_HXX
14
15#ifndef _GLIBCXX_CSTDLIB
16#include <cstdlib>
17#endif
18#ifndef _GLIBCXX_CSTDIO
19#include <cstdio>
20#endif
21
22typedef void (*UnitTest_function)();
23
24enum UnitTestResult {
25    TEST_OK,                          // test PASSED
26    TEST_TRAPPED,                     // test FAILED
27    TEST_FAILED_POSTCONDITION,
28    TEST_INTERRUPTED,                 // timeout
29    TEST_THREW,                       // exception thrown (tests should never do that)
30    TEST_INVALID,                     // test has other invalid behavior
31    TEST_LACKS_LOCATION,              // location of test is unknown (define EXPECT_VALID_TEST_LOCATION to activate this)
32    TEST_UNKNOWN_RESULT,
33};
34
35struct UnitTest_simple {
36    UnitTest_function  fun;
37    const char        *name;
38    const char        *location;
39
40    void print_error(FILE *out, UnitTestResult result) const;
41};
42
43struct UnitTester {
44    UnitTester(const char *libname, const UnitTest_simple *simple_tests, int warn_level, size_t skippedTests, const UnitTest_simple *postcond) __attribute__((noreturn));
45};
46
47UnitTestResult execute_guarded(UnitTest_function fun, long *duration_usec, long max_allowed_duration_ms, bool detect_environment_calls);
48void sleepms(long ms);
49
50// ------------------------------
51//      execution time limits
52
53const long SECONDS = 1000;
54const long MINUTES = 60*SECONDS;
55
56#if defined(DEVEL_RALF)
57
58const long MAX_EXEC_MS_NORMAL = 12 * SECONDS;       // kill with segfault after time passed
59const long MAX_EXEC_MS_SLOW   = 60 * SECONDS;       // same for slow tests
60const long MAX_EXEC_MS_ENV    = 80 * SECONDS;       // same for environment setup/cleanup
61const long MAX_EXEC_MS_VGSYS  = 140 * SECONDS;      // same for valgrinded system calls (especially pt_server)
62
63const long WARN_SLOW_ABOVE_MS = 1 * SECONDS;        // when too warn about slow test
64
65#else // !defined(DEVEL_RALF)
66
67// these are temporary test-timings to avoid test timeouts on jenkins build server
68
69const long MAX_EXEC_MS_NORMAL = 30 * MINUTES;       // kill with segfault after time passed
70const long MAX_EXEC_MS_SLOW   = 45 * MINUTES;       // same for slow tests
71const long MAX_EXEC_MS_ENV    = 45 * MINUTES;       // same for environment setup/cleanup
72const long MAX_EXEC_MS_VGSYS  = 45 * MINUTES;       // same for valgrinded system calls (especially pt_server)
73const long WARN_SLOW_ABOVE_MS = 30 * MINUTES;       // when too warn about slow test
74
75#endif
76
77#define FLAGS_DIR "flags"
78#define FLAGS_EXT "flag"
79
80#else
81#error UnitTester.hxx included twice
82#endif // UNITTESTER_HXX
Note: See TracBrowser for help on using the repository browser.