Disable DllImportSearchPathsTest and StartupHookTests on mobile (#86269)
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Thu, 18 May 2023 09:35:46 +0000 (11:35 +0200)
committerGitHub <noreply@github.com>
Thu, 18 May 2023 09:35:46 +0000 (11:35 +0200)
Also try to fix the StartupHookTests on LLVM FullAOT by making sure we also AOT dlls in subdirectories.

This uncovered an issue in src/tests/Common/external/external.csproj where an old version of Microsoft.CodeAnalysis.Compilers was referenced which made AOT fail, so I upgraded it.
That uncovered a problem AOTing Microsoft.CodeAnalysis.VisualBasic.dll so had to exclude it from AOTing.

src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.csproj
src/tests/Common/external/external.csproj
src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.cs
src/tests/Loader/StartupHooks/StartupHookTests.cs
src/tests/build.proj
src/tests/tracing/runtimeeventsource/NativeRuntimeEventSourceTest.cs

index de137ac..5b0ca25 100644 (file)
@@ -8,9 +8,9 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" />
-    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" />
-    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersion)" />
+    <PackageReference Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="$(MicrosoftCodeAnalysisAnalyzersVersion)" PrivateAssets="all" />
   </ItemGroup>
 
   <ItemGroup>
index bc749d9..d2541b5 100644 (file)
@@ -64,7 +64,7 @@
     <PackageToInclude Include="CommandLineParser"/>
     <PackageToInclude Include="Microsoft.DotNet.XUnitExtensions" />
 
-    <PackageReference Include="Microsoft.CodeAnalysis.Compilers" Version="1.1.1" />
+    <PackageReference Include="Microsoft.CodeAnalysis.Compilers" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" />
     <PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
     <PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="$(TraceEventVersion)" />
     <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
index 31e69ae..d3837ad 100644 (file)
@@ -19,7 +19,13 @@ public class DllImportSearchPathsTest
     }
 
     public static bool CanLoadAssemblyInSubdirectory =>
-        !TestLibrary.Utilities.IsNativeAot && !TestLibrary.PlatformDetection.IsMonoLLVMFULLAOT;
+        !TestLibrary.Utilities.IsNativeAot &&
+        !TestLibrary.PlatformDetection.IsMonoLLVMFULLAOT &&
+        !OperatingSystem.IsAndroid() &&
+        !OperatingSystem.IsIOS() &&
+        !OperatingSystem.IsTvOS() &&
+        !OperatingSystem.IsBrowser() &&
+        !OperatingSystem.IsWasi();
 
     [ConditionalFact(nameof(CanLoadAssemblyInSubdirectory))]
     public static void AssemblyDirectory_Found()
index 2f188bd..9bab54d 100644 (file)
@@ -16,7 +16,15 @@ public unsafe class StartupHookTests
 
     private static delegate*<void> ProcessStartupHooks = (delegate*<void>)s_startupHookProvider.GetMethod("ProcessStartupHooks", BindingFlags.NonPublic | BindingFlags.Static).MethodHandle.GetFunctionPointer();
 
-    public static bool IsSupported = ((delegate*<bool>)s_startupHookProvider.GetProperty(nameof(IsSupported), BindingFlags.NonPublic | BindingFlags.Static).GetMethod.MethodHandle.GetFunctionPointer())();
+    private static bool IsUnsupportedPlatform =
+        // these platforms need special setup for startup hooks
+        OperatingSystem.IsAndroid() ||
+        OperatingSystem.IsIOS() ||
+        OperatingSystem.IsTvOS() ||
+        OperatingSystem.IsBrowser() ||
+        OperatingSystem.IsWasi();
+
+    public static bool IsSupported = !IsUnsupportedPlatform && ((delegate*<bool>)s_startupHookProvider.GetProperty(nameof(IsSupported), BindingFlags.NonPublic | BindingFlags.Static).GetMethod.MethodHandle.GetFunctionPointer())();
 
     [Fact]
     public static void ValidHookName()
index 3a8a0d3..3be9564 100644 (file)
       <Output TaskParameter="Filtered" ItemName="TestDirs" />
     </RemoveDuplicates>
     <ItemGroup>
-      <TestsAndAssociatedAssemblies Include="%(TestDirs.Identity)/*.dll" Exclude="@(NoMonoAotAssemblyPaths)" />
-      <CoreRootDlls Include="$(CORE_ROOT)/*.dll" Exclude="$(CORE_ROOT)/xunit.performance.api.dll" />
+      <TestsAndAssociatedAssemblies Include="%(TestDirs.Identity)/**/*.dll" Exclude="@(NoMonoAotAssemblyPaths)" />
+      <CoreRootDlls Include="$(CORE_ROOT)/*.dll" Exclude="$(CORE_ROOT)/xunit.performance.api.dll;$(CORE_ROOT)/Microsoft.CodeAnalysis.VisualBasic.dll" />
       <AllDlls Condition="'$(MonoFullAot)' == 'true'" Include="@(TestsAndAssociatedAssemblies);@(CoreRootDlls)" />
       <AllDlls Condition="'$(MonoFullAot)' != 'true'" Include="@(TestsAndAssociatedAssemblies)" />
     </ItemGroup>
index 4f2c985..48bd618 100644 (file)
@@ -40,10 +40,12 @@ namespace Tracing.Tests
 
                     using (Listener listener = new())
                     {
+                        CancellationTokenSource cts = new();
+
                         // Trigger the allocator task.
                         Task.Run(() =>
                         {
-                            while (true)
+                            while (!cts.IsCancellationRequested)
                             {
                                 for (int i = 0; i < 1000; i++)
                                 {
@@ -75,6 +77,8 @@ namespace Tracing.Tests
                             }
                         }
 
+                        cts.Cancel();
+
                         Assert2.True("listener.EventCount > 0", listener.EventCount > 0);
 
                         if (OperatingSystem.IsWindows())