Skip to content

Commit

Permalink
[tests] Duplicate Microsoft.Diagnostics.NETCore.Client dependent test…
Browse files Browse the repository at this point in the history
…s for Linux arm
  • Loading branch information
mdh1418 committed Feb 24, 2022
1 parent 9b58954 commit cb2cacd
Show file tree
Hide file tree
Showing 36 changed files with 1,610 additions and 135 deletions.
7 changes: 0 additions & 7 deletions src/tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,5 @@
<TestFramework>GeneratedRunner</TestFramework>
</PropertyGroup>

<PropertyGroup>
<!-- On Linux arm coreclr, the updated tracing/eventpipe/common/Microsoft.Diagnostics.NETCore.Client/Microsoft.Diagnostics.NETCore.Client.csproj project
does not yet work for several eventpipe runtime tests. We segment those tests with the following property and symbol -->
<UseUpdatedNETCoreClient Condition="!('$(TargetOS)' == 'Linux' And '$(TargetArchitecture)' == 'arm' And '$(RuntimeFlavor)' == 'coreclr')">true</UseUpdatedNETCoreClient>
<DefineConstants Condition="'$(UseUpdatedNETCoreClient)' == 'true'">$(DefineConstants);UPDATED_NETCORE_CLIENT</DefineConstants>
</PropertyGroup>

<Import Project="$(RepositoryEngineeringDir)testing\tests.props" Condition="'$(IsTestsCommonProject)' != 'true'" />
</Project>
20 changes: 0 additions & 20 deletions src/tests/JIT/Directed/debugging/debuginfo/tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
#if UPDATED_NETCORE_CLIENT
using Microsoft.Diagnostics.NETCore.Client;
#else
using Microsoft.Diagnostics.Tools.RuntimeClient;
#endif
using Microsoft.Diagnostics.Tracing;
using Microsoft.Diagnostics.Tracing.Parsers;
using Microsoft.Diagnostics.Tracing.Parsers.Clr;
Expand All @@ -27,7 +23,6 @@ public static unsafe int Main()
var keywords =
ClrTraceEventParser.Keywords.Jit | ClrTraceEventParser.Keywords.JittedMethodILToNativeMap;

#if UPDATED_NETCORE_CLIENT
var dotnetRuntimeProvider = new List<EventPipeProvider>
{
new EventPipeProvider("Microsoft-Windows-DotNETRuntime", eventLevel: EventLevel.Verbose, keywords: (long)keywords)
Expand All @@ -40,21 +35,6 @@ public static unsafe int Main()
dotnetRuntimeProvider,
1024,
ValidateMappings);
#else
var dotnetRuntimeProvider = new List<Provider>
{
new Provider("Microsoft-Windows-DotNETRuntime", eventLevel: EventLevel.Verbose, keywords: (ulong)keywords)
};

var config = new SessionConfiguration(1024, EventPipeSerializationFormat.NetTrace, dotnetRuntimeProvider);

return
IpcTraceTest.RunAndValidateEventCounts(
new Dictionary<string, ExpectedEventCount>(),
JitMethods,
config,
ValidateMappings);
#endif
}

private static void JitMethods()
Expand Down
2 changes: 1 addition & 1 deletion src/tests/JIT/Directed/debugging/debuginfo/tester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ProjectReference Include="tests_r.ilproj" Aliases="tests_r" />
<ProjectReference Include="attribute.csproj" />
<ProjectReference Include="../../../../tracing/eventpipe/common/common.csproj" />
<ProjectReference Condition="'$(UseUpdatedNETCoreClient)' == 'true'" Include="../../../../tracing/eventpipe/common/Microsoft.Diagnostics.NETCore.Client/Microsoft.Diagnostics.NETCore.Client.csproj" />
<ProjectReference Include="../../../../tracing/eventpipe/common/Microsoft.Diagnostics.NETCore.Client/Microsoft.Diagnostics.NETCore.Client.csproj" />
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
152 changes: 152 additions & 0 deletions src/tests/JIT/Directed/debugging/debuginfo/tester_legacy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
extern alias tests_d;
extern alias tests_r;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using Microsoft.Diagnostics.Tools.RuntimeClient;
using Microsoft.Diagnostics.Tracing;
using Microsoft.Diagnostics.Tracing.Parsers;
using Microsoft.Diagnostics.Tracing.Parsers.Clr;
using Tracing.Tests.Common;
using DebugInfoMethodsD = tests_d::DebugInfoMethods;
using DebugInfoMethodsR = tests_r::DebugInfoMethods;

