summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Au <andrewau@microsoft.com>2019-03-01 10:12:48 -0800
committerAndrew Au <cshung@gmail.com>2019-03-11 19:18:11 -0700
commit18b6abc2c56adacb27b165491fc0ad757c24abdb (patch)
tree460baff71c02df228562aa4611832c50c443cf61 /tests
parentcefce5b5b82bb31600824935c585225aed059271 (diff)
downloadcoreclr-18b6abc2c56adacb27b165491fc0ad757c24abdb.tar.gz
coreclr-18b6abc2c56adacb27b165491fc0ad757c24abdb.tar.bz2
coreclr-18b6abc2c56adacb27b165491fc0ad757c24abdb.zip
Fix issue 21089 (Add tests for the `EventPipe support for "Parameters"` feature.)
Diffstat (limited to 'tests')
-rw-r--r--tests/src/tracing/common/AbstractTraceTest.cs148
-rw-r--r--tests/src/tracing/common/common.csproj1
-rw-r--r--tests/src/tracing/keyword/TwoKeywords/TwoKeywords.cs52
-rw-r--r--tests/src/tracing/keyword/TwoKeywords/TwoKeywords.csproj33
-rw-r--r--tests/src/tracing/tracecontrol/TraceControl.cs112
5 files changed, 261 insertions, 85 deletions
diff --git a/tests/src/tracing/common/AbstractTraceTest.cs b/tests/src/tracing/common/AbstractTraceTest.cs
new file mode 100644
index 0000000000..26b7299ff1
--- /dev/null
+++ b/tests/src/tracing/common/AbstractTraceTest.cs
@@ -0,0 +1,148 @@
+// 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.IO;
+using System.Reflection;
+using System.Threading;
+using System.Threading.Tasks;
+using Tracing.Tests.Common;
+
+using Microsoft.Diagnostics.Tracing;
+using Microsoft.Diagnostics.Tracing.Parsers.Clr;
+
+namespace Tracing.Tests
+{
+ [EventSource(Name = "My-Simple-Event-Source")]
+ public sealed class MySimpleEventSource : EventSource
+ {
+ private AbstractTraceTest abstractTraceTest;
+
+ [NonEvent]
+ private void OnEventCommand(object sender, EventCommandEventArgs command)
+ {
+ this.abstractTraceTest.OnEventCommand(sender, command);
+ }
+
+ public MySimpleEventSource(AbstractTraceTest abstractTraceTest)
+ {
+ this.abstractTraceTest = abstractTraceTest;
+ this.EventCommandExecuted += this.OnEventCommand;
+ }
+
+ public void Request(string message)
+ {
+ WriteEvent(1, message);
+ }
+ }
+
+ public abstract class AbstractTraceTest
+ {
+ protected abstract string GetConfigFileContents();
+
+ public virtual void OnEventCommand(object sender, EventCommandEventArgs command)
+ {
+ }
+
+ protected virtual void InstallValidationCallbacks(TraceEventDispatcher trace)
+ {
+
+ }
+
+ protected virtual bool Pass()
+ {
+ return true;
+ }
+
+ private static readonly TimeSpan TimeIntervalToReadConfigFile = new TimeSpan(0, 0, 25);
+
+ private const int BytesInOneMB = 1024 * 1024;
+
+ /// <summary>
+ /// This test collects a trace of itself and then performs some basic validation on the trace.
+ /// </summary>
+ public int Execute()
+ {
+ MySimpleEventSource MySimpleEventSource = new MySimpleEventSource(this);
+
+ // Logging before tracing is enable - this should be ignored
+ MySimpleEventSource.Request("Test 1");
+
+ // Calculate the path to the config file.
+ string configFileName = Assembly.GetEntryAssembly().GetName().Name + ".eventpipeconfig";
+ string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFileName);
+ Console.WriteLine("Calculated config file path: " + configFilePath);
+
+ // Write the config file to disk.
+ File.WriteAllText(configFilePath, GetConfigFileContents());
+ Console.WriteLine("Wrote contents of config file.");
+
+ // Wait few seconds to ensure that tracing has started.
+ Console.WriteLine($"Waiting {TimeIntervalToReadConfigFile.TotalSeconds} seconds for the config file to be picked up by the next poll operation.");
+ Thread.Sleep(TimeIntervalToReadConfigFile);
+
+ // Do some work that we can look for in the trace.
+ Console.WriteLine("Do some work that will be captured by the trace.");
+ GC.Collect(2, GCCollectionMode.Forced);
+
+ // Logging while tracing is enabled - this should NOT be ignored
+ MySimpleEventSource.Request("Test 2");
+
+ Console.WriteLine("Done with the work.");
+
+ // Delete the config file to start tracing.
+ File.Delete(configFilePath);
+ Console.WriteLine("Deleted the config file.");
+
+ // Build the full path to the trace file.
+ string[] traceFiles = Directory.GetFiles(".", "*.netperf", SearchOption.TopDirectoryOnly);
+ Assert.Equal("traceFiles.Length == 1", traceFiles.Length, 1);
+ string traceFilePath = traceFiles[0];
+
+ // Poll the file system and wait for the trace file to be written.
+ Console.WriteLine("Wait for the config file deletion to be picked up and for the trace file to be written.");
+
+ // Wait for 1 second, which is the poll time when tracing is enabled.
+ Thread.Sleep(TimeSpan.FromSeconds(1));
+
+ // Logging after tracing is disabled - this should be ignored
+ MySimpleEventSource.Request("Test 3");
+
+ // Poll for file size changes to the trace file itself.
+ // When the size of the trace file hasn't changed for few seconds, consider it fully written out.
+ Console.WriteLine($"Waiting for the trace file to be written. Poll every second to watch for {TimeIntervalToReadConfigFile.TotalSeconds} seconds of no file size changes.");
+ long lastSizeInBytes = 0;
+ DateTime timeOfLastChangeUTC = DateTime.UtcNow;
+ do
+ {
+ FileInfo traceFileInfo = new FileInfo(traceFilePath);
+ long currentSizeInBytes = traceFileInfo.Length;
+ Console.WriteLine("Trace file size: " + ((double)currentSizeInBytes / BytesInOneMB));
+
+ if (currentSizeInBytes > lastSizeInBytes)
+ {
+ lastSizeInBytes = currentSizeInBytes;
+ timeOfLastChangeUTC = DateTime.UtcNow;
+ }
+
+ Thread.Sleep(TimeSpan.FromSeconds(1));
+
+ } while (DateTime.UtcNow.Subtract(timeOfLastChangeUTC) < TimeIntervalToReadConfigFile);
+
+ // Use TraceEvent to consume the trace file and look for the work that we did.
+ Console.WriteLine("Using TraceEvent to parse the file to find the work that was done during trace capture.");
+ using (TraceEventDispatcher trace = TraceEventDispatcher.GetDispatcherFromFileName(traceFilePath))
+ {
+ InstallValidationCallbacks(trace);
+ trace.Process();
+ }
+
+ // Clean-up the resulting trace file.
+ File.Delete(traceFilePath);
+
+ return this.Pass() ? 100 : 10086;
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/src/tracing/common/common.csproj b/tests/src/tracing/common/common.csproj
index 32a210882c..0de82bc6e2 100644
--- a/tests/src/tracing/common/common.csproj
+++ b/tests/src/tracing/common/common.csproj
@@ -30,6 +30,7 @@
<Compile Include="NetPerfFile.cs" />
<Compile Include="TraceControl.cs" />
<Compile Include="TraceConfiguration.cs" />
+ <Compile Include="AbstractTraceTest.cs" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
diff --git a/tests/src/tracing/keyword/TwoKeywords/TwoKeywords.cs b/tests/src/tracing/keyword/TwoKeywords/TwoKeywords.cs
new file mode 100644
index 0000000000..89b38cec8a
--- /dev/null
+++ b/tests/src/tracing/keyword/TwoKeywords/TwoKeywords.cs
@@ -0,0 +1,52 @@
+// 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.IO;
+using System.Reflection;
+using System.Threading;
+using System.Threading.Tasks;
+using Tracing.Tests.Common;
+
+using Microsoft.Diagnostics.Tracing;
+using Microsoft.Diagnostics.Tracing.Parsers.Clr;
+
+namespace Tracing.Tests
+{
+ public static class TwoKeywordsTest
+ {
+ public static int Main(string[] args)
+ {
+ return new TwoKeywordsTraceTest().Execute();
+ }
+ }
+
+ public class TwoKeywordsTraceTest : AbstractTraceTest
+ {
+ private bool pass;
+
+ protected override string GetConfigFileContents()
+ {
+ return @"
+OutputPath=.
+CircularMB=2048
+Providers=My-Simple-Event-Source:0xFFFFFFFFFFFFFFFF:5:Key1=Value1;Key2=Value2
+";;
+ }
+
+ public override void OnEventCommand(object sender, EventCommandEventArgs command)
+ {
+ if (command.Command == EventCommand.Enable)
+ {
+ this.pass = (command.Arguments.Count == 2);
+ }
+ }
+
+ protected override bool Pass()
+ {
+ return this.pass;
+ }
+ }
+}
diff --git a/tests/src/tracing/keyword/TwoKeywords/TwoKeywords.csproj b/tests/src/tracing/keyword/TwoKeywords/TwoKeywords.csproj
new file mode 100644
index 0000000000..e5882f01c3
--- /dev/null
+++ b/tests/src/tracing/keyword/TwoKeywords/TwoKeywords.csproj
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{8E3244CB-407F-4142-BAAB-E7A55901A5FA}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <CLRTestKind>BuildAndRun</CLRTestKind>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ <CLRTestPriority>0</CLRTestPriority>
+ <GCStressIncompatible>true</GCStressIncompatible>
+ <!-- Due to https://github.com/dotnet/coreclr/issues/22247 -->
+ <UnloadabilityIncompatible>true</UnloadabilityIncompatible>
+ <DisableProjectBuild Condition="'$(Platform)' == 'arm'">true</DisableProjectBuild>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="TwoKeywords.cs" />
+ <ProjectReference Include="../../common/common.csproj" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project> \ No newline at end of file
diff --git a/tests/src/tracing/tracecontrol/TraceControl.cs b/tests/src/tracing/tracecontrol/TraceControl.cs
index 68870d9fc0..99e552ac4e 100644
--- a/tests/src/tracing/tracecontrol/TraceControl.cs
+++ b/tests/src/tracing/tracecontrol/TraceControl.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Diagnostics.Tracing;
using System.IO;
using System.Reflection;
using System.Threading;
@@ -16,101 +17,42 @@ namespace Tracing.Tests
{
public static class TraceControlTest
{
+ public static int Main(string[] args)
+ {
+ return new TraceControlTraceTest().Execute();
+ }
+ }
+
+ public class TraceControlTraceTest : AbstractTraceTest
+ {
+ private bool pass;
+
private static string ConfigFileContents = @"
OutputPath=.
CircularMB=2048
-Providers=*:0xFFFFFFFFFFFFFFFF:5
+Providers=*:0xFFFFFFFFFFFFFFFF:5:
";
-
- private static readonly TimeSpan TimeIntervalToReadConfigFile = new TimeSpan(0, 0, 25);
-
- private const int BytesInOneMB = 1024 * 1024;
-
- /// <summary>
- /// This test collects a trace of itself and then performs some basic validation on the trace.
- /// </summary>
- public static int Main(string[] args)
+ protected override string GetConfigFileContents()
{
- // Calculate the path to the config file.
- string configFileName = Assembly.GetEntryAssembly().GetName().Name + ".eventpipeconfig";
- string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFileName);
- Console.WriteLine("Calculated config file path: " + configFilePath);
-
- // Write the config file to disk.
- File.WriteAllText(configFilePath, ConfigFileContents);
- Console.WriteLine("Wrote contents of config file.");
-
- // Wait few seconds to ensure that tracing has started.
- Console.WriteLine($"Waiting {TimeIntervalToReadConfigFile.TotalSeconds} seconds for the config file to be picked up by the next poll operation.");
- Thread.Sleep(TimeIntervalToReadConfigFile);
-
- // Do some work that we can look for in the trace.
- Console.WriteLine("Do some work that will be captured by the trace.");
- GC.Collect(2, GCCollectionMode.Forced);
- Console.WriteLine("Done with the work.");
-
- // Delete the config file to start tracing.
- File.Delete(configFilePath);
- Console.WriteLine("Deleted the config file.");
-
- // Build the full path to the trace file.
- string[] traceFiles = Directory.GetFiles(".", "*.netperf", SearchOption.TopDirectoryOnly);
- Assert.Equal("traceFiles.Length == 1", traceFiles.Length, 1);
- string traceFilePath = traceFiles[0];
-
- // Poll the file system and wait for the trace file to be written.
- Console.WriteLine("Wait for the config file deletion to be picked up and for the trace file to be written.");
-
- // Wait for 1 second, which is the poll time when tracing is enabled.
- Thread.Sleep(TimeSpan.FromSeconds(1));
+ return ConfigFileContents;
+ }
- // Poll for file size changes to the trace file itself.
- // When the size of the trace file hasn't changed for few seconds, consider it fully written out.
- Console.WriteLine($"Waiting for the trace file to be written. Poll every second to watch for {TimeIntervalToReadConfigFile.TotalSeconds} seconds of no file size changes.");
- long lastSizeInBytes = 0;
- DateTime timeOfLastChangeUTC = DateTime.UtcNow;
- do
+ protected override void InstallValidationCallbacks(TraceEventDispatcher trace)
+ {
+ string gcReasonInduced = GCReason.Induced.ToString();
+ trace.Clr.GCTriggered += delegate (GCTriggeredTraceData data)
{
- FileInfo traceFileInfo = new FileInfo(traceFilePath);
- long currentSizeInBytes = traceFileInfo.Length;
- Console.WriteLine("Trace file size: " + ((double)currentSizeInBytes / BytesInOneMB));
-
- if (currentSizeInBytes > lastSizeInBytes)
+ if (gcReasonInduced.Equals(data.Reason.ToString()))
{
- lastSizeInBytes = currentSizeInBytes;
- timeOfLastChangeUTC = DateTime.UtcNow;
+ Console.WriteLine("Detected an induced GC");
+ pass = true;
}
+ };
+ }
- Thread.Sleep(TimeSpan.FromSeconds(1));
-
- } while (DateTime.UtcNow.Subtract(timeOfLastChangeUTC) < TimeIntervalToReadConfigFile);
-
- int retVal = 0;
-
- // Use TraceEvent to consume the trace file and look for the work that we did.
- Console.WriteLine("Using TraceEvent to parse the file to find the work that was done during trace capture.");
- using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(traceFilePath))
- {
- string gcReasonInduced = GCReason.Induced.ToString();
- string providerName = "Microsoft-Windows-DotNETRuntime";
- string gcTriggeredEventName = "GC/Triggered";
-
- trace.Clr.GCTriggered += delegate (GCTriggeredTraceData data)
- {
- if (gcReasonInduced.Equals(data.Reason.ToString()))
- {
- Console.WriteLine("Detected an induced GC");
- retVal = 100;
- }
- };
-
- trace.Process();
- }
-
- // Clean-up the resulting trace file.
- File.Delete(traceFilePath);
-
- return retVal;
+ protected override bool Pass()
+ {
+ return this.pass;
}
}
}