From 389e54f2af5714fd3fe7f37596f2fb1c4cf56872 Mon Sep 17 00:00:00 2001 From: NemesisDawn Date: Tue, 24 Nov 2026 22:46:02 +0300 Subject: [PATCH] Scripts: derive smoke timeout status from the child process Set the timeout flag on both wait outcomes so a caller's variable or strict mode does not change the report for a completed run. Assisted-by: OpenAI Codex (GPT-6, exact variant unavailable) --- scripts/smoke-exit.tests.ps1 | 58 ++++++++++++++++++++++++++++++++++++ scripts/smoke.ps1 | 6 ++-- 2 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 scripts/smoke-exit.tests.ps1 diff --git a/scripts/smoke-exit.tests.ps1 b/scripts/smoke-exit.tests.ps1 new file mode 100644 index 0000000000..17656a0705 --- /dev/null +++ b/scripts/smoke-exit.tests.ps1 @@ -0,0 +1,58 @@ +# Run with powershell.exe or pwsh.exe. Fake the child process to exercise both wait results. +param([string]$Smoke) +$ErrorActionPreference = 'Stop' +if (!$Smoke) { $Smoke = Join-Path $PSScriptRoot 'smoke.ps1' } +$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-smoke-exit-' + [guid]::NewGuid()) +$null = New-Item -ItemType Directory -Path $fixture +$log = Join-Path $fixture 'xcl.log' +$report = Join-Path $fixture 'report.json' +$oldNetwork = $env:XCL_NETWORK +$oldSeconds = $env:XCL_RUN_SECONDS +$oldActivity = $env:XCL_ACTIVITY + +function git { + if ($args[2] -eq 'rev-parse') { '1111111222222233333334444444555555566666' } +} + +function New-Object([string]$TypeName) { + if ($TypeName -eq 'System.Diagnostics.Process') { return $process } + Microsoft.PowerShell.Utility\New-Object -TypeName $TypeName @args +} + +function Assert-Exit([bool]$ExitedInTime, [string]$Expected) { + $process = [pscustomobject]@{ + StartInfo = $null + StandardOutput = [IO.StringReader]::new("Log: $log") + StandardError = [IO.StringReader]::new('') + ExitedInTime = $ExitedInTime + HasExited = $ExitedInTime + ExitCode = 0 + } + $process | Add-Member ScriptMethod Start { $true } + $process | Add-Member ScriptMethod WaitForExit { if ($args.Count) { $this.ExitedInTime } } + $process | Add-Member ScriptMethod Kill { $this.HasExited = $true } + + $output = & $Smoke -Game $fixture -Xcl $PSCommandPath + if (($output -split "\r?\n") -notcontains "exit: $Expected") { + throw "Expected exit: $Expected; smoke output: $output" + } + if (!$process.HasExited) { throw 'The timed-out child was not killed.' } +} + +try { + Set-Content -LiteralPath $log -Value '(7 frames shown, 7 PresentX calls)' -Encoding UTF8 + Set-Content -LiteralPath $report -Value '{"d3d12":{"adapter":"Test adapter"}}' -Encoding UTF8 + + Set-StrictMode -Version Latest + Assert-Exit $true '0x0' + $timedOut = $true + Assert-Exit $true '0x0' + Assert-Exit $false 'killed (no exit)' +} finally { + $env:XCL_NETWORK = $oldNetwork + $env:XCL_RUN_SECONDS = $oldSeconds + $env:XCL_ACTIVITY = $oldActivity + foreach ($path in $log, $report, $fixture) { + if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path } + } +} diff --git a/scripts/smoke.ps1 b/scripts/smoke.ps1 index f0738cdb98..2485e7a78a 100644 --- a/scripts/smoke.ps1 +++ b/scripts/smoke.ps1 @@ -37,10 +37,8 @@ $env:XCL_ACTIVITY = '1' $null = $p.Start() $stdoutTask = $p.StandardOutput.ReadToEndAsync() $stderrTask = $p.StandardError.ReadToEndAsync() -if (-not $p.WaitForExit(($Seconds + 120) * 1000)) { - if (-not $p.HasExited) { $p.Kill() } - $timedOut = $true -} +$timedOut = -not $p.WaitForExit(($Seconds + 120) * 1000) +if ($timedOut -and -not $p.HasExited) { $p.Kill() } $p.WaitForExit() $stdout = $stdoutTask.Result $null = $stderrTask.Result