From 54ef3eb3ceae91719330d052c502441994fde228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 17 Oct 2023 13:21:49 +0200 Subject: [PATCH 1/2] Add a test for determinism Resolves #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. --- .../SmokeTests/Determinism/Determinism.cs | 22 +++++++++++ .../SmokeTests/Determinism/Determinism.csproj | 37 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs create mode 100644 src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj diff --git a/src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs b/src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs new file mode 100644 index 0000000000000..8409645d31bc7 --- /dev/null +++ b/src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs @@ -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; diff --git a/src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj b/src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj new file mode 100644 index 0000000000000..725a7dff99fd6 --- /dev/null +++ b/src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj @@ -0,0 +1,37 @@ + + + Exe + 0 + true + + + + + + + + + $(NativeIntermediateOutputPath)%(ManagedBinary.Filename)$(IlcOutputFileExt) + $(NativeIntermediateOutputPath)%(ManagedBinary.Filename)$(IlcOutputFileExt)-singlethreaded + + + + + + + + + + + + + + + + + + From 561baefcb97ab1d2117481182d238df2846e83e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 19 Oct 2023 10:06:26 +0200 Subject: [PATCH 2/2] Call into the other test --- .../nativeaot/SmokeTests/Determinism/Determinism.cs | 12 +++++++++++- .../SmokeTests/Determinism/Determinism.csproj | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs b/src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs index 8409645d31bc7..bd2361ddf0e8b 100644 --- a/src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs +++ b/src/tests/nativeaot/SmokeTests/Determinism/Determinism.cs @@ -13,10 +13,20 @@ if (baseline.Length != compare.Length) throw new Exception("Different sizes"); -for (int i = 0; i < baseline.Length; i++) +long length = baseline.Length; +for (int i = 0; i < length; i++) { if (baseline.ReadByte() != compare.ReadByte()) throw new Exception($"Different at byte {i}"); } +// We're not interested in running this, we just want some junk to compile +if (Environment.GetEnvironmentVariable("Never") == "Ever") +{ + Delegates.Run(); + Devirtualization.Run(); + Generics.Run(); + Interfaces.Run(); +} + return 100; diff --git a/src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj b/src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj index 725a7dff99fd6..5601b0480c7ff 100644 --- a/src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj +++ b/src/tests/nativeaot/SmokeTests/Determinism/Determinism.csproj @@ -6,6 +6,11 @@ + + + + +