Imported Upstream version 5.16.0.100

Former-commit-id: 38faa55fb9669e35e7d8448b15c25dc447f25767
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-08-07 15:19:03 +00:00
parent 0a9828183b
commit 7d7f676260
4419 changed files with 170950 additions and 90273 deletions

View File

@@ -26,10 +26,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU

View File

@@ -407,7 +407,24 @@ namespace System.Diagnostics.Tracing
_pollingIntervalInMilliseconds = (int)(pollingIntervalInSeconds * 1000);
DisposeTimer();
_timeStampSinceCollectionStarted = DateTime.UtcNow;
_pollingTimer = new Timer(OnTimer, null, _pollingIntervalInMilliseconds, _pollingIntervalInMilliseconds);
// Don't capture the current ExecutionContext and its AsyncLocals onto the timer causing them to live forever
bool restoreFlow = false;
try
{
if (!ExecutionContext.IsFlowSuppressed())
{
ExecutionContext.SuppressFlow();
restoreFlow = true;
}
_pollingTimer = new Timer(s => ((EventCounterGroup)s).OnTimer(null), this, _pollingIntervalInMilliseconds, _pollingIntervalInMilliseconds);
}
finally
{
// Restore the current ExecutionContext
if (restoreFlow)
ExecutionContext.RestoreFlow();
}
}
// Always fire the timer event (so you see everything up to this time).
OnTimer(null);

View File

@@ -1 +1 @@
bb586b47b4037bb121d1552ff1fceefad32b929c
d149194d014719351966086d13bc2f8dcd7b84a7

View File

@@ -141,7 +141,7 @@ namespace BasicEventSourceTests
}
catch (Exception e)
{
if (e is EventSourceException)
if ((e is EventSourceException) && (e.InnerException != null))
e = e.InnerException;
LogWriteLine("Exception thrown: {0}", e.Message);

View File

@@ -2,7 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
using Microsoft.Diagnostics.Tracing;
using Microsoft.Diagnostics.Tracing.Session;
#endif
using System;
@@ -136,14 +137,14 @@ namespace BasicEventSourceTests
{
if (i != 0)
sb.Append(',');
sb.Append(PayloadString(i, null));
sb.Append(PayloadString(i, PayloadNames[i]));
}
sb.Append(')');
return sb.ToString();
}
}
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
/**************************************************************************/
/* Concrete implementation of the Listener abstraction */
@@ -165,7 +166,7 @@ namespace BasicEventSourceTests
// Today you have to be Admin to turn on ETW events (anyone can write ETW events).
if (TraceEventSession.IsElevated() != true)
{
throw new ApplicationException("Need to be elevated to run. ");
throw new Exception("Need to be elevated to run. ");
}
if (dataFileName == null)
@@ -214,6 +215,12 @@ namespace BasicEventSourceTests
public override void Dispose()
{
if(_disposed)
{
return;
}
_disposed = true;
_session.Flush();
Thread.Sleep(1010); // Let it drain.
_session.Dispose(); // This also will kill the real time thread
@@ -225,7 +232,6 @@ namespace BasicEventSourceTests
Debug.WriteLine("Processing data file " + Path.GetFullPath(_dataFileName));
// Parse all the events as best we can, and also send unhandled events there as well.
traceEventSource.Registered.All += OnEventHelper;
traceEventSource.Dynamic.All += OnEventHelper;
traceEventSource.UnhandledEvents += OnEventHelper;
// Process all the events in the file.
@@ -238,12 +244,23 @@ namespace BasicEventSourceTests
#region private
private void OnEventHelper(TraceEvent data)
{
// Ignore EventTrace events.
if (data.ProviderGuid == EventTraceProviderID)
return;
// Ignore kernel events.
if (data.ProviderGuid == KernelProviderID)
return;
// Ignore manifest events.
if ((int)data.ID == 0xFFFE)
return;
this.OnEvent(new EtwEvent(data));
}
private static readonly Guid EventTraceProviderID = new Guid("9e814aad-3204-11d2-9a82-006008a86939");
private static readonly Guid KernelProviderID = new Guid("9e814aad-3204-11d2-9a82-006008a86939");
/// <summary>
/// EtwEvent implements the 'Event' abstraction for ETW events (it has a TraceEvent in it)
/// </summary>
@@ -273,6 +290,7 @@ namespace BasicEventSourceTests
#endregion
}
private bool _disposed;
private string _dataFileName;
private volatile TraceEventSession _session;
#endregion
@@ -334,6 +352,12 @@ namespace BasicEventSourceTests
public override void Dispose()
{
if (_disposed)
{
return;
}
_disposed = true;
EventTestHarness.LogWriteLine("Disposing Listener");
_listener.Dispose();
}
@@ -438,5 +462,7 @@ namespace BasicEventSourceTests
return _data.Payload[propertyIndex];
}
}
private bool _disposed;
}
}

