Skip to content

Commit acf1c28

Browse files
committed
[Tests] Add basic UserEvents scenario
1 parent dd4ee67 commit acf1c28

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

src/tests/tracing/userevents/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This directory contains **functional tests** for the .NET user_events scenario.
44

55
## High-level Test Flow
66

7-
Each scenario uses the same pattern:
7+
Each scenario (for example, `basic`) uses the same pattern:
88

99
1. **Scenario invokes the shared test runner**
1010

@@ -26,4 +26,4 @@ Each scenario uses the same pattern:
2626
- `<scenario>.csproj` - Project file for the scenario.
2727
- `<scenario>.script` - `record-trace` script that configures how to collect the trace for the scenario.
2828

29-
Each scenario reuses the common runner and shared `record-trace` deployable instead of duplicating binaries or orchestration logic.
29+
Each scenario reuses the common runner and shared `record-trace` deployable instead of duplicating binaries or orchestration logic. The `basic` scenario serves as a concrete example of how to add additional scenarios.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Diagnostics;
6+
using System.Threading;
7+
using Tracing.UserEvents.Tests.Common;
8+
using Microsoft.Diagnostics.Tracing;
9+
10+
namespace Tracing.UserEvents.Tests.Basic
11+
{
12+
public class Basic
13+
{
14+
private static byte[] s_array;
15+
16+
public static void BasicTracee()
17+
{
18+
long startTimestamp = Stopwatch.GetTimestamp();
19+
long targetTicks = Stopwatch.Frequency; // 1s
20+
21+
while (Stopwatch.GetTimestamp() - startTimestamp < targetTicks)
22+
{
23+
s_array = new byte[1024 * 100];
24+
Thread.Sleep(100);
25+
}
26+
}
27+
28+
private readonly static Func<EventPipeEventSource, bool> s_traceValidator = source =>
29+
{
30+
bool allocationSampledEventFound = false;
31+
32+
source.Dynamic.All += (TraceEvent e) =>
33+
{
34+
if (e.ProviderName == "Microsoft-Windows-DotNETRuntime")
35+
{
36+
// TraceEvent's ClrTraceEventParser does not know about the AllocationSampled Event, so it shows up as "Unknown(303)"
37+
if (e.EventName.StartsWith("Unknown") && e.ID == (TraceEventID)303)
38+
{
39+
allocationSampledEventFound = true;
40+
}
41+
}
42+
};
43+
44+
source.Process();
45+
46+
if (!allocationSampledEventFound)
47+
{
48+
Console.Error.WriteLine("The trace did not contain an AllocationSampled event.");
49+
}
50+
return allocationSampledEventFound;
51+
};
52+
53+
public static int Main(string[] args)
54+
{
55+
if (args.Length > 0 && args[0].Equals("tracee", StringComparison.OrdinalIgnoreCase))
56+
{
57+
BasicTracee();
58+
return 0;
59+
}
60+
61+
return UserEventsTestRunner.Run("basic", typeof(Basic).Assembly.Location, s_traceValidator);
62+
}
63+
}
64+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<CLRTestTargetUnsupported Condition="'$(TargetOS)' != 'linux' or ('$(TargetArchitecture)' != 'x64' and '$(TargetArchitecture)' != 'arm64')">true</CLRTestTargetUnsupported>
4+
<RequiresProcessIsolation>true</RequiresProcessIsolation>
5+
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="$(MSBuildProjectName).cs" />
10+
<ProjectReference Include="../common/userevents_common.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<Content Include="basic.script">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
<TargetPath>basic.script</TargetPath>
17+
</Content>
18+
</ItemGroup>
19+
</Project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let Microsoft_Windows_DotNETRuntime_flags = new_dotnet_provider_flags();
2+
record_dotnet_provider("Microsoft-Windows-DotNETRuntime", 0x80000000000, 4, Microsoft_Windows_DotNETRuntime_flags);

0 commit comments

Comments
 (0)