Skip to content

Commit 2d55b36

Browse files
authored
Enable WinUI tests (#2487)
1 parent cf4aba3 commit 2d55b36

47 files changed

Lines changed: 1352 additions & 352 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/AzurePipelineTemplates/CsWinRT-BuildAndTest-Stage-GitHub.yml

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ stages:
7979
# that can't run in the other environment.
8080
- job: Tests
8181
displayName: Run Tests
82-
condition: false
82+
condition: succeeded()
8383
dependsOn: []
8484
timeoutInMinutes: 120
8585
strategy:
@@ -101,13 +101,26 @@ stages:
101101
path: 's\src\TestWinRT'
102102
displayName: "Checkout TestWinRT"
103103

104-
# Build Steps
104+
# Build Steps
105105
- template: CsWinRT-Build-Steps.yml@self
106106
parameters:
107107
BuildConfiguration: $(BuildConfiguration)
108108
BuildPlatform: $(BuildPlatform)
109109
SetupForBuildOnly: true
110110

111+
# Build just the CsWinRT build tooling (generator exes + WinRT.Generator.Tasks.dll)
112+
# and WinRT.Internal (WindowsRuntime.Internal.winmd), which the standalone "Build
113+
# Object Lifetime Tests" step below needs. Build by target name so the solution's
114+
# BuildDependency ordering and x64->AnyCPU platform mapping apply.
115+
- task: MSBuild@1
116+
displayName: Build CsWinRT build tooling
117+
condition: succeeded()
118+
inputs:
119+
solution: $(Build.SourcesDirectory)\src\cswinrt.slnx
120+
msbuildArguments: /restore /t:WinRT_Generator_Tasks;WinRT_Impl_Generator;WinRT_Interop_Generator;WinRT_Projection_Generator;WinRT_Projection_Ref_Generator;WinRT_WinMD_Generator;WinRT_Internal /p:CIBuildReason=CI,VersionNumber=$(VersionNumber),VersionString=$(Build.BuildNumber),AssemblyVersionNumber=$(WinRT.Runtime.AssemblyVersion),PublishBuildTool=true,BuildToolArch=$(CsWinRTBuildToolsArch)
121+
platform: $(BuildPlatform)
122+
configuration: $(BuildConfiguration)
123+
111124
- task: MSBuild@1
112125
displayName: Build Object Lifetime Tests
113126
condition: succeeded()
@@ -117,20 +130,67 @@ stages:
117130
platform: $(BuildPlatform)
118131
configuration: $(BuildConfiguration)
119132

120-
# Run Object Lifetime Tests
133+
# Run Object Lifetime Tests via VSTest. Currently DISABLED: VSTest discovery finds 0 tests because
134+
# MSTest.TestAdapter.dll's module initializer (MSTestExecutor.SetPlatformLogger) references the CsWinRT
135+
# 2.x type WinRT.ComWrappersSupport, which no longer exists in the CsWinRT 3.0 WinRT.Runtime (3.0.0.0)
136+
# the app deploys. The adapter's <Module> initializer throws TypeLoadException, VSTest skips the whole
137+
# adapter, and reports "No test is available". Root-caused from the vstest.console /Diag log. Kept (not
138+
# removed) so it can be re-enabled once a CsWinRT 3.0-compatible MSTest adapter is available. Use the
139+
# in-process runner below in the meantime.
121140
- task: VSTest@3
122141
displayName: Run Object Lifetime Tests
142+
enabled: false
123143
condition: succeeded()
144+
continueOnError: true
124145
inputs:
125-
testAssemblyVer2: Tests\ObjectLifetimeTests\bin\$(BuildPlatform)\$(BuildConfiguration)\net10.0-windows10.0.19041.0\win-$(BuildPlatform)\ObjectLifetimeTests.Lifted.build.appxrecipe
146+
testAssemblyVer2: Tests\ObjectLifetimeTests\bin\$(BuildPlatform)\$(BuildConfiguration)\net10.0-windows10.0.26100.1\win-$(BuildPlatform)\ObjectLifetimeTests.Lifted.build.appxrecipe
126147
searchFolder: $(Build.SourcesDirectory)\src
148+
resultsFolder: $(StagingFolder)\TestResults
149+
otherConsoleOptions: /Diag:$(StagingFolder)\vstest-diag\log.txt
127150

128-
# Run Source Generator Tests
129-
- task: DotNetCoreCLI@2
130-
displayName: Run Source Generator Tests
151+
# Run Object Lifetime Tests in-process by launching the packaged app directly (no --parentprocessid),
152+
# which exercises App.OnLaunched's RunTestsInProcess path; the app self-exits with the pass/fail code.
153+
# This is the actual test gate while VSTest discovery is broken (see above).
154+
- task: PowerShell@2
155+
displayName: Run Object Lifetime Tests (In-Process)
131156
condition: succeeded()
157+
# Some tests currently fail on CsWinRT 3.0; don't fail the pipeline on test failures for now.
158+
continueOnError: true
132159
inputs:
133-
command: test
134-
projects: 'src/Tests/SourceGeneratorTest/SourceGeneratorTest.csproj'
135-
arguments: --diag $(StagingFolder)\unittest\test.log --logger trx;LogFilePath=UNITTEST-$(Build.BuildNumber).trx /nologo /m /p:configuration=$(BuildConfiguration);CIBuildReason=CI;solutiondir=$(Build.SourcesDirectory)\src\;VersionNumber=$(VersionNumber);VersionString=$(Build.BuildNumber);AssemblyVersionNumber=$(WinRT.Runtime.AssemblyVersion) -- RunConfiguration.TreatNoTestsAsError=true
136-
testRunTitle: Unit Tests
160+
targetType: filePath
161+
filePath: $(Build.SourcesDirectory)\build\scripts\Run-ObjectLifetimeInProcess.ps1
162+
arguments: -LayoutDir "$(Build.SourcesDirectory)\src\Tests\ObjectLifetimeTests\bin\$(BuildPlatform)\$(BuildConfiguration)\net10.0-windows10.0.26100.1\win-$(BuildPlatform)" -OutputDir "$(StagingFolder)\ObjectLifetime-InProc"
163+
164+
# Echo the vstest.console /Diag logs to the build log and publish them. DISABLED alongside the VSTest
165+
# step above; re-enable together with it.
166+
- task: PowerShell@2
167+
displayName: Collect VSTest diagnostics
168+
enabled: false
169+
condition: succeededOrFailed()
170+
continueOnError: true
171+
inputs:
172+
targetType: inline
173+
script: |
174+
$dest = Join-Path "$(StagingFolder)" 'vstest-diag'
175+
New-Item -ItemType Directory -Force $dest | Out-Null
176+
$patterns = 'log.*.txt','*.host.*.txt','*.datacollector.*.txt','*.diag'
177+
$files = Get-ChildItem $dest -Recurse -File -Include $patterns -ErrorAction SilentlyContinue
178+
if (-not $files) {
179+
# Fallback: /Diag may have been ignored; scrape the default results/temp dirs.
180+
$roots = @("$(Agent.TempDirectory)", "$(Common.TestResultsDirectory)") | Where-Object { $_ -and (Test-Path $_) } | Select-Object -Unique
181+
$files = foreach ($r in $roots) { Get-ChildItem $r -Recurse -File -Include $patterns -ErrorAction SilentlyContinue }
182+
$files | ForEach-Object { Copy-Item $_.FullName $dest -Force -ErrorAction SilentlyContinue }
183+
}
184+
if (-not $files) { Write-Host "No VSTest diagnostics found."; return }
185+
foreach ($f in ($files | Sort-Object FullName -Unique)) {
186+
Write-Host "===== $($f.Name) ====="
187+
Get-Content $f.FullName -ErrorAction SilentlyContinue | ForEach-Object { Write-Host $_ }
188+
}
189+
190+
templateContext:
191+
outputs:
192+
- output: pipelineArtifact
193+
displayName: 'Publish Test artifacts'
194+
condition: succeededOrFailed()
195+
targetPath: $(StagingFolder)
196+
artifactName: drop_Tests_$(BuildConfiguration)

build/AzurePipelineTemplates/CsWinRT-BuildAndTest-Stage-OneBranch.yml

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ jobs:
5151
BuildConfiguration: $(BuildConfiguration)
5252
BuildPlatform: $(BuildPlatform)
5353

54-
# - template: CsWinRT-Test-Steps.yml@self
55-
# parameters:
56-
# BuildConfiguration: $(BuildConfiguration)
57-
# BuildPlatform: $(BuildPlatform)
54+
- template: CsWinRT-Test-Steps.yml@self
5855

5956
# Signing
6057
- task: onebranch.pipeline.signing@1
@@ -126,7 +123,7 @@ jobs:
126123
# that can't run in the other environment.
127124
- job: Tests
128125
displayName: Run Tests
129-
condition: false
126+
condition: succeeded()
130127
dependsOn: []
131128
pool:
132129
type: windows
@@ -154,35 +151,87 @@ jobs:
154151
displayName: "Checkout TestWinRT"
155152

156153
# Build Steps
154+
# Build just the CsWinRT build tooling (generator exes + WinRT.Generator.Tasks.dll)
155+
# and WinRT.Internal (WindowsRuntime.Internal.winmd), which the standalone "Build
156+
# Object Lifetime Tests" step below needs. Build by target name so the solution's
157+
# BuildDependency ordering and x64->AnyCPU platform mapping apply.
157158
- template: CsWinRT-Build-Steps.yml@self
158159
parameters:
159160
BuildConfiguration: $(BuildConfiguration)
160161
BuildPlatform: $(BuildPlatform)
161162
SetupForBuildOnly: true
162163

164+
- task: MSBuild@1
165+
displayName: Build CsWinRT build tooling
166+
condition: succeeded()
167+
inputs:
168+
solution: $(Build.SourcesDirectory)\src\cswinrt.slnx
169+
msbuildArguments: /restore /t:WinRT_Generator_Tasks;WinRT_Impl_Generator;WinRT_Interop_Generator;WinRT_Projection_Generator;WinRT_Projection_Ref_Generator;WinRT_WinMD_Generator;WinRT_Internal /p:CIBuildReason=CI,VersionNumber=$(VersionNumber),VersionString=$(Build.BuildNumber),AssemblyVersionNumber=$(WinRT.Runtime.AssemblyVersion),PublishBuildTool=true,BuildToolArch=$(CsWinRTBuildToolsArch)
170+
platform: $(BuildPlatform)
171+
configuration: $(BuildConfiguration)
172+
163173
- task: MSBuild@1
164174
displayName: Build Object Lifetime Tests
165175
condition: succeeded()
166176
inputs:
167177
solution: $(Build.SourcesDirectory)\src\Tests\ObjectLifetimeTests\ObjectLifetimeTests.Lifted.csproj
168-
msbuildArguments: /restore /p:CIBuildReason=CI,solutiondir=$(Build.SourcesDirectory)\src\,VersionNumber=$(VersionNumber),VersionString=$(Build.BuildNumber),AssemblyVersionNumber=$(WinRT.Runtime.AssemblyVersion),GenerateTestProjection=true,AllowedReferenceRelatedFileExtensions=".xml;.pri;.dll.config;.exe.config"
178+
msbuildArguments: /restore /p:CIBuildReason=CI,solutiondir=$(Build.SourcesDirectory)\src\,VersionNumber=$(VersionNumber),VersionString=$(Build.BuildNumber),AssemblyVersionNumber=$(WinRT.Runtime.AssemblyVersion),GenerateTestProjection=true,AllowedReferenceRelatedFileExtensions=".xml;.pri;.dll.config;.exe.config",PublishBuildTool=true,BuildToolArch=$(CsWinRTBuildToolsArch)
169179
platform: $(BuildPlatform)
170180
configuration: $(BuildConfiguration)
171181

172-
# Run Object Lifetime Tests
182+
# Run Object Lifetime Tests via VSTest. Currently DISABLED: VSTest discovery finds 0 tests because
183+
# MSTest.TestAdapter.dll's module initializer (MSTestExecutor.SetPlatformLogger) references the CsWinRT
184+
# 2.x type WinRT.ComWrappersSupport, which no longer exists in the CsWinRT 3.0 WinRT.Runtime (3.0.0.0)
185+
# the app deploys. The adapter's <Module> initializer throws TypeLoadException, VSTest skips the whole
186+
# adapter, and reports "No test is available". Root-caused from the vstest.console /Diag log. Kept (not
187+
# removed) so it can be re-enabled once a CsWinRT 3.0-compatible MSTest adapter is available. Use the
188+
# in-process runner below in the meantime.
173189
- task: VSTest@3
174190
displayName: Run Object Lifetime Tests
191+
enabled: false
175192
condition: succeeded()
193+
continueOnError: true
176194
inputs:
177-
testAssemblyVer2: Tests\ObjectLifetimeTests\bin\$(BuildPlatform)\$(BuildConfiguration)\net10.0-windows10.0.19041.0\win-$(BuildPlatform)\ObjectLifetimeTests.Lifted.build.appxrecipe
195+
testAssemblyVer2: Tests\ObjectLifetimeTests\bin\$(BuildPlatform)\$(BuildConfiguration)\net10.0-windows10.0.26100.1\win-$(BuildPlatform)\ObjectLifetimeTests.Lifted.build.appxrecipe
178196
searchFolder: $(Build.SourcesDirectory)\src
197+
resultsFolder: $(StagingFolder)\TestResults
198+
otherConsoleOptions: /Diag:$(StagingFolder)\vstest-diag\log.txt
179199

180-
# Run Source Generator Tests
181-
- task: DotNetCoreCLI@2
182-
displayName: Run Source Generator Tests
200+
# Run Object Lifetime Tests in-process by launching the packaged app directly (no --parentprocessid),
201+
# which exercises App.OnLaunched's RunTestsInProcess path; the app self-exits with the pass/fail code.
202+
# This is the actual test gate while VSTest discovery is broken (see above).
203+
- task: PowerShell@2
204+
displayName: Run Object Lifetime Tests (In-Process)
183205
condition: succeeded()
206+
# Some tests currently fail on CsWinRT 3.0; don't fail the pipeline on test failures for now.
207+
continueOnError: true
208+
inputs:
209+
targetType: filePath
210+
filePath: $(Build.SourcesDirectory)\build\scripts\Run-ObjectLifetimeInProcess.ps1
211+
arguments: -LayoutDir "$(Build.SourcesDirectory)\src\Tests\ObjectLifetimeTests\bin\$(BuildPlatform)\$(BuildConfiguration)\net10.0-windows10.0.26100.1\win-$(BuildPlatform)" -OutputDir "$(StagingFolder)\ObjectLifetime-InProc"
212+
213+
# Echo the vstest.console /Diag logs to the build log and publish them (via ob_outputDirectory auto-
214+
# publish). DISABLED alongside the VSTest step above; re-enable together with it.
215+
- task: PowerShell@2
216+
displayName: Collect VSTest diagnostics
217+
enabled: false
218+
condition: succeededOrFailed()
219+
continueOnError: true
184220
inputs:
185-
command: test
186-
projects: 'src/Tests/SourceGeneratorTest/SourceGeneratorTest.csproj'
187-
arguments: --diag $(StagingFolder)\unittest\test.log --logger trx;LogFilePath=UNITTEST-$(Build.BuildNumber).trx /nologo /m /p:configuration=$(BuildConfiguration);CIBuildReason=CI;solutiondir=$(Build.SourcesDirectory)\src\;VersionNumber=$(VersionNumber);VersionString=$(Build.BuildNumber);AssemblyVersionNumber=$(WinRT.Runtime.AssemblyVersion) -- RunConfiguration.TreatNoTestsAsError=true
188-
testRunTitle: Unit Tests
221+
targetType: inline
222+
script: |
223+
$dest = Join-Path "$(StagingFolder)" 'vstest-diag'
224+
New-Item -ItemType Directory -Force $dest | Out-Null
225+
$patterns = 'log.*.txt','*.host.*.txt','*.datacollector.*.txt','*.diag'
226+
$files = Get-ChildItem $dest -Recurse -File -Include $patterns -ErrorAction SilentlyContinue
227+
if (-not $files) {
228+
# Fallback: /Diag may have been ignored; scrape the default results/temp dirs.
229+
$roots = @("$(Agent.TempDirectory)", "$(Common.TestResultsDirectory)") | Where-Object { $_ -and (Test-Path $_) } | Select-Object -Unique
230+
$files = foreach ($r in $roots) { Get-ChildItem $r -Recurse -File -Include $patterns -ErrorAction SilentlyContinue }
231+
$files | ForEach-Object { Copy-Item $_.FullName $dest -Force -ErrorAction SilentlyContinue }
232+
}
233+
if (-not $files) { Write-Host "No VSTest diagnostics found."; return }
234+
foreach ($f in ($files | Sort-Object FullName -Unique)) {
235+
Write-Host "===== $($f.Name) ====="
236+
Get-Content $f.FullName -ErrorAction SilentlyContinue | ForEach-Object { Write-Host $_ }
237+
}

build/AzurePipelineTemplates/CsWinRT-Test-Steps.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ steps:
2222
--no-build
2323
testRunTitle: Unit Tests
2424

25-
# Run Source Generator 2 Tests
25+
# Run Source Generator 2 Tests. Gated to x64 only: these are Roslyn analyzer/source-generator tests,
26+
# which are architecture-independent (the compiler runs the analyzer the same regardless of the target
27+
# platform), so running them x86 adds no coverage. The x86 (32-bit) test host loads the full .NET 10
28+
# reference pack plus WinUI/CsWinRT references across 100+ cases and exhausts the ~2-4 GB address space
29+
# on memory-constrained pools (e.g. the OneBranch managed pool), throwing OutOfMemoryException.
2630
- task: DotNetCoreCLI@2
2731
displayName: Run Source Generator 2 Tests
28-
condition: and(succeeded(), or(eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildPlatform'], 'x64')))
32+
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x64'))
2933
inputs:
3034
command: test
3135
projects: 'src/Tests/SourceGenerator2Test/SourceGenerator2Test.csproj'
@@ -85,7 +89,7 @@ steps:
8589
# Run WUX Tests
8690
- task: CmdLine@2
8791
displayName: Run WUX Tests
88-
enabled: false
92+
enabled: true
8993
condition: and(succeeded(), or(eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildPlatform'], 'x64')))
9094
continueOnError: True
9195
inputs:

build/AzurePipelineTemplates/CsWinRT-Variables.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ variables:
1111
- name: NoSamples
1212
value: 'false'
1313
- name: _DotnetVersion
14-
value: '10.0.106'
14+
value: '10.0.109'
1515

1616
# This 'coalesce' pattern allows the yml to define a default value for a variable but allows the value to be overridden at queue time.
1717
# E.g. '_IsRelease' defaults to empty string, but if 'IsRelease' is set at queue time that value will be used.

0 commit comments

Comments
 (0)