-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EventSource Manifest Trimmer test (#56463)
* EventSource Manifest Trimmer test * FB
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/libraries/System.Diagnostics.Tracing/tests/TrimmingTests/EventSourceManifestTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Diagnostics.Tracing; | ||
using System.Linq; | ||
using System; | ||
|
||
/// <summary> | ||
/// Tests that using an EventSource to get the manifest works without method references in a trimmed application. | ||
/// EventSource has DynamicallyAccessedMembersAttribute applied at class level which means derived types keeps members | ||
/// </summary> | ||
internal class Program | ||
{ | ||
internal class EventSourceTest : EventSource | ||
{ | ||
public void EventSourceTest_Method_0() => WriteEvent(1); | ||
|
||
public void EventSourceTest_Method_1(int value) => WriteEvent(2, value); | ||
void EventSourceTest_Method_2(string name) => WriteEvent(3, name); | ||
|
||
[NonEvent] | ||
public void EventSourceTest_Method_3(int num1, int num2) => WriteEvent(4, num1, num2); | ||
[NonEvent] | ||
void EventSourceTest_Method_4(){} | ||
|
||
[Event(500)] | ||
public void EventSourceTest_Method_5(byte[] bytes) => WriteEvent(500, bytes); | ||
[Event(1500)] | ||
protected virtual void EventSourceTest_Method_6(long value) => WriteEvent(1500, value); | ||
|
||
[Event(2500)] | ||
int EventSourceTest_Method_7() => 5; | ||
} | ||
|
||
public static int Main() | ||
{ | ||
string manifest = EventSource.GenerateManifest(typeof(EventSourceTest), null); | ||
// we are going to avoid as much as possible program constructs that could give the trimmer reasons to keep members | ||
const string baseMethodName = "EventSourceTest_Method_"; | ||
int[] exclusions = { 3, 4, 8 }; | ||
for (int i = 0; i <= 8; i++) | ||
{ | ||
string methodName = $"{baseMethodName}{i}"; | ||
// We expect the methodName to be in the manifest unless the prefix, i, is in exclusions ([NonEvent] or non-existing methods) | ||
bool methodExists = manifest.Contains(methodName); | ||
bool shouldMethodExist = !exclusions.Contains(i); | ||
if (methodExists != shouldMethodExist) | ||
{ | ||
return -1; | ||
} | ||
} | ||
|
||
return 100; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...tem.Diagnostics.Tracing/tests/TrimmingTests/System.Diagnostics.Tracing.TrimmingTests.proj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
<Project DefaultTargets="Build"> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" /> | ||
|
||
<ItemGroup> | ||
<TestConsoleAppSourceFiles Include="EventSourcePropertyValueTest.cs" /> | ||
<TestConsoleAppSourceFiles Include="EventSourceManifestTest.cs" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" /> | ||
</Project> |