Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloudtest/TestGroup.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
</Setup>

<TestJob Name="CloudTest.Taef" TimeoutMins="240">
<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]\${TEST_PACKAGE_FILE} /p:Version=${version} /p:AllowUnsigned=${ALLOW_UNSIGNED_PACKAGE} /p:UnitTestsPath=[WorkingDirectory]\unit_tests /p:DistroPath=[WorkingDirectory]\test_distro.tar.xz /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" />
<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]\${TEST_PACKAGE_FILE} /p:Version=${version} /p:AllowUnsigned=${ALLOW_UNSIGNED_PACKAGE} /p:UnitTestsPath=[WorkingDirectory]\unit_tests /p:DistroPath=[WorkingDirectory]\test_distro.tar.xz /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;not(@TestCategory='WSLC') and (@WSLVersion='${version}' or not(@WSLVersion='*'))&quot;" />
</TestJob>
</TestJobGroup>
22 changes: 20 additions & 2 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ Below is a brief overview:

### Writing the Test

For tests that only apply to a specific WSL version, use the version-specific test method macros instead of `TEST_METHOD`:

- `WSL2_TEST_METHOD(Name)` — test only runs on WSL2
- `WSL1_TEST_METHOD(Name)` — test only runs on WSL1
- `WSLC_TEST_METHOD(Name)` — test only runs on WSL2 (for use in WSLC test classes)
- `TEST_METHOD(Name)` — test runs on both WSL1 and WSL2

These macros use TAEF metadata properties to tag tests with their required WSL version.
When tests are run via `run-tests.ps1` or CloudTest, a `/select:` query automatically
filters out tests that don't match the target version—so they don't appear in results at all
(no "skipped" noise).

For example, consider the file below, named `ExampleTest.cpp`:

```cpp
Expand All @@ -106,13 +118,19 @@ For example, consider the file below, named `ExampleTest.cpp`:
{
TEST_CLASS(ExampleTest) // define this as a test class

// add tests via test methods of the test class
TEST_METHOD(HelloWorldTest) // ExampleTest::ExampleTest::HelloWorldTest
// runs on both WSL1 and WSL2
TEST_METHOD(HelloWorldTest)
{
std::wstring outputExpected = L"Linux on Windows Rocks!\n";
auto [output, __] = LxsstuLaunchWslAndCaptureOutput(L"echo Linux on Windows Rocks!"); // from /test/Common.h
VERIFY_ARE_EQUAL(output, outputExpected); // TAEF test method that passes if both are equal, and fails otherwise.
}

// only runs on WSL2
WSL2_TEST_METHOD(Wsl2OnlyTest)
{
// ...
}
};
} //namespace ExampleTest
```
Expand Down
36 changes: 23 additions & 13 deletions test/windows/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,29 @@ Module Name:

#define LXSST_REMOVE_DISTRO_CONF_COMMAND_LINE L"-u root -e rm /etc/wsl.conf"

#define WSL1_TEST_ONLY() \
if (LxsstuVmMode()) \
{ \
LogSkipped("This test is only applicable to WSL1"); \
return; \
}

#define WSL2_TEST_ONLY() \
if (!LxsstuVmMode()) \
{ \
LogSkipped("This test is only applicable to WSL2"); \
return; \
}
//
// Test method declaration macros that tag tests with TAEF metadata for version-based selection.
// Use these instead of TEST_METHOD() for tests that only apply to a specific WSL version.
// When run via run-tests.ps1 or CloudTest, inapplicable tests are excluded from the run
// entirely (no "skipped" noise) via TAEF /select: queries.
//
#define WSL1_TEST_METHOD(_name) \
TAEF_BEGIN_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE(_name) \
TEST_METHOD_PROPERTY(L"WSLVersion", L"1") \
TAEF_END_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE() \
TEST_METHOD(_name)

#define WSL2_TEST_METHOD(_name) \
TAEF_BEGIN_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE(_name) \
TEST_METHOD_PROPERTY(L"WSLVersion", L"2") \
TAEF_END_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE() \
TEST_METHOD(_name)

#define WSLC_TEST_METHOD(_name) \
TAEF_BEGIN_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE(_name) \
TEST_METHOD_PROPERTY(L"WSLVersion", L"2") \
TAEF_END_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE() \
TEST_METHOD(_name)

// macro for skipping tests that are currently failing due to not yet being fully implemented
#define SKIP_TEST_NOT_IMPL() \
Expand Down
86 changes: 26 additions & 60 deletions test/windows/DrvFsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class DrvFsTests

