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
46 changes: 46 additions & 0 deletions scripts/smoke-adapter.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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'

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

function Test-SmokeAdapter([string]$Expected) {
$block = & $Smoke -Game 'D:\Synthetic' -Seconds 2 -Xcl $xcl -Title 'fixture'
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'
}
}

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'
$cimMode = 'empty'
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 {
foreach ($path in $xcl,$log,$report) { [IO.File]::Delete($path) }
[IO.Directory]::Delete($fixture)
}
9 changes: 8 additions & 1 deletion scripts/smoke.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ $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 { $_.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 }

@"
Expand Down
Loading