rippled
Loading...
Searching...
No Matches
instrumentation.h
1#pragma once
2
3#include <cassert>
4
5#ifdef ENABLE_VOIDSTAR
6#ifdef NDEBUG
7#error "Antithesis instrumentation requires Debug build"
8#endif
9#include <antithesis_sdk.h>
10#else
11// Macros below are copied from antithesis_sdk.h and slightly simplified
12// The duplication is because Visual Studio 2019 cannot compile that header
13// even with the option -Zc:__cplusplus added.
14#define ALWAYS(cond, message, ...) assert((message) && (cond))
15#define ALWAYS_OR_UNREACHABLE(cond, message) assert((message) && (cond))
16#define SOMETIMES(cond, message, ...)
17#define REACHABLE(message, ...)
18#define UNREACHABLE(message, ...) assert((message) && false)
19#endif
20
21#define XRPL_ASSERT ALWAYS_OR_UNREACHABLE
22#define XRPL_ASSERT_PARTS(cond, function, description, ...) XRPL_ASSERT(cond, function " : " description)
23
24// How to use the instrumentation macros:
25//
26// * XRPL_ASSERT if cond must be true but the line might not be reached during
27// fuzzing. Same like `assert` in normal use.
28// * XRPL_ASSERT_PARTS is for convenience, and works like XRPL_ASSERT, but
29// splits the message param into "function" and "description", then joins
30// them with " : " before passing to XRPL_ASSERT.
31// * ALWAYS if cond must be true _and_ the line must be reached during fuzzing.
32// Same like `assert` in normal use.
33// * REACHABLE if the line must be reached during fuzzing
34// * SOMETIMES a hint for the fuzzer to try to make the cond true
35// * UNREACHABLE if the line must not be reached (in fuzzing or in normal use).
36// Same like `assert(false)` in normal use.
37//
38// NOTE: XRPL_ASSERT has similar semantics as C `assert` macro, with only minor
39// differences:
40// * XRPL_ASSERT must have an unique name (naming convention in CONTRIBUTING.md)
41// * during fuzzing, the program will continue execution past failed XRPL_ASSERT
42//
43// We continue to use regular C `assert` inside unit tests and inside constexpr
44// functions.
45//
46// NOTE: UNREACHABLE does *not* have the same semantics as std::unreachable.
47// The program will continue execution past an UNREACHABLE in a Release build
48// and during fuzzing (similar to failed XRPL_ASSERT).
49// Also, the naming convention in UNREACHABLE is subtly different from other
50// instrumentation macros - its name describes the condition which was _not_
51// meant to happen, while name in other macros describes the condition that is
52// meant to happen (e.g. as in "assert that this happens").