Skip to content

Commit b39d6a6

Browse files
Add a simple size test (#81517)
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.
1 parent 6b882b4 commit b39d6a6

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

src/tests/nativeaot/SmokeTests/HardwareIntrinsics/Program.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
55
using System.Numerics;
6+
using System.Runtime.InteropServices;
67
using System.Runtime.Intrinsics;
78
using System.Runtime.Intrinsics.X86;
89

@@ -12,6 +13,36 @@ static int Main()
1213
{
1314
s_success = true;
1415

16+
#if !DEBUG
17+
Console.WriteLine("****************************************************");
18+
Console.WriteLine("* Size test *");
19+
long fileSize = new System.IO.FileInfo(Environment.ProcessPath).Length;
20+
Console.WriteLine($"* Size of the executable is {fileSize / 1024,7:n0} kB *");
21+
Console.WriteLine("****************************************************");
22+
23+
const int Meg = 1024 * 1024;
24+
const int HalfMeg = Meg / 2;
25+
long lowerBound, upperBound;
26+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
27+
{
28+
lowerBound = 2 * Meg; // 2 MB
29+
upperBound = 4 * Meg; // 4 MB
30+
}
31+
else
32+
{
33+
lowerBound = Meg + HalfMeg; // 1.5 MB
34+
upperBound = 2 * Meg; // 2 MB
35+
}
36+
37+
if (fileSize < lowerBound || fileSize > upperBound)
38+
{
39+
Console.WriteLine("BUG: File size is not in the expected range. Did a libraries change regress size of Hello World?");
40+
return 1;
41+
}
42+
43+
Console.WriteLine();
44+
#endif
45+
1546
// We expect the AOT compiler generated HW intrinsics with the following characteristics:
1647
//
1748
// * TRUE = IsSupported assumed to be true, no runtime check

src/tests/nativeaot/SmokeTests/HardwareIntrinsics/X64Baseline.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' != 'x64'">true</CLRTestTargetUnsupported>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<DefineConstants>$(DefineConstants);BASELINE_INTRINSICS</DefineConstants>
9+
<StripSymbols>true</StripSymbols>
10+
11+
<!-- We should be able to delete once CI machines no longer use ancient LLVM -->
12+
<ObjCopyName>objcopy</ObjCopyName>
913
</PropertyGroup>
1014
<ItemGroup>
1115
<Compile Include="Program.cs" />

src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64NonVex.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' != 'x64'">true</CLRTestTargetUnsupported>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<DefineConstants>$(DefineConstants);NON_VEX_INTRINSICS</DefineConstants>
9+
<StripSymbols>true</StripSymbols>
10+
11+
<!-- We should be able to delete once CI machines no longer use ancient LLVM -->
12+
<ObjCopyName>objcopy</ObjCopyName>
913
</PropertyGroup>
1014

1115
<ItemGroup>

src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64Vex.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<CLRTestTargetUnsupported Condition="'$(TargetArchitecture)' != 'x64'">true</CLRTestTargetUnsupported>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<DefineConstants>$(DefineConstants);VEX_INTRINSICS</DefineConstants>
9+
<StripSymbols>true</StripSymbols>
10+
11+
<!-- We should be able to delete once CI machines no longer use ancient LLVM -->
12+
<ObjCopyName>objcopy</ObjCopyName>
913
</PropertyGroup>
1014

1115
<ItemGroup>

0 commit comments

Comments
 (0)