From c395a8a8e7a987000455d65efac371973d96a3c8 Mon Sep 17 00:00:00 2001 From: Swaroop Sridhar Date: Thu, 28 Feb 2019 14:10:46 -0800 Subject: [PATCH] NativeLibraryTests: Platform restriction on some tests (#22732) NativeLibraryTests: Platform restriction on some tests This change adds platform restrictions on two API tests: * Change the System32 dll loading test from `msi.dll` to `uri.dll` * Restrict the System32 dll loading test to platforms where `uri.dll` actually exists in the System32 directory. * Disable double-free tests on Linux, because the OS call doesn't reliably fail. Use the public version of CoreLib, since the NativeLibrary APIs are now available. Fixes #22726 --- .../Interop/NativeLibrary/NativeLibraryTests.cs | 24 ++++++++++++---------- .../NativeLibrary/NativeLibraryTests.csproj | 1 - 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/src/Interop/NativeLibrary/NativeLibraryTests.cs b/tests/src/Interop/NativeLibrary/NativeLibraryTests.cs index 19eb125..5b04b11 100644 --- a/tests/src/Interop/NativeLibrary/NativeLibraryTests.cs +++ b/tests/src/Interop/NativeLibrary/NativeLibraryTests.cs @@ -7,8 +7,6 @@ using System.Reflection; using System.Runtime.InteropServices; using TestLibrary; -using Console = Internal.Console; - enum TestResult { Success, ReturnFailure, @@ -105,10 +103,13 @@ public class NativeLibraryTest success &= EXPECT(TryLoadLibraryAdvanced(libName, assembly, null), (TestLibrary.Utilities.IsWindows) ? TestResult.Success : TestResult.ReturnFailure); - if (TestLibrary.Utilities.IsWindows) + // Check for loading a native binary in the system32 directory. + // The choice of the binary is arbitrary, and may not be available on + // all Windows platforms (ex: Nano server) + libName = "url.dll"; + if (TestLibrary.Utilities.IsWindows && + File.Exists(Path.Combine(Environment.SystemDirectory, libName))) { - libName = GetWin32LibName(); - // Calls on a valid library from System32 directory success &= EXPECT(LoadLibraryAdvanced(libName, assembly, DllImportSearchPath.System32)); success &= EXPECT(TryLoadLibraryAdvanced(libName, assembly, DllImportSearchPath.System32)); @@ -144,7 +145,13 @@ public class NativeLibraryTest success &= EXPECT(FreeLibrary(handle)); // Double Free - success &= EXPECT(FreeLibrary(handle), TestResult.InvalidOperation); + if (TestLibrary.Utilities.IsWindows) + { + // The FreeLibrary() implementation simply calls the appropriate OS API + // with the supplied handle. Not all OSes consistently return an error + // when a library is double-freed. + success &= EXPECT(FreeLibrary(handle), TestResult.InvalidOperation); + } // Null Free success &= EXPECT(FreeLibrary(IntPtr.Zero)); @@ -190,11 +197,6 @@ public class NativeLibraryTest return "NativeLibrary"; } - static string GetWin32LibName() - { - return "msi.dll"; - } - static string GetNativeLibraryName() { string baseName = GetNativeLibraryPlainName(); diff --git a/tests/src/Interop/NativeLibrary/NativeLibraryTests.csproj b/tests/src/Interop/NativeLibrary/NativeLibraryTests.csproj index 9f01b9f..b769e9b 100644 --- a/tests/src/Interop/NativeLibrary/NativeLibraryTests.csproj +++ b/tests/src/Interop/NativeLibrary/NativeLibraryTests.csproj @@ -11,7 +11,6 @@ {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} ..\..\ true - true -- 2.7.4