Skip to content

Commit 60210a6

Browse files
nordic-krchcfriedt
authored andcommitted
tests: lib: mpsc_pbuf: Add test case for max packet allocation
Add test for validating max packet allocation. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 15db98a commit 60210a6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/lib/mpsc_pbuf/src/main.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,39 @@ void test_item_alloc_commit(void)
548548
item_alloc_commit(false);
549549
}
550550

551+
void item_max_alloc(bool overwrite)
552+
{
553+
struct mpsc_pbuf_buffer buffer;
554+
struct test_data_var *packet;
555+
556+
init(&buffer, overwrite, true);
557+
558+
/* First try to allocate the biggest possible packet. */
559+
for (int i = 0; i < 2; i++) {
560+
packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer,
561+
buffer.size - 1,
562+
K_NO_WAIT);
563+
zassert_true(packet != NULL, NULL);
564+
packet->hdr.len = buffer.size - 1;
565+
mpsc_pbuf_commit(&buffer, (union mpsc_pbuf_generic *)packet);
566+
567+
packet = (struct test_data_var *)mpsc_pbuf_claim(&buffer);
568+
mpsc_pbuf_free(&buffer, (union mpsc_pbuf_generic *)packet);
569+
}
570+
571+
/* Too big packet cannot be allocated. */
572+
packet = (struct test_data_var *)mpsc_pbuf_alloc(&buffer,
573+
buffer.size,
574+
K_NO_WAIT);
575+
zassert_true(packet == NULL, NULL);
576+
}
577+
578+
void test_item_max_alloc(void)
579+
{
580+
item_max_alloc(true);
581+
item_max_alloc(false);
582+
}
583+
551584
static uint32_t saturate_buffer_uneven(struct mpsc_pbuf_buffer *buffer,
552585
uint32_t len)
553586
{
@@ -1041,6 +1074,7 @@ void test_main(void)
10411074
ztest_unit_test(test_benchmark_item_put_ext),
10421075
ztest_unit_test(test_benchmark_item_put_data),
10431076
ztest_unit_test(test_item_alloc_commit),
1077+
ztest_unit_test(test_item_max_alloc),
10441078
ztest_unit_test(test_item_alloc_commit_saturate),
10451079
ztest_unit_test(test_item_alloc_preemption),
10461080
ztest_unit_test(test_overwrite),

0 commit comments

Comments
 (0)