Skip to content

Commit

Permalink
Move AppWithCustomEntryPoints ond ComponentWithNoDependencies to pre-…
Browse files Browse the repository at this point in the history
…built test assets (dotnet#97477)
  • Loading branch information
elinor-fung authored Jan 25, 2024
1 parent ee5d986 commit f532ff6
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<OutputType>Exe</OutputType>
<RuntimeIdentifier>$(TestTargetRid)</RuntimeIdentifier>
<RuntimeFrameworkVersion>$(MNAVersion)</RuntimeFrameworkVersion>
<SelfContained>true</SelfContained>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<RuntimeFrameworkVersion>$(MNAVersion)</RuntimeFrameworkVersion>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.Cli.Build.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

using Microsoft.DotNet.Cli.Build.Framework;
using Xunit;

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting
Expand All @@ -29,26 +27,26 @@ public GetFunctionPointer(SharedTestState sharedTestState)
[InlineData(true, false)]
public void CallDelegateOnApplicationContext(bool validType, bool validMethod)
{
var appProject = sharedState.ApplicationFixture.TestProject;
var app = sharedState.App;
string[] args =
{
AppGetFunctionPointerArg,
sharedState.HostFxrPath,
appProject.AppDll,
validType ? sharedState.FunctionPointerTypeName : $"Component.BadType, {appProject.AssemblyName}",
app.AppDll,
validType ? sharedState.FunctionPointerTypeName : $"Component.BadType, {app.AssemblyName}",
validMethod ? sharedState.FunctionPointerEntryPoint1 : "BadMethod",
};
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should()
.InitializeContextForApp(appProject.AppDll);
.InitializeContextForApp(app.AppDll);

if (validType && validMethod)
{
result.Should().Pass()
.And.ExecuteFunctionPointer(sharedState.FunctionPointerEntryPoint1, 1, 1)
.And.ExecuteInDefaultContext(appProject.AssemblyName);
.And.ExecuteInDefaultContext(app.AssemblyName);
}
else
{
Expand All @@ -62,20 +60,20 @@ public void CallDelegateOnApplicationContext(bool validType, bool validMethod)
[InlineData(true, false)]
public void CallDelegateOnComponentContext(bool validType, bool validMethod)
{
var componentProject = sharedState.ComponentWithNoDependenciesFixture.TestProject;
var component = sharedState.Component;
string[] args =
{
ComponentGetFunctionPointerArg,
sharedState.HostFxrPath,
componentProject.RuntimeConfigJson,
validType ? sharedState.ComponentTypeName : $"Component.BadType, {componentProject.AssemblyName}",
component.RuntimeConfigJson,
validType ? sharedState.ComponentTypeName : $"Component.BadType, {component.AssemblyName}",
validMethod ? sharedState.ComponentEntryPoint1 : "BadMethod",
};
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should()
.InitializeContextForConfig(componentProject.RuntimeConfigJson);
.InitializeContextForConfig(component.RuntimeConfigJson);

// This should fail even with the valid type and valid method,
// because the type is not resolvable from the default AssemblyLoadContext.
Expand All @@ -85,22 +83,22 @@ public void CallDelegateOnComponentContext(bool validType, bool validMethod)
[Fact]
public void CallDelegateOnSelfContainedApplicationContext()
{
var appProject = sharedState.SelfContainedApplicationFixture.TestProject;
var app = sharedState.SelfContainedApp;
string[] args =
{
AppGetFunctionPointerArg,
appProject.HostFxrDll,
appProject.AppDll,
app.HostFxrDll,
app.AppDll,
sharedState.FunctionPointerTypeName,
sharedState.FunctionPointerEntryPoint1,
};
CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute();

result.Should().Pass()
.And.InitializeContextForApp(appProject.AppDll)
.And.InitializeContextForApp(app.AppDll)
.And.ExecuteFunctionPointer(sharedState.FunctionPointerEntryPoint1, 1, 1)
.And.ExecuteInDefaultContext(appProject.AssemblyName);
.And.ExecuteInDefaultContext(app.AssemblyName);
}

[Theory]
Expand All @@ -110,12 +108,12 @@ public void CallDelegateOnSelfContainedApplicationContext()
[InlineData(10, true)]
public void CallDelegateOnApplicationContext_MultipleEntryPoints(int callCount, bool callUnmanaged)
{
var appProject = sharedState.ApplicationFixture.TestProject;
var app = sharedState.App;
string[] baseArgs =
{
AppGetFunctionPointerArg,
sharedState.HostFxrPath,
appProject.AppDll,
app.AppDll,
};

string functionPointer1Name = callUnmanaged ? sharedState.UnmanagedFunctionPointerEntryPoint1 : sharedState.FunctionPointerEntryPoint1;
Expand All @@ -139,8 +137,8 @@ public void CallDelegateOnApplicationContext_MultipleEntryPoints(int callCount,
.Execute();

result.Should().Pass()
.And.InitializeContextForApp(appProject.AppDll)
.And.ExecuteInDefaultContext(appProject.AssemblyName);
.And.InitializeContextForApp(app.AppDll)
.And.ExecuteInDefaultContext(app.AssemblyName);

for (int i = 1; i <= callCount; ++i)
{
Expand All @@ -155,12 +153,12 @@ public void CallDelegateOnApplicationContext_MultipleEntryPoints(int callCount,
[InlineData(10)]
public void CallDelegateOnApplicationContext_MultipleFunctionPointers(int callCount)
{
var appProject = sharedState.ApplicationFixture.TestProject;
var app = sharedState.App;
string[] baseArgs =
{
AppGetFunctionPointerArg,
sharedState.HostFxrPath,
appProject.AppDll,
app.AppDll,
};
string[] componentInfo =
{
Expand All @@ -181,8 +179,8 @@ public void CallDelegateOnApplicationContext_MultipleFunctionPointers(int callCo
.Execute();

result.Should().Pass()
.And.InitializeContextForApp(appProject.AppDll)
.And.ExecuteInDefaultContext(appProject.AssemblyName);
.And.InitializeContextForApp(app.AppDll)
.And.ExecuteInDefaultContext(app.AssemblyName);

for (int i = 1; i <= callCount; ++i)
{
Expand All @@ -196,20 +194,20 @@ public void CallDelegateOnApplicationContext_MultipleFunctionPointers(int callCo
public void CallDelegateOnApplicationContext_UnhandledException()
{
string entryPoint = "ThrowException";
var appProject = sharedState.ApplicationFixture.TestProject;
var app = sharedState.App;
string[] args =
{
AppGetFunctionPointerArg,
sharedState.HostFxrPath,
appProject.AppDll,
app.AppDll,
sharedState.FunctionPointerTypeName,
entryPoint,
};

sharedState.CreateNativeHostCommand(args, sharedState.DotNetRoot)
.Execute(expectedToFail: true)
.Should().Fail()
.And.InitializeContextForApp(appProject.AppDll)
.And.InitializeContextForApp(app.AppDll)
.And.ExecuteFunctionPointerWithException(entryPoint, 1);
}

Expand All @@ -218,9 +216,10 @@ public class SharedTestState : SharedTestStateBase
public string HostFxrPath { get; }
public string DotNetRoot { get; }

public TestProjectFixture ApplicationFixture { get; }
public TestProjectFixture ComponentWithNoDependenciesFixture { get; }
public TestProjectFixture SelfContainedApplicationFixture { get; }
public TestApp App { get; }
public TestApp Component { get; }
public TestApp SelfContainedApp { get; }

public string ComponentTypeName { get; }
public string ComponentEntryPoint1 => "ComponentEntryPoint1";
public string FunctionPointerTypeName { get; }
Expand All @@ -233,27 +232,20 @@ public SharedTestState()
DotNetRoot = TestContext.BuiltDotNet.BinPath;
HostFxrPath = TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath;

ApplicationFixture = new TestProjectFixture("AppWithCustomEntryPoints", RepoDirectories)
.EnsureRestored()
.PublishProject(selfContained: false);
ComponentWithNoDependenciesFixture = new TestProjectFixture("ComponentWithNoDependencies", RepoDirectories)
.EnsureRestored()
.PublishProject();
SelfContainedApplicationFixture = new TestProjectFixture("AppWithCustomEntryPoints", RepoDirectories)
.EnsureRestored()
.PublishProject(selfContained: true);
ComponentTypeName = $"Component.Component, {ComponentWithNoDependenciesFixture.TestProject.AssemblyName}";
FunctionPointerTypeName = $"AppWithCustomEntryPoints.Program, {ApplicationFixture.TestProject.AssemblyName}";
App = TestApp.CreateFromBuiltAssets("AppWithCustomEntryPoints");
Component = TestApp.CreateFromBuiltAssets("Component");
SelfContainedApp = TestApp.CreateFromBuiltAssets("AppWithCustomEntryPoints");
SelfContainedApp.PopulateSelfContained(TestApp.MockedComponent.None);

ComponentTypeName = $"Component.Component, {Component.AssemblyName}";
FunctionPointerTypeName = $"AppWithCustomEntryPoints.Program, {App.AssemblyName}";
}

protected override void Dispose(bool disposing)
{
if (ApplicationFixture != null)
ApplicationFixture.Dispose();
if (ComponentWithNoDependenciesFixture != null)
ComponentWithNoDependenciesFixture.Dispose();
if (SelfContainedApplicationFixture != null)
SelfContainedApplicationFixture.Dispose();
App?.Dispose();
Component?.Dispose();
SelfContainedApp?.Dispose();

base.Dispose(disposing);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.Cli.Build.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

using Microsoft.DotNet.Cli.Build.Framework;
using Xunit;

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting
Expand Down Expand Up @@ -139,11 +138,9 @@ public class SharedTestState : SharedTestStateBase
public string DotNetRoot { get; }

public TestApp Application { get; }
public TestApp Component { get; }
public TestApp SelfContainedApplication { get; }

public TestProjectFixture ComponentWithNoDependenciesFixture { get; }
public TestApp Component => ComponentWithNoDependenciesFixture.TestProject.BuiltApp;

public string ComponentTypeName { get; }
public string ComponentEntryPoint1 => "ComponentEntryPoint1";

Expand All @@ -158,11 +155,8 @@ public SharedTestState()
SelfContainedApplication = TestApp.CreateEmpty("SelfContainedApp");
SelfContainedApplication.PopulateSelfContained(TestApp.MockedComponent.None);

ComponentWithNoDependenciesFixture = new TestProjectFixture("ComponentWithNoDependencies", RepoDirectories)
.EnsureRestored()
.PublishProject();

ComponentTypeName = $"Component.Component, {ComponentWithNoDependenciesFixture.TestProject.AssemblyName}";
Component = TestApp.CreateFromBuiltAssets("Component");
ComponentTypeName = $"Component.Component, {Component.AssemblyName}";
}

internal IEnumerable<string> GetComponentLoadArgs(bool loadAssemblyBytes, bool loadSymbolBytes)
Expand All @@ -178,14 +172,9 @@ internal IEnumerable<string> GetComponentLoadArgs(bool loadAssemblyBytes, bool l

protected override void Dispose(bool disposing)
{
if (Application != null)
Application.Dispose();

if (SelfContainedApplication != null)
SelfContainedApplication.Dispose();

if (ComponentWithNoDependenciesFixture != null)
ComponentWithNoDependenciesFixture.Dispose();
Application?.Dispose();
Component?.Dispose();
SelfContainedApplication?.Dispose();

base.Dispose(disposing);
}
Expand Down
Loading

0 comments on commit f532ff6

Please sign in to comment.