diff --git a/include/seastar/testing/seastar_test.hh b/include/seastar/testing/seastar_test.hh index 51a3a960bef..415f7851f20 100644 --- a/include/seastar/testing/seastar_test.hh +++ b/include/seastar/testing/seastar_test.hh @@ -30,13 +30,23 @@ #include #include +#define SEASTAR_TEST_INVOKE(func, ...) func(__VA_ARGS__) + +namespace boost::unit_test::decorator { + +class collector_t; + +} + namespace seastar { namespace testing { class seastar_test { public: - seastar_test(const char* test_name, const char* test_file, int test_line, int expected_failures = 0); + seastar_test(const char* test_name, const char* test_file, int test_line); + seastar_test(const char* test_name, const char* test_file, int test_line, + boost::unit_test::decorator::collector_t& decorators); virtual ~seastar_test() {} static const std::string& get_name(); virtual future<> run_test_case() const = 0; diff --git a/include/seastar/testing/test_case.hh b/include/seastar/testing/test_case.hh index 7e682915867..ce61896563d 100644 --- a/include/seastar/testing/test_case.hh +++ b/include/seastar/testing/test_case.hh @@ -22,14 +22,35 @@ #pragma once +#include +#include +#include + #include #include -#define SEASTAR_TEST_CASE(name) \ - struct name : public seastar::testing::seastar_test { \ - using seastar::testing::seastar_test::seastar_test; \ - seastar::future<> run_test_case() const override; \ - }; \ - static const name name ## _instance(#name, __FILE__, __LINE__); /* NOLINT(cert-err58-cpp) */ \ +#define SEASTAR_TEST_CASE_WITH_DECO(name, decorators) \ + struct name : public seastar::testing::seastar_test { \ + using seastar::testing::seastar_test::seastar_test; \ + seastar::future<> run_test_case() const override; \ + }; \ + static const name name ## _instance( \ + #name, \ + __FILE__, \ + __LINE__, \ + decorators); /* NOLINT(cert-err58-cpp) */ \ seastar::future<> name::run_test_case() const + +#define SEASTAR_TEST_CASE_WITHOUT_DECO(name) \ + SEASTAR_TEST_CASE_WITH_DECO( \ + name, \ + boost::unit_test::decorator::collector_t::instance()) + +#define SEASTAR_TEST_CASE(...) \ + SEASTAR_TEST_INVOKE( \ + BOOST_PP_IIF( \ + BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 1), \ + SEASTAR_TEST_CASE_WITHOUT_DECO, \ + SEASTAR_TEST_CASE_WITH_DECO), \ + __VA_ARGS__) diff --git a/include/seastar/testing/thread_test_case.hh b/include/seastar/testing/thread_test_case.hh index 861f920851b..7f8cfde21a8 100644 --- a/include/seastar/testing/thread_test_case.hh +++ b/include/seastar/testing/thread_test_case.hh @@ -25,20 +25,38 @@ #include #include +#include +#include +#include + #include -#define SEASTAR_THREAD_TEST_CASE_EXPECTED_FAILURES(name, failures) \ - struct name : public seastar::testing::seastar_test { \ - using seastar::testing::seastar_test::seastar_test; \ - seastar::future<> run_test_case() const override { \ - return seastar::async([this] { \ - do_run_test_case(); \ - }); \ - } \ - void do_run_test_case() const; \ - }; \ - static const name name ## _instance(#name, __FILE__, __LINE__, failures); /* NOLINT(cert-err58-cpp) */ \ +#define SEASTAR_THREAD_TEST_CASE_WITH_DECO(name, decorators) \ + struct name : public seastar::testing::seastar_test { \ + using seastar::testing::seastar_test::seastar_test; \ + seastar::future<> run_test_case() const override { \ + return seastar::async([this] { \ + do_run_test_case(); \ + }); \ + } \ + void do_run_test_case() const; \ + }; \ + static const name name ## _instance( \ + #name, \ + __FILE__, \ + __LINE__, \ + decorators); /* NOLINT(cert-err58-cpp) */ \ void name::do_run_test_case() const -#define SEASTAR_THREAD_TEST_CASE(name) \ - SEASTAR_THREAD_TEST_CASE_EXPECTED_FAILURES(name, 0) +#define SEASTAR_THREAD_TEST_CASE_WITHOUT_DECO(name) \ + SEASTAR_THREAD_TEST_CASE_WITH_DECO( \ + name, \ + boost::unit_test::decorator::collector_t::instance()) + +#define SEASTAR_THREAD_TEST_CASE(...) \ + SEASTAR_TEST_INVOKE( \ + BOOST_PP_IIF( \ + BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 1), \ + SEASTAR_THREAD_TEST_CASE_WITHOUT_DECO, \ + SEASTAR_THREAD_TEST_CASE_WITH_DECO), \ + __VA_ARGS__) diff --git a/src/testing/seastar_test.cc b/src/testing/seastar_test.cc index f039a994e74..7edca5598a5 100644 --- a/src/testing/seastar_test.cc +++ b/src/testing/seastar_test.cc @@ -52,9 +52,16 @@ void seastar_test::run() { }); } -seastar_test::seastar_test(const char* test_name, const char* test_file, int test_line, int expected_failures) { + +seastar_test::seastar_test(const char* test_name, const char* test_file, int test_line) + : seastar_test(test_name, test_file, test_line, boost::unit_test::decorator::collector_t::instance()) {} + +seastar_test::seastar_test(const char* test_name, const char* test_file, int test_line, + boost::unit_test::decorator::collector_t& decorators) { auto test = boost::unit_test::make_test_case([this] { run(); }, test_name, test_file, test_line); - boost::unit_test::framework::current_auto_test_suite().add(test, expected_failures); + decorators.store_in(*test); + decorators.reset(); + boost::unit_test::framework::current_auto_test_suite().add(test); } std::string& seastar_test::get_name() { diff --git a/tests/unit/thread_test.cc b/tests/unit/thread_test.cc index 2aaff614572..3159499bc32 100644 --- a/tests/unit/thread_test.cc +++ b/tests/unit/thread_test.cc @@ -147,7 +147,7 @@ SEASTAR_TEST_CASE(test_asan_false_positive) { } #endif -SEASTAR_THREAD_TEST_CASE_EXPECTED_FAILURES(abc, 2) { +SEASTAR_THREAD_TEST_CASE(abc, *boost::unit_test::expected_failures(2)) { BOOST_TEST(false); BOOST_TEST(false); }