Skip to content

Commit

Permalink
Fix running tests with process isolation under naot (#100331)
Browse files Browse the repository at this point in the history
We don't currently run any RequiresProcessIsolation tests under native AOT because we hit the "not an applicable OS" early out here:

https://github.com/dotnet/runtime/blob/765ca4e9f2dddca2005ffdb45863b7980247a886/src/tests/Common/CoreCLRTestLibrary/OutOfProcessTest.cs#L75-L79
  • Loading branch information
MichalStrehovsky authored Apr 23, 2024
1 parent d92ac1f commit 6e866a6
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/tests/Common/CLRTest.Jit.targets
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ IF NOT DEFINED DoLink (
DependsOnTargets="GetDisasmCheckData">
<PropertyGroup>
<HasBashDisasmCheck>false</HasBashDisasmCheck>
<HasBashDisasmCheck Condition="'$(HasDisasmCheck)' == 'true' and '$(RuntimeFlavor)' == 'coreclr' and ('$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')">true</HasBashDisasmCheck>
<HasBashDisasmCheck Condition="'$(HasDisasmCheck)' == 'true' and '$(RuntimeFlavor)' == 'coreclr' and '$(TestBuildMode)' != 'nativeaot' and ('$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')">true</HasBashDisasmCheck>

<BashDisasmOutputFile Condition="'$(HasBashDisasmCheck)' == 'true'">$(scriptPath)__jit_disasm.out</BashDisasmOutputFile>
<BashDisasmListOutputFile Condition="'$(HasBashDisasmCheck)' == 'true'">$(scriptPath)__jit_disasm_list.out</BashDisasmListOutputFile>
Expand Down Expand Up @@ -184,7 +184,7 @@ fi
DependsOnTargets="GetDisasmCheckData">
<PropertyGroup>
<HasBatchDisasmCheck>false</HasBatchDisasmCheck>
<HasBatchDisasmCheck Condition="'$(HasDisasmCheck)' == 'true' and '$(RuntimeFlavor)' == 'coreclr'">true</HasBatchDisasmCheck>
<HasBatchDisasmCheck Condition="'$(HasDisasmCheck)' == 'true' and '$(RuntimeFlavor)' == 'coreclr' and '$(TestBuildMode)' != 'nativeaot'">true</HasBatchDisasmCheck>

<BatchDisasmOutputFile Condition="'$(HasBatchDisasmCheck)' == 'true'">$(scriptPath)__jit_disasm.out</BatchDisasmOutputFile>
<BatchDisasmListOutputFile Condition="'$(HasBatchDisasmCheck)' == 'true'">$(scriptPath)__jit_disasm_list.out</BatchDisasmListOutputFile>
Expand Down
12 changes: 9 additions & 3 deletions src/tests/Common/CoreCLRTestLibrary/OutOfProcessTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static OutOfProcessTest()
&& !OperatingSystem.IsBrowser()
&& !OperatingSystem.IsOSPlatform("Wasi");

public static void RunOutOfProcessTest(string assemblyPath)
public static void RunOutOfProcessTest(string assemblyPath, string testPathPrefix)
{
int ret = -100;
string baseDir = AppContext.BaseDirectory;
Expand All @@ -63,17 +63,23 @@ public static void RunOutOfProcessTest(string assemblyPath)
{
CoreclrTestWrapperLib wrapper = new CoreclrTestWrapperLib();

string testScriptPath = assemblyPath;
if (testPathPrefix != null)
testScriptPath = Path.Combine(testPathPrefix, testScriptPath);

if (OperatingSystem.IsWindows())
{
testExecutable = Path.Combine(baseDir, Path.ChangeExtension(assemblyPath, ".cmd"));
testExecutable = Path.Combine(baseDir, Path.ChangeExtension(testScriptPath, ".cmd"));
}
else
{
testExecutable = Path.Combine(baseDir, Path.ChangeExtension(assemblyPath.Replace("\\", "/"), ".sh"));
testExecutable = Path.Combine(baseDir, Path.ChangeExtension(testScriptPath.Replace("\\", "/"), ".sh"));
}

if (!File.Exists(testExecutable))
{
Console.WriteLine($"Test executable '{testExecutable}' not found, skipping.");

// Skip platform-specific test when running on the excluded platform
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,24 @@ public sealed class OutOfProcessTest : ITestInfo
private CodeBuilder _executionStatement { get; }
private string RelativeAssemblyPath { get; }

public OutOfProcessTest(string displayName, string relativeAssemblyPath)
public OutOfProcessTest(string displayName, string relativeAssemblyPath, string? testBuildMode)
{
Method = displayName;
DisplayNameForFiltering = displayName;
TestNameExpression = $"@\"{displayName}\"";
RelativeAssemblyPath = relativeAssemblyPath;

// Native AOT tests get generated into a 'native' directory, so we need to get out of that one first to find the test
string testPathPrefix = string.Equals(testBuildMode, "nativeaot", StringComparison.OrdinalIgnoreCase) ? "\"..\"" : "null";

_executionStatement = new CodeBuilder();
_executionStatement.AppendLine();
_executionStatement.AppendLine("if (TestLibrary.OutOfProcessTest.OutOfProcessTestsSupported)");

using (_executionStatement.NewBracesScope())
{
_executionStatement.AppendLine($@"TestLibrary.OutOfProcessTest"
+ $@".RunOutOfProcessTest(@""{relativeAssemblyPath}"");");
+ $@".RunOutOfProcessTest(@""{relativeAssemblyPath}"", {testPathPrefix});");
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/OptionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class OptionsHelper
private const string InMergedTestDirectoryOption = "build_property.InMergedTestDirectory";
private const string IsMergedTestRunnerAssemblyOption = "build_property.IsMergedTestRunnerAssembly";
private const string PriorityOption = "build_property.Priority";
private const string TestBuildModeOption = "build_property.TestBuildMode";
private const string RuntimeFlavorOption = "build_property.RuntimeFlavor";
private const string IsOutOfProcessTestAssemblyOption = "build_metadata.AdditionalFiles.IsOutOfProcessTestAssembly";
private const string TestFilterOption = "build_property.TestFilter";
Expand Down Expand Up @@ -38,6 +39,8 @@ private static bool GetBoolOption(this AnalyzerConfigOptions options, string key

internal static string RuntimeFlavor(this AnalyzerConfigOptions options) => options.TryGetValue(RuntimeFlavorOption, out string? flavor) ? flavor : "CoreCLR";

internal static string? TestBuildMode(this AnalyzerConfigOptions options) => options.TryGetValue(TestBuildModeOption, out string? option) ? option : null;

internal static bool IsOutOfProcessTestAssembly(this AnalyzerConfigOptions options) => options.GetBoolOption(IsOutOfProcessTestAssemblyOption);

internal static string? TestFilter(this AnalyzerConfigOptions options) => options.TryGetValue(TestFilterOption, out string? filter) ? filter : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
string? testDisplayName = fileOptions.TestDisplayName();
if (assemblyPath is not null && testDisplayName is not null)
{
return ImmutableArray.Create<ITestInfo>(new OutOfProcessTest(testDisplayName, assemblyPath));
return ImmutableArray.Create<ITestInfo>(new OutOfProcessTest(testDisplayName, assemblyPath, fileOptions.TestBuildMode()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<CompilerVisibleProperty Include="TargetOS" />
<CompilerVisibleProperty Include="TargetArchitecture" />
<CompilerVisibleProperty Include="Priority" />
<CompilerVisibleProperty Include="TestBuildMode" />
<!-- Properties that influence test harness generation -->
<CompilerVisibleProperty Include="InMergedTestDirectory" />
<CompilerVisibleProperty Include="IsMergedTestRunnerAssembly" />
Expand Down
3 changes: 3 additions & 0 deletions src/tests/JIT/Directed/tailcall/mutual_recursion.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<PropertyGroup>
<!-- Needed for JitOptimizationSensitive -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>

<!-- Not even printf is AOT compatible in F# -->
<NativeAotIncompatible>true</NativeAotIncompatible>
</PropertyGroup>
<PropertyGroup>
<NoStandardLib>True</NoStandardLib>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<Optimize>True</Optimize>
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
<GCStressIncompatible>True</GCStressIncompatible>

<!-- Not even printf is AOT compatible in F# -->
<NativeAotIncompatible>true</NativeAotIncompatible>
</PropertyGroup>
<ItemGroup>
<Compile Include="Runtime_72845.fs" />
Expand Down
3 changes: 3 additions & 0 deletions src/tests/Regressions/coreclr/GitHub_22888/test22888.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<!-- Needed for GC.WaitForPendingFinalizers -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<!-- Uses AssemblyLoadContext -->
<NativeAotIncompatible>true</NativeAotIncompatible>
</PropertyGroup>
<ItemGroup>
<Compile Include="test22888.cs" />
Expand Down
49 changes: 49 additions & 0 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,15 @@

<!-- NativeAOT specific -->
<ItemGroup Condition="'$(XunitTestBinBase)' != '' and '$(TestBuildMode)' == 'nativeaot' and '$(RuntimeFlavor)' == 'coreclr'">
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/devdiv_902271/DevDiv_902271/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)JIT/Methodical/tailcall_v4/hijacking/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/reflection/Modifiers/modifiers/**">
<Issue>https://github.com/dotnet/runtime/issues/91381</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/Loader/classloader/StaticVirtualMethods/Regression/GetInterfaceMapWithStaticVirtualsAndConstraints/**">
<Issue>https://github.com/dotnet/runtime/issues/89157</Issue>
</ExcludeList>
Expand Down Expand Up @@ -1151,6 +1160,46 @@
</ExcludeList>
</ItemGroup>

<!-- NativeAOT x86 specific -->
<ItemGroup Condition="'$(XunitTestBinBase)' != '' and '$(TestBuildMode)' == 'nativeaot' and '$(RuntimeFlavor)' == 'coreclr' and '$(TargetArchitecture)' == 'x86'">
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/doublearray/dblarray2_cs_d/**">
<Issue>https://github.com/dotnet/runtime/issues/101284</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/doublearray/dblarray2_cs_do/**">
<Issue>https://github.com/dotnet/runtime/issues/101284</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/doublearray/dblarray2_cs_r/**">
<Issue>https://github.com/dotnet/runtime/issues/101284</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/doublearray/dblarray2_cs_ro/**">
<Issue>https://github.com/dotnet/runtime/issues/101284</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/doublearray/dblarray3_cs_do/**">
<Issue>https://github.com/dotnet/runtime/issues/101284</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/opt/perf/doublealign/Arrays/**">
<Issue>https://github.com/dotnet/runtime/issues/101284</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/Interop/COM/ComWrappers/API/**">
<Issue>https://github.com/dotnet/runtime/issues/101363</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/IL/Tailcall/ExplicitTailCallNoSO/**">
<Issue>https://github.com/dotnet/runtime/issues/101363</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/tailcall/tailcall/**">
<Issue>https://github.com/dotnet/runtime/issues/101363</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/Loader/classloader/InlineArray/InlineArrayValid/**">
<Issue>https://github.com/dotnet/runtime/issues/101363</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/CLR-x86-JIT/V1.1-M1-Beta1/b143840/b143840/**">
<Issue>https://github.com/dotnet/runtime/issues/101363</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/CLR-x86-JIT/V1-M10/b08944/b08944b/**">
<Issue>https://github.com/dotnet/runtime/issues/101364</Issue>
</ExcludeList>
</ItemGroup>

<!-- run.proj finds all the *.cmd/*.sh scripts in a test folder and creates corresponding test methods.
Exclude these scripts to avoid creating such methods for the superpmicollect dependent test projects
and running them separately from superpmicollect test. These should be excluded regardless of RuntimeFlavor/os/arch-->
Expand Down

0 comments on commit 6e866a6

Please sign in to comment.