@samitouri / QOSAMI-WSL / commits / 813070c8

Refactor tests: use TAEF metadata for WSL version filtering (#40140)

Cherry-pick WSL1/WSL2 test changes from 9c4dba91 (feature/wsl-for-apps). Replace runtime WSL1_TEST_ONLY()/WSL2_TEST_ONLY() skip macros with WSL1_TEST_METHOD()/WSL2_TEST_METHOD() TAEF metadata macros. This moves version filtering to the test runner level via /select: queries, so inapplicable tests are excluded entirely instead of appearing as skipped. Updated files: - test/windows/Common.h: New macros + removed old skip macros - test/windows/*.cpp: Converted all test methods - tools/test/run-tests.ps1: Auto-add /select: when no user filter - cloudtest/TestGroup.xml.in: Add version filter to TAEF args - test/README.md: Document new macros Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Ben Hillis committed Apr 10, 2026 at 11:26 UTC 813070c88b6a5180c5c58873626aa066238d50ec
11 files changed +372 -621
cloudtest/TestGroup.xml.in
+1 -1
@@ -21,6 +21,6 @@
21 </Setup>
22
23 <TestJob Name="CloudTest.Taef" TimeoutMins="240">
24 - <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" />
24 + <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;" />
25 </TestJob>
26 </TestJobGroup>
test/README.md
+20 -2
@@ -91,6 +91,18 @@ Below is a brief overview:
91
92 ### Writing the Test
93
94 +For tests that only apply to a specific WSL version, use the version-specific test method macros instead of `TEST_METHOD`:
95 +
96 +- `WSL2_TEST_METHOD(Name)` — test only runs on WSL2
97 +- `WSL1_TEST_METHOD(Name)` — test only runs on WSL1
98 +- `WSLC_TEST_METHOD(Name)` — test only runs on WSL2 (for use in WSLC test classes)
99 +- `TEST_METHOD(Name)` — test runs on both WSL1 and WSL2
100 +
101 +These macros use TAEF metadata properties to tag tests with their required WSL version.
102 +When tests are run via `run-tests.ps1` or CloudTest, a `/select:` query automatically
103 +filters out tests that don't match the target version—so they don't appear in results at all
104 +(no "skipped" noise).
105 +
106 For example, consider the file below, named `ExampleTest.cpp`:
107
108 ```cpp
@@ -106,13 +118,19 @@ For example, consider the file below, named `ExampleTest.cpp`:
118 {
119 TEST_CLASS(ExampleTest) // define this as a test class
120
109 - // add tests via test methods of the test class
110 - TEST_METHOD(HelloWorldTest) // ExampleTest::ExampleTest::HelloWorldTest
121 + // runs on both WSL1 and WSL2
122 + TEST_METHOD(HelloWorldTest)
123 {
124 std::wstring outputExpected = L"Linux on Windows Rocks!\n";
125 auto [output, __] = LxsstuLaunchWslAndCaptureOutput(L"echo Linux on Windows Rocks!"); // from /test/Common.h
126 VERIFY_ARE_EQUAL(output, outputExpected); // TAEF test method that passes if both are equal, and fails otherwise.
127 }
128 +
129 + // only runs on WSL2
130 + WSL2_TEST_METHOD(Wsl2OnlyTest)
131 + {
132 + // ...
133 + }
134 };
135 } //namespace ExampleTest
136 ```
test/windows/Common.h
+23 -13
@@ -36,19 +36,29 @@ Abstract:
36
37 #define LXSST_REMOVE_DISTRO_CONF_COMMAND_LINE L"-u root -e rm /etc/wsl.conf"
38
39 -#define WSL1_TEST_ONLY() \
40 - if (LxsstuVmMode()) \
41 - { \
42 - LogSkipped("This test is only applicable to WSL1"); \
43 - return; \
44 - }
45 -
46 -#define WSL2_TEST_ONLY() \
47 - if (!LxsstuVmMode()) \
48 - { \
49 - LogSkipped("This test is only applicable to WSL2"); \
50 - return; \
51 - }
39 +//
40 +// Test method declaration macros that tag tests with TAEF metadata for version-based selection.
41 +// Use these instead of TEST_METHOD() for tests that only apply to a specific WSL version.
42 +// When run via run-tests.ps1 or CloudTest, inapplicable tests are excluded from the run
43 +// entirely (no "skipped" noise) via TAEF /select: queries.
44 +//
45 +#define WSL1_TEST_METHOD(_name) \
46 + TAEF_BEGIN_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE(_name) \
47 + TEST_METHOD_PROPERTY(L"WSLVersion", L"1") \
48 + TAEF_END_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE() \
49 + TEST_METHOD(_name)
50 +
51 +#define WSL2_TEST_METHOD(_name) \
52 + TAEF_BEGIN_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE(_name) \
53 + TEST_METHOD_PROPERTY(L"WSLVersion", L"2") \
54 + TAEF_END_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE() \
55 + TEST_METHOD(_name)
56 +
57 +#define WSLC_TEST_METHOD(_name) \
58 + TAEF_BEGIN_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE(_name) \
59 + TEST_METHOD_PROPERTY(L"WSLVersion", L"2") \
60 + TAEF_END_TEST_METHOD_PROPERTIES_IN_CLASS_SCOPE() \
61 + TEST_METHOD(_name)
62
63 // macro for skipping tests that are currently failing due to not yet being fully implemented
64 #define SKIP_TEST_NOT_IMPL() \
test/windows/DrvFsTests.cpp
+26 -60
@@ -258,7 +258,6 @@ public:
258
259 void DrvfsMountElevated(DrvFsMode Mode)
260 {
261 - WSL2_TEST_ONLY();
261 WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
262 SKIP_TEST_ARM64();
263
@@ -270,7 +269,6 @@ public:
269
270 void DrvfsMountElevatedDifferentConsole(DrvFsMode Mode)
271 {
273 - WSL2_TEST_ONLY();
272 WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
273 SKIP_TEST_ARM64();
274
@@ -282,7 +280,6 @@ public:
280
281 void DrvfsMountNonElevated(DrvFsMode Mode)
282 {
285 - WSL2_TEST_ONLY();
283 WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
284 SKIP_TEST_ARM64();
285
@@ -296,7 +293,6 @@ public:
293
294 void DrvfsMountNonElevatedDifferentConsole(DrvFsMode Mode)
295 {
299 - WSL2_TEST_ONLY();
296 WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
297 SKIP_TEST_ARM64();
298
@@ -310,7 +306,6 @@ public:
306
307 void DrvfsMountElevatedSystemDistroEnabled(DrvFsMode Mode)
308 {
313 - WSL2_TEST_ONLY();
309 WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
310 SKIP_TEST_ARM64();
311
@@ -322,7 +317,6 @@ public:
317
318 void DrvfsMountNonElevatedSystemDistroEnabled(DrvFsMode Mode)
319 {
325 - WSL2_TEST_ONLY();
320 WINDOWS_11_TEST_ONLY(); // TODO: Enable on Windows 10 when virtio support is added
321 SKIP_TEST_ARM64();
322
@@ -383,8 +377,6 @@ public:
377
378 void DrvFsMountUnicodePath(DrvFsMode Mode)
379 {
386 - WSL2_TEST_ONLY();
387 -
380 // Create a Windows directory with unicode characters
381 constexpr auto unicodeDir = L"C:\\drvfs-测试-テスト";
382 auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() { std::filesystem::remove_all(unicodeDir); });
@@ -1149,63 +1141,53 @@ class WSL1 : public DrvFsTests
1141 return true;
1142 }
1143
1152 - TEST_METHOD(DrvFsDisableQueryByName)
1144 + WSL1_TEST_METHOD(DrvFsDisableQueryByName)
1145 {
1154 - WSL1_TEST_ONLY();
1146 VERIFY_NO_THROW(DrvFsCommon(LX_DRVFS_DISABLE_QUERY_BY_NAME));
1147 }
1148
1158 - TEST_METHOD(DrvFsDisableQueryByNameAndStatInfo)
1149 + WSL1_TEST_METHOD(DrvFsDisableQueryByNameAndStatInfo)
1150 {
1160 - WSL1_TEST_ONLY();
1151 VERIFY_NO_THROW(DrvFsCommon(LX_DRVFS_DISABLE_QUERY_BY_NAME_AND_STAT_INFO));
1152 }
1153
1164 - TEST_METHOD(VfsAccessDrvFs)
1154 + WSL1_TEST_METHOD(VfsAccessDrvFs)
1155 {
1166 - WSL1_TEST_ONLY();
1156 DrvFsTests::VfsAccessDrvFs();
1157 }
1158
1170 - TEST_METHOD(FsCommonDrvFs)
1159 + WSL1_TEST_METHOD(FsCommonDrvFs)
1160 {
1172 - WSL1_TEST_ONLY();
1161 DrvFsTests::FsCommonDrvFs();
1162 }
1163
1176 - TEST_METHOD(DrvFs)
1164 + WSL1_TEST_METHOD(DrvFs)
1165 {
1178 - WSL1_TEST_ONLY();
1166 DrvFsTests::DrvFs(DrvFsMode::WSL1);
1167 }
1168
1182 - TEST_METHOD(DrvFsFat)
1169 + WSL1_TEST_METHOD(DrvFsFat)
1170 {
1184 - WSL1_TEST_ONLY();
1171 DrvFsTests::DrvFsFat(DrvFsMode::WSL1);
1172 }
1173
1188 - TEST_METHOD(DrvFsSmb)
1174 + WSL1_TEST_METHOD(DrvFsSmb)
1175 {
1190 - WSL1_TEST_ONLY();
1176 DrvFsTests::DrvFsSmb(DrvFsMode::WSL1);
1177 }
1178
1194 - TEST_METHOD(DrvFsMetadata)
1179 + WSL1_TEST_METHOD(DrvFsMetadata)
1180 {
1196 - WSL1_TEST_ONLY();
1181 DrvFsTests::DrvFsMetadata(DrvFsMode::WSL1);
1182 }
1183
1200 - TEST_METHOD(XattrDrvFs)
1184 + WSL1_TEST_METHOD(XattrDrvFs)
1185 {
1202 - WSL1_TEST_ONLY();
1186 DrvFsTests::XattrDrvFs(DrvFsMode::WSL1);
1187 }
1188
1206 - TEST_METHOD(WslPath)
1189 + WSL1_TEST_METHOD(WslPath)
1190 {
1208 - WSL1_TEST_ONLY();
1191 DrvFsTests::WslPath(DrvFsMode::WSL1);
1192 }
1193 };
@@ -1242,99 +1224,83 @@ class WSL1 : public DrvFsTests
1224 return true; \
1225 } \
1226 \
1245 - TEST_METHOD(VfsAccessDrvFs) \
1227 + WSL2_TEST_METHOD(VfsAccessDrvFs) \
1228 { \
1247 - WSL2_TEST_ONLY(); \
1229 DrvFsTests::VfsAccessDrvFs(); \
1230 } \
1231 \
1251 - TEST_METHOD(FsCommonDrvFs) \
1232 + WSL2_TEST_METHOD(FsCommonDrvFs) \
1233 { \
1253 - WSL2_TEST_ONLY(); \
1234 DrvFsTests::FsCommonDrvFs(); \
1235 } \
1236 \
1257 - TEST_METHOD(DrvFs) \
1237 + WSL2_TEST_METHOD(DrvFs) \
1238 { \
1259 - WSL2_TEST_ONLY(); \
1239 DrvFsTests::DrvFs(DrvFsMode::##_mode##); \
1240 } \
1241 \
1263 - TEST_METHOD(DrvFsFat) \
1242 + WSL2_TEST_METHOD(DrvFsFat) \
1243 { \
1265 - WSL2_TEST_ONLY(); \
1244 DrvFsTests::DrvFsFat(DrvFsMode::##_mode##); \
1245 } \
1246 \
1269 - TEST_METHOD(DrvFsSmb) \
1247 + WSL2_TEST_METHOD(DrvFsSmb) \
1248 { \
1271 - WSL2_TEST_ONLY(); \
1249 DrvFsTests::DrvFsSmb(DrvFsMode::##_mode##); \
1250 } \
1251 \
1275 - TEST_METHOD(DrvFsMetadata) \
1252 + WSL2_TEST_METHOD(DrvFsMetadata) \
1253 { \
1277 - WSL2_TEST_ONLY(); \
1254 DrvFsTests::DrvFsMetadata(DrvFsMode::##_mode##); \
1255 } \
1256 \
1281 - TEST_METHOD(DrvfsMountElevated) \
1257 + WSL2_TEST_METHOD(DrvfsMountElevated) \
1258 { \
1283 - WSL2_TEST_ONLY(); \
1259 DrvFsTests::DrvfsMountElevated(DrvFsMode::##_mode##); \
1260 } \
1261 \
1287 - TEST_METHOD(DrvfsMountElevatedDifferentConsole) \
1262 + WSL2_TEST_METHOD(DrvfsMountElevatedDifferentConsole) \
1263 { \
1289 - WSL2_TEST_ONLY(); \
1264 DrvFsTests::DrvfsMountElevatedDifferentConsole(DrvFsMode::##_mode##); \
1265 } \
1266 \
1293 - TEST_METHOD(DrvfsMountNonElevated) \
1267 + WSL2_TEST_METHOD(DrvfsMountNonElevated) \
1268 { \
1295 - WSL2_TEST_ONLY(); \
1269 DrvFsTests::DrvfsMountNonElevated(DrvFsMode::##_mode##); \
1270 } \
1271 \
1299 - TEST_METHOD(DrvfsMountNonElevatedDifferentConsole) \
1272 + WSL2_TEST_METHOD(DrvfsMountNonElevatedDifferentConsole) \
1273 { \
1301 - WSL2_TEST_ONLY(); \
1274 DrvFsTests::DrvfsMountNonElevatedDifferentConsole(DrvFsMode::##_mode##); \
1275 } \
1276 \
1305 - TEST_METHOD(DrvfsMountElevatedSystemDistroEnabled) \
1277 + WSL2_TEST_METHOD(DrvfsMountElevatedSystemDistroEnabled) \
1278 { \
1307 - WSL2_TEST_ONLY(); \
1279 DrvFsTests::DrvfsMountElevatedSystemDistroEnabled(DrvFsMode::##_mode##); \
1280 } \
1281 \
1311 - TEST_METHOD(DrvfsMountNonElevatedSystemDistroEnabled) \
1282 + WSL2_TEST_METHOD(DrvfsMountNonElevatedSystemDistroEnabled) \
1283 { \
1313 - WSL2_TEST_ONLY(); \
1284 DrvFsTests::DrvfsMountNonElevatedSystemDistroEnabled(DrvFsMode::##_mode##); \
1285 } \
1286 \
1317 - TEST_METHOD(XattrDrvFs) \
1287 + WSL2_TEST_METHOD(XattrDrvFs) \
1288 { \
1319 - WSL2_TEST_ONLY(); \
1289 DrvFsTests::XattrDrvFs(DrvFsMode::##_mode##); \
1290 } \
1291 \
1323 - TEST_METHOD(DrvFsReFs) \
1292 + WSL2_TEST_METHOD(DrvFsReFs) \
1293 { \
1325 - WSL2_TEST_ONLY(); \
1294 DrvFsTests::DrvFsReFs(DrvFsMode::##_mode##); \
1295 } \
1296 \
1329 - TEST_METHOD(WslPath) \
1297 + WSL2_TEST_METHOD(WslPath) \
1298 { \
1331 - WSL2_TEST_ONLY(); \
1299 DrvFsTests::WslPath(DrvFsMode::##_mode##); \
1300 } \
1301 \
1335 - TEST_METHOD(DrvFsMountUnicodePath) \
1302 + WSL2_TEST_METHOD(DrvFsMountUnicodePath) \
1303 { \
1337 - WSL2_TEST_ONLY(); \
1304 DrvFsTests::DrvFsMountUnicodePath(DrvFsMode::##_mode##); \
1305 } \
1306 }
test/windows/MountTests.cpp
+37 -93
@@ -203,13 +203,13 @@ class MountTests
203 }
204
205 // Attach a vhd, but don't mount it
206 - TEST_METHOD(TestBareMountVhd)
206 + WSL2_TEST_METHOD(TestBareMountVhd)
207 {
208 TestBareMountImpl(true);
209 }
210
211 // Mount one partition using --vhd and validate that options are correctly applied
212 - TEST_METHOD(TestMountOnePartitionVhd)
212 + WSL2_TEST_METHOD(TestMountOnePartitionVhd)
213 {
214 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
215
@@ -217,7 +217,7 @@ class MountTests
217 }
218
219 // Mount two partitions using --vhd on the same disk
220 - TEST_METHOD(TestMountTwoPartitionsVhd)
220 + WSL2_TEST_METHOD(TestMountTwoPartitionsVhd)
221 {
222 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
223
@@ -225,7 +225,7 @@ class MountTests
225 }
226
227 // Run a bare mount using --vhd and then mount a partition
228 - TEST_METHOD(TestAttachThenMountVhd)
228 + WSL2_TEST_METHOD(TestAttachThenMountVhd)
229 {
230 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
231
@@ -233,7 +233,7 @@ class MountTests
233 }
234
235 // Mount the disk directly
236 - TEST_METHOD(TestMountWholeDiskVhd)
236 + WSL2_TEST_METHOD(TestMountWholeDiskVhd)
237 {
238 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
239
@@ -241,49 +241,49 @@ class MountTests
241 }
242
243 // Test that mount state is deleted on shutdown (--vhd)
244 - TEST_METHOD(TestMountStateIsDeletedOnShutdownVhd)
244 + WSL2_TEST_METHOD(TestMountStateIsDeletedOnShutdownVhd)
245 {
246 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
247
248 TestMountStateIsDeletedOnShutdownImpl(true);
249 }
250
251 - TEST_METHOD(TestFilesystemDetectionWholeDisk)
251 + WSL2_TEST_METHOD(TestFilesystemDetectionWholeDisk)
252 {
253 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
254
255 TestFilesystemDetectionWholeDiskImpl(false);
256 }
257
258 - TEST_METHOD(TestFilesystemDetectionWholeDiskVhd)
258 + WSL2_TEST_METHOD(TestFilesystemDetectionWholeDiskVhd)
259 {
260 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
261
262 TestFilesystemDetectionWholeDiskImpl(true);
263 }
264
265 - TEST_METHOD(TestMountTwoPartitionsWithDetection)
265 + WSL2_TEST_METHOD(TestMountTwoPartitionsWithDetection)
266 {
267 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
268
269 TestMountTwoPartitionsWithDetectionImpl(false);
270 }
271
272 - TEST_METHOD(TestMountTwoPartitionsWithDetectionVhd)
272 + WSL2_TEST_METHOD(TestMountTwoPartitionsWithDetectionVhd)
273 {
274 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
275
276 TestMountTwoPartitionsWithDetectionImpl(true);
277 }
278
279 - TEST_METHOD(TestFilesystemDetectionFail)
279 + WSL2_TEST_METHOD(TestFilesystemDetectionFail)
280 {
281 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
282
283 TestFilesystemDetectionFailImpl(false);
284 }
285
286 - TEST_METHOD(TestFilesystemDetectionFailVhd)
286 + WSL2_TEST_METHOD(TestFilesystemDetectionFailVhd)
287 {
288 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
289
@@ -291,11 +291,9 @@ class MountTests
291 }
292
293 // Test specifying a mount name for a vhd
294 - TEST_METHOD(SpecifyMountName)
294 + WSL2_TEST_METHOD(SpecifyMountName)
295 {
296 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
297 - WSL2_TEST_ONLY();
298 -
297 const auto mountCommand = L"--mount " + VhdDevice + L" --vhd --name " + TEST_MOUNT_NAME;
298
299 WslKeepAlive keepAlive;
@@ -344,11 +342,9 @@ class MountTests
342 }
343
344 // Test ensuring that name collision detection works in --mount --name
347 - TEST_METHOD(SpecifyMountNameCollision)
345 + WSL2_TEST_METHOD(SpecifyMountNameCollision)
346 {
347 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
350 - WSL2_TEST_ONLY();
351 -
348 const auto mountCommand = L"--mount " + VhdDevice + L" --vhd --name " + TEST_MOUNT_NAME;
349
350 WslKeepAlive keepAlive;
@@ -372,11 +368,9 @@ class MountTests
368 }
369
370 // Test that multiple partitions can be mounted with --name
375 - TEST_METHOD(SpecifyMountNameTwoPartitions)
371 + WSL2_TEST_METHOD(SpecifyMountNameTwoPartitions)
372 {
373 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
378 - WSL2_TEST_ONLY();
379 -
374 const auto mountCommandOne = L"--mount " + VhdDevice + L" --vhd --name " + TEST_MOUNT_NAME + L"p1";
375 const auto mountCommandTwo = L"--mount " + VhdDevice + L" --vhd --name " + TEST_MOUNT_NAME + L"p2";
376
@@ -403,11 +397,9 @@ class MountTests
397 }
398
399 // Test relative mount/unmounting of a --vhd
406 - TEST_METHOD(RelativePathUnmount)
400 + WSL2_TEST_METHOD(RelativePathUnmount)
401 {
402 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
409 - WSL2_TEST_ONLY();
410 -
403 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--mount " TEST_MOUNT_VHD L" --vhd --bare"), (DWORD)0);
404
405 const auto disk = GetBlockDeviceInWsl();
@@ -417,11 +409,9 @@ class MountTests
409 }
410
411 // Test relative mount/unmounting of a --vhd that does not exist
420 - TEST_METHOD(RelativePathUnmountNoFileExists)
412 + WSL2_TEST_METHOD(RelativePathUnmountNoFileExists)
413 {
414 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
423 - WSL2_TEST_ONLY();
424 -
415 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--mount " TEST_MOUNT_VHD L" --vhd --bare"), (DWORD)0);
416
417 const auto disk = GetBlockDeviceInWsl();
@@ -431,11 +421,9 @@ class MountTests
421 VERIFY_ARE_NOT_EQUAL(LxsstuLaunchWsl(L"--unmount " TEST_UNMOUNT_VHD_DNE), (DWORD)0);
422 }
423
434 - TEST_METHOD(AbsolutePathVhdUnmount)
424 + WSL2_TEST_METHOD(AbsolutePathVhdUnmount)
425 {
426 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
437 - WSL2_TEST_ONLY();
438 -
427 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--mount " TEST_MOUNT_VHD L" --vhd --bare"), (DWORD)0);
428
429 const auto disk = GetBlockDeviceInWsl();
@@ -474,7 +462,7 @@ class MountTests
462 }
463
464 // Attach a disk, but don't mount it
477 - TEST_METHOD(TestBareMount)
465 + WSL2_TEST_METHOD(TestBareMount)
466 {
467 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
468
@@ -483,11 +471,9 @@ class MountTests
471
472 // Validate that attached disks that were offline when attached
473 // are still offline when detached
486 - TEST_METHOD(TestOfflineDiskStaysOffline)
474 + WSL2_TEST_METHOD(TestOfflineDiskStaysOffline)
475 {
476 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
489 - WSL2_TEST_ONLY();
490 -
477 WslKeepAlive keepAlive;
478
479 auto diskHandle = wsl::windows::common::disk::OpenDevice(DiskDevice.c_str(), GENERIC_ALL, c_diskOpenTimeoutMs);
@@ -516,7 +502,7 @@ class MountTests
502 }
503
504 // Mount one partition and validate that options are correctly applied
519 - TEST_METHOD(TestMountOnePartition)
505 + WSL2_TEST_METHOD(TestMountOnePartition)
506 {
507 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
508
@@ -524,7 +510,7 @@ class MountTests
510 }
511
512 // Mount two partitions on the same disk
527 - TEST_METHOD(TestMountTwoPartitions)
513 + WSL2_TEST_METHOD(TestMountTwoPartitions)
514 {
515 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
516
@@ -532,11 +518,9 @@ class MountTests
518 }
519
520 // Mount a fat partition
535 - TEST_METHOD(TestMountFatPartition)
521 + WSL2_TEST_METHOD(TestMountFatPartition)
522 {
523 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
538 - WSL2_TEST_ONLY();
539 -
524 WslKeepAlive keepAlive;
525
526 // Create a MBR disk with 1 ntfs partition
@@ -562,14 +546,14 @@ class MountTests
546 }
547
548 // Mount the disk directly
565 - TEST_METHOD(TestMountWholeDisk)
549 + WSL2_TEST_METHOD(TestMountWholeDisk)
550 {
551 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
552
553 TestMountWholeDiskImpl(false);
554 }
555
572 - TEST_METHOD(TestMountStateIsDeletedOnShutdown)
556 + WSL2_TEST_METHOD(TestMountStateIsDeletedOnShutdown)
557 {
558 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
559
@@ -577,11 +561,9 @@ class MountTests
561 }
562
563 // Validate that a failure to mount a disk isn't fatal
580 - TEST_METHOD(TestMountFailuresArentFatal)
564 + WSL2_TEST_METHOD(TestMountFailuresArentFatal)
565 {
566 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
583 - WSL2_TEST_ONLY();
584 -
567 WslKeepAlive keepAlive;
568
569 // Create a MBR disk with 1 ext4 partition
@@ -638,20 +620,16 @@ class MountTests
620 }
621
622 // wsl --unmount should succeed even when no disk is mounted
641 - TEST_METHOD(UnmountWithoutAnyDisk)
623 + WSL2_TEST_METHOD(UnmountWithoutAnyDisk)
624 {
625 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
644 - WSL2_TEST_ONLY();
645 -
626 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--unmount"), (DWORD)0);
627 }
628
629 // Mount two partitions on the same disk and validate that the mount is restored
650 - TEST_METHOD(TestMountTwoPartitionsAfterTimeout)
630 + WSL2_TEST_METHOD(TestMountTwoPartitionsAfterTimeout)
631 {
632 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
653 - WSL2_TEST_ONLY();
654 -
633 WslKeepAlive keepAlive;
634
635 // Create a MBR disk with 1 ext4 partition and one fat partitions
@@ -679,11 +657,9 @@ class MountTests
657 }
658
659 // Validate that non-admin can remount saved disks
682 - TEST_METHOD(TestMount1PartitionAndRemountAsNonAdmin)
660 + WSL2_TEST_METHOD(TestMount1PartitionAndRemountAsNonAdmin)
661 {
662 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
685 - WSL2_TEST_ONLY();
686 -
663 WslKeepAlive keepAlive;
664
665 FormatDisk({L"ext4"}, false);
@@ -718,7 +694,7 @@ class MountTests
694 }
695
696 // Run a bare mount and then mount a partition
721 - TEST_METHOD(TestAttachThenMount)
697 + WSL2_TEST_METHOD(TestAttachThenMount)
698 {
699 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
700
@@ -726,11 +702,9 @@ class MountTests
702 }
703
704 // Validate that unmounting works when the UVM is not running
729 - TEST_METHOD(TestMountOnePartitionAfterTimeout)
705 + WSL2_TEST_METHOD(TestMountOnePartitionAfterTimeout)
706 {
707 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
732 - WSL2_TEST_ONLY();
733 -
708 WslKeepAlive keepAlive;
709
710 // Create a MBR disk with 1 ext4 partition
@@ -758,11 +732,9 @@ class MountTests
732 }
733
734 // Validate that the proper mount error is returned if the filesystem type is wrong
761 - TEST_METHOD(TestMountPartitionWithWrongFs)
735 + WSL2_TEST_METHOD(TestMountPartitionWithWrongFs)
736 {
737 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
764 - WSL2_TEST_ONLY();
765 -
738 WslKeepAlive keepAlive;
739
740 // Create a MBR disk with 1 ext4 partition
@@ -782,11 +754,9 @@ class MountTests
754 }
755
756 // Validate that the proper mount error is returned if the partition can't be found
785 - TEST_METHOD(TestMountPartitionWithBadPartitionIndex)
757 + WSL2_TEST_METHOD(TestMountPartitionWithBadPartitionIndex)
758 {
759 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
788 - WSL2_TEST_ONLY();
789 -
760 WslKeepAlive keepAlive;
761
762 // Create a MBR disk with 1 fat partition
@@ -806,11 +776,9 @@ class MountTests
776 }
777
778 // Validate that disk aren't detached if in use by other processes
809 - TEST_METHOD(TestDeviceCantBeMountedIfInUse)
779 + WSL2_TEST_METHOD(TestDeviceCantBeMountedIfInUse)
780 {
781 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
812 - WSL2_TEST_ONLY();
813 -
782 {
783 // Format-Volume fails without automount enabled
784 SetAutoMountPolicy AutoMountPolicy{true};
@@ -859,11 +827,9 @@ class MountTests
827 VERIFY_ARE_EQUAL(output, wsl::shared::string::MultiByteToWide(fileContent));
828 }
829
862 - TEST_METHOD(TestMountWithFlagOption)
830 + WSL2_TEST_METHOD(TestMountWithFlagOption)
831 {
832 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
865 - WSL2_TEST_ONLY();
866 -
833 WslKeepAlive keepAlive;
834
835 // Create a MBR disk with 1 ext4 partition
@@ -902,21 +868,17 @@ class MountTests
868 WaitForDiskReady();
869 }
870
905 - TEST_METHOD(TestAttachFailsWithoutWsl2Distro)
871 + WSL1_TEST_METHOD(TestAttachFailsWithoutWsl2Distro)
872 {
873 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
908 - WSL1_TEST_ONLY();
909 -
874 // Attempt to mount a disk with only a WSL1 distro
875 wsl::windows::common::SvcComm service;
876 VERIFY_ARE_EQUAL(service.AttachDisk(L"Dummy", LXSS_ATTACH_MOUNT_FLAGS_PASS_THROUGH), WSL_E_WSL2_NEEDED);
877 }
878
915 - TEST_METHOD(VhdWithSpaces)
879 + WSL2_TEST_METHOD(VhdWithSpaces)
880 {
881 SKIP_UNSUPPORTED_ARM64_MOUNT_TEST();
918 - WSL2_TEST_ONLY();
919 -
882 LxsstuLaunchPowershellAndCaptureOutput(L"New-Vhd -Path 'vhd with spaces.vhdx' -SizeBytes 20MB");
883
884 auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, []() {
@@ -1211,8 +1173,6 @@ class MountTests
1173
1174 void TestBareMountImpl(bool isVhd)
1175 {
1214 - WSL2_TEST_ONLY();
1215 -
1176 WslKeepAlive keepAlive;
1177
1178 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
@@ -1246,8 +1206,6 @@ class MountTests
1206
1207 void TestMountOnePartitionImpl(bool isVhd)
1208 {
1249 - WSL2_TEST_ONLY();
1250 -
1209 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
1210 const auto mountCommand = (isVhd) ? (L"--mount " + deviceName + L" --vhd") : (L"--mount " + deviceName);
1211
@@ -1302,8 +1260,6 @@ class MountTests
1260
1261 void TestMountTwoPartitionsImpl(bool isVhd)
1262 {
1305 - WSL2_TEST_ONLY();
1306 -
1263 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
1264 const auto mountCommand = (isVhd) ? (L"--mount " + deviceName + L" --vhd") : (L"--mount " + deviceName);
1265
@@ -1338,8 +1294,6 @@ class MountTests
1294
1295 void TestAttachThenMountImpl(bool isVhd)
1296 {
1341 - WSL2_TEST_ONLY();
1342 -
1297 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
1298 const auto mountCommand = (isVhd) ? (L"--mount " + deviceName + L" --vhd") : (L"--mount " + deviceName);
1299
@@ -1369,8 +1323,6 @@ class MountTests
1323
1324 void TestMountWholeDiskImpl(bool isVhd)
1325 {
1372 - WSL2_TEST_ONLY();
1373 -
1326 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
1327 const auto mountCommand = (isVhd) ? (L"--mount " + deviceName + L" --vhd") : (L"--mount " + deviceName);
1328
@@ -1404,8 +1356,6 @@ class MountTests
1356
1357 void TestMountStateIsDeletedOnShutdownImpl(bool isVhd)
1358 {
1407 - WSL2_TEST_ONLY();
1408 -
1359 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
1360 const auto mountCommand = (isVhd) ? (L"--mount " + deviceName + L" --vhd") : (L"--mount " + deviceName);
1361
@@ -1437,8 +1387,6 @@ class MountTests
1387
1388 void TestFilesystemDetectionWholeDiskImpl(bool isVhd)
1389 {
1440 - WSL2_TEST_ONLY();
1441 -
1390 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
1391 const auto mountCommand = (isVhd) ? (L"--mount " + deviceName + L" --vhd") : (L"--mount " + deviceName);
1392
@@ -1472,8 +1420,6 @@ class MountTests
1420
1421 void TestMountTwoPartitionsWithDetectionImpl(bool isVhd)
1422 {
1475 - WSL2_TEST_ONLY();
1476 -
1423 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
1424 const auto mountCommand = (isVhd) ? (L"--mount " + deviceName + L" --vhd") : (L"--mount " + deviceName);
1425
@@ -1508,8 +1454,6 @@ class MountTests
1454
1455 void TestFilesystemDetectionFailImpl(bool isVhd)
1456 {
1511 - WSL2_TEST_ONLY();
1512 -
1457 const auto deviceName = (isVhd) ? VhdDevice : DiskDevice;
1458 const auto mountCommand = (isVhd) ? (L"--mount " + deviceName + L" --vhd") : (L"--mount " + deviceName);
1459
test/windows/NetworkTests.cpp
+152 -198
@@ -59,7 +59,6 @@ bool TryLoadWinhttpProxyMethods() noexcept
59
60 #define HYPERV_FIREWALL_TEST_ONLY() \
61 { \
62 - WSL2_TEST_ONLY(); \
62 WINDOWS_11_TEST_ONLY(); \
63 if (!AreExperimentalNetworkingFeaturesSupported() || !IsHyperVFirewallSupported()) \
64 { \
@@ -70,7 +69,6 @@ bool TryLoadWinhttpProxyMethods() noexcept
69
70 #define MIRRORED_NETWORKING_TEST_ONLY() \
71 { \
73 - WSL2_TEST_ONLY(); \
72 WINDOWS_11_TEST_ONLY(); \
73 if (!AreExperimentalNetworkingFeaturesSupported() || !IsHyperVFirewallSupported()) \
74 { \
@@ -81,7 +79,6 @@ bool TryLoadWinhttpProxyMethods() noexcept
79
80 #define DNS_TUNNELING_TEST_ONLY() \
81 { \
84 - WSL2_TEST_ONLY(); \
82 WINDOWS_11_TEST_ONLY(); \
83 if (!AreExperimentalNetworkingFeaturesSupported()) \
84 { \
@@ -97,7 +94,6 @@ bool TryLoadWinhttpProxyMethods() noexcept
94
95 #define WINHTTP_PROXY_TEST_ONLY() \
96 { \
100 - WSL2_TEST_ONLY(); \
97 if (!TryLoadWinhttpProxyMethods()) \
98 { \
99 LogSkipped("Winhttp proxy APIs not present on this OS. Skipping test..."); \
@@ -107,7 +103,6 @@ bool TryLoadWinhttpProxyMethods() noexcept
103
104 #define VIRTIOPROXY_TEST_ONLY() \
105 { \
110 - WSL2_TEST_ONLY(); \
106 }
107
108 static constexpr auto c_wslVmCreatorId = L"\'{40e0ac32-46a5-438a-A0B2-2B479E8F2E90}\'";
@@ -301,10 +296,8 @@ class NetworkTests
296 return true;
297 }
298
304 - TEST_METHOD(RemoveAndAddDefaultRoute)
299 + WSL2_TEST_METHOD(RemoveAndAddDefaultRoute)
300 {
306 - WSL2_TEST_ONLY();
307 -
301 TestCase({{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
302
303 // Verify that the default routes are set
@@ -352,10 +345,8 @@ class NetworkTests
345 VERIFY_ARE_EQUAL(v6State.DefaultRoute->Device, L"eth0");
346 }
347
355 - TEST_METHOD(SetInterfaceDownAndUp)
348 + WSL2_TEST_METHOD(SetInterfaceDownAndUp)
349 {
357 - WSL2_TEST_ONLY();
358 -
350 // Disconnect interface
351 wsl::shared::hns::NetworkInterface link;
352 link.Connected = false;
@@ -368,10 +359,8 @@ class NetworkTests
359 VERIFY_IS_TRUE(GetInterfaceState(L"eth0").Up);
360 }
361
371 - TEST_METHOD(SetMtu)
362 + WSL2_TEST_METHOD(SetMtu)
363 {
373 - WSL2_TEST_ONLY();
374 -
364 // Set MTU - must be 1280 bytes or above to meet IPv6 minimum MTU requirement
365 wsl::shared::hns::NetworkInterface link;
366 link.Connected = true;
@@ -380,10 +369,8 @@ class NetworkTests
369 VERIFY_ARE_EQUAL(GetInterfaceState(L"eth0").Mtu, 1280);
370 }
371
383 - TEST_METHOD(AddAndRemoveCustomRoute)
372 + WSL2_TEST_METHOD(AddAndRemoveCustomRoute)
373 {
385 - WSL2_TEST_ONLY();
386 -
374 TestCase({{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
375
376 // Add custom routes, one per address family
@@ -418,10 +405,8 @@ class NetworkTests
405 VERIFY_IS_TRUE(v6CustomRouteGone);
406 }
407
421 - TEST_METHOD(AddRouteWithMetrics)
408 + WSL2_TEST_METHOD(AddRouteWithMetrics)
409 {
423 - WSL2_TEST_ONLY();
424 -
410 TestCase({{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
411
412 // Add a custom route per address family
@@ -458,10 +443,8 @@ class NetworkTests
443 VERIFY_IS_TRUE(v6CustomRouteGone);
444 }
445
461 - TEST_METHOD(ResetRoutes)
446 + WSL2_TEST_METHOD(ResetRoutes)
447 {
463 - WSL2_TEST_ONLY();
464 -
448 TestCase({{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
449
450 // Add a custom route per address family
@@ -532,10 +515,8 @@ class NetworkTests
515 VERIFY_IS_TRUE(v6GwRestoredCorrectly);
516 }
517
535 - TEST_METHOD(ResetRoutesTwice)
518 + WSL2_TEST_METHOD(ResetRoutesTwice)
519 {
537 - WSL2_TEST_ONLY();
538 -
520 TestCase({{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
521
522 auto state = GetIpv4RoutingTableState();
@@ -564,10 +545,8 @@ class NetworkTests
545 VERIFY_IS_TRUE(state.Routes.empty());
546 }
547
567 - TEST_METHOD(UpdateIpAddress)
548 + WSL2_TEST_METHOD(UpdateIpAddress)
549 {
569 - WSL2_TEST_ONLY();
570 -
550 TestCase({{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
551
552 // Verify that the IPs are in the preferred state
@@ -625,10 +604,8 @@ class NetworkTests
604 IpSuffixOriginRandom,
605 };
606
628 - TEST_METHOD(TemporaryAddress)
607 + WSL2_TEST_METHOD(TemporaryAddress)
608 {
630 - WSL2_TEST_ONLY();
631 -
609 TestCase({{L"eth0", {}, {}, {{L"fc00::2", 64}}, L"fc00::1"}});
610
611 // Make the address public
@@ -687,33 +664,33 @@ class NetworkTests
664 VERIFY_ARE_EQUAL(L"fc00::abcd:1234:5678:9999", match.str(1));
665 }
666
690 - TEST_METHOD(SimpleCase)
667 + WSL2_TEST_METHOD(SimpleCase)
668 {
669 TestCase({{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
670 }
671
695 - TEST_METHOD(AddressChange)
672 + WSL2_TEST_METHOD(AddressChange)
673 {
674 TestCase(
675 {{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"},
676 {L"eth0", {{L"192.168.0.3", 24}}, L"192.168.0.1", {{L"fc00::3", 64}}, L"fc00::1"}});
677 }
678
702 - TEST_METHOD(GatewayChange)
679 + WSL2_TEST_METHOD(GatewayChange)
680 {
681 TestCase(
682 {{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"},
683 {L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.3", {{L"fc00::2", 64}}, L"fc00::3"}});
684 }
685
709 - TEST_METHOD(NetworkChange)
686 + WSL2_TEST_METHOD(NetworkChange)
687 {
688 TestCase(
689 {{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"},
690 {L"eth0", {{L"10.0.0.2", 16}}, L"10.0.0.1", {{L"fc00:abcd::5", 80}}, L"fc00:abcd::1"}});
691 }
692
716 - TEST_METHOD(NetworkChangeAndBack)
693 + WSL2_TEST_METHOD(NetworkChangeAndBack)
694 {
695 TestCase(
696 {{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"},
@@ -721,14 +698,14 @@ class NetworkTests
698 {L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
699 }
700
724 - TEST_METHOD(NoChange)
701 + WSL2_TEST_METHOD(NoChange)
702 {
703 TestCase(
704 {{L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"},
705 {L"eth0", {{L"192.168.0.2", 24}}, L"192.168.0.1", {{L"fc00::2", 64}}, L"fc00::1"}});
706 }
707
731 - TEST_METHOD(MultipleIps)
708 + WSL2_TEST_METHOD(MultipleIps)
709 {
710 TestCase(
711 {{L"eth0",
@@ -738,10 +715,8 @@ class NetworkTests
715 L"fc00::1"}});
716 }
717
741 - TEST_METHOD(MacAddressChangeAndBack)
718 + WSL2_TEST_METHOD(MacAddressChangeAndBack)
719 {
743 - WSL2_TEST_ONLY();
744 -
720 const auto originalMac = GetMacAddress();
721
722 wsl::shared::hns::MacAddress macAddress;
@@ -952,7 +927,7 @@ class NetworkTests
927 VerifyDnsQueries();
928 }
929
955 - TEST_METHOD(NatDnsTunneling)
930 + WSL2_TEST_METHOD(NatDnsTunneling)
931 {
932 DNS_TUNNELING_TEST_ONLY();
933
@@ -961,7 +936,7 @@ class NetworkTests
936 VerifyDnsTunneling(c_dnsTunnelingDefaultIp);
937 }
938
964 - TEST_METHOD(NatDnsTunnelingWithSpecificIp)
939 + WSL2_TEST_METHOD(NatDnsTunnelingWithSpecificIp)
940 {
941 DNS_TUNNELING_TEST_ONLY();
942
@@ -970,7 +945,7 @@ class NetworkTests
945 VerifyDnsTunneling(L"10.255.255.1");
946 }
947
973 - TEST_METHOD(NatDnsTunnelingVerifySuffixes)
948 + WSL2_TEST_METHOD(NatDnsTunnelingVerifySuffixes)
949 {
950 DNS_TUNNELING_TEST_ONLY();
951
@@ -979,10 +954,8 @@ class NetworkTests
954 VerifyDnsSuffixes();
955 }
956
982 - TEST_METHOD(NatWithoutIcsDnsProxy)
957 + WSL2_TEST_METHOD(NatWithoutIcsDnsProxy)
958 {
984 - WSL2_TEST_ONLY();
985 -
959 // Verify WSL has connectivity in NAT mode when the ICS DNS proxy is turned off (in which case the DNS servers
960 // from Windows are mirrored in Linux)
961 WslConfigChange config(LxssGenerateTestConfig({.dnsProxy = false}));
@@ -990,10 +963,8 @@ class NetworkTests
963 GuestClient(L"tcp-connect:bing.com:80");
964 }
965
993 - TEST_METHOD(DnsChange)
966 + WSL2_TEST_METHOD(DnsChange)
967 {
995 - WSL2_TEST_ONLY();
996 -
968 wsl::shared::hns::DNS dns;
969 dns.ServerList = {L"1.1.1.1"};
970 dns.Options = LX_INIT_RESOLVCONF_FULL_HEADER;
@@ -1004,10 +975,8 @@ class NetworkTests
975 VERIFY_ARE_EQUAL(expected, out.c_str());
976 }
977
1007 - TEST_METHOD(DnsChangeMultipleServerAndSearch)
978 + WSL2_TEST_METHOD(DnsChangeMultipleServerAndSearch)
979 {
1009 - WSL2_TEST_ONLY();
1010 -
980 wsl::shared::hns::DNS dns;
981 dns.ServerList = L"1.1.1.1,1.1.1.2";
982 dns.Search = L"foo.microsoft.com,bar.microsoft.com";
@@ -1023,24 +992,18 @@ class NetworkTests
992 VERIFY_ARE_EQUAL(expected, out.c_str());
993 }
994
1026 - TEST_METHOD(DnsResolutionBasic)
995 + WSL2_TEST_METHOD(DnsResolutionBasic)
996 {
1028 - WSL2_TEST_ONLY();
1029 -
997 NetworkTests::VerifyDnsResolutionBasic();
998 }
999
1033 - TEST_METHOD(DnsResolutionDig)
1000 + WSL2_TEST_METHOD(DnsResolutionDig)
1001 {
1035 - WSL2_TEST_ONLY();
1036 -
1002 NetworkTests::VerifyDnsResolutionDig();
1003 }
1004
1040 - TEST_METHOD(DnsResolutionRecordTypes)
1005 + WSL2_TEST_METHOD(DnsResolutionRecordTypes)
1006 {
1042 - WSL2_TEST_ONLY();
1043 -
1007 NetworkTests::VerifyDnsResolutionRecordTypes();
1008 }
1009
@@ -1272,7 +1235,7 @@ class NetworkTests
1235 VerifyHttpProxyFilterByNetworkConfiguration(false);
1236 }
1237
1275 - TEST_METHOD(NatHttpProxyVerifyConfigDisabled)
1238 + WSL2_TEST_METHOD(NatHttpProxyVerifyConfigDisabled)
1239 {
1240 WINHTTP_PROXY_TEST_ONLY();
1241 WslConfigChange config(LxssGenerateTestConfig({.autoProxy = false}));
@@ -1282,7 +1245,7 @@ class NetworkTests
1245 VerifyHttpProxyEnvVariables(L"", L"", L"");
1246 }
1247
1285 - TEST_METHOD(NatHttpProxySimple)
1248 + WSL2_TEST_METHOD(NatHttpProxySimple)
1249 {
1250 WINHTTP_PROXY_TEST_ONLY();
1251 WslConfigChange config(LxssGenerateTestConfig({.autoProxy = true}));
@@ -1290,7 +1253,7 @@ class NetworkTests
1253 VerifyHttpProxySimple();
1254 }
1255
1293 - TEST_METHOD(NatHttpProxySimpleMachineScope)
1256 + WSL2_TEST_METHOD(NatHttpProxySimpleMachineScope)
1257 {
1258 WINHTTP_PROXY_TEST_ONLY();
1259 WslConfigChange config(LxssGenerateTestConfig({.autoProxy = true}));
@@ -1299,7 +1262,7 @@ class NetworkTests
1262 VerifyHttpProxySimple(false);
1263 }
1264
1302 - TEST_METHOD(NatNoHttpProxyConfigured)
1265 + WSL2_TEST_METHOD(NatNoHttpProxyConfigured)
1266 {
1267 WINHTTP_PROXY_TEST_ONLY();
1268 WslConfigChange config(LxssGenerateTestConfig({.autoProxy = true}));
@@ -1307,38 +1270,36 @@ class NetworkTests
1270 VerifyNoHttpProxyConfigured();
1271 }
1272
1310 - TEST_METHOD(NatHttpProxyWithBypassesConfigured)
1273 + WSL2_TEST_METHOD(NatHttpProxyWithBypassesConfigured)
1274 {
1275 WINHTTP_PROXY_TEST_ONLY();
1276 WslConfigChange config(LxssGenerateTestConfig({.autoProxy = true}));
1277 VerifyHttpProxyWithBypassesConfigured();
1278 }
1279
1317 - TEST_METHOD(NatHttpProxyChange)
1280 + WSL2_TEST_METHOD(NatHttpProxyChange)
1281 {
1282 WINHTTP_PROXY_TEST_ONLY();
1283 WslConfigChange config(LxssGenerateTestConfig({.autoProxy = true}));
1284 VerifyHttpProxyChange();
1285 }
1286
1324 - TEST_METHOD(NatHttpProxyAndWslEnv)
1287 + WSL2_TEST_METHOD(NatHttpProxyAndWslEnv)
1288 {
1289 WINHTTP_PROXY_TEST_ONLY();
1290 WslConfigChange config(LxssGenerateTestConfig({.autoProxy = true}));
1291 VerifyHttpProxyAndWslEnv();
1292 }
1293
1331 - TEST_METHOD(NatHttpProxyFilterByNetworkConfiguration)
1294 + WSL2_TEST_METHOD(NatHttpProxyFilterByNetworkConfiguration)
1295 {
1296 WINHTTP_PROXY_TEST_ONLY();
1297 WslConfigChange config(LxssGenerateTestConfig({.autoProxy = true}));
1298 VerifyHttpProxyFilterByNetworkConfigurationNAT();
1299 }
1300
1338 - TEST_METHOD(RenameInterface)
1301 + WSL2_TEST_METHOD(RenameInterface)
1302 {
1340 - WSL2_TEST_ONLY();
1341 -
1303 // Disconnect "eth0" interface so it can be renamed
1304 wsl::shared::hns::NetworkInterface link;
1305 link.Connected = false;
@@ -1362,10 +1323,8 @@ class NetworkTests
1323 VERIFY_IS_TRUE(eth0Connected);
1324 }
1325
1365 - TEST_METHOD(RenameWifiInterface)
1326 + WSL2_TEST_METHOD(RenameWifiInterface)
1327 {
1367 - WSL2_TEST_ONLY();
1368 -
1328 std::wstring commandLine(L"wsl.exe bash -c \"zcat /proc/config.gz | grep CONFIG_PROXY_WIFI=y\"");
1329 const auto out = std::get<0>(LxsstuLaunchCommandAndCaptureOutputWithResult(commandLine.data()));
1330 if (out.empty())
@@ -1393,10 +1352,8 @@ class NetworkTests
1352 VERIFY_IS_TRUE(eth0Connected);
1353 }
1354
1396 - TEST_METHOD(EnableLoopbackRouting)
1355 + WSL2_TEST_METHOD(EnableLoopbackRouting)
1356 {
1398 - WSL2_TEST_ONLY();
1399 -
1357 // Enable accept_local and route_localnet settings for eth0
1358 wsl::shared::hns::VmNicCreatedNotification creationNotification{AdapterId};
1359 RunGns(creationNotification, LxGnsMessageVmNicCreatedNotification);
@@ -1409,10 +1366,8 @@ class NetworkTests
1366 VERIFY_IS_TRUE(routeLocalnetEnabled);
1367 }
1368
1412 - TEST_METHOD(InitializeLoopbackConfiguration)
1369 + WSL2_TEST_METHOD(InitializeLoopbackConfiguration)
1370 {
1414 - WSL2_TEST_ONLY();
1415 -
1371 // Assume eth0 is the GELNIC
1372 wsl::shared::hns::CreateDeviceRequest createDeviceRequest{wsl::shared::hns::DeviceType::Loopback, L"loopback", AdapterId};
1373 RunGns(createDeviceRequest, LxGnsMessageCreateDeviceRequest);
@@ -1460,10 +1415,8 @@ class NetworkTests
1415 VERIFY_IS_TRUE(shutdownSuccessful);
1416 }
1417
1463 - TEST_METHOD(AddRemoveLoopbackRoutesv4)
1418 + WSL2_TEST_METHOD(AddRemoveLoopbackRoutesv4)
1419 {
1465 - WSL2_TEST_ONLY();
1466 -
1420 const std::wstring interfaceName = L"eth0";
1421 const std::vector<std::wstring> ipAddresses = {L"127.0.0.1", L"127.0.0.2"};
1422
@@ -1514,10 +1467,8 @@ class NetworkTests
1467 The test uses the "ip route get" command, which is equivalent to asking the OS what route it will take for a packet. It
1468 functions as a small integration test.
1469 */
1517 - TEST_METHOD(LoopbackGetRoute)
1470 + WSL2_TEST_METHOD(LoopbackGetRoute)
1471 {
1519 - WSL2_TEST_ONLY();
1520 -
1472 // Verify that before configurations are applied, the route chosen for 127.0.0.1 tcp/udp uses the local routing table
1473 const bool loopbackTcpUsesLocalTable =
1474 LxsstuLaunchWsl(L"ip route get from 127.0.0.1 127.0.0.1 ipproto tcp | grep local") == (DWORD)0;
@@ -1546,10 +1497,8 @@ class NetworkTests
1497 }
1498
1499 // Validate that adapter has an ip address, default route and DNS configuration in NAT mode
1549 - TEST_METHOD(NatConfiguration)
1500 + WSL2_TEST_METHOD(NatConfiguration)
1501 {
1551 - WSL2_TEST_ONLY();
1552 -
1502 WslConfigChange config(LxssGenerateTestConfig());
1503
1504 const auto state = GetInterfaceState(L"eth0");
@@ -1634,9 +1583,8 @@ class NetworkTests
1583 VERIFY_SUCCEEDED(hr, error.get());
1584 }
1585
1637 - TEST_METHOD(NatInvalidRange)
1586 + WSL2_TEST_METHOD(NatInvalidRange)
1587 {
1639 - WSL2_TEST_ONLY();
1588 WslConfigChange config(LxssGenerateTestConfig());
1589 WriteNatConfiguration(L"InvalidRange", {}, {L"delete"});
1590 ResetWslNetwork();
@@ -1656,9 +1604,8 @@ class NetworkTests
1604 VERIFY_ARE_EQUAL(state.Gateway.value_or(L""), networkConfiguration.gatewayIpAddress);
1605 }
1606
1659 - TEST_METHOD(NatInvalidGateway)
1607 + WSL2_TEST_METHOD(NatInvalidGateway)
1608 {
1661 - WSL2_TEST_ONLY();
1609 WslConfigChange config(LxssGenerateTestConfig());
1610 WriteNatConfiguration({}, L"InvalidGateway", {});
1611 ResetWslNetwork();
@@ -1678,9 +1625,8 @@ class NetworkTests
1625 VERIFY_ARE_EQUAL(state.Gateway.value_or(L""), networkConfiguration.gatewayIpAddress);
1626 }
1627
1681 - TEST_METHOD(NatInvalidAddress)
1628 + WSL2_TEST_METHOD(NatInvalidAddress)
1629 {
1683 - WSL2_TEST_ONLY();
1630 WslConfigChange config(LxssGenerateTestConfig());
1631
1632 const auto previousConfiguration = GetNatConfiguration();
@@ -1822,7 +1768,11 @@ class NetworkTests
1768 __fallthrough;
1769 case wsl::core::NetworkingMode::Mirrored:
1770 case wsl::core::NetworkingMode::VirtioProxy:
1825 - WSL2_TEST_ONLY();
1771 + if (!LxsstuVmMode())
1772 + {
1773 + LogSkipped("This test is only applicable to WSL2");
1774 + return;
1775 + }
1776 break;
1777 }
1778
@@ -2313,19 +2263,16 @@ class NetworkTests
2263 }
2264 }
2265
2316 - TEST_METHOD(NatLocalhostRelay)
2266 + WSL2_TEST_METHOD(NatLocalhostRelay)
2267 {
2318 - WSL2_TEST_ONLY();
2268 WslKeepAlive keepAlive;
2269
2270 ValidateLocalhostRelayTraffic(AF_INET);
2271 ValidateLocalhostRelayTraffic(AF_INET6);
2272 }
2273
2325 - TEST_METHOD(NatLocalhostRelayNoIpv6)
2274 + WSL2_TEST_METHOD(NatLocalhostRelayNoIpv6)
2275 {
2327 - WSL2_TEST_ONLY();
2328 -
2276 WslConfigChange config(LxssGenerateTestConfig({.kernelCommandLine = L"ipv6.disable=1"}));
2277 WslKeepAlive keepAlive;
2278
@@ -2389,10 +2336,8 @@ class NetworkTests
2336 VERIFY_ARE_NOT_EQUAL(warnings.find(L"starting data transfer loop"), std::string::npos);
2337 }
2338
2392 - TEST_METHOD(NatNonRootNamespaceEphemeralBind)
2339 + WSL2_TEST_METHOD(NatNonRootNamespaceEphemeralBind)
2340 {
2394 - WSL2_TEST_ONLY();
2395 -
2341 // Because the test creates a new network namespace, the resolv.conf from the root network namespace
2342 // is copied in the resolv.conf of the new network namespace. The DNS tunneling listener running in the root namespace
2343 // needs to be accessible from the new namespace, so it can't use a 127* IP.
@@ -2599,7 +2544,7 @@ class NetworkTests
2544 AddFirewallRuleAndValidateTraffic(hyperVBlockRule, expectedConnectivity);
2545 }
2546
2602 - TEST_METHOD(NatFirewallRulesExpectedBlock)
2547 + WSL2_TEST_METHOD(NatFirewallRulesExpectedBlock)
2548 {
2549 HYPERV_FIREWALL_TEST_ONLY();
2550 WslConfigChange config(LxssGenerateTestConfig({.firewall = true}));
@@ -2608,7 +2553,7 @@ class NetworkTests
2553 FirewallRuleBlockedTests(FirewallTestConnectivity::Blocked);
2554 }
2555
2611 - TEST_METHOD(NatFirewallRulesExpectedBlockFirewallDisabled)
2556 + WSL2_TEST_METHOD(NatFirewallRulesExpectedBlockFirewallDisabled)
2557 {
2558 HYPERV_FIREWALL_TEST_ONLY();
2559 SKIP_TEST_UNSTABLE();
@@ -2619,7 +2564,7 @@ class NetworkTests
2564 FirewallRuleBlockedTests(FirewallTestConnectivity::Allowed);
2565 }
2566
2622 - TEST_METHOD(NatFirewallRulesExpectedBlockFirewallDisabledByPolicy)
2567 + WSL2_TEST_METHOD(NatFirewallRulesExpectedBlockFirewallDisabledByPolicy)
2568 {
2569 HYPERV_FIREWALL_TEST_ONLY();
2570
@@ -2659,7 +2604,7 @@ class NetworkTests
2604 AddFirewallRuleAndValidateTraffic(allowHyperVRule, expectedConnectivity);
2605 }
2606
2662 - TEST_METHOD(NatFirewallRulesExpectedAllow)
2607 + WSL2_TEST_METHOD(NatFirewallRulesExpectedAllow)
2608 {
2609 HYPERV_FIREWALL_TEST_ONLY();
2610 WslConfigChange config(LxssGenerateTestConfig({.firewall = true}));
@@ -2668,7 +2613,7 @@ class NetworkTests
2613 FirewallRuleAllowedTests(FirewallTestConnectivity::Allowed);
2614 }
2615
2671 - TEST_METHOD(NatFirewallRulesExpectedAllowFirewallDisabled)
2616 + WSL2_TEST_METHOD(NatFirewallRulesExpectedAllowFirewallDisabled)
2617 {
2618 HYPERV_FIREWALL_TEST_ONLY();
2619 SKIP_TEST_UNSTABLE();
@@ -2746,7 +2691,7 @@ class NetworkTests
2691 blockRule, isHyperVFirewallEnabled ? FirewallTestConnectivity::Blocked : FirewallTestConnectivity::Allowed);
2692 }
2693
2749 - TEST_METHOD(NatFirewallRulesEnabledSetting)
2694 + WSL2_TEST_METHOD(NatFirewallRulesEnabledSetting)
2695 {
2696 HYPERV_FIREWALL_TEST_ONLY();
2697 WslConfigChange config(LxssGenerateTestConfig({.firewall = true}));
@@ -2755,7 +2700,7 @@ class NetworkTests
2700 FirewallSettingEnabledTests(true);
2701 }
2702
2758 - TEST_METHOD(NatFirewallRulesEnabledSettingFirewallDisabled)
2703 + WSL2_TEST_METHOD(NatFirewallRulesEnabledSettingFirewallDisabled)
2704 {
2705 HYPERV_FIREWALL_TEST_ONLY();
2706 SKIP_TEST_UNSTABLE();
@@ -3050,8 +2995,6 @@ class NetworkTests
2995
2996 void TestCase(const std::vector<InterfaceState>& interfaceStates)
2997 {
3053 - WSL2_TEST_ONLY();
3054 -
2998 for (const auto& state : interfaceStates)
2999 {
3000 if (state.Rename)
@@ -3533,10 +3476,8 @@ class NetworkTests
3476 VERIFY_IS_FALSE(Watchdog.IsExpired());
3477 }
3478
3536 - TEST_METHOD(ConnectivityCheckTestNATDefaultSuccess)
3479 + WSL2_TEST_METHOD(ConnectivityCheckTestNATDefaultSuccess)
3480 {
3538 - WSL2_TEST_ONLY();
3539 -
3481 WslConfigChange config(LxssGenerateTestConfig());
3482 WaitForNATStateInLinux();
3483
@@ -3586,10 +3527,8 @@ class NetworkTests
3527 RunGns("www.msftconnecttest.com", AdapterId, LxGnsMessageConnectTestRequest, testErrorCode);
3528 }
3529
3589 - TEST_METHOD(ConnectivityCheckTestNATNameResolutionFailure)
3530 + WSL2_TEST_METHOD(ConnectivityCheckTestNATNameResolutionFailure)
3531 {
3591 - WSL2_TEST_ONLY();
3592 -
3532 WslConfigChange config(LxssGenerateTestConfig());
3533 WaitForNATStateInLinux();
3534
@@ -3613,10 +3552,8 @@ class NetworkTests
3552 RunGns("asdlkfadsf.bbcxzncvb", AdapterId, LxGnsMessageConnectTestRequest, testErrorCode);
3553 }
3554
3616 - TEST_METHOD(ConnectivityCheckTestNATNameResolvesButConnectivityFails)
3555 + WSL2_TEST_METHOD(ConnectivityCheckTestNATNameResolvesButConnectivityFails)
3556 {
3618 - WSL2_TEST_ONLY();
3619 -
3557 WslConfigChange config(LxssGenerateTestConfig());
3558 WaitForNATStateInLinux();
3559
@@ -3679,7 +3616,7 @@ class MirroredTests
3616 return true;
3617 }
3618
3682 - TEST_METHOD(DnsTunneling)
3619 + WSL2_TEST_METHOD(DnsTunneling)
3620 {
3621 DNS_TUNNELING_TEST_ONLY();
3622 MIRRORED_NETWORKING_TEST_ONLY();
@@ -3690,7 +3627,7 @@ class MirroredTests
3627 NetworkTests::VerifyDnsTunneling(c_dnsTunnelingDefaultIp);
3628 }
3629
3693 - TEST_METHOD(DnsTunnelingWithSpecificIp)
3630 + WSL2_TEST_METHOD(DnsTunnelingWithSpecificIp)
3631 {
3632 DNS_TUNNELING_TEST_ONLY();
3633 MIRRORED_NETWORKING_TEST_ONLY();
@@ -3702,7 +3639,7 @@ class MirroredTests
3639 NetworkTests::VerifyDnsTunneling(L"10.255.255.1");
3640 }
3641
3705 - TEST_METHOD(DnsTunnelingVerifySuffixes)
3642 + WSL2_TEST_METHOD(DnsTunnelingVerifySuffixes)
3643 {
3644 DNS_TUNNELING_TEST_ONLY();
3645 MIRRORED_NETWORKING_TEST_ONLY();
@@ -3713,7 +3650,7 @@ class MirroredTests
3650 NetworkTests::VerifyDnsSuffixes();
3651 }
3652
3716 - TEST_METHOD(WithoutTunnelingVerifySuffixes)
3653 + WSL2_TEST_METHOD(WithoutTunnelingVerifySuffixes)
3654 {
3655 MIRRORED_NETWORKING_TEST_ONLY();
3656
@@ -3723,7 +3660,7 @@ class MirroredTests
3660 NetworkTests::VerifyDnsSuffixes();
3661 }
3662
3726 - TEST_METHOD(HttpProxyVerifyConfigDisabled)
3663 + WSL2_TEST_METHOD(HttpProxyVerifyConfigDisabled)
3664 {
3665 MIRRORED_NETWORKING_TEST_ONLY();
3666 WINHTTP_PROXY_TEST_ONLY();
@@ -3735,7 +3672,7 @@ class MirroredTests
3672 NetworkTests::VerifyHttpProxyEnvVariables(L"", L"", L"");
3673 }
3674
3738 - TEST_METHOD(HttpProxySimple)
3675 + WSL2_TEST_METHOD(HttpProxySimple)
3676 {
3677 MIRRORED_NETWORKING_TEST_ONLY();
3678 WINHTTP_PROXY_TEST_ONLY();
@@ -3745,7 +3682,7 @@ class MirroredTests
3682 NetworkTests::VerifyHttpProxySimple();
3683 }
3684
3748 - TEST_METHOD(HttpProxySimpleMachineScope)
3685 + WSL2_TEST_METHOD(HttpProxySimpleMachineScope)
3686 {
3687 MIRRORED_NETWORKING_TEST_ONLY();
3688 WINHTTP_PROXY_TEST_ONLY();
@@ -3757,7 +3694,7 @@ class MirroredTests
3694 NetworkTests::VerifyHttpProxySimple(false);
3695 }
3696
3760 - TEST_METHOD(NoHttpProxyConfigured)
3697 + WSL2_TEST_METHOD(NoHttpProxyConfigured)
3698 {
3699 MIRRORED_NETWORKING_TEST_ONLY();
3700 WINHTTP_PROXY_TEST_ONLY();
@@ -3767,7 +3704,7 @@ class MirroredTests
3704 NetworkTests::VerifyNoHttpProxyConfigured();
3705 }
3706
3770 - TEST_METHOD(HttpProxyWithBypassesConfigured)
3707 + WSL2_TEST_METHOD(HttpProxyWithBypassesConfigured)
3708 {
3709 MIRRORED_NETWORKING_TEST_ONLY();
3710 WINHTTP_PROXY_TEST_ONLY();
@@ -3777,7 +3714,7 @@ class MirroredTests
3714 NetworkTests::VerifyHttpProxyWithBypassesConfigured();
3715 }
3716
3780 - TEST_METHOD(HttpProxyChange)
3717 + WSL2_TEST_METHOD(HttpProxyChange)
3718 {
3719 MIRRORED_NETWORKING_TEST_ONLY();
3720 WINHTTP_PROXY_TEST_ONLY();
@@ -3787,7 +3724,7 @@ class MirroredTests
3724 NetworkTests::VerifyHttpProxyChange();
3725 }
3726
3790 - TEST_METHOD(HttpProxyAndWslEnv)
3727 + WSL2_TEST_METHOD(HttpProxyAndWslEnv)
3728 {
3729 MIRRORED_NETWORKING_TEST_ONLY();
3730 WINHTTP_PROXY_TEST_ONLY();
@@ -3796,7 +3733,7 @@ class MirroredTests
3733 NetworkTests::VerifyHttpProxyAndWslEnv();
3734 }
3735
3799 - TEST_METHOD(HttpProxyFilterByNetworkConfiguration)
3736 + WSL2_TEST_METHOD(HttpProxyFilterByNetworkConfiguration)
3737 {
3738 MIRRORED_NETWORKING_TEST_ONLY();
3739 WINHTTP_PROXY_TEST_ONLY();
@@ -3805,7 +3742,7 @@ class MirroredTests
3742 NetworkTests::VerifyHttpProxyFilterByNetworkConfigurationMirrored();
3743 }
3744
3808 - TEST_METHOD(SmokeTest)
3745 + WSL2_TEST_METHOD(SmokeTest)
3746 {
3747 MIRRORED_NETWORKING_TEST_ONLY();
3748
@@ -3816,7 +3753,7 @@ class MirroredTests
3753 NetworkTests::GuestClient(L"tcp-connect:bing.com:80");
3754 }
3755
3819 - TEST_METHOD(InternetConnectivityV4)
3756 + WSL2_TEST_METHOD(InternetConnectivityV4)
3757 {
3758 MIRRORED_NETWORKING_TEST_ONLY();
3759
@@ -3832,7 +3769,7 @@ class MirroredTests
3769 NetworkTests::GuestClient(L"tcp4-connect:bing.com:80");
3770 }
3771
3835 - TEST_METHOD(InternetConnectivityV6)
3772 + WSL2_TEST_METHOD(InternetConnectivityV6)
3773 {
3774 MIRRORED_NETWORKING_TEST_ONLY();
3775
@@ -3848,7 +3785,7 @@ class MirroredTests
3785 NetworkTests::GuestClient(L"tcp6-connect:bing.com:80");
3786 }
3787
3851 - TEST_METHOD(LoopbackLocal)
3788 + WSL2_TEST_METHOD(LoopbackLocal)
3789 {
3790 MIRRORED_NETWORKING_TEST_ONLY();
3791
@@ -3892,7 +3829,7 @@ class MirroredTests
3829 // VerifyLoopbackConnectivity(L"::1");
3830 }
3831
3895 - TEST_METHOD(LoopbackSystemd)
3832 + WSL2_TEST_METHOD(LoopbackSystemd)
3833 {
3834 MIRRORED_NETWORKING_TEST_ONLY();
3835
@@ -3918,7 +3855,7 @@ class MirroredTests
3855 NetworkTests::VerifyLoopbackGuestToHost(L"127.0.0.1", IPPROTO_TCP);
3856 }
3857
3921 - TEST_METHOD(GuestPortCantBeBoundByHost)
3858 + WSL2_TEST_METHOD(GuestPortCantBeBoundByHost)
3859 {
3860 MIRRORED_NETWORKING_TEST_ONLY();
3861
@@ -3936,7 +3873,7 @@ class MirroredTests
3873 }
3874 }
3875
3939 - TEST_METHOD(GuestPortIsReleased)
3876 + WSL2_TEST_METHOD(GuestPortIsReleased)
3877 {
3878 MIRRORED_NETWORKING_TEST_ONLY();
3879
@@ -3970,7 +3907,7 @@ class MirroredTests
3907 VERIFY_IS_TRUE(bound);
3908 }
3909
3973 - TEST_METHOD(HostPortCantBeBoundByGuest)
3910 + WSL2_TEST_METHOD(HostPortCantBeBoundByGuest)
3911 {
3912 MIRRORED_NETWORKING_TEST_ONLY();
3913
@@ -3988,7 +3925,7 @@ class MirroredTests
3925 }
3926 }
3927
3991 - TEST_METHOD(UdpBindDoesNotPreventTcpBind)
3928 + WSL2_TEST_METHOD(UdpBindDoesNotPreventTcpBind)
3929 {
3930 MIRRORED_NETWORKING_TEST_ONLY();
3931
@@ -3999,7 +3936,7 @@ class MirroredTests
3936 auto udpPort = NetworkTests::BindGuestPort(L"UDP4-LISTEN:1234", true);
3937 }
3938
4002 - TEST_METHOD(HostUdpBindDoesNotPreventGuestTcpBind)
3939 + WSL2_TEST_METHOD(HostUdpBindDoesNotPreventGuestTcpBind)
3940 {
3941 MIRRORED_NETWORKING_TEST_ONLY();
3942
@@ -4010,7 +3947,7 @@ class MirroredTests
3947 auto tcpPort = NetworkTests::BindGuestPort(L"TCP4-LISTEN:2345", true);
3948 }
3949
4013 - TEST_METHOD(MultipleGuestBindOnSameTuple)
3950 + WSL2_TEST_METHOD(MultipleGuestBindOnSameTuple)
3951 {
3952 MIRRORED_NETWORKING_TEST_ONLY();
3953
@@ -4040,7 +3977,7 @@ class MirroredTests
3977 }
3978 }
3979
4043 - TEST_METHOD(EphemeralBind)
3980 + WSL2_TEST_METHOD(EphemeralBind)
3981 {
3982 MIRRORED_NETWORKING_TEST_ONLY();
3983
@@ -4051,7 +3988,7 @@ class MirroredTests
3988 auto udpPort = NetworkTests::BindGuestPort(L"UDP4-LISTEN:0", true);
3989 }
3990
4054 - TEST_METHOD(PortZeroBindIsTracked)
3991 + WSL2_TEST_METHOD(PortZeroBindIsTracked)
3992 {
3993 MIRRORED_NETWORKING_TEST_ONLY();
3994
@@ -4066,7 +4003,7 @@ class MirroredTests
4003 NetworkTests::VerifyPortZeroBindIsTracked(false);
4004 }
4005
4069 - TEST_METHOD(ExplicitEphemeralBind)
4006 + WSL2_TEST_METHOD(ExplicitEphemeralBind)
4007 {
4008 MIRRORED_NETWORKING_TEST_ONLY();
4009
@@ -4111,7 +4048,7 @@ class MirroredTests
4048 VERIFY_IS_TRUE(canBindUdp);
4049 }
4050
4114 - TEST_METHOD(NonRootNamespaceEphemeralBind)
4051 + WSL2_TEST_METHOD(NonRootNamespaceEphemeralBind)
4052 {
4053 MIRRORED_NETWORKING_TEST_ONLY();
4054
@@ -4127,7 +4064,7 @@ class MirroredTests
4064
4065 // Verifies that in mirrored mode, Windows can connect to a listener running in a Linux network namespace different from
4066 // the Linux root network namespace.
4130 - TEST_METHOD(PortForwardingToNonRootNamespace)
4067 + WSL2_TEST_METHOD(PortForwardingToNonRootNamespace)
4068 {
4069 MIRRORED_NETWORKING_TEST_ONLY();
4070
@@ -4207,7 +4144,7 @@ class MirroredTests
4144 VERIFY_ARE_EQUAL(connect(clientSocket.get(), reinterpret_cast<SOCKADDR*>(&serverAddr), sizeof(serverAddr)), 0);
4145 }
4146
4210 - TEST_METHOD(LinuxNonRootNamespaceConnectToWindowsHost)
4147 + WSL2_TEST_METHOD(LinuxNonRootNamespaceConnectToWindowsHost)
4148 {
4149 MIRRORED_NETWORKING_TEST_ONLY();
4150
@@ -4280,7 +4217,7 @@ class MirroredTests
4217 VERIFY_ARE_NOT_EQUAL(warnings.find(L"starting data transfer loop"), std::string::npos);
4218 }
4219
4283 - TEST_METHOD(ResolvConf)
4220 + WSL2_TEST_METHOD(ResolvConf)
4221 {
4222 MIRRORED_NETWORKING_TEST_ONLY();
4223
@@ -4293,7 +4230,7 @@ class MirroredTests
4230 VERIFY_IS_TRUE(std::regex_match(out, pattern));
4231 }
4232
4296 - TEST_METHOD(NetworkSettings)
4233 + WSL2_TEST_METHOD(NetworkSettings)
4234 {
4235 MIRRORED_NETWORKING_TEST_ONLY();
4236
@@ -4331,7 +4268,7 @@ class MirroredTests
4268 }
4269 }
4270
4334 - TEST_METHOD(FirewallRulesExpectedBlock)
4271 + WSL2_TEST_METHOD(FirewallRulesExpectedBlock)
4272 {
4273 HYPERV_FIREWALL_TEST_ONLY();
4274 MIRRORED_NETWORKING_TEST_ONLY();
@@ -4345,7 +4282,7 @@ class MirroredTests
4282 NetworkTests::FirewallRuleBlockedTests(NetworkTests::FirewallTestConnectivity::Blocked);
4283 }
4284
4348 - TEST_METHOD(FirewallRulesExpectedAllow)
4285 + WSL2_TEST_METHOD(FirewallRulesExpectedAllow)
4286 {
4287 HYPERV_FIREWALL_TEST_ONLY();
4288 MIRRORED_NETWORKING_TEST_ONLY();
@@ -4359,7 +4296,7 @@ class MirroredTests
4296 NetworkTests::FirewallRuleAllowedTests(NetworkTests::FirewallTestConnectivity::Allowed);
4297 }
4298
4362 - TEST_METHOD(FirewallRulesEnabledSetting)
4299 + WSL2_TEST_METHOD(FirewallRulesEnabledSetting)
4300 {
4301 HYPERV_FIREWALL_TEST_ONLY();
4302 MIRRORED_NETWORKING_TEST_ONLY();
@@ -4373,9 +4310,8 @@ class MirroredTests
4310 NetworkTests::FirewallSettingEnabledTests(true);
4311 }
4312
4376 - TEST_METHOD(ConnectivityCheckTestDefaultSuccess)
4313 + WSL2_TEST_METHOD(ConnectivityCheckTestDefaultSuccess)
4314 {
4378 - WSL2_TEST_ONLY();
4315 MIRRORED_NETWORKING_TEST_ONLY();
4316
4317 SKIP_TEST_UNSTABLE();
@@ -4428,9 +4364,8 @@ class MirroredTests
4364 NetworkTests::RunGns("www.msftconnecttest.com", AdapterId, LxGnsMessageConnectTestRequest, testErrorCode);
4365 }
4366
4431 - TEST_METHOD(ConnectivityCheckTestNameResolutionFailure)
4367 + WSL2_TEST_METHOD(ConnectivityCheckTestNameResolutionFailure)
4368 {
4433 - WSL2_TEST_ONLY();
4369 MIRRORED_NETWORKING_TEST_ONLY();
4370
4371 m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::Mirrored}));
@@ -4456,9 +4391,8 @@ class MirroredTests
4391 NetworkTests::RunGns("asdlkfadsf.bbcxzncvb", AdapterId, LxGnsMessageConnectTestRequest, testErrorCode);
4392 }
4393
4459 - TEST_METHOD(ConnectivityCheckTestNameResolvesButConnectivityFails)
4394 + WSL2_TEST_METHOD(ConnectivityCheckTestNameResolvesButConnectivityFails)
4395 {
4461 - WSL2_TEST_ONLY();
4396 MIRRORED_NETWORKING_TEST_ONLY();
4397
4398 SKIP_TEST_UNSTABLE();
@@ -4554,7 +4488,7 @@ class MirroredTests
4488 VERIFY_IS_FALSE(Watchdog.IsExpired());
4489 }
4490
4557 - TEST_METHOD(DnsResolutionBasic)
4491 + WSL2_TEST_METHOD(DnsResolutionBasic)
4492 {
4493 MIRRORED_NETWORKING_TEST_ONLY();
4494
@@ -4564,7 +4498,7 @@ class MirroredTests
4498 NetworkTests::VerifyDnsResolutionBasic();
4499 }
4500
4567 - TEST_METHOD(DnsResolutionDig)
4501 + WSL2_TEST_METHOD(DnsResolutionDig)
4502 {
4503 MIRRORED_NETWORKING_TEST_ONLY();
4504
@@ -4574,7 +4508,7 @@ class MirroredTests
4508 NetworkTests::VerifyDnsResolutionDig();
4509 }
4510
4577 - TEST_METHOD(DnsResolutionRecordTypes)
4511 + WSL2_TEST_METHOD(DnsResolutionRecordTypes)
4512 {
4513 MIRRORED_NETWORKING_TEST_ONLY();
4514
@@ -4612,9 +4546,8 @@ class BridgedTests
4546 return true;
4547 }
4548
4615 - TEST_METHOD(Basic)
4549 + WSL2_TEST_METHOD(Basic)
4550 {
4617 - WSL2_TEST_ONLY();
4551 WINDOWS_11_TEST_ONLY();
4552
4553 // There's no way to guarantee that an external switch will work in the test environment
@@ -4626,9 +4559,8 @@ class BridgedTests
4559 VERIFY_ARE_EQUAL(L"1\n", out);
4560 }
4561
4629 - TEST_METHOD(CustomMac)
4562 + WSL2_TEST_METHOD(CustomMac)
4563 {
4631 - WSL2_TEST_ONLY();
4564 WINDOWS_11_TEST_ONLY();
4565
4566 constexpr auto mac = L"aa:bb:cc:dd:ee:ff";
@@ -4638,9 +4570,8 @@ class BridgedTests
4570 VERIFY_ARE_EQUAL(mac, GetMacAddress());
4571 }
4572
4641 - TEST_METHOD(CustomMacDashes)
4573 + WSL2_TEST_METHOD(CustomMacDashes)
4574 {
4643 - WSL2_TEST_ONLY();
4575 WINDOWS_11_TEST_ONLY();
4576
4577 // Note: The SynthNic fails to start if the first byte of the mac address is 0xff.
@@ -4653,9 +4584,8 @@ class BridgedTests
4584 VERIFY_ARE_EQUAL(mac, GetMacAddress());
4585 }
4586
4656 - TEST_METHOD(Ipv6)
4587 + WSL2_TEST_METHOD(Ipv6)
4588 {
4658 - WSL2_TEST_ONLY();
4589 WINDOWS_11_TEST_ONLY();
4590
4591 m_config->Update(LxssGenerateTestConfig(
@@ -4665,9 +4595,8 @@ class BridgedTests
4595 VERIFY_ARE_EQUAL(L"0\n", out);
4596 }
4597
4668 - TEST_METHOD(SmokeTest)
4598 + WSL2_TEST_METHOD(SmokeTest)
4599 {
4670 - WSL2_TEST_ONLY();
4600 WINDOWS_11_TEST_ONLY();
4601
4602 if (!NetworkTests::HostHasInternetConnectivity(AF_INET) && !NetworkTests::HostHasInternetConnectivity(AF_INET6))
@@ -4682,9 +4611,8 @@ class BridgedTests
4611 NetworkTests::GuestClient(L"tcp-connect:bing.com:80");
4612 }
4613
4685 - TEST_METHOD(InternetConnectivityV4)
4614 + WSL2_TEST_METHOD(InternetConnectivityV4)
4615 {
4687 - WSL2_TEST_ONLY();
4616 WINDOWS_11_TEST_ONLY();
4617
4618 if (!NetworkTests::HostHasInternetConnectivity(AF_INET))
@@ -4698,9 +4626,8 @@ class BridgedTests
4626 NetworkTests::GuestClient(L"tcp4-connect:bing.com:80");
4627 }
4628
4701 - TEST_METHOD(InternetConnectivityV6)
4629 + WSL2_TEST_METHOD(InternetConnectivityV6)
4630 {
4703 - WSL2_TEST_ONLY();
4631 WINDOWS_11_TEST_ONLY();
4632
4633 if (!NetworkTests::HostHasInternetConnectivity(AF_INET6))
@@ -4742,7 +4669,7 @@ class VirtioProxyTests
4669 return true;
4670 }
4671
4745 - TEST_METHOD(SmokeTest)
4672 + WSL2_TEST_METHOD(SmokeTest)
4673 {
4674 VIRTIOPROXY_TEST_ONLY();
4675
@@ -4752,7 +4679,7 @@ class VirtioProxyTests
4679 NetworkTests::GuestClient(L"tcp-connect:bing.com:80");
4680 }
4681
4755 - TEST_METHOD(InternetConnectivityV4)
4682 + WSL2_TEST_METHOD(InternetConnectivityV4)
4683 {
4684 VIRTIOPROXY_TEST_ONLY();
4685
@@ -4767,7 +4694,7 @@ class VirtioProxyTests
4694 NetworkTests::GuestClient(L"tcp4-connect:bing.com:80");
4695 }
4696
4770 - TEST_METHOD(InternetConnectivityV6)
4697 + WSL2_TEST_METHOD(InternetConnectivityV6)
4698 {
4699 VIRTIOPROXY_TEST_ONLY();
4700
@@ -4784,7 +4711,7 @@ class VirtioProxyTests
4711 NetworkTests::GuestClient(L"tcp6-connect:bing.com:80");
4712 }
4713
4787 - TEST_METHOD(Configuration)
4714 + WSL2_TEST_METHOD(Configuration)
4715 {
4716 VIRTIOPROXY_TEST_ONLY();
4717
@@ -4809,7 +4736,7 @@ class VirtioProxyTests
4736 }
4737 }
4738
4812 - TEST_METHOD(GuestPortIsReleased)
4739 + WSL2_TEST_METHOD(GuestPortIsReleased)
4740 {
4741 VIRTIOPROXY_TEST_ONLY();
4742
@@ -4837,7 +4764,7 @@ class VirtioProxyTests
4764 std::chrono::minutes(2));
4765 }
4766
4840 - TEST_METHOD(LoopbackGuestToHost)
4767 + WSL2_TEST_METHOD(LoopbackGuestToHost)
4768 {
4769 VIRTIOPROXY_TEST_ONLY();
4770
@@ -4851,7 +4778,7 @@ class VirtioProxyTests
4778 // NetworkTests::VerifyLoopbackGuestToHost(L"::", IPPROTO_TCP);
4779 }
4780
4854 - TEST_METHOD(UdpBindDoesNotPreventTcpBind)
4781 + WSL2_TEST_METHOD(UdpBindDoesNotPreventTcpBind)
4782 {
4783 VIRTIOPROXY_TEST_ONLY();
4784
@@ -4861,7 +4788,7 @@ class VirtioProxyTests
4788 auto udpPort = NetworkTests::BindGuestPort(L"UDP4-LISTEN:1234", true);
4789 }
4790
4864 - TEST_METHOD(HostUdpBindDoesNotPreventGuestTcpBind)
4791 + WSL2_TEST_METHOD(HostUdpBindDoesNotPreventGuestTcpBind)
4792 {
4793 VIRTIOPROXY_TEST_ONLY();
4794
@@ -4871,7 +4798,7 @@ class VirtioProxyTests
4798 auto tcpPort = NetworkTests::BindGuestPort(L"TCP4-LISTEN:2345", true);
4799 }
4800
4874 - TEST_METHOD(PortZeroBindIsTracked)
4801 + WSL2_TEST_METHOD(PortZeroBindIsTracked)
4802 {
4803 VIRTIOPROXY_TEST_ONLY();
4804
@@ -4880,7 +4807,7 @@ class VirtioProxyTests
4807 NetworkTests::VerifyPortZeroBindIsTracked();
4808 }
4809
4883 - TEST_METHOD(HttpProxySimple)
4810 + WSL2_TEST_METHOD(HttpProxySimple)
4811 {
4812 VIRTIOPROXY_TEST_ONLY();
4813 WINHTTP_PROXY_TEST_ONLY();
@@ -4889,7 +4816,7 @@ class VirtioProxyTests
4816 NetworkTests::VerifyHttpProxySimple();
4817 }
4818
4892 - TEST_METHOD(ConfigurationV6)
4819 + WSL2_TEST_METHOD(ConfigurationV6)
4820 {
4821 VIRTIOPROXY_TEST_ONLY();
4822
@@ -4964,7 +4891,7 @@ class VirtioProxyTests
4891 }
4892 }
4893
4967 - TEST_METHOD(GuestPortIsReleasedV6)
4894 + WSL2_TEST_METHOD(GuestPortIsReleasedV6)
4895 {
4896 VIRTIOPROXY_TEST_ONLY();
4897 WINDOWS_11_TEST_ONLY();
@@ -4993,7 +4920,7 @@ class VirtioProxyTests
4920 std::chrono::minutes(2));
4921 }
4922
4996 - TEST_METHOD(ConfigurationV6DnsServers)
4923 + WSL2_TEST_METHOD(ConfigurationV6DnsServers)
4924 {
4925 VIRTIOPROXY_TEST_ONLY();
4926
@@ -5018,7 +4945,7 @@ class VirtioProxyTests
4945 VERIFY_IS_TRUE(std::regex_match(out, v6Pattern));
4946 }
4947
5021 - TEST_METHOD(DnsResolutionBasic)
4948 + WSL2_TEST_METHOD(DnsResolutionBasic)
4949 {
4950 VIRTIOPROXY_TEST_ONLY();
4951
@@ -5026,7 +4953,7 @@ class VirtioProxyTests
4953 NetworkTests::VerifyDnsResolutionBasic();
4954 }
4955
5029 - TEST_METHOD(DnsResolutionDig)
4956 + WSL2_TEST_METHOD(DnsResolutionDig)
4957 {
4958 VIRTIOPROXY_TEST_ONLY();
4959
@@ -5034,12 +4961,39 @@ class VirtioProxyTests
4961 NetworkTests::VerifyDnsResolutionDig();
4962 }
4963
5037 - TEST_METHOD(DnsResolutionRecordTypes)
4964 + WSL2_TEST_METHOD(DnsResolutionRecordTypes)
4965 {
4966 VIRTIOPROXY_TEST_ONLY();
4967
4968 m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy, .dnsTunneling = false}));
4969 NetworkTests::VerifyDnsResolutionRecordTypes();
4970 }
4971 +
4972 + WSL2_TEST_METHOD(DnsResolutionBasicDnsTunneling)
4973 + {
4974 + VIRTIOPROXY_TEST_ONLY();
4975 + DNS_TUNNELING_TEST_ONLY();
4976 +
4977 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy, .dnsTunneling = true}));
4978 + NetworkTests::VerifyDnsResolutionBasic();
4979 + }
4980 +
4981 + WSL2_TEST_METHOD(DnsResolutionDigDnsTunneling)
4982 + {
4983 + VIRTIOPROXY_TEST_ONLY();
4984 + DNS_TUNNELING_TEST_ONLY();
4985 +
4986 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy, .dnsTunneling = true}));
4987 + NetworkTests::VerifyDnsResolutionDig();
4988 + }
4989 +
4990 + WSL2_TEST_METHOD(DnsResolutionRecordTypesDnsTunneling)
4991 + {
4992 + VIRTIOPROXY_TEST_ONLY();
4993 + DNS_TUNNELING_TEST_ONLY();
4994 +
4995 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy, .dnsTunneling = true}));
4996 + NetworkTests::VerifyDnsResolutionRecordTypes();
4997 + }
4998 };
4999 } // namespace NetworkTests
test/windows/PluginTests.cpp
+25 -74
@@ -150,10 +150,8 @@ class PluginTests
150 }
151 }
152
153 - TEST_METHOD(Success)
153 + WSL2_TEST_METHOD(Success)
154 {
155 - WSL2_TEST_ONLY();
156 -
155 constexpr auto ExpectedOutput =
156 LR"(Plugin loaded. TestMode=1
157 VM created (settings->CustomConfigurationFlags=0)
@@ -168,10 +166,8 @@ class PluginTests
166 ValidateLogFile(ExpectedOutput);
167 }
168
171 - TEST_METHOD(CustomKernelOverriddenByPolicy)
169 + WSL2_TEST_METHOD(CustomKernelOverriddenByPolicy)
170 {
173 - WSL2_TEST_ONLY();
174 -
171 RegistryKeyChange policy(
172 HKEY_LOCAL_MACHINE, wsl::windows::policies::c_registryKey, wsl::windows::policies::c_allowCustomKernelUserSetting, static_cast<DWORD>(0));
173
@@ -191,10 +187,8 @@ class PluginTests
187 ValidateLogFile(ExpectedOutput);
188 }
189
194 - TEST_METHOD(DuplicatedPlugin)
190 + WSL2_TEST_METHOD(DuplicatedPlugin)
191 {
196 - WSL2_TEST_ONLY();
197 -
192 constexpr auto ExpectedOutput =
193 LR"(Plugin loaded. TestMode=1
194 VM created (settings->CustomConfigurationFlags=0)
@@ -217,10 +211,8 @@ class PluginTests
211 ValidateLogFile(ExpectedOutput);
212 }
213
220 - TEST_METHOD(CustomKernel)
214 + WSL2_TEST_METHOD(CustomKernel)
215 {
222 - WSL2_TEST_ONLY();
223 -
216 constexpr auto ExpectedOutput =
217 LR"(Plugin loaded. TestMode=1
218 VM created (settings->CustomConfigurationFlags=1)
@@ -250,10 +242,8 @@ class PluginTests
242 ValidateLogFile(ExpectedOutput);
243 }
244
253 - TEST_METHOD(CustomKernelCommandLine)
245 + WSL2_TEST_METHOD(CustomKernelCommandLine)
246 {
255 - WSL2_TEST_ONLY();
256 -
247 constexpr auto ExpectedOutput =
248 LR"(Plugin loaded. TestMode=1
249 VM created (settings->CustomConfigurationFlags=2)
@@ -270,10 +260,8 @@ class PluginTests
260 ValidateLogFile(ExpectedOutput);
261 }
262
273 - TEST_METHOD(DistroIdStaysTheSame)
263 + WSL2_TEST_METHOD(DistroIdStaysTheSame)
264 {
275 - WSL2_TEST_ONLY();
276 -
265 constexpr auto ExpectedOutput =
266 LR"(Plugin loaded. TestMode=10
267 VM created (settings->CustomConfigurationFlags=0)
@@ -294,10 +282,8 @@ class PluginTests
282 ValidateLogFile(ExpectedOutput);
283 }
284
297 - TEST_METHOD(InitPidIsDifferent)
285 + WSL2_TEST_METHOD(InitPidIsDifferent)
286 {
299 - WSL2_TEST_ONLY();
300 -
287 constexpr auto ExpectedOutput =
288 LR"(Plugin loaded. TestMode=14
289 VM created (settings->CustomConfigurationFlags=0)
@@ -316,10 +302,8 @@ class PluginTests
302 ValidateLogFile(ExpectedOutput);
303 }
304
319 - TEST_METHOD(PluginUpdateRequired)
305 + WSL2_TEST_METHOD(PluginUpdateRequired)
306 {
321 - WSL2_TEST_ONLY();
322 -
307 constexpr auto ExpectedOutput =
308 LR"(Plugin loaded. TestMode=9
309 OnLoad: WSL_E_PLUGINREQUIRESUPDATE)";
@@ -333,10 +317,8 @@ class PluginTests
317 ValidateLogFile(ExpectedOutput);
318 }
319
336 - TEST_METHOD(APIErrors)
320 + WSL2_TEST_METHOD(APIErrors)
321 {
338 - WSL2_TEST_ONLY();
339 -
322 constexpr auto ExpectedOutput =
323 LR"(Plugin loaded. TestMode=7
324 VM created (settings->CustomConfigurationFlags=0)
@@ -350,10 +332,8 @@ class PluginTests
332 ValidateLogFile(ExpectedOutput);
333 }
334
353 - TEST_METHOD(SuccessWSL1)
335 + WSL1_TEST_METHOD(SuccessWSL1)
336 {
355 - WSL1_TEST_ONLY();
356 -
337 constexpr auto ExpectedOutput = LR"(Plugin loaded. TestMode=1)";
338
339 ConfigurePlugin(PluginTestType::Success);
@@ -361,9 +341,8 @@ class PluginTests
341 ValidateLogFile(ExpectedOutput);
342 }
343
364 - TEST_METHOD(LoadFailureFatalWSL2)
344 + WSL2_TEST_METHOD(LoadFailureFatalWSL2)
345 {
366 - WSL2_TEST_ONLY();
346 constexpr auto ExpectedOutput =
347 LR"(Plugin loaded. TestMode=2
348 OnLoad: E_UNEXPECTED)";
@@ -376,10 +355,8 @@ class PluginTests
355 ValidateLogFile(ExpectedOutput);
356 }
357
379 - TEST_METHOD(LoadFailureNonFatalWSL1)
358 + WSL1_TEST_METHOD(LoadFailureNonFatalWSL1)
359 {
381 - WSL1_TEST_ONLY();
382 -
360 constexpr auto ExpectedOutput =
361 LR"(Plugin loaded. TestMode=2
362 OnLoad: E_UNEXPECTED)";
@@ -389,10 +366,8 @@ class PluginTests
366 ValidateLogFile(ExpectedOutput);
367 }
368
392 - TEST_METHOD(VmStartFailure)
369 + WSL2_TEST_METHOD(VmStartFailure)
370 {
394 - WSL2_TEST_ONLY();
395 -
371 constexpr auto ExpectedOutput =
372 LR"(Plugin loaded. TestMode=3
373 VM created (settings->CustomConfigurationFlags=0)
@@ -407,10 +382,8 @@ class PluginTests
382 ValidateLogFile(ExpectedOutput);
383 }
384
410 - TEST_METHOD(VmStartFailureWithPluginErrorTwice)
385 + WSL2_TEST_METHOD(VmStartFailureWithPluginErrorTwice)
386 {
412 - WSL2_TEST_ONLY();
413 -
387 constexpr auto ExpectedOutput =
388 LR"(Plugin loaded. TestMode=13
389 VM created (settings->CustomConfigurationFlags=0)
@@ -435,10 +408,8 @@ class PluginTests
408 ValidateLogFile(ExpectedOutput);
409 }
410
438 - TEST_METHOD(VmStopFailure)
411 + WSL2_TEST_METHOD(VmStopFailure)
412 {
440 - WSL2_TEST_ONLY();
441 -
413 constexpr auto ExpectedOutput =
414 LR"(Plugin loaded. TestMode=5
415 VM created (settings->CustomConfigurationFlags=0)
@@ -452,10 +423,8 @@ class PluginTests
423 ValidateLogFile(ExpectedOutput);
424 }
425
455 - TEST_METHOD(DistributionStartFailure)
426 + WSL2_TEST_METHOD(DistributionStartFailure)
427 {
457 - WSL2_TEST_ONLY();
458 -
428 constexpr auto ExpectedOutput =
429 LR"(Plugin loaded. TestMode=4
430 VM created (settings->CustomConfigurationFlags=0)
@@ -472,10 +441,8 @@ class PluginTests
441 ValidateLogFile(ExpectedOutput);
442 }
443
475 - TEST_METHOD(DistributionStopFailure)
444 + WSL2_TEST_METHOD(DistributionStopFailure)
445 {
477 - WSL2_TEST_ONLY();
478 -
446 constexpr auto ExpectedOutput =
447 LR"(Plugin loaded. TestMode=6
448 VM created (settings->CustomConfigurationFlags=0)
@@ -489,10 +456,8 @@ class PluginTests
456 ValidateLogFile(ExpectedOutput);
457 }
458
492 - TEST_METHOD(ErrorMessageStartVm)
459 + WSL2_TEST_METHOD(ErrorMessageStartVm)
460 {
494 - WSL2_TEST_ONLY();
495 -
461 constexpr auto ExpectedOutput =
462 LR"(Plugin loaded. TestMode=11
463 VM created (settings->CustomConfigurationFlags=0)
@@ -508,10 +473,8 @@ class PluginTests
473 ValidateLogFile(ExpectedOutput);
474 }
475
511 - TEST_METHOD(ErrorMessageStartDistro)
476 + WSL2_TEST_METHOD(ErrorMessageStartDistro)
477 {
513 - WSL2_TEST_ONLY();
514 -
478 constexpr auto ExpectedOutput =
479 LR"(Plugin loaded. TestMode=12
480 VM created (settings->CustomConfigurationFlags=0)
@@ -529,10 +492,8 @@ class PluginTests
492 ValidateLogFile(ExpectedOutput);
493 }
494
532 - TEST_METHOD(RegisterSuccess)
495 + WSL2_TEST_METHOD(RegisterSuccess)
496 {
534 - WSL2_TEST_ONLY();
535 -
497 ConfigurePlugin(PluginTestType::Success);
498
499 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--import plugin-test-distro . \"" + g_testDistroPath + L"\" --version 2"), 0L);
@@ -550,10 +511,8 @@ class PluginTests
511 ValidateLogFile(ExpectedOutput);
512 }
513
553 - TEST_METHOD(ImportInplaceSuccess)
514 + WSL2_TEST_METHOD(ImportInplaceSuccess)
515 {
555 - WSL2_TEST_ONLY();
556 -
516 ConfigurePlugin(PluginTestType::Success);
517
518 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--import plugin-test-distro . \"" + g_testDistroPath + L"\" --version 2"), 0L);
@@ -581,10 +540,8 @@ class PluginTests
540 ValidateLogFile(ExpectedOutput);
541 }
542
584 - TEST_METHOD(RegisterUnregisterFail)
543 + WSL2_TEST_METHOD(RegisterUnregisterFail)
544 {
586 - WSL2_TEST_ONLY();
587 -
545 ConfigurePlugin(PluginTestType::FailToRegisterUnregisterDistro);
546
547 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--import plugin-test-distro . \"" + g_testDistroPath + L"\" --version 2"), 0L);
@@ -602,10 +559,8 @@ class PluginTests
559 ValidateLogFile(ExpectedOutput);
560 }
561
605 - TEST_METHOD(ExecuteDistroCommand)
562 + WSL2_TEST_METHOD(ExecuteDistroCommand)
563 {
607 - WSL2_TEST_ONLY();
608 -
564 ConfigurePlugin(PluginTestType::RunDistroCommand);
565
566 constexpr auto ExpectedOutput =
@@ -622,10 +577,8 @@ class PluginTests
577 ValidateLogFile(ExpectedOutput);
578 }
579
625 - TEST_METHOD(PluginToken)
580 + WSL2_TEST_METHOD(PluginToken)
581 {
627 - WSL2_TEST_ONLY();
628 -
582 ConfigurePlugin(PluginTestType::GetUsername);
583
584 constexpr auto ExpectedOutput =
@@ -640,10 +593,8 @@ class PluginTests
593 ValidateLogFile(ExpectedOutput);
594 }
595 // This test must run last so it doesn't break test cases that depends on plugin signature.
643 - TEST_METHOD(InvalidPluginSignature)
596 + WSL2_TEST_METHOD(InvalidPluginSignature)
597 {
645 - WSL2_TEST_ONLY();
646 -
598 if constexpr (!wsl::shared::OfficialBuild)
599 {
600 LogSkipped("This test only applies to signed builds");
test/windows/PolicyTests.cpp
+10 -29
@@ -73,11 +73,9 @@ class PolicyTest
73 }
74 };
75
76 - TEST_METHOD(MountPolicyAllowed)
76 + WSL2_TEST_METHOD(MountPolicyAllowed)
77 {
78 SKIP_TEST_ARM64();
79 - WSL2_TEST_ONLY();
80 -
79 auto revert = SetPolicy(c_allowDiskMount, 1);
80 ValidateOutput(
81 L"--mount DoesNotExist",
@@ -85,11 +83,9 @@ class PolicyTest
83 L"Error code: Wsl/Service/AttachDisk/MountDisk/HCS/ERROR_FILE_NOT_FOUND\r\n");
84 }
85
88 - TEST_METHOD(MountPolicyDisabled)
86 + WSL2_TEST_METHOD(MountPolicyDisabled)
87 {
88 SKIP_TEST_ARM64();
91 - WSL2_TEST_ONLY();
92 -
89 auto revert = SetPolicy(c_allowDiskMount, 0);
90 ValidateOutput(
91 L"--mount DoesNotExist",
@@ -128,10 +124,8 @@ class PolicyTest
124 }
125 }
126
131 - TEST_METHOD(KernelCommandLine)
127 + WSL2_TEST_METHOD(KernelCommandLine)
128 {
133 - WSL2_TEST_ONLY();
134 -
129 auto validate = [](DWORD policyValue) {
130 auto [commandLine, _] = LxsstuLaunchWslAndCaptureOutput(L"cat /proc/cmdline");
131
@@ -152,10 +146,9 @@ class PolicyTest
146 validate);
147 }
148
155 - TEST_METHOD(NestedVirtualization)
149 + WSL2_TEST_METHOD(NestedVirtualization)
150 {
151 SKIP_TEST_ARM64();
158 - WSL2_TEST_ONLY();
152 WINDOWS_11_TEST_ONLY();
153
154 ValidatePolicy(
@@ -164,10 +157,8 @@ class PolicyTest
157 L"wsl: The .wslconfig setting 'wsl2.nestedVirtualization' is disabled by the computer policy.\r\n");
158 }
159
167 - TEST_METHOD(KernelDebugging)
160 + WSL2_TEST_METHOD(KernelDebugging)
161 {
169 - WSL2_TEST_ONLY();
170 -
162 WINDOWS_11_TEST_ONLY();
163
164 ValidatePolicy(
@@ -176,10 +167,8 @@ class PolicyTest
167 L"wsl: The .wslconfig setting 'wsl2.kernelDebugPort' is disabled by the computer policy.\r\n");
168 }
169
179 - TEST_METHOD(CustomKernel)
170 + WSL2_TEST_METHOD(CustomKernel)
171 {
181 - WSL2_TEST_ONLY();
182 -
172 const std::wstring wslConfigPath = wsl::windows::common::helpers::GetWslConfigPath();
173 const std::wstring nonExistentFile = L"DoesNotExist";
174 WslConfigChange config(LxssGenerateTestConfig({.kernel = nonExistentFile.c_str(), .kernelModules = nonExistentFile.c_str()}));
@@ -215,10 +204,8 @@ class PolicyTest
204 }
205 }
206
218 - TEST_METHOD(CustomSystemDistro)
207 + WSL2_TEST_METHOD(CustomSystemDistro)
208 {
220 - WSL2_TEST_ONLY();
221 -
209 WslConfigChange config(LxssGenerateTestConfig() + L"systemDistro=DoesNotExist");
210 const std::wstring wslConfigPath = wsl::windows::common::helpers::GetWslConfigPath();
211
@@ -241,10 +228,8 @@ class PolicyTest
228 }
229 }
230
244 - TEST_METHOD(CustomNetworkingMode)
231 + WSL2_TEST_METHOD(CustomNetworkingMode)
232 {
246 - WSL2_TEST_ONLY();
247 -
233 WslConfigChange config(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
234
235 {
@@ -274,10 +259,8 @@ class PolicyTest
259 }
260 }
261
277 - TEST_METHOD(DebugShell)
262 + WSL2_TEST_METHOD(DebugShell)
263 {
279 - WSL2_TEST_ONLY();
280 -
264 auto revert = SetPolicy(c_allowDebugShellUserSetting, 0);
265 WslShutdown();
266
@@ -388,10 +371,8 @@ class PolicyTest
371 testPolicy(wsl::windows::policies::c_allowWSL, HRESULT_FROM_WIN32(ERROR_ACCESS_DISABLED_BY_POLICY), false);
372 }
373
391 - TEST_METHOD(DefaultNetworkingMode)
374 + WSL2_TEST_METHOD(DefaultNetworkingMode)
375 {
393 - WSL2_TEST_ONLY();
394 -
376 WslConfigChange config(LxssGenerateTestConfig());
377
378 {
test/windows/SimpleTests.cpp
+1 -3
@@ -73,10 +73,8 @@ class SimpleTests
73 VERIFY_IS_TRUE(WI_IsFlagSet(attributes, FILE_ATTRIBUTE_SPARSE_FILE) == sparse);
74 }
75
76 - TEST_METHOD(CheckSparse)
76 + WSL2_TEST_METHOD(CheckSparse)
77 {
78 - WSL2_TEST_ONLY();
79 -
78 WslConfigChange config(LxssGenerateTestConfig({.sparse = true}));
79
80 std::filesystem::path tar = std::tmpnam(nullptr);
test/windows/UnitTests.cpp
+60 -148
@@ -170,10 +170,8 @@ class UnitTests
170 }
171 }
172
173 - TEST_METHOD(SystemdSafeMode)
173 + WSL2_TEST_METHOD(SystemdSafeMode)
174 {
175 - WSL2_TEST_ONLY();
176 -
175 SKIP_TEST_UNSTABLE(); // TODO: Re-enable when this issue is solved in main.
176
177 auto revert = EnableSystemd();
@@ -190,19 +188,15 @@ class UnitTests
188 VERIFY_IS_TRUE(IsSystemdRunning(L"--system"));
189 }
190
193 - TEST_METHOD(SystemdDisabled)
191 + WSL2_TEST_METHOD(SystemdDisabled)
192 {
195 - WSL2_TEST_ONLY();
196 -
193 // tests that systemd does not run without the wsl.conf option enabled
194 // run and check the output of systemctl --system
195 VERIFY_IS_FALSE(IsSystemdRunning(L"--system", 1));
196 }
197
202 - TEST_METHOD(SystemdSystem)
198 + WSL2_TEST_METHOD(SystemdSystem)
199 {
204 - WSL2_TEST_ONLY();
205 -
200 auto cleanup = wil::scope_exit([] {
201 // clean up wsl.conf file
202 const std::wstring disableSystemdCmd(LXSST_REMOVE_DISTRO_CONF_COMMAND_LINE);
@@ -228,10 +222,8 @@ class UnitTests
222 VERIFY_ARE_EQUAL(out, L"LoadState=masked\n");
223 }
224
231 - TEST_METHOD(SystemdUser)
225 + WSL2_TEST_METHOD(SystemdUser)
226 {
233 - WSL2_TEST_ONLY();
234 -
227 // enable systemd before creating the user.
228 // if not called first, the runtime directories needed for --user will not have been created
229 auto cleanup = EnableSystemd();
@@ -337,10 +329,8 @@ class UnitTests
329 return false;
330 }
331
340 - TEST_METHOD(SystemdNoClearTmpUnit)
332 + WSL2_TEST_METHOD(SystemdNoClearTmpUnit)
333 {
342 - WSL2_TEST_ONLY();
343 -
334 // The X11 socket is only created when gui applications are enabled.
335 WslConfigChange config(LxssGenerateTestConfig({.guiApplications = true}));
336
@@ -355,10 +345,8 @@ class UnitTests
345 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test -d /tmp/.X11-unix"), 0L);
346 }
347
358 - TEST_METHOD(SystemdBinfmtIsRestored)
348 + WSL2_TEST_METHOD(SystemdBinfmtIsRestored)
349 {
360 - WSL2_TEST_ONLY();
361 -
350 // Override WSL's binfmt interpreter
351 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"mkdir -p /usr/lib/binfmt.d && echo ':WSLInterop:M::MZ::/bin/echo:PF' > /usr/lib/binfmt.d/dummy.conf"), 0L);
352
@@ -410,10 +398,8 @@ class UnitTests
398 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests dup", L"Dup"));
399 }
400
413 - TEST_METHOD(Epoll)
401 + WSL1_TEST_METHOD(Epoll)
402 {
415 - WSL1_TEST_ONLY();
416 -
403 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests epoll", L"Epoll"));
404 }
405
@@ -429,17 +415,13 @@ class UnitTests
415 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests flock", L"Flock"));
416 }
417
432 - TEST_METHOD(Fork)
418 + WSL1_TEST_METHOD(Fork)
419 {
434 - WSL1_TEST_ONLY();
435 -
420 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests fork", L"Fork"));
421 }
422
439 - TEST_METHOD(FsCommonLxFs)
423 + WSL1_TEST_METHOD(FsCommonLxFs)
424 {
441 - WSL1_TEST_ONLY();
442 -
425 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests fscommon", L"fscommon_lxfs"));
426 }
427
@@ -448,10 +430,8 @@ class UnitTests
430 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests get_set_id", L"get_set_id"));
431 }
432
451 - TEST_METHOD(Inotify)
433 + WSL1_TEST_METHOD(Inotify)
434 {
453 - WSL1_TEST_ONLY();
454 -
435 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests inotify", L"INOTIFY"));
436 }
437
@@ -479,45 +459,33 @@ class UnitTests
459 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests mprotect", L"mprotect"));
460 }
461
482 - TEST_METHOD(Pipe)
462 + WSL1_TEST_METHOD(Pipe)
463 {
484 - WSL1_TEST_ONLY();
485 -
464 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests pipe", L"Pipe"));
465 }
466
489 - TEST_METHOD(Sched)
467 + WSL1_TEST_METHOD(Sched)
468 {
491 - WSL1_TEST_ONLY();
492 -
469 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests sched", L"sched"));
470 }
471
496 - TEST_METHOD(SocketNonblocking)
472 + WSL1_TEST_METHOD(SocketNonblocking)
473 {
498 - WSL1_TEST_ONLY();
499 -
474 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests socket_nonblock", L"socket_nonblocking"));
475 }
476
503 - TEST_METHOD(Splice)
477 + WSL1_TEST_METHOD(Splice)
478 {
505 - WSL1_TEST_ONLY();
506 -
479 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests splice", L"Splice"));
480 }
481
510 - TEST_METHOD(Sysfs)
482 + WSL1_TEST_METHOD(Sysfs)
483 {
512 - WSL1_TEST_ONLY();
513 -
484 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests sysfs", L"SysFs"));
485 }
486
517 - TEST_METHOD(Tty)
487 + WSL1_TEST_METHOD(Tty)
488 {
519 - WSL1_TEST_ONLY();
520 -
489 auto OriginalHandles = UseOriginalStdHandles();
490
491 auto Restore = wil::scope_exit([&OriginalHandles]() { RestoreTestStdHandles(OriginalHandles); });
@@ -525,10 +493,8 @@ class UnitTests
493 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests tty", L"tty"));
494 }
495
528 - TEST_METHOD(Utimensat)
496 + WSL1_TEST_METHOD(Utimensat)
497 {
530 - WSL1_TEST_ONLY();
531 -
498 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests utimensat", L"Utimensat"));
499 }
500
@@ -552,10 +518,8 @@ class UnitTests
518 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests vfsaccess", L"vfsaccess"));
519 }
520
555 - TEST_METHOD(DevPt)
521 + WSL1_TEST_METHOD(DevPt)
522 {
557 - WSL1_TEST_ONLY();
558 -
523 auto OriginalHandles = UseOriginalStdHandles();
524
525 auto Restore = wil::scope_exit([&OriginalHandles]() { RestoreTestStdHandles(OriginalHandles); });
@@ -565,17 +529,13 @@ class UnitTests
529 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests dev_pt_2", L"dev_pt_2"));
530 }
531
568 - TEST_METHOD(Timer)
532 + WSL1_TEST_METHOD(Timer)
533 {
570 - WSL1_TEST_ONLY();
571 -
534 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests timer", L"timer"));
535 }
536
575 - TEST_METHOD(SysInfo)
537 + WSL1_TEST_METHOD(SysInfo)
538 {
577 - WSL1_TEST_ONLY();
578 -
539 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests sysinfo", L"Sysinfo"));
540 }
541
@@ -584,10 +544,8 @@ class UnitTests
544 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests timerfd", L"timerfd"));
545 }
546
587 - TEST_METHOD(Ioprio)
547 + WSL1_TEST_METHOD(Ioprio)
548 {
589 - WSL1_TEST_ONLY();
590 -
549 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests ioprio", L"Ioprio"));
550 }
551
@@ -705,10 +663,8 @@ class UnitTests
663 LxsstuLaunchWsl(L"stat -c %U /data/test/default_user_test | grep -iF kerneltest", nullptr, nullptr, nullptr, nullptr), 0u);
664 }
665
708 - TEST_METHOD(Execve)
666 + WSL1_TEST_METHOD(Execve)
667 {
710 - WSL1_TEST_ONLY();
711 -
668 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests execve", L"Execve"));
669 }
670
@@ -717,10 +673,8 @@ class UnitTests
673 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests xattr", L"xattr"));
674 }
675
720 - TEST_METHOD(Namespace)
676 + WSL1_TEST_METHOD(Namespace)
677 {
722 - WSL1_TEST_ONLY();
723 -
678 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests namespace", L"Namespace"));
679 }
680
@@ -754,17 +708,13 @@ class UnitTests
708 }
709 }
710
757 - TEST_METHOD(Netlink)
711 + WSL1_TEST_METHOD(Netlink)
712 {
759 - WSL1_TEST_ONLY();
760 -
713 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests netlink", L"Netlink"));
714 }
715
764 - TEST_METHOD(Random)
716 + WSL1_TEST_METHOD(Random)
717 {
766 - WSL1_TEST_ONLY();
767 -
718 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests random", L"random"));
719 }
720
@@ -773,31 +723,23 @@ class UnitTests
723 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests keymgmt", L"Keymgmt"));
724 }
725
776 - TEST_METHOD(Shm)
726 + WSL1_TEST_METHOD(Shm)
727 {
778 - WSL1_TEST_ONLY();
779 -
728 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests shm", L"shm"));
729 }
730
783 - TEST_METHOD(Sem)
731 + WSL1_TEST_METHOD(Sem)
732 {
785 - WSL1_TEST_ONLY();
786 -
733 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests sem", L"sem"));
734 }
735
790 - TEST_METHOD(Ttys)
736 + WSL1_TEST_METHOD(Ttys)
737 {
792 - WSL1_TEST_ONLY();
793 -
738 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests ttys", L"Ttys"));
739 }
740
797 - TEST_METHOD(OverlayFs)
741 + WSL1_TEST_METHOD(OverlayFs)
742 {
799 - WSL1_TEST_ONLY();
800 -
743 VERIFY_NO_THROW(LxsstuRunTest(L"/data/test/wsl_unit_tests overlayfs", L"OverlayFs"));
744 }
745
@@ -1753,10 +1695,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
1695 VerifyOutput(L"--install foo", AddCrlf(WslInstallHelpMessage), -1);
1696 }
1697
1756 - TEST_METHOD(TestExistingSwapVhd)
1698 + WSL2_TEST_METHOD(TestExistingSwapVhd)
1699 {
1758 - WSL2_TEST_ONLY();
1759 -
1700 // Create a 100MB swap vhdx.
1701 auto swapVhd = wil::GetCurrentDirectoryW<std::wstring>() + L"\\TestSwap.vhdx";
1702
@@ -1810,17 +1750,13 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
1750 VERIFY_ARE_EQUAL(L"SigBlk:\t0000000000000000\n", output);
1751 }
1752
1813 - TEST_METHOD(InitReadonly)
1753 + WSL2_TEST_METHOD(InitReadonly)
1754 {
1815 - WSL2_TEST_ONLY();
1816 -
1755 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L" grep '^rootfs /init rootfs ro,' /proc/self/mounts", nullptr, nullptr, nullptr, nullptr), 0u);
1756 }
1757
1820 - TEST_METHOD(GpuMounts)
1758 + WSL2_TEST_METHOD(GpuMounts)
1759 {
1822 - WSL2_TEST_ONLY();
1823 -
1760 auto ValidateGpuMounts = [](HANDLE Token) {
1761 VERIFY_ARE_EQUAL(
1762 LxsstuLaunchWsl(
@@ -1933,10 +1869,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
1869 validate(longHostName, wsl::shared::string::MultiByteToWide(longHostName.substr(0, 64)));
1870 }
1871
1936 - TEST_METHOD(WslConfWarnings)
1872 + WSL2_TEST_METHOD(WslConfWarnings)
1873 {
1938 - WSL2_TEST_ONLY();
1939 -
1874 DistroFileChange configChange(L"/etc/wsl.conf", false);
1875
1876 auto validateWarnings = [&configChange](const std::wstring& config, const std::wstring& expectedWarnings) {
@@ -1986,10 +1920,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
1920 }
1921 }
1922
1989 - TEST_METHOD(Warnings)
1923 + WSL2_TEST_METHOD(Warnings)
1924 {
1991 - WSL2_TEST_ONLY();
1992 -
1925 WslConfigChange configChange(LxssGenerateTestConfig());
1926
1927 auto validateWarnings = [&configChange](
@@ -2177,10 +2109,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2109 VERIFY_ARE_EQUAL(L"", warnings);
2110 }
2111
2180 - TEST_METHOD(Processors)
2112 + WSL2_TEST_METHOD(Processors)
2113 {
2182 - WSL2_TEST_ONLY();
2183 -
2114 WslConfigChange configChange(LxssGenerateTestConfig() + L"\nprocessors=1");
2115
2116 auto [output, warnings] = LxsstuLaunchWslAndCaptureOutput(L"nproc --all");
@@ -2188,10 +2118,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2118 VERIFY_ARE_EQUAL(L"", warnings);
2119 }
2120
2191 - TEST_METHOD(GuiApplications)
2121 + WSL2_TEST_METHOD(GuiApplications)
2122 {
2193 - WSL2_TEST_ONLY();
2194 -
2123 auto validateEnvironment = [&](bool systemdEnabled) {
2124 WslConfigChange configChange(LxssGenerateTestConfig({.guiApplications = true}));
2125
@@ -2257,10 +2185,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2185 validateEnvironment(true);
2186 }
2187
2260 - TEST_METHOD(GuiApplicationsSystemd)
2188 + WSL2_TEST_METHOD(GuiApplicationsSystemd)
2189 {
2262 - WSL2_TEST_ONLY();
2263 -
2190 DistroFileChange wslConf(L"/etc/wsl.conf", false);
2191 wslConf.SetContent(L"[boot]\nsystemd=true\n");
2192 WslConfigChange config{LxssGenerateTestConfig({.guiApplications = true})};
@@ -2365,10 +2291,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2291 VERIFY_ARE_NOT_EQUAL(signedFiles, 0);
2292 }
2293
2368 - TEST_METHOD(CorruptedVhd)
2294 + WSL2_TEST_METHOD(CorruptedVhd)
2295 {
2370 - WSL2_TEST_ONLY();
2371 -
2296 // Create a 100MB vhd without a filesystem.
2297 auto distroPath = std::filesystem::weakly_canonical(wil::GetCurrentDirectoryW<std::wstring>());
2298 auto vhdPath = distroPath / L"CorruptedTest.vhdx";
@@ -2613,10 +2537,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2537 cleanup.release();
2538 }
2539
2616 - TEST_METHOD(ManualDistroShutdown)
2540 + WSL2_TEST_METHOD(ManualDistroShutdown)
2541 {
2618 - WSL2_TEST_ONLY();
2619 -
2542 // Terminate a distribution from within WSL. This command should be terminated by the VM terminating
2543 LxsstuLaunchWsl(L"echo foo > /dev/shm/bar ; reboot -f ; sleep 1d");
2544
@@ -2636,10 +2558,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2558 VERIFY_ARE_EQUAL(out, L"ok");
2559 }
2560
2639 - TEST_METHOD(KernelModules)
2561 + WSL2_TEST_METHOD(KernelModules)
2562 {
2641 - WSL2_TEST_ONLY();
2642 -
2563 // Get the kernel version and strip off everything after the first dash.
2564 std::wstring kernelVersion{TEXT(KERNEL_VERSION)};
2565 auto position = kernelVersion.find_first_of(L"-");
@@ -2732,10 +2652,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2652 ValidateOutput(L"dmesg | grep -iF \"failed to load module 'not-found'\" | wc -l", L"1\n", L"", 0);
2653 }
2654
2735 - TEST_METHOD(CrashCollection)
2655 + WSL2_TEST_METHOD(CrashCollection)
2656 {
2737 - WSL2_TEST_ONLY();
2738 -
2657 const auto folder = std::filesystem::absolute(L"test-crash-dumps");
2658
2659 auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&]() {
@@ -2883,10 +2801,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2801 }
2802 }
2803
2886 - TEST_METHOD(Resize)
2804 + WSL2_TEST_METHOD(Resize)
2805 {
2888 - WSL2_TEST_ONLY();
2889 -
2806 constexpr auto name = L"resize-test-distro";
2807
2808 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(std::format(L"--import {} . \"{}\" --version 2", name, g_testDistroPath)), 0L);
@@ -2922,10 +2838,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2838 }
2839 }
2840
2925 - TEST_METHOD(FileOffsets)
2841 + WSL2_TEST_METHOD(FileOffsets)
2842 {
2927 - WSL2_TEST_ONLY();
2928 -
2843 auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, []() { DeleteFile(L"output.txt"); });
2844
2845 std::ofstream file("output.txt");
@@ -2955,9 +2869,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
2869 VERIFY_IS_TRUE(isDriveMountingEnabled());
2870 }
2871
2958 - TEST_METHOD(WriteWslConfig)
2872 + WSL2_TEST_METHOD(WriteWslConfig)
2873 {
2960 - WSL2_TEST_ONLY();
2874 WSL_SETTINGS_TEST();
2875
2876 auto installPath = wsl::windows::common::wslutil::GetMsiPackagePath();
@@ -6245,10 +6158,8 @@ Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n",
6158 }
6159 }
6160
6248 - TEST_METHOD(CustomModulesVhd)
6161 + WSL2_TEST_METHOD(CustomModulesVhd)
6162 {
6250 - WSL2_TEST_ONLY();
6251 -
6163 #ifdef WSL_DEV_INSTALL_PATH
6164
6165 auto modulesPath = std::format(L"{}\\modules.vhd", WSL_DEV_INSTALL_PATH);
@@ -6421,19 +6332,15 @@ Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n",
6332 VERIFY_ARE_EQUAL(err, L"");
6333 }
6334
6424 - TEST_METHOD(WslDebug)
6335 + WSL2_TEST_METHOD(WslDebug)
6336 {
6426 - WSL2_TEST_ONLY();
6427 -
6337 // Verify that hvsocket debug events are logged to dmesg.
6338 WslConfigChange config(LxssGenerateTestConfig({.kernelCommandLine = L"WSL_DEBUG=hvsocket"}));
6339 VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"dmesg | grep -iF 'vmbus_send_tl_connect_request'"), 0L);
6340 }
6341
6433 - TEST_METHOD(CGroupv1)
6342 + WSL2_TEST_METHOD(CGroupv1)
6343 {
6435 - WSL2_TEST_ONLY();
6436 -
6344 auto expectedMount = [](const char* path, const wchar_t* expected) {
6345 auto [out, _] = LxsstuLaunchWslAndCaptureOutput(std::format(L"findmnt -ln '{}' || true", path));
6346
@@ -6468,19 +6375,15 @@ Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n",
6375 std::wstring::npos);
6376 }
6377
6471 - TEST_METHOD(InitPermissions)
6378 + WSL2_TEST_METHOD(InitPermissions)
6379 {
6473 - WSL2_TEST_ONLY();
6474 -
6380 auto [out, _] = LxsstuLaunchWslAndCaptureOutput(L"stat -c %a /init");
6381
6382 VERIFY_ARE_EQUAL(out, L"755\n");
6383 }
6384
6480 - TEST_METHOD(ExportImportVhd)
6385 + WSL2_TEST_METHOD(ExportImportVhd)
6386 {
6482 - WSL2_TEST_ONLY();
6483 -
6387 WslShutdown();
6388
6389 constexpr auto vhdPath = L"exported-test-distro.vhd";
@@ -6543,10 +6446,19 @@ Error code: Wsl/InstallDistro/WSL_E_INVALID_JSON\r\n",
6446 VERIFY_ARE_EQUAL(err, L"");
6447 }
6448
6546 - TEST_METHOD(InteractiveMount)
6449 + TEST_METHOD(BytesToHex)
6450 {
6548 - WSL2_TEST_ONLY();
6451 + using wsl::windows::common::string::BytesToHex;
6452
6453 + VERIFY_ARE_EQUAL(BytesToHex({}), L"0x");
6454 + VERIFY_ARE_EQUAL(BytesToHex({0x0F}), L"0x0f");
6455 + VERIFY_ARE_EQUAL(BytesToHex({0xDE, 0xAD, 0xBE, 0xEF}), L"0xdeadbeef");
6456 + VERIFY_ARE_EQUAL(BytesToHex({0x00, 0x00}), L"0x0000");
6457 + VERIFY_ARE_EQUAL(BytesToHex({0xFF, 0xFF}), L"0xffff");
6458 + }
6459 +
6460 + WSL2_TEST_METHOD(InteractiveMount)
6461 + {
6462 // Add a fake interactive mount helper.
6463 DistroFileChange mountHelper(L"/sbin/mount.hang", false);
6464 mountHelper.SetContent(
tools/test/run-tests.ps1
+17
@@ -67,8 +67,25 @@ if ($TeArgs -and ($TeArgs -icontains '/attachdebugger'))
67 }
68 }
69
70 +# If the user provided a /name: or /select: filter, don't add automatic version filtering.
71 +$HasUserSelection = $false
72 +foreach ($arg in $TeArgs)
73 +{
74 + if ($arg -like '/name:*' -or $arg -like '/select:*' -or $arg -like '-name:*' -or $arg -like '-select:*')
75 + {
76 + $HasUserSelection = $true
77 + break
78 + }
79 +}
80 +
81 $teArgList = @($TestDllPath, "/p:SetupScript=$SetupScript", "/p:Version=$Version", "/p:DistroPath=$DistroPath",
82 "/p:Package=$Package", "/p:UnitTestsPath=$UnitTestsPath", "/p:PullRequest=$PullRequest", "/p:AllowUnsigned=1") + $TeArgs
83 +
84 +if (-not $HasUserSelection)
85 +{
86 + $teArgList += "/select:`"@WSLVersion='$Version' or not(@WSLVersion='*')`""
87 +}
88 +
89 $teProcess = Start-Process -FilePath "te.exe" -ArgumentList $teArgList -PassThru -NoNewWindow
90
91 if ($AttachDebugger)