@samitouri / QOSAMI-WSL / commits / c78930c5

CLI: Add virtiofs mapshared regression test (#41427)

* Add virtiofs mapshared regression test

David Bennett committed Aug 25, 2026 at 13:57 UTC c78930c5827e7d086e0aea695a906ace3cbcf30e
1 file changed +34
test/windows/wslc/e2e/WSLCE2EContainerRunTests.cpp
+34
@@ -1175,6 +1175,40 @@ class WSLCE2EContainerRunTests
1175 result.Verify({.Stdout = L"WSLC Mount Bind Test", .Stderr = L"", .ExitCode = 0});
1176 }
1177
1178 + WSLC_TEST_METHOD(WSLCE2E_Container_Run_Volume_Bind_VirtioFs_MapShared_Success)
1179 + {
1180 + const auto hostDirectory = EnvTestFile1.parent_path();
1181 + const auto fileName = EnvTestFile1.filename().wstring();
1182 + VERIFY_IS_TRUE(DeleteFileW(EnvTestFile1.c_str()));
1183 +
1184 + constexpr auto mapSharedScript =
1185 + LR"PY(
1186 +import mmap
1187 +import os
1188 +import sys
1189 +
1190 +with open('/proc/mounts', encoding='utf-8') as mounts_file:
1191 + mounts = (line.split() for line in mounts_file)
1192 + if not any(fields[1:3] == ['/data', 'virtiofs'] for fields in mounts):
1193 + raise RuntimeError('/data is not mounted as virtiofs')
1194 +
1195 +fd = os.open(sys.argv[1], os.O_RDWR | os.O_CREAT | os.O_NOFOLLOW | os.O_CLOEXEC, 0o777)
1196 +os.ftruncate(fd, 32 * 1024)
1197 +with mmap.mmap(fd, 32 * 1024, flags=mmap.MAP_SHARED, prot=mmap.PROT_READ | mmap.PROT_WRITE) as mapping:
1198 + mapping[0:1] = b'W'
1199 + mapping.flush()
1200 + if os.pread(fd, 1, 0) != b'W':
1201 + raise RuntimeError('MAP_SHARED write was not visible through the file')
1202 +)PY";
1203 +
1204 + auto result = RunWslc(std::format(
1205 + L"container run --rm --volume \"{}:/data\" {} python3 -c \"{}\" /data/{}", hostDirectory.wstring(), PythonImage.NameAndTag(), mapSharedScript, fileName));
1206 + result.Verify({.Stdout = L"", .Stderr = L"", .ExitCode = 0});
1207 + VERIFY_IS_TRUE(std::filesystem::exists(EnvTestFile1));
1208 + VERIFY_ARE_EQUAL(32ull * 1024, std::filesystem::file_size(EnvTestFile1));
1209 + VERIFY_ARE_EQUAL(L'W', ReadFileContent(EnvTestFile1.wstring())[0]);
1210 + }
1211 +
1212 WSLC_TEST_METHOD(WSLCE2E_Container_Run_Mount_Volume_Success)
1213 {
1214 auto result = RunWslc(std::format(