From 5bb16452e9456ee0735fe824208f56946019fe63 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 15 Dec 2022 17:32:55 +0800 Subject: [PATCH] test/crimson: specialize fmt::formater<> for types to be formatted since fmt v9, fmt::formatter<> is not specialized for the types with operator<<(ostream&, ...) anymore. so we need to specialize it manually. in this change, fmt::formatter<> is specialized for some types to be formatted with fmtlib, so the tree can compile with fmt v9. Signed-off-by: Kefu Chai --- src/crimson/net/Interceptor.h | 64 +++++++++++-------- src/test/crimson/seastore/test_block.h | 1 + .../seastore/test_transaction_manager.cc | 12 ++-- src/test/crimson/test_messenger.cc | 9 +++ 4 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/crimson/net/Interceptor.h b/src/crimson/net/Interceptor.h index 8f34dc3b7c8..cc4dc77d6c5 100644 --- a/src/crimson/net/Interceptor.h +++ b/src/crimson/net/Interceptor.h @@ -42,15 +42,6 @@ enum class bp_action_t { STALL }; -inline std::ostream& operator<<(std::ostream& out, const bp_action_t& action) { - static const char *const action_names[] = {"CONTINUE", - "FAULT", - "BLOCK", - "STALL"}; - assert(static_cast(action) < std::size(action_names)); - return out << action_names[static_cast(action)]; -} - class socket_blocker { std::optional p_blocked; std::optional p_unblocked; @@ -122,11 +113,39 @@ struct Breakpoint { bool operator<(const Breakpoint& x) const { return bp < x.bp; } }; -inline std::ostream& operator<<(std::ostream& out, const Breakpoint& bp) { - if (auto custom_bp = std::get_if(&bp.bp)) { - return out << get_bp_name(*custom_bp); - } else { - auto tag_bp = std::get(bp.bp); +struct Interceptor { + socket_blocker blocker; + virtual ~Interceptor() {} + virtual void register_conn(Connection& conn) = 0; + virtual void register_conn_ready(Connection& conn) = 0; + virtual void register_conn_closed(Connection& conn) = 0; + virtual void register_conn_replaced(Connection& conn) = 0; + virtual bp_action_t intercept(Connection& conn, Breakpoint bp) = 0; +}; + +} // namespace crimson::net + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(const crimson::net::bp_action_t& action, FormatContext& ctx) const { + static const char *const action_names[] = {"CONTINUE", + "FAULT", + "BLOCK", + "STALL"}; + assert(static_cast(action) < std::size(action_names)); + return formatter::format(action_names[static_cast(action)], ctx); + } +}; + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(const crimson::net::Breakpoint& bp, FormatContext& ctx) const { + if (auto custom_bp = std::get_if(&bp.bp)) { + return formatter::format(crimson::net::get_bp_name(*custom_bp), ctx); + } + auto tag_bp = std::get(bp.bp); static const char *const tag_names[] = {"NONE", "HELLO", "AUTH_REQUEST", @@ -149,19 +168,8 @@ inline std::ostream& operator<<(std::ostream& out, const Breakpoint& bp) { "KEEPALIVE2_ACK", "ACK"}; assert(static_cast(tag_bp.tag) < std::size(tag_names)); - return out << tag_names[static_cast(tag_bp.tag)] - << (tag_bp.type == bp_type_t::WRITE ? "_WRITE" : "_READ"); + return fmt::format_to(ctx.out(), "{}_{}", + tag_names[static_cast(tag_bp.tag)], + tag_bp.type == crimson::net::bp_type_t::WRITE ? "WRITE" : "READ"); } -} - -struct Interceptor { - socket_blocker blocker; - virtual ~Interceptor() {} - virtual void register_conn(Connection& conn) = 0; - virtual void register_conn_ready(Connection& conn) = 0; - virtual void register_conn_closed(Connection& conn) = 0; - virtual void register_conn_replaced(Connection& conn) = 0; - virtual bp_action_t intercept(Connection& conn, Breakpoint bp) = 0; }; - -} // namespace crimson::net diff --git a/src/test/crimson/seastore/test_block.h b/src/test/crimson/seastore/test_block.h index 9324694d38e..26588321d09 100644 --- a/src/test/crimson/seastore/test_block.h +++ b/src/test/crimson/seastore/test_block.h @@ -148,6 +148,7 @@ struct test_block_mutator_t { WRITE_CLASS_DENC_BOUNDED(crimson::os::seastore::test_block_delta_t) #if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; template <> struct fmt::formatter : fmt::ostream_formatter {}; template <> struct fmt::formatter : fmt::ostream_formatter {}; #endif diff --git a/src/test/crimson/seastore/test_transaction_manager.cc b/src/test/crimson/seastore/test_transaction_manager.cc index 0e88aa35575..6c300519ae7 100644 --- a/src/test/crimson/seastore/test_transaction_manager.cc +++ b/src/test/crimson/seastore/test_transaction_manager.cc @@ -45,10 +45,14 @@ struct test_extent_record_t { } }; -std::ostream &operator<<(std::ostream &lhs, const test_extent_record_t &rhs) { - return lhs << "test_extent_record_t(" << rhs.desc - << ", refcount=" << rhs.refcount << ")"; -} +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(const test_extent_record_t& r, FormatContext& ctx) const { + return fmt::format_to(ctx.out(), "test_extent_record_t({}, refcount={})", + r.desc, r.refcount); + } +}; struct transaction_manager_test_t : public seastar_test_suite_t, diff --git a/src/test/crimson/test_messenger.cc b/src/test/crimson/test_messenger.cc index 6409ffa7990..b8cde621689 100644 --- a/src/test/crimson/test_messenger.cc +++ b/src/test/crimson/test_messenger.cc @@ -524,6 +524,15 @@ std::ostream& operator<<(std::ostream& out, const conn_state_t& state) { } } +} // anonymous namespace + +#if FMT_VERSION >= 90000 +template<> +struct fmt::formatter : fmt::ostream_formatter {}; +#endif + +namespace { + struct ConnResult { ConnectionRef conn; unsigned index; -- 2.39.5