Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3772abb

Browse files
committedJul 1, 2024
Fix MultiBufferEncode test with pool allocator
1 parent 58572b3 commit 3772abb

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed
 

‎src/system/SystemPacketBuffer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ PacketBufferHandle PacketBufferHandle::New(size_t aAvailableSize, uint16_t aRese
581581

582582
if (lAllocSize > PacketBuffer::kMaxAllocSize)
583583
{
584-
ChipLogError(chipSystemLayer, "PacketBuffer: allocation exceeding buffer capacity limits.");
584+
ChipLogError(chipSystemLayer, "PacketBuffer: allocation exceeding buffer capacity limits: %lu > %lu",
585+
static_cast<unsigned long>(lAllocSize), static_cast<unsigned long>(PacketBuffer::kMaxAllocSize));
585586
return PacketBufferHandle();
586587
}
587588

‎src/system/tests/TestTLVPacketBufferBackingStore.cpp

+22-11
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,28 @@ TEST_F(TestTLVPacketBufferBackingStore, MultiBufferEncode)
162162
// Third entry is 1 control byte, 2 length bytes, 2000 bytes of data,
163163
// for a total of 2009 bytes.
164164
constexpr size_t totalSize = 2009;
165-
EXPECT_EQ(buffer->TotalLength(), totalSize);
166-
EXPECT_EQ(buffer->DataLength(), static_cast<size_t>(2));
167-
ASSERT_TRUE(buffer->HasChainedBuffer());
168-
auto nextBuffer = buffer->Next();
169-
EXPECT_EQ(nextBuffer->TotalLength(), totalSize - 2);
170-
EXPECT_EQ(nextBuffer->DataLength(), PacketBuffer::kMaxSizeWithoutReserve);
171-
ASSERT_TRUE(nextBuffer->HasChainedBuffer());
172-
nextBuffer = nextBuffer->Next();
173-
EXPECT_EQ(nextBuffer->TotalLength(), nextBuffer->DataLength());
174-
EXPECT_EQ(nextBuffer->DataLength(), totalSize - 2 - PacketBuffer::kMaxSizeWithoutReserve);
175-
ASSERT_FALSE(nextBuffer->HasChainedBuffer());
165+
#if CHIP_SYSTEM_PACKETBUFFER_FROM_LWIP_STANDARD_POOL || CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_POOL
166+
// In case of pool allocation, the buffer size is always the maximum size.
167+
constexpr size_t bufferSizes[] = { PacketBuffer::kMaxSizeWithoutReserve, totalSize - PacketBuffer::kMaxSizeWithoutReserve };
168+
#elif CHIP_SYSTEM_PACKETBUFFER_FROM_CHIP_HEAP
169+
constexpr size_t bufferSizes[] = { 2, PacketBuffer::kMaxSizeWithoutReserve,
170+
totalSize - 2 - PacketBuffer::kMaxSizeWithoutReserve };
171+
#else
172+
// Skipping the test for other configurations because the allocation method is unknown.
173+
GTEST_SKIP();
174+
#endif
175+
size_t checkedSize = 0;
176+
auto bufferTmp = buffer.Retain();
177+
for (const auto size : bufferSizes)
178+
{
179+
ASSERT_FALSE(bufferTmp.IsNull());
180+
EXPECT_EQ(bufferTmp->TotalLength(), totalSize - checkedSize);
181+
EXPECT_EQ(bufferTmp->DataLength(), size);
182+
bufferTmp = bufferTmp->Next();
183+
checkedSize += size;
184+
}
185+
// There should be no more buffers.
186+
ASSERT_TRUE(bufferTmp.IsNull());
176187

177188
// PacketBufferTLVReader cannot handle non-contiguous buffers, and our
178189
// buffers are too big to stick into a single packet buffer.

0 commit comments

Comments
 (0)
Please sign in to comment.