View File

@@ -30,5 +30,10 @@ namespace BasicEventSourceTests
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) : ""));
}
public static EventWrittenEventArgs LastEvent
{
get { return t_lastEvent; }
}
}
}

View File

@@ -8,7 +8,7 @@ using Microsoft.Diagnostics.Tracing;
#else
using System.Diagnostics.Tracing;
#endif
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue https://github.com/dotnet/corefx/issues/4864
#if USE_ETW
using Microsoft.Diagnostics.Tracing.Session;
#endif
using Xunit;
@@ -25,6 +25,12 @@ namespace BasicEventSourceTests
{
public class TestEventCounter
{
#if USE_ETW
// Specifies whether the process is elevated or not.
private static readonly Lazy<bool> s_isElevated = new Lazy<bool>(() => AdminHelpers.IsProcessElevated());
private static bool IsProcessElevated => s_isElevated.Value;
#endif // USE_ETW
private sealed class MyEventSource : EventSource
{
private EventCounter _requestCounter;
@@ -52,6 +58,7 @@ namespace BasicEventSourceTests
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, reason: "https://github.com/dotnet/corefx/issues/23661")]
#endif
[ActiveIssue("https://github.com/dotnet/corefx/issues/22791", TargetFrameworkMonikers.UapAot)]
[ActiveIssue("https://github.com/dotnet/corefx/issues/25029")]
public void Test_Write_Metric_EventListener()
{
using (var listener = new EventListenerListener())
@@ -61,7 +68,8 @@ namespace BasicEventSourceTests
}
#if USE_ETW
[Fact]
[ConditionalFact(nameof(IsProcessElevated))]
[ActiveIssue("https://github.com/dotnet/corefx/issues/27106")]
public void Test_Write_Metric_ETW()
{

View File

@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -13,7 +14,8 @@ using Microsoft.Diagnostics.Tracing;
using System.Diagnostics.Tracing;
#endif
using Xunit;
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
using Microsoft.Diagnostics.Tracing;
using Microsoft.Diagnostics.Tracing.Session;
#endif
using System.IO;
@@ -23,7 +25,9 @@ namespace BasicEventSourceTests
{
public class TestShutdown
{
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
// TODO: Depends on desktop APIs (AppDomainSetup and Evidence).
#if USE_ETW && FALSE
/// <summary>
/// Test for manifest event being logged during AD/Process shutdown during EventSource Dispose(bool) method.
/// </summary>
@@ -89,7 +93,6 @@ namespace BasicEventSourceTests
};
// Parse all the events as best we can, and also send unhandled events there as well.
traceEventSource.Registered.All += onEvent;
traceEventSource.Dynamic.All += onEvent;
traceEventSource.UnhandledEvent += onEvent;
traceEventSource.Process();

View File

@@ -15,6 +15,10 @@ namespace BasicEventSourceTests
{
internal class TestUtilities
{
// Specifies whether the process is elevated or not.
private static readonly Lazy<bool> s_isElevated = new Lazy<bool>(() => AdminHelpers.IsProcessElevated());
internal static bool IsProcessElevated => s_isElevated.Value;
/// <summary>
/// Confirms that there are no EventSources running.
/// </summary>

View File

@@ -104,9 +104,9 @@ namespace BasicEventSourceTests
() => EventSource.GenerateManifest(typeof(Sdt.TooManyChannelsEventSource), string.Empty));
#endif
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
e = AssertExtensions.Throws<ArgumentException>(GetResourceString("EventSource_EventWithAdminChannelMustHaveMessage", "WriteInteger", "Admin"),
() => EventSource.GenerateManifest(typeof(Sdt.EventWithAdminChannelNoMessageEventSource), string.Empty, strictOptions));
#if USE_ETW
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithAdminChannelNoMessageEventSource), string.Empty, strictOptions));
AsserExceptionStringsEqual(() => GetResourceString("EventSource_EventWithAdminChannelMustHaveMessage", "WriteInteger", "Admin"), e);
#endif // USE_ETW
e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions));

