From bc2af995f03c8110fd3b015ea857e24224d7ad0d Mon Sep 17 00:00:00 2001 From: michaelv Date: Fri, 13 Mar 2026 16:54:39 -0400 Subject: [PATCH] Fix racy mvid tests. `DeterministicMvidWorks`, `NewMvidWorks`, and `RetainMvid` were running as part of `All.CommandLineTests` and as part of their own `IndividualTests`. The individual test is going to use the same sandbox location as the `All.CommandLineTests` run uses. This means that the two tests can conflict. Which I suspect explains why our CI randomly hit the error below. Given that trimming these tests twice is wasteful. Let's update the individual test to run `Check`, giving the individual test the same coverage as when the test was running in `All.CommandsLineTests`. Then lets move the tests into an `Individual` folder so that they are not picked up by `All.CommandsLineTests`. Other tests in `IndividualTests` are following this pattern. ``` 1) Failed : Mono.Linker.Tests.TestCases.All.CommandLine.Mvid.DeterministicMvidWorks [19:40:23.176 Information] System.UnauthorizedAccessException : Access to the path 'test.exe' is denied. at System.IO.FileSystem.RemoveDirectoryRecursive(String fullPath, WIN32_FIND_DATA& findData, Boolean topLevel) at System.IO.FileSystem.RemoveDirectory(String fullPath, Boolean recursive) at Mono.Linker.Tests.Extensions.NPath.Delete(DeleteMode deleteMode) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 580 at Mono.Linker.Tests.Extensions.Extensions.Delete(IEnumerable`1 self) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 889 at Mono.Linker.Tests.Extensions.NPath.DeleteContents() in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 614 at Mono.Linker.Tests.TestCasesRunner.TestCaseSandbox..ctor(TestCase testCase, NPath rootTemporaryDirectory, String namePrefix) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Trimming.Tests.Shared\TestCaseSandbox.cs:line 45 at Mono.Linker.Tests.TestCasesRunner.TestRunner.Run(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Trimming.Tests.Shared\TestRunner.cs:line 35 at Mono.Linker.Tests.TestCases.All.Run(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\TestCases\TestSuites.cs:line 304 at Mono.Linker.Tests.TestCases.All.CommandLineTests(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\TestCases\TestSuites.cs:line 64 at InvokeStub_All.CommandLineTests(Object, Span`1) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 2) Failed : Mono.Linker.Tests.TestCases.All.CommandLine.Mvid.NewMvidWorks System.UnauthorizedAccessException : Access to the path 'test.exe' is denied. at System.IO.FileSystem.RemoveDirectoryRecursive(String fullPath, WIN32_FIND_DATA& findData, Boolean topLevel) at System.IO.FileSystem.RemoveDirectory(String fullPath, Boolean recursive) at Mono.Linker.Tests.Extensions.NPath.Delete(DeleteMode deleteMode) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 580 at Mono.Linker.Tests.Extensions.Extensions.Delete(IEnumerable`1 self) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 889 at Mono.Linker.Tests.Extensions.NPath.DeleteContents() in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 614 at Mono.Linker.Tests.TestCasesRunner.TestCaseSandbox..ctor(TestCase testCase, NPath rootTemporaryDirectory, String namePrefix) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Trimming.Tests.Shared\TestCaseSandbox.cs:line 45 at Mono.Linker.Tests.TestCasesRunner.TestRunner.Run(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Trimming.Tests.Shared\TestRunner.cs:line 35 at Mono.Linker.Tests.TestCases.All.Run(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\TestCases\TestSuites.cs:line 304 at Mono.Linker.Tests.TestCases.All.CommandLineTests(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\TestCases\TestSuites.cs:line 64 at InvokeStub_All.CommandLineTests(Object, Span`1) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 3) Failed : Mono.Linker.Tests.TestCases.All.CommandLine.Mvid.RetainMvid System.UnauthorizedAccessException : Access to the path 'test.exe' is denied. at System.IO.FileSystem.RemoveDirectoryRecursive(String fullPath, WIN32_FIND_DATA& findData, Boolean topLevel) at System.IO.FileSystem.RemoveDirectory(String fullPath, Boolean recursive) at Mono.Linker.Tests.Extensions.NPath.Delete(DeleteMode dele [19:40:23.177 Information] teMode) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 580 at Mono.Linker.Tests.Extensions.Extensions.Delete(IEnumerable`1 self) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 889 at Mono.Linker.Tests.Extensions.NPath.DeleteContents() in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\Extensions\NiceIO.cs:line 614 at Mono.Linker.Tests.TestCasesRunner.TestCaseSandbox..ctor(TestCase testCase, NPath rootTemporaryDirectory, String namePrefix) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Trimming.Tests.Shared\TestCaseSandbox.cs:line 45 at Mono.Linker.Tests.TestCasesRunner.TestRunner.Run(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Trimming.Tests.Shared\TestRunner.cs:line 35 at Mono.Linker.Tests.TestCases.All.Run(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\TestCases\TestSuites.cs:line 304 at Mono.Linker.Tests.TestCases.All.CommandLineTests(TestCase testCase) in C:\build\output\unity\il2cpp\external\runtime\src\tools\illink\test\Mono.Linker.Tests\TestCases\TestSuites.cs:line 64 at InvokeStub_All.CommandLineTests(Object, Span`1) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) ``` --- .../CommandLine.Mvid.IndividualTests.g.cs | 31 +++++++++++++++++++ .../CommandLine.MvidTests.g.cs | 18 ----------- .../DeterministicMvidWorks.cs | 2 +- .../Mvid/{ => Individual}/NewMvidWorks.cs | 2 +- .../Mvid/{ => Individual}/RetainMvid.cs | 2 +- .../TestCases/IndividualTests.cs | 9 ++++++ 6 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/CommandLine.Mvid.IndividualTests.g.cs rename src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/{ => Individual}/DeterministicMvidWorks.cs (85%) rename src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/{ => Individual}/NewMvidWorks.cs (84%) rename src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/{ => Individual}/RetainMvid.cs (84%) diff --git a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/CommandLine.Mvid.IndividualTests.g.cs b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/CommandLine.Mvid.IndividualTests.g.cs new file mode 100644 index 00000000000000..a377f9e0ebc383 --- /dev/null +++ b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/CommandLine.Mvid.IndividualTests.g.cs @@ -0,0 +1,31 @@ +using System; +using System.Threading.Tasks; +using Xunit; + +namespace ILLink.RoslynAnalyzer.Tests.CommandLine.Mvid +{ + public sealed partial class IndividualTests : LinkerTestBase + { + + protected override string TestSuiteName => "CommandLine.Mvid.Individual"; + + [Fact] + public Task DeterministicMvidWorks() + { + return RunTest(allowMissingWarnings: true); + } + + [Fact] + public Task NewMvidWorks() + { + return RunTest(allowMissingWarnings: true); + } + + [Fact] + public Task RetainMvid() + { + return RunTest(allowMissingWarnings: true); + } + + } +} diff --git a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/CommandLine.MvidTests.g.cs b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/CommandLine.MvidTests.g.cs index 2b5dfbefe86d09..11f4d15ae3fb00 100644 --- a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/CommandLine.MvidTests.g.cs +++ b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/CommandLine.MvidTests.g.cs @@ -15,23 +15,5 @@ public Task DefaultMvidBehavior() return RunTest(allowMissingWarnings: true); } - [Fact] - public Task DeterministicMvidWorks() - { - return RunTest(allowMissingWarnings: true); - } - - [Fact] - public Task NewMvidWorks() - { - return RunTest(allowMissingWarnings: true); - } - - [Fact] - public Task RetainMvid() - { - return RunTest(allowMissingWarnings: true); - } - } } diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/DeterministicMvidWorks.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/DeterministicMvidWorks.cs similarity index 85% rename from src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/DeterministicMvidWorks.cs rename to src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/DeterministicMvidWorks.cs index ff6f678b5aa27b..0a44a3caee10ac 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/DeterministicMvidWorks.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/DeterministicMvidWorks.cs @@ -1,7 +1,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; -namespace Mono.Linker.Tests.Cases.CommandLine.Mvid +namespace Mono.Linker.Tests.Cases.CommandLine.Mvid.Individual { [SetupLinkerArgument("--deterministic", "true")] public class DeterministicMvidWorks diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/NewMvidWorks.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/NewMvidWorks.cs similarity index 84% rename from src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/NewMvidWorks.cs rename to src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/NewMvidWorks.cs index ed0049e7005339..59b44cdfc7c344 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/NewMvidWorks.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/NewMvidWorks.cs @@ -1,7 +1,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; -namespace Mono.Linker.Tests.Cases.CommandLine.Mvid +namespace Mono.Linker.Tests.Cases.CommandLine.Mvid.Individual { [SetupLinkerArgument("--new-mvid", "true")] public class NewMvidWorks diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/RetainMvid.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/RetainMvid.cs similarity index 84% rename from src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/RetainMvid.cs rename to src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/RetainMvid.cs index a78c8dc9ae6629..36d09393cdfc48 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/RetainMvid.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/CommandLine/Mvid/Individual/RetainMvid.cs @@ -1,7 +1,7 @@ using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; -namespace Mono.Linker.Tests.Cases.CommandLine.Mvid +namespace Mono.Linker.Tests.Cases.CommandLine.Mvid.Individual { [SetupLinkerArgument("--new-mvid", "false")] public class RetainMvid diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs index e919363365a279..7ab1fb7522446e 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs @@ -9,6 +9,7 @@ using System.Xml; using Mono.Cecil; using Mono.Linker.Tests.Cases.CommandLine.Mvid; +using Mono.Linker.Tests.Cases.CommandLine.Mvid.Individual; using Mono.Linker.Tests.Cases.Interop.PInvoke.Individual; using Mono.Linker.Tests.Cases.References.Individual; using Mono.Linker.Tests.Cases.Tracing.Individual; @@ -199,6 +200,7 @@ public void DeterministicMvidWorks() { var testCase = CreateIndividualCase(typeof(DeterministicMvidWorks)); var result = Run(testCase, out TestRunner runner); + Check(result); var originalMvid = GetMvid(result.InputAssemblyPath); var firstOutputMvid = GetMvid(result.OutputAssemblyPath); @@ -217,6 +219,7 @@ public void NewMvidWorks() { var testCase = CreateIndividualCase(typeof(NewMvidWorks)); var result = Run(testCase, out TestRunner runner); + Check(result); var originalMvid = GetMvid(result.InputAssemblyPath); var firstOutputMvid = GetMvid(result.OutputAssemblyPath); @@ -234,6 +237,7 @@ public void RetainMvidWorks() { var testCase = CreateIndividualCase(typeof(RetainMvid)); var result = Run(testCase, out TestRunner runner); + Check(result); var originalMvid = GetMvid(result.InputAssemblyPath); var firstOutputMvid = GetMvid(result.OutputAssemblyPath); @@ -269,5 +273,10 @@ protected virtual TrimmedTestCaseResult Run(TestCase testCase, out TestRunner ru runner = new TestRunner(new ObjectFactory()); return runner.Run(testCase); } + + protected virtual void Check(TrimmedTestCaseResult linkedResult) + { + new ResultChecker().Check(linkedResult); + } } }