Fix various issues in the virtionet tests#40963
Open
OneBlue wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Windows WSLC “virtionet”/port-mapping test code to align host-IP selection with the product’s networking logic and fixes an incorrect LogInfo format specifier that could print garbage.
Changes:
- Switched
GetHostAdapterIpv4()to usewsl::core::networking::GetHostEndpointSettings()and return a wide string IP. - Fixed a
LogInfocall to use%hsforstd::stringarguments under wide-format logging. - Updated WSLC tests to use
std::wstringhost IPs and convert to narrow strings where required for inspect/binding comparisons.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Updates port-mapping tests to handle wide host IPs and fixes logging format for narrow strings. |
| test/windows/wslc/e2e/WSLCE2EContainerRunTests.cpp | Updates port binding assertion to compare against a narrow-converted host IP. |
| test/windows/Common.h | Changes GetHostAdapterIpv4() return type to std::optional<std::wstring>. |
| test/windows/Common.cpp | Reimplements host IPv4 selection using product endpoint settings. |
Comment on lines
+3047
to
+3053
| auto endpoint = wsl::core::networking::GetHostEndpointSettings(); | ||
| if (!endpoint) | ||
| { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::vector<BYTE> buffer(bufferSize); | ||
| auto* adapters = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buffer.data()); | ||
| result = GetAdaptersAddresses(AF_INET, flags, nullptr, adapters, &bufferSize); | ||
| if (result != ERROR_SUCCESS) | ||
| { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| for (auto* adapter = adapters; adapter != nullptr; adapter = adapter->Next) | ||
| { | ||
| if (adapter->OperStatus != IfOperStatusUp || adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK || adapter->IfType == IF_TYPE_TUNNEL) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| for (auto* addr = adapter->FirstUnicastAddress; addr != nullptr; addr = addr->Next) | ||
| { | ||
| if (addr->Address.lpSockaddr->sa_family != AF_INET) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| auto& ipv4 = reinterpret_cast<sockaddr_in*>(addr->Address.lpSockaddr)->sin_addr; | ||
|
|
||
| // Skip APIPA (169.254.x.x) addresses. | ||
| if ((ntohl(ipv4.s_addr) & 0xFFFF0000) == 0xA9FE0000) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| char buf[INET_ADDRSTRLEN]; | ||
| VERIFY_IS_NOT_NULL(inet_ntop(AF_INET, &ipv4, buf, sizeof(buf))); | ||
| return std::string(buf); | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| return std::nullopt; | ||
| return endpoint->PreferredIpAddress.AddressString; |
benhillis
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
This change solves two issues with the virtionet tests:
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed