Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert all remaining tests in the Loader subtree to the merged model #92407

Merged
merged 19 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
59b5967
Manual modifications to tests under Loader/classloader/generics
trylek Sep 15, 2023
0cd17d3
Mechanically merge all tests under Loader/classloader/generics
trylek Sep 15, 2023
1452e97
Fix two overlooked renames of the Methods/Lib.ilproj library project
trylek Sep 15, 2023
c3ff48f
Manual modifications to tests under Loader/classloader/regressions
trylek Sep 17, 2023
f52ee8c
Mechnical merging of all tests under Loader/classloader/regressions
trylek Sep 17, 2023
45acb20
Manual modifications to remaining tests under Loader/classloader
trylek Sep 18, 2023
87fbd40
Mechanically merge all remaining tests under Loader/classloader
trylek Sep 18, 2023
3e03efc
Shorten several excessively long names causing trouble even with long…
trylek Sep 19, 2023
11e6c80
Revert changes to TSAmbiguities test and mark them with explicit Main
trylek Sep 21, 2023
ad85f80
Manual modifications to remaining tests under Loader
trylek Sep 21, 2023
f2a4860
Mechanically merge all remaining tests under Loader
trylek Sep 21, 2023
da9619d
Mark the two Unloaded projects as DisableProjectBuild to suppress dup…
trylek Sep 21, 2023
e6bf6ca
Fix annotation for the Unloaded library projects
trylek Sep 21, 2023
7b304af
Deduplicate the Unloaded support assemblies per Mark's PR feedback
trylek Sep 21, 2023
a1e8b24
Fix the ResolvedFromDifferentContext collectible assembly test
trylek Sep 25, 2023
1027118
Remove superfluous imports of Directory.Merged.props from Loader subf…
trylek Sep 25, 2023
384f295
Fix BinderTracingTest filtering on Mono
trylek Sep 26, 2023
5984ce2
Fix genmeth.ilproj to indicate this is a build-only project
trylek Sep 26, 2023
c2eb64d
Fix LLVAM AOT crash when compiling the genmeth.dll assembly
trylek Sep 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<!-- Default priority building values. -->
<PropertyGroup>
<DisableProjectBuild Condition="'$(IsMergedTestRunnerAssembly)' == 'true' and $(BuildAsStandalone)">true</DisableProjectBuild>
<OutputType Condition="('$(IsMergedTestRunnerAssembly)' == 'true' and !$(BuildAsStandalone)) or '$(RequiresProcessIsolation)' == 'true'">Exe</OutputType>
<OutputType Condition="('$(IsMergedTestRunnerAssembly)' == 'true' and !$(BuildAsStandalone)) or ('$(RequiresProcessIsolation)' == 'true' and '$(CLRTestKind)' != 'SharedLibrary')">Exe</OutputType>

