]> git.mdlowis.com Git - archive/atc.git/commitdiff
Added tests for heap.c
authorMike D. Lowis <mike.lowis@gentex.com>
Wed, 15 Apr 2015 20:10:49 +0000 (16:10 -0400)
committerMike D. Lowis <mike.lowis@gentex.com>
Wed, 15 Apr 2015 20:10:49 +0000 (16:10 -0400)
source/runtime/heap.c
tests/test_heap.c

index 0ebd15dc6eb211811baf5319d62b67a7c7f51ec5..ee2a34fc0fbdbf591ece3d2bf4f56494e6aaf583 100644 (file)
@@ -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;
index 350a7eef1417c660e7bee070c221f5cd7f1eb839..5c24af91e20fb66e96655d0fd17d05bd5d0ff6fb 100644 (file)
@@ -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);
+    }
 }