public void MissingFrameworkInRuntimeConfig_Fails(bool useAppHost) { TestApp app = sharedTestState.MockApp.Copy(); RuntimeConfig.FromFile(app.RuntimeConfigJson).Save(); Command command; if (useAppHost) { command = Command.Create(app.AppExe) .DotNetRoot(sharedTestState.BuiltDotNet.BinPath); } else { command = sharedTestState.BuiltDotNet.Exec(app.AppDll); } string hostPolicyName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostpolicy"); command.EnableTracingAndCaptureOutputs() .MultilevelLookup(false) .Execute() .Should().Fail() .And.HaveStdErrContaining($"The library '{hostPolicyName}' required to execute the application was not found") .And.HaveStdErrContaining("Failed to run as a self-contained app") .And.HaveStdErrContaining($"'{app.RuntimeConfigJson}' did not specify a framework"); }
public SharedTestStateBase() { BaseDirectory = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "nativeHosting")); _baseDirArtifact = new TestArtifact(BaseDirectory); Directory.CreateDirectory(BaseDirectory); string nativeHostName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("nativehost"); NativeHostPath = Path.Combine(BaseDirectory, nativeHostName); // Copy over native host RepoDirectories = new RepoDirectoriesProvider(); File.Copy(Path.Combine(RepoDirectories.Artifacts, "corehost_test", 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 // user-friendly way of linking against nethost (instead of dlopen/LoadLibrary and dlsym/GetProcAddress). // On Windows, we can delay load through a linker option, but on other platforms load is required on start. string nethostName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("nethost"); NethostPath = Path.Combine(Path.GetDirectoryName(NativeHostPath), nethostName); File.Copy( Path.Combine(RepoDirectories.HostArtifacts, nethostName), NethostPath); }
public SharedTestState() { // Copy nethost next to native host string nethostName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("nethost"); File.Copy( Path.Combine(RepoDirectories.CorehostPackages, nethostName), Path.Combine(Path.GetDirectoryName(NativeHostPath), nethostName)); InvalidInstallRoot = Path.Combine(BaseDirectory, "invalid"); Directory.CreateDirectory(InvalidInstallRoot); ValidInstallRoot = Path.Combine(BaseDirectory, "valid"); HostFxrPath = CreateHostFxr(Path.Combine(ValidInstallRoot, "dotnet")); string appDir = Path.Combine(BaseDirectory, "app"); Directory.CreateDirectory(appDir); string assemblyPath = Path.Combine(appDir, "App.dll"); File.WriteAllText(assemblyPath, string.Empty); TestAssemblyPath = assemblyPath; string productDir = Path.Combine(BaseDirectory, "product"); Directory.CreateDirectory(productDir); ProductHostFxrPath = Path.Combine(productDir, HostFxrName); File.Copy(Path.Combine(RepoDirectories.CorehostPackages, HostFxrName), ProductHostFxrPath); }
public SharedTestState() { BaseDirectory = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "nativeHosting")); Directory.CreateDirectory(BaseDirectory); string nativeHostName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("nativehost"); NativeHostPath = Path.Combine(BaseDirectory, nativeHostName); // Copy over native host and nethost RepoDirectories = new RepoDirectoriesProvider(); string nethostName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("nethost"); File.Copy(Path.Combine(RepoDirectories.CorehostPackages, nethostName), Path.Combine(BaseDirectory, nethostName)); File.Copy(Path.Combine(RepoDirectories.Artifacts, "corehost_test", nativeHostName), NativeHostPath); InvalidInstallRoot = Path.Combine(BaseDirectory, "invalid"); Directory.CreateDirectory(InvalidInstallRoot); ValidInstallRoot = Path.Combine(BaseDirectory, "valid"); HostFxrPath = CreateHostFxr(Path.Combine(ValidInstallRoot, "dotnet")); string appDir = Path.Combine(BaseDirectory, "app"); Directory.CreateDirectory(appDir); string assemblyPath = Path.Combine(appDir, "App.dll"); File.WriteAllText(assemblyPath, string.Empty); TestAssemblyPath = assemblyPath; }
public SharedTestState() { RepoDirectories = new RepoDirectoriesProvider(); HostApiInvokerAppFixture = new TestProjectFixture("HostApiInvokerApp", RepoDirectories) .EnsureRestored(RepoDirectories.CorehostPackages) .BuildProject(); ComponentWithNoDependencies = CreateComponentWithNoDependencies(null, Location); ComponentWithDependencies = CreateComponentWithDependencies(null, Location); ComponentWithResources = CreateComponentWithResources(null, Location); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // On non-Windows, we can't just P/Invoke to already loaded hostpolicy, so copy it next to the app dll. var fixture = HostApiInvokerAppFixture; var hostpolicy = Path.Combine( fixture.BuiltDotnet.GreatestVersionSharedFxPath, RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostpolicy")); File.Copy( hostpolicy, Path.GetDirectoryName(fixture.TestProject.AppDll)); } }
public void Running_Publish_Output_Standalone_EXE_By_Renaming_dotnet_exe_Fails() { var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); var appExe = fixture.TestProject.AppExe; string hostExeName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet"); string builtHost = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName); File.Copy(builtHost, appExe, true); int exitCode = Command.Create(appExe) .CaptureStdErr() .CaptureStdOut() .Execute(fExpectedToFail: true) .ExitCode; if (OperatingSystem.IsWindows()) { exitCode.Should().Be(-2147450748); } else { // Some Unix flavors filter exit code to ubyte. (exitCode & 0xFF).Should().Be(0x84); } }
/// <summary> /// Add a mock of the Microsoft.NETCore.App framework with the specified version /// </summary> /// <param name="version">Version to add</param> /// <param name="customizer">Customizer to customize the framework before it is built</param> /// <remarks> /// Product runtime binaries are not added. All the added mock framework will contain is hostpolicy, /// a mock version of coreclr, and a minimal Microsoft.NETCore.App.deps.json. /// </remarks> public DotNetBuilder AddMicrosoftNETCoreAppFrameworkMockCoreClr(string version, Action <NetCoreAppBuilder> customizer = null) { // ./shared/Microsoft.NETCore.App/<version> - create a mock of the root framework string netCoreAppPath = Path.Combine(_path, "shared", "Microsoft.NETCore.App", version); Directory.CreateDirectory(netCoreAppPath); string hostPolicyFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostpolicy"); string coreclrFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("coreclr"); string mockCoreclrFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("mockcoreclr"); string currentRid = _repoDirectories.TargetRID; NetCoreAppBuilder.ForNETCoreApp("Microsoft.NETCore.App", currentRid) .WithStandardRuntimeFallbacks() .WithProject("Microsoft.NETCore.App", version, p => p .WithNativeLibraryGroup(null, g => g // ./shared/Microsoft.NETCore.App/<version>/coreclr.dll - this is a mock, will not actually run CoreClr .WithAsset((new NetCoreAppBuilder.RuntimeFileBuilder($"runtimes/{currentRid}/native/{coreclrFileName}")) .CopyFromFile(Path.Combine(_repoDirectories.Artifacts, "corehost_test", mockCoreclrFileName)) .WithFileOnDiskPath(coreclrFileName)))) .WithPackage($"runtime.{currentRid}.Microsoft.NETCore.DotNetHostPolicy", version, p => p .WithNativeLibraryGroup(null, g => g // ./shared/Microsoft.NETCore.App/<version>/hostpolicy.dll - this is the real component and will load CoreClr library .WithAsset((new NetCoreAppBuilder.RuntimeFileBuilder($"runtimes/{currentRid}/native/{hostPolicyFileName}")) .CopyFromFile(Path.Combine(_repoDirectories.Artifacts, "corehost", hostPolicyFileName)) .WithFileOnDiskPath(hostPolicyFileName)))) .WithCustomizer(customizer) .Build(new TestApp(netCoreAppPath, "Microsoft.NETCore.App")); return(this); }
public SingleFileSharedState() { // We include mockcoreclr in our project to test native binaries extraction. string mockCoreClrPath = Path.Combine(RepoDirectories.Artifacts, "corehost_test", RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("mockcoreclr")); TestFixture = PreparePublishedSelfContainedTestProject("SingleFileApiTests", $"/p:AddFile={mockCoreClrPath}"); }
// This helper is used in lieu of SDK support for publishing apps using the singlefilehost. // It replaces the apphost with singlefilehost, and along with appropriate app.dll updates in the host. // For now, we leave behind the hostpolicy and hostfxr DLLs in the publish directory, because // removing them requires deps.json update. void ReplaceApphostWithStaticHost(TestProjectFixture fixture) { var staticHost = Path.Combine(fixture.RepoDirProvider.HostArtifacts, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("singlefilehost")); HostWriter.CreateAppHost(staticHost, BundleHelper.GetHostPath(fixture), BundleHelper.GetAppPath(fixture)); }
public SharedTestState() { var dotNet = new DotNetBuilder(BaseDirectory, Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), "mockRuntime") .AddMicrosoftNETCoreAppFrameworkMockCoreClr(NetCoreAppVersion) .Build(); DotNetRoot = dotNet.BinPath; HostFxrPath = Path.Combine( dotNet.GreatestVersionHostFxrPath, RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr")); string appDir = Path.Combine(BaseDirectory, "app"); Directory.CreateDirectory(appDir); AppPath = Path.Combine(appDir, "App.dll"); File.WriteAllText(AppPath, string.Empty); RuntimeConfig.FromFile(Path.Combine(appDir, "App.runtimeconfig.json")) .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion)) .WithProperty(AppPropertyName, AppPropertyValue) .Save(); AppPath_MultiProperty = Path.Combine(appDir, "App_MultiProperty.dll"); File.WriteAllText(AppPath_MultiProperty, string.Empty); RuntimeConfig.FromFile(Path.Combine(appDir, "App_MultiProperty.runtimeconfig.json")) .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion)) .WithProperty(AppPropertyName, AppPropertyValue) .WithProperty(AppMultiPropertyName, AppMultiPropertyValue) .Save(); string configDir = Path.Combine(BaseDirectory, "config"); Directory.CreateDirectory(configDir); RuntimeConfigPath = Path.Combine(configDir, "Component.runtimeconfig.json"); RuntimeConfig.FromFile(RuntimeConfigPath) .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion)) .WithProperty(ConfigPropertyName, ConfigPropertyValue) .Save(); RuntimeConfigPath_MultiProperty = Path.Combine(configDir, "Component_MultiProperty.runtimeconfig.json"); RuntimeConfig.FromFile(RuntimeConfigPath_MultiProperty) .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion)) .WithProperty(ConfigPropertyName, ConfigPropertyValue) .WithProperty(ConfigMultiPropertyName, ConfigMultiPropertyValue) .Save(); string secondaryDir = Path.Combine(BaseDirectory, "secondary"); Directory.CreateDirectory(secondaryDir); SecondaryRuntimeConfigPath = Path.Combine(secondaryDir, "Secondary.runtimeconfig.json"); RuntimeConfig.FromFile(SecondaryRuntimeConfigPath) .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion)) .WithProperty(SecondaryConfigPropertyName, SecondaryConfigPropertyValue) .Save(); }
public void Framework_Dependent_AppHost_Succeeds() { var fixture = sharedTestState.PortableAppFixture_Published .Copy(); // Since SDK doesn't support building framework dependent apphost yet, emulate that behavior // by creating the executable from apphost.exe var appExe = fixture.TestProject.AppExe; var appDllName = Path.GetFileName(fixture.TestProject.AppDll); string hostExeName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost"); string builtAppHost = Path.Combine(sharedTestState.RepoDirectories.HostArtifacts, hostExeName); string appDir = Path.GetDirectoryName(appExe); string appDirHostExe = Path.Combine(appDir, hostExeName); // Make a copy of apphost first, replace hash and overwrite app.exe, rather than // overwrite app.exe and edit in place, because the file is opened as "write" for // the replacement -- the test fails with ETXTBSY (exit code: 26) in Linux when // executing a file opened in "write" mode. File.Copy(builtAppHost, appDirHostExe, true); using (var sha256 = SHA256.Create()) { // Replace the hash with the managed DLL name. var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes("foobar")); var hashStr = BitConverter.ToString(hash).Replace("-", "").ToLower(); BinaryUtils.SearchAndReplace(appDirHostExe, Encoding.UTF8.GetBytes(hashStr), Encoding.UTF8.GetBytes(appDllName)); } File.Copy(appDirHostExe, appExe, true); // Get the framework location that was built string builtDotnet = fixture.BuiltDotnet.BinPath; // Verify running with the default working directory Command.Create(appExe) .CaptureStdErr() .CaptureStdOut() .EnvironmentVariable("DOTNET_ROOT", builtDotnet) .EnvironmentVariable("DOTNET_ROOT(x86)", builtDotnet) .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); // Verify running from within the working directory Command.Create(appExe) .WorkingDirectory(fixture.TestProject.OutputDirectory) .EnvironmentVariable("DOTNET_ROOT", builtDotnet) .EnvironmentVariable("DOTNET_ROOT(x86)", builtDotnet) .CaptureStdErr() .CaptureStdOut() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") .And.HaveStdOutContaining($"Framework Version:{sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion}"); }
/// <summary> /// Add a mock of the Microsoft.NETCore.App framework with the specified version /// </summary> /// <param name="version">Version to add</param> /// <remarks> /// Product runtime binaries are not added. All the added mock framework will contain is hostpolicy, /// a mock version of coreclr, and a minimal Microsoft.NETCore.App.deps.json. /// </remarks> public DotNetBuilder AddMicrosoftNETCoreAppFrameworkMockCoreClr(string version) { // ./shared/Microsoft.NETCore.App/<version> - create a mock of the root framework string netCoreAppPath = Path.Combine(_path, "shared", "Microsoft.NETCore.App", version); Directory.CreateDirectory(netCoreAppPath); // ./shared/Microsoft.NETCore.App/<version>/hostpolicy.dll - this is the real component and will load CoreClr library string hostPolicyFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostpolicy"); File.Copy( Path.Combine(_repoDirectories.Artifacts, "corehost", hostPolicyFileName), Path.Combine(netCoreAppPath, hostPolicyFileName), true); // ./shared/Microsoft.NETCore.App/<version>/coreclr.dll - this is a mock, will not actually run CoreClr string coreclrFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("coreclr"); string mockCoreclrFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("mockcoreclr"); File.Copy( Path.Combine(_repoDirectories.Artifacts, "corehost_test", mockCoreclrFileName), Path.Combine(netCoreAppPath, coreclrFileName), true); string netCoreAppPathDepsJson = Path.Combine(netCoreAppPath, "Microsoft.NETCore.App.deps.json"); string currentRid = _repoDirectories.TargetRID; string depsJsonBody = $@"{{ ""runtimeTarget"": "".NETCoreApp"", ""targets"": {{ "".NETCoreApp"": {{ ""Microsoft.NETCore.App/{version}"": {{ ""native"": {{ ""runtimes/{currentRid}/native/{coreclrFileName}"": {{ }} }} }}, ""runtime.{currentRid}.Microsoft.NETCore.DotNetHostPolicy/{version}"": {{ ""native"": {{ ""runtimes/{currentRid}/native/{hostPolicyFileName}"": {{}} }} }} }} }}, ""libraries"": {{ ""Microsoft.NETCore.App/{version}"": {{ ""type"": ""package"", ""serviceable"": true, ""sha512"": """" }} }} }}"; File.WriteAllText(netCoreAppPathDepsJson, depsJsonBody); return(this); }
// This helper is used in lieu of SDK support for publishing apps using the singlefilehost. // It replaces the apphost with singlefilehost, and along with appropriate app.dll updates in the host. // For now, we leave behind the hostpolicy and hostfxr DLLs in the publish directory, because // removing them requires deps.json update. public static string UseSingleFileSelfContainedHost(TestProjectFixture testFixture) { var singleFileHost = Path.Combine( testFixture.RepoDirProvider.HostArtifacts, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("singlefilehost")); var publishedHostPath = BundleHelper.GetHostPath(testFixture); HostWriter.CreateAppHost(singleFileHost, publishedHostPath, BundleHelper.GetAppName(testFixture)); return(publishedHostPath); }
public static string UseFrameworkDependentHost(TestProjectFixture testFixture) { var appHost = Path.Combine( testFixture.RepoDirProvider.HostArtifacts, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost")); var publishedHostPath = BundleHelper.GetHostPath(testFixture); HostWriter.CreateAppHost(appHost, publishedHostPath, BundleHelper.GetAppName(testFixture)); return(publishedHostPath); }
public void CoreClrLookup_WithNoDirectorySeparatorInDeps() { var fixture = SharedFxLookupPortableAppFixture .Copy(); var dotnet = fixture.BuiltDotnet; var appDll = fixture.TestProject.AppDll; string runtimeConfig = Path.Combine(fixture.TestProject.OutputDirectory, "SharedFxLookupPortableApp.runtimeconfig.json"); SharedFramework.SetRuntimeConfigJson(runtimeConfig, "9999.0.0", null); // Add versions in the exe folders SharedFramework.AddAvailableSharedFxVersions(_builtSharedFxDir, _exeSharedFxBaseDir, "9999.0.0"); string sharedFxPath = Path.Combine(_exeSharedFxBaseDir, "9999.0.0"); string sharedFxDepsJsonPath = Path.Combine(sharedFxPath, "Microsoft.NETCore.App.deps.json"); // Modify the .deps.json for Microsoft.NETCore.App FX JObject root = JObject.Parse(File.ReadAllText(sharedFxDepsJsonPath)); IEnumerable <JProperty> netCoreAppNativeAssets = root["targets"] .Children <JProperty>().Where(p => p.Name.Contains("/")) .Children().Children().OfType <JProperty>().Where(p => p.Name.Contains("runtime") && p.Name.Contains("Microsoft.NETCore.App")) .Values()["native"].Children().OfType <JProperty>(); // Change the coreclr.dll asset to specify only "coreclr.dll" as the relative path (no directories). string coreClrLibraryName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("coreclr"); JProperty coreClrProperty = netCoreAppNativeAssets.First(p => p.Name.Contains(coreClrLibraryName)); JProperty newCoreClrProperty = new JProperty(coreClrProperty.Name.Substring(coreClrProperty.Name.LastIndexOf('/') + 1), coreClrProperty.Value); coreClrProperty.Parent.Add(newCoreClrProperty); coreClrProperty.Remove(); // Change the clrjit.dll asset to specify only "clrjit.dll" as the relative path (no directories). string clrJitLibraryName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("clrjit"); JProperty clrJitProperty = netCoreAppNativeAssets.First(p => p.Name.Contains(clrJitLibraryName)); JProperty newClrJitProperty = new JProperty(clrJitProperty.Name.Substring(clrJitProperty.Name.LastIndexOf('/') + 1), clrJitProperty.Value); clrJitProperty.Parent.Add(newClrJitProperty); clrJitProperty.Remove(); File.WriteAllText(sharedFxDepsJsonPath, root.ToString()); dotnet.Exec(appDll) .WorkingDirectory(_currentWorkingDir) .EnvironmentVariable("COREHOST_TRACE", "1") .CaptureStdOut() .CaptureStdErr() .Execute() .Should().Pass() .And.HaveStdErrContaining($"CoreCLR path = '{Path.Combine(sharedFxPath, coreClrLibraryName)}'") .And.HaveStdErrContaining($"The resolved JIT path is '{Path.Combine(sharedFxPath, clrJitLibraryName)}'"); }
public SharedTestState() { RepoDirectories = new RepoDirectoriesProvider(); BuiltAppHost = Path.Combine(RepoDirectories.HostArtifacts, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost")); PortableAppFixture_Built = new TestProjectFixture("PortableApp", RepoDirectories) .EnsureRestored(RepoDirectories.CorehostPackages) .BuildProject(); PortableAppFixture_Published = new TestProjectFixture("PortableApp", RepoDirectories) .EnsureRestored(RepoDirectories.CorehostPackages) .PublishProject(); }
public SharedTestStateBase() { BaseDirectory = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "nativeHosting")); Directory.CreateDirectory(BaseDirectory); string nativeHostName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("nativehost"); NativeHostPath = Path.Combine(BaseDirectory, nativeHostName); // Copy over native host RepoDirectories = new RepoDirectoriesProvider(); File.Copy(Path.Combine(RepoDirectories.Artifacts, "corehost_test", nativeHostName), NativeHostPath); }
public SingleFileSharedState() { try { // We include mockcoreclr in our project to test native binaries extraction. string mockCoreClrPath = Path.Combine(RepoDirectories.Artifacts, "corehost_test", RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("mockcoreclr")); TestFixture = PreparePublishedSelfContainedTestProject("SingleFileApiTests", $"/p:AddFile={mockCoreClrPath}"); } catch (Exception e) when(TestUtils.FailFast(e)) // Fail fast to gather a crash dump { throw; } }
public CommandResult RunComponentResolutionMultiThreadedTest(string componentOnePath, string componentTwoPath, TestApp hostApp, string hostFxrFolder) { string[] args = { resolve_component_dependencies, run_app_and_resolve_multithreaded, Path.Combine(hostFxrFolder, RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr")), hostApp.AppDll, componentOnePath, componentTwoPath }; return(Command.Create(NativeHostPath, args) .EnableTracingAndCaptureOutputs() .Execute()); }
/// <summary> /// Use a mock version of HostFxr. /// </summary> /// <param name="version">Version to add</param> /// <remarks> /// Currently, the only mock version of HostFxr that we have is mockhostfxr_2_2. /// </remarks> public DotNetBuilder AddMockHostFxr(Version version) { string hostfxrPath = Path.Combine(_path, "host", "fxr", version.ToString()); Directory.CreateDirectory(hostfxrPath); bool hasCustomErrorWriter = version.Major >= 3; string mockHostFxrFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform(hasCustomErrorWriter ? "mockhostfxr" : "mockhostfxr_2_2"); File.Copy( Path.Combine(_repoDirectories.Artifacts, "corehost_test", mockHostFxrFileName), Path.Combine(hostfxrPath, RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr")), true); return(this); }
public SharedTestState() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // COM activation is only supported on Windows return; } using (var assemblyStream = new FileStream(ComLibraryFixture.TestProject.AppDll, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read)) using (var peReader = new System.Reflection.PortableExecutable.PEReader(assemblyStream)) { if (peReader.HasMetadata) { string regFreeManifestPath = Path.Combine(BaseDirectory, $"{ ComLibraryFixture.TestProject.AssemblyName }.X.manifest"); MetadataReader reader = peReader.GetMetadataReader(); RegFreeComManifest.CreateManifestFromClsidmap( ComLibraryFixture.TestProject.AssemblyName, Path.GetFileName(ComHostPath), reader.GetAssemblyDefinition().Version.ToString(), ClsidMapPath, regFreeManifestPath, TypeLibraries ); } } string testDirectoryPath = Path.GetDirectoryName(NativeHostPath); string comsxsName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("comsxs"); ComSxsPath = Path.Combine(testDirectoryPath, comsxsName); File.Copy( Path.Combine(RepoDirectories.Artifacts, "corehost_test", comsxsName), ComSxsPath); File.Copy( ComHostPath, Path.Combine(testDirectoryPath, Path.GetFileName(ComHostPath))); File.Copy( ComLibraryFixture.TestProject.AppDll, Path.Combine(testDirectoryPath, Path.GetFileName(ComLibraryFixture.TestProject.AppDll))); File.Copy( ComLibraryFixture.TestProject.DepsJson, Path.Combine(testDirectoryPath, Path.GetFileName(ComLibraryFixture.TestProject.DepsJson))); File.Copy( ComLibraryFixture.TestProject.RuntimeConfigJson, Path.Combine(testDirectoryPath, Path.GetFileName(ComLibraryFixture.TestProject.RuntimeConfigJson))); }
/// <summary> /// Add a mock of the Microsoft.NETCore.App framework with the specified version /// </summary> /// <param name="version">Version to add</param> /// <remarks> /// Product runtime binaries are not added. All the added mock framework will contain is a mock version of host policy. /// </remarks> public DotNetBuilder AddMicrosoftNETCoreAppFrameworkMockHostPolicy(string version) { // ./shared/Microsoft.NETCore.App/<version> - create a mock of the root framework string netCoreAppPath = Path.Combine(_path, "shared", "Microsoft.NETCore.App", version); Directory.CreateDirectory(netCoreAppPath); // ./shared/Microsoft.NETCore.App/<version>/hostpolicy.dll - this is a mock, will not actually load CoreCLR string mockHostPolicyFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("mockhostpolicy"); File.Copy( Path.Combine(_repoDirectories.Artifacts, "corehost_test", mockHostPolicyFileName), Path.Combine(netCoreAppPath, RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostpolicy")), true); return(this); }
public void TestOnlyDisabledByDefault() { // Intentionally not enabling test-only behavior. This test validates that even if the test-only env. variable is set // it will not take effect on its own by default. // To make sure the test is reliable, copy the product binary again into the test folder where we run it from. // This is to make sure that we're using the unmodified product binary. If some previous test // enabled test-only product behavior on the binary and didn't correctly cleanup, this test would fail. File.Copy( Path.Combine(sharedState.RepoDirectories.CorehostPackages, RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("nethost")), sharedState.NethostPath, overwrite: true); Command.Create(sharedState.NativeHostPath, GetHostFxrPath) .EnableTracingAndCaptureOutputs() .EnvironmentVariable(Constants.TestOnlyEnvironmentVariables.GloballyRegisteredPath, sharedState.ValidInstallRoot) .Execute() .Should().NotHaveStdErrContaining($"Using global installation location [{sharedState.ValidInstallRoot}] as runtime location."); }
public void Running_Publish_Output_Standalone_EXE_By_Renaming_apphost_exe_Succeeds() { var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); var appExe = fixture.TestProject.AppExe; var renamedAppExe = fixture.TestProject.AppExe + RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("renamed"); File.Copy(appExe, renamedAppExe, true); Command.Create(renamedAppExe) .CaptureStdErr() .CaptureStdOut() .Execute() .Should().Pass() .And.HaveStdOutContaining("Hello World") .And.HaveStdOutContaining(sharedTestState.RepoDirectories.MicrosoftNETCoreAppVersion); }
public CommandResult RunComponentResolutionTest(string componentPath, TestApp hostApp, string hostFxrFolder, Action <Command> commandCustomizer = null) { string[] args = { resolve_component_dependencies, run_app_and_resolve, Path.Combine(hostFxrFolder, RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr")), hostApp.AppDll, componentPath }; Command command = Command.Create(NativeHostPath, args) .EnableTracingAndCaptureOutputs(); commandCustomizer?.Invoke(command); return(command.Execute() .StdErrAfter("corehost_resolve_component_dependencies = {")); }
public SharedTestState() { DotNet = new DotNetBuilder(BaseDirectory, Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), "mockRuntime") .AddMicrosoftNETCoreAppFrameworkMockCoreClr(NetCoreAppVersion) .Build(); HostFxrPath = Path.Combine( DotNet.GreatestVersionHostFxrPath, RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr")); AppDirectory = Path.Combine(BaseDirectory, "app"); Directory.CreateDirectory(AppDirectory); AppPath = Path.Combine(AppDirectory, "App.dll"); File.WriteAllText(AppPath, string.Empty); RuntimeConfig.FromFile(Path.Combine(AppDirectory, "App.runtimeconfig.json")) .WithFramework(new RuntimeConfig.Framework(Constants.MicrosoftNETCoreApp, NetCoreAppVersion)) .Save(); }
public SharedTestState() { RepoDirectories = new RepoDirectoriesProvider(); BuiltAppHost = Path.Combine(RepoDirectories.HostArtifacts, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost")); BuiltDotNet = new DotNetCli(RepoDirectories.BuiltDotnet); PortableAppFixture_Built = new TestProjectFixture("PortableApp", RepoDirectories) .EnsureRestored() .BuildProject(); PortableAppFixture_Published = new TestProjectFixture("PortableApp", RepoDirectories) .EnsureRestored() .PublishProject(); MockApp = new TestApp(SharedFramework.CalculateUniqueTestDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "portableAppActivation")), "App"); Directory.CreateDirectory(MockApp.Location); File.WriteAllText(MockApp.AppDll, string.Empty); File.Copy(BuiltAppHost, MockApp.AppExe); AppHostExtensions.BindAppHost(MockApp.AppExe); }
public DotNetBuilder(string basePath, string builtDotnet, string name) { _path = Path.Combine(basePath, name); Directory.CreateDirectory(_path); _repoDirectories = new RepoDirectoriesProvider(builtDotnet: _path); // Prepare the dotnet installation mock // ./dotnet.exe - used as a convenient way to load and invoke hostfxr. May change in the future to use test-specific executable var builtDotNetCli = new DotNetCli(builtDotnet); File.Copy( builtDotNetCli.DotnetExecutablePath, Path.Combine(_path, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet")), true); // ./host/fxr/<version>/hostfxr.dll - this is the component being tested SharedFramework.CopyDirectory( builtDotNetCli.GreatestVersionHostFxrPath, Path.Combine(_path, "host", "fxr", Path.GetFileName(builtDotNetCli.GreatestVersionHostFxrPath))); }
public void Running_Publish_Output_Standalone_EXE_With_DOTNET_ROOT_Fails() { var fixture = sharedTestState.StandaloneAppFixture_Published .Copy(); var appExe = fixture.TestProject.AppExe; var appDll = fixture.TestProject.AppDll; // Move whole directory to a subdirectory string currentOutDir = fixture.TestProject.OutputDirectory; string relativeNewPath = ".."; relativeNewPath = Path.Combine(relativeNewPath, "newDir2"); string newOutDir = Path.Combine(currentOutDir, relativeNewPath); Directory.Move(currentOutDir, newOutDir); // Move the apphost exe and app dll back to original location string appExeName = Path.GetFileName(appExe); string sourceAppExePath = Path.Combine(newOutDir, appExeName); Directory.CreateDirectory(Path.GetDirectoryName(appExe)); File.Move(sourceAppExePath, appExe); string appDllName = Path.GetFileName(appDll); string sourceAppDllPath = Path.Combine(newOutDir, appDllName); File.Move(sourceAppDllPath, appDll); // This verifies a self-contained apphost cannot use DOTNET_ROOT to reference a flat // self-contained layout since a flat layout of the shared framework is not supported. Command.Create(appExe) .EnableTracingAndCaptureOutputs() .DotNetRoot(newOutDir) .Execute(expectedToFail: true) .Should().Fail() .And.HaveUsedDotNetRootInstallLocation(Path.GetFullPath(newOutDir), fixture.CurrentRid) .And.HaveStdErrContaining($"The required library {RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr")} could not be found."); }
public TestApp CreateSelfContainedAppWithMockHostPolicy() { string testAppDir = Path.Combine(_baseDir, "SelfContainedApp"); Directory.CreateDirectory(testAppDir); TestApp testApp = new TestApp(testAppDir); string hostFxrFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostfxr"); string hostPolicyFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("hostpolicy"); string mockHostPolicyFileName = RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("mockhostpolicy"); string appHostFileName = RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("apphost"); DotNetCli builtDotNetCli = new DotNetCli(_builtDotnet); // ./hostfxr - the product version File.Copy(builtDotNetCli.GreatestVersionHostFxrFilePath, Path.Combine(testAppDir, hostFxrFileName)); // ./hostpolicy - the mock File.Copy( Path.Combine(_repoDirectories.Artifacts, "corehost_test", mockHostPolicyFileName), Path.Combine(testAppDir, hostPolicyFileName)); // ./SelfContainedApp.dll File.WriteAllText(Path.Combine(testAppDir, "SelfContainedApp.dll"), string.Empty); // ./SelfContainedApp.runtimeconfig.json File.WriteAllText(Path.Combine(testAppDir, "SelfContainedApp.runtimeconfig.json"), "{}"); // ./SelfContainedApp.exe string selfContainedAppExePath = Path.Combine(testAppDir, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("SelfContainedApp")); File.Copy( Path.Combine(_repoDirectories.HostArtifacts, appHostFileName), selfContainedAppExePath); AppHostExtensions.BindAppHost(selfContainedAppExePath); return(testApp); }