diff options
Diffstat (limited to 'tests/src')
3 files changed, 146 insertions, 3 deletions
diff --git a/tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs b/tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs index 5bf11b8f78..78ab88aed9 100644 --- a/tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs +++ b/tests/src/tracing/eventpipesmoke/EventPipeSmoke.cs @@ -10,11 +10,19 @@ namespace Tracing.Tests { private static int allocIterations = 10000; private static int trivialSize = 0x100000; - private static bool keepOutput = false; static int Main(string[] args) { - string outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf"; + bool keepOutput = false; + // Use the first arg as an output filename if there is one + string outputFilename = null; + if (args.Length >= 1) { + outputFilename = args[0]; + keepOutput = true; + } + else { + outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf"; + } Console.WriteLine("\tStart: Enable tracing."); TraceControl.EnableDefault(outputFilename); @@ -49,7 +57,7 @@ namespace Tracing.Tests System.IO.File.Delete(outputFilename); } - return pass ? 100 : 0; + return pass ? 100 : -1; } } } diff --git a/tests/src/tracing/eventsourcesmoke/EventSourceSmoke.cs b/tests/src/tracing/eventsourcesmoke/EventSourceSmoke.cs new file mode 100644 index 0000000000..c3fe8366ab --- /dev/null +++ b/tests/src/tracing/eventsourcesmoke/EventSourceSmoke.cs @@ -0,0 +1,104 @@ +using System; +using System.Threading.Tasks; +using System.IO; +using System.Diagnostics.Tracing; + +using Tracing.Tests.Common; + +namespace Tracing.Tests +{ + [EventSource(Name = "SimpleEventSource")] + class SimpleEventSource : EventSource + { + public SimpleEventSource() : base(true) { } + + [Event(1)] + internal void Message(string msg) { this.WriteEvent(1, msg); } + } + + class EventPipeSmoke + { + private static int messageIterations = 10000; + private static int trivialSize = 0x100000; + + public static TraceConfiguration GetConfig(EventSource eventSource, string outputFile="default.netperf") + { + // Setup the configuration values. + uint circularBufferMB = 1024; // 1 GB + uint level = 5;//(uint)EventLevel.Informational; + TimeSpan profSampleDelay = TimeSpan.FromMilliseconds(1); + + // Create a new instance of EventPipeConfiguration. + TraceConfiguration config = new TraceConfiguration(outputFile, circularBufferMB); + // Setup the provider values. + // Public provider. + string providerName = eventSource.Guid.ToString("D"); + UInt64 keywords = 0xffffffffffffffff; + + // Enable the provider. + config.EnableProvider(providerName, keywords, level); + + // Set the sampling rate. + config.SetSamplingRate(profSampleDelay); + + return config; + } + + static int Main(string[] args) + { + bool keepOutput = false; + // Use the first arg as an output filename if there is one + string outputFilename = null; + if (args.Length >= 1) { + outputFilename = args[0]; + keepOutput = true; + } + else { + outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf"; + } + + SimpleEventSource eventSource = new SimpleEventSource(); + + Console.WriteLine("\tStart: Enable tracing."); + TraceControl.Enable(GetConfig(eventSource, outputFilename)); + Console.WriteLine("\tEnd: Enable tracing.\n"); + + Console.WriteLine("\tStart: Messaging."); + // Send messages + // Use random numbers and addition as a simple, human readble checksum + Random generator = new Random(); + for(int i=0; i<messageIterations; i++) + { + int x = generator.Next(1,1000); + int y = generator.Next(1,1000); + string result = String.Format("{0} + {1} = {2}", x, y, x+y); + + eventSource.Message(result); + } + Console.WriteLine("\tEnd: Messaging.\n"); + + Console.WriteLine("\tStart: Disable tracing."); + TraceControl.Disable(); + Console.WriteLine("\tEnd: Disable tracing.\n"); + + FileInfo outputMeta = new FileInfo(outputFilename); + Console.WriteLine("\tCreated {0} bytes of data", outputMeta.Length); + + bool pass = false; + if (outputMeta.Length > trivialSize){ + pass = true; + } + + if (keepOutput) + { + Console.WriteLine(String.Format("\tOutput file: {0}", outputFilename)); + } + else + { + System.IO.File.Delete(outputFilename); + } + + return pass ? 100 : -1; + } + } +} diff --git a/tests/src/tracing/eventsourcesmoke/eventsourcesmoke.csproj b/tests/src/tracing/eventsourcesmoke/eventsourcesmoke.csproj new file mode 100644 index 0000000000..897ebfd983 --- /dev/null +++ b/tests/src/tracing/eventsourcesmoke/eventsourcesmoke.csproj @@ -0,0 +1,31 @@ +<?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> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + </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="EventSourceSmoke.cs" /> + <ProjectReference Include="../common/common.csproj" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> +</Project> |