Skip to content

Commit f6ae432

Browse files
committed
Generic Memory Pools
1. Add API test for function `wc_LoadStaticMemory_ex()`.
1 parent d239948 commit f6ae432

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

tests/api.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,91 @@ static int test_wolfCrypt_Cleanup(void)
672672
return EXPECT_RESULT();
673673
}
674674

675+
static int test_wc_LoadStaticMemory_ex(void)
676+
{
677+
EXPECT_DECLS;
678+
#ifdef WOLFSSL_STATIC_MEMORY
679+
byte staticMemory[440000];
680+
word32 sizeList[WOLFMEM_DEF_BUCKETS] = { WOLFMEM_BUCKETS };
681+
word32 distList[WOLFMEM_DEF_BUCKETS] = { WOLFMEM_DIST };
682+
WOLFSSL_HEAP_HINT* heap;
683+
684+
/* Pass in zero everything. */
685+
ExpectIntEQ(wc_LoadStaticMemory_ex(NULL, 0, NULL, NULL, NULL, 0, 0, 0),
686+
BAD_FUNC_ARG);
687+
688+
/* Set the heap pointer to NULL. */
689+
ExpectIntEQ(wc_LoadStaticMemory_ex(NULL,
690+
WOLFMEM_DEF_BUCKETS, sizeList, distList,
691+
staticMemory, (word32)sizeof(staticMemory),
692+
0, 1),
693+
BAD_FUNC_ARG);
694+
695+
/* Set other pointer values to NULL one at a time. */
696+
heap = NULL;
697+
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
698+
WOLFMEM_DEF_BUCKETS, NULL, distList,
699+
staticMemory, (word32)sizeof(staticMemory),
700+
0, 1),
701+
BAD_FUNC_ARG);
702+
heap = NULL;
703+
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
704+
WOLFMEM_DEF_BUCKETS, sizeList, NULL,
705+
staticMemory, (word32)sizeof(staticMemory),
706+
0, 1),
707+
BAD_FUNC_ARG);
708+
heap = NULL;
709+
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
710+
WOLFMEM_DEF_BUCKETS, sizeList, distList,
711+
NULL, (word32)sizeof(staticMemory),
712+
0, 1),
713+
BAD_FUNC_ARG);
714+
/* Set the size of the static buffer to 0. */
715+
heap = NULL;
716+
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
717+
WOLFMEM_DEF_BUCKETS, sizeList, distList,
718+
staticMemory, 0,
719+
0, 1),
720+
BUFFER_E);
721+
722+
/* Set the size of the static buffer to one less than minimum allowed. */
723+
heap = NULL;
724+
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
725+
WOLFMEM_DEF_BUCKETS, sizeList, distList,
726+
staticMemory,
727+
(word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)) - 1,
728+
0, 1),
729+
BUFFER_E);
730+
731+
/* Set the number of buckets to 1 too many allowed. */
732+
heap = NULL;
733+
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
734+
WOLFMEM_MAX_BUCKETS+1, sizeList, distList,
735+
staticMemory, (word32)sizeof(staticMemory),
736+
0, 1),
737+
BAD_FUNC_ARG);
738+
739+
/* Set the size of the static buffer to exactly the minimum size. */
740+
heap = NULL;
741+
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
742+
WOLFMEM_DEF_BUCKETS, sizeList, distList,
743+
staticMemory,
744+
(word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)),
745+
0, 1),
746+
0);
747+
748+
/* Success case. */
749+
heap = NULL;
750+
ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
751+
WOLFMEM_DEF_BUCKETS, sizeList, distList,
752+
staticMemory, (word32)sizeof(staticMemory),
753+
0, 1),
754+
0);
755+
#endif /* WOLFSSL_STATIC_MEMORY */
756+
return EXPECT_RESULT();
757+
}
758+
759+
675760
/*----------------------------------------------------------------------------*
676761
| Platform dependent function test
677762
*----------------------------------------------------------------------------*/
@@ -71565,6 +71650,8 @@ TEST_CASE testCases[] = {
7156571650

7156671651
TEST_DECL(test_wolfCrypt_Init),
7156771652

71653+
TEST_DECL(test_wc_LoadStaticMemory_ex),
71654+
7156871655
/* Locking with Compat Mutex */
7156971656
TEST_DECL(test_wc_SetMutexCb),
7157071657
TEST_DECL(test_wc_LockMutex_ex),

0 commit comments

Comments
 (0)