Skip to content

Commit

Permalink
[iOS] Enable Diagnostics.Tracing tests (#72545)
Browse files Browse the repository at this point in the history
This change modifies System.Diagnostics.Tracing tests to enable the diagnostics runtime component feature.  Additionally, the AppleAppBuilder task was modified to read the `AotDataFile` path that is produced when aot'ing assemblies.  Previously, we would assume they were located in the publish directory.

Co-authored-by: Ankit Jain <radical@gmail.com>
  • Loading branch information
steveisok and radical authored Jul 25, 2022
1 parent 5e91aa4 commit bbdd837
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace BasicEventSourceTests
public class ActivityTracking
{
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56073", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void StartStopCreatesActivity()
{
using ActivityEventListener l = new ActivityEventListener();
Expand All @@ -28,7 +27,6 @@ public void StartStopCreatesActivity()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56073", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public async Task ActivityFlowsAsync()
{
using ActivityEventListener l = new ActivityEventListener();
Expand Down Expand Up @@ -77,7 +75,6 @@ private async Task YieldTwoActivitiesDeep(ActivityEventSource es)
// the future we might decide it wasn't even desirable to begin with.
// Compare with SetCurrentActivityIdAfterEventDoesNotFlowAsync below.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56073", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public async Task SetCurrentActivityIdBeforeEventFlowsAsync()
{
using ActivityEventListener l = new ActivityEventListener();
Expand All @@ -103,7 +100,6 @@ public async Task SetCurrentActivityIdBeforeEventFlowsAsync()
// the future we might decide it wasn't even desirable to begin with.
// Compare with SetCurrentActivityIdBeforeEventFlowsAsync above.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/56073", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public async Task SetCurrentActivityIdAfterEventDoesNotFlowAsync()
{
using ActivityEventListener l = new ActivityEventListener();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ private static string GetResourceStringFromReflection(string key)
/// </summary>
[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "https://github.com/dotnet/runtime/issues/21421")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_GenerateManifest_InvalidEventSources()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class TestsTraits
/// Tests EventSource Traits.
/// </summary>
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_EventSource_Traits_Contract()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand All @@ -46,7 +45,6 @@ public void Test_EventSource_Traits_Contract()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_EventSource_Traits_Dynamic()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private void Test_BadTypes_Manifest(EventSource source)
/// Test the
/// </summary>
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: https://github.com/dotnet/runtime/issues/26197
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_BadEventSource_MismatchedIds()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ private struct PartB_UserInfo
/// </summary>
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/21564", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_Write_T_EventListener()
{
using (var listener = new EventListenerListener())
Expand All @@ -52,7 +51,6 @@ public void Test_Write_T_EventListener()
/// </summary>
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/21564", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_Write_T_EventListener_UseEvents()
{
Test_Write_T(new EventListenerListener(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public partial class TestsWriteEventToListener
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/21569", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public unsafe void Test_WriteEvent_ArgsBasicTypes()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down Expand Up @@ -214,7 +213,6 @@ public unsafe void Test_WriteEvent_ArgsBasicTypes()

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/21569", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_WriteEvent_ArgsCornerCases()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down Expand Up @@ -248,7 +246,6 @@ public void Test_WriteEvent_ArgsCornerCases()
static partial void Test_WriteEvent_ArgsCornerCases_TestEtw(EventSourceTest log);

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_WriteEvent_InvalidCalls()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand All @@ -271,7 +268,6 @@ public void Test_WriteEvent_InvalidCalls()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_WriteEvent_ToChannel_Coverage()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand All @@ -286,7 +282,6 @@ public void Test_WriteEvent_ToChannel_Coverage()

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/21569", TargetFrameworkMonikers.NetFramework)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_WriteEvent_ZeroKwds()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down Expand Up @@ -323,7 +318,6 @@ public void Test_WriteEvent_ZeroKwds()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_EventSourceCreatedEvents_BeforeListener()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down Expand Up @@ -387,7 +381,6 @@ public void Test_EventSourceCreatedEvents_BeforeListener()
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_EventSourceCreatedEvents_AfterListener()
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down Expand Up @@ -452,7 +445,6 @@ public void Test_EventSourceCreatedEvents_AfterListener()
[Theory]
[InlineData(true)]
[InlineData(false)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51382", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public void Test_EventListenerThrows_ExceptionIsNotRethrownToCaller(bool setThrowOnEventWriteErrorsFlag)
{
TestUtilities.CheckNoEventSourcesRunning("Start");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<TestRuntime>true</TestRuntime>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
</PropertyGroup>
<PropertyGroup>
<RuntimeComponents Condition="'$(TargetsAppleMobile)' == 'true'">diagnostics_tracing</RuntimeComponents>
</PropertyGroup>
<!-- Windows only files -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
<Compile Include="BasicEventSourceTest\Harness\EtwListener.cs" />
Expand Down
16 changes: 14 additions & 2 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Reflection/tests/System.Reflection.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Threading.Channels/tests/System.Threading.Channels.Tests.csproj" />

<!--
System.Formats.Cbor crashes on tvOS
-->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Formats.Cbor\tests\System.Formats.Cbor.Tests.csproj" />

<!--
Test apps that are too large and take too long to build
Keep here until aggressive trimming targets can work on helix.
-->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.RegularExpressions\tests\UnitTests\System.Text.RegularExpressions.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Json\tests\System.Text.Json.SourceGeneration.Tests\System.Text.Json.SourceGeneration.Roslyn4.0.Tests.csproj" />


<!-- Functional tests on devices have problems with return codes from mlaunch -->
<ProjectExclusions Include="$(RepoRoot)\src\tests\FunctionalTests\$(TargetOS)\Device\**\*.Test.csproj" />
</ItemGroup>
Expand Down Expand Up @@ -311,7 +324,6 @@

<!-- App Crash https://github.com/dotnet/runtime/issues/53624 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Dynamic.Runtime/tests/System.Dynamic.Runtime.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Linq.Expressions/tests/System.Linq.Expressions.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.Requests/tests/System.Net.Requests.Tests.csproj" />
Expand Down Expand Up @@ -377,7 +389,7 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.DependencyInjection\tests\DI.Tests\Microsoft.Extensions.DependencyInjection.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Logging.EventSource\tests\Microsoft.Extensions.Logging.EventSource.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Diagnostics.DiagnosticSource\tests\System.Diagnostics.DiagnosticSource.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj" />
<ProjectExclusions Condition="'$(TargetOS)' != 'iOS'" Include="$(MSBuildThisFileDirectory)System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj" />

<!-- Issue: https://github.com/dotnet/runtime/issues/51708 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Linq.Expressions\tests\System.Linq.Expressions.Tests.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions src/mono/msbuild/apple/build/AppleApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
BuildAppBundle="$(GenerateXcodeProject)"
Optimized="$(Optimized)"
DevTeamProvisioning="$(DevTeamProvisioning)"
RuntimeComponents="$(RuntimeComponents)"
DiagnosticPorts="$(DiagnosticPorts)"
OutputDirectory="$(AppleAppBundleDir)"
AppDir="$(AppleAppDir)">
<Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
Expand Down
36 changes: 20 additions & 16 deletions src/tasks/AotCompilerTask/MonoAOTCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
public string[]? FileWrites { get; private set; }

private static readonly Encoding s_utf8Encoding = new UTF8Encoding(false);
private const string s_originalFullPathMetadataName = "__OriginalFullPath";

private List<string> _fileWrites = new();

Expand Down Expand Up @@ -484,8 +485,9 @@ private bool ExecuteInternal()
if (!ProcessAndValidateArguments())
return false;

_assembliesToCompile = EnsureAndGetAssembliesInTheSameDir(Assemblies);
_assembliesToCompile = FilterAssemblies(_assembliesToCompile);
IEnumerable<ITaskItem> managedAssemblies = FilterOutUnmanagedAssemblies(Assemblies);
managedAssemblies = EnsureAllAssembliesInTheSameDir(managedAssemblies);
_assembliesToCompile = managedAssemblies.Where(f => !ShouldSkipForAOT(f)).ToList();

if (!string.IsNullOrEmpty(AotModulesTablePath) && !GenerateAotModulesTable(_assembliesToCompile, Profilers, AotModulesTablePath))
return false;
Expand Down Expand Up @@ -582,39 +584,40 @@ static bool IsNewerThanOutput(string inFile, string outFile)
(File.GetLastWriteTimeUtc(inFile) > File.GetLastWriteTimeUtc(outFile));
}

private IList<ITaskItem> FilterAssemblies(IEnumerable<ITaskItem> assemblies)
private IEnumerable<ITaskItem> FilterOutUnmanagedAssemblies(IEnumerable<ITaskItem> assemblies)
{
List<ITaskItem> filteredAssemblies = new();
foreach (var asmItem in assemblies)
{
if (ShouldSkip(asmItem))
if (ShouldSkipForAOT(asmItem))
{
if (parsedAotMode == MonoAotMode.LLVMOnly)
throw new LogAsErrorException($"Building in AOTMode=LLVMonly is not compatible with excluding any assemblies for AOT. Excluded assembly: {asmItem.ItemSpec}");

Log.LogMessage(MessageImportance.Low, $"Skipping {asmItem.ItemSpec} because it has %(AOT_InternalForceToInterpret)=true");
continue;
}

string assemblyPath = asmItem.GetMetadata("FullPath");
using var assemblyFile = File.OpenRead(assemblyPath);
using PEReader reader = new(assemblyFile, PEStreamOptions.Default);
if (!reader.HasMetadata)
else
{
Log.LogWarning($"Skipping unmanaged {assemblyPath} for AOT");
continue;
string assemblyPath = asmItem.GetMetadata("FullPath");
using var assemblyFile = File.OpenRead(assemblyPath);
using PEReader reader = new(assemblyFile, PEStreamOptions.Default);
if (!reader.HasMetadata)
{
Log.LogMessage(MessageImportance.Low, $"Skipping unmanaged {assemblyPath} for AOT");
continue;
}
}

filteredAssemblies.Add(asmItem);
}

return filteredAssemblies;

static bool ShouldSkip(ITaskItem asmItem)
=> bool.TryParse(asmItem.GetMetadata("AOT_InternalForceToInterpret"), out bool skip) && skip;
}

private IList<ITaskItem> EnsureAndGetAssembliesInTheSameDir(IList<ITaskItem> assemblies)
private static bool ShouldSkipForAOT(ITaskItem asmItem)
=> bool.TryParse(asmItem.GetMetadata("AOT_InternalForceToInterpret"), out bool skip) && skip;

private IEnumerable<ITaskItem> EnsureAllAssembliesInTheSameDir(IEnumerable<ITaskItem> assemblies)
{
string firstAsmDir = Path.GetDirectoryName(assemblies.First().GetMetadata("FullPath")) ?? string.Empty;
bool allInSameDir = assemblies.All(asm => Path.GetDirectoryName(asm.GetMetadata("FullPath")) == firstAsmDir);
Expand All @@ -640,6 +643,7 @@ private IList<ITaskItem> EnsureAndGetAssembliesInTheSameDir(IList<ITaskItem> ass

ITaskItem newAsm = new TaskItem(newPath);
asmItem.CopyMetadataTo(newAsm);
asmItem.SetMetadata(s_originalFullPathMetadataName, asmPath);
newAssemblies.Add(newAsm);
}

Expand Down
20 changes: 14 additions & 6 deletions src/tasks/AppleAppBuilder/AppleAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,26 @@ public override bool Execute()
}
Directory.CreateDirectory(binDir);

var assemblerFiles = new List<string>();
var assemblerFilesToLink = new List<string>();
List<string> assemblerFiles = new List<string>();
List<string> assemblerDataFiles = new List<string>();
List<string> assemblerFilesToLink = new List<string>();
foreach (ITaskItem file in Assemblies)
{
// use AOT files if available
var obj = file.GetMetadata("AssemblerFile");
var llvmObj = file.GetMetadata("LlvmObjectFile");
string obj = file.GetMetadata("AssemblerFile");
string llvmObj = file.GetMetadata("LlvmObjectFile");
string dataFile = file.GetMetadata("AotDataFile");

if (!string.IsNullOrEmpty(obj))
{
assemblerFiles.Add(obj);
}

if (!string.IsNullOrEmpty(dataFile))
{
assemblerDataFiles.Add(dataFile);
}

if (!string.IsNullOrEmpty(llvmObj))
{
assemblerFilesToLink.Add(llvmObj);
Expand Down Expand Up @@ -243,7 +251,7 @@ public override bool Execute()

if (GenerateXcodeProject)
{
XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerFilesToLink,
XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink,
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource);

if (BuildAppBundle)
Expand All @@ -261,7 +269,7 @@ public override bool Execute()
}
else if (GenerateCMakeProject)
{
generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerFilesToLink,
generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerDataFiles, assemblerFilesToLink,
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, EnableAppSandbox, DiagnosticPorts, RuntimeComponents, NativeMainSource);
}

Expand Down
Loading

0 comments on commit bbdd837

Please sign in to comment.