Skip to content

Commit

Permalink
Add a test for determinism
Browse files Browse the repository at this point in the history
Resolves dotnet#73931. This checks that the result of parallel build is the same as the result of single-threaded build.

I'd like to add some more code to this so that there's more junk to compile but don't have a good idea of what to add. `XmlSerializer`? Suggestions welcome.
  • Loading branch information
MichalStrehovsky committed Oct 17, 2023
1 parent e68a4cd commit 54ef3eb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.IO;

using var baseline = File.OpenRead("baseline.object");
using var compare = File.OpenRead("compare.object");

Console.WriteLine($"Baseline size: {baseline.Length}");
Console.WriteLine($"Compare size: {compare.Length}");

if (baseline.Length != compare.Length)
throw new Exception("Different sizes");

for (int i = 0; i < baseline.Length; i++)
{
if (baseline.ReadByte() != compare.ReadByte())
throw new Exception($"Different at byte {i}");
}

return 100;
37 changes: 37 additions & 0 deletions src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>0</CLRTestPriority>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="Determinism.cs" />
</ItemGroup>

<Target Name="IlcCompileSingleThreaded"
Inputs="$(NativeIntermediateOutputPath)%(ManagedBinary.Filename)$(IlcOutputFileExt)"
Outputs="$(NativeIntermediateOutputPath)%(ManagedBinary.Filename)$(IlcOutputFileExt)-singlethreaded"
AfterTargets="IlcCompile">

<PropertyGroup>
<OldObjectFileName>$(NativeIntermediateOutputPath)%(ManagedBinary.Filename)$(IlcOutputFileExt)</OldObjectFileName>
<NewObjectFileName>$(NativeIntermediateOutputPath)%(ManagedBinary.Filename)$(IlcOutputFileExt)-singlethreaded</NewObjectFileName>
</PropertyGroup>

<ItemGroup>
<IlcArg Remove="-o:$(OldObjectFileName)" />
<IlcArg Include="-o:$(NewObjectFileName)" />
<IlcArg Include="--parallelism:1" />
</ItemGroup>

<WriteLinesToFile File="%(ManagedBinary.IlcRspFile)-singlethreaded" Lines="@(IlcArg)" Overwrite="true" WriteOnlyWhenDifferent="true" />

<Message Text="Compiling single-threaded baseline" Importance="High" />

<Exec Command="&quot;$(IlcToolsPath)\ilc&quot; @&quot;%(ManagedBinary.IlcRspFile)-singlethreaded&quot;"
EnvironmentVariables="$(_IlcEnvironmentVariables)" />

<Copy SourceFiles="$(OldObjectFileName)" DestinationFiles="$(OutDir)\baseline.object" />
<Copy SourceFiles="$(NewObjectFileName)" DestinationFiles="$(OutDir)\compare.object" />
</Target>
</Project>

0 comments on commit 54ef3eb

Please sign in to comment.