From 0980253c534c010f51eef57dba6a854eeb0ef26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Fri, 13 Nov 2026 22:49:28 -0500 Subject: [PATCH] Use MTP for tests --- global.json | 1 + make.ps1 | 95 +++++++++++-------- src/core/IronPython/IronPython.csproj | 2 +- tests/IronPython.Tests/Cases/CaseExecuter.cs | 1 - tests/IronPython.Tests/Cases/CaseGenerator.cs | 1 - .../IronPython.Tests/IronPython.Tests.csproj | 17 +++- tests/IronPython.Tests/Stress/Engine.cs | 1 - 7 files changed, 73 insertions(+), 45 deletions(-) create mode 100644 global.json diff --git a/global.json b/global.json new file mode 100644 index 000000000..7a61fa392 --- /dev/null +++ b/global.json @@ -0,0 +1 @@ +{ "test": { "runner": "Microsoft.Testing.Platform" } } diff --git a/make.ps1 b/make.ps1 index 81e983bc9..991865b3d 100755 --- a/make.ps1 +++ b/make.ps1 @@ -45,6 +45,9 @@ function GenerateRunSettings([String] $framework, [String] $platform, [String] $ # # # +# +# -1 +# # $dec = $doc.CreateXmlDeclaration("1.0","UTF-8",$null) @@ -80,6 +83,12 @@ function GenerateRunSettings([String] $framework, [String] $platform, [String] $ $testRunParameters.AppendChild($parameter) | Out-Null } + $nunit = $doc.CreateElement("NUnit") + $runSettings.AppendChild($nunit) | Out-Null + $verbosity = $doc.CreateElement("Verbosity") + $verbosity.InnerText = "-1" + $nunit.AppendChild($verbosity) | Out-Null + $doc.AppendChild($runSettings) | Out-Null $fileName = [System.IO.Path]::Combine($_BASEDIR, "tests", "IronPython.Tests", "runsettings.$framework.xml") @@ -113,6 +122,7 @@ function RunTestTasks($tasks) { } $testScript = { + [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false) & dotnet test $args # pass the status out in case of failure if($LastExitCode -ne 0) { @@ -123,46 +133,55 @@ function RunTestTasks($tasks) { # create initial jobs $bgJobs = @{} $nextJob = 0 - for ($i = 0; $i -lt $maxJobs; $i++) { - $j = Start-Job -ScriptBlock $testScript -ArgumentList $tasks[$nextJob].params - $bgJobs[$j] = $nextJob; - $nextJob += 1 - } - - $failedTests = @() - while ($bgJobs.values.Count -gt 0) { - $finished = Wait-Job -Any -Timeout 10 -Job @($bgJobs.keys) - - # redirect output - foreach ($j in $bgJobs.keys) { - Receive-Job $j | ForEach-Object { "$($tasks[$bgJobs.$j].name) $_" } + try { + for ($i = 0; $i -lt $maxJobs; $i++) { + $j = Start-Job -ScriptBlock $testScript -ArgumentList $tasks[$nextJob].params + $bgJobs[$j] = $nextJob; + $nextJob += 1 } - # clean up finished jobs and create new ones - if ($null -ne $finished) { - $testName = $tasks[$bgJobs.$finished].name - Write-Host - if ($finished.State -eq 'Failed') { - Write-Host -ForegroundColor Red "$testName failed" - $global:Result = $finished.ChildJobs[0].JobStateInfo.Reason.ErrorRecord.TargetObject - $failedTests += $testName - } else { - Write-Host "$testName succeeded" - } + $failedTests = @() + while ($bgJobs.values.Count -gt 0) { + $finished = Wait-Job -Any -Timeout 10 -Job @($bgJobs.keys) - $bgJobs.Remove($finished) - Remove-Job $finished - if ($nextJob -lt $tasks.Count) { - $j = Start-Job -ScriptBlock $testScript -ArgumentList $tasks[$nextJob].params - $bgJobs[$j] = $nextJob; - $nextJob += 1 + # redirect output + foreach ($j in $bgJobs.keys) { + Receive-Job $j | ForEach-Object { "$($tasks[$bgJobs.$j].name) $_" } } - Write-Host "$($bgJobs.Count) jobs running: $(($bgJobs.values | ForEach-Object {$tasks[$_].name}) -Join ", ")" - Write-Host "$($tasks.Count - $nextJob) jobs pending: $(($nextJob..$tasks.Count | ForEach-Object {$tasks[$_].name}) -Join ", ")" - if ($failedTests) { - Write-Host -ForegroundColor Red "$($failedTests.Count) jobs failed: $($failedTests -Join ", ")" + + # clean up finished jobs and create new ones + if ($null -ne $finished) { + $testName = $tasks[$bgJobs.$finished].name + Write-Host + if ($finished.State -eq 'Failed') { + Write-Host -ForegroundColor Red "$testName failed" + $global:Result = $finished.ChildJobs[0].JobStateInfo.Reason.ErrorRecord.TargetObject + $failedTests += $testName + } else { + Write-Host "$testName succeeded" + } + + $bgJobs.Remove($finished) + Remove-Job $finished + if ($nextJob -lt $tasks.Count) { + $j = Start-Job -ScriptBlock $testScript -ArgumentList $tasks[$nextJob].params + $bgJobs[$j] = $nextJob; + $nextJob += 1 + } + Write-Host "$($bgJobs.Count) jobs running: $(($bgJobs.values | ForEach-Object {$tasks[$_].name}) -Join ", ")" + Write-Host "$($tasks.Count - $nextJob) jobs pending: $(($nextJob..$tasks.Count | ForEach-Object {$tasks[$_].name}) -Join ", ")" + if ($failedTests) { + Write-Host -ForegroundColor Red "$($failedTests.Count) jobs failed: $($failedTests -Join ", ")" + } + Write-Host } - Write-Host + } + } finally { + # on Ctrl+C, the jobs and the test processes they started would otherwise keep running + if ($bgJobs.Count -gt 0) { + Write-Host -ForegroundColor Yellow "Stopping $($bgJobs.Count) running job(s)" + $bgJobs.Keys | Stop-Job + $bgJobs.Keys | Remove-Job } } } @@ -177,7 +196,7 @@ function Test([String] $target, [String] $configuration, [String[]] $frameworks, $runSettings = GenerateRunSettings $framework $platform $configuration $runIgnored function createTask($filtername, $filter) { - [Object[]] $args = @("$_BASEDIR/tests/IronPython.Tests/IronPython.Tests.csproj", '-f', "$framework", '-o', "$_BASEDIR/bin/$configuration/$framework", '-c', "$configuration", '--no-build', '-v', 'n', '-l', "trx;LogFileName=$filtername-$framework-$configuration-result.trx", '-s', "$runSettings", "--filter=$filter"); + [Object[]] $args = @('--project', "$_BASEDIR/tests/IronPython.Tests/IronPython.Tests.csproj", '-f', "$framework", '-c', "$configuration", '--no-build', '--output', 'Detailed', '--show-stdout', 'All', '--show-stderr', 'All', '--report-trx', '--report-trx-filename', "$filtername-$framework-$configuration-result.trx", '--results-directory', "$_BASEDIR/tests/IronPython.Tests/TestResults", '--settings', "$runSettings", '--filter', "$filter"); Write-Host "Enqueue [$framework $filtername]:" Write-Host "dotnet test $args" Write-Host @@ -196,9 +215,9 @@ function Test([String] $target, [String] $configuration, [String[]] $frameworks, "cpython" { $tasks += createTask "cpython" "TestCategory=CPython" } default { if ($filter.ToLower().StartsWith('ironpython')) { - $tasks += createTask "query" "TestCategory=IronPython&Name=$framework.$filter" + $tasks += createTask "query" "TestCategory=IronPython&Name=$framework.IronPython$($filter.Substring(10))" } elseif ($filter.ToLower().StartsWith('cpython')) { - $tasks += createTask "query" "TestCategory=CPython&Name=$framework.$filter" + $tasks += createTask "query" "TestCategory=CPython&Name=$framework.CPython$($filter.Substring(7))" } else { $tasks += createTask "query" $filter } diff --git a/src/core/IronPython/IronPython.csproj b/src/core/IronPython/IronPython.csproj index 11f2dbfae..a604c58c5 100644 --- a/src/core/IronPython/IronPython.csproj +++ b/src/core/IronPython/IronPython.csproj @@ -51,7 +51,7 @@ - + diff --git a/tests/IronPython.Tests/Cases/CaseExecuter.cs b/tests/IronPython.Tests/Cases/CaseExecuter.cs index 0cdfa1a09..a4503b880 100644 --- a/tests/IronPython.Tests/Cases/CaseExecuter.cs +++ b/tests/IronPython.Tests/Cases/CaseExecuter.cs @@ -14,7 +14,6 @@ using System.Text.RegularExpressions; using System.Threading; -using IronPython; using IronPython.Hosting; using IronPython.Runtime; using IronPython.Runtime.Exceptions; diff --git a/tests/IronPython.Tests/Cases/CaseGenerator.cs b/tests/IronPython.Tests/Cases/CaseGenerator.cs index b1f39575b..34efde17d 100644 --- a/tests/IronPython.Tests/Cases/CaseGenerator.cs +++ b/tests/IronPython.Tests/Cases/CaseGenerator.cs @@ -10,7 +10,6 @@ using System.IO; using System.Runtime.InteropServices; -using IronPython; using IronPythonTest.Util; using NUnit.Framework; diff --git a/tests/IronPython.Tests/IronPython.Tests.csproj b/tests/IronPython.Tests/IronPython.Tests.csproj index aca87003e..49fe1497a 100644 --- a/tests/IronPython.Tests/IronPython.Tests.csproj +++ b/tests/IronPython.Tests/IronPython.Tests.csproj @@ -3,6 +3,9 @@ net462;net8.0;net10.0 true + Exe + true + M:System.IO.Path.GetRelativePath(System.String, System.String); @@ -15,9 +18,11 @@ - - - + + + + + @@ -32,6 +37,12 @@ + + + mono + "$(TargetPath)" $(StartArguments) + + diff --git a/tests/IronPython.Tests/Stress/Engine.cs b/tests/IronPython.Tests/Stress/Engine.cs index be10df258..db9b2bfb7 100644 --- a/tests/IronPython.Tests/Stress/Engine.cs +++ b/tests/IronPython.Tests/Stress/Engine.cs @@ -8,7 +8,6 @@ using Microsoft.Scripting.Generation; using Microsoft.Scripting.Hosting; -using IronPython; using IronPython.Hosting; using NUnit.Framework;