Skip to content

Fix various issues in the virtionet tests#40963

Open
OneBlue wants to merge 1 commit into
masterfrom
user/oneblue/fix-tests-13
Open

Fix various issues in the virtionet tests#40963
OneBlue wants to merge 1 commit into
masterfrom
user/oneblue/fix-tests-13

Conversation

@OneBlue

@OneBlue OneBlue commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary of the Pull Request

This change solves two issues with the virtionet tests:

  • The host IP address logic doesn't match the product logic, and so it sometimes mismatches (especially if Hyper-V is running)
  • A broken "%s" string outputs garbage

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • [Xd] Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI review requested due to automatic review settings July 1, 2026 01:30
@OneBlue OneBlue requested a review from a team as a code owner July 1, 2026 01:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR 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 use wsl::core::networking::GetHostEndpointSettings() and return a wide string IP.
  • Fixed a LogInfo call to use %hs for std::string arguments under wide-format logging.
  • Updated WSLC tests to use std::wstring host 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 thread test/windows/Common.cpp
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants