summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/coreclr/hosts/corerun/corerun.cpp28
-rw-r--r--src/coreclr/hosts/coreshim/CoreShim.cpp86
-rw-r--r--src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp20
-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
22 files changed, 225 insertions, 168 deletions
diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp
index c1d1fcef49..42aa3009ea 100644
--- a/src/coreclr/hosts/corerun/corerun.cpp
+++ b/src/coreclr/hosts/corerun/corerun.cpp
@@ -423,6 +423,23 @@ private:
ULONG_PTR _actCookie;
};
+bool TryLoadHostPolicy(StackSString& hostPolicyPath)
+{
+ const WCHAR *hostpolicyName = W("hostpolicy.dll");
+ HMODULE hMod = ::GetModuleHandleW(hostpolicyName);
+ if (hMod != nullptr)
+ {
+ return true;
+ }
+ // Check if a hostpolicy exists and if it does, load it.
+ if (INVALID_FILE_ATTRIBUTES != ::GetFileAttributesW(hostPolicyPath.GetUnicode()))
+ {
+ hMod = ::LoadLibraryExW(hostPolicyPath.GetUnicode(), nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
+ }
+
+ return hMod != nullptr;
+}
+
bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbose, const bool waitForDebugger, DWORD &exitCode)
{
@@ -498,6 +515,17 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo
nativeDllSearchDirs.Append(W(";"));
nativeDllSearchDirs.Append(hostEnvironment.m_coreCLRDirectoryPath);
+ // Preload mock hostpolicy if requested.
+ StackSString hostpolicyPath;
+ if (WszGetEnvironmentVariable(W("MOCK_HOSTPOLICY"), hostpolicyPath) > 0 && hostpolicyPath.GetCount() > 0)
+ {
+ if (!TryLoadHostPolicy(hostpolicyPath))
+ {
+ log << W("Unable to load requested mock hostpolicy.");
+ return false;
+ }
+ }
+
// Start the CoreCLR
ICLRRuntimeHost4 *host = hostEnvironment.GetCLRRuntimeHost();
diff --git a/src/coreclr/hosts/coreshim/CoreShim.cpp b/src/coreclr/hosts/coreshim/CoreShim.cpp
index 2583215b20..7a5c3a1d1c 100644
--- a/src/coreclr/hosts/coreshim/CoreShim.cpp
+++ b/src/coreclr/hosts/coreshim/CoreShim.cpp
@@ -64,17 +64,28 @@ namespace
return std::wstring{ buffer.Buf, buffer.Buf + len };
}
- std::wstring GetEnvVar(_In_z_ const WCHAR *env)
+ bool TryGetEnvVar(_In_z_ const WCHAR* env, _Inout_ std::wstring& value)
{
DWORD len = ::GetEnvironmentVariableW(env, nullptr, 0);
if (len == 0)
- throw __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND);
+ return false;
PathBuffer<WCHAR> buffer;
buffer.SetLength(len);
(void)::GetEnvironmentVariableW(env, buffer, buffer);
- return static_cast<WCHAR *>(buffer.Buf);
+ value = static_cast<WCHAR *>(buffer.Buf);
+ return true;
+ }
+
+ std::wstring GetEnvVar(_In_z_ const WCHAR *env)
+ {
+ std::wstring value;
+ if (!TryGetEnvVar(env, value))
+ {
+ throw __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND);
+ }
+ return value;
}
std::string ConvertWideToUtf8(_In_ const std::wstring &wide)
@@ -150,6 +161,37 @@ namespace Utility
}
}
+bool TryLoadHostPolicy(const WCHAR* hostPolicyPath)
+{
+ const WCHAR *hostpolicyName = W("hostpolicy.dll");
+ HMODULE hMod = ::GetModuleHandleW(hostpolicyName);
+ if (hMod != nullptr)
+ {
+ return true;
+ }
+
+ // Check if a hostpolicy exists and if it does, load it.
+ if (INVALID_FILE_ATTRIBUTES != ::GetFileAttributesW(hostPolicyPath))
+ {
+ hMod = ::LoadLibraryExW(hostPolicyPath, nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
+ if (hMod == nullptr)
+ return false;
+
+ // Initialize the hostpolicy mock to a default state
+ using Set_corehost_resolve_component_dependencies_Values_fn = void(__cdecl *)(
+ int returnValue,
+ const WCHAR *assemblyPaths,
+ const WCHAR *nativeSearchPaths,
+ const WCHAR *resourceSearchPaths);
+ auto set_comp_depend_values = (Set_corehost_resolve_component_dependencies_Values_fn)
+ ::GetProcAddress(hMod, "Set_corehost_resolve_component_dependencies_Values");
+
+ assert(set_comp_depend_values != nullptr);
+ set_comp_depend_values(0, W(""), W(""), W(""));
+ }
+ return true;
+}
+
HRESULT coreclr::GetCoreClrInstance(_Outptr_ coreclr **instance, _In_opt_z_ const WCHAR *path)
{
if (s_CoreClrInstance != nullptr)
@@ -158,42 +200,18 @@ HRESULT coreclr::GetCoreClrInstance(_Outptr_ coreclr **instance, _In_opt_z_ cons
return S_FALSE;
}
- // Since the CoreShim is being loaded, there is a chance the scenario depends on
- // other aspects of the offical host platform (e.g. hostpolicy). Verify a hostpolicy
- // is _not_ already loaded and if not, attempt to load a hostpolicy library adjacent
- // to the coreshim. If there isn't one, just keep going.
- const WCHAR *hostpolicyName = W("hostpolicy.dll");
- HMODULE hMod = ::GetModuleHandleW(hostpolicyName);
- if (hMod == nullptr)
- {
- HRESULT hr;
- std::wstring coreShimPath;
- RETURN_IF_FAILED(Utility::GetCoreShimDirectory(coreShimPath));
-
- std::wstring hostpolicyPath{ coreShimPath };
- hostpolicyPath.append(hostpolicyName);
+ const wchar_t* mockHostPolicyEnvVar = W("MOCK_HOSTPOLICY");
+ std::wstring hostPolicyPath;
- // Check if a hostpolicy exists and if it does, load it.
- if (INVALID_FILE_ATTRIBUTES != ::GetFileAttributesW(hostpolicyPath.c_str()))
+ if (TryGetEnvVar(mockHostPolicyEnvVar, hostPolicyPath))
+ {
+ if (!TryLoadHostPolicy(hostPolicyPath.c_str()))
{
- hMod = ::LoadLibraryExW(hostpolicyPath.c_str(), nullptr, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
- if (hMod == nullptr)
- return E_UNEXPECTED;
-
- // Initialize the hostpolicy mock to a default state
- using Set_corehost_resolve_component_dependencies_Values_fn = void(__cdecl *)(
- int returnValue,
- const WCHAR *assemblyPaths,
- const WCHAR *nativeSearchPaths,
- const WCHAR *resourceSearchPaths);
- auto set_comp_depend_values = (Set_corehost_resolve_component_dependencies_Values_fn)
- ::GetProcAddress(hMod, "Set_corehost_resolve_component_dependencies_Values");
-
- assert(set_comp_depend_values != nullptr);
- set_comp_depend_values(0, W(""), W(""), W(""));
+ return E_UNEXPECTED;
}
}
+
try
{
std::wstring pathLocal;
diff --git a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp
index 7bfe2eaa98..1a6bf118c4 100644
--- a/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp
+++ b/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp
@@ -339,6 +339,18 @@ int ExecuteManagedAssembly(
nativeDllSearchDirs.append(":");
nativeDllSearchDirs.append(clrFilesAbsolutePath);
+ void* hostpolicyLib = nullptr;
+ char* mockHostpolicyPath = getenv("MOCK_HOSTPOLICY");
+ if (mockHostpolicyPath)
+ {
+ hostpolicyLib = dlopen(mockHostpolicyPath, RTLD_LAZY);
+ if (hostpolicyLib == nullptr)
+ {
+ fprintf(stderr, "Failed to load mock hostpolicy at path '%s'. Error: %s", mockHostpolicyPath, dlerror());
+ return -1;
+ }
+ }
+
AddFilesFromDirectoryToTpaList(clrFilesAbsolutePath, tpaList);
void* coreclrLib = dlopen(coreClrDllPath.c_str(), RTLD_NOW | RTLD_LOCAL);
@@ -466,5 +478,13 @@ int ExecuteManagedAssembly(
fprintf(stderr, "dlopen failed to open the libcoreclr.so with error %s\n", error);
}
+ if (hostpolicyLib)
+ {
+ if(dlclose(hostpolicyLib) != 0)
+ {
+ fprintf(stderr, "Warning - dlclose of mock hostpolicy failed.\n");
+ }
+ }
+
return exitCode;
}
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>