15#ifndef IOX2_BB_TESTING_ERROR_REPORTING_TESTING_ERROR_HANDLER_HPP
16#define IOX2_BB_TESTING_ERROR_REPORTING_TESTING_ERROR_HANDLER_HPP
25#include <gmock/gmock.h>
26#include <gtest/gtest.h>
64 static auto
init() noexcept ->
void;
75 const std::lock_guard<std::mutex> guard(m_mutex);
76 m_errors.push_back(desc);
82 const std::lock_guard<std::mutex> guard(m_mutex);
83 m_violations.push_back(desc);
89 return m_panicked.
load(std::memory_order_relaxed);
94 const std::lock_guard<std::mutex> guard(m_mutex);
98 m_jumpState.
store(JumpState::Obtainable);
103 const std::lock_guard<std::mutex> guard(m_mutex);
104 return !m_errors.empty();
111 const std::lock_guard<std::mutex> guard(m_mutex);
112 for (
auto desc : m_errors) {
113 if (desc.code == code) {
114 if (module == ANY_MODULE) {
117 return desc.module ==
module;
126 const std::lock_guard<std::mutex> guard(m_mutex);
128 for (
auto desc : m_violations) {
129 if (desc.code == code) {
141 if (m_jumpState.
exchange(JumpState::Pending) == JumpState::Pending) {
149 if (setjmp(&(m_jumpBuffer)[0]) != JUMPED_INDICATOR) {
157 void jump() noexcept {
158 if (m_jumpState.
load(std::memory_order_relaxed) == JumpState::Pending) {
160 longjmp(&m_jumpBuffer[0], JUMPED_INDICATOR);
168 static constexpr int JUMPED_INDICATOR { 1 };
170 mutable std::mutex m_mutex;
171 legacy::concurrent::Atomic<bool> m_panicked {
false };
172 std::vector<legacy::er::ErrorDescriptor> m_errors;
175 std::vector<legacy::er::ErrorDescriptor> m_violations;
179 jmp_buf m_jumpBuffer {};
181 enum class JumpState : uint8_t {
189 legacy::concurrent::Atomic<JumpState> m_jumpState { JumpState::Obtainable };
195 void OnTestStart(const ::testing::TestInfo& test_info)
override;
205 auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
#define IOX2_MAYBE_UNUSED
IOX2_MAYBE_UNUSED adds the [[gnu::unused]] attribute when it is available for the current compiler or...
This class hooks into gTest to automatically resets the error handler on the start of a test.
void OnTestStart(const ::testing::TestInfo &test_info) override
Defines the test reaction of dynamic error handling.
auto has_violation(legacy::er::ErrorCode code) const noexcept -> bool
Indicates whether a assumption violation occurred previously.
auto on_panic() -> void override
Defines the reaction on panic.
auto reset() noexcept -> void
Reset panic state and clears all errors that occurred previously.
auto has_error(legacy::er::ErrorCode code, legacy::er::ModuleId module=legacy::er::ModuleId()) const noexcept -> bool
Indicates whether a specific error occurred previously.
auto fatal_failure_test_context(const bb::StaticFunction< void()> &test_function) -> bool
runs test_function in a test context that can detect fatal failures; runs in the same thread
auto has_error() const noexcept -> bool
Indicates whether any error occurred previously.
TestingErrorHandler() noexcept=default
auto on_report_violation(legacy::er::ErrorDescriptor desc) -> void override
Defines the reaction on violation.
auto on_report_error(legacy::er::ErrorDescriptor desc) -> void override
Defines the reaction on error.
static auto init() noexcept -> void
Initialized the error handler. This should be called in the main function of the test binary.
auto has_panicked() const noexcept -> bool
Indicates whether there was a panic call previously.
static bool set(StaticLifetimeGuard< Handler > handlerGuard) noexcept
set the current singleton instance
Manages a static instance of type T in a way so that each existing StaticLifetimeGuard prevents the d...
static T & instance(Args &&... args) noexcept
Construct the instance to be guarded with constructor arguments.
T load(std::memory_order order=std::memory_order_seq_cst) const noexcept
Atomically loads and returns the stored value.
void store(T value, std::memory_order order=std::memory_order_seq_cst) noexcept
Atomically stores the given value with the given memory order.
T exchange(T value, std::memory_order order=std::memory_order_seq_cst) noexcept
Atomically exchanges the given value with the stored value using the given memory order and returns t...
Defines the dynamic error handling interface (i.e. changeable at runtime).
Contains all required information about the error. Can be extended as needed without breaking the int...
static constexpr type ANY