Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][tests] Enable ILStrip after AOT compilation for library tests #88167

Merged
merged 17 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,17 @@ public void PinnedAndUnpinnedLocals()
Assert.Equal("DoSomething", reader.GetString(methodDef.Name));

MethodBodyBlock body = peReader.GetMethodBody(methodDef.RelativeVirtualAddress);
StandaloneSignature localSignature = reader.GetStandaloneSignature(body.LocalSignature);

ImmutableArray<string> localTypes = localSignature.DecodeLocalSignature(provider, genericContext: null);

// Compiler can generate temporaries or re-order so just check the ones we expect are there.
// (They could get optimized away too. If that happens in practice, change this test to use hard-coded signatures.)
Assert.Contains("uint8[] pinned", localTypes);
Assert.Contains("uint8[]", localTypes);
var il = body.GetILBytes();
// ILStrip replaces method body with the 'ret' IL opcode i.e. 0x2a
if (!(il?.Length == 1 && il[0] == 0x2a)) {
StandaloneSignature localSignature = reader.GetStandaloneSignature(body.LocalSignature);
ImmutableArray<string> localTypes = localSignature.DecodeLocalSignature(provider, genericContext: null);

// Compiler can generate temporaries or re-order so just check the ones we expect are there.
// (They could get optimized away too. If that happens in practice, change this test to use hard-coded signatures.)
Assert.Contains("uint8[] pinned", localTypes);
Assert.Contains("uint8[]", localTypes);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ private static void TestConstructors1Worker(Type t)
Assert.False(c.IsConstructedGenericMethod());
Assert.False(c.IsGenericMethod);
Assert.Equal(MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, c.Attributes);
Assert.Equal(MethodImplAttributes.IL, c.MethodImplementationFlags);
if (c.MethodImplementationFlags.HasFlag(MethodImplAttributes.NoInlining))
{
// when the assembly was processed with ILStrip, the NoInlining flag is set
Assert.Equal(MethodImplAttributes.IL | MethodImplAttributes.NoInlining, c.MethodImplementationFlags);
}
else
{
Assert.Equal(MethodImplAttributes.IL, c.MethodImplementationFlags);
}
Assert.Equal(CallingConventions.Standard | CallingConventions.HasThis, c.CallingConvention);

ParameterInfo[] ps = c.GetParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ private static void TestMethods1Worker(Type t)
Assert.False(m.IsConstructedGenericMethod());
Assert.False(m.IsGenericMethod);
Assert.Equal(MethodAttributes.Public | MethodAttributes.HideBySig, m.Attributes);
Assert.Equal(MethodImplAttributes.IL, m.MethodImplementationFlags);
if (m.MethodImplementationFlags.HasFlag(MethodImplAttributes.NoInlining))
{
// when the assembly was processed with ILStrip, the NoInlining flag is set
Assert.Equal(MethodImplAttributes.IL | MethodImplAttributes.NoInlining, m.MethodImplementationFlags);
}
else
{
Assert.Equal(MethodImplAttributes.IL, m.MethodImplementationFlags);
}
Assert.Equal(CallingConventions.Standard | CallingConventions.HasThis, m.CallingConvention);

Type theT = t.GetGenericArguments()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void Asserts_Interpolation_Syntax()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
kotlarmilos marked this conversation as resolved.
Show resolved Hide resolved
public void WriteIf_Interpolation()
{
Debug.WriteIfInterpolatedStringHandler handler;
Expand Down Expand Up @@ -76,6 +77,7 @@ public void WriteIf_Interpolation_Syntax()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void WriteLineIf_Interpolation()
{
Debug.WriteIfInterpolatedStringHandler handler;
Expand All @@ -97,6 +99,7 @@ public void WriteLineIf_Interpolation()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void WriteLineIf_Interpolation_Syntax()
{
VerifyLogged(() => Debug.WriteLineIf(true, $"{EmptyToString.Instance}logged"), "logged" + Environment.NewLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected void GoToNextLine()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void Debug_Write_Indents()
{
// This test when run alone verifies Debug.Write indentation, even on first call, is correct.
Expand Down Expand Up @@ -67,6 +68,7 @@ public void Debug_WriteNull_SkipsIndentation()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void Debug_WriteLineNull_IndentsEmptyStringProperly()
{
Debug.Indent();
Expand Down Expand Up @@ -100,6 +102,7 @@ public void Fail()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void Write()
{
VerifyLogged(() => Debug.Write(5), "5");
Expand Down Expand Up @@ -159,6 +162,7 @@ public void WriteIf()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void WriteLineIf()
{
VerifyLogged(() => Debug.WriteLineIf(true, 5), "5" + Environment.NewLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void Trace_Write_TraceListenerAlwaysIndentsOnFirstCall()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void Trace_Write_Indents()
{
// This test when run alone verifies Trace.Write indentation, even on first call, is correct.
Expand All @@ -74,6 +75,7 @@ public void Trace_WriteLine_Indents()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void Trace_WriteLine_WontIndentAfterWrite()
{
Trace.Indent();
Expand Down Expand Up @@ -129,6 +131,7 @@ public void Trace_WriteLineNull_IndentsEmptyStringProperly()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void Trace_UpdatingDebugIndentation_UpdatesTraceIndentation_AndViceVersa()
{
int before = Debug.IndentSize * Debug.IndentLevel;
Expand Down Expand Up @@ -181,6 +184,7 @@ public void Trace_UpdatingDebugIndentation_UpdatesTraceIndentation_AndViceVersa(
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void Trace_Refresh_ResetsIndentSize()
{
int before = Debug.IndentSize * Debug.IndentLevel;
Expand All @@ -196,6 +200,7 @@ public void Trace_Refresh_ResetsIndentSize()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void Trace_ClearTraceListeners_StopsWritingToDebugger()
{
VerifyLogged(() => Debug.Write("pizza"), "pizza");
Expand All @@ -211,6 +216,7 @@ public void Trace_ClearTraceListeners_StopsWritingToDebugger()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void TraceWriteIf()
{
VerifyLogged(() => Trace.WriteIf(true, 5), "5");
Expand All @@ -229,6 +235,7 @@ public void TraceWriteIf()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Trace and debug listeners were processed using ILStrip.")]
public void TraceWriteLineIf()
{
VerifyLogged(() => Trace.WriteLineIf(true, 5), "5" + Environment.NewLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Reflection;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

#pragma warning disable 0219 // field is never used
Expand Down Expand Up @@ -55,6 +56,9 @@ public static void TestMethodBody()
{
MethodBase mbase = typeof(MethodBaseTests).GetMethod("MyOtherMethod", BindingFlags.Static | BindingFlags.Public);
MethodBody mb = mbase.GetMethodBody();
var il = mb.GetILAsByteArray();
if (il?.Length == 1 && il[0] == 0x2a) // ILStrip replaces method bodies with the 'ret' IL opcode i.e. 0x2a
throw new SkipTestException("The method body was processed using ILStrip.");
var codeSize = mb.GetILAsByteArray().Length;
Assert.True(mb.InitLocals); // local variables are initialized

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Reflection;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

#pragma warning disable 0219 // field is never used
Expand All @@ -17,6 +18,10 @@ public static void Test_MethodBody_ExceptionHandlingClause()
MethodInfo mi = typeof(MethodBodyTests).GetMethod("MethodBodyExample", BindingFlags.NonPublic | BindingFlags.Static);
MethodBody mb = mi.GetMethodBody();

var il = mb.GetILAsByteArray();
if (il?.Length == 1 && il[0] == 0x2a) // ILStrip replaces method bodies with the 'ret' IL opcode i.e. 0x2a
throw new SkipTestException("The method body was processed using ILStrip.");

Assert.True(mb.InitLocals); // local variables are initialized
#if DEBUG
Assert.Equal(2, mb.MaxStackSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ public static class MethodImplAttributeTests
public static void AggressiveOptimizationTest()
{
MethodImplAttributes implAttributes = MethodBase.GetCurrentMethod().MethodImplementationFlags;
Assert.Equal(MethodImplAttributes.AggressiveOptimization, implAttributes);
Assert.Equal(MethodImplOptions.AggressiveOptimization, (MethodImplOptions)implAttributes);
if (implAttributes.HasFlag(MethodImplAttributes.NoInlining))
{
// when the assembly was processed with ILStrip, the NoInlining flag is set
Assert.Equal(MethodImplAttributes.AggressiveOptimization | MethodImplAttributes.NoInlining, implAttributes);
Assert.Equal(MethodImplOptions.AggressiveOptimization | MethodImplOptions.NoInlining, (MethodImplOptions)implAttributes);
}
else
{
Assert.Equal(MethodImplAttributes.AggressiveOptimization, implAttributes);
Assert.Equal(MethodImplOptions.AggressiveOptimization, (MethodImplOptions)implAttributes);
}
}
}
}
3 changes: 1 addition & 2 deletions src/mono/msbuild/apple/build/AppleBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<UseMonoJustInterp Condition="'$(RunAOTCompilation)' == 'true' and '$(MonoForceInterpreter)' == 'true'">true</UseMonoJustInterp>

<StripDebugSymbols Condition="'$(StripDebugSymbols)' == ''" >false</StripDebugSymbols>
<!-- Tracking issue: https://github.com/dotnet/runtime/issues/87740 -->
<!-- <ShouldILStrip Condition="'$(RunAOTCompilation)' == 'true' and '$(MonoForceInterpreter)' != 'true'">true</ShouldILStrip> -->
<ShouldILStrip Condition="'$(RunAOTCompilation)' == 'true' and '$(MonoForceInterpreter)' != 'true'">true</ShouldILStrip>

<_IsLibraryMode Condition="'$(UseNativeAOTRuntime)' != 'true' and '$(NativeLib)' != ''">true</_IsLibraryMode>

Expand Down
Loading