From 0f2f0274745cfcd28f2af641f0893c399c635ca8 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Thu, 14 Sep 2023 16:19:15 -0400 Subject: [PATCH] Match unit tests on start of test name (#4634) * 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. --- src/ripple/beast/unit_test/match.hpp | 8 +++ src/test/app/NFTokenBurn_test.cpp | 68 +++++++++++++++++++---- src/test/app/NFToken_test.cpp | 75 +++++++++++++++++++++---- src/test/app/Offer_test.cpp | 83 +++++++++++++++++++++++----- 4 files changed, 197 insertions(+), 37 deletions(-) diff --git a/src/ripple/beast/unit_test/match.hpp b/src/ripple/beast/unit_test/match.hpp index 859eb1f71ca..689b189567d 100644 --- a/src/ripple/beast/unit_test/match.hpp +++ b/src/ripple/beast/unit_test/match.hpp @@ -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: diff --git a/src/test/app/NFTokenBurn_test.cpp b/src/test/app/NFTokenBurn_test.cpp index 75c32385acf..2bd7074b2a8 100644 --- a/src/test/app/NFTokenBurn_test.cpp +++ b/src/test/app/NFTokenBurn_test.cpp @@ -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 @@ -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 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 diff --git a/src/test/app/NFToken_test.cpp b/src/test/app/NFToken_test.cpp index 1f3636e4e39..0539d2abd93 100644 --- a/src/test/app/NFToken_test.cpp +++ b/src/test/app/NFToken_test.cpp @@ -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}; @@ -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 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 diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index 1c8e544af30..fbf9cc890dc 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -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) @@ -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 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 @@ -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