public unsafe class DebugInfoTest
{
public static unsafe int Main()
{
var keywords =
ClrTraceEventParser.Keywords.Jit | ClrTraceEventParser.Keywords.JittedMethodILToNativeMap;

var dotnetRuntimeProvider = new List<Provider>
{
new Provider("Microsoft-Windows-DotNETRuntime", eventLevel: EventLevel.Verbose, keywords: (ulong)keywords)
};

var config = new SessionConfiguration(1024, EventPipeSerializationFormat.NetTrace, dotnetRuntimeProvider);

return
IpcTraceTest.RunAndValidateEventCounts(
new Dictionary<string, ExpectedEventCount>(),
JitMethods,
config,
ValidateMappings);
}

private static void JitMethods()
{
ProcessType(typeof(DebugInfoMethodsD));
ProcessType(typeof(DebugInfoMethodsR));
}

private static void ProcessType(Type t)
{
foreach (MethodInfo mi in t.GetMethods())
{
if (mi.GetCustomAttribute<ExpectedILMappings>() != null)
{
RuntimeHelpers.PrepareMethod(mi.MethodHandle);
}
}
}

private static Func<int> ValidateMappings(EventPipeEventSource source)
{
List<(long MethodID, OptimizationTier Tier, (int ILOffset, int NativeOffset)[] Mappings)> methodsWithMappings = new();
Dictionary<long, OptimizationTier> methodTier = new();

source.Clr.MethodLoad += e => methodTier[e.MethodID] = e.OptimizationTier;
source.Clr.MethodLoadVerbose += e => methodTier[e.MethodID] = e.OptimizationTier;
source.Clr.MethodILToNativeMap += e =>
{
if (e.MethodID == 0)
return;
var mappings = new (int, int)[e.CountOfMapEntries];
for (int i = 0; i < mappings.Length; i++)
mappings[i] = (e.ILOffset(i), e.NativeOffset(i));
if (!methodTier.TryGetValue(e.MethodID, out OptimizationTier tier))
tier = OptimizationTier.Unknown;
methodsWithMappings.Add((e.MethodID, tier, mappings));
};

return () =>
{
int result = 100;
foreach ((long methodID, OptimizationTier tier, (int ILOffset, int NativeOffset)[] mappings) in methodsWithMappings)
{
MethodBase meth = s_getMethodBaseByHandle(null, (IntPtr)(void*)methodID);
ExpectedILMappings attrib = meth.GetCustomAttribute<ExpectedILMappings>();
if (attrib == null)
{
continue;
}
string name = $"[{meth.DeclaringType.Assembly.GetName().Name}]{meth.DeclaringType.FullName}.{meth.Name}";
// If DebuggableAttribute is saying that the assembly must be debuggable, then verify debug mappings.
// Otherwise verify release mappings.
// This may seem a little strange since we do not use the tier at all -- however, we expect debug
// to never tier and in release, we expect the release mappings to be the "least common denominator",
// i.e. tier0 and tier1 mappings should both be a superset.
// Note that tier0 and MinOptJitted differs in mappings generated exactly due to DebuggableAttribute.
DebuggableAttribute debuggableAttrib = meth.DeclaringType.Assembly.GetCustomAttribute<DebuggableAttribute>();
bool debuggableMappings = debuggableAttrib != null && debuggableAttrib.IsJITOptimizerDisabled;
Console.WriteLine("{0}: Validate mappings for {1} codegen (tier: {2})", name, debuggableMappings ? "debuggable" : "optimized", tier);
int[] expected = debuggableMappings ? attrib.Debug : attrib.Opts;
if (expected == null)
{
continue;
}
if (!ValidateSingle(expected, mappings))
{
Console.WriteLine(" Validation failed: expected mappings at IL offsets {0}", string.Join(", ", expected.Select(il => $"{il:x3}")));
Console.WriteLine(" Actual (IL <-> native):");
foreach ((int ilOffset, int nativeOffset) in mappings)
{
string ilOffsetName = Enum.IsDefined((SpecialILOffset)ilOffset) ? ((SpecialILOffset)ilOffset).ToString() : $"{ilOffset:x3}";
Console.WriteLine(" {0:x3} <-> {1:x3}", ilOffsetName, nativeOffset);
}
result = -1;
}
}
return result;
};
}

// Validate that all IL offsets we expected had mappings generated for them.
private static bool ValidateSingle(int[] expected, (int ILOffset, int NativeOffset)[] mappings)
{
return expected.All(il => mappings.Any(t => t.ILOffset == il));
}

private enum SpecialILOffset
{
NoMapping = -1,
Prolog = -2,
Epilog = -3,
}

static DebugInfoTest()
{
Type runtimeMethodHandleInternalType = typeof(RuntimeMethodHandle).Assembly.GetType("System.RuntimeMethodHandleInternal");
Type runtimeTypeType = typeof(RuntimeMethodHandle).Assembly.GetType("System.RuntimeType");
MethodInfo getMethodBaseMethod = runtimeTypeType.GetMethod("GetMethodBase", BindingFlags.NonPublic | BindingFlags.Static, new[] { runtimeTypeType, runtimeMethodHandleInternalType });
s_getMethodBaseByHandle = (delegate*<object, IntPtr, MethodBase>)getMethodBaseMethod.MethodHandle .GetFunctionPointer();
}

// Needed to go from MethodID -> MethodBase
private static readonly delegate*<object, IntPtr, MethodBase> s_getMethodBaseByHandle;
}
17 changes: 17 additions & 0 deletions src/tests/JIT/Directed/debugging/debuginfo/tester_legacy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<DebugType>PdbOnly</DebugType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
<GCStressIncompatible>true</GCStressIncompatible>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="tests_d.ilproj" Aliases="tests_d" />
<ProjectReference Include="tests_r.ilproj" Aliases="tests_r" />
<ProjectReference Include="attribute.csproj" />
<ProjectReference Include="../../../../tracing/eventpipe/common_legacy/common_legacy.csproj" />
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
51 changes: 51 additions & 0 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3855,4 +3855,55 @@
<Issue>missing assembly</Issue>
</ExcludeList>
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'Linux' And '$(TargetArchitecture)' == 'arm' And '$(RuntimeFlavor)' == 'coreclr'" >
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Directed/debugging/debuginfo/tester.cs;$(XunitTestBinBase)/JIT/Directed/debugging/debuginfo/tester.csproj">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/bigevent/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/buffersize/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/bigevent/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/eventsourceerror/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/gcdump/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/providervalidation/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/rundownvalidation/**">
<Issue>needs triage</Issue>
</ExcludeList>
</ItemGroup>

