diff --git a/scripts/smoke-log.tests.ps1 b/scripts/smoke-log.tests.ps1 new file mode 100644 index 0000000000..9ff3397b9e --- /dev/null +++ b/scripts/smoke-log.tests.ps1 @@ -0,0 +1,40 @@ +$ErrorActionPreference = 'Stop' +$smoke = Join-Path $PSScriptRoot 'smoke.ps1' +$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-smoke-log-' + [guid]::NewGuid()) +$null = New-Item -ItemType Directory -Path $fixture +$log = Join-Path $fixture 'run.log' +$run = Join-Path $fixture 'run.txt' +$report = Join-Path $fixture 'report.json' +Push-Location -LiteralPath $fixture +try { + # findstr acts as the launcher. It prints the Log: line containing "run" from the fixture. + 'Log: .\run.log' | Set-Content -LiteralPath $run -Encoding Ascii + '{"d3d12":{"adapter":"Test GPU"}}' | Set-Content -LiteralPath $report -Encoding Ascii + $xcl = (Get-Command findstr.exe).Source + $shell = (Get-Process -Id $PID).Path + function Check-Report([string[]]$lines, [string[]]$expected) { + [IO.File]::WriteAllLines($log, $lines) + $block = & $shell -NoProfile -ExecutionPolicy Bypass -File $smoke -Game $run -Xcl $xcl -Seconds 1 + if ($LASTEXITCODE -ne 0) { throw "Smoke script exited $LASTEXITCODE" } + foreach ($field in $expected) { + if (($block -split '\r?\n') -notcontains $field) { throw "Missing '$field' in smoke block:`n$block" } + } + } + Check-Report @( + 'memory: 900 MB committed','activity (2 s): 42 presents', + 'activity (2 s): 3 presents','activity (2 s): 6 presents','activity (2 s): 0 presents', + 'memory: 400 MB committed', 'unhandled exception; process ends with status; device removed', + 'device removed', '(51 frames shown, 52 PresentX calls)', '(2 frames shown, 3 PresentX calls)' + ) @('frames shown: 51 (PresentX 52)', 'presents per 2 s (last 3): 3 6 0', + 'peak commit: 900 MB', 'device removals: 2', 'crashes: 2') + Check-Report @('some launcher output') @('frames shown: none logged (the run did not reach its end)', + 'presents per 2 s (last 3): ', 'peak commit: n/a MB', 'device removals: 0', 'crashes: 0') + Check-Report @('memory: 0 MB committed', 'activity (2 s): 0 presents') @( + 'presents per 2 s (last 3): 0', 'peak commit: 0 MB') + '3 smoke-log cases passed' +} finally { + Pop-Location + foreach ($path in @($log, $run, $report, $fixture)) { + if ($path -and (Test-Path -LiteralPath $path)) { Remove-Item -LiteralPath $path } + } +} diff --git a/scripts/smoke.ps1 b/scripts/smoke.ps1 index f0738cdb98..3ed3304a97 100644 --- a/scripts/smoke.ps1 +++ b/scripts/smoke.ps1 @@ -49,15 +49,32 @@ 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 - -$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 } -$lastPresents = ($presents | Select-Object -Last 3) -join ' ' -$commits = [regex]::Matches($text, 'memory: (\d+) MB committed') | ForEach-Object { [int]$_.Groups[1].Value } -$peak = if ($commits) { ($commits | Measure-Object -Maximum).Maximum } else { 'n/a' } -$removals = ([regex]::Matches($text, 'device removed')).Count -$crashes = ([regex]::Matches($text, 'unhandled exception|process ends with status')).Count +# The log can be much larger than the resulting report. Keep only the running counters. +$frames = $null +$recent = [System.Collections.Generic.Queue[int]]::new(3) +$peak = $null +$removals = 0 +$crashes = 0 +$markers = 'frames shown,', 'activity (2 s):', 'memory:', 'device removed', 'unhandled exception', 'process ends with status' +Select-String -LiteralPath $log -Encoding UTF8 -SimpleMatch -Pattern $markers | ForEach-Object { + $line = $_.Line + if ($null -eq $frames -and $line -match '\((\d+) frames shown, (\d+) PresentX calls\)') { + $frames = "$($Matches[1]) (PresentX $($Matches[2]))" + } + foreach ($m in [regex]::Matches($line, 'activity \(2 s\): (\d+) presents')) { + if ($recent.Count -eq 3) { $null = $recent.Dequeue() } + $recent.Enqueue([int]$m.Groups[1].Value) + } + foreach ($m in [regex]::Matches($line, 'memory: (\d+) MB committed')) { + $value = [int]$m.Groups[1].Value + if ($null -eq $peak -or $value -gt $peak) { $peak = $value } + } + $removals += [regex]::Matches($line, 'device removed').Count + $crashes += [regex]::Matches($line, 'unhandled exception|process ends with status').Count +} +if ($null -eq $frames) { $frames = 'none logged (the run did not reach its end)' } +if ($null -eq $peak) { $peak = 'n/a' } +$lastPresents = $recent -join ' ' # 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 $gpu = $null