diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc905cb1bc..35e7ce4940 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,16 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Test log summaries (PowerShell 5.1 and 7) + shell: pwsh + run: | + foreach ($shell in 'powershell.exe', 'pwsh.exe') { + foreach ($test in 'test-native-stderr.tests.ps1', 'test-totals.tests.ps1', 'summarize-tests.tests.ps1') { + & $shell -NoProfile -ExecutionPolicy Bypass -File "scripts/$test" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + } + - name: Rust (stable, MSVC) run: | rustup toolchain install stable --profile minimal diff --git a/README.md b/README.md index d9d151320a..2f100e72dc 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,24 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder .\scripts\test.ps1 # cargo build --workspace + cargo test --workspace ``` +The script sums the reported passed, failed and ignored counts from completed test suites. +If a run stops early, these totals cover only the suites that printed a result; the script +preserves Cargo's exit code. A passed count can include tests that skipped their checks, +as described below. + +To summarize an existing test log without running tests again: + +```powershell +.\scripts\summarize-tests.ps1 -LiteralPath .\test.log +.\scripts\summarize-tests.ps1 -LiteralPath .\test.log -Json +``` + +The report lists completed-suite totals, `SKIPPED` records, explicitly named failed tests +and sample inputs reported as unset. UTF-8 and UTF-16 logs are supported. A successful +summary command means the log was read, not that the logged tests passed or that the +whole run finished. Concatenated runs are summed, not deduplicated. Logs with no completed +test-suite summaries are rejected. + Unit tests, an end-to-end test with our own "console title" (`tests/testtitle`) and GPU tests (D3D12, SM 6.6; skipped without a GPU / DXC; `XCL_ADAPTER=1` or `XCL_ADAPTER=radeon` picks another adapter than the first high-performance one, for titles too). A GPU test that cannot run on diff --git a/scripts/summarize-tests.ps1 b/scripts/summarize-tests.ps1 new file mode 100644 index 0000000000..9b40150163 --- /dev/null +++ b/scripts/summarize-tests.ps1 @@ -0,0 +1,68 @@ +# Summarize a saved Cargo/libtest log without running tests or modifying the log. +param( + [Parameter(Mandatory = $true, Position = 0)] + [string]$LiteralPath, + [switch]$Json +) +$ErrorActionPreference = 'Stop' +$file = Get-Item -LiteralPath $LiteralPath +if ($file.PSIsContainer) { throw 'Expected a test log file, not a directory.' } +$totals = @{ Passed = 0L; Failed = 0L; Ignored = 0L; Suites = 0; Started = 0 } +$skips = [Collections.Generic.List[object]]::new() +$failed = [Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal) +$missing = [Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal) +# StreamReader detects UTF-8 and UTF-16 BOMs, including Windows PowerShell logs. +$reader = [IO.StreamReader]::new($file.FullName) +try { + while ($null -ne ($line = $reader.ReadLine())) { + $line = $line -replace '\x1B\[[0-?]*[ -/]*[@-~]', '' + if ($line -match '^running \d+ tests?$') { $totals.Started++ } + if ($line -match '^test result: (?:ok|FAILED)\. (\d+) passed; (\d+) failed; (\d+) ignored;') { + $totals.Passed += [long]$Matches[1] + $totals.Failed += [long]$Matches[2] + $totals.Ignored += [long]$Matches[3] + $totals.Suites++ + } + if ($line -match '^(?:test \S+ \.\.\. )?SKIPPED (\S+): (.+)$') { + $skips.Add([pscustomobject]@{ Test = $Matches[1]; Reason = $Matches[2] }) + } + if ($line -match '^test (\S+) \.\.\. FAILED$') { $null = $failed.Add($Matches[1]) } + if ($line -match '^not set, their tests are skipped: (.+)$') { + foreach ($variable in [regex]::Matches($Matches[1], '\bXCL_SAMPLE_[A-Z0-9_]+\b')) { + $null = $missing.Add($variable.Value) + } + } + } +} finally { + $reader.Dispose() +} +if (!$totals.Suites) { throw 'No completed libtest summaries found; this is not evidence of a successful test run.' } +$notes = @( + 'Totals cover completed suites, not unique tests across repeated runs.', + 'Passed counts may include skipped checks. Skip records are reported separately, not subtracted.', + 'The original process exit code and whole-run completion cannot be established from these summaries.' +) +if ($totals.Started -gt $totals.Suites) { $notes += 'More suite starts than results were found; the log may be incomplete.' } +$report = [pscustomobject][ordered]@{ + source = $file.FullName + completed_suites = $totals.Suites + passed = $totals.Passed + failed = $totals.Failed + ignored = $totals.Ignored + skip_records = @($skips.ToArray()) + failed_tests = @($failed | Sort-Object) + missing_sample_inputs = @($missing | Sort-Object) + notes = $notes +} +if ($Json) { + $report | ConvertTo-Json -Depth 5 +} else { + "Source: $($report.source)" + "Completed test suites: $($report.completed_suites); reported totals: $($report.passed) passed, $($report.failed) failed, $($report.ignored) ignored." + "SKIPPED records: $($skips.Count) (absence of records does not prove that all checks ran)." + foreach ($skip in $skips) { " $($skip.Test): $($skip.Reason)" } + foreach ($test in $report.failed_tests) { "FAILED: $test" } + if ($missing.Count) { "Sample inputs not set: $($report.missing_sample_inputs -join ', ')" } + $notes +} +# Success means the log was summarized, not that the logged tests passed. diff --git a/scripts/summarize-tests.tests.ps1 b/scripts/summarize-tests.tests.ps1 new file mode 100644 index 0000000000..1da64c2f87 --- /dev/null +++ b/scripts/summarize-tests.tests.ps1 @@ -0,0 +1,65 @@ +# Run with powershell.exe or pwsh.exe; exercises the command as a separate process. +$ErrorActionPreference = 'Stop' +$script = Join-Path $PSScriptRoot 'summarize-tests.ps1' +$hostExe = (Get-Process -Id $PID).Path +$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-log-summary-' + [guid]::NewGuid()) +$null = New-Item -ItemType Directory -Path $fixture +$log = Join-Path $fixture 'test [1].log' + +function Read-Report($path, $expectFailure = $false) { + $ErrorActionPreference = 'Continue' + $output = & $hostExe -NoProfile -ExecutionPolicy Bypass -File $script -LiteralPath $path -Json 2>&1 + $code = $LASTEXITCODE + $ErrorActionPreference = 'Stop' + if ($expectFailure) { + if (!$code) { throw 'Expected a failing exit code for an unusable input.' } + } else { + if ($code) { throw "Summary failed: $output" } + ($output -join "`n") | ConvertFrom-Json + } +} +try { + $esc = [char]27 + $text = @" +not set, their tests are skipped: XCL_SAMPLE_RPF, XCL_SAMPLE_DLLS +running 4 tests +SKIPPED gpu_one: no wave64 +test gpu_two ... SKIPPED gpu_two: no mesh shaders +test failing_test ... FAILED +${esc}[31mtest result: FAILED. 2 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.01s${esc}[0m +running 3 tests +test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s +diagnostic: test result: ok. 999 passed; 0 failed; 0 ignored; +"@ + foreach ($encoding in @([Text.UTF8Encoding]::new($false), [Text.Encoding]::Unicode)) { + [IO.File]::WriteAllText($log, $text, $encoding) + $r = Read-Report $log + if ($r.completed_suites -ne 2 -or $r.passed -ne 5 -or $r.failed -ne 1 -or $r.ignored -ne 1) { + throw 'Incorrect totals or diagnostic text counted as a summary.' + } + if ($r.skip_records.Count -ne 2 -or $r.skip_records[1].Test -ne 'gpu_two') { throw 'Lost skip records.' } + if ($r.failed_tests.Count -ne 1 -or $r.failed_tests[0] -ne 'failing_test') { throw 'Lost failed test name.' } + if ($r.missing_sample_inputs.Count -ne 2) { throw 'Lost missing sample inputs.' } + if ($r.notes.Count -ne 3) { throw 'Missing limitations or false truncation warning.' } + Write-Host "PASS $($encoding.WebName), ANSI, literal path, skips and failures" + } + [IO.File]::WriteAllText($log, $text + "`nrunning 5 tests`n", [Text.Encoding]::UTF8) + $r = Read-Report $log + if ($r.completed_suites -ne 2 -or $r.notes[-1] -notlike '*incomplete*') { throw 'Missed incomplete suite.' } + Write-Host 'PASS incomplete log' + [IO.File]::WriteAllText($log, 'test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;', [Text.Encoding]::UTF8) + $r = Read-Report $log + if ($r.completed_suites -ne 1 -or $r.skip_records.Count -ne 0 -or $r.failed_tests.Count -ne 0) { throw 'Empty arrays or suite were lost.' } + Write-Host 'PASS empty completed suite' + [IO.File]::WriteAllText($log, 'running 3 tests', [Text.Encoding]::UTF8) + Read-Report $log $true + Write-Host 'PASS no completed summaries rejected' + Read-Report (Join-Path $fixture 'missing.log') $true + Write-Host 'PASS missing file rejected' + Read-Report $fixture $true + Write-Host 'PASS directory rejected' +} finally { + foreach ($path in $log, $fixture) { + if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path } + } +} diff --git a/scripts/test-totals.tests.ps1 b/scripts/test-totals.tests.ps1 new file mode 100644 index 0000000000..d6fd790873 --- /dev/null +++ b/scripts/test-totals.tests.ps1 @@ -0,0 +1,68 @@ +# Run with powershell.exe or pwsh.exe; no Rust toolchain or GPU is needed. +$ErrorActionPreference = 'Stop' +$runner = Join-Path $PSScriptRoot 'test.ps1' +$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-test-totals-' + [guid]::NewGuid()) +$null = New-Item -ItemType Directory -Path $fixture +$cargo = Join-Path $fixture 'cargo.cmd' +$inputLog = Join-Path $fixture 'input.txt' +$outputLog = Join-Path $fixture 'output.txt' +$oldPath = $env:PATH +Push-Location + +function Check-Run($name, $lines, $buildExit, $testExit, $summary, $skipSummary = '') { + $command = @" +@echo off +if "%1"=="build" exit /b $buildExit +if not "%1"=="test" exit /b 127 +echo forwarded: %* +type "%~dp0input.txt" +exit /b $testExit +"@ + [IO.File]::WriteAllText($cargo, $command, [Text.Encoding]::ASCII) + [IO.File]::WriteAllText($inputLog, ($lines -join "`r`n") + "`r`n", [Text.Encoding]::ASCII) + if ((Get-Command cargo).Path -ne $cargo) { throw 'The Cargo fixture was not selected.' } + & $runner --skip omitted *> $outputLog + $expectedExit = if ($buildExit) { $buildExit } else { $testExit } + if ($LASTEXITCODE -ne $expectedExit) { throw "${name}: expected exit $expectedExit, got $LASTEXITCODE" } + $output = Get-Content -LiteralPath $outputLog -Raw + $found = @($output -split '\r?\n' | Where-Object { $_ -like 'Completed test suites:*' }) + if ($summary) { + if ($found.Count -ne 1 -or $found[0] -ne $summary) { throw "${name}: incorrect summary: $($found -join ', ')" } + } elseif ($found.Count) { throw "${name}: invented totals without a completed suite" } + if ($skipSummary -and !$output.Contains($skipSummary)) { throw "${name}: lost the skip summary" } + if ($buildExit) { + if ($output.Contains('forwarded:')) { throw "${name}: ran tests after a failed build" } + } elseif (!$output.Contains('forwarded: test --workspace -- --test-threads=4 --skip omitted')) { + throw "${name}: changed the forwarded test arguments" + } + Write-Host "PASS $name" +} + +try { + $env:PATH = $fixture + Check-Run 'multiple suites and skips' @( + 'SKIPPED gpu_fixture: no wave64', + 'test result: ok. 5 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.01s', + 'diagnostic: test result: ok. 999 passed; 0 failed; 0 ignored;', + "$([char]27)[32mtest result: ok. 3 passed; 0 failed; 2 ignored; 0 measured; 5 filtered out; finished in 0.01s$([char]27)[0m" + ) 0 0 'Completed test suites: 2; reported totals: 8 passed, 0 failed, 3 ignored.' 'GPU tests skipped on this adapter: 1 (no wave64)' + Check-Run 'failed suite keeps the Cargo exit code' @( + 'test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s', + 'test result: FAILED. 4 passed; 1 failed; 2 ignored; 0 measured; 0 filtered out; finished in 0.01s' + ) 0 101 'Completed test suites: 2; reported totals: 6 passed, 1 failed, 2 ignored.' + Check-Run 'failure before any summary' @('running 3 tests', 'process aborted') 0 101 '' + Check-Run 'empty completed suite' @( + 'test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s' + ) 0 0 'Completed test suites: 1; reported totals: 0 passed, 0 failed, 0 ignored.' + Check-Run 'build failure does not run tests' @() 7 0 '' + Check-Run 'interrupted suite is not counted' @( + 'test result: ok. 2 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.01s', + 'running 5 tests', 'test unfinished ...' + ) 0 101 'Completed test suites: 1; reported totals: 2 passed, 0 failed, 1 ignored.' +} finally { + Pop-Location + $env:PATH = $oldPath + foreach ($path in $cargo, $inputLog, $outputLog, $fixture) { + if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path } + } +} diff --git a/scripts/test.ps1 b/scripts/test.ps1 index 8bf6dca1e7..1a58d74a68 100644 --- a/scripts/test.ps1 +++ b/scripts/test.ps1 @@ -13,12 +13,23 @@ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # GPU tests that cannot run on this adapter pass too: each prints "SKIPPED : " # to stderr (XCL_REQUIRE_GPU=wave64 / =mesh makes them fail); counted at the end $skipped = @() +$totals = @{ Passed = 0L; Failed = 0L; Ignored = 0L; Suites = 0 } cargo test --workspace -- --test-threads=4 @args 2>&1 | ForEach-Object { $line = "$_" - if ($line -match '^SKIPPED \S+: (.+)$') { $skipped += $Matches[1] } + $plain = $line -replace '\x1B\[[0-?]*[ -/]*[@-~]', '' + if ($plain -match '^SKIPPED \S+: (.+)$') { $skipped += $Matches[1] } + if ($plain -match '^test result: (?:ok|FAILED)\. (\d+) passed; (\d+) failed; (\d+) ignored;') { + $totals.Passed += [long]$Matches[1] + $totals.Failed += [long]$Matches[2] + $totals.Ignored += [long]$Matches[3] + $totals.Suites++ + } Write-Host $line } $code = $LASTEXITCODE +if ($totals.Suites) { + Write-Host "Completed test suites: $($totals.Suites); reported totals: $($totals.Passed) passed, $($totals.Failed) failed, $($totals.Ignored) ignored." +} if ($skipped) { $counts = $skipped | Group-Object | Sort-Object Count -Descending | ForEach-Object { "$($_.Count) ($($_.Name))" } Write-Host "GPU tests skipped on this adapter: $($counts -join ', ')"