Run threaded api-test SFTP/SCP tests on Windows#1058
Draft
yosuke-wolfssl wants to merge 6 commits into
Draft
Conversation
513ad06 to
e506b82
Compare
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
Runs the 11 threaded echoserver+client tests in
api-test(real SFTP/SCPtransport and rekey over a socket) on Windows for the first time, giving genuine
SFTP/SCP integration coverage under MSVC AddressSanitizer. Previously these tests
were stubbed out on Windows because the test harness's readiness handshake was
POSIX-only.
This is a follow-up to the
windows-check.ymlfix that made Windows CI actuallycompile
WOLFSSH_SSHD/SFTP/SCP/CERTS/X509 and runapi-test+unit-testunder ASan. That restored compile and unit-level coverage; this PR adds the
integration coverage that was still missing.
Background / root cause
The threaded tests follow this shape:
The readiness handshake (block the client until the server is listening, then
hand back the bound port) was implemented only for POSIX threads. On MSVC
_POSIX_THREADSis undefined, soWaitTcpReadyreturned immediately andSignalTcpReadynever setready->port— the client raced ahead and connectedto port 0, tripping
AssertNotNull(ctx). Win32 threads themselves already worked(
ThreadStartuses_beginthreadex); only the readiness primitive was missing.What changed
1. Win32 readiness primitive (
wolfssh/test.h,examples/echoserver/echoserver.c)Added a Win32 branch to the readiness primitive, mirroring the POSIX semantics:
tcp_readygains aCRITICAL_SECTION+ a manual-reset eventHANDLE.InitTcpReady/FreeTcpReady/WaitTcpReadyandSignalTcpReadyget#elif defined(USE_WINDOWS_API)branches.WaitTcpReadyuses a bounded 30s wait instead of an indefinite one: the signalfires right after
listen(), so the real wait is sub-second, and a server thatdies before signaling fails the test fast instead of hanging CI. On timeout the
port stays 0 and the existing
AssertNotNull(ctx)trips.FreeTcpReadynulls the event handle after closing it so cleanup is idempotent.All Win32 code is strictly additive (
#elif USE_WINDOWS_API); the POSIX andsingle-threaded branches are untouched, so non-Windows builds are unaffected.
2. Re-enable the stubbed tests (
tests/api.c)Dropped
!defined(USE_WINDOWS_API)from the SFTP and SCP-rekey block guards sothe real test bodies compile and run on Windows. Also paired every
InitTcpReadywith
FreeTcpReady(api-test previously had 6 inits and 0 frees, unliketestsuite.c/kex.c/sftp.c), releasing the new Windows event handle andcritical section as well as the pre-existing POSIX mutex/cond.
Tests that now run on Windows:
SetDefaultPath
3. Ephemeral port on Windows (
wolfssh/test.h,tests/api.c,examples/echoserver/echoserver.c)The tests passed
-p 0(OS-assigned ephemeral port) only on POSIX; on Windowsthe server fell back to the fixed
wolfSshPortbecausetcp_listencould notread the bound port back. Reusing one fixed port across the serial networked
tests is the worst case for
TIME_WAITrebind on Windows, which (correctly) doesnot set
SO_REUSEADDR.Let Windows use an ephemeral port like POSIX already does, so each test binds a
fresh port and never contends with a prior connection lingering in
TIME_WAIT:test.h: drop theUSE_WINDOWS_APIexclusion from thegetsocknameportreadback (
getsockname/ntohs/socklen_tare all available on Winsock).tests/api.c: pass-p 0on all platforms.echoserver.c: reject-p 0only for the standalone main driver, not theNO_MAIN_DRIVERtest harness, so the Windows api-test server accepts anephemeral port.
Testing
#elif USE_WINDOWS_API,so POSIX preprocessed output is unchanged. Rebuilt
api-test+testsuiteandran under ASan+UBSan (
-fsanitize=address,undefined -fno-omit-frame-pointer) —exit 0, no AddressSanitizer errors. (One pre-existing UBSan note at
test.h:478, agethostbynamemisalignedchar*load, is unrelated to thischange.)
windows-check.ymlasan-testsjob — the onlyplace
_WIN32+ features + threads + ASan combine. The 11 tests should now rungreen under MSVC ASan.
Scope / risk
test.h,echoserver.c) used by everyexample/test program, so the change is strictly additive
(
#elif USE_WINDOWS_API) with the POSIX/single-threaded branches unchanged.transport + rekey coverage under AddressSanitizer.