Add 3 EventPipe tests about GC (dotnet/coreclr#26429)
authorjiangzeng01 <49379637+jiangzeng01@users.noreply.github.com>
Thu, 5 Sep 2019 16:29:30 +0000 (00:29 +0800)
committerJohn Salem <josalem@microsoft.com>
Thu, 5 Sep 2019 16:29:30 +0000 (09:29 -0700)
* Add 3 EventPipe tests about GC

* Set eventpipe tests priority to 1

Commit migrated from https://github.com/dotnet/coreclr/commit/363e42ca38a3846d18c0c07bdb71594fdba235d2

src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.cs
src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/ExceptionThrown_V1.csproj
src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCEvents.cs [new file with mode: 0644]
src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCEvents.csproj [moved from src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCStartStop.csproj with 85% similarity]
src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCFinalizers.cs [moved from src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCStartStop.cs with 69% similarity]
src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj [new file with mode: 0644]

index fe0813f..4051095 100644 (file)
@@ -17,6 +17,7 @@ namespace Tracing.Tests.ExceptionThrown_V1
             var providers = new List<Provider>()
             {
                 new Provider("Microsoft-DotNETCore-SampleProfiler"),
+                //ExceptionKeyword (0x8000): 0b1000_0000_0000_0000
                 new Provider("Microsoft-Windows-DotNETRuntime", 0b1000_0000_0000_0000, EventLevel.Warning)
             };
 
index 07cb036..4eb4886 100644 (file)
@@ -5,7 +5,7 @@
     <CLRTestKind>BuildAndRun</CLRTestKind>
     <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <CLRTestPriority>0</CLRTestPriority>
+    <CLRTestPriority>1</CLRTestPriority>
     <UnloadabilityIncompatible>true</UnloadabilityIncompatible>
   </PropertyGroup>
   <ItemGroup>
diff --git a/src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCEvents.cs b/src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCEvents.cs
new file mode 100644 (file)
index 0000000..adb9eec
--- /dev/null
@@ -0,0 +1,87 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics.Tracing;
+using System.Collections.Generic;
+using Microsoft.Diagnostics.Tools.RuntimeClient;
+using Microsoft.Diagnostics.Tracing;
+using Tracing.Tests.Common;
+
+namespace Tracing.Tests.GCEvents
+{
+    public class ProviderValidation
+    {
+        public static int Main(string[] args)
+        {
+            var providers = new List<Provider>()
+            {
+                new Provider("Microsoft-DotNETCore-SampleProfiler"),
+                //GCKeyword (0x1): 0b1
+                new Provider("Microsoft-Windows-DotNETRuntime", 0b1, EventLevel.Informational)
+            };
+            
+            var configuration = new SessionConfiguration(circularBufferSizeMB: 1024, format: EventPipeSerializationFormat.NetTrace,  providers: providers);
+            return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, configuration, _DoesTraceContainEvents);
+        }
+
+        private static Dictionary<string, ExpectedEventCount> _expectedEventCounts = new Dictionary<string, ExpectedEventCount>()
+        {
+            { "Microsoft-Windows-DotNETRuntime", -1 },
+            { "Microsoft-Windows-DotNETRuntimeRundown", -1 },
+            { "Microsoft-DotNETCore-SampleProfiler", -1 }
+        };
+
+        private static Action _eventGeneratingAction = () => 
+        {
+            for (int i = 0; i < 1000; i++)
+            {
+                if (i % 100 == 0)
+                    Logger.logger.Log($"Called GC.Collect() {i} times...");
+                ProviderValidation providerValidation = new ProviderValidation();
+                providerValidation = null;
+                GC.Collect();
+            }
+        };
+
+        private static Func<EventPipeEventSource, Func<int>> _DoesTraceContainEvents = (source) => 
+        {
+            int GCStartEvents = 0;
+            int GCEndEvents = 0;
+            source.Clr.GCStart += (eventData) => GCStartEvents += 1;
+            source.Clr.GCStop += (eventData) => GCEndEvents += 1;
+
+            int GCRestartEEStartEvents = 0;
+            int GCRestartEEStopEvents = 0;           
+            source.Clr.GCRestartEEStart += (eventData) => GCRestartEEStartEvents += 1;
+            source.Clr.GCRestartEEStop += (eventData) => GCRestartEEStopEvents += 1; 
+
+            int GCSuspendEEEvents = 0;
+            int GCSuspendEEEndEvents = 0;
+            source.Clr.GCSuspendEEStart += (eventData) => GCSuspendEEEvents += 1;
+            source.Clr.GCSuspendEEStop += (eventData) => GCSuspendEEEndEvents += 1;
+
+            return () => {
+                Logger.logger.Log("Event counts validation");
+
+                Logger.logger.Log("GCStartEvents: " + GCStartEvents);
+                Logger.logger.Log("GCEndEvents: " + GCEndEvents);
+                bool GCStartStopResult = GCStartEvents >= 1000 && GCEndEvents >= 1000 && GCStartEvents == GCEndEvents;
+                Logger.logger.Log("GCStartStopResult check: " + GCStartStopResult);
+
+                Logger.logger.Log("GCRestartEEStartEvents: " + GCRestartEEStartEvents);
+                Logger.logger.Log("GCRestartEEStopEvents: " + GCRestartEEStopEvents);
+                bool GCRestartEEStartStopResult = GCRestartEEStartEvents >= 1000 && GCRestartEEStopEvents >= 1000;
+                Logger.logger.Log("GCRestartEEStartStopResult check: " + GCRestartEEStartStopResult);
+
+                Logger.logger.Log("GCSuspendEEEvents: " + GCSuspendEEEvents);
+                Logger.logger.Log("GCSuspendEEEndEvents: " + GCSuspendEEEndEvents);
+                bool GCSuspendEEStartStopResult = GCSuspendEEEvents >= 1000 && GCSuspendEEEndEvents >= 1000;
+                Logger.logger.Log("GCSuspendEEStartStopResult check: " + GCSuspendEEStartStopResult);
+
+                return GCStartStopResult && GCRestartEEStartStopResult && GCSuspendEEStartStopResult ? 100 : -1;
+            };
+        };
+    }
+}
\ No newline at end of file
@@ -5,11 +5,11 @@
     <CLRTestKind>BuildAndRun</CLRTestKind>
     <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <CLRTestPriority>0</CLRTestPriority>
