Skip to content

Refactor tests: use TAEF metadata for WSL version filtering#40129

Merged
benhillis merged 1 commit intofeature/wsl-for-appsfrom
user/benhill/test_metadata
Apr 9, 2026
Merged

Refactor tests: use TAEF metadata for WSL version filtering#40129
benhillis merged 1 commit intofeature/wsl-for-appsfrom
user/benhill/test_metadata

Conversation

@benhillis
Copy link
Copy Markdown
Member

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

@benhillis benhillis requested a review from a team as a code owner April 7, 2026 20:05
Copilot AI review requested due to automatic review settings April 7, 2026 20:05
@benhillis benhillis force-pushed the user/benhill/test_metadata branch from d63c10a to f202d59 Compare April 7, 2026 20:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and WSLC_TEST_METHOD macros that tag test methods with WSLVersion metadata.
  • 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.

Comment thread tools/test/run-tests.ps1
Comment on lines +67 to +68
$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%"
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
$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"

Copilot uses AI. Check for mistakes.
Comment thread tools/test/run-tests.ps1
Comment on lines +51 to +61
$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)
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
$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)

Copilot uses AI. Check for mistakes.
Comment thread cloudtest/TestGroup.xml.in
Comment thread cloudtest/TestGroup-wslc.xml.in
Comment thread test/windows/WSLCTests.cpp
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>
@benhillis benhillis force-pushed the user/benhill/test_metadata branch from f202d59 to 64354b2 Compare April 7, 2026 21:22
Copy link
Copy Markdown
Member Author

@benhillis benhillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dismissing Copilot bot comments — all 5 are either incorrect or not actionable.


<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:&quot;@TestCategory='WSLC'&quot;" />
<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:&quot;@TestCategory='WSLC' and (@WSLVersion='2' or not(@WSLVersion='*'))&quot;" />
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we can change that in a follow-up.

@benhillis benhillis merged commit 9c4dba9 into feature/wsl-for-apps Apr 9, 2026
7 checks passed
benhillis pushed a commit that referenced this pull request Apr 9, 2026
Replace WSL2_TEST_ONLY() runtime skip macro (removed in #40129) with
WSLC_TEST_METHOD metadata macro in tmpfs tests added by #40128.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
benhillis added a commit that referenced this pull request Apr 9, 2026
Replace WSL2_TEST_ONLY() runtime skip macro (removed in #40129) with
WSLC_TEST_METHOD metadata macro in tmpfs tests added by #40128.

Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants