From 5128241c661329948418ffd10072343e0cefe8c8 Mon Sep 17 00:00:00 2001 From: "Victor \"Nate\" Graf" Date: Wed, 28 Feb 2018 18:03:12 -0800 Subject: [PATCH] Create test for rundown events with EventPipe (#16667) --- tests/src/tracing/common/Assert.cs | 9 +++ tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs | 41 ------------ .../src/tracing/tracevalidation/rundown/Rundown.cs | 73 ++++++++++++++++++++++ .../rundown/rundown.csproj} | 5 +- 4 files changed, 84 insertions(+), 44 deletions(-) delete mode 100644 tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs create mode 100644 tests/src/tracing/tracevalidation/rundown/Rundown.cs rename tests/src/tracing/{eventpipesmoke/eventpipesmoke.csproj => tracevalidation/rundown/rundown.csproj} (90%) diff --git a/tests/src/tracing/common/Assert.cs b/tests/src/tracing/common/Assert.cs index fa47281..be147db 100755 --- a/tests/src/tracing/common/Assert.cs +++ b/tests/src/tracing/common/Assert.cs @@ -4,6 +4,15 @@ namespace Tracing.Tests.Common { public static class Assert { + public static void True(string name, bool condition) + { + if (!condition) + { + throw new Exception( + string.Format("Condition '{0}' is not true", name)); + } + } + public static void Equal(string name, T left, T right) where T : IEquatable { if (left == null && right != null) diff --git a/tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs b/tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs deleted file mode 100644 index 370d082..0000000 --- a/tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.IO; -using Tracing.Tests.Common; - -namespace Tracing.Tests -{ - class EventPipeSmoke - { - private static int allocIterations = 10000; - private static bool zapDisabled = Int32.Parse(Environment.GetEnvironmentVariable("COMPlus_ZapDisable") ?? "0") > 0; - private static int trivialSize = zapDisabled ? 64 * 1024 : 1 * 1024 * 1024; - - static int Main(string[] args) - { - using (var netPerfFile = NetPerfFile.Create(args)) - { - Console.WriteLine("\tStart: Enable tracing."); - TraceControl.EnableDefault(netPerfFile.Path); - Console.WriteLine("\tEnd: Enable tracing.\n"); - - Console.WriteLine("\tStart: Allocation."); - // Allocate for allocIterations iterations. - for (int i = 0; i < allocIterations; i++) - { - GC.KeepAlive(new object()); - } - Console.WriteLine("\tEnd: Allocation.\n"); - - Console.WriteLine("\tStart: Disable tracing."); - TraceControl.Disable(); - Console.WriteLine("\tEnd: Disable tracing.\n"); - - FileInfo outputMeta = new FileInfo(netPerfFile.Path); - Console.WriteLine("\tExpecting at least {0} bytes of data", trivialSize); - Console.WriteLine("\tCreated {0} bytes of data", outputMeta.Length); - - return outputMeta.Length > trivialSize ? 100 : 0; - } - } - } -} diff --git a/tests/src/tracing/tracevalidation/rundown/Rundown.cs b/tests/src/tracing/tracevalidation/rundown/Rundown.cs new file mode 100644 index 0000000..6b064d2 --- /dev/null +++ b/tests/src/tracing/tracevalidation/rundown/Rundown.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Tracing.Tests.Common; +using Microsoft.Diagnostics.Tracing; +using Microsoft.Diagnostics.Tracing.Parsers; +using Microsoft.Diagnostics.Tracing.Parsers.Clr; + +namespace Tracing.Tests +{ + public static class TraceValidationRundown + { + public static int Main(string[] args) + { + // Additional assemblies will be seen, but these are ones we must see + string[] AssembliesExpected = new string[] { + "rundown", // this assembly + "System.Runtime", + "Microsoft.Diagnostics.Tracing.TraceEvent", + "System.Diagnostics.Tracing", + "System.Private.CoreLib" + }; + + using (var netPerfFile = NetPerfFile.Create(args)) + { + Console.WriteLine("\tStart: Enable tracing."); + TraceControl.EnableDefault(netPerfFile.Path); + Console.WriteLine("\tEnd: Enable tracing.\n"); + + // Since all we care about is rundown, there is nothing to do there + + Console.WriteLine("\tStart: Disable tracing."); + TraceControl.Disable(); + Console.WriteLine("\tEnd: Disable tracing.\n"); + + Console.WriteLine("\tStart: Process the trace file."); + + var assembliesLoaded = new HashSet(); + int nonMatchingEventCount = 0; + + using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(netPerfFile.Path)) + { + var rundownParser = new ClrRundownTraceEventParser(trace); + + rundownParser.LoaderAssemblyDCStop += delegate(AssemblyLoadUnloadTraceData data) + { + var nameIndex = Array.IndexOf(data.PayloadNames, ("FullyQualifiedAssemblyName")); + if(nameIndex >= 0) + { + // Add the assembly name to a set to verify later + assembliesLoaded.Add(((string)data.PayloadValue(nameIndex)).Split(',')[0]); + } + else + { + nonMatchingEventCount++; + } + }; + + trace.Process(); + } + Console.WriteLine("\tEnd: Processing events from file.\n"); + + foreach (var name in AssembliesExpected) + { + Assert.True($"Assembly {name} in loaded assemblies", assembliesLoaded.Contains(name)); + } + Assert.Equal(nameof(nonMatchingEventCount), nonMatchingEventCount, 0); + } + + return 100; + } + } +} diff --git a/tests/src/tracing/eventpipesmoke/eventpipesmoke.csproj b/tests/src/tracing/tracevalidation/rundown/rundown.csproj similarity index 90% rename from tests/src/tracing/eventpipesmoke/eventpipesmoke.csproj rename to tests/src/tracing/tracevalidation/rundown/rundown.csproj index 4a1cd0c..c7314c8 100644 --- a/tests/src/tracing/eventpipesmoke/eventpipesmoke.csproj +++ b/tests/src/tracing/tracevalidation/rundown/rundown.csproj @@ -11,7 +11,6 @@ ..\..\ BuildAndRun $(DefineConstants);STATIC - true 0 @@ -23,8 +22,8 @@ - - + + \ No newline at end of file -- 2.7.4