View File

@@ -74,35 +74,39 @@ namespace BasicEventSourceTests
[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.
#if USE_ETW
// We expect only one session to be on when running the test but if a ETW session was left
// hanging, it will confuse the EventListener tests.
EtwListener.EnsureStopped();
// hanging, it will confuse the EventListener tests.
if(TestUtilities.IsProcessElevated)
{
EtwListener.EnsureStopped();
}
#endif // USE_ETW
TestUtilities.CheckNoEventSourcesRunning("Start");
var onStartups = new bool[] { false, true };
var listenerGenerators = new Func<Listener>[]
{
() => new EventListenerListener(),
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
() => new EtwListener()
var listenerGenerators = new List<Func<Listener>>();
listenerGenerators.Add(() => new EventListenerListener());
#if USE_ETW
if(TestUtilities.IsProcessElevated)
{
listenerGenerators.Add(() => new EtwListener());
}
#endif // USE_ETW
};
var settings = new EventSourceSettings[] { EventSourceSettings.Default, EventSourceSettings.EtwSelfDescribingEventFormat };
var settings = new EventSourceSettings[] { EventSourceSettings.Default, EventSourceSettings.EtwSelfDescribingEventFormat };
// For every interesting combination, run the test and see that we get a nice failure message.
foreach (bool onStartup in onStartups)
// For every interesting combination, run the test and see that we get a nice failure message.
foreach (bool onStartup in onStartups)
{
foreach (Func<Listener> listenerGenerator in listenerGenerators)
{
foreach (EventSourceSettings setting in settings)
{
foreach (Func<Listener> listenerGenerator in listenerGenerators)
{
foreach (EventSourceSettings setting in settings)
{
Test_Bad_EventSource_Startup(onStartup, listenerGenerator(), setting);
}
}
Test_Bad_EventSource_Startup(onStartup, listenerGenerator(), setting);
}
}
}
TestUtilities.CheckNoEventSourcesRunning("Stop");

View File

@@ -13,7 +13,7 @@ using Microsoft.Diagnostics.Tracing;
using System.Diagnostics.Tracing;
#endif
using Xunit;
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
using Microsoft.Diagnostics.Tracing.Session;
#endif
using System.Diagnostics;
@@ -32,6 +32,12 @@ namespace BasicEventSourceTests
public class TestsWrite
{
#if USE_ETW
// Specifies whether the process is elevated or not.
private static readonly Lazy<bool> s_isElevated = new Lazy<bool>(() => AdminHelpers.IsProcessElevated());
private static bool IsProcessElevated => s_isElevated.Value;
#endif // USE_ETW
[EventData]
private struct PartB_UserInfo
{
@@ -63,12 +69,12 @@ namespace BasicEventSourceTests
Test_Write_T(new EventListenerListener(true));
}
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
/// <summary>
/// Tests the EventSource.Write[T] method (can only use the self-describing mechanism).
/// Tests the ETW code path
/// </summary>
[Fact]
[ConditionalFact(nameof(IsProcessElevated))]
public void Test_Write_T_ETW()
{
using (var listener = new EtwListener())
@@ -380,6 +386,27 @@ namespace BasicEventSourceTests
Assert.Equal(evt.PayloadValue(1, "b"), "");
}));
#if USE_ETW
// This test only applies to ETW and will fail on EventListeners due to different behavior
// for strings with embedded NULL characters.
if (listener is EtwListener)
{
tests.Add(new SubTest("Write/Basic/WriteOfTWithEmbeddedNullString",
delegate ()
{
string nullString = null;
logger.Write("EmbeddedNullStringEvent", new { a = "Hello" + '\0' + "World!", b = nullString });
},
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EmbeddedNullStringEvent", evt.EventName);
Assert.Equal(evt.PayloadValue(0, "a"), "Hello");
Assert.Equal(evt.PayloadValue(1, "b"), "");
}));
}
#endif // USE_ETW
Guid activityId = new Guid("00000000-0000-0000-0000-000000000001");
Guid relActivityId = new Guid("00000000-0000-0000-0000-000000000002");
tests.Add(new SubTest("Write/Basic/WriteOfTWithOptios",
@@ -414,21 +441,25 @@ namespace BasicEventSourceTests
/// </summary>
[Fact]
[ActiveIssue("dotnet/corefx #18806", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue("https://github.com/dotnet/corefx/issues/27106")]
public void Test_Write_T_In_Manifest_Serialization()
{
using (var eventListener = new EventListenerListener())
{
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
using (var etwListener = new EtwListener())
#if USE_ETW
EtwListener etwListener = null;
#endif
try
{
var listenerGenerators = new Func<Listener>[]
var listenerGenerators = new List<Func<Listener>>();
listenerGenerators.Add(() => eventListener);
#if USE_ETW
if(IsProcessElevated)
{
() => eventListener,
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
() => etwListener
etwListener = new EtwListener();
listenerGenerators.Add(() => etwListener);
}
#endif // USE_ETW
};
foreach (Func<Listener> listenerGenerator in listenerGenerators)
{
@@ -453,6 +484,15 @@ namespace BasicEventSourceTests
Assert.Equal("hi", (string)_event.PayloadValue(1, "arg2"));
}
}
finally
{
#if USE_ETW
if(etwListener != null)
{
etwListener.Dispose();
}
#endif // USE_ETW
}
}
}

View File

@@ -24,12 +24,16 @@ namespace BasicEventSourceTests
{
public class TestsWriteEvent
{
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
// Specifies whether the process is elevated or not.
private static readonly Lazy<bool> s_isElevated = new Lazy<bool>(() => AdminHelpers.IsProcessElevated());
private static bool IsProcessElevated => s_isElevated.Value;
/// <summary>
/// Tests WriteEvent using the manifest based mechanism.
/// Tests the ETW path.
/// </summary>
[Fact]
[ConditionalFact(nameof(IsProcessElevated))]
public void Test_WriteEvent_Manifest_ETW()
{
using (var listener = new EtwListener())
@@ -62,12 +66,12 @@ namespace BasicEventSourceTests
{
Test_WriteEvent(new EventListenerListener(true), false);
}
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
/// <summary>
/// Tests WriteEvent using the self-describing mechanism.
/// Tests both the ETW and TraceListener paths.
/// </summary>
[Fact]
[ConditionalFact(nameof(IsProcessElevated))]
public void Test_WriteEvent_SelfDescribing_ETW()
{
using (var listener = new EtwListener())
@@ -156,23 +160,26 @@ namespace BasicEventSourceTests
Assert.Equal(evt.PayloadValue(0, "arg1"), "one");
Assert.Equal(evt.PayloadValue(1, "arg2"), "two");
}));
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
/*************************************************************************/
tests.Add(new SubTest("Write/Basic/EventWithManyTypeArgs",
delegate ()
{
logger.EventWithManyTypeArgs("Hello", 1, 2, 3, 'a', 4, 5, 6, 7,
(float)10.0, (double)11.0, logger.Guid);
},
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventWithManyTypeArgs", evt.EventName);
Assert.Equal("Hello", evt.PayloadValue(0, "msg"));
Assert.Equal((float)10.0, evt.PayloadValue(9, "f"));
Assert.Equal((double)11.0, evt.PayloadValue(10, "d"));
Assert.Equal(logger.Guid, evt.PayloadValue(11, "guid"));
}));
if(IsProcessElevated)
{
tests.Add(new SubTest("Write/Basic/EventWithManyTypeArgs",
delegate ()
{
logger.EventWithManyTypeArgs("Hello", 1, 2, 3, 'a', 4, 5, 6, 7,
(float)10.0, (double)11.0, logger.Guid);
},
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventWithManyTypeArgs", evt.EventName);
Assert.Equal("Hello", evt.PayloadValue(0, "msg"));
Assert.Equal((float)10.0, evt.PayloadValue(9, "f"));
Assert.Equal((double)11.0, evt.PayloadValue(10, "d"));
Assert.Equal(logger.Guid, evt.PayloadValue(11, "guid"));
}));
}
#endif // USE_ETW
/*************************************************************************/
tests.Add(new SubTest("Write/Basic/EventWith7Strings",
@@ -200,29 +207,32 @@ namespace BasicEventSourceTests
Assert.Equal("s0", (string)evt.PayloadValue(0, "s0"));
Assert.Equal("s8", (string)evt.PayloadValue(8, "s8"));
}));
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
/*************************************************************************/
tests.Add(new SubTest("Write/Activity/EventWithXferWeirdArgs",
delegate ()
{
var actid = Guid.NewGuid();
logger.EventWithXferWeirdArgs(actid,
(IntPtr)128,
true,
SdtEventSources.MyLongEnum.LongVal1);
},
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
if(IsProcessElevated)
{
tests.Add(new SubTest("Write/Activity/EventWithXferWeirdArgs",
delegate ()
{
var actid = Guid.NewGuid();
logger.EventWithXferWeirdArgs(actid,
(IntPtr)128,
true,
SdtEventSources.MyLongEnum.LongVal1);
},
delegate (Event evt)
{
Assert.Equal(logger.Name, evt.ProviderName);
// We log EventWithXferWeirdArgs in one case and
// WorkWeirdArgs/Send in the other
Assert.True(evt.EventName.Contains("WeirdArgs"));
// We log EventWithXferWeirdArgs in one case and
// WorkWeirdArgs/Send in the other
Assert.True(evt.EventName.Contains("WeirdArgs"));
Assert.Equal("128", evt.PayloadValue(0, "iptr").ToString());
Assert.Equal(true, (bool)evt.PayloadValue(1, "b"));
Assert.Equal((long)SdtEventSources.MyLongEnum.LongVal1, (long)evt.PayloadValue(2, "le"));
}));
Assert.Equal("128", evt.PayloadValue(0, "iptr").ToString());
Assert.Equal(true, (bool)evt.PayloadValue(1, "b"));
Assert.Equal((long)SdtEventSources.MyLongEnum.LongVal1, ((IConvertible)evt.PayloadValue(2, "le")).ToInt64(null));
}));
}
#endif // USE_ETW
/*************************************************************************/
/*************************** ENUM TESTING *******************************/
@@ -239,7 +249,7 @@ namespace BasicEventSourceTests
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventEnum", evt.EventName);
Assert.Equal(1, (int)evt.PayloadValue(0, "x"));
Assert.Equal(1, ((IConvertible)evt.PayloadValue(0, "x")).ToInt32(null));
if (evt.IsEtw && !useSelfDescribingEvents)
Assert.Equal("Blue", evt.PayloadString(0, "x"));
}));
@@ -254,7 +264,7 @@ namespace BasicEventSourceTests
Assert.Equal(logger.Name, evt.ProviderName);
Assert.Equal("EventEnum1", evt.EventName);
Assert.Equal(1, (int)evt.PayloadValue(0, "x"));
Assert.Equal(1, ((IConvertible)evt.PayloadValue(0, "x")).ToInt32(null));
if (evt.IsEtw && !useSelfDescribingEvents)
Assert.Equal("Blue", evt.PayloadString(0, "x"));
}));
@@ -363,7 +373,12 @@ namespace BasicEventSourceTests
Assert.Equal("", evt.PayloadValue(2, null));
}));
if (useSelfDescribingEvents)
// Self-describing ETW does not support NULL arguments.
if (useSelfDescribingEvents
#if USE_ETW
&& !(listener is EtwListener)
#endif // USE_ETW
)
{
tests.Add(new SubTest("WriteEvent/Basic/EventVarArgsWithString",
delegate () { logger.EventVarArgsWithString(1, 2, 12, null); },
@@ -430,12 +445,12 @@ namespace BasicEventSourceTests
}
}
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
/// <summary>
/// Tests sending complex data (class, arrays etc) from WriteEvent
/// Tests the EventListener case
/// </summary>
[Fact]
[ConditionalFact(nameof(IsProcessElevated))]
public void Test_WriteEvent_ComplexData_SelfDescribing_ETW()
{
using (var listener = new EtwListener())
@@ -519,13 +534,13 @@ namespace BasicEventSourceTests
Test_WriteEvent_ByteArray(false, new EventListenerListener(true));
}
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
/// <summary>
/// Tests sending complex data (class, arrays etc) from WriteEvent
/// Uses Manifest format
/// Tests the EventListener case
/// </summary>
[Fact]
[ConditionalFact(nameof(IsProcessElevated))]
public void Test_WriteEvent_ByteArray_Manifest_ETW()
{
using (var listener = new EtwListener())
@@ -549,13 +564,13 @@ namespace BasicEventSourceTests
}
}
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
/// <summary>
/// Tests sending complex data (class, arrays etc) from WriteEvent
/// Uses Self-Describing format
/// Tests the EventListener case
/// </summary>
[Fact]
[ConditionalFact(nameof(IsProcessElevated))]
public void Test_WriteEvent_ByteArray_SelfDescribing_ETW()
{
using (var listener = new EtwListener())
@@ -647,6 +662,8 @@ namespace BasicEventSourceTests
Assert.Equal(1000, (long)evt.PayloadValue(1, "lng"));
}));
/* TODO: NULL byte array does not seem to be supported.
* An EventSourceMessage event is written for this case.
tests.Add(new SubTest("Write/Array/EventWithNullByteArray",
delegate ()
{
@@ -664,6 +681,7 @@ namespace BasicEventSourceTests
Assert.Equal(0, (int)evt.PayloadValue(1, "n"));
}
}));
*/
tests.Add(new SubTest("Write/Array/EventWithEmptyByteArray",
delegate ()

View File

@@ -19,6 +19,12 @@ namespace BasicEventSourceTests
{
public class TestsWriteEventToListener
{
#if USE_ETW
// Specifies whether the process is elevated or not.
private static readonly Lazy<bool> s_isElevated = new Lazy<bool>(() => AdminHelpers.IsProcessElevated());
private static bool IsProcessElevated => s_isElevated.Value;
#endif // USE_ETW
[Fact]
[ActiveIssue("dotnet/corefx #19462", TargetFrameworkMonikers.NetFramework)]
public void Test_WriteEvent_ArgsBasicTypes()
@@ -38,7 +44,7 @@ namespace BasicEventSourceTests
Assert.Equal(1, LoudListener.t_lastEvent.EventId);
Assert.Equal(0, LoudListener.t_lastEvent.Payload.Count);
#region Validate "int" arguments
#region Validate "int" arguments
log.EventI(10);
Assert.Equal(2, LoudListener.t_lastEvent.EventId);
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
@@ -56,9 +62,9 @@ namespace BasicEventSourceTests
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
#endregion
#region Validate "long" arguments
#region Validate "long" arguments
log.EventL(10);
Assert.Equal(5, LoudListener.t_lastEvent.EventId);
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
@@ -77,9 +83,9 @@ namespace BasicEventSourceTests
Assert.Equal(11, (long)LoudListener.t_lastEvent.Payload[1]);
Assert.Equal(12, (long)LoudListener.t_lastEvent.Payload[2]);
#endregion
#endregion
#region Validate "string" arguments
#region Validate "string" arguments
log.EventS("10");
Assert.Equal(8, LoudListener.t_lastEvent.EventId);
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
@@ -97,17 +103,17 @@ namespace BasicEventSourceTests
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
#endregion
#region Validate byte array arguments
#region Validate byte array arguments
byte[] arr = new byte[20];
log.EventWithByteArray(arr);
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
#endregion
#region Validate mixed type arguments
#region Validate mixed type arguments
log.EventSI("10", 11);
Assert.Equal(11, LoudListener.t_lastEvent.EventId);
Assert.Equal(2, LoudListener.t_lastEvent.Payload.Count);
@@ -126,9 +132,9 @@ namespace BasicEventSourceTests
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
#endregion
#region Validate enums/flags
#region Validate enums/flags
log.EventEnum(MyColor.Blue);
Assert.Equal(19, LoudListener.t_lastEvent.EventId);
Assert.Equal(1, LoudListener.t_lastEvent.Payload.Count);
@@ -148,16 +154,16 @@ namespace BasicEventSourceTests
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
#endregion
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#region Validate DateTime
#if USE_ETW
#region Validate DateTime
DateTime now = DateTime.Now;
log.EventDateTime(now);
Assert.Equal(24, LoudListener.LastEvent.EventId);
Assert.Equal(1, LoudListener.LastEvent.Payload.Count);
Assert.Equal((DateTime)LoudListener.LastEvent.Payload[0], now);
#endregion
#endregion
#endif // USE_ETW
}
}
@@ -178,7 +184,7 @@ namespace BasicEventSourceTests
EventSource.SendCommand(log, EventCommand.SendManifest, options);
Guid guid = Guid.NewGuid();
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
#if USE_ETW
log.EventWithManyTypeArgs("Hello", 0, 0, 0, 'a', 0, 0, 0, 0, (float)10.0, (double)11.0, guid);
Assert.Equal(25, LoudListener.LastEvent.EventId);
Assert.Equal(12, LoudListener.LastEvent.Payload.Count);
@@ -206,7 +212,7 @@ namespace BasicEventSourceTests
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.
#if USE_ETW
log.EventWithWeirdArgs(IntPtr.Zero, true, MyLongEnum.LongVal1 /*, 9999999999999999999999999999m*/);
Assert.Equal(30, LoudListener.LastEvent.EventId);
Assert.Equal(3 /*4*/, LoudListener.LastEvent.Payload.Count);
@@ -255,14 +261,14 @@ namespace BasicEventSourceTests
TestUtilities.CheckNoEventSourcesRunning("Stop");
}
#if USE_ETW // TODO: Enable when TraceEvent is available on CoreCLR. GitHub issue #4864.
[Fact]
#if USE_ETW
[ConditionalFact(nameof(IsProcessElevated))]
public void Test_WriteEvent_TransferEvents()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
using (var log = new EventSourceTest())
{
using (var el = new LoudListener())
using (var el = new LoudListener(log))
{
Guid actid = Guid.NewGuid();
log.LogTaskScheduled(actid, "Hello from a test");
@@ -352,7 +358,7 @@ namespace BasicEventSourceTests
TestUtilities.CheckNoEventSourcesRunning("Stop");
}
#if FEATURE_ETLEVENTS
#if FEATURE_ETLEVENTS
[Fact]
public void Test_EventSourceCreatedEvents_BeforeListener()
{

View File

@@ -2,8 +2,8 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
netstandard;
netcoreapp-Windows_NT;
netcoreapp-Unix;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -137,13 +137,12 @@ namespace SdtEventSources
public void EventDateTime(DateTime dt) { WriteEvent(24, dt); }
[Event(25, Keywords = Keywords.HasNoArgs, Level = EventLevel.Informational)]
public void EventWithManyTypeArgs(string msg, long l, uint ui, UInt64 ui64,
public void EventWithManyTypeArgs(string msg, long l, uint ui, UInt64 ui64, char c,
byte b, sbyte sb, short sh, ushort ush,
float f, double d, Guid guid)
{
if (IsEnabled(EventLevel.Informational, Keywords.HasNoArgs))
// 4.5 EventSource does not support "Char" type
WriteEvent(25, msg, l, ui, ui64, b, sb, sh, ush, f, d, guid);
WriteEvent(25, msg, l, ui, ui64, c, b, sb, sh, ush, f, d, guid);
}
[Event(26)]

View File

@@ -5,12 +5,13 @@
<ProjectGuid>{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}</ProjectGuid>
<DefineConstants Condition="'$(TargetGroup)' == 'netcoreapp'">$(DefineConstants);FEATURE_ETLEVENTS</DefineConstants>
<DefineConstants Condition="'$(TargetGroup)' == 'netcoreapp'">$(DefineConstants);FEATURE_EVENTCOUNTER_DISPOSE</DefineConstants>
<DefineConstants Condition="'$(TargetGroup)' == 'netcoreapp' And '$(TargetsWindows)' == 'true'">$(DefineConstants);USE_ETW</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="BasicEventSourceTest\Harness\EventTestHarness.cs" />
<Compile Include="BasicEventSourceTest\FuzzyTests.cs" />
@@ -38,6 +39,9 @@
<Compile Include="CustomEventSources\UseAbstractEventSource.cs" />
<Compile Include="CustomEventSources\UseInterfaceEventSource.cs" />
</ItemGroup>
<ItemGroup>
<ReferenceFromRuntime Include="Microsoft.Diagnostics.Tracing.TraceEvent" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
</ItemGroup>