From: Mike D. Lowis Date: Wed, 15 Apr 2015 20:10:49 +0000 (-0400) Subject: Added tests for heap.c X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=541c6d3895faec025dde8a3c14eadb44d40fdc98;p=archive%2Fatc.git Added tests for heap.c --- diff --git a/source/runtime/heap.c b/source/runtime/heap.c index 0ebd15d..ee2a34f 100644 --- a/source/runtime/heap.c +++ b/source/runtime/heap.c @@ -103,7 +103,7 @@ void heap_finish_collection(heap_t* heap) { /* All blocks remaining in the greylist now are unreachable so free them */ splaytree_destroy(heap->greylist); - /* Now iterate over the sub heaps and make sure the full/available lists are in order */ + /* Now iterate over the sub heaps and make sure the full/available lists are correct */ for (unsigned int i = 0; i < NUM_HEAP_STACKS; i++) { segment_t* prev = NULL; segment_t* curr = heap->heaps[i].full; diff --git a/tests/test_heap.c b/tests/test_heap.c index 350a7ee..5c24af9 100644 --- a/tests/test_heap.c +++ b/tests/test_heap.c @@ -47,4 +47,26 @@ TEST_SUITE(Heap) { CHECK(NULL != heap->blocks->root->value); heap_destroy(heap); } + + /* Verify: heap_start_collection + *************************************************************************/ + TEST(Verify_start_collection_prepares_the_heap_for_garbage_collection) { + heap_t* heap = heap_create(); + splaytree_t* blocks = heap->blocks; + heap_start_collection(heap); + CHECK(heap->blocks != blocks); + CHECK(heap->greylist == blocks); + heap_destroy(heap); + } + + /* Verify: heap_finish_collection + *************************************************************************/ + TEST(Verify_finish_collection_cleans_up_after_garbage_collection) { + heap_t* heap = heap_create(); + splaytree_t* blocks = heap->blocks; + heap_start_collection(heap); + heap_finish_collection(heap); + CHECK(blocks != heap->blocks); + heap_destroy(heap); + } }