void DrvfsMountElevated(DrvFsMode Mode)
{
WSL2_TEST_ONLY();
WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
SKIP_TEST_ARM64();

Expand All @@ -270,7 +269,6 @@ class DrvFsTests

void DrvfsMountElevatedDifferentConsole(DrvFsMode Mode)
{
WSL2_TEST_ONLY();
WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
SKIP_TEST_ARM64();

Expand All @@ -282,7 +280,6 @@ class DrvFsTests

void DrvfsMountNonElevated(DrvFsMode Mode)
{
WSL2_TEST_ONLY();
WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
SKIP_TEST_ARM64();

Expand All @@ -296,7 +293,6 @@ class DrvFsTests

void DrvfsMountNonElevatedDifferentConsole(DrvFsMode Mode)
{
WSL2_TEST_ONLY();
WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
SKIP_TEST_ARM64();

Expand All @@ -310,7 +306,6 @@ class DrvFsTests

void DrvfsMountElevatedSystemDistroEnabled(DrvFsMode Mode)
{
WSL2_TEST_ONLY();
WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
SKIP_TEST_ARM64();

Expand All @@ -322,7 +317,6 @@ class DrvFsTests

void DrvfsMountNonElevatedSystemDistroEnabled(DrvFsMode Mode)
{
WSL2_TEST_ONLY();
WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
SKIP_TEST_ARM64();

Expand Down Expand Up @@ -383,8 +377,6 @@ class DrvFsTests

void DrvFsMountUnicodePath(DrvFsMode Mode)
{
WSL2_TEST_ONLY();

// Create a Windows directory with unicode characters
constexpr auto unicodeDir = L"C:\\drvfs-测试-テスト";
auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() { std::filesystem::remove_all(unicodeDir); });
Expand Down Expand Up @@ -1149,63 +1141,53 @@ class WSL1 : public DrvFsTests
return true;
}

TEST_METHOD(DrvFsDisableQueryByName)
WSL1_TEST_METHOD(DrvFsDisableQueryByName)
{
WSL1_TEST_ONLY();
VERIFY_NO_THROW(DrvFsCommon(LX_DRVFS_DISABLE_QUERY_BY_NAME));
}

TEST_METHOD(DrvFsDisableQueryByNameAndStatInfo)
WSL1_TEST_METHOD(DrvFsDisableQueryByNameAndStatInfo)
{
WSL1_TEST_ONLY();
VERIFY_NO_THROW(DrvFsCommon(LX_DRVFS_DISABLE_QUERY_BY_NAME_AND_STAT_INFO));
}

TEST_METHOD(VfsAccessDrvFs)
WSL1_TEST_METHOD(VfsAccessDrvFs)
{
WSL1_TEST_ONLY();
DrvFsTests::VfsAccessDrvFs();
}

TEST_METHOD(FsCommonDrvFs)
WSL1_TEST_METHOD(FsCommonDrvFs)
{
WSL1_TEST_ONLY();
DrvFsTests::FsCommonDrvFs();
}

TEST_METHOD(DrvFs)
WSL1_TEST_METHOD(DrvFs)
{
WSL1_TEST_ONLY();
DrvFsTests::DrvFs(DrvFsMode::WSL1);
}

TEST_METHOD(DrvFsFat)
WSL1_TEST_METHOD(DrvFsFat)
{
WSL1_TEST_ONLY();
DrvFsTests::DrvFsFat(DrvFsMode::WSL1);
}

TEST_METHOD(DrvFsSmb)
WSL1_TEST_METHOD(DrvFsSmb)
{
WSL1_TEST_ONLY();
DrvFsTests::DrvFsSmb(DrvFsMode::WSL1);
}

TEST_METHOD(DrvFsMetadata)
WSL1_TEST_METHOD(DrvFsMetadata)
{
WSL1_TEST_ONLY();
DrvFsTests::DrvFsMetadata(DrvFsMode::WSL1);
}

TEST_METHOD(XattrDrvFs)
WSL1_TEST_METHOD(XattrDrvFs)
{
WSL1_TEST_ONLY();
DrvFsTests::XattrDrvFs(DrvFsMode::WSL1);
}

TEST_METHOD(WslPath)
WSL1_TEST_METHOD(WslPath)
{
WSL1_TEST_ONLY();
DrvFsTests::WslPath(DrvFsMode::WSL1);
}
};
Expand Down Expand Up @@ -1242,99 +1224,83 @@ class WSL1 : public DrvFsTests
return true; \
} \
\
TEST_METHOD(VfsAccessDrvFs) \
WSL2_TEST_METHOD(VfsAccessDrvFs) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::VfsAccessDrvFs(); \
} \
\
TEST_METHOD(FsCommonDrvFs) \
WSL2_TEST_METHOD(FsCommonDrvFs) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::FsCommonDrvFs(); \
} \
\
TEST_METHOD(DrvFs) \
WSL2_TEST_METHOD(DrvFs) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvFs(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvFsFat) \
WSL2_TEST_METHOD(DrvFsFat) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvFsFat(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvFsSmb) \
WSL2_TEST_METHOD(DrvFsSmb) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvFsSmb(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvFsMetadata) \
WSL2_TEST_METHOD(DrvFsMetadata) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvFsMetadata(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvfsMountElevated) \
WSL2_TEST_METHOD(DrvfsMountElevated) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvfsMountElevated(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvfsMountElevatedDifferentConsole) \
WSL2_TEST_METHOD(DrvfsMountElevatedDifferentConsole) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvfsMountElevatedDifferentConsole(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvfsMountNonElevated) \
WSL2_TEST_METHOD(DrvfsMountNonElevated) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvfsMountNonElevated(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvfsMountNonElevatedDifferentConsole) \
WSL2_TEST_METHOD(DrvfsMountNonElevatedDifferentConsole) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvfsMountNonElevatedDifferentConsole(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvfsMountElevatedSystemDistroEnabled) \
WSL2_TEST_METHOD(DrvfsMountElevatedSystemDistroEnabled) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvfsMountElevatedSystemDistroEnabled(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvfsMountNonElevatedSystemDistroEnabled) \
WSL2_TEST_METHOD(DrvfsMountNonElevatedSystemDistroEnabled) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvfsMountNonElevatedSystemDistroEnabled(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(XattrDrvFs) \
WSL2_TEST_METHOD(XattrDrvFs) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::XattrDrvFs(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvFsReFs) \
WSL2_TEST_METHOD(DrvFsReFs) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvFsReFs(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(WslPath) \
WSL2_TEST_METHOD(WslPath) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::WslPath(DrvFsMode::##_mode##); \
} \
\
TEST_METHOD(DrvFsMountUnicodePath) \
WSL2_TEST_METHOD(DrvFsMountUnicodePath) \
{ \
WSL2_TEST_ONLY(); \
DrvFsTests::DrvFsMountUnicodePath(DrvFsMode::##_mode##); \
} \
}
Expand Down
Loading
Loading