Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<Compile Include="Utilities.cs" />
<Compile Include="HostPolicyMock.cs" />
<Compile Include="XPlatformUtils.cs" />

<!-- xUnit-style attribute support -->
<Compile Include="SkipOnPlatformAttribute.cs" />
<Compile Include="TestPlatforms.cs" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/SkipOnPlatformAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

using System;

namespace Xunit
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class SkipOnPlatformAttribute : Attribute
{
internal SkipOnPlatformAttribute() { }
public SkipOnPlatformAttribute(TestPlatforms testPlatforms, string reason) { }
}
}
27 changes: 27 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/TestPlatforms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

using System;

namespace Xunit
{
[Flags]
public enum TestPlatforms
{
Windows = 1,
Linux = 2,
OSX = 4,
FreeBSD = 8,
NetBSD = 16,
illumos= 32,
Solaris = 64,
iOS = 128,
tvOS = 256,
Android = 512,
Browser = 1024,
MacCatalyst = 2048,
AnyUnix = FreeBSD | Linux | NetBSD | OSX | illumos | Solaris | iOS | tvOS | MacCatalyst | Android | Browser,
Any = ~0
}
}
19 changes: 19 additions & 0 deletions src/tests/Common/ILTestRunner/ILTestRunner.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<Import Project="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props" />

<ItemGroup>
<ProjectReference Include="$(RepoRoot)\src\tests\JIT\IL_Conformance\Old\directed\AutoInit.ilproj" Aliases="autoinit" />
</ItemGroup>
</Project>
139 changes: 139 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/ITestInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

namespace XUnitWrapperGenerator;

interface ITestInfo
{
string ExecutionStatement { get; }
}

sealed class BasicTestMethod : ITestInfo
{
public BasicTestMethod(IMethodSymbol method, string externAlias, ImmutableArray<string> arguments = default)
{
var args = arguments.IsDefaultOrEmpty ? "" : string.Join(", ", arguments);
string containingType = method.ContainingType.ToDisplayString(XUnitWrapperGenerator.FullyQualifiedWithoutGlobalNamespace);
if (method.IsStatic)
{
ExecutionStatement = $"{externAlias}::{containingType}.{method.Name}({args});";
}
else
{
ExecutionStatement = $"using ({externAlias}::{containingType} obj = new()) obj.{method.Name}({args});";
}
}

public string ExecutionStatement { get; }

public override bool Equals(object obj)
{
return obj is BasicTestMethod other && ExecutionStatement == other.ExecutionStatement;
}
}

sealed class ConditionalTest : ITestInfo
{
public ConditionalTest(ITestInfo innerTest, string condition)
{
ExecutionStatement = $"if ({condition}) {{ {innerTest.ExecutionStatement} }}";
}

public string ExecutionStatement { get; }

public override bool Equals(object obj)
{
return obj is ConditionalTest other && ExecutionStatement == other.ExecutionStatement;
}
}

sealed class PlatformSpecificTest : ITestInfo
{
public PlatformSpecificTest(ITestInfo innerTest, Xunit.TestPlatforms platform)
{
List<string> platformCheckConditions = new();
if (platform.HasFlag(Xunit.TestPlatforms.Windows))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsWindows()");
}
if (platform.HasFlag(Xunit.TestPlatforms.Linux))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsLinux()");
}
if (platform.HasFlag(Xunit.TestPlatforms.OSX))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsMacOS()");
}
if (platform.HasFlag(Xunit.TestPlatforms.illumos))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsOSPlatform(""illumos"")");
}
if (platform.HasFlag(Xunit.TestPlatforms.Solaris))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsOSPlatform(""Solaris"")");
}
if (platform.HasFlag(Xunit.TestPlatforms.Android))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsAndroid()");
}
if (platform.HasFlag(Xunit.TestPlatforms.iOS))
{
platformCheckConditions.Add("(global::System.OperatingSystem.IsIOS() && !global::System.OperatingSystem.IsMacCatalyst())");
}
if (platform.HasFlag(Xunit.TestPlatforms.tvOS))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsTVOS()");
}
if (platform.HasFlag(Xunit.TestPlatforms.MacCatalyst))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsMacCatalyst()");
}
if (platform.HasFlag(Xunit.TestPlatforms.Browser))
{
platformCheckConditions.Add("global::System.OperatingSystem.IsBrowser()");
}
if (platform.HasFlag(Xunit.TestPlatforms.FreeBSD))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsFreeBSD()");
}
if (platform.HasFlag(Xunit.TestPlatforms.NetBSD))
{
platformCheckConditions.Add(@"global::System.OperatingSystem.IsOSPlatform(""NetBSD"")");
}
ExecutionStatement = $"if ({string.Join(" || ", platformCheckConditions)}) {{ {innerTest.ExecutionStatement} }}";
}

