perfview icon indicating copy to clipboard operation
perfview copied to clipboard

Add comprehensive test framework for TraceParserGen

Open Copilot opened this issue 3 months ago • 0 comments

Summary

This PR introduces a new test project TraceParserGen.Tests that implements a comprehensive test framework for validating TraceParserGen.exe.

Changes Made

Latest Updates

  • Removed FindInputDir method - Simplified to use Path.Combine(Environment.CurrentDirectory, "inputs") directly since inputs are copied to the output directory
  • Use ProjectReference for test apps - Changed from <Reference> tag to <ProjectReference> pointing to TraceEvent.csproj, ensuring all dependencies are included

Previous Updates

  • Simplified to net462 only - Changed from multi-targeting to just net462 since tests only need to run on Windows
  • Removed Windows platform check - No longer needed since net462 only runs on Windows
  • Removed TraceEvent ProjectReference from test project - Not needed in the test project itself
  • Use system TEMP directory - Changed to .NET's standard temp directory via Path.GetTempPath()
  • Simplified directory creation - Removed redundant check before Directory.CreateDirectory
  • Removed else path - Test app always creates a parser and processes a trace file
  • Enhanced test validation with real trace files - Uses TraceEventDispatcher.GetDispatcherFromFileName and hooks TraceEventParser.All
  • Removed --no-build flag - Test app rebuilds each time
  • Deterministic TraceParserGen.exe location - Added build target to copy TraceParserGen.exe to test output

Test Framework Features

The test framework validates the entire code generation pipeline:

  1. Runs TraceParserGen.exe with test input (ETW manifest files)
  2. Verifies successful generation of C# parser files
  3. Creates temporary console projects that:
    • Use ProjectReference to TraceEvent.csproj (found at runtime)
    • Include the generated parsers
    • Always use real trace files to validate event parsing
    • Hook All event to count processed events
  4. Builds and runs the temporary projects to ensure generated code works correctly

Benefits

  • Enables safe refactoring - Changes to TraceParserGen can now be validated automatically
  • Regression prevention - Catches breaking changes before they reach production
  • Real-world validation - Tests always use actual trace files to verify parsers work correctly
  • Proper dependency management - Uses ProjectReference to ensure all TraceEvent dependencies are included
  • Windows-focused - Targets net462 only, ensuring tests run in the correct environment
  • Clean and simple - Uses standard .NET patterns for temp directories and project structure
Original prompt

The repo contains an exe that we build from source called TraceParserGen. This exe is responsible for taking ETW manifests or DLLs containing EventSource implementations and building C# classes that implement parsers for the events defined in the manifest for EventSource. We do not currently have a set of test cases, which means that we are unable to make changes to TraceParserGen without breaking it.

I'd like you to build a project called TraceParserGen.Tests that implements a test framework for TraceParserGen. The test cases won't be standard in-app C# test cases, but instead will need to be able to do the following:

  1. Run the built copy of TraceParserGen.exe with test input (a manifest file or a C# EventSource dll).
  2. Ensure that TraceParserGen.exe successfully runs and generates a C# file.
  3. Create a temporary console project that depends on the TraceEvent (also built in the repo) and includes the newly generated C# file.
  4. Build the temporary project and run the resulting executable, making sure that no asserts or errors occur. NOTE: We likely won't have traces to run the parser against, but we can make sure that we don't run into any obvious C# failures.

I would like you to build the test framework and maybe a single sample test. For step 3, create a sample application that uses reflection to find all of the TraceEvent-based parsers that exist in the current assembly and then create an instance of each and subscribe to all of the events.

Expect that I will review this work and then provide additional coaching.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Oct 07 '25 00:10 Copilot