Refactor tests: use TAEF metadata for WSL version filtering#40129
Refactor tests: use TAEF metadata for WSL version filtering#40129benhillis merged 1 commit intofeature/wsl-for-appsfrom
Conversation
d63c10a to
f202d59
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the Windows test suite to use TAEF metadata (WSLVersion) for WSL1/WSL2 applicability, so version-inapplicable tests are excluded at selection time (via /select:) instead of being skipped at runtime.
Changes:
- Introduces
WSL1_TEST_METHOD,WSL2_TEST_METHOD, andWSLC_TEST_METHODmacros that tag test methods withWSLVersionmetadata. - Converts many tests from
TEST_METHOD+WSL1_TEST_ONLY()/WSL2_TEST_ONLY()runtime skips to the new metadata macros. - Updates local and CloudTest runners to add
/select:queries for WSL version filtering.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/test/run-tests.ps1 | Adds automatic /select: filtering by WSL version (when no user selection is provided). |
| test/windows/Common.h | Adds version-tagging test method macros using TAEF properties; removes runtime-only WSL1/WSL2 skip macros. |
| test/windows/WSLCTests.cpp | Migrates many WSLC tests to WSLC_TEST_METHOD and removes most runtime WSL2-only skips. |
| test/windows/WslcSdkTests.cpp | Migrates SDK tests to WSLC_TEST_METHOD. |
| test/windows/UnitTests.cpp | Migrates many WSL1/WSL2-specific tests to WSL1_TEST_METHOD / WSL2_TEST_METHOD. |
| test/windows/SimpleTests.cpp | Migrates a WSL2-only test to WSL2_TEST_METHOD. |
| test/windows/PolicyTests.cpp | Migrates policy tests to WSL2_TEST_METHOD. |
| test/windows/PluginTests.cpp | Migrates plugin tests to WSL1_TEST_METHOD / WSL2_TEST_METHOD. |
| test/windows/NetworkTests.cpp | Migrates most tests to WSL2_TEST_METHOD and adjusts composite “*_TEST_ONLY” helpers accordingly. |
| test/windows/MountTests.cpp | Migrates mount tests to version-tagged methods. |
| test/windows/DrvFsTests.cpp | Migrates DrvFs tests to version-tagged methods and removes runtime version checks from helpers. |
| test/windows/wslc/e2e/WSLCE2ESessionEnterTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EImageTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EImageSaveTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EImageListTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EImageInspectTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EImageDeleteTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EImageBuildTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EGlobalTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EContainerTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EContainerStopTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EContainerRunTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EContainerRemoveTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EContainerListTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EContainerKillTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EContainerExecTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/windows/wslc/e2e/WSLCE2EContainerCreateTests.cpp | Migrates WSLC E2E tests to WSLC_TEST_METHOD. |
| test/README.md | Documents the new version-tagging macros and selection behavior. |
| cloudtest/TestGroup.xml.in | Adds WSL version filtering to non-WSLC CloudTest selection query. |
| cloudtest/TestGroup-wslc.xml.in | Adds WSL version filtering to WSLC CloudTest selection query. |
| $env:TAEF_SELECT = "@WSLVersion='$Version' or not(@WSLVersion='*')" | ||
| te.exe $TestDllPath /p:SetupScript=$SetupScript /p:Version=$Version /p:DistroPath=$DistroPath /p:TestDataPath=$TestDataPath /p:Package=$Package /p:UnitTestsPath=$UnitTestsPath /p:PullRequest=$PullRequest /p:AllowUnsigned=1 @TeArgs --% /select:"%TAEF_SELECT%" |
There was a problem hiding this comment.
The default version filter expression @WSLVersion='$Version' or not(@WSLVersion='*') will not actually filter anything: not(@WSLVersion='*') evaluates true for both missing attributes and non-'*' values (e.g. '1'/'2'), so the whole expression becomes always-true. Also, /select:"%TAEF_SELECT%" won’t expand %TAEF_SELECT% in PowerShell (that’s cmd.exe syntax, and --% disables PowerShell expansion), so TE.exe is likely receiving the literal string %TAEF_SELECT%. Consider passing the filter as a normal PowerShell argument (e.g. using $env:TAEF_SELECT/a local $select variable) and using or not(@WSLVersion) (or equivalent) to include untagged tests.
| $env:TAEF_SELECT = "@WSLVersion='$Version' or not(@WSLVersion='*')" | |
| te.exe $TestDllPath /p:SetupScript=$SetupScript /p:Version=$Version /p:DistroPath=$DistroPath /p:TestDataPath=$TestDataPath /p:Package=$Package /p:UnitTestsPath=$UnitTestsPath /p:PullRequest=$PullRequest /p:AllowUnsigned=1 @TeArgs --% /select:"%TAEF_SELECT%" | |
| $select = "@WSLVersion='$Version' or not(@WSLVersion)" | |
| te.exe $TestDllPath /p:SetupScript=$SetupScript /p:Version=$Version /p:DistroPath=$DistroPath /p:TestDataPath=$TestDataPath /p:Package=$Package /p:UnitTestsPath=$UnitTestsPath /p:PullRequest=$PullRequest /p:AllowUnsigned=1 @TeArgs "/select:$select" |
| $HasUserSelection = $false | ||
| foreach ($arg in $TeArgs) | ||
| { | ||
| if ($arg -like '/name:*' -or $arg -like '/select:*' -or $arg -like '-name:*' -or $arg -like '-select:*') | ||
| { | ||
| $HasUserSelection = $true | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if ($HasUserSelection) |
There was a problem hiding this comment.
The script disables the automatic WSLVersion /select filter when the user passes /name:. Since many tests are now version-tagged (and no longer do runtime WSL1/WSL2 skipping), running a subset by /name: on the “wrong” version may start executing inapplicable tests instead of being filtered out. It would be safer to only treat user-provided /select: as an override, and still append the version /select when only /name: is provided (if TE.exe supports combining them).
| $HasUserSelection = $false | |
| foreach ($arg in $TeArgs) | |
| { | |
| if ($arg -like '/name:*' -or $arg -like '/select:*' -or $arg -like '-name:*' -or $arg -like '-select:*') | |
| { | |
| $HasUserSelection = $true | |
| break | |
| } | |
| } | |
| if ($HasUserSelection) | |
| $HasUserSelectOverride = $false | |
| foreach ($arg in $TeArgs) | |
| { | |
| if ($arg -like '/select:*' -or $arg -like '-select:*') | |
| { | |
| $HasUserSelectOverride = $true | |
| break | |
| } | |
| } | |
| if ($HasUserSelectOverride) |
Replace runtime WSL2_TEST_ONLY()/WSL1_TEST_ONLY() skip macros with TAEF metadata-based test selection. Tests that don't apply to the current WSL version are now excluded by /select: queries at selection time rather than skipped at runtime, eliminating hundreds of 'skipped' results from test output. Changes: - Add WSL2_TEST_METHOD, WSL1_TEST_METHOD, WSLC_TEST_METHOD macros in Common.h that tag tests with WSLVersion metadata property - Convert ~430 test methods across 26 files to use new macros - Update run-tests.ps1 to auto-add /select: version filter - Update CloudTest XML configs with version selection queries - Remove WSL2_TEST_ONLY() from composite macros in NetworkTests.cpp - Update test README with new macro documentation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f202d59 to
64354b2
Compare
|
|
||
| <TestJob Name="CloudTest.Taef" TimeoutMins="120"> | ||
| <Execution Type="TAEF" Path="[WorkingDirectory]\wsltests.dll" Args="/p:bugReportDirectory=[LoggingDirectory]\BugReportOutput /errorOnCrash /testmode:etwlogger /EtwLogger:WPRProfileFile=[WorkingDirectory]\wsl.wprp /EtwLogger:WPRProfile=WSL /EtwLogger:SavePoint=ExecutionComplete /EtwLogger:RecordingScope=Execution /p:SetupScript=.\test-setup.ps1 /p:Package=[WorkingDirectory]\Microsoft.WSL_${PACKAGE_VERSION}_x64_ARM64.msixbundle /p:Version=2 /p:AllowUnsigned=${ALLOW_UNSIGNED_PACKAGE} /p:UnitTestsPath=[WorkingDirectory]\unit_tests /p:DistroPath=[WorkingDirectory]\test_distro.tar.xz /p:TestDataPath=[WorkingDirectory]\test_data /p:DistroName=test_distro /logOutput:High /p:RedirectStdout=[LoggingDirectory]\stdout.txt /p:RedirectStderr=[LoggingDirectory]\stderr.txt /p:KernelLogs=[LoggingDirectory]\dmesg.txt /p:DumpFolder=[LoggingDirectory] /p:WerReport /p:LogDmesg /p:PipelineBuildId=${PIPELINE_BUILD_ID} /p:DumpTool=DumpTool.exe /select:"@TestCategory='WSLC'"" /> | ||
| <Execution Type="TAEF" Path="[WorkingDirectory]\wsltests.dll" Args="/p:bugReportDirectory=[LoggingDirectory]\BugReportOutput /errorOnCrash /testmode:etwlogger /EtwLogger:WPRProfileFile=[WorkingDirectory]\wsl.wprp /EtwLogger:WPRProfile=WSL /EtwLogger:SavePoint=ExecutionComplete /EtwLogger:RecordingScope=Execution /p:SetupScript=.\test-setup.ps1 /p:Package=[WorkingDirectory]\Microsoft.WSL_${PACKAGE_VERSION}_x64_ARM64.msixbundle /p:Version=2 /p:AllowUnsigned=${ALLOW_UNSIGNED_PACKAGE} /p:UnitTestsPath=[WorkingDirectory]\unit_tests /p:DistroPath=[WorkingDirectory]\test_distro.tar.xz /p:TestDataPath=[WorkingDirectory]\test_data /p:DistroName=test_distro /logOutput:High /p:RedirectStdout=[LoggingDirectory]\stdout.txt /p:RedirectStderr=[LoggingDirectory]\stderr.txt /p:KernelLogs=[LoggingDirectory]\dmesg.txt /p:DumpFolder=[LoggingDirectory] /p:WerReport /p:LogDmesg /p:PipelineBuildId=${PIPELINE_BUILD_ID} /p:DumpTool=DumpTool.exe /select:"@TestCategory='WSLC' and (@WSLVersion='2' or not(@WSLVersion='*'))"" /> |
There was a problem hiding this comment.
nit: I think that was discussed on a previous PR, but I'd have a preference for having only one template file and using different variables to configure the filters we want
There was a problem hiding this comment.
yeah we can change that in a follow-up.
Replace runtime WSL2_TEST_ONLY()/WSL1_TEST_ONLY() skip macros with TAEF metadata-based test selection. Tests that don't apply to the current WSL version are now excluded by /select: queries at selection time rather than skipped at runtime, eliminating hundreds of 'skipped' results from test output.
Changes: