Skip to content

Commit

Permalink
Convert ilasm unit tests to use one "merged" runner (dotnet#107167)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky authored Sep 3, 2024
1 parent 800ba81 commit 252f413
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 151 deletions.
9 changes: 8 additions & 1 deletion src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;

Expand Down Expand Up @@ -40,7 +41,13 @@ public BasicTestMethod(IMethodSymbol method,
.FullyQualifiedWithoutGlobalNamespace);
Method = method.Name;
DisplayNameForFiltering = $"{ContainingType}.{Method}({args})";
TestNameExpression = displayNameExpression ?? $"\"{externAlias}::{ContainingType}.{Method}({args})\"";

// Make arguments interpolated expressions to avoid issues with string arguments.
ImmutableArray<string> argumentsForName = arguments.IsDefaultOrEmpty
? ImmutableArray<string>.Empty
: arguments.Select(arg => $"{{{arg}}}").ToImmutableArray();

TestNameExpression = displayNameExpression ?? $"$\"{externAlias}::{ContainingType}.{Method}({string.Join(", ", argumentsForName)})\"";

if (method.IsStatic)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using Xunit;

public static class MethodImplOptionsTests
public class MethodImplOptionsTests : IDisposable
{
public static int Main()
private string _ilasmFile;
private string _ildasmFile;

public MethodImplOptionsTests()
{
const int Pass = 100;
const int Fail = 101;
Expand All @@ -17,12 +21,12 @@ public static int Main()
if (string.IsNullOrWhiteSpace(coreRoot))
{
Console.WriteLine("Environment variable is not set: 'CORE_ROOT'");
return Fail;
throw new InvalidOperationException("Environment variable is not set: 'CORE_ROOT'");
}
if (!Directory.Exists(coreRoot))
{
Console.WriteLine($"Did not find CORE_ROOT directory: {coreRoot}");
return Fail;
throw new InvalidOperationException("Did not find CORE_ROOT directory");
}

var nativeExeExtensions = new string[] { string.Empty, ".exe" };
Expand All @@ -42,68 +46,41 @@ public static int Main()
if (!found)
{
Console.WriteLine($"Did not find ilasm or ildasm in CORE_ROOT directory: {coreRoot}");
return Fail;
throw new InvalidOperationException("Did not find ilasm or ildasm in CORE_ROOT directory");
}

bool allPassed = true;
allPassed &=
RunMethodImplOptionsTest(
ilasmFile,
ildasmFile,
"AggressiveOptimizationTest",
"MiAggressiveOptimization.il",
"aggressiveoptimization");
return allPassed ? Pass : Fail;
_ilasmFile = ilasmFile;
_ildasmFile = ildasmFile;
}

private static bool RunMethodImplOptionsTest(
string ilasmFile,
string ildasmFile,
[Theory]
[InlineData("AggressiveOptimizationTest", "MiAggressiveOptimization.il", "aggressiveoptimization")]
public void RunMethodImplOptionsTest(
string testName,
string ilFileName,
string ilDisasmAttributeKeyword)
{
Console.WriteLine(testName);

try
{
string disasmIlFileName;
ProcessStartInfo ilasmPsi, ildasmPsi;
GetIlasmProcessStartInfos(ilasmFile, ildasmFile, ilFileName, out disasmIlFileName, out ilasmPsi, out ildasmPsi);
string disasmIlFileName;
ProcessStartInfo ilasmPsi, ildasmPsi;
GetIlasmProcessStartInfos(_ilasmFile, _ildasmFile, ilFileName, out disasmIlFileName, out ilasmPsi, out ildasmPsi);

Process ilasmProcess = Process.Start(ilasmPsi);
ilasmProcess.WaitForExit();
if (ilasmProcess.ExitCode != 0)
{
Console.WriteLine($"ilasm failed with exit code: {ilasmProcess.ExitCode}");
return false;
}
Process ilasmProcess = Process.Start(ilasmPsi);
ilasmProcess.WaitForExit();
Assert.Equal(0, ilasmProcess.ExitCode);

Process ildasmProcess = Process.Start(ildasmPsi);
ildasmProcess.WaitForExit();
if (ildasmProcess.ExitCode != 0)
{
Console.WriteLine($"ildasm failed with exit code: {ildasmProcess.ExitCode}");
return false;
}
Process ildasmProcess = Process.Start(ildasmPsi);
ildasmProcess.WaitForExit();
Assert.Equal(0, ildasmProcess.ExitCode);

string disasmIl = File.ReadAllText(disasmIlFileName);
var findMainAttributeRegex =
new Regex(
@"\bvoid\s+Main\s*\(\s*\).*?\b" + ilDisasmAttributeKeyword + @"\b",
RegexOptions.Compiled | RegexOptions.Multiline);
if (!findMainAttributeRegex.IsMatch(disasmIl))
{
Console.WriteLine($"Attribute '{ilDisasmAttributeKeyword}' did not round-trip through ilasm and ildasm");
return false;
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
return false;
}
return true;
string disasmIl = File.ReadAllText(disasmIlFileName);
var findMainAttributeRegex =
new Regex(
@"\bvoid\s+Main\s*\(\s*\).*?\b" + ilDisasmAttributeKeyword + @"\b",
RegexOptions.Compiled | RegexOptions.Multiline);

Assert.True(findMainAttributeRegex.IsMatch(disasmIl), $"Attribute '{ilDisasmAttributeKeyword}' did not round-trip through ilasm and ildasm");
}

private static void GetIlasmProcessStartInfos(
Expand Down Expand Up @@ -137,4 +114,6 @@ private static void GetIlasmProcessStartInfos(
disasmIlFileName = $"{Path.GetFileNameWithoutExtension(ilFileName)}_dis{Path.GetExtension(ilFileName)}";
ildasmPsi.Arguments = $"-out={disasmIlFileName} {asmDllFileName}";
}

public void Dispose() {}
}
50 changes: 0 additions & 50 deletions src/tests/ilasm/PortablePdb/IlasmPortablePdbTests.csproj

This file was deleted.

This file was deleted.

71 changes: 71 additions & 0 deletions src/tests/ilasm/ilasm_tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<HasMergedInTests>true</HasMergedInTests>
<!-- These tests rely on being able to call out to the ilasm and ildasm executables, which we can't do on mobile. -->
<DisableProjectBuild Condition="'$(TargetsMobile)' == 'true'">true</DisableProjectBuild>
<!-- Mono doesn't provide ilasm or ildasm in their Core_Root layout. -->
<DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'mono'">true</DisableProjectBuild>
</PropertyGroup>
<ItemGroup>
<Compile Include="PortablePdb\IlasmPortablePdbTester.cs" />
<Compile Include="PortablePdb\IlasmPortablePdbTesterCommon.cs" />
<Compile Include="PortablePdb\IlasmPortablePdbTesterTypes.cs" />
<Compile Include="MethodImplOptions\MethodImplOptionsTests.cs" />
</ItemGroup>
<ItemGroup>
<Compile Remove="PortablePdb\Resources\**" />
<EmbeddedResource Remove="PortablePdb\Resources\**" />
<None Remove="PortablePdb\Resources\**" />
</ItemGroup>
<ItemGroup>
<None Include="PortablePdb\TestFiles\TestDocuments1_unix.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestDocuments1_win.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestLocalScopes1.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestLocalScopes2.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestLocalScopes3.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestLocalScopes4.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestMethodDebugInformation.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestMethodDebugInformation_unix.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestMethodDebugInformation_win.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestPdbDebugDirectory1.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="PortablePdb\TestFiles\TestPdbDebugDirectory2.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>TestFiles\%(FileName)%(Extension)</Link>
</None>
<None Include="MethodImplOptions/MiAggressiveOptimization.il">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<Link>MiAggressiveOptimization.il</Link>
</None>
</ItemGroup>
<Import Project="$(TestSourceDir)MergedTestRunner.targets" />
</Project>
33 changes: 1 addition & 32 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,7 @@
<ExcludeList Include="$(XunitTestBinBase)/GC/API/WeakReference/Finalize2/*">
<Issue>Expectations about finalization order</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/ilasm/PortablePdb/IlasmPortablePdbTests/*">
<Issue>Specific to CoreCLR</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests/*">
<ExcludeList Include="$(XunitTestBinBase)/ilasm/*">
<Issue>Specific to CoreCLR</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/Interop/ArrayMarshalling/SafeArray/SafeArrayTest/*">
Expand Down Expand Up @@ -3107,12 +3104,6 @@
<ExcludeList Include = "$(XunitTestBinBase)/Exceptions/ForeignThread/ForeignThreadExceptions/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/ilasm/PortablePdb/IlasmPortablePdbTests/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/opt/Devirtualization/box2/**">
<Issue>https://github.com/dotnet/runtime/issues/41472</Issue>
</ExcludeList>
Expand Down Expand Up @@ -3270,9 +3261,6 @@
<ExcludeList Include = "$(XunitTestBinBase)/GC/API/WeakReference/multipleWRs_1/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/Interop/ICustomMarshaler/ConflictingNames/SameNameDifferentAssembly/**">
<Issue>needs triage</Issue>
</ExcludeList>
Expand Down Expand Up @@ -3333,9 +3321,6 @@
<ExcludeList Include = "$(XunitTestBinBase)/GC/LargeMemory/API/gc/gettotalmemory/**">
<Issue>https://github.com/dotnet/runtime/issues/54913</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/ilasm/PortablePdb/IlasmPortablePdbTests/**">
<Issue>https://github.com/dotnet/runtime/issues/54906</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/Interop/NativeLibrary/API/NativeLibraryTests/**">
<Issue>https://github.com/dotnet/runtime/issues/54905</Issue>
</ExcludeList>
Expand Down Expand Up @@ -3510,14 +3495,6 @@
<Issue>GC_API 0|1|2</Issue>
</ExcludeList>

<ExcludeList Include = "$(XunitTestBinBase)/ilasm/PortablePdb/IlasmPortablePdbTests/**">
<Issue>System.IO.FileNotFoundException: Could not load file or assembly 'xunit.runner.utility.netcoreapp10, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' or one of its dependencies.</Issue>
</ExcludeList>

<ExcludeList Include = "$(XunitTestBinBase)/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests/**">
<Issue>Environment variable is not set: 'CORE_ROOT'</Issue>
</ExcludeList>

<ExcludeList Include = "$(XunitTestBinBase)/GC/LargeMemory/API/gc/gettotalmemory/**">
<Issue>System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')</Issue>
</ExcludeList>
Expand Down Expand Up @@ -3717,12 +3694,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/jit64/opt/rngchk/RngchkStress3/*">
<Issue>timeout</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/ilasm/PortablePdb/IlasmPortablePdbTests/**">
<Issue> Did not find ilasm or ildasm in CORE_ROOT directory </Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests/**">
<Issue> Did not find ilasm or ildasm in CORE_ROOT directory </Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/tracing/eventpipe/bigevent/bigevent/**">
<Issue>Can't find file dotnet-diagnostic-{pid}-*-socket</Issue>
</ExcludeList>
Expand Down Expand Up @@ -3840,8 +3811,6 @@
<ExcludeList Include = "$(XunitTestBinBase)/Interop/StringMarshalling/VBByRefStr/VBByRefStrTest/**" />
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Intrinsics/TypeIntrinsics_r/**" />
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Intrinsics/TypeIntrinsics_ro/**" />
<ExcludeList Include = "$(XunitTestBinBase)/ilasm/System/Runtime/CompilerServices/MethodImplOptionsTests/**" />
<ExcludeList Include = "$(XunitTestBinBase)/ilasm/PortablePdb/IlasmPortablePdbTests/**" />
<ExcludeList Include = "$(XunitTestBinBase)/Loader/classloader/generics/ByRefLike/**" />
</ItemGroup>

Expand Down

0 comments on commit 252f413

Please sign in to comment.