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
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,47 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder

</details>

## Reproduce a world-entry smoke run

Use the same local game copy and a checkpoint of its XCL data root for both builds. The checkpoint
should contain the title's save data and settings. Choose an input schedule that reaches the intended
scene on your copy. Time alone and a count of presented frames cannot identify that scene.

Build `xcl` from each checkout before running its copy of the script. Use a new trial directory for
each checkout and keep both the trials and artifacts outside the repository. This example shows the
two runs for `main`. Repeat from the PR checkout with a different `$trial` and the same game, duration,
label and input schedule.

```powershell
cargo build --release -p xcl
$game = 'D:\Games\MyTitle'
$checkpoint = 'D:\XCL\saved-checkpoint'
$trial = Join-Path $env:LOCALAPPDATA 'XCLWorldRuns\main'
$artifacts = Join-Path $env:LOCALAPPDATA 'XCLWorldRuns\artifacts'
New-Item -ItemType Directory -Path $trial | Out-Null # use a directory that does not exist yet
$env:XCL_PRESS_AT = '14:A,18.5:DOWN,20:A' # replace with your title's schedule
$env:XCL_DXIL_CACHE = Join-Path $trial 'dxil'
Remove-Item Env:XCL_PRESS_A_AT -ErrorAction SilentlyContinue
$options = @{ Game = $game; Seconds = 180; Title = 'world-entry'; ArtifactsDir = $artifacts }

$env:XCL_DATA_ROOT = Join-Path $trial 'first-data'
Copy-Item -LiteralPath $checkpoint -Destination $env:XCL_DATA_ROOT -Recurse
.\scripts\smoke.ps1 @options -CacheState fresh

$env:XCL_DATA_ROOT = Join-Path $trial 'second-data'
Copy-Item -LiteralPath $checkpoint -Destination $env:XCL_DATA_ROOT -Recurse
.\scripts\smoke.ps1 @options -CacheState seeded
```

The second run reuses the first run's XCL DXIL and pipeline cache and starts from a fresh checkpoint
copy. `-CacheState` labels the run in its manifest. The script does not clear caches or reset the GPU
driver's system cache. Each invocation creates a separate artifacts subdirectory with `xcl.log`,
`report.json` if produced, and `manifest.json` with build, GPU, input and cache settings. The
`xcl-smoke v1` block remains the output for the PR. Keep the saved run artifacts local.

Use a separate capture run with the same checkpoint and inputs to record the last scene you can
visually confirm. If you use `XCL_FRAME_DUMP`, keep it disabled for the four timed runs.

## Tests

```powershell
Expand Down
75 changes: 75 additions & 0 deletions scripts/smoke-artifacts.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Run with powershell.exe or pwsh.exe. The launcher fixture produces local smoke logs.
$ErrorActionPreference = 'Stop'
$smoke = Join-Path $PSScriptRoot 'smoke.ps1'
$temp = (Resolve-Path -LiteralPath ([IO.Path]::GetTempPath())).Path.TrimEnd([IO.Path]::DirectorySeparatorChar)
$fixture = Join-Path $temp ('xcl-smoke-artifacts-' + [guid]::NewGuid())
$null = New-Item -ItemType Directory -Path $fixture

# Keep the no-report GPU fallback independent of which machine runs the test.
function Get-CimInstance {
[pscustomobject]@{ Name = 'Fixture fallback GPU' }
}

$envNames = @('XCL_PRESS_AT', 'XCL_DATA_ROOT', 'XCL_DXIL_CACHE', 'XCL_NETWORK')
$originalEnv = @{}
foreach ($name in $envNames) { $originalEnv[$name] = [Environment]::GetEnvironmentVariable($name) }

try {
$xcl = Join-Path $fixture 'xcl.cmd'
$log = Join-Path $fixture 'xcl.log'
$report = Join-Path $fixture 'report.json'
$artifacts = Join-Path $fixture 'artifacts'
[IO.File]::WriteAllText($xcl, "@echo off`r`necho Log: %~dp0xcl.log`r`n")
$firstLog = "(7 frames shown, 7 PresentX calls)`n"
$firstReport = '{"d3d12":{"adapter":"Fixture GPU (1 GB VRAM)"}}'
[IO.File]::WriteAllText($log, $firstLog)
[IO.File]::WriteAllText($report, $firstReport)
$env:XCL_PRESS_AT = '0.25:A,0.75:MENU'
$env:XCL_DATA_ROOT = Join-Path $fixture 'data'
$env:XCL_DXIL_CACHE = Join-Path $fixture 'dxil'
$common = @{ Game = 'D:\Games\Fixture'; Seconds = 1; Xcl = $xcl; Title = 'smoke fixture' }

