mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +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:
@@ -174,8 +174,8 @@ private:
|
||||
, m_repeat(repeat)
|
||||
, m_probe(probe)
|
||||
{
|
||||
ASSERT(
|
||||
m_probe != nullptr,
|
||||
XRPL_ASSERT(
|
||||
m_probe,
|
||||
"beast::io_latency_probe::sample_op::sample_op : non-null "
|
||||
"probe input");
|
||||
m_probe->addref();
|
||||
@@ -187,8 +187,8 @@ private:
|
||||
, m_repeat(from.m_repeat)
|
||||
, m_probe(from.m_probe)
|
||||
{
|
||||
ASSERT(
|
||||
m_probe != nullptr,
|
||||
XRPL_ASSERT(
|
||||
m_probe,
|
||||
"beast::io_latency_probe::sample_op::sample_op(sample_op&&) : "
|
||||
"non-null probe input");
|
||||
from.m_probe = nullptr;
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
void
|
||||
set(time_point const& when)
|
||||
{
|
||||
ASSERT(
|
||||
XRPL_ASSERT(
|
||||
!Clock::is_steady || when >= now_,
|
||||
"beast::manual_clock::set(time_point) : forward input");
|
||||
now_ = when;
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
void
|
||||
advance(std::chrono::duration<Rep, Period> const& elapsed)
|
||||
{
|
||||
ASSERT(
|
||||
XRPL_ASSERT(
|
||||
!Clock::is_steady || (now_ + elapsed) >= now_,
|
||||
"beast::manual_clock::advance(duration) : forward input");
|
||||
now_ += elapsed;
|
||||
|
||||
@@ -1330,7 +1330,7 @@ public:
|
||||
size_type
|
||||
bucket(Key const& k) const
|
||||
{
|
||||
ASSERT(
|
||||
XRPL_ASSERT(
|
||||
bucket_count() != 0,
|
||||
"beast::detail::aged_unordered_container::bucket : nonzero bucket "
|
||||
"count");
|
||||
@@ -1474,7 +1474,7 @@ private:
|
||||
{
|
||||
if (would_exceed(additional))
|
||||
m_buck.resize(size() + additional, m_cont);
|
||||
ASSERT(
|
||||
XRPL_ASSERT(
|
||||
load_factor() <= max_load_factor(),
|
||||
"beast::detail::aged_unordered_container::maybe_rehash : maximum "
|
||||
"load factor");
|
||||
|
||||
@@ -160,9 +160,8 @@ struct LexicalCast<Out, char const*>
|
||||
bool
|
||||
operator()(Out& out, char const* in) const
|
||||
{
|
||||
ASSERT(
|
||||
in != nullptr,
|
||||
"beast::detail::LexicalCast(char const*) : non-null input");
|
||||
XRPL_ASSERT(
|
||||
in, "beast::detail::LexicalCast(char const*) : non-null input");
|
||||
return LexicalCast<Out, std::string_view>()(out, in);
|
||||
}
|
||||
};
|
||||
@@ -177,9 +176,7 @@ struct LexicalCast<Out, char*>
|
||||
bool
|
||||
operator()(Out& out, char* in) const
|
||||
{
|
||||
ASSERT(
|
||||
in != nullptr,
|
||||
"beast::detail::LexicalCast(char*) : non-null input");
|
||||
XRPL_ASSERT(in, "beast::detail::LexicalCast(char*) : non-null input");
|
||||
return LexicalCast<Out, std::string_view>()(out, in);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -205,7 +205,7 @@ public:
|
||||
*/
|
||||
Stream(Sink& sink, Severity level) : m_sink(sink), m_level(level)
|
||||
{
|
||||
ASSERT(
|
||||
XRPL_ASSERT(
|
||||
m_level < severities::kDisabled,
|
||||
"beast::Journal::Stream::Stream : maximum level");
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -42,7 +42,7 @@ rngfill(void* buffer, std::size_t bytes, Generator& g)
|
||||
bytes -= sizeof(v);
|
||||
}
|
||||
|
||||
ASSERT(
|
||||
XRPL_ASSERT(
|
||||
bytes < sizeof(result_type), "beast::rngfill(void*) : maximum bytes");
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
Reference in New Issue
Block a user