@@ -672,6 +672,93 @@ 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+ wc_UnloadStaticMemory(heap);
748+
749+ /* Success case. */
750+ heap = NULL;
751+ ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
752+ WOLFMEM_DEF_BUCKETS, sizeList, distList,
753+ staticMemory, (word32)sizeof(staticMemory),
754+ 0, 1),
755+ 0);
756+ wc_UnloadStaticMemory(heap);
757+ #endif /* WOLFSSL_STATIC_MEMORY */
758+ return EXPECT_RESULT();
759+ }
760+
761+
675762/*----------------------------------------------------------------------------*
676763 | Platform dependent function test
677764 *----------------------------------------------------------------------------*/
@@ -71571,6 +71658,8 @@ TEST_CASE testCases[] = {
7157171658
7157271659 TEST_DECL(test_wolfCrypt_Init),
7157371660
71661+ TEST_DECL(test_wc_LoadStaticMemory_ex),
71662+
7157471663 /* Locking with Compat Mutex */
7157571664 TEST_DECL(test_wc_SetMutexCb),
7157671665 TEST_DECL(test_wc_LockMutex_ex),
0 commit comments