diff --git a/CLAUDE.md b/CLAUDE.md index edbb6df4..8eb8e88e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -18,6 +18,7 @@ are frozen history cited from code, not kept in step with it. - `build.bat installer`: NSIS setup (needs `winget install NSIS.NSIS`), then `tools\installer_check.ps1`. - `pwsh -File tools\release.ps1`: release installer into `dist\` (what CI runs). - UI tests: `npx playwright test` in `ui/` (run when anything under `ui/` changes). +- `tools\testenv\run.ps1` falls back to a virtual primary when the TV is off; `matrix.ps1` proves other screen setups. See `tools\testenv\README.md`. - `pwsh -File tools\check_copyright.ps1`: CI gate; every new source file needs the copyright/SPDX header. See 11. ## Stack and map diff --git a/docs/architecture/11-build-test-release.md b/docs/architecture/11-build-test-release.md index cefacda2..ecaea0af 100644 --- a/docs/architecture/11-build-test-release.md +++ b/docs/architecture/11-build-test-release.md @@ -115,6 +115,14 @@ upstream notices), generated files (`flyout_palettes.h`, `themes.css`, `themes.j file goes in the script's exclusion lists. The binaries carry the same notice as `LegalCopyright` (`src/wind.rc`, `src/tray_app/wind_tray.rc`, `installer/wind.nsi`). +## Testing on other displays + +The proving ground can run on virtual screens (Virtual Display Driver), so it works with the TV off and +across resolutions, refresh rates, scales and a second monitor. `run.ps1 -Display` picks the screen and +`matrix.ps1` runs a list of setups. The screen is made primary because the transform engine only +magnifies the primary (`src/engine/engine_pick.h`). Virtual runs are health-only unless the setup has its own +baseline; the TV stays the reference for smoothness and latency. See `tools/testenv/README.md`. + ## Local UIAccess deploy UIAccess is needed for the input-transform publish (transform on the desktop), binds over diff --git a/tools/testenv/README.md b/tools/testenv/README.md index 53bbebf1..f7461083 100644 --- a/tools/testenv/README.md +++ b/tools/testenv/README.md @@ -92,6 +92,61 @@ Rules and limits: - External spec JSON (ZoomText etc.): name, exe, procNames, zoomInVks/zoomOutVks (the chord), startWaitMs. The external program is left running afterwards (it was likely there first). +## Displays: TV, virtual screens and the matrix + +The suite needs a live display: with the TV off or asleep, DWM drops to about 13 Hz and every +timing is noise. `run.ps1 -Display` decides what to do about it: + +| `-Display` | What happens | +|---|---| +| `auto` (default) | TV on: run on it as always. TV off or asleep: a virtual screen becomes primary for the run, if the driver is installed; otherwise the old abort (exit 4) | +| `virtual` | Always a virtual primary. Set it with `-DisplayMode WxH@Hz,scale` (default `3840x2160@120,100`) and `-VirtualCount 2` for a second screen | +| `tv` | Never switch | + + pwsh -File tools\testenv\matrix.ps1 # rapid across 6 setups, about 8 min + pwsh -File tools\testenv\matrix.ps1 -Only 1080p,dual + pwsh -File tools\testenv\display.ps1 -List + pwsh -File tools\testenv\display.ps1 -Restore # after a crashed run + +The virtual screen must be primary because the transform engine magnifies the primary monitor only. +The layout is saved to `results/display-layout.json` before any change and restored after each run. +If the TV is still off at that point, the virtual screen stays and the snapshot is kept: run `-Restore` +when the TV is back. Virtual monitors are detached from the desktop between runs. + +**Idle state (#571).** The virtual screen stays plugged in, so Windows falls back to it whenever the TV +is switched off. Idle, it matches the TV: 3840x2160, 144 Hz (60 Hz if the driver does not offer 144), +225 % scale and one monitor. Windows then keeps the same logical desktop (1707x960), so windows keep +their size. Tests may change it while they run. `Restore-DisplayLayout` (the end of every `run.ps1` +virtual run, also on failure and on the pending path), `matrix.ps1` and `display.ps1 -Restore` put it back. +The values live in `$script:VirtualIdle` in `display.ps1`. + + pwsh -File tools\testenv\display.ps1 -Idle -DryRun # what would change; changes nothing + pwsh -File tools\testenv\display.ps1 -Idle # apply it now + pwsh -File tools\testenv\display.ps1 -SelfTest # checks of the idle-state logic + +Mode and scale can only be set while the virtual screen is on the desktop. Windows stores the scale +relative to the screen's recommended scale at that resolution (`DpiValue` under +`HKCU\Control Panel\Desktop\PerMonitorSettings\MTT1337...`), so the function sets it through the same +call as Settings and never writes that value by hand. Windows also remembers the mode it last used for +the "virtual screen only" layout. Run `-Idle` once while the TV is off (or let a nightly run end on the +pending path) to replace an old 1366x768 entry. + +Setup, once per PC, as admin: `winget install VirtualDrivers.Virtual-Display-Driver`, then `devcon install` +of the package's `SignedDrivers\x86\VDD\MttVDD.inf` with hardware id `Root\MttVDD`. Create +`C:\VirtualDisplayDriver\vdd_settings.xml` first, with `` set to the GPU Wind renders on, +and list the modes the matrix uses. List **3840x2160 first** with `144`: +the driver offers the first `` as the preferred mode, which Windows uses when it falls back +to a screen it has no saved mode for. Keep 144 among the `` values, which the driver +adds to every resolution. The driver reads the file when it loads, so a change applies at the next +reload (a count change through the pipe, a reboot, or disabling and enabling the device). +Monitors appear with `MTT1337` in their device path. + +What a virtual run proves: Wind starts, picks the right engine, zooms, stays within the cap and leaves +no stranded state on that resolution, refresh rate, scale and monitor count. It does not prove +smoothness or latency, so **virtual screens are health-only**: the absolute timing limits are calibrated +on the 144 Hz TV and do not apply. Nor is HDR covered. While the TV is on and attached as a secondary, DWM +still composes at its rate, so `hz` in the results is the screen's mode, not the pace measured. + ## Baselines and CI `baselines.json` stores per-scenario PASS numbers from the dev machine (`-UpdateBaseline`). `-CI` @@ -99,6 +154,10 @@ compares with tolerance (1.6x + slack) and exits nonzero on regression. Absolute (dtP99 > 25 ms, jitP95 > 25 px, backSteps in a non-rezoom scenario) catch catastrophes even without a baseline. +The top-level numbers are the TV's. Each virtual screen keeps its own under +`profiles.`, so a virtual run is never judged against TV numbers; one without a baseline is +health-only until `-UpdateBaseline`. Record them with the TV off, so the screen paces itself. + GitHub-hosted runners cannot run this (no real GPU/display for Desktop Duplication or the Magnification API), so the push-to-main story is local: `hooks/pre-push.sample` (reminder gate) and `register_nightly.ps1` (scheduled full run on the dev machine). @@ -108,6 +167,8 @@ gate) and `register_nightly.ps1` (scheduled full run on the dev machine). | File | What it is | |---|---| | `run.ps1` | Orchestrator: suites (rapid, quick, full, soak, stress), scenarios, health checks, verdicts, JSON | +| `display.ps1` | Virtual screens: attach, make primary, set mode and scale, snapshot and restore the layout | +| `matrix.ps1` | Runs one suite across a list of virtual display setups, with one summary table | | `bench.ps1` | Cross-magnifier benchmark: scoreboard and `results/catalog.csv` history | | `lib.ps1` | Shared interop (injection, tones, Wind lifecycle, backdrops) and telemetry analysis | | `backdrop.ps1` | One backdrop window per child process | diff --git a/tools/testenv/display.ps1 b/tools/testenv/display.ps1 new file mode 100644 index 00000000..401e233e --- /dev/null +++ b/tools/testenv/display.ps1 @@ -0,0 +1,432 @@ +# Copyright (c) 2026 Max Aubert. All rights reserved. +# Proprietary source-available software; see LICENSE. SPDX-License-Identifier: LicenseRef-Wind-Proprietary +# Virtual test displays for the proving ground. Spec: research note 2026-11-08 (virtual display testing). +# +# pwsh -File tools\testenv\display.ps1 -List # what is attached right now +# pwsh -File tools\testenv\display.ps1 -Restore # put the saved layout back after a crashed run +# pwsh -File tools\testenv\display.ps1 -Detach # take virtual monitors off the desktop +# pwsh -File tools\testenv\display.ps1 -Idle # put the virtual screen in its idle state (see below) +# pwsh -File tools\testenv\display.ps1 -Idle -DryRun # only print what -Idle would change +# pwsh -File tools\testenv\display.ps1 -SelfTest # checks of the idle-state logic; changes nothing +# +# Dot-source it to use the functions. Needs the Virtual Display Driver (winget +# VirtualDrivers.Virtual-Display-Driver plus a one-time devcon install); no admin at run time. +# +# Virtual monitors are found by the MTT1337 device path, never by \\.\DISPLAYn, which shifts when the +# driver reloads. The transform engine magnifies the PRIMARY monitor only (src/engine/engine_pick.h), so +# a test screen has to be primary or the run exercises the wrong engine. +param([switch]$List, [switch]$Restore, [switch]$Detach, [switch]$Idle, [switch]$DryRun, [switch]$SelfTest) + +if (-not ('WindCcd' -as [type])) { +Add-Type -TypeDefinition @' +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +[StructLayout(LayoutKind.Sequential)] public struct CcdLuid { public uint Low; public int High; } +[StructLayout(LayoutKind.Sequential)] public struct CcdSource { public CcdLuid adapterId; public uint id; public uint modeInfoIdx; public uint statusFlags; } +[StructLayout(LayoutKind.Sequential)] public struct CcdTarget { + public CcdLuid adapterId; public uint id; public uint modeInfoIdx; public uint outputTechnology; public uint rotation; public uint scaling; + public uint refreshNum; public uint refreshDen; public uint scanLineOrdering; public int targetAvailable; public uint statusFlags; } +[StructLayout(LayoutKind.Sequential)] public struct CcdPath { public CcdSource source; public CcdTarget target; public uint flags; } +[StructLayout(LayoutKind.Explicit, Size=64)] public struct CcdMode { + [FieldOffset(0)] public uint infoType; [FieldOffset(4)] public uint id; [FieldOffset(8)] public CcdLuid adapterId; + [FieldOffset(16)] public uint width; [FieldOffset(20)] public uint height; [FieldOffset(24)] public uint pixelFormat; + [FieldOffset(28)] public int posX; [FieldOffset(32)] public int posY; } +[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] public struct CcdTargetName { + public uint type; public uint size; public CcdLuid adapterId; public uint id; + public uint flags; public uint outputTechnology; public ushort mfg; public ushort prod; public uint connector; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)] public string friendly; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)] public string path; } +[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] public struct CcdSourceName { + public uint type; public uint size; public CcdLuid adapterId; public uint id; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] public string gdi; } +// Undocumented but stable: the same calls Settings > Display > Scale makes (types -3 and -4). +[StructLayout(LayoutKind.Sequential)] public struct CcdDpiGet { public int type; public uint size; public CcdLuid adapterId; public uint id; public int min; public int cur; public int max; } +[StructLayout(LayoutKind.Sequential)] public struct CcdDpiSet { public int type; public uint size; public CcdLuid adapterId; public uint id; public int rel; } +[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] public struct CcdDevMode { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] public string name; + public ushort spec, driver, size, extra; public uint fields; public int x, y; public uint orient, fixedOut; + public short color, duplex, yres, tt, collate; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] public string form; + public ushort logPixels; public uint bpp, width, height, flags, hz; public uint icm, intent, media, dither, r1, r2, panW, panH; } + +public static class WindCcd { + [DllImport("user32.dll")] static extern int GetDisplayConfigBufferSizes(uint f, out uint p, out uint m); + [DllImport("user32.dll")] static extern int QueryDisplayConfig(uint f, ref uint np, [Out] CcdPath[] p, ref uint nm, [Out] CcdMode[] m, IntPtr t); + [DllImport("user32.dll")] static extern int SetDisplayConfig(uint np, [In] CcdPath[] p, uint nm, [In] CcdMode[] m, uint f); + [DllImport("user32.dll")] static extern int DisplayConfigGetDeviceInfo(ref CcdTargetName t); + [DllImport("user32.dll")] static extern int DisplayConfigGetDeviceInfo(ref CcdSourceName t); + [DllImport("user32.dll")] static extern int DisplayConfigGetDeviceInfo(ref CcdDpiGet t); + [DllImport("user32.dll")] static extern int DisplayConfigSetDeviceInfo(ref CcdDpiSet t); + [DllImport("user32.dll", CharSet=CharSet.Unicode)] static extern int ChangeDisplaySettingsExW(string dev, ref CcdDevMode m, IntPtr h, uint f, IntPtr l); + [DllImport("user32.dll", CharSet=CharSet.Unicode)] static extern bool EnumDisplaySettingsW(string dev, int mode, ref CcdDevMode m); + + public const uint INVALID = 0xffffffff, ACTIVE = 1; + public const uint QDC_ALL = 1, QDC_ACTIVE = 2; + public const uint APPLY_SUPPLIED = 0x80 | 0x20 | 0x400 | 0x200; // APPLY, USE_SUPPLIED, ALLOW_CHANGES, SAVE_TO_DATABASE + + public static void Query(uint flag, out CcdPath[] paths, out CcdMode[] modes) { + uint np, nm; int r = GetDisplayConfigBufferSizes(flag, out np, out nm); + if (r != 0) throw new Exception("GetDisplayConfigBufferSizes " + r); + paths = new CcdPath[np]; modes = new CcdMode[nm]; + r = QueryDisplayConfig(flag, ref np, paths, ref nm, modes, IntPtr.Zero); + if (r != 0) throw new Exception("QueryDisplayConfig " + r); + Array.Resize(ref paths, (int)np); Array.Resize(ref modes, (int)nm); + } + public static CcdTargetName Target(CcdPath p) { + var t = new CcdTargetName(); t.type = 2; t.size = (uint)Marshal.SizeOf(typeof(CcdTargetName)); t.adapterId = p.target.adapterId; t.id = p.target.id; + DisplayConfigGetDeviceInfo(ref t); return t; + } + public static string Gdi(CcdPath p) { + var s = new CcdSourceName(); s.type = 1; s.size = (uint)Marshal.SizeOf(typeof(CcdSourceName)); s.adapterId = p.source.adapterId; s.id = p.source.id; + DisplayConfigGetDeviceInfo(ref s); return s.gdi; + } + static T From(string s) where T : struct { + byte[] b = Convert.FromBase64String(s); var h = GCHandle.Alloc(b, GCHandleType.Pinned); + try { return (T)Marshal.PtrToStructure(h.AddrOfPinnedObject(), typeof(T)); } finally { h.Free(); } + } + static string To(T v) where T : struct { + byte[] b = new byte[Marshal.SizeOf(typeof(T))]; var h = GCHandle.Alloc(b, GCHandleType.Pinned); + try { Marshal.StructureToPtr(v, h.AddrOfPinnedObject(), false); } finally { h.Free(); } + return Convert.ToBase64String(b); + } + // In C# because PowerShell writes a field of an array-held or nested struct to a throwaway copy. + public static void SetPos(CcdMode[] m, uint i, int x, int y) { m[i].posX = x; m[i].posY = y; } + public static CcdPath Activated(CcdPath p) { p.flags |= ACTIVE; p.source.modeInfoIdx = INVALID; p.target.modeInfoIdx = INVALID; return p; } + public static CcdPath PathFrom(string s) { return From(s); } + public static CcdMode ModeFrom(string s) { return From(s); } + public static string PathTo(CcdPath v) { return To(v); } + public static string ModeTo(CcdMode v) { return To(v); } + public static int Apply(CcdPath[] paths, CcdMode[] modes) { return SetDisplayConfig((uint)paths.Length, paths, (uint)modes.Length, modes, APPLY_SUPPLIED); } + + // Apply a subset of the active paths, dropping and re-indexing modes that nothing refers to any more. + public static int ApplySubset(CcdPath[] keep, CcdMode[] modes) { + var map = new Dictionary(); var outModes = new List(); + Func remap = i => { + if (i == INVALID || i >= modes.Length) return INVALID; + uint n; if (!map.TryGetValue(i, out n)) { n = (uint)outModes.Count; outModes.Add(modes[i]); map[i] = n; } + return n; }; + for (int i = 0; i < keep.Length; i++) { keep[i].source.modeInfoIdx = remap(keep[i].source.modeInfoIdx); keep[i].target.modeInfoIdx = remap(keep[i].target.modeInfoIdx); } + return Apply(keep, outModes.ToArray()); + } + // Windows steps scale along a fixed ladder, relative to the monitor's recommended rung. + static readonly int[] Ladder = { 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500 }; + public static int SetScale(CcdPath p, int percent) { + var g = new CcdDpiGet(); g.type = -3; g.size = (uint)Marshal.SizeOf(typeof(CcdDpiGet)); g.adapterId = p.source.adapterId; g.id = p.source.id; + int r = DisplayConfigGetDeviceInfo(ref g); if (r != 0) return r; + int idx = Array.IndexOf(Ladder, percent); if (idx < 0) return 87; + var s = new CcdDpiSet(); s.type = -4; s.size = (uint)Marshal.SizeOf(typeof(CcdDpiSet)); s.adapterId = p.source.adapterId; s.id = p.source.id; + s.rel = idx - Math.Abs(g.min); + return DisplayConfigSetDeviceInfo(ref s); + } + public static int GetScale(CcdPath p) { + var g = new CcdDpiGet(); g.type = -3; g.size = (uint)Marshal.SizeOf(typeof(CcdDpiGet)); g.adapterId = p.source.adapterId; g.id = p.source.id; + if (DisplayConfigGetDeviceInfo(ref g) != 0) return 0; + int idx = Math.Abs(g.min) + g.cur; + return (idx >= 0 && idx < Ladder.Length) ? Ladder[idx] : 0; + } + public static int SetMode(string gdi, int w, int h, int hz) { + var d = new CcdDevMode(); d.size = (ushort)Marshal.SizeOf(typeof(CcdDevMode)); + d.width = (uint)w; d.height = (uint)h; d.hz = (uint)hz; d.fields = 0x80000 | 0x100000 | 0x400000; // PELSWIDTH, PELSHEIGHT, DISPLAYFREQUENCY + return ChangeDisplaySettingsExW(gdi, ref d, IntPtr.Zero, 1, IntPtr.Zero); // CDS_UPDATEREGISTRY + } + public static string[] Modes(string gdi) { + var seen = new List(); var d = new CcdDevMode(); d.size = (ushort)Marshal.SizeOf(typeof(CcdDevMode)); + for (int i = 0; EnumDisplaySettingsW(gdi, i, ref d); i++) { string s = d.width + "x" + d.height + "@" + d.hz; if (!seen.Contains(s)) seen.Add(s); } + return seen.ToArray(); + } +} +'@ +} + +$script:DisplaySnapshotPath = Join-Path $PSScriptRoot 'results\display-layout.json' +$script:VddPipeName = 'MTTVirtualDisplayPipe' +$script:VddMatch = 'MTT1337' + +function Get-ActiveLayout { + $p = $null; $m = $null; [WindCcd]::Query([WindCcd]::QDC_ACTIVE, [ref]$p, [ref]$m) + [pscustomobject]@{ Paths = $p; Modes = $m } +} + +function Get-DisplayList { + $l = Get-ActiveLayout + foreach ($x in $l.Paths) { + $n = [WindCcd]::Target($x); $s = $l.Modes[$x.source.modeInfoIdx] + $hz = if ($x.target.refreshDen) { [math]::Round($x.target.refreshNum / $x.target.refreshDen, 2) } else { 0 } + [pscustomobject]@{ + Name = $n.friendly; Gdi = [WindCcd]::Gdi($x); Width = [int]$s.width; Height = [int]$s.height; Hz = $hz + X = $s.posX; Y = $s.posY; Primary = ($s.posX -eq 0 -and $s.posY -eq 0); Virtual = ($n.path -match $script:VddMatch) + Scale = [WindCcd]::GetScale($x) + } + } +} + +function Test-VirtualDisplayInstalled { + [bool](Get-PnpDevice -Class Display -PresentOnly -ErrorAction SilentlyContinue | Where-Object { $_.HardwareID -contains 'Root\MttVDD' -and $_.Status -eq 'OK' }) +} + +# Raw paths and modes go to disk first, so a crashed run can still be undone with -Restore. +function Save-DisplayLayout { + if (Test-Path $script:DisplaySnapshotPath) { return } # the first snapshot is the real one + $dir = Split-Path $script:DisplaySnapshotPath + if (-not (Test-Path $dir)) { New-Item -ItemType Directory $dir | Out-Null } + $l = Get-ActiveLayout + $names = @($l.Paths | ForEach-Object { [WindCcd]::Target($_).path }) + [ordered]@{ saved = (Get-Date -Format s); targets = $names + paths = @($l.Paths | ForEach-Object { [WindCcd]::PathTo($_) }); modes = @($l.Modes | ForEach-Object { [WindCcd]::ModeTo($_) }) + } | ConvertTo-Json -Depth 4 | Set-Content $script:DisplaySnapshotPath +} + +function Remove-VirtualFromDesktop { + $l = Get-ActiveLayout + $keep = @($l.Paths | Where-Object { [WindCcd]::Target($_).path -notmatch $script:VddMatch }) + if ($keep.Count -eq $l.Paths.Count) { return 'none attached' } + if ($keep.Count -eq 0) { return 'kept: it is the only screen' } + $r = [WindCcd]::ApplySubset([CcdPath[]]$keep, $l.Modes) + if ($r -ne 0) { throw "SetDisplayConfig (detach) failed: $r" } + 'detached' +} + +# Returns 'restored' or 'pending'. Pending means the real screen is not there (TV powered off): the +# snapshot stays on disk and the virtual screen stays, so the PC is never left with no desktop at all. +# The virtual screen goes back to its idle state first, and again on the pending path, because the +# snapshot itself can hold a test mode (a run that started with the TV off saves a virtual-only layout). +function Restore-DisplayLayout { + Invoke-VirtualIdle + if (-not (Test-Path $script:DisplaySnapshotPath)) { Remove-VirtualFromDesktop | Out-Null; return 'restored' } + $snap = Get-Content $script:DisplaySnapshotPath -Raw | ConvertFrom-Json + [CcdPath[]]$paths = @($snap.paths | ForEach-Object { [WindCcd]::PathFrom($_) }) + [CcdMode[]]$modes = @($snap.modes | ForEach-Object { [WindCcd]::ModeFrom($_) }) + $r = [WindCcd]::Apply($paths, $modes) + if ($r -ne 0) { + # Stale adapter ids after a reboot, or a target that went away. Fall back to taking the virtual off. + if ((Remove-VirtualFromDesktop) -like 'kept*') { Invoke-VirtualIdle; return 'pending' } + } + Start-Sleep -Milliseconds 800 + $now = @(Get-DisplayList) + if (@($now | Where-Object { -not $_.Virtual }).Count -eq 0) { Invoke-VirtualIdle; return 'pending' } + if (@($now | Where-Object Virtual).Count -gt 0) { Remove-VirtualFromDesktop | Out-Null } + Remove-Item $script:DisplaySnapshotPath -ErrorAction SilentlyContinue + 'restored' +} + +function Send-VddCommand([string]$Command) { + $pipe = [IO.Pipes.NamedPipeClientStream]::new('.', $script:VddPipeName, [IO.Pipes.PipeDirection]::InOut) + try { $pipe.Connect(3000); $b = [Text.Encoding]::Unicode.GetBytes($Command); $pipe.Write($b, 0, $b.Length); $pipe.Flush() } + finally { $pipe.Dispose() } +} + +function Wait-VirtualOutputs([int]$Count, [int]$Seconds = 15) { + $until = (Get-Date).AddSeconds($Seconds) + do { + $p = $null; $m = $null; [WindCcd]::Query([WindCcd]::QDC_ALL, [ref]$p, [ref]$m) + $t = @($p | Where-Object { $_.target.targetAvailable -ne 0 -and [WindCcd]::Target($_).path -match $script:VddMatch } | ForEach-Object { $_.target.id } | Sort-Object -Unique) + if ($t.Count -ge $Count) { return $t.Count } + Start-Sleep -Milliseconds 300 + } while ((Get-Date) -lt $until) + $t.Count +} + +# Sets the monitor count only when it differs; a reload disturbs the desktop for several seconds. +function Set-VirtualCount([int]$Count) { + $null = Wait-VirtualOutputs 1 2 + if ((Get-VirtualOutputCount) -eq $Count) { return } + Send-VddCommand "SETDISPLAYCOUNT $Count" + if ((Wait-VirtualOutputs $Count) -lt $Count) { throw "the driver did not produce $Count virtual monitor(s)" } + Start-Sleep -Seconds 2 +} + +function Get-VirtualOutputCount { + $p = $null; $m = $null; [WindCcd]::Query([WindCcd]::QDC_ALL, [ref]$p, [ref]$m) + @($p | Where-Object { $_.target.targetAvailable -ne 0 -and [WindCcd]::Target($_).path -match $script:VddMatch } | ForEach-Object { $_.target.id } | Sort-Object -Unique).Count +} + +# IDLE STATE (2026-11-17, #571). The virtual screen is always plugged in, so when the TV is switched off +# Windows falls back to it. At its old idle mode (1366x768, 100 %) every window was squeezed and stayed +# small when the TV came back. Idle it matches the TV instead: same pixels, same scale, so the logical +# desktop (1707x960) and every window keep their size. Tests may change it while they run; every exit +# path (Restore-DisplayLayout, matrix.ps1) puts it back. The mode is also the driver's preferred one +# (first in vdd_settings.xml), for a fallback the tests never touched. +$script:VirtualIdle = @{ Width = 3840; Height = 2160; Hz = 144; FallbackHz = 60; Scale = 225; Count = 1 } + +# Pure, so -SelfTest can check it: the steps that bring the virtual screen to the idle state. +# $Current is the first attached virtual screen (Width, Height, Hz, Scale) or $null when none is on the +# desktop; $Offered is the driver's mode list for it ('WxH@Hz'); $Outputs the driver's monitor count. +# A mode change always re-sets the scale: Windows stores scale relative to the recommended rung, and the +# recommended rung moves with the resolution. +function Get-VirtualIdlePlan($Current, [string[]]$Offered, [int]$Outputs, [hashtable]$Target = $script:VirtualIdle) { + $steps = @() + if ($Outputs -ne $Target.Count) { $steps += [pscustomobject]@{ Step = 'count'; Value = $Target.Count } } + if (-not $Current) { return $steps } + $hz = $null + foreach ($f in @($Target.Hz, $Target.FallbackHz)) { if ("$($Target.Width)x$($Target.Height)@$f" -in $Offered) { $hz = $f; break } } + if ($null -eq $hz) { + return $steps + [pscustomobject]@{ Step = 'error'; Value = "the driver does not offer $($Target.Width)x$($Target.Height) at $($Target.Hz) or $($Target.FallbackHz) Hz (see vdd_settings.xml)" } + } + $modeOk = $Current.Width -eq $Target.Width -and $Current.Height -eq $Target.Height -and [math]::Round($Current.Hz) -eq $hz + if (-not $modeOk) { $steps += [pscustomobject]@{ Step = 'mode'; Value = "$($Target.Width)x$($Target.Height)@$hz" } } + if (-not $modeOk -or $Current.Scale -ne $Target.Scale) { $steps += [pscustomobject]@{ Step = 'scale'; Value = $Target.Scale } } + $steps +} + +function Get-FirstVirtualPath { @((Get-ActiveLayout).Paths | Where-Object { [WindCcd]::Target($_).path -match $script:VddMatch }) | Select-Object -First 1 } + +# Applies the idle state. Mode and scale can only be set while the virtual screen is on the desktop; when +# it is not, the count is all there is to fix, and the preferred mode covers the next fallback. +# Returns the steps taken (or that would be taken with -DryRun). +function Set-VirtualIdleMode([switch]$DryRun) { + if (-not (Test-VirtualDisplayInstalled)) { return @() } + $outputs = Get-VirtualOutputCount + $done = @() + # The count goes first and alone: a count change reloads the driver, which can change what is attached. + if (-not $DryRun -and $outputs -ne $script:VirtualIdle.Count) { + Set-VirtualCount $script:VirtualIdle.Count + $done += [pscustomobject]@{ Step = 'count'; Value = $script:VirtualIdle.Count } + $outputs = Get-VirtualOutputCount + } + $path = Get-FirstVirtualPath + $cur = $null; $offered = @(); $gdi = $null + if ($path) { + $gdi = [WindCcd]::Gdi($path) + $cur = @(Get-DisplayList | Where-Object { $_.Virtual -and $_.Gdi -eq $gdi }) | Select-Object -First 1 + $offered = [WindCcd]::Modes($gdi) + } + $plan = @(Get-VirtualIdlePlan $cur $offered $outputs) + if ($DryRun) { return $plan } + foreach ($s in $plan) { + switch ($s.Step) { + 'error' { throw $s.Value } + 'count' { throw "the driver still has $outputs virtual monitor(s), not $($s.Value)" } + 'mode' { + $null = $s.Value -match '^(\d+)x(\d+)@(\d+)$' + $r = [WindCcd]::SetMode($gdi, [int]$Matches[1], [int]$Matches[2], [int]$Matches[3]) + if ($r -ne 0) { throw "ChangeDisplaySettingsEx failed on ${gdi}: $r" } + Start-Sleep -Milliseconds 800 + } + 'scale' { + $r = [WindCcd]::SetScale((Get-FirstVirtualPath), [int]$s.Value) + if ($r -ne 0) { throw "setting scale $($s.Value)% failed: $r" } + } + } + $done += $s + } + $done +} + +# For exit paths: report, never throw, so a failed idle step cannot block the layout restore. +function Invoke-VirtualIdle { + try { + $s = @(Set-VirtualIdleMode) + if ($s.Count) { Write-Host ('Virtual screen idle: ' + (($s | ForEach-Object { "$($_.Step) $($_.Value)" }) -join ', ')) } + } catch { Write-Host "Could not put the virtual screen in its idle state: $($_.Exception.Message)" -ForegroundColor Yellow } +} + +function Test-VirtualIdlePlan { + $t = @{ Width = 3840; Height = 2160; Hz = 144; FallbackHz = 60; Scale = 225; Count = 1 } + $all = @('1366x768@60','3840x2160@60','3840x2160@120','3840x2160@144') + $cases = @( + @{ n = 'fallback state of 2026-11-17'; c = @{ Width = 1366; Height = 768; Hz = 60; Scale = 100 }; o = $all; k = 1; want = 'mode=3840x2160@144 scale=225' }, + @{ n = 'already idle'; c = @{ Width = 3840; Height = 2160; Hz = 143.99; Scale = 225 }; o = $all; k = 1; want = '' }, + @{ n = 'test scale left behind'; c = @{ Width = 3840; Height = 2160; Hz = 144; Scale = 100 }; o = $all; k = 1; want = 'scale=225' }, + @{ n = 'test refresh left behind'; c = @{ Width = 3840; Height = 2160; Hz = 120; Scale = 225 }; o = $all; k = 1; want = 'mode=3840x2160@144 scale=225' }, + @{ n = 'no 144 Hz: fall back to 60'; c = @{ Width = 1920; Height = 1080; Hz = 60; Scale = 100 }; o = @('3840x2160@60'); k = 1; want = 'mode=3840x2160@60 scale=225' }, + @{ n = 'dual left behind, detached'; c = $null; o = @(); k = 2; want = 'count=1' }, + @{ n = 'detached, count right'; c = $null; o = @(); k = 1; want = '' }, + @{ n = 'no 4K mode at all'; c = @{ Width = 1920; Height = 1080; Hz = 60; Scale = 100 }; o = @('1920x1080@60'); k = 1; want = 'error' } + ) + $bad = 0 + foreach ($x in $cases) { + $cur = if ($x.c) { [pscustomobject]$x.c } else { $null } + $got = (@(Get-VirtualIdlePlan $cur $x.o $x.k $t) | ForEach-Object { if ($_.Step -eq 'error') { 'error' } else { "$($_.Step)=$($_.Value)" } }) -join ' ' + $ok = $got -eq $x.want + if (-not $ok) { $bad++ } + Write-Host ('{0} {1}: {2}' -f $(if ($ok) { 'PASS' } else { 'FAIL' }), $x.n, $(if ($ok) { $got } else { "got '$got', want '$($x.want)'" })) + } + $bad +} + +function Add-VirtualToDesktop([int]$Count) { + $l = Get-ActiveLayout + $p = $null; $m = $null; [WindCcd]::Query([WindCcd]::QDC_ALL, [ref]$p, [ref]$m) + $activeTargets = @($l.Paths | ForEach-Object { '{0}:{1}' -f $_.target.adapterId.Low, $_.target.id }) + $activeSources = @($l.Paths | ForEach-Object { '{0}:{1}' -f $_.source.adapterId.Low, $_.source.id }) + $paths = New-Object 'System.Collections.Generic.List[CcdPath]' + foreach ($x in $l.Paths) { $paths.Add($x) } + $attached = @($l.Paths | Where-Object { [WindCcd]::Target($_).path -match $script:VddMatch }).Count + foreach ($c in $p) { + if ($attached -ge $Count) { break } + if ($c.target.targetAvailable -eq 0 -or [WindCcd]::Target($c).path -notmatch $script:VddMatch) { continue } + $tk = '{0}:{1}' -f $c.target.adapterId.Low, $c.target.id; $sk = '{0}:{1}' -f $c.source.adapterId.Low, $c.source.id + if ($activeTargets -contains $tk -or $activeSources -contains $sk) { continue } + $paths.Add([WindCcd]::Activated($c)); $activeTargets += $tk; $activeSources += $sk; $attached++ + } + if ($attached -lt $Count) { throw "only $attached of $Count virtual monitor(s) could be attached" } + $r = [WindCcd]::Apply($paths.ToArray(), $l.Modes) + if ($r -ne 0) { throw "SetDisplayConfig (attach) failed: $r" } + Start-Sleep -Milliseconds 800 +} + +# Primary means the source sits at (0,0). Everything else lines up to the right of it. +function Set-VirtualPrimaryPosition { + $l = Get-ActiveLayout + $modes = $l.Modes + $virt = @($l.Paths | Where-Object { [WindCcd]::Target($_).path -match $script:VddMatch }) + if ($virt.Count -eq 0) { throw 'no virtual monitor on the desktop' } + $first = $modes[$virt[0].source.modeInfoIdx] + $x = [int]$first.width + [WindCcd]::SetPos($modes, $virt[0].source.modeInfoIdx, 0, 0) + foreach ($pa in $l.Paths) { + if ($pa.source.id -eq $virt[0].source.id -and $pa.source.adapterId.Low -eq $virt[0].source.adapterId.Low) { continue } + [WindCcd]::SetPos($modes, $pa.source.modeInfoIdx, $x, 0) + $x += [int]$modes[$pa.source.modeInfoIdx].width + } + $r = [WindCcd]::Apply($l.Paths, $modes) + if ($r -ne 0) { throw "SetDisplayConfig (primary) failed: $r" } + Start-Sleep -Milliseconds 800 +} + +function Use-VirtualPrimary { + param([int]$Width = 3840, [int]$Height = 2160, [int]$Hz = 120, [int]$Scale = 100, [int]$Count = 1, [int]$SecondScale = 150) + if (-not (Test-VirtualDisplayInstalled)) { throw 'The Virtual Display Driver is not installed (see tools\testenv\README.md).' } + Save-DisplayLayout + Set-VirtualCount $Count + Add-VirtualToDesktop $Count + $virt = @((Get-ActiveLayout).Paths | Where-Object { [WindCcd]::Target($_).path -match $script:VddMatch }) + for ($i = 0; $i -lt $virt.Count; $i++) { + $gdi = [WindCcd]::Gdi($virt[$i]) + # The secondary is a fixed 1080p so the two-monitor case differs in size as well as scale. + $w = if ($i -eq 0) { $Width } else { 1920 }; $h = if ($i -eq 0) { $Height } else { 1080 }; $f = if ($i -eq 0) { $Hz } else { 60 } + if ("${w}x${h}@$f" -notin [WindCcd]::Modes($gdi)) { throw "the driver does not offer ${w}x${h}@$f (add it to C:\VirtualDisplayDriver\vdd_settings.xml)" } + $r = [WindCcd]::SetMode($gdi, $w, $h, $f) + if ($r -ne 0) { throw "ChangeDisplaySettingsEx failed on ${gdi}: $r" } + } + Start-Sleep -Milliseconds 800 + Set-VirtualPrimaryPosition + $virt = @((Get-ActiveLayout).Paths | Where-Object { [WindCcd]::Target($_).path -match $script:VddMatch }) + for ($i = 0; $i -lt $virt.Count; $i++) { + $want = if ($i -eq 0) { $Scale } else { $SecondScale } + $r = [WindCcd]::SetScale($virt[$i], $want) + if ($r -ne 0) { throw "setting scale $want% failed: $r" } + } + Start-Sleep -Milliseconds 800 + $p = Get-DisplayList | Where-Object Primary | Select-Object -First 1 + if (-not $p.Virtual) { throw "the primary is $($p.Name), not the virtual screen" } + $p +} + +function Get-DisplayProfileKey($Display) { '{0}x{1}@{2},{3}' -f $Display.Width, $Display.Height, [math]::Round($Display.Hz), $Display.Scale } + +if ($MyInvocation.InvocationName -ne '.') { + if ($Restore) { $s = Restore-DisplayLayout; Write-Host "Display layout: $s"; Get-DisplayList | Format-Table -AutoSize; if ($s -eq 'pending') { exit 5 } } + elseif ($Detach) { Write-Host (Remove-VirtualFromDesktop); Get-DisplayList | Format-Table -AutoSize } + elseif ($SelfTest) { $bad = Test-VirtualIdlePlan; if ($bad) { Write-Host "$bad check(s) FAILED" -ForegroundColor Red; exit 1 }; Write-Host 'Idle-state checks passed.' -ForegroundColor Green } + elseif ($Idle) { + $s = @(Set-VirtualIdleMode -DryRun:$DryRun) + $verb = if ($DryRun) { 'Would change' } else { 'Changed' } + if ($s.Count) { $s | ForEach-Object { Write-Host "$verb $($_.Step): $($_.Value)" } } else { Write-Host 'The virtual screen is already in its idle state (or not on the desktop).' } + if (-not (Get-FirstVirtualPath)) { Write-Host 'Not on the desktop: mode and scale apply the next time Windows falls back to it.' } + Get-DisplayList | Format-Table -AutoSize + } + else { Get-DisplayList | Format-Table -AutoSize } +} diff --git a/tools/testenv/matrix.ps1 b/tools/testenv/matrix.ps1 new file mode 100644 index 00000000..3f6fa1be --- /dev/null +++ b/tools/testenv/matrix.ps1 @@ -0,0 +1,54 @@ +# Copyright (c) 2026 Max Aubert. All rights reserved. +# Proprietary source-available software; see LICENSE. SPDX-License-Identifier: LicenseRef-Wind-Proprietary +# Runs one proving-ground suite across several virtual screens, so Wind is proven beyond one display. +# +# pwsh -File tools\testenv\matrix.ps1 # rapid suite, every setup +# pwsh -File tools\testenv\matrix.ps1 -Only 1080p,dual # just those +# pwsh -File tools\testenv\matrix.ps1 -UpdateBaseline # record each setup's own baseline +# +# Takes the screen for about 2 minutes a setup, like any suite. The TV is restored after each one. +param( + [ValidateSet('iterate','rapid','quick','full','stress')] [string]$Suite = 'rapid', + [string[]]$Only = @(), + [switch]$CI, + [switch]$UpdateBaseline +) +$ErrorActionPreference = 'Stop' +. (Join-Path $PSScriptRoot 'display.ps1') +if (-not (Test-VirtualDisplayInstalled)) { Write-Host 'The Virtual Display Driver is not installed (see README.md).' -ForegroundColor Red; exit 7 } + +$setups = @( + @{ name = '1080p'; mode = '1920x1080@60,100'; count = 1 }, + @{ name = '1440p'; mode = '2560x1440@144,125'; count = 1 }, + @{ name = '4k'; mode = '3840x2160@120,150'; count = 1 }, + @{ name = 'ultrawide'; mode = '3440x1440@100,100'; count = 1 }, + @{ name = 'low-end'; mode = '1366x768@60,100'; count = 1 }, + @{ name = 'dual'; mode = '1920x1080@60,100'; count = 2 } # second screen: 1080p, 150 % +) +if ($Only.Count) { $setups = @($setups | Where-Object { $_.name -in $Only }) } + +$rows = @(); $bad = 0 +$results = Join-Path $PSScriptRoot 'results' +try { + foreach ($s in $setups) { + Write-Host "`n=== $($s.name): $($s.mode), $($s.count) virtual screen(s)" -ForegroundColor Cyan + $before = Get-Date + $runArgs = @('-NoProfile','-ExecutionPolicy','Bypass','-File',(Join-Path $PSScriptRoot 'run.ps1'),'-Suite',$Suite,'-Display','virtual','-DisplayMode',$s.mode,'-VirtualCount',$s.count) + if ($UpdateBaseline) { $runArgs += '-UpdateBaseline' } + & (Get-Process -Id $PID).Path @runArgs + $code = $LASTEXITCODE + $file = Get-ChildItem (Join-Path $results "$Suite-*.json") -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -gt $before } | Sort-Object LastWriteTime | Select-Object -Last 1 + if (-not $file) { $rows += [pscustomobject]@{ setup = $s.name; display = $s.mode; verdict = "NO RESULT (exit $code)"; engine = ''; fails = '' }; $bad++; continue } + $r = Get-Content $file.FullName -Raw | ConvertFrom-Json + $engines = @($r.scenarios.PSObject.Properties.Value | ForEach-Object { $_.engine } | Where-Object { $_ } | Sort-Object -Unique) -join ',' + $ok = ($r.fails -eq 0) -and ($code -eq 0) + if (-not $ok) { $bad++ } + $rows += [pscustomobject]@{ setup = $s.name; display = $r.display; verdict = $(if ($ok) { 'PASS' } else { 'FAIL' }); engine = $engines; fails = $r.fails } + } +} finally { + # Each run.ps1 restores its own setup; this also covers a matrix stopped between two runs. + Invoke-VirtualIdle +} +$rows | Format-Table -AutoSize | Out-String | Write-Host +if ($bad) { Write-Host "$bad setup(s) FAILED" -ForegroundColor Red; if ($CI) { exit 1 } } else { Write-Host 'All setups PASSED' -ForegroundColor Green } +exit 0 diff --git a/tools/testenv/run.ps1 b/tools/testenv/run.ps1 index 39172c0f..1f5ee191 100644 --- a/tools/testenv/run.ps1 +++ b/tools/testenv/run.ps1 @@ -9,6 +9,8 @@ # powershell -File tools\testenv\run.ps1 -Suite soak -Minutes 30 # powershell -File tools\testenv\run.ps1 -Suite full -CI # exit 1 on regression vs baselines # powershell -File tools\testenv\run.ps1 -Suite full -UpdateBaseline +# powershell -File tools\testenv\run.ps1 -Display virtual -DisplayMode 2560x1440@144,125 +# -Display auto (default) uses the TV, or a virtual primary when the TV is off; see display.ps1 # # Iteration gate: iterate (or quick by change risk) -> full -> PR. Run stress before releases # and after engine-level work. -Suite iterate = the load-bearing four in ~45s. @@ -31,12 +33,53 @@ param( [int]$Minutes = 30, # soak only [switch]$CI, # compare vs baselines.json; nonzero exit on regression [switch]$UpdateBaseline, + [ValidateSet('auto','tv','virtual','current')] [string]$Display = 'auto', # 'current' is internal + [ValidatePattern('^\d+x\d+@\d+,\d+$')] [string]$DisplayMode = '3840x2160@120,100', # WxH@Hz,scale% + [ValidateRange(1,2)] [int]$VirtualCount = 1, + [string]$DisplayProfile = '', # internal: set on the inner run that measures a virtual screen [string]$WindExe = 'C:\Program Files\Wind\Wind.exe' ) $ErrorActionPreference = 'Stop' . (Join-Path $PSScriptRoot 'lib.ps1') $script:WindExe = $WindExe +# VIRTUAL SCREEN (2026-11-08). The suite below has many exit paths and everything in it reads the +# primary monitor, so the layout change wraps a whole child run of this script: this process owns +# the switch and the restore, the child measures whatever is primary. Ctrl+C reaches the finally. +. (Join-Path $PSScriptRoot 'display.ps1') +$script:VirtualProfile = $DisplayProfile +if ($Display -in @('auto','virtual')) { + $goVirtual = $Display -eq 'virtual' + if ($Display -eq 'auto' -and (Get-CompositeHz) -lt 50) { + if (Test-VirtualDisplayInstalled) { $goVirtual = $true; Write-Host 'The TV is off or asleep: using a virtual screen.' -ForegroundColor Yellow } + } + if ($goVirtual) { + $null = $DisplayMode -match '^(\d+)x(\d+)@(\d+),(\d+)$' + $code = 2 + try { + $d = Use-VirtualPrimary -Width $Matches[1] -Height $Matches[2] -Hz $Matches[3] -Scale $Matches[4] -Count $VirtualCount + $key = Get-DisplayProfileKey $d + if ($VirtualCount -gt 1) { $key += "+$VirtualCount" } + Write-Host "Virtual primary ready: $key" + $inner = @('-NoProfile','-ExecutionPolicy','Bypass','-File',$PSCommandPath,'-Suite',$Suite,'-Minutes',$Minutes,'-WindExe',$WindExe,'-Display','current','-DisplayProfile',$key) + if ($NoFailFast) { $inner += '-NoFailFast' } + if ($CI) { $inner += '-CI' } + if ($UpdateBaseline) { $inner += '-UpdateBaseline' } + & (Get-Process -Id $PID).Path @inner + $code = $LASTEXITCODE + } catch { + Write-Host "VIRTUAL DISPLAY FAILURE: $($_.Exception.Message)" -ForegroundColor Red + } finally { + # Restore-DisplayLayout also puts the virtual screen back to its idle state (TV size and scale, #571). + try { $restored = Restore-DisplayLayout } + catch { $restored = "FAILED ($($_.Exception.Message))"; Invoke-VirtualIdle } + Write-Host "Display layout: $restored" + if ($restored -ne 'restored') { Write-Host 'The TV is still off or the restore failed. The virtual screen is left at the TV''s size and scale. When the TV is back: pwsh -File tools\testenv\display.ps1 -Restore' -ForegroundColor Yellow } + } + exit $code + } +} + $sw = [TE]::GetSystemMetrics(0); $sh = [TE]::GetSystemMetrics(1) $resultsDir = Join-Path $PSScriptRoot 'results' if (-not (Test-Path $resultsDir)) { New-Item -ItemType Directory $resultsDir | Out-Null } @@ -160,6 +203,12 @@ $script:abortedOn = $null function Test-NonNegotiable($a, [double]$cap, [bool]$isStress) { $why = @() if (-not $a -or $a.ticks -lt 10) { return @('NO-DATA') } + # Every limit below is calibrated on the 144 Hz TV (a 60 Hz frame alone is over the 12 ms hitch + # line), so a virtual screen is health-only: alive, no device-lost, cap held, plus its own baseline. + if ($script:VirtualProfile) { + if ($a.maxLevel -gt $cap + 0.05) { $why += "level ESCAPED cap $cap : $($a.maxLevel)" } + return $why + } if ($a.dtP99 -and $a.dtP99 -gt 25.0) { $why += "dtP99=$($a.dtP99)ms" } # HITCHING, calibrated against what this rig actually produces rather than a round number. # A healthy transform scenario runs dtP99 8.5-9.3ms with 0-4 hitches; the 25ms ceiling above @@ -425,6 +474,9 @@ $ramLeak = [math]::Round($ramSamples['end'] - $ramSamples['start'], 1) # ---- verdicts ------------------------------------------------------------------------------- # Absolute floors catch catastrophes even with no baseline; baselines tighten per-scenario. $baselines = if (Test-Path $baselinePath) { Get-Content $baselinePath -Raw | ConvertFrom-Json } else { $null } +# The top-level scenarios are the TV's; each virtual screen has its own under profiles.. +$baseScen = if (-not $baselines) { $null } elseif ($script:VirtualProfile) { $baselines.profiles.($script:VirtualProfile).scenarios } else { $baselines.scenarios } +if ($script:VirtualProfile -and -not $baseScen) { Write-Host "No baseline for $script:VirtualProfile yet: health-only." -ForegroundColor Yellow } $rows = @(); $fails = 0 foreach ($ph in $phases) { $a = $analysis[$ph.name] @@ -435,8 +487,8 @@ foreach ($ph in $phases) { $isStress = $ph.prog -in @('overzoom','zoomstorm','slam','flick','rezoom') $nn = @(Test-NonNegotiable $a $maxLevel $isStress) if ($nn.Count -gt 0 -and $nn[0] -ne 'NO-DATA') { $verdict = 'FAIL'; $why += $nn } - if ($baselines -and $baselines.scenarios.($ph.name)) { - $b = $baselines.scenarios.($ph.name) + if ($baseScen -and $baseScen.($ph.name)) { + $b = $baseScen.($ph.name) if ($a.dtP99 -and $b.dtP99 -and $a.dtP99 -gt $b.dtP99 * 1.6 + 2) { $verdict = 'FAIL'; $why += "dtP99 $($a.dtP99) vs base $($b.dtP99)" } if ($a.jitP95 -and $b.jitP95 -and $a.jitP95 -gt $b.jitP95 * 1.6 + 3) { $verdict = 'FAIL'; $why += "jitP95 $($a.jitP95) vs base $($b.jitP95)" } if ($a.hitches -ne $null -and $b.hitches -ne $null -and $a.hitches -gt ($b.hitches + 5) * 2) { $verdict = 'FAIL'; $why += "hitches $($a.hitches) vs base $($b.hitches)" } @@ -489,6 +541,7 @@ if ($healthBad.Count -eq 0) { Write-Host 'Health: alive, dwm intact, no stranded # ---- outputs -------------------------------------------------------------------------------- $result = [ordered]@{ suite = $Suite; stamp = $stamp; hz = $hz + display = $(if ($script:VirtualProfile) { $script:VirtualProfile } else { 'tv' }) ramStartMB = $ramSamples['start']; ramEndMB = $ramSamples['end']; ramDeltaMB = $ramLeak health = $healthBad healthInfo = $healthInfo @@ -507,7 +560,15 @@ if ($UpdateBaseline) { $bl.scenarios[$r.scenario] = [ordered]@{ dtP95=$r.dtP95; dtP99=$r.dtP99; hitches=$r.hitches; devMed=$r.devMed; devP95=$r.devP95; jitP95=$r.jitP95; engine=$r.engine } } } - $bl | ConvertTo-Json -Depth 5 | Set-Content $baselinePath + # One run only ever replaces its own display's numbers. + $profiles = [ordered]@{} + if ($baselines -and $baselines.profiles) { foreach ($p in $baselines.profiles.PSObject.Properties) { $profiles[$p.Name] = $p.Value } } + if ($script:VirtualProfile) { + $profiles[$script:VirtualProfile] = $bl + $bl = [ordered]@{ updated = $baselines.updated; suite = $baselines.suite; scenarios = $baselines.scenarios } + } + if ($profiles.Count) { $bl.profiles = $profiles } + $bl | ConvertTo-Json -Depth 7 | Set-Content $baselinePath Write-Host "Baselines updated: $baselinePath" }