You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
@@ -1,12 +1,7 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.12
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{90DA2470-329A-4DD0-95B3-F00D42DD9137}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
documentation\EventCounterTutorial.md = documentation\EventCounterTutorial.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Diagnostics.Tracing.Tests", "tests\System.Diagnostics.Tracing.Tests.csproj", "{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4} = {EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<h1>Introduction Tutorial: How to measure performance for very frequent events using EventCounters</h1>
|
||||
# Introduction Tutorial: How to measure performance for very frequent events using EventCounters
|
||||
|
||||
<p>While EventSource is fast, logging too many events for very frequent events is still a performance hit. In this tutorial, we will introduce EventCounter, a mechanism for measuring performance for very frequent events.</p>
|
||||
While `EventSource` is fast, logging too many events for very frequent events is still a performance hit. In this tutorial, we will introduce `EventCounter`, a mechanism for measuring performance for very frequent events.
|
||||
|
||||
<p>For event that happen very frequently (for example, if it happen every few milliseconds), in general, you will want the performance overhead per event to be very low (e.g. less than a millisecond), otherwise it is going to cost a significant performance overhead. Logging an event, at the end of the day, need to write something to the disk. If the disk is not fast enough, you will lost events. We need a solution other than logging the event itself.</p>
|
||||
For event that happen very frequently (for example, if it happen every few milliseconds), in general, you will want the performance overhead per event to be very low (e.g. less than a millisecond), otherwise it is going to cost a significant performance overhead. Logging an event, at the end of the day, need to write something to the disk. If the disk is not fast enough, you will lost events. We need a solution other than logging the event itself.
|
||||
|
||||
<p>When dealing with large number of events, knowing the measure per event is not very useful either. Most of the time all we need is just some statistics out of it. So we could crank the statistics within the process itself and then write an event once in a while to report the statistics, that's what EventCounter will do for us. Let's take a look at an example how to do this in Microsoft.Diagnostics.Tracing.EventSource</p>
|
||||
When dealing with large number of events, knowing the measure per event is not very useful either. Most of the time all we need is just some statistics out of it. So we could crank the statistics within the process itself and then write an event once in a while to report the statistics, that's what `EventCounter` will do for us. Let's take a look at an example how to do this in `Microsoft.Diagnostics.Tracing.EventSource`.
|
||||
|
||||
<p>In the sequel, we assume you are familiar with the basic EventSource usage, if you don't, please refer to <a href="http://blogs.msdn.com/b/vancem/archive/2012/07/09/logging-your-own-etw-events-in-c-system-diagnostics-tracing-eventsource.aspx">Vance's excellent blog</a> on that.</p>
|
||||
In the sequel, we assume you are familiar with the basic `EventSource` usage, if you don't, please refer to [Vance's excellent blog](http://blogs.msdn.com/b/vancem/archive/2012/07/09/logging-your-own-etw-events-in-c-system-diagnostics-tracing-eventsource.aspx) on that.
|
||||
|
||||
<p>Without further ado, here is an example on how to use the EventCounter</p>
|
||||
Without further ado, here is an example on how to use the `EventCounter`
|
||||
|
||||
<pre><code>// Give your event sources a descriptive name using the EventSourceAttribute, otherwise the name of the class is used.
|
||||
```c#
|
||||
// Give your event sources a descriptive name using the EventSourceAttribute, otherwise the name of the class is used.
|
||||
[EventSource(Name = "Samples-EventCounterDemos-Minimal")]
|
||||
public sealed class MinimalEventCounterSource : EventSource
|
||||
{
|
||||
@@ -23,7 +24,7 @@ public sealed class MinimalEventCounterSource : EventSource
|
||||
this.requestCounter = new EventCounter("request", this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Call this method to indicate that a request for a URL was made which tool a particular amount of time
|
||||
public void Request(string url, float elapsedMSec)
|
||||
{
|
||||
@@ -38,34 +39,40 @@ public sealed class MinimalEventCounterSource : EventSource
|
||||
this.requestCounter.WriteMetric(elapsedMSec); // This adds it to the PerfCounter called 'Request' if PerfCounters are on
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
```
|
||||
|
||||
<p>The WriteEvent line is the EventSource part and is not part of EventCounter, it is shown to show that you can log a message together with the event counter.</p>
|
||||
The` WriteEvent` line is the `EventSource` part and is not part of `EventCounter`, it is shown to show that you can log a message together with the event counter.
|
||||
|
||||
<p>So, with that, we logged the metric to the EventCounter, but unless we can actually get the statistics out of it, it is not useful. To get the statistics, we need to enable the EventCounter by setting off a timer how frequently we want the events, as well as a listener to capture the events, to do that, you can use PerfView. Again, we assumed familiarity with PerfView, if not, you can refer to Vance's blog on that.</p>
|
||||
So, with that, we logged the metric to the `EventCounter`, but unless we can actually get the statistics out of it, it is not useful. To get the statistics, we need to enable the `EventCounter` by setting off a timer how frequently we want the events, as well as a listener to capture the events, to do that, you can use PerfView. Again, we assumed familiarity with PerfView, if not, you can refer to Vance's blog on that.
|
||||
|
||||
<p>There is an extra keyword that you will need to specify the turn on the EventCounters.</p>
|
||||
There is an extra keyword that you will need to specify the turn on the EventCounters.
|
||||
|
||||
<p><code>PerfView /onlyProviders=*Samples-EventCounterDemos-Minimal:**EventCounterIntervalSec=1** collect</code></p>
|
||||
```
|
||||
PerfView /onlyProviders=*Samples-EventCounterDemos-Minimal:**EventCounterIntervalSec=1** collect
|
||||
```
|
||||
|
||||
<p>Note the bold part about EventCounterIntervalSec, that indicate the frequency of the sampling.</p>
|
||||
Note the bold part about `EventCounterIntervalSec`, that indicate the frequency of the sampling.
|
||||
|
||||
<p>As usual, turn on PerfView, and then run the sample code, we will have something like this</p>
|
||||
As usual, turn on PerfView, and then run the sample code, we will have something like this
|
||||
|
||||
<p><img src="PerfViewCapture_Counters.png" alt="PerfView Capture of EventCounter traces" title="PerfView Capture of EventCounter traces" /></p>
|
||||
<img src="PerfViewCapture_Counters.png" alt="PerfView Capture of EventCounter traces" title="PerfView Capture of EventCounter traces" />
|
||||
|
||||
<p>Now let's drill into what the data captured meant - when I copied from PerfView, it looks like this</p>
|
||||
Now let's drill into what the data captured meant - when I copied from PerfView, it looks like this
|
||||
|
||||
<p>Payload="{ Name="request", Mean=51.66667, StandardDerivation=34.37376, Count=3, Min=23, Max=100, IntervalSec=1.038177 }" </p>
|
||||
```
|
||||
Payload="{ Name="request", Mean=51.66667, StandardDerivation=34.37376, Count=3, Min=23, Max=100, IntervalSec=1.038177 }"
|
||||
```
|
||||
|
||||
<p>Now it is obvious that within a sampling period, we have 5 events, and all the other statistics.</p>
|
||||
Now it is obvious that within a sampling period, we have 5 events, and all the other statistics.
|
||||
|
||||
<p>Notice that, this command also log the events, so we will get both the events and the counter statistics.</p>
|
||||
Notice that, this command also log the events, so we will get both the events and the counter statistics.
|
||||
|
||||
<p><img src="PerfViewCapture_Events.png" alt="PerfView Capture of Event Traces" title="PerfView Capture of Event Traces" /></p>
|
||||
<img src="PerfViewCapture_Events.png" alt="PerfView Capture of Event Traces" title="PerfView Capture of Event Traces" />
|
||||
|
||||
<p>As we mentioned, to avoid overhead, sometimes we will want just the counters. This command can be used to log <em>only</em> the counters:</p>
|
||||
As we mentioned, to avoid overhead, sometimes we will want just the counters. This command can be used to log <em>only</em> the counters:
|
||||
|
||||
<p><code>PerfView /onlyProviders=*Samples-EventCounterDemos-Minimal:*:Critical:EventCounterIntervalSec=1 collect</code></p>
|
||||
```
|
||||
PerfView /onlyProviders=*Samples-EventCounterDemos-Minimal:*:Critical:EventCounterIntervalSec=1 collect
|
||||
```
|
||||
|
||||
<p>Notice the 'Critical' keyword in the command line, that is used to filter out the other events with lower priorities.</p>
|
||||
Notice the `Critical` keyword in the command line, that is used to filter out the other events with lower priorities.
|
||||
|
||||
@@ -1 +1 @@
|
||||
d60c3fe92a6033280df85116aeb1fad1689932b7
|
||||
72476cb0a5b15d6b7a21b27d78fc441d15826544
|
||||
@@ -3,31 +3,28 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Tracing;
|
||||
|
||||
|
||||
namespace BasicEventSourceTests
|
||||
{
|
||||
internal class LoudListener : EventListener
|
||||
{
|
||||
[ThreadStatic]
|
||||
public static EventWrittenEventArgs LastEvent;
|
||||
public static EventWrittenEventArgs t_lastEvent;
|
||||
|
||||
protected override void OnEventSourceCreated(EventSource eventSource)
|
||||
public LoudListener(EventSource eventSource)
|
||||
{
|
||||
base.OnEventSourceCreated(eventSource);
|
||||
EnableEvents(eventSource, EventLevel.LogAlways, (EventKeywords)0xffffffff);
|
||||
}
|
||||
|
||||
protected override void OnEventWritten(EventWrittenEventArgs eventData)
|
||||
{
|
||||
LastEvent = eventData;
|
||||
t_lastEvent = eventData;
|
||||
|
||||
Debug.Write(String.Format("Event {0} ", eventData.EventId));
|
||||
Debug.Write(String.Format(" (activity {0}{1}) ", eventData.ActivityId, eventData.RelatedActivityId != null ? "->" + eventData.RelatedActivityId : ""));
|
||||
Debug.WriteLine(String.Format(" ({0}).", eventData.Payload != null ? string.Join(", ", eventData.Payload) : ""));
|
||||
Debug.Write(string.Format("Event {0} ", eventData.EventId));
|
||||
Debug.Write(string.Format(" (activity {0}{1}) ", eventData.ActivityId, eventData.RelatedActivityId != null ? "->" + eventData.RelatedActivityId : ""));
|
||||
Debug.WriteLine(string.Format(" ({0}).", eventData.Payload != null ? string.Join(", ", eventData.Payload) : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace BasicEventSourceTests
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[PlatformSpecific(TestPlatforms.Windows)] // non-Windows EventSources don't have lifetime
|
||||
[ActiveIssue(20837,TargetFrameworkMonikers.UapAot)]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Test requires private reflection.")]
|
||||
public void Test_EventSource_Lifetime()
|
||||
{
|
||||
TestUtilities.CheckNoEventSourcesRunning("Start");
|
||||
|
||||
@@ -30,14 +30,14 @@ namespace BasicEventSourceTests
|
||||
{
|
||||
using (var es = new SdtEventSources.DontPollute.EventSource())
|
||||
{
|
||||
using (var el = new LoudListener())
|
||||
using (var el = new LoudListener(es))
|
||||
{
|
||||
int i = 12;
|
||||
es.EventWrite(i);
|
||||
|
||||
Assert.Equal(1, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(i, LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(i, LoudListener.t_lastEvent.Payload[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,17 @@ namespace BasicEventSourceTests
|
||||
{
|
||||
public class TestsManifestNegative
|
||||
{
|
||||
private static void AsserExceptionStringsEqual(Func<string> expectedStrFunc, Exception ex)
|
||||
{
|
||||
if (!PlatformDetection.IsNetNative)
|
||||
{
|
||||
string expectedStr = expectedStrFunc();
|
||||
Assert.Equal(ex.Message, expectedStr);
|
||||
}
|
||||
}
|
||||
|
||||
#region Message string building
|
||||
public static string GetResourceString(string key, params object[] args)
|
||||
private static string GetResourceString(string key, params object[] args)
|
||||
{
|
||||
string fmt = GetResourceStringFromReflection(key);
|
||||
if (fmt != null)
|
||||
@@ -58,11 +67,11 @@ namespace BasicEventSourceTests
|
||||
|
||||
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty));
|
||||
|
||||
Exception e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_TypeMustBeSealedOrAbstract"), e.Message);
|
||||
Exception e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_TypeMustBeSealedOrAbstract"), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_TypeMustBeSealedOrAbstract"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_TypeMustBeSealedOrAbstract"), e);
|
||||
|
||||
// starting with NuGet we allow non-void returning methods as long as they have the [Event] attribute
|
||||
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithReturnEventSource), string.Empty));
|
||||
@@ -71,129 +80,134 @@ namespace BasicEventSourceTests
|
||||
|
||||
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithReturnEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty));
|
||||
Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));
|
||||
Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.OutOfRangeKwdEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(String.Join(Environment.NewLine,
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.OutOfRangeKwdEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => String.Join(Environment.NewLine,
|
||||
GetResourceString("EventSource_IllegalKeywordsValue", "Kwd1", "0x100000000000"),
|
||||
GetResourceString("EventSource_KeywordCollision", "Session3", "Kwd1", "0x100000000000")),
|
||||
e.Message);
|
||||
e);
|
||||
|
||||
#if FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
|
||||
e = Assert.Throws<ArgumentException>(GetResourceString("EventSource_MaxChannelExceeded"),
|
||||
e = AssertExtensions.Throws<ArgumentException>(GetResourceString("EventSource_MaxChannelExceeded"),
|
||||
() => EventSource.GenerateManifest(typeof(Sdt.TooManyChannelsEventSource), string.Empty));
|
||||
#endif
|
||||
|
||||
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
|
||||
e = Assert.Throws<ArgumentException>(GetResourceString("EventSource_EventWithAdminChannelMustHaveMessage", "WriteInteger", "Admin"),
|
||||
e = AssertExtensions.Throws<ArgumentException>(GetResourceString("EventSource_EventWithAdminChannelMustHaveMessage", "WriteInteger", "Admin"),
|
||||
() => EventSource.GenerateManifest(typeof(Sdt.EventWithAdminChannelNoMessageEventSource), string.Empty, strictOptions));
|
||||
#endif // USE_ETW
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(String.Join(Environment.NewLine,
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => String.Join(Environment.NewLine,
|
||||
GetResourceString("EventSource_IllegalOpcodeValue", "Op1", 3),
|
||||
GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1)),
|
||||
e.Message);
|
||||
e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(String.Join(Environment.NewLine,
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => String.Join(Environment.NewLine,
|
||||
GetResourceString("EventSource_IllegalOpcodeValue", "Op1", 3),
|
||||
GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1)),
|
||||
e.Message);
|
||||
e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty));
|
||||
Assert.Equal(GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger"), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(String.Join(Environment.NewLine,
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => String.Join(Environment.NewLine,
|
||||
GetResourceString("EventSource_EnumKindMismatch", "Op1", "EventKeywords", "Opcodes"),
|
||||
GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger")),
|
||||
e.Message);
|
||||
e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));
|
||||
Assert.Equal(GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger"), e);
|
||||
|
||||
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty));
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_MismatchIdToWriteEvent", "WriteInteger", 10, 1), e.Message);
|
||||
// These tests require the IL to be present for inspection.
|
||||
if (!PlatformDetection.IsNetNative)
|
||||
{
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_MismatchIdToWriteEvent", "WriteInteger", 10, 1), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_MismatchIdToWriteEvent", "WriteInteger", 10, 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_MismatchIdToWriteEvent", "WriteInteger", 10, 1), e);
|
||||
}
|
||||
|
||||
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty));
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(String.Join(Environment.NewLine,
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => String.Join(Environment.NewLine,
|
||||
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"),
|
||||
GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)),
|
||||
e.Message);
|
||||
e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(String.Join(Environment.NewLine,
|
||||
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => String.Join(Environment.NewLine,
|
||||
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"),
|
||||
GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)),
|
||||
e.Message);
|
||||
e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_EventNameReused", "WriteInteger"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_EventNameReused", "WriteInteger"), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_EventNameReused", "WriteInteger"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_EventNameReused", "WriteInteger"), e);
|
||||
|
||||
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty));
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 2, "WriteInteger1", 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 2, "WriteInteger1", 1), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 2, "WriteInteger1", 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 2, "WriteInteger1", 1), e);
|
||||
|
||||
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty));
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1), e);
|
||||
|
||||
Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithInvalidMessageEventSource), string.Empty));
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.EventWithInvalidMessageEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_UnsupportedMessageProperty", "WriteString", "Message = {0,12:G}"), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithInvalidMessageEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_UnsupportedMessageProperty", "WriteString", "Message = {0,12:G}"), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(String.Join(Environment.NewLine,
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => String.Join(Environment.NewLine,
|
||||
GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Keywords"),
|
||||
GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Tasks"),
|
||||
GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Opcodes")),
|
||||
e.Message);
|
||||
e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(String.Join(Environment.NewLine,
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => String.Join(Environment.NewLine,
|
||||
GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Keywords"),
|
||||
GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Tasks"),
|
||||
GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Opcodes")),
|
||||
e.Message);
|
||||
e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", "WriteInteger", 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", "WriteInteger", 1), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", "WriteInteger", 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", "WriteInteger", 1), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_EventMustNotBeExplicitImplementation", "SdtEventSources.ILogging.Error", 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_EventMustNotBeExplicitImplementation", "SdtEventSources.ILogging.Error", 1), e);
|
||||
|
||||
e = Assert.Throws<ArgumentException>(() => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions));
|
||||
Assert.Equal(GetResourceString("EventSource_EventMustNotBeExplicitImplementation", "SdtEventSources.ILogging.Error", 1), e.Message);
|
||||
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions));
|
||||
AsserExceptionStringsEqual(() => GetResourceString("EventSource_EventMustNotBeExplicitImplementation", "SdtEventSources.ILogging.Error", 1), e);
|
||||
|
||||
TestUtilities.CheckNoEventSourcesRunning("Stop");
|
||||
}
|
||||
|
||||
@@ -47,9 +47,14 @@ namespace BasicEventSourceTests
|
||||
Assert.Equal(events.Count, 1);
|
||||
Event _event = events[0];
|
||||
Assert.Equal("EventSourceMessage", _event.EventName);
|
||||
string message = _event.PayloadString(0, "message");
|
||||
// expected message: "ERROR: Exception in Command Processing for EventSource BadEventSource_Bad_Type_ByteArray: Unsupported type Byte[] in event source. "
|
||||
Assert.True(Regex.IsMatch(message, "Unsupported type"));
|
||||
|
||||
// Check the exception text if not ProjectN.
|
||||
if (!PlatformDetection.IsNetNative)
|
||||
{
|
||||
string message = _event.PayloadString(0, "message");
|
||||
// expected message: "ERROR: Exception in Command Processing for EventSource BadEventSource_Bad_Type_ByteArray: Unsupported type Byte[] in event source. "
|
||||
Assert.True(Regex.IsMatch(message, "Unsupported type"));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -62,6 +67,7 @@ namespace BasicEventSourceTests
|
||||
/// Test the
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Depends on inspecting IL at runtime.")]
|
||||
public void Test_BadEventSource_MismatchedIds()
|
||||
{
|
||||
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
|
||||
|
||||
@@ -40,7 +40,6 @@ namespace BasicEventSourceTests
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[ActiveIssue("dotnet/corefx #19455", TargetFrameworkMonikers.NetFramework)]
|
||||
[ActiveIssue(20744, TargetFrameworkMonikers.UapAot)]
|
||||
public void Test_Write_T_EventListener()
|
||||
{
|
||||
using (var listener = new EventListenerListener())
|
||||
@@ -55,7 +54,6 @@ namespace BasicEventSourceTests
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[ActiveIssue("dotnet/corefx #19455", TargetFrameworkMonikers.NetFramework)]
|
||||
[ActiveIssue(20744, TargetFrameworkMonikers.UapAot)]
|
||||
public void Test_Write_T_EventListener_UseEvents()
|
||||
{
|
||||
Test_Write_T(new EventListenerListener(true));
|
||||
@@ -412,7 +410,6 @@ namespace BasicEventSourceTests
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[ActiveIssue("dotnet/corefx #18806", TargetFrameworkMonikers.NetFramework)]
|
||||
[ActiveIssue(20744, TargetFrameworkMonikers.UapAot)]
|
||||
public void Test_Write_T_In_Manifest_Serialization()
|
||||
{
|
||||
using (var eventListener = new EventListenerListener())
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace BasicEventSourceTests
|
||||
TestUtilities.CheckNoEventSourcesRunning("Start");
|
||||
using (var log = new EventSourceTest())
|
||||
{
|
||||
using (var el = new LoudListener())
|
||||
using (var el = new LoudListener(log))
|
||||
{
|
||||
var sources = EventSource.GetSources();
|
||||
Assert.True(sources.Contains(log));
|
||||
@@ -31,119 +31,119 @@ namespace BasicEventSourceTests
|
||||
Assert.Null(EventSource.GenerateManifest(typeof(EventSourceTest), string.Empty, EventManifestOptions.OnlyIfNeededForRegistration));
|
||||
|
||||
log.Event0();
|
||||
Assert.Equal(1, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(0, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(0, LoudListener.t_lastEvent.Payload.Count);
|
||||
|
||||
#region Validate "int" arguments
|
||||
log.EventI(10);
|
||||
Assert.Equal(2, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(10, (int)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(10, (int)LoudListener.t_lastEvent.Payload[0]);
|
||||
|
||||
log.EventII(10, 11);
|
||||
Assert.Equal(3, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(10, (int)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(11, (int)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal(3, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(10, (int)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(11, (int)LoudListener.t_lastEvent.Payload[1]);
|
||||
|
||||
log.EventIII(10, 11, 12);
|
||||
Assert.Equal(4, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(3, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(10, (int)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(11, (int)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal(12, (int)LoudListener.LastEvent.Payload[2]);
|
||||
Assert.Equal(4, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(3, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(10, (int)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(11, (int)LoudListener.t_lastEvent.Payload[1]);
|
||||
Assert.Equal(12, (int)LoudListener.t_lastEvent.Payload[2]);
|
||||
#endregion
|
||||
|
||||
#region Validate "long" arguments
|
||||
log.EventL(10);
|
||||
Assert.Equal(5, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(10, (long)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(5, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(10, (long)LoudListener.t_lastEvent.Payload[0]);
|
||||
|
||||
log.EventLL(10, 11);
|
||||
Assert.Equal(6, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(10, (long)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(11, (long)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal(6, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(10, (long)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(11, (long)LoudListener.t_lastEvent.Payload[1]);
|
||||
|
||||
log.EventLLL(10, 11, 12);
|
||||
Assert.Equal(7, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(3, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(10, (long)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(11, (long)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal(12, (long)LoudListener.LastEvent.Payload[2]);
|
||||
Assert.Equal(7, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(3, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(10, (long)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(11, (long)LoudListener.t_lastEvent.Payload[1]);
|
||||
Assert.Equal(12, (long)LoudListener.t_lastEvent.Payload[2]);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validate "string" arguments
|
||||
log.EventS("10");
|
||||
Assert.Equal(8, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(8, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
|
||||
log.EventSS("10", "11");
|
||||
Assert.Equal(9, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal("11", (string)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal(9, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal("11", (string)LoudListener.t_lastEvent.Payload[1]);
|
||||
|
||||
log.EventSSS("10", "11", "12");
|
||||
Assert.Equal(10, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(3, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal("11", (string)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal("12", (string)LoudListener.LastEvent.Payload[2]);
|
||||
Assert.Equal(10, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(3, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal("11", (string)LoudListener.t_lastEvent.Payload[1]);
|
||||
Assert.Equal("12", (string)LoudListener.t_lastEvent.Payload[2]);
|
||||
#endregion
|
||||
|
||||
#region Validate byte array arguments
|
||||
byte[] arr = new byte[20];
|
||||
log.EventWithByteArray(arr);
|
||||
Assert.Equal(52, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(arr.Length, ((byte[])LoudListener.LastEvent.Payload[0]).Length);
|
||||
Assert.Equal(52, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(arr.Length, ((byte[])LoudListener.t_lastEvent.Payload[0]).Length);
|
||||
#endregion
|
||||
|
||||
#region Validate mixed type arguments
|
||||
log.EventSI("10", 11);
|
||||
Assert.Equal(11, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(11, (int)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal(11, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(11, (int)LoudListener.t_lastEvent.Payload[1]);
|
||||
|
||||
log.EventSL("10", 11);
|
||||
Assert.Equal(12, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(11, (long)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal(12, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(11, (long)LoudListener.t_lastEvent.Payload[1]);
|
||||
|
||||
log.EventSII("10", 11, 12);
|
||||
Assert.Equal(13, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(3, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(11, (int)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.Equal(12, (int)LoudListener.LastEvent.Payload[2]);
|
||||
Assert.Equal(13, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(3, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("10", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(11, (int)LoudListener.t_lastEvent.Payload[1]);
|
||||
Assert.Equal(12, (int)LoudListener.t_lastEvent.Payload[2]);
|
||||
#endregion
|
||||
|
||||
#region Validate enums/flags
|
||||
log.EventEnum(MyColor.Blue);
|
||||
Assert.Equal(19, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(MyColor.Blue, (MyColor)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(19, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(MyColor.Blue, (MyColor)LoudListener.t_lastEvent.Payload[0]);
|
||||
|
||||
log.EventEnum1(MyColor.Green);
|
||||
Assert.Equal(20, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(MyColor.Green, (MyColor)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(20, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(MyColor.Green, (MyColor)LoudListener.t_lastEvent.Payload[0]);
|
||||
|
||||
log.EventFlags(MyFlags.Flag1);
|
||||
Assert.Equal(21, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(MyFlags.Flag1, (MyFlags)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(21, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(MyFlags.Flag1, (MyFlags)LoudListener.t_lastEvent.Payload[0]);
|
||||
|
||||
log.EventFlags1(MyFlags.Flag1);
|
||||
Assert.Equal(22, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal(MyFlags.Flag1, (MyFlags)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(22, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal(MyFlags.Flag1, (MyFlags)LoudListener.t_lastEvent.Payload[0]);
|
||||
#endregion
|
||||
|
||||
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
|
||||
@@ -167,7 +167,7 @@ namespace BasicEventSourceTests
|
||||
TestUtilities.CheckNoEventSourcesRunning("Start");
|
||||
using (var log = new EventSourceTest())
|
||||
{
|
||||
using (var el = new LoudListener())
|
||||
using (var el = new LoudListener(log))
|
||||
{
|
||||
// coverage for EventSource.SendCommand()
|
||||
var options = new Dictionary<string, string>() { { "arg", "val" } };
|
||||
@@ -192,16 +192,16 @@ namespace BasicEventSourceTests
|
||||
Assert.Equal(guid, (Guid)LoudListener.LastEvent.Payload[11]);
|
||||
#endif // USE_ETW
|
||||
log.EventWith7Strings("s0", "s1", "s2", "s3", "s4", "s5", "s6");
|
||||
Assert.Equal(26, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(7, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("s0", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal("s6", (string)LoudListener.LastEvent.Payload[6]);
|
||||
Assert.Equal(26, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(7, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("s0", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal("s6", (string)LoudListener.t_lastEvent.Payload[6]);
|
||||
|
||||
log.EventWith9Strings("s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8");
|
||||
Assert.Equal(27, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(9, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("s0", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal("s8", (string)LoudListener.LastEvent.Payload[8]);
|
||||
Assert.Equal(27, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(9, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("s0", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal("s8", (string)LoudListener.t_lastEvent.Payload[8]);
|
||||
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
|
||||
log.EventWithWeirdArgs(IntPtr.Zero, true, MyLongEnum.LongVal1 /*, 9999999999999999999999999999m*/);
|
||||
Assert.Equal(30, LoudListener.LastEvent.EventId);
|
||||
@@ -222,17 +222,17 @@ namespace BasicEventSourceTests
|
||||
TestUtilities.CheckNoEventSourcesRunning("Start");
|
||||
using (var log = new InvalidCallsToWriteEventEventSource())
|
||||
{
|
||||
using (var el = new LoudListener())
|
||||
using (var el = new LoudListener(log))
|
||||
{
|
||||
log.WriteTooManyArgs("Hello");
|
||||
Assert.Equal(2, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count); // Faked count (compat)
|
||||
Assert.Equal("Hello", LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); // Faked count (compat)
|
||||
Assert.Equal("Hello", LoudListener.t_lastEvent.Payload[0]);
|
||||
|
||||
log.WriteTooFewArgs(10, 100);
|
||||
Assert.Equal(1, LoudListener.LastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.LastEvent.Payload.Count); // Real # of args passed to WriteEvent
|
||||
Assert.Equal(10, LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.EventId);
|
||||
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count); // Real # of args passed to WriteEvent
|
||||
Assert.Equal(10, LoudListener.t_lastEvent.Payload[0]);
|
||||
}
|
||||
}
|
||||
TestUtilities.CheckNoEventSourcesRunning("Stop");
|
||||
@@ -243,10 +243,9 @@ namespace BasicEventSourceTests
|
||||
{
|
||||
TestUtilities.CheckNoEventSourcesRunning("Start");
|
||||
|
||||
using (var el = new LoudListener())
|
||||
using (var log = new SimpleEventSource())
|
||||
using (var el = new LoudListener(log))
|
||||
{
|
||||
el.EnableEvents(log, EventLevel.Verbose);
|
||||
log.WriteIntToAdmin(10);
|
||||
}
|
||||
TestUtilities.CheckNoEventSourcesRunning("Stop");
|
||||
@@ -320,7 +319,7 @@ namespace BasicEventSourceTests
|
||||
|
||||
using (var log = new EventSourceTest())
|
||||
{
|
||||
using (var el = new LoudListener())
|
||||
using (var el = new LoudListener(log))
|
||||
{
|
||||
// match any kwds == 0
|
||||
el.EnableEvents(log, 0, 0);
|
||||
@@ -329,21 +328,21 @@ namespace BasicEventSourceTests
|
||||
|
||||
// 1. Validate that the event fires when ETW event method called unconditionally
|
||||
log.EventWithEscapingMessage("Hello world!", 10);
|
||||
Assert.NotNull(LoudListener.LastEvent);
|
||||
Assert.Equal(2, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("Hello world!", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(10, (int)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.NotNull(LoudListener.t_lastEvent);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("Hello world!", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(10, (int)LoudListener.t_lastEvent.Payload[1]);
|
||||
|
||||
// reset LastEvent
|
||||
LoudListener.LastEvent = null;
|
||||
LoudListener.t_lastEvent = null;
|
||||
|
||||
// 2. Validate that the event fires when ETW event method call is guarded by IsEnabled
|
||||
if (log.IsEnabled(EventLevel.Informational, 0))
|
||||
log.EventWithEscapingMessage("Goodbye skies!", 100);
|
||||
Assert.NotNull(LoudListener.LastEvent);
|
||||
Assert.Equal(2, LoudListener.LastEvent.Payload.Count);
|
||||
Assert.Equal("Goodbye skies!", (string)LoudListener.LastEvent.Payload[0]);
|
||||
Assert.Equal(100, (int)LoudListener.LastEvent.Payload[1]);
|
||||
Assert.NotNull(LoudListener.t_lastEvent);
|
||||
Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count);
|
||||
Assert.Equal("Goodbye skies!", (string)LoudListener.t_lastEvent.Payload[0]);
|
||||
Assert.Equal(100, (int)LoudListener.t_lastEvent.Payload[1]);
|
||||
}
|
||||
}
|
||||
TestUtilities.CheckNoEventSourcesRunning("Stop");
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Library>
|
||||
<!-- TraceLogging tests need to be able to create this type using reflection. -->
|
||||
<Type Name="BasicEventSourceTests.UserData" Dynamic="Required All" />
|
||||
</Library>
|
||||
</Directives>
|
||||
@@ -40,5 +40,8 @@
|
||||
<Link>CommonTest\System\PlatformDetection.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user