+    <CLRTestPriority>1</CLRTestPriority>
     <UnloadabilityIncompatible>true</UnloadabilityIncompatible>
   </PropertyGroup>
   <ItemGroup>
-    <Compile Include="GCStartStop.cs" />
+    <Compile Include="GCEvents.cs" />
     <ProjectReference Include="../common/common.csproj" />
   </ItemGroup>
 </Project>
@@ -9,7 +9,7 @@ using Microsoft.Diagnostics.Tools.RuntimeClient;
 using Microsoft.Diagnostics.Tracing;
 using Tracing.Tests.Common;
 
-namespace Tracing.Tests.GCStartStop
+namespace Tracing.Tests.GCFinalizers
 {
     public class ProviderValidation
     {
@@ -18,6 +18,7 @@ namespace Tracing.Tests.GCStartStop
             var providers = new List<Provider>()
             {
                 new Provider("Microsoft-DotNETCore-SampleProfiler"),
+                //GCKeyword (0x1): 0b1
                 new Provider("Microsoft-Windows-DotNETRuntime", 0b1, EventLevel.Informational)
             };
             
@@ -37,24 +38,27 @@ namespace Tracing.Tests.GCStartStop
             for (int i = 0; i < 1000; i++)
             {
                 if (i % 100 == 0)
-                    Logger.logger.Log($"Called GC.Collect() {i} times...");
+                    Logger.logger.Log($"Called GC.WaitForPendingFinalizers() {i} times...");
                 ProviderValidation providerValidation = new ProviderValidation();
                 providerValidation = null;
-                GC.Collect();
+                GC.WaitForPendingFinalizers();
             }
+            GC.Collect();
+            GC.WaitForPendingFinalizers();
+            GC.Collect();
         };
 
         private static Func<EventPipeEventSource, Func<int>> _DoesTraceContainEvents = (source) => 
         {
-            int GCStartEvents = 0;
-            int GCEndEvents = 0;
-            source.Clr.GCStart += (eventData) => GCStartEvents += 1;
-            source.Clr.GCStop += (eventData) => GCEndEvents += 1;
+            int GCFinalizersEndEvents = 0;
+            source.Clr.GCFinalizersStop += (eventData) => GCFinalizersEndEvents += 1;
+            int GCFinalizersStartEvents = 0;
+            source.Clr.GCFinalizersStart += (eventData) => GCFinalizersStartEvents += 1;
             return () => {
                 Logger.logger.Log("Event counts validation");
-                Logger.logger.Log("GCStartEvents: " + GCStartEvents);
-                Logger.logger.Log("GCEndEvents: " + GCEndEvents);
-                return GCStartEvents >= 1000 && GCEndEvents >= 1000 && GCStartEvents == GCEndEvents ? 100 : -1;
+                Logger.logger.Log("GCFinalizersEndEvents: " + GCFinalizersEndEvents);
+                Logger.logger.Log("GCFinalizersStartEvents: " + GCFinalizersStartEvents);
+                return GCFinalizersEndEvents >= 1000 && GCFinalizersStartEvents >= 1000 ? 100 : -1;
             };
         };
     }
diff --git a/src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj b/src/coreclr/tests/src/tracing/eventpipe/eventsvalidation/GCFinalizers.csproj
new file mode 100644 (file)
index 0000000..194a724
--- /dev/null
@@ -0,0 +1,15 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
+    <OutputType>exe</OutputType>
+    <CLRTestKind>BuildAndRun</CLRTestKind>
+    <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <CLRTestPriority>1</CLRTestPriority>
+    <UnloadabilityIncompatible>true</UnloadabilityIncompatible>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="GCFinalizers.cs" />
+    <ProjectReference Include="../common/common.csproj" />
+  </ItemGroup>
+</Project>