Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public enum EventActivityOptions
Recursive = 4,
Detachable = 8,
}
[AttributeUsage(System.AttributeTargets.Class)]
public sealed class EventSourceEventGenerateAttribute : Attribute
{
}

[System.AttributeUsageAttribute(System.AttributeTargets.Method)]
public sealed partial class EventAttribute : System.Attribute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,226 @@ public void Test_WriteEvent_NoAttribute()
}
}

[Fact]
public void Test_AutoWritedEvent()
{
using (Listener listener = new EventListenerListener(true))
{
Test_Generated(listener);
}
}

private void Test_Generated(Listener listener)
{
using (EventSourceAutoGenerated logger = new EventSourceAutoGenerated())
{
var tests = new List<SubTest>();

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/Event0",
delegate ()
{ logger.Event0(); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("Event0", evt.EventName);
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventI",
delegate ()
{ logger.EventI(11); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventI", evt.EventName);
Assert.Equal(11, evt.PayloadValue(0, "arg1"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventII",
delegate ()
{ logger.EventII(11,22); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventII", evt.EventName);
Assert.Equal(11, evt.PayloadValue(0, "arg1"));
Assert.Equal(22, evt.PayloadValue(1, "arg2"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventIII",
delegate ()
{ logger.EventIII(11, 22); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventIII", evt.EventName);
Assert.Equal(11, evt.PayloadValue(0, "arg1"));
Assert.Equal(22, evt.PayloadValue(1, "arg2"));
Assert.Equal(12, evt.PayloadValue(2, "arg3"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventIII",
delegate ()
{ logger.EventIII(11, 22, 33); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventIII", evt.EventName);
Assert.Equal(11, evt.PayloadValue(0, "arg1"));
Assert.Equal(22, evt.PayloadValue(1, "arg2"));
Assert.Equal(33, evt.PayloadValue(2, "arg3"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventL",
delegate ()
{ logger.EventL(11L); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventL", evt.EventName);
Assert.Equal(11L, evt.PayloadValue(0, "arg1"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventLL",
delegate ()
{ logger.EventLL(11L,22L); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventLL", evt.EventName);
Assert.Equal(11L, evt.PayloadValue(0, "arg1"));
Assert.Equal(22L, evt.PayloadValue(1, "arg2"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventLLL",
delegate ()
{ logger.EventLLL(11L, 22L, 33L); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventLLL", evt.EventName);
Assert.Equal(11L, evt.PayloadValue(0, "arg1"));
Assert.Equal(22L, evt.PayloadValue(1, "arg2"));
Assert.Equal(33L, evt.PayloadValue(2, "arg3"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventS",
delegate ()
{ logger.EventS("hello"); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventS", evt.EventName);
Assert.Equal("hello", evt.PayloadValue(0, "arg1"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventS",
delegate ()
{ logger.EventS(null); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventS", evt.EventName);
Assert.Equal(string.Empty,evt.PayloadValue(0, "arg1"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventSS",
delegate ()
{ logger.EventSS("hello", "world"); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventSS", evt.EventName);
Assert.Equal("hello", evt.PayloadValue(0, "arg1"));
Assert.Equal("world", evt.PayloadValue(1, "arg2"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventSSS",
delegate ()
{ logger.EventSSS("hello", "world", "!"); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventSSS", evt.EventName);
Assert.Equal("hello", evt.PayloadValue(0, "arg1"));
Assert.Equal("world", evt.PayloadValue(1, "arg2"));
Assert.Equal("!", evt.PayloadValue(2, "arg3"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventSI",
delegate ()
{ logger.EventSI("hello",11); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventSI", evt.EventName);
Assert.Equal("hello", evt.PayloadValue(0, "arg1"));
Assert.Equal(11, evt.PayloadValue(1, "arg2"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventSL",
delegate ()
{ logger.EventSL("hello", 11L); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventSL", evt.EventName);
Assert.Equal("hello", evt.PayloadValue(0, "arg1"));
Assert.Equal(11L, evt.PayloadValue(1, "arg2"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventSII",
delegate ()
{ logger.EventSII("hello", 11, 22); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventSII", evt.EventName);
Assert.Equal("hello", evt.PayloadValue(0, "arg1"));
Assert.Equal(11, evt.PayloadValue(1, "arg2"));
Assert.Equal(22, evt.PayloadValue(2, "arg3"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventDouble",
delegate ()
{ logger.EventDouble(1d); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventDouble", evt.EventName);
Assert.Equal(1d, evt.PayloadValue(0, "arg1"));
}));

/*************************************************************************/
tests.Add(new SubTest("EventSourceAutoGenerated/EventEnum",
delegate ()
{ logger.EventEnum(SdtEventSources.Color.Green); },
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventEnum", evt.EventName);
Assert.Equal(SdtEventSources.Color.Green, evt.PayloadValue(0, "arg1"));
}));

EventTestHarness.RunTests(tests, listener, logger);
}
}

/// <summary>
/// Helper method for the two tests above.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,60 @@ public sealed class EventSourceNoAttribute : EventSource
// Make sure this is before any #if so it gets a deterministic ID
public void EventNoAttributes(string s) { WriteEvent(16, s); }
}
[EventSourceEventGenerate]
[EventSource(Guid = "4EF35517-7515-4843-9F2F-32B2017F0FDC", Name = "EventSourceAutoGenerated")]
public sealed unsafe partial class EventSourceAutoGenerated: EventSource
{
[Event(1, Level = EventLevel.Informational)]
public partial void Event0();

[Event(2, Level = EventLevel.Informational)]
public partial void EventI(int arg1);

[Event(3, Level = EventLevel.Informational)]
public partial void EventII(int arg1, int arg2);

[Event(4, Level = EventLevel.Informational)]
public partial void EventIII(int arg1, int arg2, int arg3 = 12);

[Event(5, Level = EventLevel.Informational)]
public partial void EventL(long arg1);

[Event(6, Level = EventLevel.Informational)]
public partial void EventLL(long arg1, long arg2);

[Event(7, Level = EventLevel.Informational)]
public partial void EventLLL(long arg1, long arg2, long arg3);

[Event(8, Level = EventLevel.Informational)]
public partial void EventS(string arg1);

[Event(9, Level = EventLevel.Informational)]
public partial void EventSS(string arg1, string arg2);

[Event(10, Level = EventLevel.Informational)]
public partial void EventSSS(string arg1, string arg2, string arg3);

[Event(11, Level = EventLevel.Informational)]
public partial void EventSI(string arg1, int arg2);

[Event(12, Level = EventLevel.Informational)]
public partial void EventSL(string arg1, long arg2);

[Event(13, Level = EventLevel.Informational)]
public partial void EventSII(string arg1, int arg2, int arg3);

[Event(14, Level = EventLevel.Informational)]
public partial void EventDouble(double arg1);

[Event(15, Level = EventLevel.Informational)]
public partial void EventEnum(Color arg1);


}
public enum Color
{
Red,
Green
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TestRuntime>true</TestRuntime>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TestDisableParallelization>true</TestDisableParallelization>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsAppleMobile)' == 'true' or '$(TargetOS)' == 'android'">
<RuntimeComponents Include="diagnostics_tracing" />
Expand Down Expand Up @@ -51,4 +52,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="$(TraceEventVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)\System.Private.CoreLib\gen\System.Private.CoreLib.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.DotnetRuntime.Extensions;

namespace Generators
{
public partial class EventSourceEventGenerator
{
private const string Category = "System.Diagnostics.Tracing";

private static DiagnosticDescriptor EventSourceNoSupportType { get; } = DiagnosticDescriptorHelper.Create(
id: "SYSLIB2000", //I don't know what id need I set
title: new LocalizableResourceString(nameof(SR.EventSourceGeneratorTitle), SR.ResourceManager, typeof(FxResources.System.Private.CoreLib.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.EventSourceNoSupportType), SR.ResourceManager, typeof(FxResources.System.Private.CoreLib.Generators.SR)),
category: Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
customTags: WellKnownDiagnosticTags.NotConfigurable);

private static DiagnosticDescriptor ContextClassesMustBePartial { get; } = DiagnosticDescriptorHelper.Create(
id: "SYSLIB2001", //I don't know what id need I set
title: new LocalizableResourceString(nameof(SR.ContextClassesMustBePartialTitle), SR.ResourceManager, typeof(FxResources.System.Private.CoreLib.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.ContextClassesMustBePartialMessageFormat), SR.ResourceManager, typeof(FxResources.System.Private.CoreLib.Generators.SR)),
category: Category,
DiagnosticSeverity.Error,
isEnabledByDefault: true,
customTags: WellKnownDiagnosticTags.NotConfigurable);
}
}
Loading