diff --git a/rts/motoko-rts-tests/src/gc.rs b/rts/motoko-rts-tests/src/gc.rs index f681bdb92e0..33c6f4a6217 100644 --- a/rts/motoko-rts-tests/src/gc.rs +++ b/rts/motoko-rts-tests/src/gc.rs @@ -67,8 +67,9 @@ fn test_gc( ) { let heap = MotokoHeap::new(refs, roots, closure_table, gc); - // Check `check_dynamic_heap` sanity + // Check `create_dynamic_heap` sanity check_dynamic_heap( + false, // before gc refs, roots, closure_table, @@ -85,6 +86,7 @@ fn test_gc( let heap_ptr_offset = heap.heap_ptr_offset(); let closure_table_ptr_offset = heap.closure_table_ptr_offset(); check_dynamic_heap( + true, // after gc refs, roots, closure_table, @@ -98,14 +100,15 @@ fn test_gc( /// Check the dynamic heap: /// -/// - All and only reachable objects should be in the heap. Reachable objects are those in the -/// transitive closure of roots. +/// - All (and in post-gc mode, only) reachable objects should be in the heap. Reachable objects +/// are those in the transitive closure of roots. /// /// - Objects should point to right objects. E.g. if object with index X points to objects with /// indices Y and Z in the `objects` map, it should point to objects with indices Y and Z on the /// heap. /// fn check_dynamic_heap( + post_gc: bool, objects: &HashMap>, roots: &[ObjectIdx], closure_table: &[ObjectIdx], @@ -197,34 +200,37 @@ fn check_dynamic_heap( .copied() .collect(); - // Unreachable objects that we've seen in the heap - let extra_objects: Vec = seen_objects - .difference(&reachable_objects) - .copied() - .collect(); - let mut error_message = String::new(); if !missing_objects.is_empty() { write!( &mut error_message, - "Reachable objects missing in the post-GC heap: {:?}", + "Reachable objects missing in the {} heap: {:?}", + if post_gc { "post-gc" } else { "pre-gc" }, missing_objects, ) .unwrap(); } - if !extra_objects.is_empty() { - if !error_message.is_empty() { - error_message.push('\n'); - } + if post_gc { + // Unreachable objects that we've seen in the heap + let extra_objects: Vec = seen_objects + .difference(&reachable_objects) + .copied() + .collect(); - write!( - &mut error_message, - "Unreachable objects seen in the post-GC heap: {:?}", - extra_objects, - ) - .unwrap(); + if !extra_objects.is_empty() { + if !error_message.is_empty() { + error_message.push('\n'); + } + + write!( + &mut error_message, + "Unreachable objects seen in the post-GC heap: {:?}", + extra_objects, + ) + .unwrap(); + } } if !error_message.is_empty() {