@@ -548,6 +548,39 @@ void test_item_alloc_commit(void)
548
548
item_alloc_commit (false);
549
549
}
550
550
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
+
551
584
static uint32_t saturate_buffer_uneven (struct mpsc_pbuf_buffer * buffer ,
552
585
uint32_t len )
553
586
{
@@ -1041,6 +1074,7 @@ void test_main(void)
1041
1074
ztest_unit_test (test_benchmark_item_put_ext ),
1042
1075
ztest_unit_test (test_benchmark_item_put_data ),
1043
1076
ztest_unit_test (test_item_alloc_commit ),
1077
+ ztest_unit_test (test_item_max_alloc ),
1044
1078
ztest_unit_test (test_item_alloc_commit_saturate ),
1045
1079
ztest_unit_test (test_item_alloc_preemption ),
1046
1080
ztest_unit_test (test_overwrite ),
0 commit comments