forked from microsoft/microsoft-ui-xaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunTestsOnTShellConnectedDevice.ps1
259 lines (221 loc) · 8.86 KB
/
RunTestsOnTShellConnectedDevice.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
[CmdletBinding()]
param(
[switch]$NoRun,
[switch]$NoDeploy,
[switch]$NoBuild,
[switch]$ForceDeploy,
[switch]$LogVerbose,
[switch]$LogSuperVerbose,
[switch]$Release,
[Alias("L")][switch]$List,
[Alias("CC")][switch]$CodeCoverage,
[String[]]$Name,
[String[]]$xName,
[String]$Flavor = "Debug",
[String]$Platform = "x86",
[String]$MinVersion,
[switch]$dllOnly,
[switch]$appxOnly,
[switch]$waitForDebugger,
[switch]$waitForAppDebugger,
[int]$Iterations = 1,
[string]$LogFile = "TestResults.out",
[String]$OutputPath = "$PSScriptRoot\CodeCoverageOutput",
[String]$TestTimeout,
[String]$MagellanInstallPath = "$env:USERPROFILE\.nuget\packages\microsoft.internal.magellan\5.4.170227001-pkges"
)
#
# NOTE: This file currently relies on TShell to execute commands on a remote machine, which is not available externally.
# Use Open-Device to connect to a remote machine, then run this script to run tests on that machine.
# TODO 19757865: Change this so that it no longer has a dependency on TShell.
#
if (!(test-path variable:\DeviceAddress))
{
Write-Host "";
Write-Host "DeviceAddress variable is not set -- are you connected to a device?" -foregroundcolor red
Write-Host "";
return;
}
$deviceDir = "c:\data\test\bin"
$ignoredOutput = cmdd if not exist $deviceDir mkdir $deviceDir
if(!$NoDeploy)
{
$testSuite = "DevTest"
if($Release)
{
$testSuite = "NugetPkgTests"
}
& .\CreateTestBinariesDirFromBuild.ps1 -NoBuild:$NoBuild -TestSuite:$testSuite -Flavor:$Flavor -Platform:$Platform
}
# If we're doing a code coverage run, let's instrument the binaries now.
if ($CodeCoverage)
{
Invoke-Expression "$PSScriptRoot\tools\CodeCoverage\InstrumentBinaries.ps1 -BuildPlatform $Platform -BuildConfiguration $Flavor"
}
# Always copy over the test files.
$repoDirectory = Split-Path -Parent $script:MyInvocation.MyCommand.Path
if(!$NoDeploy)
{
$payloadDir = Join-Path $repoDirectory "HelixPayload\$flavor\$platform\*"
Write-Host "Copying files from '$payloadDir' to device";
$putDOutput += putd -Recurse $payloadDir $deviceDir
}
# Make watson keep dumps offline locally. We will check after the tests run to see if there were any dumps.
$regdOutput += regd add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v DisableArchive /t REG_DWORD /d 0
$regdOutput += regd add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v Disabled /t REG_DWORD /d 0
$regdOutput += regd add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v BypassDataThrottling /t REG_DWORD /d 1
$regdOutput += regd add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v ConfigureArchive /t REG_DWORD /d 2
$regdOutput += regd add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Windows Error Reporting\LocalDumps" /v DumpType /t REG_DWORD /d 2
$regdOutput += regd add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\DataCollection" /v AllowTelemetry /t REG_DWORD /d 3
# Get a snapshot of the dump folder before we start running tests
$WERArchiveBeforeRun = ((cmdd dir /s /b "%programdata%\microsoft\windows\wer\reportarchive\*.zip" -HideOutput).Output -split "\r\n")
cdd $deviceDir
if (!$NoRun)
{
if ($CodeCoverage)
{
Write-Host "Starting code coverage..."
execd cmd -AsUser -Arguments "/c %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File $deviceDir\StartCodeCoverage.ps1 -MagellanInstallPath $deviceDir\Magellan"
}
$teCmd = "execd ""$deviceDir\TE.exe"" -DeviceLogPath $LogFile -Arguments """
$selectQuery = @()
if (!$appxOnly)
{
if(!$Release)
{
$teCmd += " MUXControls.Test.dll"
}
else
{
$teCmd += " MUXControls.ReleaseTest.dll"
}
}
if (!$dllOnly)
{
if(!$Release)
{
$teCmd += " MUXControlsTestApp.appx /APPX:CertificateFileName=MUXControlsTestApp.cer";
$teCmd += " IXMPTestApp.appx /APPX:CertificateFileName=IXMPTestApp.cer";
}
}
if ($Name)
{
$nameCondition = ($Name | % { "@Name='*$_*'" }) -join " OR "
$selectQuery += "$nameCondition"
}
if ($MinVersion)
{
$selectQuery += "@MinVersion='$MinVersion' OR not(@MinVersion=*)"
}
if($selectQuery)
{
$teCmd += " /select:""""$(($selectQuery | % { "($_)" }) -join " AND ")"""""
}
if ($LogVerbose -or $LogSuperVerbose)
{
$teCmd += " /logOutput:High /p:LogVerbose";
}
if ($LogSuperVerbose)
{
$teCmd += " /p:LogSuperVerbose";
}
if ($List)
{
$teCmd += " /list";
}
if ($waitForDebugger)
{
$teCmd += " /p:WaitForDebugger";
}
if ($waitForAppDebugger)
{
$teCmd += " /p:WaitForAppDebugger";
}
if ($TestTimeout)
{
$teCmd += " /testtimeout:$TestTimeout";
}
else
{
# Don't set a timeout if someone is attaching a debugger. We don't want the test to be killed while
# it is in the middle of being debugged.
if(!$waitForDebugger -and !$waitForAppDebugger)
{
$teCmd += " /testtimeout:0:01";
}
}
if ($Iterations -ne 1)
{
$teCmd += " /testmode:loop /looptest:$Iterations"
}
$teCmd += " /screenCaptureOnError""";
Write-Host
Write-Host "Running '$teCmd'";
Write-Host
Invoke-Expression $teCmd | Set-Variable TEOutput;
if ($TEOutput.ExitCode -ne 0)
{
Write-Host ("ERROR: TE.exe returned error code {0}" -f $TEOutput.ExitCode);
}
if ($CodeCoverage)
{
Write-Host "Stopping code coverage..."
execd cmd -AsUser -Arguments "/c %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File $deviceDir\StopCodeCoverage.ps1 -TestSuite Integration -MagellanInstallPath $deviceDir\Magellan" 1> $null
Write-Host
if ($TEOutput.ExitCode -eq 0)
{
Write-Host "Gathering code coverage data..."
if (-not (Test-Path "$OutputPath"))
{
New-Item "$OutputPath" -ItemType Directory
}
Copy-Item "BuildOutput\$Flavor\$platform\Microsoft.UI.Xaml\instr\*.covsym" "$OutputPath\" 1> $null
getd "C:\ProgramData\Coverage\microsoft.ui.xaml.dll\*.covdata" "$OutputPath\" 1> $null
Write-Host "Creating code coverage report..."
Invoke-Expression "$PSScriptRoot\tools\CodeCoverage\CreateCodeCoverageReport.ps1 -MagellanInstallPath `"$MagellanInstallPath`" -covSymPath `"$OutputPath`" -covDataPath `"$OutputPath`" -coverageSummaryOutputPath `"$OutputPath\Summary`" -coverageReportOutputPath `"$OutputPath\Report`" -isLocalRun" 1> $null
if (Test-Path $OutputPath\Report\index.html)
{
Write-Host "Code coverage report written to $OutputPath\Report."
$shouldOpenReport = ""
while ($shouldOpenReport -inotlike "y" -and $shouldOpenReport -inotlike "n")
{
$shouldOpenReport = Read-Host "Open report? (y/n)"
}
if ($shouldOpenReport -ilike "y")
{
Start-Process -FilePath "$OutputPath\Report\index.html"
}
}
}
else
{
Write-Host "Test failures detected. Skipping code coverage data gathering."
}
}
}
# If we were doing a code coverage run, let's put back the old test appx now.
if ($CodeCoverage -and (Test-Path "$testAppOutputDir\AppPackages\MUXControlsTestApp_Test\MUXControlsTestApp.appx.orig"))
{
Remove-Item "$testAppOutputDir\AppPackages\MUXControlsTestApp_Test\MUXControlsTestApp.appx"
Rename-Item "$testAppOutputDir\AppPackages\MUXControlsTestApp_Test\MUXControlsTestApp.appx.orig" "$testAppOutputDir\AppPackages\MUXControlsTestApp_Test\MUXControlsTestApp.appx"
}
# Check for dumps
$WERArchiveAfterRun = ((cmdd dir /s /b "%programdata%\microsoft\windows\wer\reportarchive\*.zip" -HideOutput).Output -split "\r\n")
$NewCabs = $WERArchiveAfterRun | Where-Object { -not $WERArchiveBeforeRun.Contains($_) }
Write-Verbose "Before cabs: $WERArchiveBeforeRun"
Write-Verbose "After cabs: $WERArchiveAfterRun"
Write-Verbose "New cabs = $NewCabs"
if ($NewCabs)
{
Write-Host "Error: Dumps found during test run" -foregroundcolor Red
$LocalDumpPath = "$PSScriptRoot\DumpFiles"
if (-not (Test-Path $LocalDumpPath)) { New-Item -Force $LocalDumpPath -ItemType Directory }
foreach ($NewCab in $NewCabs)
{
# Make the filename the archive directory name (instead of "report.zip")
$fileName = Split-Path (Split-Path $NewCab) -Leaf
$localFilePath = "$LocalDumpPath\$fileName.zip"
$ignored = Get-Device $NewCab -Destination $localFilePath
Write-Host "CAB: $localFilePath" -foregroundcolor Red
}
}