-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathunittest.cpp
More file actions
95 lines (79 loc) · 2.73 KB
/
unittest.cpp
File metadata and controls
95 lines (79 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "unittest.h"
#include "backtrace.h"
#include "exceptionassert.h"
#include "prettifysegfault.h"
#include "shared_state.h"
#include "tasktimer.h"
#include "timer.h"
#include "verifyexecutiontime.h"
#include "demangle.h"
#include "barrier.h"
#include "shared_state_traits_backtrace.h"
#include <stdio.h>
#include <exception>
#include <boost/exception/diagnostic_information.hpp>
using namespace std;
namespace BacktraceTest {
string lastname;
#define RUNTEST(x) do { \
TaskTimer tt("%s", #x); \
lastname = #x; \
x::test (); \
} while(false)
int UnitTest::
test(bool rethrow_exceptions)
{
try {
Timer(); // Init performance counting
TaskTimer tt("Running tests");
RUNTEST(Backtrace);
RUNTEST(ExceptionAssert);
RUNTEST(PrettifySegfault);
RUNTEST(Timer);
RUNTEST(shared_state_test);
RUNTEST(VerifyExecutionTime);
RUNTEST(spinning_barrier);
RUNTEST(locking_barrier);
RUNTEST(shared_state_traits_backtrace);
} catch (const ExceptionAssert& x) {
if (rethrow_exceptions)
throw;
char const * const * f = boost::get_error_info<boost::throw_file>(x);
int const * l = boost::get_error_info<boost::throw_line>(x);
char const * const * c = boost::get_error_info<ExceptionAssert::ExceptionAssert_condition>(x);
std::string const * m = boost::get_error_info<ExceptionAssert::ExceptionAssert_message>(x);
fflush(stdout);
fprintf(stderr, "%s",
str(boost::format("%s:%d: %s. %s\n"
"%s\n"
" FAILED in %s::test()\n\n")
% (f?*f:0) % (l?*l:-1) % (c?*c:0) % (m?*m:0) % boost::diagnostic_information(x) % lastname ).c_str());
fflush(stderr);
return 1;
} catch (const exception& x) {
if (rethrow_exceptions)
throw;
fflush(stdout);
fprintf(stderr, "%s",
str(boost::format("%s\n"
"%s\n"
" FAILED in %s::test()\n\n")
% vartype(x) % boost::diagnostic_information(x) % lastname ).c_str());
fflush(stderr);
return 1;
} catch (...) {
if (rethrow_exceptions)
throw;
fflush(stdout);
fprintf(stderr, "%s",
str(boost::format("Not an std::exception\n"
"%s\n"
" FAILED in %s::test()\n\n")
% boost::current_exception_diagnostic_information () % lastname ).c_str());
fflush(stderr);
return 1;
}
printf("\n OK\n\n");
return 0;
}
} // namespace BacktraceTest