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 BM_CHECK macros.
27 // CheckHandler will log information about the failures and abort when it is
31 CheckHandler(const char* check
, const char* file
, const char* func
, int line
)
32 : log_(GetErrorLogInstance()) {
33 log_
<< file
<< ":" << line
<< ": " << func
<< ": Check `" << check
37 LogType
& GetLog() { return log_
; }
39 BENCHMARK_NORETURN
~CheckHandler() BENCHMARK_NOEXCEPT_OP(false) {
44 CheckHandler
& operator=(const CheckHandler
&) = delete;
45 CheckHandler(const CheckHandler
&) = delete;
46 CheckHandler() = delete;
52 } // end namespace internal
53 } // end namespace benchmark
55 // The BM_CHECK macro returns a std::ostream object that can have extra
56 // information written to it.
59 (b ? ::benchmark::internal::GetNullLogInstance() \
60 : ::benchmark::internal::CheckHandler(#b, __FILE__, __func__, __LINE__) \
63 #define BM_CHECK(b) ::benchmark::internal::GetNullLogInstance()
67 // preserve whitespacing between operators for alignment
68 #define BM_CHECK_EQ(a, b) BM_CHECK((a) == (b))
69 #define BM_CHECK_NE(a, b) BM_CHECK((a) != (b))
70 #define BM_CHECK_GE(a, b) BM_CHECK((a) >= (b))
71 #define BM_CHECK_LE(a, b) BM_CHECK((a) <= (b))
72 #define BM_CHECK_GT(a, b) BM_CHECK((a) > (b))
73 #define BM_CHECK_LT(a, b) BM_CHECK((a) < (b))
75 #define BM_CHECK_FLOAT_EQ(a, b, eps) BM_CHECK(std::fabs((a) - (b)) < (eps))
76 #define BM_CHECK_FLOAT_NE(a, b, eps) BM_CHECK(std::fabs((a) - (b)) >= (eps))
77 #define BM_CHECK_FLOAT_GE(a, b, eps) BM_CHECK((a) - (b) > -(eps))
78 #define BM_CHECK_FLOAT_LE(a, b, eps) BM_CHECK((b) - (a) > -(eps))
79 #define BM_CHECK_FLOAT_GT(a, b, eps) BM_CHECK((a) - (b) > (eps))
80 #define BM_CHECK_FLOAT_LT(a, b, eps) BM_CHECK((b) - (a) > (eps))