Skip to content

Commit

Permalink
pw_multisink: Fix compiler warnings for tests
Browse files Browse the repository at this point in the history
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 🤖 <[email protected]>
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Reviewed-by: Anthony DiGirolamo <[email protected]>
Commit-Queue: Wyatt Hepler <[email protected]>
  • Loading branch information
255 authored and CQ Bot Account committed May 30, 2024
1 parent 694805f commit 2728737
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pw_multisink/multisink_threaded_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@

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<const StringBuffer<kEntryBufferSize>>;

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());
EXPECT_EQ(std::string_view(sent_messages[i]),
std::string_view(received_messages[i]));
}
}

} // namespace

// Static message pool to avoid recreating messages for every test and avoids
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -368,4 +371,6 @@ TEST_F(MultiSinkTest, OverflowMultisink) {
// can't control the order threads will operate.
}

#endif // PW_THREAD_JOINING_ENABLED

} // namespace pw::multisink

0 comments on commit 2728737

Please sign in to comment.