Skip to content

Conversation

noahfalk
Copy link
Member

We've had EventSource serialization tests for a long time but EventPipe never got added to it. Unforetunately not testing EventPipe in this way previously meant that quite a few discrepancies between EventPipe and ETW went unnoticed. As a first step to documenting and/or resolving the problems I wanted to get EventPipe running in the same set of tests. I also did several other small fixes and improvements while doing the work.

  • EventPipeListener added as a new 3rd target for EventSource (in addition to EventListener and ETW which are there now)
  • Modified the Listener test abstraction so that EventPipe could also work
    • Removed assumption that providers can changed after the listener starts running
    • Added capability flags to indicate whether listeners supported certain kinds of serialization behavior
    • Worked around incomplete implementation of IDictionary for payloads in TraceEvent
  • Leveraged xunit theory attribute to avoid needing different top-level APIs for every listener configuration
  • Fixed EventTestHarness assert which had actual and expected values swapped
  • TestsWrite: Fixed mistaken call to Array.Equals with Assert.Equal so the test actually validates what it was supposed to
  • Removed ActiveIssue 88305 attribute which was already closed in the past.
  • Moved some test cases from TestsWriteEvent.Etw.cs to TestsWriteEvent.cs so that they can run for other listeners when supported.

We've had EventSource serialization tests for a long time but EventPipe never got added to it. Unforetunately not testing EventPipe in this way previously
meant that quite a few discrepancies between EventPipe and ETW went unnoticed. As a first step to documenting and/or resolving the problems I wanted
to get EventPipe running in the same set of tests. I also did several other small fixes and improvements while doing the work.

- EventPipeListener added as a new 3rd target for EventSource (in addition to EventListener and ETW which are there now)
- Modified the Listener test abstraction so that EventPipe could also work
  - Removed assumption that providers can changed after the listener starts running
  - Added capability flags to indicate whether listeners supported certain kinds of serialization behavior
  - Worked around incomplete implementation of IDictionary for payloads in TraceEvent
- Leveraged xunit theory attribute to avoid needing different top-level APIs for every listener configuration
- Fixed EventTestHarness assert which had actual and expected values swapped
- TestsWrite: Fixed mistaken call to Array.Equals with Assert.Equal so the test actually validates what it was supposed to
- Removed ActiveIssue 88305 attribute which was already closed in the past.
- Moved some test cases from TestsWriteEvent.Etw.cs to TestsWriteEvent.cs so that they can run for other listeners when supported.
@noahfalk
Copy link
Member Author

fyi @lateralusX

Copy link
Contributor

Tagging subscribers to this area: @tarekgh, @tommcdon, @steveisok
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@mdh1418 mdh1418 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we only want to test DynamicConfigChange on particular tests? Or would it be valuable to have both DynamicConfigChange and non DynamicConfigChange for all EventSource tests? Just curious when to test Start -> EventSourceCommand vs EventSourceCommand -> Start like how TestsUserErrors.cs uses the former in Test_BadTypes_Manifest_UserClass but uses the latter in Test_BadEventSource_MismatchedIds.

