From 5a7ceea52f7f73855fac1e8eac48b8db4d98fa96 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Tue, 12 Jun 2018 14:12:34 -0700 Subject: [PATCH] Fix GC KeepAlive test We need to determine that an object finalizer has not been run *before* the KeepAlive call. After the call, it is perfectly valid for the finalizer to be called, which can happen under GCStress. Commit migrated from https://github.com/dotnet/coreclr/commit/75623f73d1fd635ddace9d36ee28eeabe6030531 --- src/coreclr/tests/src/GC/API/GC/KeepAlive.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tests/src/GC/API/GC/KeepAlive.cs b/src/coreclr/tests/src/GC/API/GC/KeepAlive.cs index c5dd55d..badc54a 100644 --- a/src/coreclr/tests/src/GC/API/GC/KeepAlive.cs +++ b/src/coreclr/tests/src/GC/API/GC/KeepAlive.cs @@ -56,8 +56,10 @@ public class Test } - public static void RunTest() + public static bool RunTest() { + bool success = false; + Dummy obj = new Dummy(); RunTest2(); @@ -71,14 +73,18 @@ public class Test GC.Collect(); //} + success = (visited1 == false) && (visited2 == true); + GC.KeepAlive(obj); // will keep obj alive until this point + + return success; } public static int Main() { - RunTest(); + bool success = RunTest(); - if ((visited1 == false) && (visited2 == true)) + if (success) { Console.WriteLine("Test for KeepAlive() passed!"); return 100; @@ -86,8 +92,6 @@ public class Test else { Console.WriteLine("Test for KeepAlive() failed!"); - - return 1; } } -- 2.7.4