Skip to content

Commit

Permalink
Add a simple size test (#81517)
Browse files Browse the repository at this point in the history
The size of Hello World is currently 1.8 MB. This is achieved by avoiding any non-field reflection in the codepaths that are part of a hello world. If reflection comes into picture, the size jumps by several 100 kB because suddenly we need a lot of code to support that. This is a smoke test to detect those situations. We're getting proper size testing in the dotnet/performance repo with trend histories, etc., but the invariant for Hello World is easy to check for and nice to gate commits on.
  • Loading branch information
MichalStrehovsky authored Feb 7, 2023
1 parent 6b882b4 commit b39d6a6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/tests/nativeaot/SmokeTests/HardwareIntrinsics/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

Expand All @@ -12,6 +13,36 @@ static int Main()
{
s_success = true;

#if !DEBUG
Console.WriteLine("****************************************************");
Console.WriteLine("* Size test *");
long fileSize = new System.IO.FileInfo(Environment.ProcessPath).Length;
Console.WriteLine($"* Size of the executable is {fileSize / 1024,7:n0} kB *");
Console.WriteLine("****************************************************");

const int Meg = 1024 * 1024;
const int HalfMeg = Meg / 2;
long lowerBound, upperBound;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
lowerBound = 2 * Meg; // 2 MB
upperBound = 4 * Meg; // 4 MB
}
else
{
lowerBound = Meg + HalfMeg; // 1.5 MB
upperBound = 2 * Meg; // 2 MB
}

if (fileSize < lowerBound || fileSize > upperBound)
{
Console.WriteLine("BUG: File size is not in the expected range. Did a libraries change regress size of Hello World?");
return 1;
}

Console.WriteLine();
#endif

// We expect the AOT compiler generated HW intrinsics with the following characteristics:
//
// * TRUE = IsSupported assumed to be true, no runtime check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' != 'x64'">true</CLRTestTargetUnsupported>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);BASELINE_INTRINSICS</DefineConstants>
<StripSymbols>true</StripSymbols>

<!-- We should be able to delete once CI machines no longer use ancient LLVM -->
<ObjCopyName>objcopy</ObjCopyName>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' != 'x64'">true</CLRTestTargetUnsupported>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);NON_VEX_INTRINSICS</DefineConstants>
<StripSymbols>true</StripSymbols>

<!-- We should be able to delete once CI machines no longer use ancient LLVM -->
<ObjCopyName>objcopy</ObjCopyName>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' != 'x64'">true</CLRTestTargetUnsupported>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);VEX_INTRINSICS</DefineConstants>
<StripSymbols>true</StripSymbols>

<!-- We should be able to delete once CI machines no longer use ancient LLVM -->
<ObjCopyName>objcopy</ObjCopyName>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit b39d6a6

Please sign in to comment.