nit: inconsistency of one-line if blocks using/not-using curly braces + if( -> if (

<MicrosoftDiaSymReaderVersion>2.0.0</MicrosoftDiaSymReaderVersion>
<MicrosoftDiaSymReaderNativeVersion>17.10.0-beta1.24272.1</MicrosoftDiaSymReaderNativeVersion>
<TraceEventVersion>3.1.16</TraceEventVersion>
<MicrosoftDiagnosticsNetCoreClientVersion>0.2.621003</MicrosoftDiagnosticsNetCoreClientVersion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminded me that I added a modified copy of Microsoft.Diagnostics.NETCore.Client in the runtime to get the EventPipe tests at src/tests/tracing/eventpipe working for Android #64358. Were there any changes on the diagnostics side that are missing in runtime's local copy that EventPipeListener needs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't run into anything but I also didn't run the tests on Android during my local testing. If loopback DiagnosticsClient doesn't work there I'd probably just turn the tests off on that platform. The goal of the new testing was to validate the serialization works and all the serialization code should be identical regardless of platform/OS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it's reasonable to still reference the runtime's copy src/tests/tracing/eventpipe/common/Microsoft.Diagnostics.NETCore.Client in System.Diagnostics.Tracing.Tests.csproj. I wasn't particularly thinking about the test running on Android, more that #64358 removed this property so all tests would use the runtime copy. Reintroducing this property means there's some places that uses the runtimes copy and other places that uses the diagnostics copy.

I'm fine if we want to do that, I just recall that one of the previous debts was that the runtime copy would be bumped if there was new logic in the diagnostics copy, so I was just curious if there was something in 0.2.621003 that the local copy was missing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't need to run the serialization tests on all platforms and we mainly need the runtime version of the NETCore.Client on mobile platforms using TCP/IP, then maybe we should keep using runtime version for mobile platforms and turn of the serialization tests on those platforms. Alternative is to bring over whats missing into the runtime version of NETCore.Client (and probably turn off the serialization tests on mobile if it depends on spawning additional processes).

public void EventSourceSynchronousEnable(EventSource eventSource, FilteringOptions options = null)
{
if(!IsDynamicConfigChangeSupported)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit spacing

/// </summary>
[Fact]
public void Test_WriteEvent_ComplexData_SelfDescribing_EventListener()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

@noahfalk
Copy link
Member Author

Do we only want to test DynamicConfigChange on particular tests? Or would it be valuable to have both DynamicConfigChange and non DynamicConfigChange for all EventSource tests? Just curious when to test Start -> EventSourceCommand vs EventSourceCommand -> Start

I think there are a few parts to this and I believe they are still getting tested:

  1. What is the ordering of enabling the provider in respect to enabling the session. ETW and EventListener are enabling the session first and providers afterwards as they were before. Although the EventSourceCommand() calls occur before Start() the internal queueing means the commands get executed after the session already started.
  2. What is the ordering of enabling the provider relative to registering the EventSource - both orderings are tested.
  3. What is the ordering of disabling the provider relative to ending the session. The test disables one of the providers early to confirm the events aren't received but this is only done for ETW and EventListener since EventPipe doesn't support the dynamic config change.

@Copilot Copilot AI review requested due to automatic review settings October 20, 2025 22:41
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds EventPipe as a third event listener target alongside the existing EventListener and ETW implementations in the EventSource serialization tests. Previously, EventPipe was not tested through this framework, which allowed serialization discrepancies between EventPipe and ETW to go unnoticed.

Key Changes:

  • Added EventPipeListener implementation using DiagnosticsClient
  • Refactored test infrastructure to support multiple listener configurations via xunit Theory
  • Added capability flags for listener-specific serialization behaviors
  • Fixed several existing test issues and removed closed ActiveIssue attributes

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
System.Diagnostics.Tracing.Tests.csproj Added EventPipeListener.cs and Microsoft.Diagnostics.NetCore.Client package reference
TestsWriteEventToListener.cs Added listener.Start() calls to enable proper listener initialization
TestsWriteEvent.cs Converted individual test methods to Theory-based approach using GetListenerConfigurations(), added conditional test execution based on listener capabilities
TestsWriteEvent.Etw.cs Updated method signatures and removed ActiveIssue attributes for resolved issue #88305
TestsWrite.cs Converted to Theory-based tests, fixed Array.Equals/Assert.Equal bug, added listener capability checks
TestsWrite.Etw.cs Removed ActiveIssue attribute for resolved issue #88305
TestsUserErrors.cs Added listener.Start() calls for proper initialization
Listeners.cs Added Start() method, capability flags, pending command queue, and fixed IDictionary iteration bug
EventTestHarness.cs Updated to use new Start() pattern and fixed swapped Assert.Equal arguments
EventPipeListener.cs New EventPipeListener implementation for EventPipe event collection
EtwListener.cs Refactored to support pending command queue and added Start() method
Versions.props Added MicrosoftDiagnosticsNetCoreClientVersion property

@noahfalk noahfalk force-pushed the eventpipe_metadata_tests branch from cb628f6 to e83aebc Compare October 20, 2025 22:56
{
using (var listener = new EventListenerListener())
TheoryData<Listener> data = new TheoryData<Listener>();
if (PlatformDetection.IsNetCore && PlatformDetection.IsNotAndroid && PlatformDetection.IsNotBrowser && PlatformDetection.IsNotMonoRuntime)
Copy link
Member

@lateralusX lateralusX Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess EventPipe tests would work on Mono runtime desktop platforms, did it get excluded just because it was not tested or is there any know issues or limitations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I excluded it because it appeared DiagnosticClient(int pid) wasn't working to self-attach. Does that sound right or maybe I misinterpreted something?

Copy link
Member

@lateralusX lateralusX Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it won't work on EventPipe using TCP/IP (Android, iOS, WebAssembly) since it won't create an IPC channel based on PID + no default diagnostic listener, but for Mono desktop/maccatalyst it uses the same IPC implementation as CoreCLR by default, so I assume it should work. If it doesn't work on Mono desktop/maccatalyst, then I believe we should look into why, would be great to at least have one Mono platform running these tests as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants