mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Antithesis instrumentation improvements (#5213)
* Rename ASSERT to XRPL_ASSERT * Upgrade to Anthithesis SDK 0.4.4, and use new 0.4.4 features * automatic cast to bool, like assert * Add instrumentation workflow to verify build with instrumentation enabled
This commit is contained in:
@@ -28,37 +28,43 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#endif
|
||||
#include <antithesis_sdk.h>
|
||||
#else
|
||||
#define ALWAYS(cond, name, ...) assert((name) && (cond))
|
||||
#define ALWAYS_OR_UNREACHABLE(cond, name, ...) assert((name) && (cond))
|
||||
#define SOMETIMES(cond, name, ...)
|
||||
#define REACHABLE(name, ...)
|
||||
#define UNREACHABLE(name, ...) assert((name) && false)
|
||||
// Macros below are copied from antithesis_sdk.h and slightly simplified
|
||||
// The duplication is because Visual Studio 2019 cannot compile that header
|
||||
// even with the option -Zc:__cplusplus added.
|
||||
#define ALWAYS(cond, message, ...) assert((message) && (cond))
|
||||
#define ALWAYS_OR_UNREACHABLE(cond, message, ...) assert((message) && (cond))
|
||||
#define SOMETIMES(cond, message, ...)
|
||||
#define REACHABLE(message, ...)
|
||||
#define UNREACHABLE(message, ...) assert((message) && false)
|
||||
#endif
|
||||
|
||||
#define ASSERT ALWAYS_OR_UNREACHABLE
|
||||
#define XRPL_ASSERT ALWAYS_OR_UNREACHABLE
|
||||
|
||||
// How to use the instrumentation macros:
|
||||
//
|
||||
// ALWAYS if cond must be true and the line must be reached during fuzzing
|
||||
// ASSERT if cond must be true but the line might not be reached during fuzzing
|
||||
// REACHABLE if the line must be reached during fuzzing
|
||||
// SOMETIMES a hint for the fuzzer to try to make the cond true
|
||||
// UNREACHABLE if the line must not be reached (in fuzzing or in normal use)
|
||||
// * XRPL_ASSERT if cond must be true but the line might not be reached during
|
||||
// fuzzing. Same like `assert` in normal use.
|
||||
// * ALWAYS if cond must be true _and_ the line must be reached during fuzzing.
|
||||
// Same like `assert` in normal use.
|
||||
// * REACHABLE if the line must be reached during fuzzing
|
||||
// * SOMETIMES a hint for the fuzzer to try to make the cond true
|
||||
// * UNREACHABLE if the line must not be reached (in fuzzing or in normal use).
|
||||
// Same like `assert(false)` in normal use.
|
||||
//
|
||||
// NOTE: ASSERT has similar semantics as C assert macro, with minor differences:
|
||||
// * ASSERT must have an unique name (naming convention in CONTRIBUTING.md)
|
||||
// * the condition (which comes first) must be *implicitly* convertible to bool
|
||||
// * during fuzzing, the program will continue execution past a failed ASSERT
|
||||
// NOTE: XRPL_ASSERT has similar semantics as C `assert` macro, with only minor
|
||||
// differences:
|
||||
// * XRPL_ASSERT must have an unique name (naming convention in CONTRIBUTING.md)
|
||||
// * during fuzzing, the program will continue execution past failed XRPL_ASSERT
|
||||
//
|
||||
// We continue to use regular C assert inside unit tests and inside constexpr
|
||||
// We continue to use regular C `assert` inside unit tests and inside constexpr
|
||||
// functions.
|
||||
//
|
||||
// NOTE: UNREACHABLE does *not* have the same semantics as std::unreachable.
|
||||
// The program will continue execution past an UNREACHABLE in a Release build
|
||||
// and during fuzzing (similar to ASSERT).
|
||||
// and during fuzzing (similar to failed XRPL_ASSERT).
|
||||
// Also, the naming convention in UNREACHABLE is subtly different from other
|
||||
// instrumentation macros - its name describes the condition which was *not*
|
||||
// meant to happen, while name in other macros describe the condition that is
|
||||
// instrumentation macros - its name describes the condition which was _not_
|
||||
// meant to happen, while name in other macros describes the condition that is
|
||||
// meant to happen (e.g. as in "assert that this happens").
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user