Skip to content

fix(test): unblock Windows type-checking and fix the arm64 sockaddr assertions - #89

Merged
jeoliva merged 2 commits into
masterfrom
test/portability-and-arm64-addr
Jul 29, 2026
Merged

fix(test): unblock Windows type-checking and fix the arm64 sockaddr assertions#89
jeoliva merged 2 commits into
masterfrom
test/portability-and-arm64-addr

Conversation

@jeoliva

@jeoliva jeoliva commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Two test-only fixes. No library code changes, so no runtime risk.

1. netutils_test.go blocked go test on Windows

It imported golang.org/x/sys/unix with no build tag and used unix.AF_INET / unix.AF_INET6. Under GOOS=windows that package has no such constants, so the whole test package failed to type-check. go build of the library was unaffected — consumers were fine — but the tests could never run there.

The package already defines afINET4 / afINET6 for both build tags, so the test now uses those and drops the import. That makes the test run on Windows rather than hiding it behind //go:build !windows, and it is also more correct on its own terms: on Windows unix.AF_INET6 would be 10, while the value sockAddrFromIp6 actually writes is windows.AF_INET6 == 23.

portability_test.go parses every *_test.go under a GOOS=windows build context and fails if any imports a package that cannot build there, so this cannot silently regress.

It also updates the CI comment that named this as the reason for having no Windows job — that reason is now gone. What remains is the toolchain: libsrt on a Windows runner needs a vcpkg build whose MSVC import libraries don't line up with the mingw gcc cgo uses.

2. TestCreateAddrInetV4 / V6 failed on Linux arm64

Both fail on master under GOOS=linux GOARCH=arm64 and pass everywhere else. The cause is in the test, not in CreateAddrInet: the assertions compared sa_data against negative int8 literals, which only works where C's char is signed. It is signed on x86-64 and on darwin, and unsigned on Linux arm64, so the same correct bytes compared unequal.

The assertions now use []byte with hex literals and compare byte(ip.sa_data[i]), which is signedness-independent, and the failure message reports index/got/want instead of just "does not match". The library was producing the right sockaddr all along — no user on linux/arm64 was affected.

Verification

Platform Before After
Linux arm64 TestCreateAddrInetV4/V6 FAIL PASS — suite fully green for the first time
Linux amd64 pass pass
macOS arm64 pass pass

Both directions checked: reverting only the byte arrays reproduces the arm64 failure (at 1: got 0x9a, want -0x66), and reverting only the import swap fails TestTestFilesTypeCheckOnWindows.

Note CI cannot cover the arm64 fix — the matrix is ubuntu-latest and macos-latest, both amd64/darwin-arm64. It was verified locally in a linux/arm64 container.

Honest limit: GOOS=windows go vet still cannot type-check the full package here, but now for an unrelated reason — cgo cross-compilation is unavailable, so CGO_ENABLED=0 strips the cgo files and SrtSocket itself is undefined. The x/sys/unix blocker is genuinely gone; a real Windows toolchain is needed to go further.

🤖 Generated with Claude Code

srtgo added 2 commits July 29, 2026 22:52
netutils_test.go imported golang.org/x/sys/unix with no build constraint,
purely to name unix.AF_INET/unix.AF_INET6. That package has essentially no
files selected for GOOS=windows, so those identifiers are undefined there and
the entire srtgo test package failed to type-check on Windows -- all 26 tests,
not just the two that used it. The library itself was never affected;
netutils_unix.go is the only non-test importer and it is //go:build !windows.

Use the package-internal afINET4/afINET6 constants, which netutils.go already
uses for exactly these values and which are defined for both build tags. This
makes the test compile and run on Windows rather than hiding it behind a
//go:build !windows tag, and it asserts the same constant the code under test
writes (windows.AF_INET6 is 23, not the 10 x/sys/unix would have claimed).

Add portability_test.go, which walks every *_test.go that go/build selects for
GOOS=windows and fails if it imports a package with no Windows implementation,
and correct the now-false CI comment that documented this as a live condition.
CreateAddrInet produces byte-identical sockaddrs on linux/amd64 and
linux/arm64; nothing in netutils.go is wrong on arm64 and no user is affected.
The two tests failed there because they hardcoded expected sa_data bytes as
signed decimals (-102, -72, -123, -93) and compared through int(). sa_data is
C char, whose signedness is ABI-defined: cgo maps it to int8 where plain char
is signed (x86-64 System V, Apple arm64) and to uint8 where it is unsigned
(AArch64 Linux / AAPCS64). On the latter int(uint8(0x9a)) is 154 and can never
equal -102.

Express the expectations as raw bytes and compare through byte(), which is
value-preserving for the same bit pattern under either mapping, and report
index/got/want so the next platform surprise is diagnosable. The expected bit
patterns are unchanged, and index 1 is now genuinely asserted on linux/arm64
where it previously could only ever mismatch. Note CI covers ubuntu-latest
(amd64) and macos-latest (arm64, signed char); Linux+AArch64 is the untested
combination, so this can regress silently again without an arm64 runner.
@jeoliva
jeoliva merged commit 8fcf76b into master Jul 29, 2026
4 checks passed
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.

1 participant