diff --git a/scripts/smoke.ps1 b/scripts/smoke.ps1 index db296218b2..ed6c5d7c7b 100644 --- a/scripts/smoke.ps1 +++ b/scripts/smoke.ps1 @@ -9,6 +9,15 @@ # -Title prints the given label instead. Use the same one for the main and the PR run. # # Networking is off (XCL_NETWORK=0). Build first: cargo build --release -p xcl + +<# +.PARAMETER OutDir +Saves stdout.txt and stderr.txt, replacing both after each launcher run. Use a +fresh directory for each run. If the launcher exits before printing a log path, +a reused directory can still contain manifest.json, xcl.log and report.json +from the previous run. Check for script errors and verify the launcher exit +code in the current xcl-smoke block before using the artifacts. +#> param( [Parameter(Mandatory = $true)][string]$Game, [int]$Seconds = 60, @@ -65,9 +74,17 @@ if (-not $p.WaitForExit(($Seconds + 120) * 1000)) { } $p.WaitForExit() $stdout = $stdoutTask.Result -$null = $stderrTask.Result +$stderr = $stderrTask.Result Remove-Item Env:XCL_RUN_SECONDS, Env:XCL_ACTIVITY +if ($OutDir) { + if (-not (Test-Path $OutDir)) { + $null = New-Item -ItemType Directory -Path $OutDir -Force + } + Set-Content -LiteralPath (Join-Path $OutDir 'stdout.txt') -Value $stdout -Encoding utf8 -NoNewline + Set-Content -LiteralPath (Join-Path $OutDir 'stderr.txt') -Value $stderr -Encoding utf8 -NoNewline +} + $logLine = ($stdout -split "`n" | Where-Object { $_ -match '^Log:\s+(.+)$' } | Select-Object -Last 1) if (-not $logLine) { throw "XCL printed no log path; its output:`n$stdout" } $log = ($logLine -replace '^Log:\s+', '').Trim() @@ -91,9 +108,6 @@ if (-not $gpu) { $gpu = (Get-CimInstance Win32_VideoController | Where-Object { $code = if ($timedOut) { 'killed (no exit)' } else { '0x{0:x}' -f $p.ExitCode } if ($OutDir) { - if (-not (Test-Path $OutDir)) { - $null = New-Item -ItemType Directory -Path $OutDir -Force - } Copy-Item -LiteralPath $log -Destination (Join-Path $OutDir 'xcl.log') -Force $destReport = Join-Path $OutDir 'report.json' if (Test-Path $report) { diff --git a/scripts/test-smoke-artifacts.tests.ps1 b/scripts/test-smoke-artifacts.tests.ps1 index 399a29602b..37181474a4 100644 --- a/scripts/test-smoke-artifacts.tests.ps1 +++ b/scripts/test-smoke-artifacts.tests.ps1 @@ -26,12 +26,13 @@ try { '{"d3d12": {"adapter": "Mock Synthetic Adapter (16384 MB VRAM)"}}' | Set-Content -LiteralPath $mockReport -Encoding utf8 - # Mock XCL script outputs Log: path + # A failed launcher can still print a usable Log: path. @" @echo off -echo Running mock game... +echo First launch echo Log: $mockLog -exit /b 0 +>&2 echo memory allocation of 18220 bytes failed +exit /b 37 "@ | Set-Content -LiteralPath $mockXcl -Encoding Ascii # Run 1: with report.json present @@ -41,30 +42,70 @@ exit /b 0 if (-not (Test-Path (Join-Path $outDir1 'xcl.log'))) { throw 'run 1 did not preserve xcl.log' } if (-not (Test-Path (Join-Path $outDir1 'report.json'))) { throw 'run 1 did not preserve report.json' } if (-not (Test-Path (Join-Path $outDir1 'manifest.json'))) { throw 'run 1 did not write manifest.json' } + $stdoutPath = Join-Path $outDir1 'stdout.txt' + $stderrPath = Join-Path $outDir1 'stderr.txt' + if (-not (Test-Path -LiteralPath $stderrPath)) { throw 'run 1 did not preserve launcher stderr' } + if (-not (Test-Path -LiteralPath $stdoutPath)) { throw 'run 1 did not preserve launcher stdout' } + $savedStdout = Get-Content -LiteralPath $stdoutPath -Encoding utf8 + $savedStderr = Get-Content -LiteralPath $stderrPath -Encoding utf8 + if (($savedStdout -join "`n") -ne "First launch`nLog: $mockLog") { throw 'run 1 saved the wrong stdout' } + if (($savedStderr -join "`n") -ne 'memory allocation of 18220 bytes failed') { throw 'run 1 lost the allocator diagnostic' } $manifest1 = Get-Content (Join-Path $outDir1 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json if ($manifest1.gpu -ne 'Mock Synthetic Adapter') { throw "unexpected gpu: $($manifest1.gpu)" } if ($manifest1.seconds -ne 5) { throw "unexpected seconds: $($manifest1.seconds)" } if ($manifest1.frames -ne '90 (PresentX 90)') { throw "unexpected frames: $($manifest1.frames)" } + if ($manifest1.exit -ne '0x25') { throw "unexpected exit: $($manifest1.exit)" } if ($manifest1.title -ne 'MockRun1') { throw "unexpected title: $($manifest1.title)" } $smokeBlock = $output1 -join "`n" if ($smokeBlock -notmatch 'xcl-smoke v1') { throw "smoke block missing header: $smokeBlock" } if ($smokeBlock -notmatch 'gpu: Mock Synthetic Adapter') { throw "smoke block missing mock gpu: $smokeBlock" } + if ($smokeBlock -match 'memory allocation of') { throw 'run 1 leaked stderr into the smoke block' } # Run 2: remove report.json to test missing report case; reuse $outDir1 to verify stale report.json is purged Remove-Item -LiteralPath $mockReport -Force + @" +@echo off +echo Second launch +echo Log: $mockLog +exit /b 0 +"@ | Set-Content -LiteralPath $mockXcl -Encoding Ascii $output2 = & $runner -Game $gameDir -Xcl $mockXcl -Seconds 10 -OutDir $outDir1 -Title 'MockRun2' if ($LASTEXITCODE -ne 0) { throw "smoke.ps1 exited with code $LASTEXITCODE on run 2" } if (-not (Test-Path (Join-Path $outDir1 'xcl.log'))) { throw 'run 2 did not preserve xcl.log' } if (Test-Path (Join-Path $outDir1 'report.json')) { throw 'run 2 did not clean up stale report.json' } if (-not (Test-Path (Join-Path $outDir1 'manifest.json'))) { throw 'run 2 did not write manifest.json' } + $savedStdout = Get-Content -LiteralPath $stdoutPath -Encoding utf8 + $savedStderr = Get-Content -LiteralPath $stderrPath -Raw -Encoding utf8 + if (($savedStdout -join "`n") -ne "Second launch`nLog: $mockLog") { throw 'run 2 kept stale stdout' } + if ($savedStderr) { throw 'run 2 kept stale stderr' } $manifest2 = Get-Content (Join-Path $outDir1 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json if ($manifest2.seconds -ne 10) { throw "unexpected seconds: $($manifest2.seconds)" } if ($manifest2.title -ne 'MockRun2') { throw "unexpected title: $($manifest2.title)" } + # Run 3: an early launcher failure still leaves its streams even without a Log: line. + @" +@echo off +echo Third launch +>&2 echo failed to start the game process +exit /b 2 +"@ | Set-Content -LiteralPath $mockXcl -Encoding Ascii + + $failure = $null + try { + $null = & $runner -Game $gameDir -Xcl $mockXcl -Seconds 10 -OutDir $outDir1 -Title 'MockRun3' + } catch { + $failure = $_.Exception.Message + } + if ($failure -notmatch '^XCL printed no log path') { throw "unexpected run 3 error: $failure" } + $savedStdout = Get-Content -LiteralPath $stdoutPath -Encoding utf8 + $savedStderr = Get-Content -LiteralPath $stderrPath -Encoding utf8 + if (($savedStdout -join "`n") -ne 'Third launch') { throw 'run 3 lost stdout without a log path' } + if (($savedStderr -join "`n") -ne 'failed to start the game process') { throw 'run 3 lost stderr without a log path' } + Write-Host "test-smoke-artifacts: all assertions passed successfully." } finally { if (Test-Path -LiteralPath $fixture) {