-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] Migrate zmalloc.c unit tests to new test framework. (#493)
This is the actual PR which is created to migrate all tests related to zmalloc into new test framework as part of the parent issue #428. Signed-off-by: Karthick Ariyaratnam <[email protected]> Signed-off-by: adetunjii <[email protected]>
- Loading branch information
Showing
5 changed files
with
58 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "../zmalloc.h" | ||
#include "test_help.h" | ||
|
||
int test_zmallocInitialUsedMemory(int argc, char **argv, int flags) { | ||
UNUSED(argc); | ||
UNUSED(argv); | ||
UNUSED(flags); | ||
|
||
TEST_ASSERT(zmalloc_used_memory() == 0); | ||
|
||
return 0; | ||
} | ||
|
||
int test_zmallocAllocReallocCallocAndFree(int argc, char **argv, int flags) { | ||
UNUSED(argc); | ||
UNUSED(argv); | ||
UNUSED(flags); | ||
|
||
void *ptr, *ptr2; | ||
|
||
ptr = zmalloc(123); | ||
TEST_PRINT_INFO("Allocated 123 bytes; used: %zu\n", zmalloc_used_memory()); | ||
|
||
ptr = zrealloc(ptr, 456); | ||
TEST_PRINT_INFO("Reallocated to 456 bytes; used: %zu\n", zmalloc_used_memory()); | ||
|
||
ptr2 = zcalloc(123); | ||
TEST_PRINT_INFO("Callocated 123 bytes; used: %zu\n", zmalloc_used_memory()); | ||
|
||
zfree(ptr); | ||
zfree(ptr2); | ||
TEST_PRINT_INFO("Freed pointers; used: %zu\n", zmalloc_used_memory()); | ||
|
||
TEST_ASSERT(zmalloc_used_memory() == 0); | ||
|
||
return 0; | ||
} | ||
|
||
int test_zmallocAllocZeroByteAndFree(int argc, char **argv, int flags) { | ||
UNUSED(argc); | ||
UNUSED(argv); | ||
UNUSED(flags); | ||
|
||
void *ptr; | ||
|
||
ptr = zmalloc(0); | ||
TEST_PRINT_INFO("Allocated 0 bytes; used: %zu\n", zmalloc_used_memory()); | ||
zfree(ptr); | ||
|
||
TEST_ASSERT(zmalloc_used_memory() == 0); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters