Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ checked before anything else; a PR that does not meet them waits (or is closed a
no crash (the `main` run may: a PR that fixes a crash shows it there), at least 80 % of `main`'s
frames and at most 125 % of its peak commit. A run on a title that does not reach the code the PR
changes still counts as a regression check; say what it does not cover under **Not tested**.
Use `scripts/smoke.ps1 -Repeat 3` to collect three consecutive blocks from one build. Each
run uses the same title data directory. When `-OutDir` is supplied, the artifacts go into
numbered subdirectories such as `run-001`, with a separate manifest for each completed run.
Use a fresh `-OutDir` for each batch. An existing numbered destination stops the batch before
any title launches.
If a run errors before it can produce a block, the script saves an `error.txt` when
`-OutDir` is supplied, attempts the remaining runs, and reports the errors after the last run.
This collects blocks only: until #2268 lands, `pr_check.py` still compares the last clean
PR block with the first matching `main` block. Inspect every run when reporting results.
`scripts/pr_check.py` checks all of this (and the rest of this list it can see) on every PR.
If a test-only diff touches a runtime file, a maintainer can apply the `test-only` label after
reviewing the diff. The label event waives only the smoke check for that revision. Adding or
Expand Down
45 changes: 43 additions & 2 deletions scripts/smoke.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# prints an `xcl-smoke` block to paste into the PR's "Regression run" section – once built
# from main, once from the PR's head commit (CONTRIBUTING.md, "What a PR needs to be merged").
#
# .\scripts\smoke.ps1 -Game 'D:\Games\SomeTitle' [-Seconds 60] [-Xcl .\target\release\xcl.exe] [-Title <label>] [-OutDir <path>] [-StartupTimeoutSeconds 120]
# .\scripts\smoke.ps1 -Game 'D:\Games\SomeTitle' [-Seconds 60] [-Xcl .\target\release\xcl.exe] [-Title <label>] [-OutDir <path>] [-StartupTimeoutSeconds 120] [-Repeat 1]
#
# The block's `title:` line is the first 8 hex digits of the SHA-256 of the game folder's name
# (trimmed, UTF-8), not the name itself, so PR descriptions do not name anyone's copy of a game (#677);
Expand All @@ -16,10 +16,51 @@ param(
[string]$Title,
[string]$OutDir,
# Additional time for launcher work such as shader preparation before the guest timer starts.
[ValidateRange(1,86400)][int]$StartupTimeoutSeconds = 120
[ValidateRange(1,86400)][int]$StartupTimeoutSeconds = 120,
[ValidateRange(1,2147483647)][int]$Repeat = 1
)
$ErrorActionPreference = 'Stop'

if ($Repeat -gt 1) {
if ($OutDir) {
for ($run = 1; $run -le $Repeat; $run++) {
$destination = Join-Path $OutDir ('run-{0:d3}' -f $run)
if (Test-Path -LiteralPath $destination) {
throw "Repeat output destination already exists: $destination. Use a fresh -OutDir for each batch."
}
}
}
$runArgs = @{} + $PSBoundParameters
$runArgs.Remove('Repeat')
$failures = [System.Collections.Generic.List[string]]::new()
for ($run = 1; $run -le $Repeat; $run++) {
$runName = 'run-{0:d3}' -f $run
$runDir = $null
try {
if ($OutDir) {
$runDir = Join-Path $OutDir $runName
$runArgs['OutDir'] = $runDir
}
& $PSCommandPath @runArgs
} catch {
$message = $_.Exception.Message
$failures.Add("$runName failed. $message")
if ($runDir) {
try {
$null = New-Item -ItemType Directory -Path $runDir -Force
Set-Content -LiteralPath (Join-Path $runDir 'error.txt') -Value $message -Encoding utf8
} catch {
$failures[$failures.Count - 1] += " Could not save the failure diagnostic. $($_.Exception.Message)"
}
}
}
}
if ($failures.Count) {
throw "$($failures.Count) of $Repeat smoke runs failed.`n$($failures -join "`n")"
}
return
}

if ($PSBoundParameters.ContainsKey('Title')) {
$Title = $Title.Trim()
# control, format and line/paragraph separator characters would split the line for pr_check.py
Expand Down
113 changes: 113 additions & 0 deletions scripts/test-smoke-repeat.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Run with powershell.exe or pwsh.exe.
$ErrorActionPreference = 'Stop'
$runner = Join-Path $PSScriptRoot 'smoke.ps1'
$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-smoke-repeat-' + [guid]::NewGuid())
$fixture = (New-Item -ItemType Directory -Path $fixture).FullName
$log = Join-Path $fixture 'source.log'
$launches = Join-Path $fixture 'launches.txt'
$mockXcl = Join-Path $fixture 'mock_xcl.cmd'
$artifacts = Join-Path $fixture 'artifacts'

try {
'(90 frames shown, 90 PresentX calls)' | Set-Content -LiteralPath $log -Encoding utf8
'{"d3d12": {"adapter": "Synthetic Adapter"}}' |
Set-Content -LiteralPath (Join-Path $fixture 'report.json') -Encoding utf8
@"
@echo off
echo launch>>"$launches"
echo Log: $log
exit /b 0
"@ | Set-Content -LiteralPath $mockXcl -Encoding Ascii

$output = & $runner -Game $fixture -Xcl $mockXcl -Seconds 5 -Title RepeatTest -OutDir $artifacts -Repeat 3
if (@(Get-Content -LiteralPath $launches).Count -ne 3) { throw 'Expected three independent launches.' }
if ([regex]::Matches(($output -join "`n"), '(?m)^xcl-smoke v1\r?$').Count -ne 3) {
throw 'Expected three complete smoke blocks.'
}
foreach ($run in 1..3) {
$dir = Join-Path $artifacts ('run-{0:d3}' -f $run)
$manifest = Get-Content -LiteralPath (Join-Path $dir 'manifest.json') -Raw | ConvertFrom-Json
if ($manifest.title -ne 'RepeatTest' -or $manifest.seconds -ne 5 -or $manifest.exit -ne '0x0') {
throw "Run $run did not preserve the requested title and duration."
}
foreach ($name in 'xcl.log', 'report.json') {
if (-not (Test-Path -LiteralPath (Join-Path $dir $name))) { throw "Run $run is missing $name." }
}
}
$manifestPaths = 1..3 | ForEach-Object { Join-Path $artifacts ('run-{0:d3}/manifest.json' -f $_) }
$before = Get-FileHash -LiteralPath $manifestPaths | Select-Object -ExpandProperty Hash
$reuseError = $null
try {
& $runner -Game $fixture -Xcl $mockXcl -Seconds 5 -Title OverwriteTest -OutDir $artifacts -Repeat 3 |
Out-Null
} catch {
$reuseError = $_.Exception.Message
}
if ($reuseError -notmatch 'run-001' -or $reuseError -notmatch 'fresh') {
throw "Expected repeat output directory reuse to fail. Got: $reuseError"
}
if (@(Get-Content -LiteralPath $launches).Count -ne 3) { throw 'Reuse must not start another launch.' }
$after = Get-FileHash -LiteralPath $manifestPaths | Select-Object -ExpandProperty Hash
if (Compare-Object $before $after -SyncWindow 0) { throw 'Reuse changed a previous manifest.' }

$partialArtifacts = Join-Path $fixture 'partial-artifacts'
$null = New-Item -ItemType Directory -Path (Join-Path $partialArtifacts 'run-002') -Force
$partialError = $null
try {
& $runner -Game $fixture -Xcl $mockXcl -Seconds 5 -Title RepeatTest -OutDir $partialArtifacts -Repeat 2 |
Out-Null
} catch {
$partialError = $_.Exception.Message
}
if ($partialError -notmatch 'run-002' -or @(Get-Content -LiteralPath $launches).Count -ne 3) {
throw 'A later occupied destination must stop the entire batch before launching.'
}

$launches = Join-Path $fixture 'mixed-launches.txt'
$firstRun = Join-Path $fixture 'first-run'
$secondRun = Join-Path $fixture 'second-run'
$mixedArtifacts = Join-Path $fixture 'mixed-artifacts'
@"
@echo off
echo launch>>"$launches"
if not exist "$firstRun" goto first
if not exist "$secondRun" goto second
echo Log: $log
exit /b 0
:first
type nul > "$firstRun"
echo Log: $log
exit /b 0
:second
type nul > "$secondRun"
exit /b 3
"@ | Set-Content -LiteralPath $mockXcl -Encoding Ascii

$blocks = [System.Collections.Generic.List[string]]::new()
$failure = $null
try {
& $runner -Game $fixture -Xcl $mockXcl -Seconds 5 -Title RepeatTest -OutDir $mixedArtifacts -Repeat 3 |
ForEach-Object { $blocks.Add($_) }
} catch {
$failure = $_.Exception.Message
}
if (@(Get-Content -LiteralPath $launches).Count -ne 3) { throw 'Expected all three launches after a failure.' }
if ([regex]::Matches(($blocks -join "`n"), '(?m)^xcl-smoke v1?$').Count -ne 2) {
throw 'Expected both successful runs to print smoke blocks.'
}
if ($failure -notmatch '1 of 3' -or $failure -notmatch 'run-002' -or $failure -notmatch 'no log path') {
throw "Expected an aggregate error naming the failed run. Got: $failure"
}
foreach ($run in 'run-001', 'run-003') {
$manifest = Get-Content -LiteralPath (Join-Path $mixedArtifacts "$run/manifest.json") -Raw | ConvertFrom-Json
if ($manifest.exit -ne '0x0') { throw "Missing successful manifest for $run." }
}
if ((Get-Content -LiteralPath (Join-Path $mixedArtifacts 'run-002/error.txt') -Raw) -notmatch 'no log path') {
throw 'Expected the failed run to retain its diagnostic.'
}
Write-Host 'smoke-repeat: ok'
} finally {
if ((Resolve-Path -LiteralPath $fixture).Path -eq $fixture) {
Remove-Item -LiteralPath $fixture -Recurse -Force
}
}
Expand Down
Loading