Skip to content

Conversation

tomeksowi
Copy link
Member

CLRTestTargetUnsupported for not-windows added in #111887 to jit64_2.csproj is not respected when CLR tests are built with BuildAllTestsAsStandalone=true.

Part of #84834, cc @dotnet/samsung

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 11, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 11, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Feb 12, 2025

Can we fix the test scripts instead of adding these redundant annotations?

@tomeksowi
Copy link
Member Author

tomeksowi commented Feb 13, 2025

Can we fix the test scripts instead of adding these redundant annotations?

That would require adding [ConditionalFact] to each test method which would be equally redundant, unless there's some way to mass-annotate that I don't know of.

I removed the CLRTestTargetUnsupported from the merged target project, it's not necessary anymore.

EDIT: tests failing, it's probably necessary, I'll try [ConditionalFact]s

@tomeksowi
Copy link
Member Author

tomeksowi commented Feb 13, 2025

I removed the CLRTestTargetUnsupported from the merged target project, it's not necessary anymore.

EDIT: tests failing, it's probably necessary, I'll try [ConditionalFact]s

[ConditionalFact]s look messy in IL. The test failures could be side-stepped with <RequiresProcessIsolation> but that defeats the purpose of a merged test target. I reverted CLRTestTargetUnsupported in the merged target. I ran out of ideas to make it less redundant, it probably has to stay this way.

@jkotas
Copy link
Member

jkotas commented Feb 13, 2025

@jkoritzinsky Is there a way to make CLRTestTargetUnsupported work for BuildAllTestsAsStandalone=true?

@jkotas jkotas requested a review from jkoritzinsky February 13, 2025 15:39
@jkoritzinsky
Copy link
Member

I'd recommend using ConditionalFact as I want us to move to the attributes overall. There is a nice syntax for IL that I found that we've used for a few tests. Attributes will work for all cases.

@tomeksowi
Copy link
Member Author

tomeksowi commented Feb 14, 2025

I'd recommend using ConditionalFact as I want us to move to the attributes overall.

I tried ConditionalFact but apparently it needs XUnitWrapperGenerator to pick up the attributes and generate Main method.

The only thing I got working so far with and without BuildAllTestsAsStandalone=true and without a redundant CLRTestTargetUnsupported tag in ilproj is to make your own Main():

.method public static int32 Main()
{
  .entrypoint
  .maxstack  1

  call       bool [TestLibrary]TestLibrary.PlatformDetection::get_IsWindows()
  brtrue.s DoTest
  ldc.i4 100
  ret

DoTest:
  call       int32 MCCTest.MyClass::Test()
  ret
}

The ConditionalFacts in IL CLR tests have a redundant condition in the build project which we're trying to avoid, e.g.

// [ConditionalFact(typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsNotX86Process))]
.custom instance void [Microsoft.DotNet.XUnitExtensions]Xunit.ConditionalFactAttribute::.ctor(class [System.Runtime]System.Type,
string[]) = ( 01 00 61 54 65 73 74 4C 69 62 72 61 72 79 2E 50 // ..aTestLibrary.P
6C 61 74 66 6F 72 6D 44 65 74 65 63 74 69 6F 6E // latformDetection
2C 20 54 65 73 74 4C 69 62 72 61 72 79 2C 20 56 // , TestLibrary, V
65 72 73 69 6F 6E 3D 30 2E 30 2E 30 2E 30 2C 20 // ersion=0.0.0.0,
43 75 6C 74 75 72 65 3D 6E 65 75 74 72 61 6C 2C // Culture=neutral,
20 50 75 62 6C 69 63 4B 65 79 54 6F 6B 65 6E 3D // PublicKeyToken=
6E 75 6C 6C 01 00 00 00 0F 49 73 4E 6F 74 58 38 // null.....IsNotX8
36 50 72 6F 63 65 73 73 00 00 ) // 6Process..

<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' == 'x86'">true</CLRTestTargetUnsupported>

There is a nice syntax for IL that I found that we've used for a few tests. Attributes will work for all cases.

Can you point me to these tests that avoid the above-mentioned problems?

@filipnavara
Copy link
Member

There is a nice syntax for IL

For reference,

// [ConditionalFact(typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.Is32BitProcess))]
.custom instance void [Microsoft.DotNet.XUnitExtensions]Xunit.ConditionalFactAttribute::.ctor(class [System.Runtime]System.Type, string[]) =
{
    type ([TestLibrary]TestLibrary.PlatformDetection)
    string[1] ('Is32BitProcess')
}

@tomeksowi
Copy link
Member Author

// [ConditionalFact(typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.Is32BitProcess))]
.custom instance void [Microsoft.DotNet.XUnitExtensions]Xunit.ConditionalFactAttribute::.ctor(class [System.Runtime]System.Type, string[]) =
{
    type ([TestLibrary]TestLibrary.PlatformDetection)
    string[1] ('Is32BitProcess')
}

Thanks, it looks nicer. Still the problem was no Main() is generated off of the attribute, I don't see it working anywhere else in CLR tests without the condition doubled in .ilproj.

@tomeksowi
Copy link
Member Author

Still the problem was no Main() is generated off of the attribute

'ReferenceXUnitWrapperGenerator' was not set for IL, this change at least puts a project reference:

--- a/src/tests/Directory.Build.targets
+++ b/src/tests/Directory.Build.targets
@@ -493,7 +493,7 @@
     </ItemGroup>
   </Target>

-  <PropertyGroup Condition="'$(Language)' == 'C#' and '$(_CLRTestNeedsToRun)' == 'true' and ('$(BuildAsStandalone)' == 'true' or '$(RequiresProcessIsolation)' == 'true' or '$(InMergedTestDirectory)' == 'true' or '$(IsMergedTestRunnerAssembly)' == 'true')">
+  <PropertyGroup Condition="('$(Language)' == 'C#' or '$(Language)' == 'IL') and '$(_CLRTestNeedsToRun)' == 'true' and ('$(BuildAsStandalone)' == 'true' or '$(RequiresProcessIsolation)' == 'true' or '$(InMergedTestDirectory)' == 'true' or '$(IsMergedTestRunnerAssembly)' == 'true')">
     <ReferenceXUnitWrapperGenerator Condition="'$(ReferenceXUnitWrapperGenerator)' == ''">true</ReferenceXUnitWrapperGenerator>
   </PropertyGroup>

Still, the wrapper generator is not called.

@tomeksowi tomeksowi marked this pull request as draft March 13, 2025 08:49
@jkoritzinsky
Copy link
Member

The wrapper generator won't be called for IL. You'll need to add a Main method into each IL project that manually calls the different cases.

@tomeksowi tomeksowi marked this pull request as ready for review March 17, 2025 12:24
Copy link
Member

@am11 am11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tomeksowi tomeksowi changed the title Bring back CLRTestTargetUnsupported to mcc build projects Move unsupported target conditions to IL in mcc tests Mar 19, 2025
@jkoritzinsky jkoritzinsky merged commit e9ebf41 into dotnet:main Mar 20, 2025
72 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants