Skip to content

Commit

Permalink
Move ManagedHost project for host tests to pre-built test asset (dotn…
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung authored Feb 6, 2024
1 parent 85b5eab commit 5d3a3c1
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

</Project>
10 changes: 10 additions & 0 deletions src/installer/tests/Assets/Projects/ManagedHost/RegFreeCom.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ApplicationManifest>App.manifest</ApplicationManifest>
</PropertyGroup>

</Project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public void ManagedHost(bool selfContained)
"comhost",
sharedState.ClsidString
};
TestProjectFixture fixture = selfContained ? sharedState.ManagedHostFixture_SelfContained : sharedState.ManagedHostFixture_FrameworkDependent;
CommandResult result = Command.Create(fixture.TestProject.AppExe, args)
TestApp app = selfContained ? sharedState.ManagedHost_SelfContained : sharedState.ManagedHost_FrameworkDependent;
CommandResult result = Command.Create(app.AppExe, args)
.EnableTracingAndCaptureOutputs()
.DotNetRoot(fixture.BuiltDotnet.BinPath)
.DotNetRoot(TestContext.BuiltDotNet.BinPath)
.MultilevelLookup(false)
.Execute();

Expand All @@ -85,8 +85,8 @@ public class SharedTestState : Comhost.SharedTestState

public string ComSxsPath { get; }

public TestProjectFixture ManagedHostFixture_FrameworkDependent { get; }
public TestProjectFixture ManagedHostFixture_SelfContained { get; }
public TestApp ManagedHost_FrameworkDependent { get; }
public TestApp ManagedHost_SelfContained { get; }

public SharedTestState()
{
Expand Down Expand Up @@ -122,15 +122,14 @@ public SharedTestState()
Path.Combine(RepoDirectoriesProvider.Default.HostTestArtifacts, comsxsName),
ComSxsPath);

ManagedHostFixture_FrameworkDependent = new TestProjectFixture("ManagedHost", RepoDirectories)
.EnsureRestored()
.PublishProject(selfContained: false, extraArgs: "/p:RegFreeCom=true");
File.Copy(regFreeManifestPath, Path.Combine(ManagedHostFixture_FrameworkDependent.TestProject.BuiltApp.Location, regFreeManifestName));
ManagedHost_FrameworkDependent = TestApp.CreateFromBuiltAssets("RegFreeCom");
ManagedHost_FrameworkDependent.CreateAppHost();
File.Copy(regFreeManifestPath, Path.Combine(ManagedHost_FrameworkDependent.Location, regFreeManifestName));

ManagedHostFixture_SelfContained = new TestProjectFixture("ManagedHost", RepoDirectories)
.EnsureRestored()
.PublishProject(selfContained: true, extraArgs: "/p:RegFreeCom=true");
File.Copy(regFreeManifestPath, Path.Combine(ManagedHostFixture_SelfContained.TestProject.BuiltApp.Location, regFreeManifestName));
ManagedHost_SelfContained = TestApp.CreateFromBuiltAssets("RegFreeCom");
ManagedHost_SelfContained.PopulateSelfContained(TestApp.MockedComponent.None);
ManagedHost_FrameworkDependent.CreateAppHost();
File.Copy(regFreeManifestPath, Path.Combine(ManagedHost_SelfContained.Location, regFreeManifestName));

// Copy the ComLibrary output and comhost to the ComSxS and ManagedHost directories
string[] toCopy = {
Expand All @@ -142,15 +141,15 @@ public SharedTestState()
foreach (string filePath in toCopy)
{
File.Copy(filePath, Path.Combine(comsxsDirectory, Path.GetFileName(filePath)));
File.Copy(filePath, Path.Combine(ManagedHostFixture_FrameworkDependent.TestProject.BuiltApp.Location, Path.GetFileName(filePath)));
File.Copy(filePath, Path.Combine(ManagedHostFixture_SelfContained.TestProject.BuiltApp.Location, Path.GetFileName(filePath)));
File.Copy(filePath, Path.Combine(ManagedHost_FrameworkDependent.Location, Path.GetFileName(filePath)));
File.Copy(filePath, Path.Combine(ManagedHost_SelfContained.Location, Path.GetFileName(filePath)));
}
}

protected override void Dispose(bool disposing)
{
ManagedHostFixture_FrameworkDependent.Dispose();
ManagedHostFixture_SelfContained.Dispose();
ManagedHost_FrameworkDependent?.Dispose();
ManagedHost_SelfContained?.Dispose();

base.Dispose(disposing);
}
Expand Down
41 changes: 17 additions & 24 deletions src/installer/tests/HostActivation.Tests/NativeHosting/Ijwhost.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// 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.IO;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;

using Microsoft.DotNet.Cli.Build.Framework;
using Xunit;
Expand Down Expand Up @@ -40,7 +36,7 @@ public void LoadLibrary(bool no_runtimeconfig)
File.Delete(app.RuntimeConfigJson);
}

CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.RepoDirectories.BuiltDotnet)
CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath)
.Execute();

if (no_runtimeconfig)
Expand Down Expand Up @@ -69,13 +65,13 @@ public void LoadLibraryWithoutRuntimeConfigButActiveRuntime()
"ijwhost",
app.AppDll,
"NativeEntryPoint",
sharedState.HostFxrPath, // optional 4th and 5th arguments that tell nativehost to start the runtime before loading the C++/CLI library
TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath, // optional 4th and 5th arguments that tell nativehost to start the runtime before loading the C++/CLI library
startupConfigPath
};

File.Move(app.RuntimeConfigJson, startupConfigPath);

CommandResult result = sharedState.CreateNativeHostCommand(args, sharedState.RepoDirectories.BuiltDotnet)
CommandResult result = sharedState.CreateNativeHostCommand(args, TestContext.BuiltDotNet.BinPath)
.Execute();

result.Should().Pass()
Expand All @@ -94,10 +90,10 @@ public void ManagedHost(bool selfContained)
sharedState.IjwApp.AppDll,
"NativeEntryPoint"
};
TestProjectFixture fixture = selfContained ? sharedState.ManagedHostFixture_SelfContained : sharedState.ManagedHostFixture_FrameworkDependent;
CommandResult result = Command.Create(fixture.TestProject.AppExe, args)
TestApp app = selfContained ? sharedState.ManagedHost_SelfContained : sharedState.ManagedHost_FrameworkDependent;
CommandResult result = Command.Create(app.AppExe, args)
.EnableTracingAndCaptureOutputs()
.DotNetRoot(fixture.BuiltDotnet.BinPath)
.DotNetRoot(TestContext.BuiltDotNet.BinPath)
.MultilevelLookup(false)
.Execute();

Expand All @@ -109,42 +105,39 @@ public void ManagedHost(bool selfContained)

public class SharedTestState : SharedTestStateBase
{
public string HostFxrPath { get; }
public TestProjectFixture ManagedHostFixture_FrameworkDependent { get; }
public TestProjectFixture ManagedHostFixture_SelfContained { get; }
public TestApp ManagedHost_FrameworkDependent { get; }
public TestApp ManagedHost_SelfContained { get; }
public TestApp IjwApp {get;}

public SharedTestState()
{
HostFxrPath = TestContext.BuiltDotNet.GreatestVersionHostFxrFilePath;
string folder = Path.Combine(BaseDirectory, "ijw");
IjwApp = new TestApp(folder, "ijw");
// Copy over ijwhost
string ijwhostName = "ijwhost.dll";
File.Copy(Path.Combine(RepoDirectories.HostArtifacts, ijwhostName), Path.Combine(folder, ijwhostName));
File.Copy(Path.Combine(RepoDirectoriesProvider.Default.HostArtifacts, ijwhostName), Path.Combine(folder, ijwhostName));

// Copy over the C++/CLI test library
string ijwLibraryName = "ijw.dll";
File.Copy(Path.Combine(RepoDirectories.HostTestArtifacts, ijwLibraryName), Path.Combine(folder, ijwLibraryName));
File.Copy(Path.Combine(RepoDirectoriesProvider.Default.HostTestArtifacts, ijwLibraryName), Path.Combine(folder, ijwLibraryName));

// Create a runtimeconfig.json for the C++/CLI test library
new RuntimeConfig(Path.Combine(folder, "ijw.runtimeconfig.json"))
.WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, TestContext.MicrosoftNETCoreAppVersion))
.Save();

ManagedHostFixture_FrameworkDependent = new TestProjectFixture("ManagedHost", RepoDirectories)
.EnsureRestored()
.PublishProject(selfContained: false);
ManagedHost_FrameworkDependent = TestApp.CreateFromBuiltAssets("ManagedHost");
ManagedHost_FrameworkDependent.CreateAppHost();

ManagedHostFixture_SelfContained = new TestProjectFixture("ManagedHost", RepoDirectories)
.EnsureRestored()
.PublishProject(selfContained: true);
ManagedHost_SelfContained = TestApp.CreateFromBuiltAssets("ManagedHost");
ManagedHost_SelfContained.PopulateSelfContained(TestApp.MockedComponent.None);
ManagedHost_FrameworkDependent.CreateAppHost();
}

protected override void Dispose(bool disposing)
{
ManagedHostFixture_FrameworkDependent.Dispose();
ManagedHostFixture_SelfContained.Dispose();
ManagedHost_FrameworkDependent?.Dispose();
ManagedHost_SelfContained?.Dispose();

base.Dispose(disposing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public SharedTestState()
string productDir = Path.Combine(BaseDirectory, "product");
Directory.CreateDirectory(productDir);
ProductHostFxrPath = Path.Combine(productDir, HostFxrName);
File.Copy(Path.Combine(RepoDirectories.HostArtifacts, HostFxrName), ProductHostFxrPath);
File.Copy(Binaries.HostFxr.FilePath, ProductHostFxrPath);
}

private string CreateHostFxr(string destinationDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class SharedTestStateBase : IDisposable
public string BaseDirectory { get; }
public string NativeHostPath { get; }
public string NethostPath { get; }
public RepoDirectoriesProvider RepoDirectories { get; }

private readonly TestArtifact _baseDirArtifact;

Expand All @@ -27,8 +26,7 @@ public SharedTestStateBase()
NativeHostPath = Path.Combine(BaseDirectory, nativeHostName);

// Copy over native host
RepoDirectories = new RepoDirectoriesProvider();
File.Copy(Path.Combine(RepoDirectories.HostTestArtifacts, nativeHostName), NativeHostPath);
File.Copy(Path.Combine(RepoDirectoriesProvider.Default.HostTestArtifacts, nativeHostName), NativeHostPath);

// Copy nethost next to native host
// This is done even for tests not directly using nethost because nativehost consumes nethost in the more
Expand Down

0 comments on commit 5d3a3c1

Please sign in to comment.