Skip to content

Commit

Permalink
Match unit tests on start of test name (XRPLF#4634)
Browse files Browse the repository at this point in the history
* For example, without this change, to run the TxQ tests, must specify
  `--unittest=TxQ1,TxQ2` on the command line. With this change, can use
  `--unittest=TxQ`, and both will be run.
* An exact match will prevent any further partial matching.
* This could have some side effects for different tests with a common
  name beginning. For example, NFToken, NFTokenBurn, NFTokenDir. This
  might be useful. If not, the shorter-named test(s) can be renamed. For
  example, NFToken to NFTokens.
* Split the NFToken, NFTokenBurn, and Offer test classes. Potentially speeds
  up parallel tests by a factor of 5.
  • Loading branch information
ximinez authored and ckeshava committed Sep 25, 2023
1 parent b162e1b commit 0f2f027
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 37 deletions.
8 changes: 8 additions & 0 deletions src/ripple/beast/unit_test/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ selector::operator()(suite_info const& s)
return ! s.manual();
}

// check start of name
if (s.name().starts_with(pat_) || s.full_name().starts_with(pat_))
{
// Don't change the mode so that the partial pattern can match
// more than once
return !s.manual();
}

return false;

case suite:
Expand Down
68 changes: 57 additions & 11 deletions src/test/app/NFTokenBurn_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace ripple {

class NFTokenBurn_test : public beast::unit_test::suite
class NFTokenBurn0_test : public beast::unit_test::suite
{
// Helper function that returns the owner count of an account root.
static std::uint32_t
Expand Down Expand Up @@ -786,22 +786,68 @@ class NFTokenBurn_test : public beast::unit_test::suite
testBurnTooManyOffers(features);
}

protected:
void
run(std::uint32_t instance, bool last = false)
{
using namespace test::jtx;
static FeatureBitset const all{supported_amendments()};
static FeatureBitset const fixNFTDir{fixNFTokenDirV1};

static std::array<FeatureBitset, 4> const feats{
all - fixNonFungibleTokensV1_2 - fixNFTDir - fixNFTokenRemint,
all - fixNonFungibleTokensV1_2 - fixNFTokenRemint,
all - fixNFTokenRemint,
all};

if (BEAST_EXPECT(instance < feats.size()))
{
testWithFeats(feats[instance]);
}
BEAST_EXPECT(!last || instance == feats.size() - 1);
}

public:
void
run() override
{
using namespace test::jtx;
FeatureBitset const all{supported_amendments()};
FeatureBitset const fixNFTDir{fixNFTokenDirV1};

testWithFeats(
all - fixNonFungibleTokensV1_2 - fixNFTDir - fixNFTokenRemint);
testWithFeats(all - fixNonFungibleTokensV1_2 - fixNFTokenRemint);
testWithFeats(all - fixNFTokenRemint);
testWithFeats(all);
run(0);
}
};

class NFTokenBurn1_test : public NFTokenBurn0_test
{
public:
void
run() override
{
NFTokenBurn0_test::run(1);
}
};

class NFTokenBurn2_test : public NFTokenBurn0_test
{
public:
void
run() override
{
NFTokenBurn0_test::run(2);
}
};

class NFTokenBurn3_test : public NFTokenBurn0_test
{
public:
void
run() override
{
NFTokenBurn0_test::run(3, true);
}
};

