Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
assert.hpp File Reference
#include "barretenberg/common/bb_bench.hpp"
#include "barretenberg/common/compiler_hints.hpp"
#include "barretenberg/common/throw_or_abort.hpp"
#include <cstdint>
#include <sstream>
#include "barretenberg/common/log.hpp"
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <string>

Go to the source code of this file.

Classes

struct  bb::AssertGuard
 

Namespaces

namespace  bb
 Entry point for Barretenberg command-line interface.
 

Macros

#define BB_BENCH_ASSERT(x)
 
#define BB_DISABLE_ASSERTS()   bb::AssertGuard __bb_assert_guard(bb::AssertMode::WARN)
 
#define DONT_EVALUATE(expression)
 
#define ASSERT_DEBUG(expression, ...)   ASSERT(expression, __VA_ARGS__)
 
#define ASSERT_IN_CONSTEXPR(expression, ...)
 
#define ASSERT(expression, ...)
 
#define BB_ASSERT_EQ(actual, expected, ...)
 
#define BB_ASSERT_NEQ(actual, expected, ...)
 
#define BB_ASSERT_GT(left, right, ...)
 
#define BB_ASSERT_GTE(left, right, ...)
 
#define BB_ASSERT_LT(left, right, ...)
 
#define BB_ASSERT_LTE(left, right, ...)
 
#define ASSERT_THROW_OR_ABORT(statement, matcher)   ASSERT_THROW(statement, std::runtime_error)
 
#define EXPECT_THROW_OR_ABORT(statement, matcher)   EXPECT_THROW(statement, std::runtime_error)
 

Enumerations

enum class  bb::AssertMode : std::uint8_t { bb::ABORT , bb::WARN }
 

Functions

AssertModebb::get_assert_mode ()
 
void bb::assert_failure (std::string const &err)
 

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   expression,
  ... 
)
Value:
do { \
BB_BENCH_ASSERT("ASSERT" #expression); \
if (!(BB_LIKELY(expression))) { \
std::ostringstream oss; \
oss << "Assertion failed: (" #expression ")"; \
__VA_OPT__(oss << " | Reason: " << __VA_ARGS__;) \
bb::assert_failure(oss.str()); \
} \
} while (0)
#define BB_LIKELY(x)
void assert_failure(std::string const &err)
Definition assert.cpp:11

Definition at line 77 of file assert.hpp.

◆ ASSERT_DEBUG

#define ASSERT_DEBUG (   expression,
  ... 
)    ASSERT(expression, __VA_ARGS__)

Definition at line 54 of file assert.hpp.

◆ ASSERT_IN_CONSTEXPR

#define ASSERT_IN_CONSTEXPR (   expression,
  ... 
)
Value:
do { \
if (!(BB_LIKELY(expression))) { \
info("Assertion failed: (" #expression ")"); \
__VA_OPT__(info("Reason : ", __VA_ARGS__);) \
} \
} while (0)
void info(Args... args)
Definition log.hpp:74

Definition at line 68 of file assert.hpp.

◆ ASSERT_THROW_OR_ABORT

#define ASSERT_THROW_OR_ABORT (   statement,
  matcher 
)    ASSERT_THROW(statement, std::runtime_error)

Definition at line 184 of file assert.hpp.

◆ BB_ASSERT_EQ

