summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>2019-04-02 16:39:11 -0700
committerGitHub <noreply@github.com>2019-04-02 16:39:11 -0700
commit2516a53b75ef74b585cc507e07d39e37675993b9 (patch)
tree4d49073d0ee1453f3e49f91413c18e5d486bbae9 /tests
parentf036d2339b030258bf31bc73ebc23f553744fa04 (diff)
downloadcoreclr-2516a53b75ef74b585cc507e07d39e37675993b9.tar.gz
coreclr-2516a53b75ef74b585cc507e07d39e37675993b9.tar.bz2
coreclr-2516a53b75ef74b585cc507e07d39e37675993b9.zip
Change tests to not modify Core_Root (#23470)
Redesign tests that needed to modify Core_Root to no longer do so. - Loader.FromNativePaths: Use `CORE_LIBRARIES` instead of `COREROOT` - Loader.AssemblyDependencyResolver: Split out the invalid hosting test that needs hostpolicy to not be preloaded. Have `CoreRun` and `CoreShim` preload hostpolicy when a path to a hostpolicy is specified in the `MOCK_HOSTPOLICY` environment variable. - Add a `CLRTest.MockHosting.targets` file that is imported when a test requires hostpolicy. It adds the reference to the mock hostpolicy and ensures that the `MOCK_HOSTPOLICY` environment variable is correctly set in the test scripts. Fixes #23429.
Diffstat (limited to 'tests')
-rw-r--r--tests/src/CLRTest.Execute.Bash.targets1
-rw-r--r--tests/src/CLRTest.Execute.targets1
-rw-r--r--tests/src/CLRTest.MockHosting.targets21
-rw-r--r--tests/src/Common/CoreCLRTestLibrary/HostPolicyMock.cs27
-rw-r--r--tests/src/Interop/COM/Activator/Activator.csproj3
-rw-r--r--tests/src/Interop/COM/NativeClients/DefaultInterfaces.csproj6
-rw-r--r--tests/src/Interop/COM/NativeClients/Licensing.csproj6
-rw-r--r--tests/src/Interop/COM/NativeClients/Primitives.csproj6
-rw-r--r--tests/src/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj2
-rw-r--r--tests/src/Interop/Interop.settings.targets7
-rw-r--r--tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.cs (renamed from tests/src/Loader/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.cs)4
-rw-r--r--tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.csproj (renamed from tests/src/Loader/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.csproj)7
-rw-r--r--tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/NativeDependencyTests.cs (renamed from tests/src/Loader/AssemblyDependencyResolverTests/NativeDependencyTests.cs)0
-rw-r--r--tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/TestBase.cs (renamed from tests/src/Loader/AssemblyDependencyResolverTests/TestBase.cs)0
-rw-r--r--tests/src/Loader/AssemblyDependencyResolver/MissingHostPolicyTests/InvalidHostingTest.cs43
-rw-r--r--tests/src/Loader/AssemblyDependencyResolver/MissingHostPolicyTests/MissingHostPolicyTests.csproj19
-rw-r--r--tests/src/Loader/AssemblyDependencyResolverTests/InvalidHostingTest.cs71
-rw-r--r--tests/src/Loader/NativeLibs/FromNativePaths.cs19
-rw-r--r--tests/src/Loader/NativeLibs/FromNativePaths.csproj16
19 files changed, 125 insertions, 134 deletions
diff --git a/tests/src/CLRTest.Execute.Bash.targets b/tests/src/CLRTest.Execute.Bash.targets
index a73f20555c..44dfcdb204 100644
--- a/tests/src/CLRTest.Execute.Bash.targets
+++ b/tests/src/CLRTest.Execute.Bash.targets
@@ -253,7 +253,6 @@ fi
</PropertyGroup>
<PropertyGroup>
<_CLRTestRunFile Condition="'$(CLRTestIsHosted)'=='true'">"$CORE_ROOT/corerun"</_CLRTestRunFile>
-
<BashCLRTestLaunchCmds>$(BashIlrtTestLaunchCmds)</BashCLRTestLaunchCmds>
<BashCLRTestLaunchCmds Condition="'$(CLRTestKind)' == 'BuildAndRun'">
diff --git a/tests/src/CLRTest.Execute.targets b/tests/src/CLRTest.Execute.targets
index ff0becbf25..de79609130 100644
--- a/tests/src/CLRTest.Execute.targets
+++ b/tests/src/CLRTest.Execute.targets
@@ -71,6 +71,7 @@ This file contains the logic for providing Execution Script generation.
<Import Project="CLRTest.CrossGen.targets" />
<Import Project="CLRTest.GC.targets" />
<Import Project="CLRTest.Execute.*.targets" />
+ <Import Project="CLRTest.MockHosting.targets" Condition="'$(RequiresMockHostPolicy)' == 'true'" />
<Target Name="GenerateExecutionScriptsInternal"
Condition="$(_CLRTestNeedsToRun) or $(_CLRTestBuildsExecutable)"
diff --git a/tests/src/CLRTest.MockHosting.targets b/tests/src/CLRTest.MockHosting.targets
new file mode 100644
index 0000000000..a139caaeb8
--- /dev/null
+++ b/tests/src/CLRTest.MockHosting.targets
@@ -0,0 +1,21 @@
+<!--
+***********************************************************************************************
+CLRTest.MockHosting.targets
+
+This file contains the logic for correctly hooking up a mock hostpolicy to a test.
+
+***********************************************************************************************
+-->
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <HostPolicyFileExtension>.so</HostPolicyFileExtension>
+ <HostPolicyFileExtension Condition="'$(TargetsOSX)' =='true'">.dylib</HostPolicyFileExtension>
+ </PropertyGroup>
+ <ItemGroup>
+ <ProjectReference Include="$(MSBuildThisFileDirectory)/Common/hostpolicymock/CMakeLists.txt" />
+ <!-- %28 decodes to '('. It's needed to keep MSBuild from trying to parse $(pwd) as an MSBuild property -->
+ <CLRTestBashEnvironmentVariable Include="export MOCK_HOSTPOLICY=$%28pwd)/hostpolicy$(HostPolicyFileExtension)" />
+ <!-- %25 decodes to '%'. It's needed to keep %cd itself from being decoded since we want '%cd%' directly in the script. -->
+ <CLRTestBatchEnvironmentVariable Include="set MOCK_HOSTPOLICY=%25cd%\hostpolicy.dll" />
+ </ItemGroup>
+</Project>
diff --git a/tests/src/Common/CoreCLRTestLibrary/HostPolicyMock.cs b/tests/src/Common/CoreCLRTestLibrary/HostPolicyMock.cs
index f354d9ab56..0bbce1b6e5 100644
--- a/tests/src/Common/CoreCLRTestLibrary/HostPolicyMock.cs
+++ b/tests/src/Common/CoreCLRTestLibrary/HostPolicyMock.cs
@@ -43,35 +43,8 @@ namespace TestLibrary
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = HostpolicyCharSet)]
public delegate void ErrorWriterDelegate(string message);
- public static string DeleteExistingHostpolicy(string coreRoot)
- {
-#if REFERENCING_SYSTEMPRIVATECORELIB
- throw new Exception("This API is not supported when compiled referencing SPCL");
-
-#else
- string hostPolicyFileName = XPlatformUtils.GetStandardNativeLibraryFileName("hostpolicy");
- string destinationPath = Path.Combine(coreRoot, hostPolicyFileName);
-
- if (File.Exists(destinationPath))
- {
- File.Delete(destinationPath);
- }
-
- return destinationPath;
-#endif
- }
-
public static void Initialize(string testBasePath, string coreRoot)
{
-#if !REFERENCING_SYSTEMPRIVATECORELIB
- string hostPolicyFileName = XPlatformUtils.GetStandardNativeLibraryFileName("hostpolicy");
- string destinationPath = DeleteExistingHostpolicy(coreRoot);
-
- File.Copy(
- Path.Combine(testBasePath, hostPolicyFileName),
- destinationPath);
-#endif
-
_assemblyDependencyResolverType = typeof(AssemblyDependencyResolver);
// This is needed for marshalling of function pointers to work - requires private access to the ADR unfortunately
diff --git a/tests/src/Interop/COM/Activator/Activator.csproj b/tests/src/Interop/COM/Activator/Activator.csproj
index b656a5c1e9..51b0b73ea4 100644
--- a/tests/src/Interop/COM/Activator/Activator.csproj
+++ b/tests/src/Interop/COM/Activator/Activator.csproj
@@ -8,7 +8,7 @@
<SchemaVersion>2.0</SchemaVersion>
<OutputType>Exe</OutputType>
<ReferenceSystemPrivateCoreLib>true</ReferenceSystemPrivateCoreLib>
-
+ <RequiresMockHostPolicy>true</RequiresMockHostPolicy>
<!-- Test unsupported outside of windows -->
<TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows>
<DisableProjectBuild Condition="'$(TargetsWindows)' != 'true'">true</DisableProjectBuild>
@@ -29,7 +29,6 @@
<ProjectReference Include="Servers\AssemblyB.csproj" />
<ProjectReference Include="Servers\AssemblyC.csproj" />
<ProjectReference Include="Servers\AssemblyContracts.csproj" />
- <ProjectReference Include="../../../Common/hostpolicymock/CMakeLists.txt" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
diff --git a/tests/src/Interop/COM/NativeClients/DefaultInterfaces.csproj b/tests/src/Interop/COM/NativeClients/DefaultInterfaces.csproj
index 040ec132bf..f8a5dd6d22 100644
--- a/tests/src/Interop/COM/NativeClients/DefaultInterfaces.csproj
+++ b/tests/src/Interop/COM/NativeClients/DefaultInterfaces.csproj
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
- <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" />
<PropertyGroup>
<IgnoreCoreCLRTestLibraryDependency>true</IgnoreCoreCLRTestLibraryDependency>
<CLRTestScriptLocalCoreShim>true</CLRTestScriptLocalCoreShim>
+ <RequiresMockHostPolicy>true</RequiresMockHostPolicy>
<TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows>
<DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild>
@@ -16,8 +16,8 @@
<ItemGroup>
<ProjectReference Include="DefaultInterfaces/CMakeLists.txt" />
<ProjectReference Include="../NetServer/NetServer.DefaultInterfaces.ilproj" />
- <ProjectReference Include="../../../Common/hostpolicymock/CMakeLists.txt" />
<ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project> \ No newline at end of file
+</Project>
diff --git a/tests/src/Interop/COM/NativeClients/Licensing.csproj b/tests/src/Interop/COM/NativeClients/Licensing.csproj
index dba48db706..3bebdce282 100644
--- a/tests/src/Interop/COM/NativeClients/Licensing.csproj
+++ b/tests/src/Interop/COM/NativeClients/Licensing.csproj
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
- <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" />
<PropertyGroup>
<IgnoreCoreCLRTestLibraryDependency>true</IgnoreCoreCLRTestLibraryDependency>
<CLRTestScriptLocalCoreShim>true</CLRTestScriptLocalCoreShim>
+ <RequiresMockHostPolicy>true</RequiresMockHostPolicy>
<TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows>
<DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild>
@@ -16,8 +16,8 @@
<ItemGroup>
<ProjectReference Include="Licensing/CMakeLists.txt" />
<ProjectReference Include="../NetServer/NetServer.csproj" />
- <ProjectReference Include="../../../Common/hostpolicymock/CMakeLists.txt" />
<ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project> \ No newline at end of file
+</Project>
diff --git a/tests/src/Interop/COM/NativeClients/Primitives.csproj b/tests/src/Interop/COM/NativeClients/Primitives.csproj
index 305f1048b3..932fdb7342 100644
--- a/tests/src/Interop/COM/NativeClients/Primitives.csproj
+++ b/tests/src/Interop/COM/NativeClients/Primitives.csproj
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
- <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" />
<PropertyGroup>
<IgnoreCoreCLRTestLibraryDependency>true</IgnoreCoreCLRTestLibraryDependency>
<CLRTestScriptLocalCoreShim>true</CLRTestScriptLocalCoreShim>
+ <RequiresMockHostPolicy>true</RequiresMockHostPolicy>
<TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows>
<DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild>
@@ -16,8 +16,8 @@
<ItemGroup>
<ProjectReference Include="Primitives/CMakeLists.txt" />
<ProjectReference Include="../NetServer/NetServer.csproj" />
- <ProjectReference Include="../../../Common/hostpolicymock/CMakeLists.txt" />
<ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project> \ No newline at end of file
+</Project>
diff --git a/tests/src/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj b/tests/src/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj
index 395a81c286..165826ccd8 100644
--- a/tests/src/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj
+++ b/tests/src/Interop/IJW/LoadIjwFromModuleHandle/LoadIjwFromModuleHandle.csproj
@@ -12,6 +12,7 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<ReferenceSystemPrivateCoreLib>true</ReferenceSystemPrivateCoreLib>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <RequiresMockHostPolicy>true</RequiresMockHostPolicy>
<!-- IJW is Windows-only -->
<!-- Test unsupported outside of windows -->
@@ -43,7 +44,6 @@
<ItemGroup>
<ProjectReference Include="../IjwNativeCallingManagedDll/CMakeLists.txt" />
<ProjectReference Include="../ijwhostmock/CMakeLists.txt" />
- <ProjectReference Include="../../../Common/hostpolicymock/CMakeLists.txt" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Interop.settings.targets))\Interop.settings.targets" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
diff --git a/tests/src/Interop/Interop.settings.targets b/tests/src/Interop/Interop.settings.targets
index fc906f200d..f67ae45432 100644
--- a/tests/src/Interop/Interop.settings.targets
+++ b/tests/src/Interop/Interop.settings.targets
@@ -4,11 +4,6 @@
<InteropCommonDir>$(MSBuildThisFileDirectory)common/</InteropCommonDir>
</PropertyGroup>
- <!-- Environment properties -->
- <PropertyGroup>
- <DefineConstants Condition="'$(ReferenceSystemPrivateCoreLib)' == 'true'">$(DefineConstants);REFERENCING_SYSTEMPRIVATECORELIB</DefineConstants>
- </PropertyGroup>
-
<!-- Add the CoreCLRTestLibrary dependency -->
<ItemGroup Condition="('$(IgnoreCoreCLRTestLibraryDependency)' != 'true') And ('$(ReferenceSystemPrivateCoreLib)' != 'true')">
<ProjectReference
@@ -20,7 +15,7 @@
Compile in relevant files used for testing interop. -->
<ItemGroup Condition="('$(IgnoreCoreCLRTestLibraryDependency)' != 'true') And ('$(ReferenceSystemPrivateCoreLib)' == 'true')">
<Compile Include="$(MSBuildThisFileDirectory)\..\Common\CoreCLRTestLibrary\Assertion.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)\..\Common\CoreCLRTestLibrary\HostPolicyMock.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)\..\Common\CoreCLRTestLibrary\HostPolicyMock.cs" Condition="'$(RequiresMockHostPolicy)' == 'true'"/>
<Compile Include="$(MSBuildThisFileDirectory)\..\Common\CoreCLRTestLibrary\XPlatformUtils.cs" />
</ItemGroup>
diff --git a/tests/src/Loader/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.cs b/tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.cs
index 3e74a6627d..1b6e2a2a7a 100644
--- a/tests/src/Loader/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.cs
+++ b/tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.cs
@@ -312,10 +312,6 @@ namespace AssemblyDependencyResolverTests
public static int Main()
{
return TestBase.RunTests(
- // It's important that the invalid hosting test runs first as it relies on the ability
- // to delete (if it's there) the hostpolicy.dll. All other tests will end up loading the dll
- // and thus locking it.
- typeof(InvalidHostingTest),
typeof(AssemblyDependencyResolverTests),
typeof(NativeDependencyTests));
}
diff --git a/tests/src/Loader/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.csproj b/tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.csproj
index e2dd0a4df3..0564626a6a 100644
--- a/tests/src/Loader/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.csproj
+++ b/tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/AssemblyDependencyResolverTests.csproj
@@ -8,18 +8,15 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
- <!-- The test fails if ran twice in the same process. In one of the test cases, it expects a hostpolicy to not to be found, but it actually is found in the second pass -->
- <UnloadabilityIncompatible>true</UnloadabilityIncompatible>
+ <RequiresMockHostPolicy>true</RequiresMockHostPolicy>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyDependencyResolverTests.cs" />
- <Compile Include="InvalidHostingTest.cs" />
<Compile Include="NativeDependencyTests.cs" />
<Compile Include="TestBase.cs" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- <ProjectReference Include="../../Common/hostpolicymock/CMakeLists.txt" />
+ <ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
diff --git a/tests/src/Loader/AssemblyDependencyResolverTests/NativeDependencyTests.cs b/tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/NativeDependencyTests.cs
index e7ac906e02..e7ac906e02 100644
--- a/tests/src/Loader/AssemblyDependencyResolverTests/NativeDependencyTests.cs
+++ b/tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/NativeDependencyTests.cs
diff --git a/tests/src/Loader/AssemblyDependencyResolverTests/TestBase.cs b/tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/TestBase.cs
index 74532c6a78..74532c6a78 100644
--- a/tests/src/Loader/AssemblyDependencyResolverTests/TestBase.cs
+++ b/tests/src/Loader/AssemblyDependencyResolver/AssemblyDependencyResolverTests/TestBase.cs
diff --git a/tests/src/Loader/AssemblyDependencyResolver/MissingHostPolicyTests/InvalidHostingTest.cs b/tests/src/Loader/AssemblyDependencyResolver/MissingHostPolicyTests/InvalidHostingTest.cs
new file mode 100644
index 0000000000..892fe7be48
--- /dev/null
+++ b/tests/src/Loader/AssemblyDependencyResolver/MissingHostPolicyTests/InvalidHostingTest.cs
@@ -0,0 +1,43 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+using System;
+using System.IO;
+using System.Runtime.Loader;
+using TestLibrary;
+using Xunit;
+
+using Assert = Xunit.Assert;
+
+namespace AssemblyDependencyResolverTests
+{
+ class InvalidHostingTest
+ {
+ public static int Main(string [] args)
+ {
+ try
+ {
+ string assemblyLocation = typeof(InvalidHostingTest).Assembly.Location;
+ string testBasePath = Path.GetDirectoryName(assemblyLocation);
+ string componentDirectory = Path.Combine(testBasePath, $"InvalidHostingComponent_{Guid.NewGuid().ToString().Substring(0, 8)}");
+ Directory.CreateDirectory(componentDirectory);
+ string componentAssemblyPath = Path.Combine(componentDirectory, "InvalidHostingComponent.dll");
+ File.WriteAllText(componentAssemblyPath, "Mock assembly");
+
+ object innerException = Assert.Throws<InvalidOperationException>(() =>
+ {
+ AssemblyDependencyResolver resolver = new AssemblyDependencyResolver(
+ Path.Combine(testBasePath, componentAssemblyPath));
+ }).InnerException;
+
+ Assert.IsType<DllNotFoundException>(innerException);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ return 101;
+ }
+ return 100;
+ }
+ }
+}
diff --git a/tests/src/Loader/AssemblyDependencyResolver/MissingHostPolicyTests/MissingHostPolicyTests.csproj b/tests/src/Loader/AssemblyDependencyResolver/MissingHostPolicyTests/MissingHostPolicyTests.csproj
new file mode 100644
index 0000000000..f165028c1a
--- /dev/null
+++ b/tests/src/Loader/AssemblyDependencyResolver/MissingHostPolicyTests/MissingHostPolicyTests.csproj
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <CLRTestKind>BuildAndRun</CLRTestKind>
+ <CLRTestPriority>1</CLRTestPriority>
+ <ProjectGuid>{ABB86728-A3E0-4489-BD97-A0BAB00B322F}</ProjectGuid>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="InvalidHostingTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="../../../Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
diff --git a/tests/src/Loader/AssemblyDependencyResolverTests/InvalidHostingTest.cs b/tests/src/Loader/AssemblyDependencyResolverTests/InvalidHostingTest.cs
deleted file mode 100644
index d1fc56ecf4..0000000000
--- a/tests/src/Loader/AssemblyDependencyResolverTests/InvalidHostingTest.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-using System;
-using System.IO;
-using System.Runtime.Loader;
-using TestLibrary;
-using Xunit;
-
-using Assert = Xunit.Assert;
-
-namespace AssemblyDependencyResolverTests
-{
- class InvalidHostingTest : TestBase
- {
- private string _componentDirectory;
- private string _componentAssemblyPath;
- private string _officialHostPolicyPath;
- private string _localHostPolicyPath;
- private string _renamedHostPolicyPath;
-
- protected override void Initialize()
- {
- // Make sure there's no hostpolicy available
- _officialHostPolicyPath = HostPolicyMock.DeleteExistingHostpolicy(CoreRoot);
- string hostPolicyFileName = XPlatformUtils.GetStandardNativeLibraryFileName("hostpolicy");
- _localHostPolicyPath = Path.Combine(TestBasePath, hostPolicyFileName);
- _renamedHostPolicyPath = Path.Combine(TestBasePath, hostPolicyFileName + "_renamed");
- if (File.Exists(_renamedHostPolicyPath))
- {
- File.Delete(_renamedHostPolicyPath);
- }
- File.Move(_localHostPolicyPath, _renamedHostPolicyPath);
-
- _componentDirectory = Path.Combine(TestBasePath, $"InvalidHostingComponent_{Guid.NewGuid().ToString().Substring(0, 8)}");
- Directory.CreateDirectory(_componentDirectory);
- _componentAssemblyPath = Path.Combine(_componentDirectory, "InvalidHostingComponent.dll");
- File.WriteAllText(_componentAssemblyPath, "Mock assembly");
- }
-
- protected override void Cleanup()
- {
- if (Directory.Exists(_componentDirectory))
- {
- Directory.Delete(_componentDirectory, recursive: true);
- }
-
- if (File.Exists(_renamedHostPolicyPath))
- {
- File.Move(_renamedHostPolicyPath, _localHostPolicyPath);
- }
- }
-
- public void TestMissingHostPolicy()
- {
- object innerException = Assert.Throws<InvalidOperationException>(() =>
- {
- AssemblyDependencyResolver resolver = new AssemblyDependencyResolver(
- Path.Combine(TestBasePath, _componentAssemblyPath));
- }).InnerException;
-
- Assert.IsType<DllNotFoundException>(innerException);
- }
-
- // Note: No good way to test the missing entry point case where hostpolicy.dll
- // exists, but it doesn't have the right entry points.
- // Loading a "wrong" hostpolicy.dll into the process is non-revertable operation
- // so we would not be able to run other tests along side this one.
- // Having a standalone .exe just for that one test is not worth it.
- }
-}
diff --git a/tests/src/Loader/NativeLibs/FromNativePaths.cs b/tests/src/Loader/NativeLibs/FromNativePaths.cs
index 7f9975311c..29e7a5486a 100644
--- a/tests/src/Loader/NativeLibs/FromNativePaths.cs
+++ b/tests/src/Loader/NativeLibs/FromNativePaths.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Runtime.InteropServices;
public class FromNativePaths
@@ -29,17 +30,21 @@ public class FromNativePaths
// search paths for corerun include the folder where corerun resides. Move the native library there to verify that it
// can be loaded from there.
- var coreRoot = Environment.GetEnvironmentVariable("CORE_ROOT");
- if (string.IsNullOrWhiteSpace(coreRoot))
+ var coreLibraries = Environment.GetEnvironmentVariable("CORE_LIBRARIES");
+ if (string.IsNullOrWhiteSpace(coreLibraries))
{
- Console.WriteLine("FromNativePaths failed: CORE_ROOT is not defined.");
+ Console.WriteLine("FromNativePaths failed: CORE_LIBRARIES is not defined.");
return false;
}
- if (!Directory.Exists(coreRoot))
+
+ // In case there were multiple paths in CORE_LIBRARIES, assume that the last one is the one added in the test script.
+ coreLibraries = coreLibraries.Split(new [] {TestLibrary.Utilities.IsWindows ? ';' : ':'}, StringSplitOptions.RemoveEmptyEntries).Last();
+
+ if (!Directory.Exists(coreLibraries))
{
Console.WriteLine(
- "FromNativePaths failed: Directory specified by CORE_ROOT does not exist: {0}",
- coreRoot);
+ "FromNativePaths failed: Directory specified by CORE_LIBRARIES does not exist: {0}",
+ coreLibraries);
return false;
}
@@ -51,7 +56,7 @@ public class FromNativePaths
if (!File.Exists(nativeLibraryName))
continue;
- var destinationPath = Path.Combine(coreRoot, nativeLibraryName);
+ var destinationPath = Path.Combine(coreLibraries, nativeLibraryName);
try
{
var destinationFileInfo = new FileInfo(destinationPath);
diff --git a/tests/src/Loader/NativeLibs/FromNativePaths.csproj b/tests/src/Loader/NativeLibs/FromNativePaths.csproj
index c607beb4e4..5ce7e02a60 100644
--- a/tests/src/Loader/NativeLibs/FromNativePaths.csproj
+++ b/tests/src/Loader/NativeLibs/FromNativePaths.csproj
@@ -18,7 +18,21 @@
<Compile Include="FromNativePaths.cs" />
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\..\Common\CoreCLRTestLibrary\CoreCLRTestLibrary.csproj" />
<ProjectReference Include="CMakeLists.txt" />
</ItemGroup>
+ <ItemGroup>
+ <CLRTestBashEnvironmentVariable Include="export CORE_LIBRARIES=$CORE_LIBRARIES:$%28pwd)/Subdirectory" />
+ <CLRTestBatchEnvironmentVariable Include="set CORE_LIBRARIES=$CORE_LIBRARIES%3B%25cd%\\Subdirectory" />
+ </ItemGroup>
+ <PropertyGroup>
+ <PathEnvSetupCommands>
+ <![CDATA[
+ mkdir Subdirectory
+ ]]>
+ </PathEnvSetupCommands>
+ <BashCLRTestPreCommands>$(BashCLRTestPreCommands);$(PathEnvSetupCommands)</BashCLRTestPreCommands>
+ <CLRTestBatchPreCommands>$(BatchCLRTestPreCommands);$(PathEnvSetupCommands)</CLRTestBatchPreCommands>
+ </PropertyGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
-</Project> \ No newline at end of file
+</Project>