From 272873750faa65275e9e1a0340289c2992692cfc Mon Sep 17 00:00:00 2001 From: Wyatt Hepler Date: Thu, 30 May 2024 20:48:57 +0000 Subject: [PATCH] pw_multisink: Fix compiler warnings for tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC warns about constructing a MultiBuf with an uninitialized array, so initialize it first. This isn't a problem in practice because the uninitialized data is never read. Also, ensure the test builds when joining is disabled, though none of the tests can run. Bug: b/343480404 Change-Id: I24a0157228621cae7ed85562929f65a663d7fc82 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/212051 Lint: Lint 🤖 Pigweed-Auto-Submit: Wyatt Hepler Presubmit-Verified: CQ Bot Account Reviewed-by: Anthony DiGirolamo Commit-Queue: Wyatt Hepler --- pw_multisink/multisink_threaded_test.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pw_multisink/multisink_threaded_test.cc b/pw_multisink/multisink_threaded_test.cc index 2f42ead887..3db78889c0 100644 --- a/pw_multisink/multisink_threaded_test.cc +++ b/pw_multisink/multisink_threaded_test.cc @@ -26,14 +26,16 @@ namespace pw::multisink { namespace { + constexpr size_t kEntryBufferSize = sizeof("message 000"); constexpr size_t kMaxMessageCount = 250; constexpr size_t kBufferSize = kMaxMessageCount * kEntryBufferSize; using MessageSpan = span>; -void CompareSentAndReceivedMessages(const MessageSpan& sent_messages, - const MessageSpan& received_messages) { +// This function is unused if joining is not supported. +[[maybe_unused]] void CompareSentAndReceivedMessages( + const MessageSpan& sent_messages, const MessageSpan& received_messages) { ASSERT_EQ(sent_messages.size(), received_messages.size()); for (size_t i = 0; i < sent_messages.size(); ++i) { ASSERT_EQ(sent_messages[i].size(), received_messages[i].size()); @@ -41,6 +43,7 @@ void CompareSentAndReceivedMessages(const MessageSpan& sent_messages, std::string_view(received_messages[i])); } } + } // namespace // Static message pool to avoid recreating messages for every test and avoids @@ -183,14 +186,14 @@ class LogWriterThread : public thread::ThreadCore { class MultiSinkTest : public ::testing::Test { protected: - MultiSinkTest() : multisink_(buffer_) {} + MultiSinkTest() : buffer_{}, multisink_(buffer_) {} std::byte buffer_[kBufferSize]; MultiSink multisink_; - - private: }; +#if PW_THREAD_JOINING_ENABLED + TEST_F(MultiSinkTest, SingleWriterSingleReader) { const uint32_t log_count = 100; const uint32_t drop_count = 5; @@ -368,4 +371,6 @@ TEST_F(MultiSinkTest, OverflowMultisink) { // can't control the order threads will operate. } +#endif // PW_THREAD_JOINING_ENABLED + } // namespace pw::multisink