$plain = & $smoke @common
$first = & $smoke @common -ArtifactsDir $artifacts -CacheState fresh
if ($first -cne $plain) { throw 'Saving artifacts changed the smoke block' }
$firstDir = Get-ChildItem -LiteralPath $artifacts -Directory
$firstManifest = Get-Content -LiteralPath (Join-Path $firstDir.FullName 'manifest.json') -Raw | ConvertFrom-Json
if ($firstManifest.gpu -ne 'Fixture GPU' -or $firstManifest.seconds -ne 1 -or
$firstManifest.title -ne 'smoke fixture' -or $firstManifest.commit -notmatch '^[0-9a-f]{40}$' -or
$firstManifest.input.press_at -ne $env:XCL_PRESS_AT -or $firstManifest.cache.state -ne 'fresh' -or
$firstManifest.cache.dxil_root -ne $env:XCL_DXIL_CACHE -or $firstManifest.data_root -ne $env:XCL_DATA_ROOT) {
throw 'The first manifest does not describe the run'
}

$secondLog = "(3 frames shown, 3 PresentX calls)`n"
[IO.File]::WriteAllText($log, $secondLog)
Remove-Item -LiteralPath $report
$second = & $smoke @common -ArtifactsDir $artifacts -CacheState seeded
if ($second -notmatch '(?m)^gpu: Fixture fallback GPU\r?$') { throw 'Missing-report fallback failed' }
$runs = @(Get-ChildItem -LiteralPath $artifacts -Directory)
if ($runs.Count -ne 2) { throw "Expected two artifact directories, found $($runs.Count)" }
$secondDir = $runs | Where-Object FullName -ne $firstDir.FullName
$secondManifest = Get-Content -LiteralPath (Join-Path $secondDir.FullName 'manifest.json') -Raw | ConvertFrom-Json
if ($secondManifest.cache.state -ne 'seeded' -or $secondManifest.report -ne $null -or
(Test-Path -LiteralPath (Join-Path $secondDir.FullName 'report.json'))) { throw 'The second run reused the earlier report' }
if ($firstManifest.report -ne 'report.json' -or
[IO.File]::ReadAllText((Join-Path $firstDir.FullName 'report.json')) -cne $firstReport -or
[IO.File]::ReadAllText((Join-Path $firstDir.FullName 'xcl.log')) -cne $firstLog -or
[IO.File]::ReadAllText((Join-Path $secondDir.FullName 'xcl.log')) -cne $secondLog) {
throw 'The preserved logs or report do not match their invocations'
}
$rejected = $false
try {
& $smoke @common -ArtifactsDir (Join-Path $PSScriptRoot '.') | Out-Null
} catch {
if ($_.Exception.Message -notmatch 'outside the XCL checkout') { throw }
$rejected = $true
}
if (-not $rejected) { throw 'An artifacts directory inside the checkout was accepted' }
'smoke-artifacts: ok'
} finally {
foreach ($name in $envNames) { [Environment]::SetEnvironmentVariable($name, $originalEnv[$name]) }
$resolvedFixture = (Resolve-Path -LiteralPath $fixture).Path
if ((Split-Path -Parent $resolvedFixture) -ne $temp) { throw 'Unexpected fixture location' }
Remove-Item -LiteralPath $resolvedFixture -Recurse -Force
}
60 changes: 55 additions & 5 deletions scripts/smoke.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
# 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);
# -Title prints the given label instead. Use the same one for the main and the PR run.
# -ArtifactsDir preserves each run's log, report and manifest in a new local directory.
#
# Networking is off (XCL_NETWORK=0). Build first: cargo build --release -p xcl
param(
[Parameter(Mandatory = $true)][string]$Game,
[int]$Seconds = 60,
[string]$Xcl = (Join-Path $PSScriptRoot '..\target\release\xcl.exe'),
[string]$Title
[string]$Title,
[ValidateNotNullOrEmpty()][string]$ArtifactsDir,
[ValidateSet('fresh', 'seeded', 'unspecified')][string]$CacheState = 'unspecified'
)
$ErrorActionPreference = 'Stop'