BEAST_DEFINE_TESTSUITE_PRIO(NFTokenBurn, tx, ripple, 3);
BEAST_DEFINE_TESTSUITE_PRIO(NFTokenBurn0, tx, ripple, 3);
BEAST_DEFINE_TESTSUITE_PRIO(NFTokenBurn1, tx, ripple, 3);
BEAST_DEFINE_TESTSUITE_PRIO(NFTokenBurn2, tx, ripple, 3);
BEAST_DEFINE_TESTSUITE_PRIO(NFTokenBurn3, tx, ripple, 3);

} // namespace ripple
75 changes: 63 additions & 12 deletions src/test/app/NFToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace ripple {

class NFToken_test : public beast::unit_test::suite
class NFToken0_test : public beast::unit_test::suite
{
FeatureBitset const disallowIncoming{featureDisallowIncoming};

Expand Down Expand Up @@ -6835,23 +6835,74 @@ class NFToken_test : public beast::unit_test::suite

public:
void
run() override
run(std::uint32_t instance, bool last = false)
{
using namespace test::jtx;
FeatureBitset const all{supported_amendments()};
FeatureBitset const fixNFTDir{fixNFTokenDirV1};
static FeatureBitset const all{supported_amendments()};
static FeatureBitset const fixNFTDir{fixNFTokenDirV1};

testWithFeats(
all - fixNFTDir - fixNonFungibleTokensV1_2 - fixNFTokenRemint);
testWithFeats(
static std::array<FeatureBitset, 5> const feats{
all - fixNFTDir - fixNonFungibleTokensV1_2 - fixNFTokenRemint,
all - disallowIncoming - fixNonFungibleTokensV1_2 -
fixNFTokenRemint);
testWithFeats(all - fixNonFungibleTokensV1_2 - fixNFTokenRemint);
testWithFeats(all - fixNFTokenRemint);
testWithFeats(all);
fixNFTokenRemint,
all - fixNonFungibleTokensV1_2 - fixNFTokenRemint,
all - fixNFTokenRemint,
all};

if (BEAST_EXPECT(instance < feats.size()))
{
testWithFeats(feats[instance]);
}
BEAST_EXPECT(!last || instance == feats.size() - 1);
}

void
run() override
{
run(0);
}
};

class NFToken1_test : public NFToken0_test
{
void
run() override
{
NFToken0_test::run(1);
}
};

class NFToken2_test : public NFToken0_test
{
void
run() override
{
NFToken0_test::run(2);
}
};

class NFToken3_test : public NFToken0_test
{
void
run() override
{
NFToken0_test::run(3);
}
};

class NFToken4_test : public NFToken0_test
{
void
run() override
{
NFToken0_test::run(4, true);
}
};

BEAST_DEFINE_TESTSUITE_PRIO(NFToken, tx, ripple, 2);
BEAST_DEFINE_TESTSUITE_PRIO(NFToken0, tx, ripple, 2);
BEAST_DEFINE_TESTSUITE_PRIO(NFToken1, tx, ripple, 2);
BEAST_DEFINE_TESTSUITE_PRIO(NFToken2, tx, ripple, 2);
BEAST_DEFINE_TESTSUITE_PRIO(NFToken3, tx, ripple, 2);
BEAST_DEFINE_TESTSUITE_PRIO(NFToken4, tx, ripple, 2);

} // namespace ripple
83 changes: 69 additions & 14 deletions src/test/app/Offer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace ripple {
namespace test {

class Offer_test : public beast::unit_test::suite
class Offer0_test : public beast::unit_test::suite
{
XRPAmount
reserve(jtx::Env& env, std::uint32_t count)
Expand Down Expand Up @@ -5145,25 +5145,76 @@ class Offer_test : public beast::unit_test::suite
}

void
run() override
run(std::uint32_t instance, bool last = false)
{
using namespace jtx;
FeatureBitset const all{supported_amendments()};
FeatureBitset const flowCross{featureFlowCross};
FeatureBitset const takerDryOffer{fixTakerDryOfferRemoval};
FeatureBitset const rmSmallIncreasedQOffers{fixRmSmallIncreasedQOffers};
FeatureBitset const immediateOfferKilled{featureImmediateOfferKilled};
static FeatureBitset const all{supported_amendments()};
static FeatureBitset const flowCross{featureFlowCross};
static FeatureBitset const takerDryOffer{fixTakerDryOfferRemoval};
static FeatureBitset const rmSmallIncreasedQOffers{
fixRmSmallIncreasedQOffers};
static FeatureBitset const immediateOfferKilled{
featureImmediateOfferKilled};

static std::array<FeatureBitset, 5> const feats{
all - takerDryOffer - immediateOfferKilled,
all - flowCross - takerDryOffer - immediateOfferKilled,
all - flowCross - immediateOfferKilled,
all - rmSmallIncreasedQOffers - immediateOfferKilled,
all};

if (BEAST_EXPECT(instance < feats.size()))
{
testAll(feats[instance]);
}
BEAST_EXPECT(!last || instance == feats.size() - 1);
}

testAll(all - takerDryOffer - immediateOfferKilled);
testAll(all - flowCross - takerDryOffer - immediateOfferKilled);
testAll(all - flowCross - immediateOfferKilled);
testAll(all - rmSmallIncreasedQOffers - immediateOfferKilled);
testAll(all);
void
run() override
{
run(0);
testFalseAssert();
}
};

class Offer_manual_test : public Offer_test
class Offer1_test : public Offer0_test
{
void
run() override
{
Offer0_test::run(1);
}
};

class Offer2_test : public Offer0_test
{
void
run() override
{
Offer0_test::run(2);
}
};

class Offer3_test : public Offer0_test
{
void
run() override
{
Offer0_test::run(3);
}
};

class Offer4_test : public Offer0_test
{
void
run() override
{
Offer0_test::run(4, true);
}
};

class Offer_manual_test : public Offer0_test
{
void
run() override
Expand All @@ -5184,7 +5235,11 @@ class Offer_manual_test : public Offer_test
}
};

BEAST_DEFINE_TESTSUITE_PRIO(Offer, tx, ripple, 4);
BEAST_DEFINE_TESTSUITE_PRIO(Offer0, tx, ripple, 4);
BEAST_DEFINE_TESTSUITE_PRIO(Offer1, tx, ripple, 4);
BEAST_DEFINE_TESTSUITE_PRIO(Offer2, tx, ripple, 4);
BEAST_DEFINE_TESTSUITE_PRIO(Offer3, tx, ripple, 4);
BEAST_DEFINE_TESTSUITE_PRIO(Offer4, tx, ripple, 4);
BEAST_DEFINE_TESTSUITE_MANUAL_PRIO(Offer_manual, tx, ripple, 20);

} // namespace test
Expand Down

0 comments on commit 0f2f027

Please sign in to comment.