8 #include "internal_macros.h"
14 typedef void(AbortHandlerT
)();
16 inline AbortHandlerT
*& GetAbortHandler() {
17 static AbortHandlerT
* handler
= &std::abort
;
21 BENCHMARK_NORETURN
inline void CallAbortHandler() {
23 std::abort(); // fallback to enforce noreturn
26 // CheckHandler is the class constructed by failing CHECK macros. CheckHandler
27 // will log information about the failures and abort when it is destructed.
30 CheckHandler(const char* check
, const char* file
, const char* func
, int line
)
31 : log_(GetErrorLogInstance()) {
32 log_
<< file
<< ":" << line
<< ": " << func
<< ": Check `" << check
36 LogType
& GetLog() { return log_
; }
38 BENCHMARK_NORETURN
~CheckHandler() BENCHMARK_NOEXCEPT_OP(false) {
43 CheckHandler
& operator=(const CheckHandler
&) = delete;
44 CheckHandler(const CheckHandler
&) = delete;
45 CheckHandler() = delete;
51 } // end namespace internal
52 } // end namespace benchmark
54 // The CHECK macro returns a std::ostream object that can have extra information
58 (b ? ::benchmark::internal::GetNullLogInstance() \
59 : ::benchmark::internal::CheckHandler(#b, __FILE__, __func__, __LINE__) \
62 #define CHECK(b) ::benchmark::internal::GetNullLogInstance()
65 #define CHECK_EQ(a, b) CHECK((a) == (b))
66 #define CHECK_NE(a, b) CHECK((a) != (b))
67 #define CHECK_GE(a, b) CHECK((a) >= (b))
68 #define CHECK_LE(a, b) CHECK((a) <= (b))
69 #define CHECK_GT(a, b) CHECK((a) > (b))
70 #define CHECK_LT(a, b) CHECK((a) < (b))
72 #define CHECK_FLOAT_EQ(a, b, eps) CHECK(std::fabs((a) - (b)) < (eps))
73 #define CHECK_FLOAT_NE(a, b, eps) CHECK(std::fabs((a) - (b)) >= (eps))
74 #define CHECK_FLOAT_GE(a, b, eps) CHECK((a) - (b) > -(eps))
75 #define CHECK_FLOAT_LE(a, b, eps) CHECK((b) - (a) > -(eps))
76 #define CHECK_FLOAT_GT(a, b, eps) CHECK((a) - (b) > (eps))
77 #define CHECK_FLOAT_LT(a, b, eps) CHECK((b) - (a) > (eps))