public string ExecutionStatement { get; }

public override bool Equals(object obj)
{
return obj is PlatformSpecificTest other && ExecutionStatement == other.ExecutionStatement;
}
}

sealed class MemberDataTest : ITestInfo
{
public MemberDataTest(ISymbol referencedMember, ITestInfo innerTest, string externAlias, string argumentLoopVarIdentifier)
{
string containingType = referencedMember.ContainingType.ToDisplayString(XUnitWrapperGenerator.FullyQualifiedWithoutGlobalNamespace);
string memberInvocation = referencedMember switch
{
IPropertySymbol { IsStatic: true } => $"{externAlias}::{containingType}.{referencedMember.Name}",
IMethodSymbol { IsStatic: true, Parameters: { Length: 0 } } => $"{externAlias}::{containingType}.{referencedMember.Name}()",
_ => throw new ArgumentException()
};
ExecutionStatement = $@"
foreach (object[] {argumentLoopVarIdentifier} in {memberInvocation})
{{
{innerTest.ExecutionStatement}
}}
";
}

public string ExecutionStatement { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text;

namespace XUnitWrapperGenerator
{
internal class ImmutableDictionaryValueComparer<TKey, TValue> : IEqualityComparer<ImmutableDictionary<TKey, TValue>>
where TKey : notnull
{
private readonly IEqualityComparer<TValue> _valueComparer;

public ImmutableDictionaryValueComparer(IEqualityComparer<TValue> valueComparer)
{
_valueComparer = valueComparer;
}

public bool Equals(ImmutableDictionary<TKey, TValue> x, ImmutableDictionary<TKey, TValue> y)
{
if (x.Count != y.Count)
{
return false;
}

foreach (var pair in x)
{
if (!y.TryGetValue(pair.Key, out TValue? value) || !_valueComparer.Equals(value, pair.Value))
{
return false;
}
}
return true;
}

public int GetHashCode(ImmutableDictionary<TKey, TValue> obj) => throw new NotImplementedException();
}
}
16 changes: 16 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/RuntimeConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Xunit
{
[Flags]
public enum RuntimeConfiguration
{
Any = ~0,
Checked = 1,
Debug = 1 << 1,
Release = 1 << 2
}
}
38 changes: 38 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/RuntimeTestModes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Xunit
{
[Flags]
public enum RuntimeTestModes
{
// Disable always when using coreclr runtime.
Any = ~0,

// We're running regular tests with no runtime stress modes
RegularRun = 1,

// JitStress, JitStressRegs, JitMinOpts and TailcallStress enable
// various modes in the JIT that cause us to exercise more code paths,
// and generate different kinds of code
JitStress = 1 << 1, // COMPlus_JitStress is set.
JitStressRegs = 1 << 2, // COMPlus_JitStressRegs is set.
JitMinOpts = 1 << 3, // COMPlus_JITMinOpts is set.
TailcallStress = 1 << 4, // COMPlus_TailcallStress is set.

// ZapDisable says to not use NGEN or ReadyToRun images.
// This means we JIT everything.
ZapDisable = 1 << 5, // COMPlus_ZapDisable is set.

// GCStress3 forces a GC at various locations, typically transitions
// to/from the VM from managed code.
GCStress3 = 1 << 6, // COMPlus_GCStress includes mode 0x3.

// GCStressC forces a GC at every JIT-generated code instruction,
// including in NGEN/ReadyToRun code.
GCStressC = 1 << 7, // COMPlus_GCStress includes mode 0xC.
AnyGCStress = GCStress3 | GCStressC // Disable when any GCStress is exercised.
}
}
26 changes: 26 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/TestPlatforms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Xunit
{
[Flags]
public enum TestPlatforms
{
Windows = 1,
Linux = 2,
OSX = 4,
FreeBSD = 8,
NetBSD = 16,
illumos= 32,
Solaris = 64,
iOS = 128,
tvOS = 256,
Android = 512,
Browser = 1024,
MacCatalyst = 2048,
AnyUnix = FreeBSD | Linux | NetBSD | OSX | illumos | Solaris | iOS | tvOS | MacCatalyst | Android | Browser,
Any = ~0
}
}
15 changes: 15 additions & 0 deletions src/tests/Common/XUnitWrapperGenerator/TestRuntimes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Xunit
{
[Flags]
public enum TestRuntimes
{
CoreCLR = 1,
Mono = 2,
Any = ~0
}
}
Loading