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
68 changes: 68 additions & 0 deletions scripts/smoke-adapter.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Run in PowerShell 5.1 or 7. Simulate a test run on a machine without access to CIM.
param([string]$Smoke = (Join-Path $PSScriptRoot 'smoke.ps1'))
$ErrorActionPreference = 'Stop'
$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-smoke-adapter-' + [guid]::NewGuid())
$null = New-Item -ItemType Directory -Path $fixture
$xcl = Join-Path $fixture 'xcl.cmd'
$log = Join-Path $fixture 'xcl.log'
$report = Join-Path $fixture 'report.json'
$artifacts = Join-Path $fixture 'artifacts'

function Get-CimInstance {
[CmdletBinding()]
param([Parameter(Position = 0)][string]$ClassName)
if ($cimMode -eq 'unavailable') { throw 'Fixture: CIM is unavailable' }
if ($cimMode -eq 'empty') { return }
if ($cimMode -eq 'available') {
[pscustomobject]@{ Name = $null }
[pscustomobject]@{ Name = ' ' }
}
[pscustomobject]@{ Name = 'Microsoft Basic Display Adapter' }
if ($cimMode -eq 'available') { [pscustomobject]@{ Name = 'Fixture Controller' } }
}

function Test-SmokeAdapter([string]$Expected, [switch]$SaveArtifacts) {
$options = @{}
if ($SaveArtifacts) { $options.OutDir = $artifacts }
$block = & $Smoke -Game 'D:\Synthetic' -Seconds 2 -Xcl $xcl -Title 'fixture' @options
if ($block -notmatch ('(?m)^gpu: ' + [regex]::Escape($Expected) + '\r?$')) {
throw "Smoke did not report '$Expected'"
}
if ($block -notmatch '(?m)^device removals: 1\r?$' -or $block -notmatch '(?m)^crashes: 1\r?$' -or
$block -notmatch '(?m)^peak commit: 512 MB\r?$') {
throw 'Smoke lost the failure or memory diagnostics'
}
if ($SaveArtifacts) {
$manifest = Get-Content -LiteralPath (Join-Path $artifacts 'manifest.json') -Raw -Encoding utf8 | ConvertFrom-Json
if ($manifest.gpu -ne $Expected -or $manifest.removals -ne 1 -or $manifest.crashes -ne 1 -or
$manifest.peak_commit_mb -ne 512 -or -not (Test-Path -LiteralPath (Join-Path $artifacts 'xcl.log'))) {
throw 'Smoke lost the failure diagnostics in the saved artifacts'
}
}
}

try {
[IO.File]::WriteAllText($xcl, "@echo off`r`necho Log: %~dp0xcl.log`r`n")
[IO.File]::WriteAllLines($log, @('memory: 512 MB committed', 'device removed', 'unhandled exception'))

$cimMode = 'unavailable'
Test-SmokeAdapter 'unknown' -SaveArtifacts
$cimMode = 'empty'
Test-SmokeAdapter 'unknown'
$cimMode = 'basic'
Test-SmokeAdapter 'unknown'
$cimMode = 'available'
Test-SmokeAdapter 'Fixture Controller'

[IO.File]::WriteAllText($report, '{"d3d12":{"adapter":"Report GPU (4096 MiB VRAM)"}}')
Test-SmokeAdapter 'Report GPU'
'smoke-adapter: ok'
} finally {
if (Test-Path -LiteralPath $artifacts) {
[IO.File]::Delete((Join-Path $artifacts 'manifest.json'))
[IO.File]::Delete((Join-Path $artifacts 'xcl.log'))
[IO.Directory]::Delete($artifacts)
}
foreach ($path in $xcl,$log,$report) { [IO.File]::Delete($path) }
[IO.Directory]::Delete($fixture)
}
11 changes: 10 additions & 1 deletion scripts/smoke.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ $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) {
try {
$gpu = (Get-CimInstance Win32_VideoController -ErrorAction Stop |
Where-Object { -not [string]::IsNullOrWhiteSpace($_.Name) -and $_.Name -notmatch 'Basic' } |
Select-Object -First 1).Name
} catch {
# A run can lack a report, and CIM can be unavailable. Keep the crash summary.
}
}
if (-not $gpu) { $gpu = 'unknown' }
$code = if ($timedOut) { 'killed (no exit)' } else { '0x{0:x}' -f $p.ExitCode }

if ($OutDir) {
Expand Down
Loading