<CLRTestKind Condition="'$(CLRTestKind)' == '' and '$(OutputType)' == 'Exe'">BuildAndRun</CLRTestKind>
<CLRTestKind Condition="'$(CLRTestKind)' == ''">SharedLibrary</CLRTestKind>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace AssemblyDependencyResolverTests
{
class AssemblyDependencyResolverTests : TestBase
public class AssemblyDependencyResolverTests : TestBase
{
string _componentDirectory;
string _componentAssemblyPath;
Expand Down Expand Up @@ -306,7 +306,8 @@ private string CreateMockStandardNativeLibrary(string relativePath, string simpl
relativePath + Path.DirectorySeparatorChar + XPlatformUtils.GetStandardNativeLibraryFileName(simpleName));
}

public static int Main()
[Fact]
public static int TestEntryPoint()
{
return TestBase.RunTests(
typeof(AssemblyDependencyResolverTests),
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 NativeAotIncompatible -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<RequiresMockHostPolicy>true</RequiresMockHostPolicy>
<!-- AssemblyDependencyResolver is not supported -->
<NativeAotIncompatible>true</NativeAotIncompatible>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace AssemblyDependencyResolverTests
{
class TestBase
public class TestBase
{
protected string TestBasePath { get; private set; }
protected string BinaryBasePath { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

namespace AssemblyDependencyResolverTests
{
class InvalidHostingTest
public class InvalidHostingTest
{
public static int Main()
[Fact]
public static int TestEntryPoint()
{
try
{
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 mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using Xunit;

class Program
public class Program
{
class TestALC : AssemblyLoadContext
{
Expand All @@ -25,7 +26,8 @@ protected override Assembly Load(AssemblyName name)
}
}

static int Main()
[Fact]
public static int TestEntryPoint()
{
var holdResult = HoldAssembliesAliveThroughByRefFields(out GCHandle gch1, out GCHandle gch2);
if (holdResult != 100)
Expand Down Expand Up @@ -90,7 +92,7 @@ private static ReadOnlySpan<byte> LoadAssembly(out GCHandle gchToAssembly)
{
var currentALC = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly());
var alc = new TestALC(currentALC);
var a = alc.LoadFromAssemblyPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Unloaded.dll"));
var a = alc.LoadFromAssemblyPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ByRefLocalsUnloaded.dll"));
gchToAssembly = GCHandle.Alloc(a, GCHandleType.WeakTrackResurrection);

var spanAccessor = (IReturnSpan)Activator.CreateInstance(a.GetType("SpanAccessor"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for GC.WaitForPendingFinalizers -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="Unloaded.csproj" />
<ProjectReference Include="ByRefLocalsUnloaded.csproj" />
<ProjectReference Include="SpanAccessor.csproj" />
<Compile Include="ByRefLocals.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="SpanAccessor.csproj" />
<Compile Include="Unloaded.cs" />
<Compile Include="ByRefLocalsUnloaded.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.IO;
using Xunit;

class TestAssemblyLoadContext : AssemblyLoadContext
{
Expand All @@ -31,7 +32,7 @@ protected override Assembly Load(AssemblyName assemblyName)
{
AssemblyLoadContext alc1 = new AssemblyLoadContext("Dependencies", true);
Console.WriteLine($"Loading TestInterface by alc {alc1} for {(IsCollectible ? "collectible" : "non-collectible")} alc {this}");
Assembly a = alc1.LoadFromAssemblyPath(Test.GetTestAssemblyPath(Path.Join("..", "TestInterface", "TestInterface.dll")));
Assembly a = alc1.LoadFromAssemblyPath(Test.GetTestAssemblyPath(Path.Join("TestInterface", "TestInterface.dll")));
interfaceAssemblyRef = new WeakReference(a);
return a;
}
Expand All @@ -40,7 +41,7 @@ protected override Assembly Load(AssemblyName assemblyName)
}
}

class Test
public class Test
{
static AssemblyLoadContext alc1 = null;
static WeakReference interfaceAssemblyRef = null;
Expand All @@ -56,7 +57,7 @@ private static Assembly LoadUsingResolvingEvent(bool collectibleParent)
alc1 = new AssemblyLoadContext("Dependencies", true);
AssemblyLoadContext alc2 = new AssemblyLoadContext("Test1", collectibleParent);
alc2.Resolving += Alc2_Resolving;
Assembly assembly = alc2.LoadFromAssemblyPath(Test.GetTestAssemblyPath(Path.Join("..", "TestClass", "TestClass.dll")));
Assembly assembly = alc2.LoadFromAssemblyPath(Test.GetTestAssemblyPath(Path.Join("TestClass", "TestClass.dll")));

Type t = assembly.GetType("TestClass.Class");
Console.WriteLine($"Type {t} obtained");
Expand All @@ -76,7 +77,7 @@ private static Assembly Alc2_Resolving(AssemblyLoadContext arg1, AssemblyName ar
if (alc1 != null && arg2.Name == "TestInterface")
{
Console.WriteLine($"Loading TestInterface by alc {alc1} for {(arg1.IsCollectible ? "collectible" : "non-collectible")} alc {arg1}");
Assembly a = alc1.LoadFromAssemblyPath(Test.GetTestAssemblyPath(Path.Join("..", "TestInterface", "TestInterface.dll")));
Assembly a = alc1.LoadFromAssemblyPath(Test.GetTestAssemblyPath(Path.Join("TestInterface", "TestInterface.dll")));
interfaceAssemblyRef = new WeakReference(a);
return a;
}
Expand All @@ -88,7 +89,7 @@ private static Assembly Alc2_Resolving(AssemblyLoadContext arg1, AssemblyName ar
private static Assembly LoadUsingLoadOverride(bool collectibleParent)
{
TestAssemblyLoadContext alc2 = new TestAssemblyLoadContext("Test2", collectibleParent);
Assembly assembly = alc2.LoadFromAssemblyPath(Test.GetTestAssemblyPath(Path.Join("..", "TestClass", "TestClass.dll")));
Assembly assembly = alc2.LoadFromAssemblyPath(Test.GetTestAssemblyPath(Path.Join("TestClass", "TestClass.dll")));

Type t = assembly.GetType("TestClass.Class");

Expand Down Expand Up @@ -206,7 +207,8 @@ private static int TestFullUnload(TestCase testCase)
return 100;
}

public static int Main()
[Fact]
public static int TestEntryPoint()
{
int status = 100;
foreach (TestCase testCase in Enum.GetValues(typeof(TestCase)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<!-- Needed for UnloadabilityIncompatible, GC.WaitForPendingFinalizers -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<!-- Test creates non-collectible AssemblyLoadContext -->
<UnloadabilityIncompatible>true</UnloadabilityIncompatible>
<CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<ItemGroup>
<Compile Include="ResolvedFromDifferentContext.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="TestInterface.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="TestClass.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<PropertyGroup>
<TestClassOutputPath>$(OutputPath)/../TestClass</TestClassOutputPath>
<TestInterfaceOutputPath>$(OutputPath)/../TestInterface</TestInterfaceOutputPath>
</PropertyGroup>

<Target Name="CopySupportAssembliesToOutputSubfolders" AfterTargets="Build">
<MakeDir Directories="$(TestClassOutputPath);$(TestInterfaceOutputPath)" />
<Copy SourceFiles="$(TestClassOutputPath)/TestClass.dll" DestinationFolder="$(OutputPath)/TestClass" />
<Copy SourceFiles="$(TestInterfaceOutputPath)/TestInterface.dll" DestinationFolder="$(OutputPath)/TestInterface" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using Xunit;

class Program
public class Program
{
class TestALC : AssemblyLoadContext
{
Expand All @@ -25,11 +26,12 @@ protected override Assembly Load(AssemblyName name)
}
}

static int Main()
[Fact]
public static int TestEntryPoint()
{
var currentALC = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly());
var alc = new TestALC(currentALC);
var a = alc.LoadFromAssemblyPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Unloaded.dll"));
var a = alc.LoadFromAssemblyPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "StaticsUnloaded.dll"));

var accessor = (IStaticTest)Activator.CreateInstance(a.GetType("StaticTest"));
accessor.SetStatic(12759, 548739, 5468, 8518, 9995);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="Unloaded.csproj" />
<ProjectReference Include="StaticsUnloaded.csproj" />
<ProjectReference Include="Accessor.csproj" />
<Compile Include="CollectibleStatics.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="Accessor.csproj" />
<Compile Include="Unloaded.cs" />
<Compile Include="StaticsUnloaded.cs" />
</ItemGroup>
</Project>
15 changes: 7 additions & 8 deletions src/tests/Loader/ContextualReflection/ContextualReflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@ class MockAssembly : Assembly
public MockAssembly() {}
}

class Program : IProgram
public class Program : IProgram
{
public AssemblyLoadContext alc { get; set; }
public Assembly alcAssembly { get; set; }
public Type alcProgramType { get; set; }
public IProgram alcProgramInstance { get; set; }
public Assembly defaultAssembly { get; set; }

public static int Main()
[Fact]
public static void TestEntryPoint()
{
Program program = new Program(isolated:false);

program.RunTests();

Console.WriteLine("Success");

return 100;
}

public Program()
Expand Down Expand Up @@ -84,7 +83,7 @@ void VerifyIsolationDefault()
VerifyIsolation();
Assert.Equal(defaultAssembly, Assembly.GetExecutingAssembly());
Assert.Equal(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()));
Assert.NotEqual(alcProgramType, typeof(Program));
Assert.NotEqual(typeof(Program), alcProgramType);
Assert.NotEqual((object)alcProgramInstance, (object)this);
}

Expand All @@ -93,7 +92,7 @@ void VerifyIsolationAlc()
VerifyIsolation();
Assert.Equal(alcAssembly, Assembly.GetExecutingAssembly());
Assert.Equal(alc, AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()));
Assert.Equal(alcProgramType, typeof(Program));
Assert.Equal(typeof(Program), alcProgramType);
Assert.Equal((object)alcProgramInstance, (object)this);
}

Expand Down Expand Up @@ -286,7 +285,7 @@ void VerifyBadContextualReflectionUsage()
try
{
IDisposable defaultScope = AssemblyLoadContext.EnterContextualReflection(null);
Assert.Equal(null, AssemblyLoadContext.CurrentContextualReflectionContext);
Assert.Null(AssemblyLoadContext.CurrentContextualReflectionContext);

throw new InvalidOperationException();
}
Expand Down Expand Up @@ -738,7 +737,7 @@ void TestDefineDynamicAssembly(bool collectibleContext, AssemblyBuilderAccess as

AssemblyLoadContext context = AssemblyLoadContext.GetLoadContext(assemblyBuilder);
Assert.Equal(assemblyLoadContext, context);
Assert.True(assemblyLoadContext.Assemblies.Any(a => AssemblyName.ReferenceMatchesDefinition(a.GetName(), assemblyBuilder.GetName())));
Assert.Contains(assemblyLoadContext.Assemblies, a => AssemblyName.ReferenceMatchesDefinition(a.GetName(), assemblyBuilder.GetName()));
}

void TestMockAssemblyThrows()
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 UnloadabilityIncompatible -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<!-- The test uses AssemblyLoadContext (directly) to load the test assembly and its dependency that's part of the test again.
When the test is loaded into an unloadable context in the runincontext tool, the dependency assembly cannot be found
since it is in a different folder than the runincontext tool. -->
Expand Down
9 changes: 5 additions & 4 deletions src/tests/Loader/CustomAttributes/DynamicObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
namespace DynamicObjects {
public class M {
public const string ObjectRequiredMessage = "some string";
public static int Main() {
[Fact]
public static void TestEntryPoint()
{
var instance = createObject();
var attrs = instance.GetType().GetProperty("prop1").GetCustomAttributes();

Assert.True(attrs.Count() == 2);
Assert.Equal(attrs.ElementAt(0).ToString(), "System.ComponentModel.DataAnnotations.DisplayAttribute");
Assert.Equal(attrs.ElementAt(1).ToString(), "System.ComponentModel.DataAnnotations.RequiredAttribute");
Assert.Equal("System.ComponentModel.DataAnnotations.DisplayAttribute", attrs.ElementAt(0).ToString());
Assert.Equal("System.ComponentModel.DataAnnotations.RequiredAttribute", attrs.ElementAt(1).ToString());
Assert.Equal(typeof(RequiredAttribute), attrs.ElementAt(1).GetType());
Assert.Equal(ObjectRequiredMessage, ((RequiredAttribute)attrs.ElementAt(1)).FormatErrorMessage("abc"));

Console.WriteLine("Success");
return 100;
}

public static object createObject () {
Expand Down
3 changes: 2 additions & 1 deletion src/tests/Loader/CustomAttributes/DynamicObjects.csproj
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 mechanical merging of all remaining tests, this particular project may not actually need process isolation -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
Expand Down
11 changes: 11 additions & 0 deletions src/tests/Loader/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Merged.props', $(MSBuildThisFileDirectory)..))" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<RunAnalyzers>true</RunAnalyzers>
<NoWarn>$(NoWarn);xUnit1013</NoWarn>
<EnableNETAnalyzers>false</EnableNETAnalyzers>
</PropertyGroup>
</Project>
13 changes: 13 additions & 0 deletions src/tests/Loader/Loader.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<MergedWrapperProjectReference Include="*/**/*.??proj" />
<MergedWrapperProjectReference Remove="$(MSBuildProjectName).csproj" />
<MergedWrapperProjectReference Remove="classloader/generics/**/*.??proj" />
<MergedWrapperProjectReference Remove="classloader/regressions/**/*.??proj" />
<MergedWrapperProjectReference Remove="classloader/TypeGeneratorTests/**/*.??proj" />
<MergedWrapperProjectReference Remove="classloader/StaticVirtualMethods/GenericContext/Generator/**/*.??proj" />
<MergedWrapperProjectReference Remove="classloader/StaticVirtualMethods/TypeHierarchy/Generator/**/*.??proj" />
</ItemGroup>

<Import Project="$(TestSourceDir)MergedTestRunner.targets" />
</Project>
Loading
Loading