@samitouri / QOSAMI-WSL / commits / b05909c5

Add a command line option to run the tests under verifier (#41440)

* Save state * Save state * Save state * Add a /verifier option to run-tests.ps1 to run the test under verifier

Blue committed Aug 26, 2026 at 18:48 UTC b05909c51b51fc680c7879d60db6b95ad4e157ff
1 file changed +78 -11
tools/test/run-tests.ps1
+78 -11
@@ -48,6 +48,26 @@ if ($Fast)
48 $SetupScript = $null
49 }
50
51 +$Verifier = $false
52 +$VerifierTargets = @(
53 + "wsl.exe",
54 + "wslc.exe",
55 + "wslhost.exe",
56 + "wslrelay.exe",
57 + "wslservice.exe",
58 + "wslg.exe",
59 + "wslcsession.exe",
60 + "dllhost.exe",
61 + "te.exe",
62 + "TE.ProcessHost.exe"
63 +)
64 +
65 +if ($TeArgs -and ($TeArgs -icontains '/verifier'))
66 +{
67 + $TeArgs = @($TeArgs | Where-Object { $_ -ine '/verifier' })
68 + $Verifier = $true
69 +}
70 +
71 # Handle /attachdebugger: verify WinDbgX is available, then add /waitfordebugger so we can find and attach to the test host.
72 $AttachDebugger = $false
73 if ($TeArgs -and ($TeArgs -icontains '/attachdebugger'))
@@ -73,23 +93,70 @@ if ($TeArgs -and ($TeArgs -icontains '/attachdebugger'))
93 $teArgList = @($TestDllPath, "/p:SetupScript=$SetupScript", "/p:Version=$Version", "/p:DistroPath=$DistroPath", "/p:TestDataPath=$TestDataPath",
94 "/p:Package=$Package", "/p:UnitTestsPath=$UnitTestsPath", "/p:PullRequest=$PullRequest", "/p:AllowUnsigned=1") + $TeArgs
95
76 -if ($AttachDebugger)
96 +$verifierTargetsEnabled = @()
97 +$testExitCode = 0
98 +try
99 {
78 - $teProcess = Start-Process -FilePath "te.exe" -ArgumentList $teArgList -PassThru -NoNewWindow
100 + if ($Verifier)
101 + {
102 + foreach ($target in $VerifierTargets)
103 + {
104 + & appverif.exe -verify $target
105 + if ($LASTEXITCODE -ne 0)
106 + {
107 + throw "Failed to enable Application Verifier for $target (exit code: $LASTEXITCODE)."
108 + }
109 +
110 + $verifierTargetsEnabled += $target
111 +
112 + # Required otherwise calls like std::chrono::current_zone() are reported as leaks
113 + & appverif.exe -enable Leak -for $target -with "Leak.ExcludeUCRT=true"
114 + if ($LASTEXITCODE -ne 0)
115 + {
116 + throw "Failed to exclude UCRT allocations from leak detection for $target (exit code: $LASTEXITCODE)."
117 + }
118
80 - # /inproc is always added above, so attach directly to TE.exe.
81 - Write-Host "Launching WinDbgX attached to TE.exe (PID: $($teProcess.Id))..."
82 - Start-Process "WinDbgX.exe" -ArgumentList "-p $($teProcess.Id)"
119 + & appverif.exe -enable Handles -for $target -with "Handles.Traces=65536"
120 + if ($LASTEXITCODE -ne 0)
121 + {
122 + throw "Failed to configure handle tracing for $target (exit code: $LASTEXITCODE)."
123 + }
124 + }
125 + }
126
84 - $teProcess | Wait-Process
85 - exit $teProcess.ExitCode
127 + if ($AttachDebugger)
128 + {
129 + $teProcess = Start-Process -FilePath "te.exe" -ArgumentList $teArgList -PassThru -NoNewWindow
130 +
131 + # /inproc is always added above, so attach directly to TE.exe.
132 + Write-Host "Launching WinDbgX attached to TE.exe (PID: $($teProcess.Id))..."
133 + Start-Process "WinDbgX.exe" -ArgumentList "-p $($teProcess.Id)"
134 +
135 + $teProcess | Wait-Process
136 + $testExitCode = $teProcess.ExitCode
137 + }
138 + else
139 + {
140 + te.exe $teArgList
141 + $testExitCode = $LASTEXITCODE
142 + }
143 }
87 -else
144 +finally
145 {
89 - te.exe $teArgList
90 - if ($LASTEXITCODE -ne 0)
146 + $cleanupFailures = @()
147 + foreach ($target in $verifierTargetsEnabled)
148 + {
149 + & appverif.exe -delete settings -for $target
150 + if ($LASTEXITCODE -ne 0)
151 + {
152 + $cleanupFailures += $target
153 + }
154 + }
155 +
156 + if ($cleanupFailures.Count -ne 0)
157 {
92 - exit $LASTEXITCODE
158 + Write-Error "Failed to disable Application Verifier for: $($cleanupFailures -join ', ')."
159 }
160 }
161
162 +exit $testExitCode