Expand All @@ -32,6 +35,14 @@ if (-not (Test-Path $Xcl)) { throw "no $Xcl - build it first (cargo build --rele
$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)
if ($ArtifactsDir) {
$ArtifactsDir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ArtifactsDir)
$rootPrefix = $root.TrimEnd('\', '/') + [IO.Path]::DirectorySeparatorChar
$destination = $ArtifactsDir.TrimEnd('\', '/') + [IO.Path]::DirectorySeparatorChar
if ($destination.StartsWith($rootPrefix, [StringComparison]::OrdinalIgnoreCase)) {
throw '-ArtifactsDir must be outside the XCL checkout'
}
}

# Use ProcessStartInfo instead of Start-Process: the latter cannot build its
# environment block on Windows PowerShell 5.1 when PATH is present twice with
Expand All @@ -50,6 +61,7 @@ $p.StartInfo = $psi
$env:XCL_NETWORK = '0'
$env:XCL_RUN_SECONDS = "$Seconds"
$env:XCL_ACTIVITY = '1'
$started = [DateTime]::UtcNow
$null = $p.Start()
$stdoutTask = $p.StandardOutput.ReadToEndAsync()
$stderrTask = $p.StandardError.ReadToEndAsync()
Expand All @@ -65,7 +77,7 @@ Remove-Item Env:XCL_RUN_SECONDS, Env:XCL_ACTIVITY
$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()
$text = Get-Content $log -Raw -Encoding utf8
$text = Get-Content -LiteralPath $log -Raw -Encoding utf8

$frames = if ($text -match '\((\d+) frames shown, (\d+) PresentX calls\)') { "$($Matches[1]) (PresentX $($Matches[2]))" } else { 'none logged (the run did not reach its end)' }
$presents = [regex]::Matches($text, 'activity \(2 s\): (\d+) presents') | ForEach-Object { [int]$_.Groups[1].Value }
Expand All @@ -78,12 +90,50 @@ $crashes = ([regex]::Matches($text, 'unhandled exception|process ends with statu
# not the first one Windows lists – on a machine with an iGPU that is often not the one used
$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 { }
$hasReport = Test-Path -LiteralPath $report -PathType Leaf
if ($hasReport) {
try { $gpu = ((Get-Content -LiteralPath $report -Raw -Encoding utf8 | ConvertFrom-Json).d3d12.adapter -replace '\s*\([^()]*VRAM\)$', '') } catch { }
}
if (-not $gpu) {
try {
$gpu = (Get-CimInstance Win32_VideoController -ErrorAction Stop | Where-Object { $_.Name -notmatch 'Basic' } | Select-Object -First 1).Name
} catch { }
}
if (-not $gpu) { $gpu = (Get-CimInstance Win32_VideoController | Where-Object { $_.Name -notmatch 'Basic' } | Select-Object -First 1).Name }
$code = if ($timedOut) { 'killed (no exit)' } else { '0x{0:x}' -f $p.ExitCode }

if ($ArtifactsDir) {
$runName = $started.ToString('yyyyMMddTHHmmssZ') + '-' + [guid]::NewGuid().ToString('N')
$run = Join-Path $ArtifactsDir $runName
$null = [IO.Directory]::CreateDirectory($run)
Copy-Item -LiteralPath $log -Destination (Join-Path $run 'xcl.log')
if ($hasReport) { Copy-Item -LiteralPath $report -Destination (Join-Path $run 'report.json') }
$manifest = [ordered]@{
version = 1
started_utc = $started.ToString('o')
commit = $commit
dirty = $dirty
gpu = $gpu
title = $Title
seconds = $Seconds
exit = $code
log = 'xcl.log'
report = if ($hasReport) { 'report.json' } else { $null }
input = @{
press_at = $env:XCL_PRESS_AT
press_a_at = $env:XCL_PRESS_A_AT
}
data_root = if ($env:XCL_DATA_ROOT) { $env:XCL_DATA_ROOT } else { Join-Path $env:LOCALAPPDATA 'XCL' }
cache = @{
state = $CacheState
dxil_root = if ($env:XCL_DXIL_CACHE) { $env:XCL_DXIL_CACHE } else { Join-Path $env:LOCALAPPDATA 'xcl\dxil' }
translated = $env:XCL_TRANSLATED_CACHE
pso = $env:XCL_PSO_DISK_CACHE
}
}
[IO.File]::WriteAllText((Join-Path $run 'manifest.json'), ($manifest | ConvertTo-Json -Depth 4))
Write-Verbose "Saved smoke artifacts to $run"
}

@"
``````
xcl-smoke v1
Expand Down
Loading