ARB
UnitTester.hxx
Go to the documentation of this file.
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 
22 typedef void (*UnitTest_function)();
23 
25  TEST_OK, // test PASSED
26  TEST_TRAPPED, // test FAILED
28  TEST_INTERRUPTED, // timeout
29  TEST_THREW, // exception thrown (tests should never do that)
32 };
33 
36  const char *name;
37  const char *location;
38 
39  void print_error(FILE *out, UnitTestResult result) const;
40 };
41 
42 struct UnitTester {
43  UnitTester(const char *libname, const UnitTest_simple *simple_tests, int warn_level, size_t skippedTests, const UnitTest_simple *postcond) __attribute__((noreturn));
44 };
45 
46 UnitTestResult execute_guarded(UnitTest_function fun, long *duration_usec, long max_allowed_duration_ms, bool detect_environment_calls);
47 void sleepms(long ms);
48 
49 // ------------------------------
50 // execution time limits
51 
52 const long SECONDS = 1000;
53 const long MINUTES = 60*SECONDS;
54 
55 #if defined(DEVEL_RALF)
56 
57 const long MAX_EXEC_MS_NORMAL = 12 * SECONDS; // kill with segfault after time passed
58 const long MAX_EXEC_MS_SLOW = 60 * SECONDS; // same for slow tests
59 const long MAX_EXEC_MS_ENV = 80 * SECONDS; // same for environment setup/cleanup
60 const long MAX_EXEC_MS_VGSYS = 140 * SECONDS; // same for valgrinded system calls (especially pt_server)
61 
62 const long WARN_SLOW_ABOVE_MS = 1 * SECONDS; // when too warn about slow test
63 
64 #else // !defined(DEVEL_RALF)
65 
66 // these are temporary test-timings to avoid test timeouts on jenkins build server
67 
68 const long MAX_EXEC_MS_NORMAL = 30 * MINUTES; // kill with segfault after time passed
69 const long MAX_EXEC_MS_SLOW = 45 * MINUTES; // same for slow tests
70 const long MAX_EXEC_MS_ENV = 45 * MINUTES; // same for environment setup/cleanup
71 const long MAX_EXEC_MS_VGSYS = 45 * MINUTES; // same for valgrinded system calls (especially pt_server)
72 const long WARN_SLOW_ABOVE_MS = 30 * MINUTES; // when too warn about slow test
73 
74 #endif
75 
76 #define FLAGS_DIR "flags"
77 #define FLAGS_EXT "flag"
78 
79 #else
80 #error UnitTester.hxx included twice
81 #endif // UNITTESTER_HXX
const char * location
Definition: UnitTester.hxx:37
string result
void(* UnitTest_function)()
Definition: UnitTester.hxx:22
UnitTestResult execute_guarded(UnitTest_function fun, long *duration_usec, long max_allowed_duration_ms, bool detect_environment_calls)
Definition: UnitTester.cxx:403
const long MAX_EXEC_MS_NORMAL
Definition: UnitTester.hxx:68
const long SECONDS
Definition: UnitTester.hxx:52
UnitTest_function fun
Definition: UnitTester.hxx:35
const char * name
Definition: UnitTester.hxx:36
void sleepms(long ms)
Definition: UnitTester.cxx:354
const long WARN_SLOW_ABOVE_MS
Definition: UnitTester.hxx:72
void print_error(FILE *out, UnitTestResult result) const
Definition: UnitTester.cxx:486
const long MAX_EXEC_MS_SLOW
Definition: UnitTester.hxx:69
const long MINUTES
Definition: UnitTester.hxx:53
const long MAX_EXEC_MS_ENV
Definition: UnitTester.hxx:70
UnitTestResult
Definition: UnitTester.hxx:24
const long MAX_EXEC_MS_VGSYS
Definition: UnitTester.hxx:71
UnitTester(const char *libname, const UnitTest_simple *simple_tests, int warn_level, size_t skippedTests, const UnitTest_simple *postcond) __attribute__((noreturn))
Definition: UnitTester.cxx:632
struct PT_short_chain_header __attribute__