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:
Bronek Kozicki
2024-12-16 22:48:33 +00:00
committed by tequ
parent 68705eee2c
commit 0fa542f672
223 changed files with 1461 additions and 1351 deletions

View File

@@ -53,7 +53,7 @@ toSTAmount(XRPAmount const& xrp)
inline STAmount
toSTAmount(XRPAmount const& xrp, Issue const& iss)
{
ASSERT(
XRPL_ASSERT(
isXRP(iss.account) && isXRP(iss.currency),
"ripple::toSTAmount : is XRP");
return toSTAmount(xrp);
@@ -74,14 +74,14 @@ template <>
inline IOUAmount
toAmount<IOUAmount>(STAmount const& amt)
{
ASSERT(
XRPL_ASSERT(
amt.mantissa() < std::numeric_limits<std::int64_t>::max(),
"ripple::toAmount<IOUAmount> : maximum mantissa");
bool const isNeg = amt.negative();
std::int64_t const sMant =
isNeg ? -std::int64_t(amt.mantissa()) : amt.mantissa();
ASSERT(!isXRP(amt), "ripple::toAmount<IOUAmount> : is not XRP");
XRPL_ASSERT(!isXRP(amt), "ripple::toAmount<IOUAmount> : is not XRP");
return IOUAmount(sMant, amt.exponent());
}
@@ -89,14 +89,14 @@ template <>
inline XRPAmount
toAmount<XRPAmount>(STAmount const& amt)
{
ASSERT(
XRPL_ASSERT(
amt.mantissa() < std::numeric_limits<std::int64_t>::max(),
"ripple::toAmount<XRPAmount> : maximum mantissa");
bool const isNeg = amt.negative();
std::int64_t const sMant =
isNeg ? -std::int64_t(amt.mantissa()) : amt.mantissa();
ASSERT(isXRP(amt), "ripple::toAmount<XRPAmount> : is XRP");
XRPL_ASSERT(isXRP(amt), "ripple::toAmount<XRPAmount> : is XRP");
return XRPAmount(sMant);
}

View File

@@ -151,7 +151,7 @@ public:
explicit FeatureBitset(base const& b) : base(b)
{
ASSERT(
XRPL_ASSERT(
b.count() == count(),
"ripple::FeatureBitset::FeatureBitset(base) : count match");
}
@@ -160,7 +160,7 @@ public:
explicit FeatureBitset(uint256 const& f, Fs&&... fs)
{
initFromFeatures(f, std::forward<Fs>(fs)...);
ASSERT(
XRPL_ASSERT(
count() == (sizeof...(fs) + 1),
"ripple::FeatureBitset::FeatureBitset(uint256) : count and "
"sizeof... do match");
@@ -171,7 +171,7 @@ public:
{
for (auto const& f : fs)
set(featureToBitsetIndex(f));
ASSERT(
XRPL_ASSERT(
fs.size() == count(),
"ripple::FeatureBitset::FeatureBitset(Container auto) : count and "
"size do match");

View File

@@ -426,12 +426,12 @@ mulDivU(Source1 value, Dest mul, Source2 div)
{
// split the asserts so if one hits, the user can tell which
// without a debugger.
ASSERT(
XRPL_ASSERT(
value.value() >= 0,
"ripple::feeunit::mulDivU : minimum value input");
ASSERT(
XRPL_ASSERT(
mul.value() >= 0, "ripple::feeunit::mulDivU : minimum mul input");
ASSERT(
XRPL_ASSERT(
div.value() >= 0, "ripple::feeunit::mulDivU : minimum div input");
return std::nullopt;
}

View File

@@ -245,7 +245,8 @@ page(uint256 const& root, std::uint64_t index = 0) noexcept;
inline Keylet
page(Keylet const& root, std::uint64_t index = 0) noexcept
{
ASSERT(root.type == ltDIR_NODE, "ripple::keylet::page : valid root type");
XRPL_ASSERT(
root.type == ltDIR_NODE, "ripple::keylet::page : valid root type");
return page(root.key, index);
}
/** @} */

View File

@@ -159,7 +159,7 @@ struct MultiApiJson
-> std::
invoke_result_t<Fn, decltype(json.val[0]), Version, Args&&...>
{
ASSERT(
XRPL_ASSERT(
valid(version) && index(version) >= 0 && index(version) < size,
"ripple::detail::MultiApiJson::operator<Args...>() : valid "
"version");
@@ -179,7 +179,7 @@ struct MultiApiJson
operator()(Json& json, Version version, Fn fn) const
-> std::invoke_result_t<Fn, decltype(json.val[0])>
{
ASSERT(
XRPL_ASSERT(
valid(version) && index(version) >= 0 && index(version) < size,
"ripple::detail::MultiApiJson::operator() : valid version");
return std::invoke(fn, json.val[index(version)]);

View File

@@ -298,7 +298,7 @@ public:
friend double
relativeDistance(Quality const& q1, Quality const& q2)
{
ASSERT(
XRPL_ASSERT(
q1.m_value > 0 && q2.m_value > 0,
"ripple::Quality::relativeDistance : minimum inputs");

View File

@@ -355,7 +355,7 @@ STAmount::STAmount(
, mIsNegative(negative)
{
// mValue is uint64, but needs to fit in the range of int64
ASSERT(
XRPL_ASSERT(
mValue <= std::numeric_limits<std::int64_t>::max(),
"ripple::STAmount::STAmount(SField, A, std::uint64_t, int, bool) : "
"maximum mantissa input");

View File

@@ -170,8 +170,9 @@ template <int Bits>
void
STBitString<Bits>::add(Serializer& s) const
{
ASSERT(getFName().isBinary(), "ripple::STBitString::add : field is binary");
ASSERT(
XRPL_ASSERT(
getFName().isBinary(), "ripple::STBitString::add : field is binary");
XRPL_ASSERT(
getFName().fieldType == getSType(),
"ripple::STBitString::add : field type match");
s.addBitString<Bits>(value_);

View File

@@ -110,8 +110,9 @@ template <typename Integer>
inline void
STInteger<Integer>::add(Serializer& s) const
{
ASSERT(getFName().isBinary(), "ripple::STInteger::add : field is binary");
ASSERT(
XRPL_ASSERT(
getFName().isBinary(), "ripple::STInteger::add : field is binary");
XRPL_ASSERT(
getFName().fieldType == getSType(),
"ripple::STInteger::add : field type match");
s.addInteger(value_);

View File

@@ -737,8 +737,7 @@ STObject::Proxy<T>::assign(U&& u)
t = dynamic_cast<T*>(st_->getPField(*f_, true));
else
t = dynamic_cast<T*>(st_->makeFieldPresent(*f_));
ASSERT(
t != nullptr, "ripple::STObject::Proxy::assign : type cast succeeded");
XRPL_ASSERT(t, "ripple::STObject::Proxy::assign : type cast succeeded");
*t = std::forward<U>(u);
}
@@ -1034,17 +1033,17 @@ STObject::at(TypedField<T> const& f) const
if (auto const u = dynamic_cast<T const*>(b))
return u->value();
ASSERT(
mType != nullptr,
XRPL_ASSERT(
mType,
"ripple::STObject::at(TypedField auto) : field template non-null");
ASSERT(
XRPL_ASSERT(
b->getSType() == STI_NOTPRESENT,
"ripple::STObject::at(TypedField auto) : type not present");
if (mType->style(f) == soeOPTIONAL)
Throw<STObject::FieldErr>("Missing optional field: " + f.getName());
ASSERT(
XRPL_ASSERT(
mType->style(f) == soeDEFAULT,
"ripple::STObject::at(TypedField auto) : template style is default");
@@ -1064,16 +1063,16 @@ STObject::at(OptionaledField<T> const& of) const
auto const u = dynamic_cast<T const*>(b);
if (!u)
{
ASSERT(
mType != nullptr,
XRPL_ASSERT(
mType,
"ripple::STObject::at(OptionaledField auto) : field template "
"non-null");
ASSERT(
XRPL_ASSERT(
b->getSType() == STI_NOTPRESENT,
"ripple::STObject::at(OptionaledField auto) : type not present");
if (mType->style(*of.f) == soeOPTIONAL)
return std::nullopt;
ASSERT(
XRPL_ASSERT(
mType->style(*of.f) == soeDEFAULT,
"ripple::STObject::at(OptionaledField auto) : template style is "
"default");

View File

@@ -257,7 +257,7 @@ inline STPathElement::STPathElement(
is_offer_ = false;
mAccountID = *account;
mType |= typeAccount;
ASSERT(
XRPL_ASSERT(
mAccountID != noAccount(),
"ripple::STPathElement::STPathElement : account is set");
}
@@ -272,7 +272,7 @@ inline STPathElement::STPathElement(
{
mIssuerID = *issuer;
mType |= typeIssuer;
ASSERT(
XRPL_ASSERT(
mIssuerID != noAccount(),
"ripple::STPathElement::STPathElement : issuer is set");
}

View File

@@ -176,7 +176,7 @@ STValidation::STValidation(
Throw<std::runtime_error>("Invalid signature in validation");
}
ASSERT(
XRPL_ASSERT(
nodeID_.isNonZero(),
"ripple::STValidation::STValidation(SerialIter) : nonzero node");
}
@@ -201,7 +201,7 @@ STValidation::STValidation(
, nodeID_(nodeID)
, seenTime_(signTime)
{
ASSERT(
XRPL_ASSERT(
nodeID_.isNonZero(),
"ripple::STValidation::STValidation(PublicKey, SecretKey) : nonzero "
"node");

View File

@@ -55,8 +55,8 @@ public:
if (size)
{
ASSERT(
data != nullptr,
XRPL_ASSERT(
data,
"ripple::Serializer::Serializer(void const*) : non-null input");
std::memcpy(mData.data(), data, size);
}
@@ -333,7 +333,8 @@ Serializer::addVL(Iter begin, Iter end, int len)
len -= begin->size();
#endif
}
ASSERT(len == 0, "ripple::Serializer::addVL : length matches distance");
XRPL_ASSERT(
len == 0, "ripple::Serializer::addVL : length matches distance");
return ret;
}

View File

@@ -155,7 +155,7 @@ public:
STAmount
getDeliveredAmount() const
{
ASSERT(
XRPL_ASSERT(
hasDeliveredAmount(),
"ripple::TxMeta::getDeliveredAmount : non-null delivered amount");
return *mDelivered;

View File

@@ -148,11 +148,11 @@ inplace_bigint_div_rem(std::span<uint64_t> numerator, std::uint64_t divisor)
unsigned __int128 const denom128 = denom;
unsigned __int128 const d = num / denom128;
unsigned __int128 const r = num - (denom128 * d);
ASSERT(
XRPL_ASSERT(
d >> 64 == 0,
"ripple::b58_fast::detail::inplace_bigint_div_rem::div_rem_64 : "
"valid division result");
ASSERT(
XRPL_ASSERT(
r >> 64 == 0,
"ripple::b58_fast::detail::inplace_bigint_div_rem::div_rem_64 : "
"valid remainder");
@@ -179,7 +179,7 @@ b58_10_to_b58_be(std::uint64_t input)
{
[[maybe_unused]] static constexpr std::uint64_t B_58_10 =
430804206899405824; // 58^10;
ASSERT(
XRPL_ASSERT(
input < B_58_10,
"ripple::b58_fast::detail::b58_10_to_b58_be : valid input");
constexpr std::size_t resultSize = 10;