NativeLibraryTests: Platform restriction on some tests (#22732)
authorSwaroop Sridhar <Swaroop.Sridhar@microsoft.com>
Thu, 28 Feb 2019 22:10:46 +0000 (14:10 -0800)
committerGitHub <noreply@github.com>
Thu, 28 Feb 2019 22:10:46 +0000 (14:10 -0800)
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

tests/src/Interop/NativeLibrary/NativeLibraryTests.cs
tests/src/Interop/NativeLibrary/NativeLibraryTests.csproj

index 19eb125..5b04b11 100644 (file)
@@ -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();
index 9f01b9f..b769e9b 100644 (file)
@@ -11,7 +11,6 @@
     <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <ReferenceSystemPrivateCoreLib>true</ReferenceSystemPrivateCoreLib>
   </PropertyGroup>
   <!-- Default configurations to help VS understand the configurations -->
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">