From f450fb45fd33bac9d6accad1b5cd657422946259 Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Mon, 17 Jul 2023 14:51:54 +0100 Subject: Adjust some tests which were relying on non-deterministic behavior. Test: gtests Bug: 291273982 Change-Id: Ie8dbfa67c908df2209265680a904e21d77b3798d --- runtime/gc/heap_test.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'runtime/gc/heap_test.cc') diff --git a/runtime/gc/heap_test.cc b/runtime/gc/heap_test.cc index b569241bdc..57358e6ef1 100644 --- a/runtime/gc/heap_test.cc +++ b/runtime/gc/heap_test.cc @@ -111,6 +111,7 @@ bool AnyIsFalse(bool x, bool y) { return !x || !y; } TEST_F(HeapTest, GCMetrics) { // Allocate a few string objects (to be collected), then trigger garbage // collection, and check that GC metrics are updated (where applicable). + Heap* heap = Runtime::Current()->GetHeap(); { constexpr const size_t kNumObj = 128; ScopedObjectAccess soa(Thread::Current()); @@ -119,8 +120,10 @@ TEST_F(HeapTest, GCMetrics) { Handle string [[maybe_unused]] ( hs.NewHandle(mirror::String::AllocFromModifiedUtf8(soa.Self(), "test"))); } + // Do one GC while the temporary objects cannot be collected. This GC will age the objects,and + // ensure that the GC at line 127 does scan the objects. + heap->CollectGarbage(/* clear_soft_references= */ false); } - Heap* heap = Runtime::Current()->GetHeap(); heap->CollectGarbage(/* clear_soft_references= */ false); // ART Metrics. -- cgit v1.2.3-59-g8ed1b