#define BB_ASSERT_EQ (   actual,
  expected,
  ... 
)
Value:
do { \
BB_BENCH_ASSERT("BB_ASSERT_EQ" #actual " == " #expected); \
auto _actual = (actual); \
auto _expected = (expected); \
if (!(BB_LIKELY(_actual == _expected))) { \
std::ostringstream oss; \
oss << "Assertion failed: (" #actual " == " #expected ")\n"; \
oss << " Actual : " << _actual << "\n"; \
oss << " Expected: " << _expected; \
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
bb::assert_failure(oss.str()); \
} \
} while (0)
Examples
/opt/build/repo/barretenberg/cpp/src/barretenberg/common/zip_view.hpp.

Definition at line 88 of file assert.hpp.

◆ BB_ASSERT_GT

#define BB_ASSERT_GT (   left,
  right,
  ... 
)
Value:
do { \
BB_BENCH_ASSERT("BB_ASSERT_GT" #left " > " #right); \
auto _left = (left); \
auto _right = (right); \
if (!(BB_LIKELY(_left > _right))) { \
std::ostringstream oss; \
oss << "Assertion failed: (" #left " > " #right ")\n"; \
oss << " Left : " << _left << "\n"; \
oss << " Right : " << _right; \
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
bb::assert_failure(oss.str()); \
} \
} while (0)

Definition at line 118 of file assert.hpp.

◆ BB_ASSERT_GTE

#define BB_ASSERT_GTE (   left,
  right,
  ... 
)
Value:
do { \
BB_BENCH_ASSERT("BB_ASSERT_GTE" #left " >= " #right); \
auto _left = (left); \
auto _right = (right); \
if (!(BB_LIKELY(_left >= _right))) { \
std::ostringstream oss; \
oss << "Assertion failed: (" #left " >= " #right ")\n"; \
oss << " Left : " << _left << "\n"; \
oss << " Right : " << _right; \
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
bb::assert_failure(oss.str()); \
} \
} while (0)

Definition at line 133 of file assert.hpp.

◆ BB_ASSERT_LT

#define BB_ASSERT_LT (   left,
  right,
  ... 
)
Value:
do { \
BB_BENCH_ASSERT("BB_ASSERT_LT" #left " < " #right); \
auto _left = (left); \
auto _right = (right); \
if (!(BB_LIKELY(_left < _right))) { \
std::ostringstream oss; \
oss << "Assertion failed: (" #left " < " #right ")\n"; \
oss << " Left : " << _left << "\n"; \
oss << " Right : " << _right; \
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
bb::assert_failure(oss.str()); \
} \
} while (0)

Definition at line 148 of file assert.hpp.

◆ BB_ASSERT_LTE

#define BB_ASSERT_LTE (   left,
  right,
  ... 
)
Value:
do { \
BB_BENCH_ASSERT("BB_ASSERT_LTE" #left " <= " #right); \
auto _left = (left); \
auto _right = (right); \
if (!(BB_LIKELY(_left <= _right))) { \
std::ostringstream oss; \
oss << "Assertion failed: (" #left " <= " #right ")\n"; \
oss << " Left : " << _left << "\n"; \
oss << " Right : " << _right; \
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
bb::assert_failure(oss.str()); \
} \
} while (0)

Definition at line 163 of file assert.hpp.

◆ BB_ASSERT_NEQ

#define BB_ASSERT_NEQ (   actual,
  expected,
  ... 
)
Value:
do { \
BB_BENCH_ASSERT("BB_ASSERT_NEQ" #actual " != " #expected); \
auto _actual = (actual); \
auto _expected = (expected); \
if (!(BB_LIKELY(_actual != _expected))) { \
std::ostringstream oss; \
oss << "Assertion failed: (" #actual " != " #expected ")\n"; \
oss << " Actual : " << _actual << "\n"; \
oss << " Not expected: " << _expected; \
__VA_OPT__(oss << "\n Reason : " << __VA_ARGS__;) \
bb::assert_failure(oss.str()); \
} \
} while (0)

Definition at line 103 of file assert.hpp.

◆ BB_BENCH_ASSERT

#define BB_BENCH_ASSERT (   x)

Definition at line 12 of file assert.hpp.

◆ BB_DISABLE_ASSERTS

#define BB_DISABLE_ASSERTS ( )    bb::AssertGuard __bb_assert_guard(bb::AssertMode::WARN)

Definition at line 32 of file assert.hpp.

◆ DONT_EVALUATE

#define DONT_EVALUATE (   expression)
Value:
{ \
true ? static_cast<void>(0) : static_cast<void>((expression)); \
}

Definition at line 36 of file assert.hpp.

◆ EXPECT_THROW_OR_ABORT

#define EXPECT_THROW_OR_ABORT (   statement,
  matcher 
)    EXPECT_THROW(statement, std::runtime_error)

Definition at line 185 of file assert.hpp.