<ItemGroup Condition="!('$(TargetOS)' == 'Linux' And '$(TargetArchitecture)' == 'arm' And '$(RuntimeFlavor)' == 'coreclr')" >
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Directed/debugging/debuginfo/tester_legacy*">
<Issue>Legacy to remove when main tests pass on Linux arm coreclr</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/buffersize_legacy/**">
<Issue>Legacy to remove when main tests pass on Linux arm coreclr</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/bigevent_legacy/**">
<Issue>Legacy to remove when main tests pass on Linux arm coreclr</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/eventsourceerror_legacy/**">
<Issue>Legacy to remove when main tests pass on Linux arm coreclr</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/gcdump_legacy/**">
<Issue>Legacy to remove when main tests pass on Linux arm coreclr</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/providervalidation_legacy/**">
<Issue>Legacy to remove when main tests pass on Linux arm coreclr</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/rundownvalidation_legacy/**">
<Issue>Legacy to remove when main tests pass on Linux arm coreclr</Issue>
</ExcludeList>
</ItemGroup>
</Project>
16 changes: 1 addition & 15 deletions src/tests/tracing/eventpipe/bigevent/bigevent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
using Microsoft.Diagnostics.Tracing;
using Tracing.Tests.Common;
using Microsoft.Diagnostics.Tracing.Parsers.Clr;
#if (UPDATED_NETCORE_CLIENT == true)
using Microsoft.Diagnostics.NETCore.Client;
#else
using Microsoft.Diagnostics.Tools.RuntimeClient;
#endif
using Microsoft.Diagnostics.NETCore.Client;

namespace Tracing.Tests.BigEventsValidation
{
Expand Down Expand Up @@ -49,22 +45,12 @@ public static int Main(string[] args)
{
// This test tries to send a big event (>100KB) and checks that the app does not crash
// See https://github.com/dotnet/runtime/issues/50515 for the regression issue
#if (UPDATED_NETCORE_CLIENT == true)
var providers = new List<EventPipeProvider>()
{
new EventPipeProvider("BigEventSource", EventLevel.Verbose)
};

return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _Verify);
#else
var providers = new List<Provider>()
{
new Provider("BigEventSource")
};

var configuration = new SessionConfiguration(circularBufferSizeMB: 1024, format: EventPipeSerializationFormat.NetTrace, providers: providers);
return IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, configuration, _Verify);
#endif
}

private static Dictionary<string, ExpectedEventCount> _expectedEventCounts = new Dictionary<string, ExpectedEventCount>()
Expand Down
2 changes: 1 addition & 1 deletion src/tests/tracing/eventpipe/bigevent/bigevent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
<ProjectReference Include="../common/common.csproj" />
<ProjectReference Condition="'$(UseUpdatedNETCoreClient)' == 'true'" Include="../common/Microsoft.Diagnostics.NETCore.Client/Microsoft.Diagnostics.NETCore.Client.csproj" />
<ProjectReference Include="../common/Microsoft.Diagnostics.NETCore.Client/Microsoft.Diagnostics.NETCore.Client.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit cb2cacd

Please sign in to comment.