Skip to content

Commit

Permalink
Add error check for skipped tests in merged groups (#84284)
Browse files Browse the repository at this point in the history
If I test is written in the old style (with a Main and OutputType==Exe without an attribute such as RequiresProcessIsolation) in a merged test group directory, it will be skipped. This change adds a check to detect those cases.

I have struggled with ways to automatically set OutputType. Directory.Build.props is too early (the test project file will override it). Directory.Build.targets is too late as the C# targets files will already have been processed and set other variables based on the value of OutputType. This Target doesn't execute until later, but since it is an error it doesn't matter how those additional properties were set.

Since this adds more boilerplate to each merged test directory, I created a src/tests/Directory.Merged.props to share all of that.

This catches 3 tests that aren't currently executing.

Unrelated:

- Use GetPathOfFileAbove in nearby locations for Directory.Build.props chaining rather than specific paths
- Fix two easy IL warnings that appeared in my local build of all tests

Resolves #84182
  • Loading branch information
markples authored Apr 4, 2023
1 parent 00f921d commit 735ddea
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 55 deletions.
13 changes: 13 additions & 0 deletions src/tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@
<SkipImportILTargets Condition="'$(CLRTestBuildAllTargets)' != '' And '$(CLRTestNeedTarget)' != '$(CLRTestBuildAllTargets)'">true</SkipImportILTargets>
</PropertyGroup>

<!-- If a test in a merged test directory (e.g., under JIT\Directed where Directed_1.csproj and siblings -->
<!-- represent the groups) has OutputType==Exe set, then it will end up being skipped because the merged -->
<!-- groups are supposed to cover all of the tests. The merged groups themselves should be Exes, as -->
<!-- should any test marked RequiresProcessIsolation or BuildAsStandalone. -->
<Target Name="CheckForTestOutsideOfGroup" BeforeTargets="Build">
<Error Condition="'$(InMergedTestDirectory)' == 'true'
and '$(OutputType)' == 'Exe'
and '$(RequiresProcessIsolation)' != 'true'
and '$(BuildAsStandalone)' != 'true'
and '$(IsMergedTestRunnerAssembly)' != 'true'"
Text="Tests in merged test directories should not set OutputType to Exe unless they are RequiresProcessIsolation, BuildAsStandalone, or IsMergedTestRunnerAssembly." />
</Target>

<Target Name="CopyNativeProjectBinaries" Condition="'$(_CopyNativeProjectBinaries)' == 'true'">
<ItemGroup Condition="'$(UseVisualStudioNativeBinariesLayout)' == 'true'">
<NativeProjectBinaries Include="$(NativeProjectOutputFolder)\*.*" />
Expand Down
8 changes: 8 additions & 0 deletions src/tests/Directory.Merged.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<InMergedTestDirectory>true</InMergedTestDirectory>
<BuildAsStandalone Condition="'$(BuildAsStandalone)' == ''">false</BuildAsStandalone>

<AssemblyName Condition="'$(BuildAsStandalone)' != 'true'">$(MSBuildProjectName.Replace('_il_d', '').Replace('_il_r', ''))</AssemblyName>
</PropertyGroup>
</Project>
10 changes: 2 additions & 8 deletions src/tests/JIT/Directed/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<BuildAsStandalone Condition="'$(BuildAsStandalone)' == ''">false</BuildAsStandalone>

<AssemblyName Condition="'$(BuildAsStandalone)' != 'true'">$(MSBuildProjectName.Replace('_il_d', '').Replace('_il_r', ''))</AssemblyName>
</PropertyGroup>

<Import Project="..\..\Directory.Build.props" />
<Import Project="..\..\Directory.Merged.props" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<RunAnalyzers>true</RunAnalyzers>
Expand Down
5 changes: 1 addition & 4 deletions src/tests/JIT/HardwareIntrinsics/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<Project>
<PropertyGroup>
<BuildAsStandalone Condition="'$(BuildAsStandalone)' == ''">false</BuildAsStandalone>
</PropertyGroup>

<Import Project="..\..\Directory.Merged.props" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Threading;
using Xunit;

class StaticReadonlySimd
public class StaticReadonlySimd
{
static int Main()
[Fact]
public static void TestEntryPoint()
{
for (int i = 0; i < 100; i++)
{
// Warm up Test so the Tier1 version will be statically initialized.
Test();
Thread.Sleep(15);
}
return 100;
}

static readonly Vector2 v1 = new Vector2(-1.0f, 2.0f);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- Needed for CLRTestEnvironmentVariable -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using Xunit;

namespace IntelHardwareIntrinsicTest
{
class Program
public class Program
{
const int Pass = 100;
const int Fail = 0;

static unsafe int Main()
[Fact]
public static unsafe int TestEntryPoint()
{
int testResult = X86Serialize.X64.IsSupported ? Pass : Fail;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
Expand Down
6 changes: 1 addition & 5 deletions src/tests/JIT/IL_Conformance/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<BuildAsStandalone Condition="'$(BuildAsStandalone)' == ''">false</BuildAsStandalone>
</PropertyGroup>

<Import Project="..\..\Directory.Merged.props" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
Expand Down
10 changes: 2 additions & 8 deletions src/tests/JIT/Methodical/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<BuildAsStandalone Condition="'$(BuildAsStandalone)' == ''">false</BuildAsStandalone>

<AssemblyName Condition="'$(BuildAsStandalone)' != 'true'">$(MSBuildProjectName.Replace('_il_d', '').Replace('_il_r', ''))</AssemblyName>
</PropertyGroup>

<Import Project="..\..\Directory.Build.props" />
<Import Project="..\..\Directory.Merged.props" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<RunAnalyzers>true</RunAnalyzers>
Expand Down
7 changes: 1 addition & 6 deletions src/tests/JIT/Regression/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<BuildAsStandalone Condition="'$(BuildAsStandalone)' == ''">false</BuildAsStandalone>

<AssemblyName Condition="'$(BuildAsStandalone)' != 'true'">$(MSBuildProjectName.Replace('_il_d', '').Replace('_il_r', ''))</AssemblyName>
</PropertyGroup>

<Import Project="..\..\Directory.Merged.props" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<BuildAsStandalone>false</BuildAsStandalone>
</PropertyGroup>

<Import Project="..\..\..\Directory.Build.props" />
<Import Project="..\..\..\Directory.Merged.props" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<RunAnalyzers>true</RunAnalyzers>
Expand Down
10 changes: 2 additions & 8 deletions src/tests/baseservices/threading/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<BuildAsStandalone Condition="'$(BuildAsStandalone)' == ''">false</BuildAsStandalone>

<AssemblyName Condition="'$(BuildAsStandalone)' != 'true'">$(MSBuildProjectName.Replace('_il_d', '').Replace('_il_r', ''))</AssemblyName>
</PropertyGroup>

<Import Project="..\..\Directory.Build.props" />
<Import Project="..\..\Directory.Merged.props" />
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<RunAnalyzers>true</RunAnalyzers>
Expand Down
4 changes: 2 additions & 2 deletions src/tests/reflection/ldtoken/byrefs.il
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
}
}

.class private auto ansi beforefieldinit MyType1
.class private auto ansi sealed beforefieldinit MyType1
extends [mscorlib]System.ValueType
{
}

.class private auto ansi beforefieldinit MyType2
.class private auto ansi sealed beforefieldinit MyType2
extends [mscorlib]System.ValueType
{
}

0 comments on commit 735ddea

Please sign in to comment.