Skip to content
Open
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
31 changes: 28 additions & 3 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>]
# .\scripts\smoke.ps1 -Game 'D:\Games\SomeTitle' [-Seconds 60] [-Xcl .\target\release\xcl.exe] [-Title <label>] [-OutDir <path>] [-Build debug|release]
#
# 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 @@ -14,7 +14,8 @@ param(
[int]$Seconds = 60,
[string]$Xcl = (Join-Path $PSScriptRoot '..\target\release\xcl.exe'),
[string]$Title,
[string]$OutDir
[string]$OutDir,
[string]$Build
)
$ErrorActionPreference = 'Stop'

Expand All @@ -29,7 +30,21 @@ if ($PSBoundParameters.ContainsKey('Title')) {
$Title = -join ($digest[0..3] | ForEach-Object { $_.ToString('x2') })
}

if ($PSBoundParameters.ContainsKey('Build')) {
$Build = $Build.Trim().ToLowerInvariant()
if ($Build -notin @('debug', 'release')) { throw "-Build must be 'debug' or 'release'" }
}

if (-not (Test-Path $Xcl)) { throw "no $Xcl - build it first (cargo build --release -p xcl)" }
if (-not $Build) {
$resolvedXcl = (Resolve-Path -LiteralPath $Xcl).Path
$parentDir = (Split-Path -Leaf (Split-Path -Parent $resolvedXcl)).ToLowerInvariant()
if ($parentDir -in @('debug', 'release')) {
$Build = $parentDir
} else {
$Build = 'unknown'
}
}
$root = Split-Path $PSScriptRoot -Parent
$commit = (git -C $root rev-parse HEAD).Trim()
$dirty = [bool](git -C $root status --porcelain --untracked-files=no -- crates Cargo.toml Cargo.lock)
Expand Down Expand Up @@ -82,12 +97,18 @@ $removals = ([regex]::Matches($text, 'device removed')).Count
$crashes = ([regex]::Matches($text, 'unhandled exception|process ends with status')).Count
# the adapter XCL ran on (report.json next to the log; XCL removes the last run's at start),
# not the first one Windows lists – on a machine with an iGPU that is often not the one used
$controllers = @()
try {
$controllers = @(Get-CimInstance Win32_VideoController -ErrorAction Stop | Where-Object { $_.Name -notmatch 'Basic' })
} catch { }
$gpu = $null
$report = Join-Path (Split-Path $log -Parent) 'report.json'
if (Test-Path $report) {
try { $gpu = ((Get-Content $report -Raw -Encoding utf8 | ConvertFrom-Json).d3d12.adapter -replace '\s*\([^()]*VRAM\)$', '') } catch { }
}
if (-not $gpu) { $gpu = (Get-CimInstance Win32_VideoController | Where-Object { $_.Name -notmatch 'Basic' } | Select-Object -First 1).Name }
if (-not $gpu -and $controllers.Count -gt 0) { $gpu = $controllers[0].Name }
$controller = if ($gpu) { $controllers | Where-Object { $_.Name -eq $gpu } | Select-Object -First 1 } else { $null }
$driver = if ($controller -and -not [string]::IsNullOrWhiteSpace($controller.DriverVersion)) { $controller.DriverVersion.Trim() } else { 'unknown' }
$code = if ($timedOut) { 'killed (no exit)' } else { '0x{0:x}' -f $p.ExitCode }

if ($OutDir) {
Expand All @@ -105,6 +126,8 @@ if ($OutDir) {
commit = $commit
dirty = $dirty
gpu = $gpu
driver = $driver
build = $Build
title = $Title
seconds = $Seconds
exit = $code
Expand All @@ -124,6 +147,8 @@ if ($OutDir) {
xcl-smoke v1
commit: $commit$(if ($dirty) { ' (uncommitted changes)' })
gpu: $gpu
driver: $driver
build: $Build
title: $Title
seconds: $Seconds
exit: $code
Expand Down
34 changes: 33 additions & 1 deletion scripts/test-smoke-artifacts.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ exit /b 0

$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.driver -ne 'unknown') { throw "unexpected driver: $($manifest1.driver)" }
if ($manifest1.build -ne 'unknown') { throw "unexpected build: $($manifest1.build)" }
if ($manifest1.seconds -ne 5) { throw "unexpected seconds: $($manifest1.seconds)" }
if ($manifest1.frames -ne '90 (PresentX 90)') { throw "unexpected frames: $($manifest1.frames)" }
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 -notmatch '(?m)^driver: unknown\r?$') { throw "smoke block missing driver: $smokeBlock" }
if ($smokeBlock -notmatch '(?m)^build: unknown\r?$') { throw "smoke block missing build: $smokeBlock" }

# Run 2: remove report.json to test missing report case; reuse $outDir1 to verify stale report.json is purged
Remove-Item -LiteralPath $mockReport -Force
$output2 = & $runner -Game $gameDir -Xcl $mockXcl -Seconds 10 -OutDir $outDir1 -Title 'MockRun2'
$output2 = & $runner -Game $gameDir -Xcl $mockXcl -Seconds 10 -Build Release -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' }
Expand All @@ -64,6 +68,34 @@ exit /b 0
$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)" }
if ($manifest2.build -ne 'release') { throw "unexpected explicit build: $($manifest2.build)" }
$expectedController = $null
try {
$expectedController = Get-CimInstance Win32_VideoController -ErrorAction Stop | Where-Object { $_.Name -notmatch 'Basic' } | Select-Object -First 1
} catch { }
$expectedDriver = if ($expectedController -and -not [string]::IsNullOrWhiteSpace($expectedController.DriverVersion)) { $expectedController.DriverVersion.Trim() } else { 'unknown' }
if ($manifest2.driver -ne $expectedDriver) { throw "unexpected fallback driver '$($manifest2.driver)', expected '$expectedDriver'" }

# Run 3: infer build profile from debug/release parent directory and reject invalid -Build values
foreach ($profile in @('debug', 'release')) {
$profileDir = Join-Path $fixture $profile
$null = New-Item -ItemType Directory -Path $profileDir
$profileXcl = Join-Path $profileDir 'xcl.cmd'
Copy-Item -LiteralPath $mockXcl -Destination $profileXcl -Force
$inferredBlock = (& $runner -Game $gameDir -Xcl $profileXcl -Seconds 1 -Title 'InferredBuild') -join "`n"
if ($inferredBlock -notmatch "(?m)^build: $profile\r?$") { throw "failed to infer build '$profile': $inferredBlock" }
}

$threw = $false
try { $null = & $runner -Game $gameDir -Xcl $mockXcl -Seconds 1 -Build 'invalid' } catch { $threw = $true }
if (-not $threw) { throw '-Build invalid was accepted' }

# Run 4: positional invocation preserves 5th slot for OutDir
$null = & $runner $gameDir 1 $mockXcl 'PositionalRun' $outDir2
if ($LASTEXITCODE -ne 0) { throw "smoke.ps1 exited with code $LASTEXITCODE on positional run" }
if (-not (Test-Path (Join-Path $outDir2 'manifest.json'))) { throw 'positional run did not write manifest.json in OutDir' }
$manifestPos = Get-Content (Join-Path $outDir2 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
if ($manifestPos.title -ne 'PositionalRun') { throw "unexpected positional title: $($manifestPos.title)" }

Write-Host "test-smoke-artifacts: all assertions passed successfully."
} finally {
Expand Down
Loading