[Windows] Compile the remaining test targets (NIOPosixTests, NIOFoundationCompatTests) (#3665)

## Motivation

Follow-up to #3663 (which got the "low-hanging" test targets compiling
on Windows). This finishes the job by getting the **last two** test
targets — `NIOPosixTests` and `NIOFoundationCompatTests` — compiling on
Windows, so **all 16 test targets now build**, and switches Windows CI
to `swift build --build-tests`.

These are **compile-only** changes: the goal is compilation, not runtime
pass. Verified by building on a Windows ARM64 VM with `swift build
--build-tests`.

## What's here

1. **Compile `NIOFoundationCompatTests`** — the target imports the `NIO`
umbrella (in `WaitSpinningRunLoopTests`, for
`MultiThreadedEventLoopGroup`) but only declared
`NIOCore`/`NIOFoundationCompat` as dependencies. `NIO` re-exports
`NIOPosix`, which imports the `CNIOPosix` **C module**; Linux/macOS
resolve that transitively, but on Windows the C-module map isn't in the
target's search path unless declared, giving the opaque `<unknown>:0:
error: missing required module 'CNIOPosix'`. Fix: declare the `NIO`
dependency it actually uses.

2. **Compile `NIOPosixTests`** — the deeply-POSIX target.
Gate-out-plus-minimal-shim:
- `import WinSDK` where only `sockaddr`/`timeval`/`in_addr` field or
type access was missing (`MemberImportVisibility`) — this alone cleared
the two largest files (`SocketAddressTest`, `HappyEyeballsTest`).
- Real fixes where cheap: `pipe` → `_pipe` (via `ucrt`), an
`STDOUT_FILENO` shim, `Thread.sleep` instead of `sleep`, and letting
`IOResult` type inference pick `ssize_t`.
- `#if !os(Windows)` gating (per-method where possible, to preserve
Windows-compilable coverage) for genuinely-unavailable APIs:
`fcntl`/`O_NONBLOCK`/`O_ASYNC`/`F_GETFL`/`F_SETFL`, `Posix.fcntl`,
`Posix.socketpair`, the integer socket-option API
(`ChannelOptions.socket`, `SOL_SOCKET`, `SO_REUSEADDR`, `so_timestamp`),
`poll`/`pollfd`, `cmsg`/`msghdr` construction,
`NonBlockingFileIO.lstat`/`symlink`/`listDirectory`/`createDirectory`,
vsock CID/connect tests, `/dev/null` syscall-wrapper perf tests, and
socket-handle (`NIOBSDSocket.Handle` `UInt64` vs `CInt`) mismatches.
- Whole-file gating only where a file is pervasively unsupported: the
SAL mock harness and its dependents (`SyscallAbstractionLayer[Context]`,
`SALChannelTests`, `SALEventLoopTests`) — it's built on `CInt` fds and
can't compile against Windows's `UInt64` socket handles without a larger
rework; `ControlMessageTests` (POSIX `msghdr`/control-message
throughout); and `MulticastTest` (deprecated
`enumerateInterfaces`/`NIONetworkInterface`).

3. **Build the test targets in CI** — change the Windows matrix command
from `swift build` to `swift build --build-tests` in `main.yml` and
`pull_request.yml`.

## Notes for reviewers

- No behavior change off Windows: every edit is behind `#if os(Windows)`
/ `#if !os(Windows)`; the few shared-line changes (`Thread.sleep`,
`IOResult` inference, an IUO force-unwrap of `msg_name`) are identical
on POSIX.
- The tests are **compiled, not run** on Windows yet. Running them needs
real Winsock work (socket handle types, etc.) and is the natural next
step.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
This commit is contained in:
Jake PetroulesandGeorge Barnett authored and GitHub committed 2026-07-24 13:59:45 +00:00
1 parent 63018571c8
commit 15b77e6400
31 files changed
+230 -14

No files matched your search

+1 -1
View File
@@ -110,7 +110,7 @@ jobs:
MATRIX_LINUX_NIGHTLY_NEXT_ENABLED: false
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
MATRIX_WINDOWS_6_3_ENABLED: true
MATRIX_WINDOWS_COMMAND: "swift build"
MATRIX_WINDOWS_COMMAND: "swift build --build-tests"
windows-build:
name: Windows build (currently-supported targets)
+1 -1
View File
@@ -86,7 +86,7 @@ jobs:
MATRIX_LINUX_NIGHTLY_NEXT_ENABLED: false
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
MATRIX_WINDOWS_6_3_ENABLED: true
MATRIX_WINDOWS_COMMAND: "swift build"
MATRIX_WINDOWS_COMMAND: "swift build --build-tests"
windows-build:
name: Windows build (currently-supported targets)
+1
View File
@@ -570,6 +570,7 @@ let package = Package(
dependencies: [
"NIOCore",
"NIOFoundationCompat",
"NIOPosix",
],
swiftSettings: swiftSettings
),
@@ -12,8 +12,9 @@
//
//===----------------------------------------------------------------------===//
import NIO
import NIOCore
import NIOFoundationCompat
import NIOPosix
import XCTest
final class WaitSpinningRunLoopTests: XCTestCase {
@@ -19,6 +19,10 @@ import XCTest
@testable import NIOCore
@testable import NIOPosix
#if os(Windows)
import ucrt
#endif
private final class IPHeaderRemoverHandler: ChannelInboundHandler {
typealias InboundIn = AddressedEnvelope<ByteBuffer>
typealias InboundOut = AddressedEnvelope<ByteBuffer>
@@ -601,6 +605,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
}
func testServerClientBootstrap_withAsyncChannel_clientConnectedSocket() async throws {
#if os(Windows)
throw XCTSkip("Creating a channel from a pre-connected socket is not supported on Windows")
#else
let eventLoopGroup = self.group!
let channel = try await ServerBootstrap(group: eventLoopGroup)
@@ -658,6 +665,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
group.cancelAll()
}
#endif
}
// MARK: Datagram Bootstrap
@@ -1321,6 +1329,9 @@ final class AsyncChannelBootstrapTests: XCTestCase {
// MARK: VSock
func testVSock() async throws {
#if os(Windows)
throw XCTSkip("VSOCK is not supported on Windows")
#else
try XCTSkipUnless(System.supportsVsockLoopback, "No vsock loopback transport available")
let eventLoopGroup = self.group!
@@ -1379,6 +1390,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
group.cancelAll()
}
#endif
}
// MARK: - Test Helpers
@@ -1388,11 +1400,19 @@ final class AsyncChannelBootstrapTests: XCTestCase {
) {
var pipe1FDs: [CInt] = [-1, -1]
pipe1FDs.withUnsafeMutableBufferPointer { ptr in
#if os(Windows)
XCTAssertEqual(0, _pipe(ptr.baseAddress!, 4096, _O_BINARY))
#else
XCTAssertEqual(0, pipe(ptr.baseAddress!))
#endif
}
var pipe2FDs: [CInt] = [-1, -1]
pipe2FDs.withUnsafeMutableBufferPointer { ptr in
#if os(Windows)
XCTAssertEqual(0, _pipe(ptr.baseAddress!, 4096, _O_BINARY))
#else
XCTAssertEqual(0, pipe(ptr.baseAddress!))
#endif
}
return (pipe1FDs[0], pipe1FDs[1], pipe2FDs[0], pipe2FDs[1])
}
@@ -1400,7 +1420,11 @@ final class AsyncChannelBootstrapTests: XCTestCase {
private func makePipeFileDescriptors() -> (pipeReadFD: CInt, pipeWriteFD: CInt) {
var pipeFDs: [CInt] = [-1, -1]
pipeFDs.withUnsafeMutableBufferPointer { ptr in
#if os(Windows)
XCTAssertEqual(0, _pipe(ptr.baseAddress!, 4096, _O_BINARY))
#else
XCTAssertEqual(0, pipe(ptr.baseAddress!))
#endif
}
return (pipeFDs[0], pipeFDs[1])
}
@@ -1520,6 +1544,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
}
}
#if !os(Windows)
private func makeClientChannel(
eventLoopGroup: EventLoopGroup,
fileDescriptor: CInt
@@ -1535,6 +1560,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
}
}
}
#endif
private func makeClientChannelWithProtocolNegotiation(
eventLoopGroup: EventLoopGroup,
+16 -2
View File
@@ -191,6 +191,8 @@ class BootstrapTest: XCTestCase {
)
}
#if !os(Windows)
// Uses Posix.socketpair / socklen_t / CInt socket handles, unavailable on Windows.
func testPreConnectedClientSocketToleratesFuturesFromDifferentEventLoopsReturnedInInitializers() throws {
var socketFDs: [CInt] = [-1, -1]
XCTAssertNoThrow(
@@ -269,6 +271,7 @@ class BootstrapTest: XCTestCase {
XCTAssertNoThrow(try childChannelDone.futureResult.wait())
XCTAssertNoThrow(try serverChannelDone.futureResult.wait())
}
#endif
func testTCPClientBootstrapAllowsConformanceCorrectly() throws {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
@@ -380,7 +383,10 @@ class BootstrapTest: XCTestCase {
)
}
func testPreConnectedSocketSetsChannelOptionsBeforeChannelInitializer() {
func testPreConnectedSocketSetsChannelOptionsBeforeChannelInitializer() throws {
#if os(Windows)
throw XCTSkip("Creating a channel from a pre-connected socket is not supported on Windows")
#else
XCTAssertNoThrow(
try withTCPServerChannel(group: self.group) { server in
var maybeSocket: Socket? = nil
@@ -413,6 +419,7 @@ class BootstrapTest: XCTestCase {
XCTAssertNoThrow(try channel?.close().wait())
}
)
#endif
}
func testDatagramBootstrapSetsChannelOptionsBeforeChannelInitializer() {
@@ -470,7 +477,10 @@ class BootstrapTest: XCTestCase {
)
}
func testPipeBootstrapInEventLoop() {
func testPipeBootstrapInEventLoop() throws {
#if os(Windows)
throw XCTSkip("Pipe channels are not supported on Windows")
#else
let testGrp = DispatchGroup()
testGrp.enter()
@@ -496,6 +506,7 @@ class BootstrapTest: XCTestCase {
}.wait()
)
testGrp.wait()
#endif
}
func testServerBootstrapAddsAcceptHandlerAfterServerChannelInitialiser() {
@@ -797,6 +808,8 @@ class BootstrapTest: XCTestCase {
}
// There was a bug where file handle ownership was not released when creating pipe channels failed.
#if !os(Windows)
// Uses raw socket()/Posix.socketpair with CInt handles, unavailable on Windows.
func testReleaseFileHandleOnOwningFailure() {
struct NIOPipeBootstrapHooksChannelFail: NIOPipeBootstrapHooks {
func makePipeChannel(
@@ -888,6 +901,7 @@ class BootstrapTest: XCTestCase {
$0.takingOwnershipOfDescriptors(input: $1, output: dup($1))
}
}
#endif
}
private final class AddOnceHandler: ChannelInboundHandler, Sendable {
@@ -22,6 +22,11 @@ import XCTest
@testable import NIOCore
#if os(Windows)
import WinSDK
private typealias in_port_t = UInt16
#endif
private final class IndexWritingHandler: ChannelDuplexHandler {
typealias InboundIn = ByteBuffer
typealias InboundOut = ByteBuffer
+6
View File
@@ -3133,6 +3133,9 @@ final class ChannelTests: XCTestCase {
}
func testApplyingTwoDistinctSocketOptionsOfSameTypeWorks() throws {
#if os(Windows)
throw XCTSkip("SO_TIMESTAMP is not available on Windows")
#else
let singleThreadedELG = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer {
XCTAssertNoThrow(try singleThreadedELG.syncShutdownGracefully())
@@ -3218,6 +3221,7 @@ final class ChannelTests: XCTestCase {
XCTAssertTrue(try getBoolSocketOption(channel: accepted3, level: .socket, name: .so_keepalive))
XCTAssertFalse(try getBoolSocketOption(channel: accepted3, level: .tcp, name: .tcp_nodelay))
#endif
}
func testUnprocessedOutboundUserEventFailsOnServerSocketChannel() throws {
@@ -3642,6 +3646,7 @@ final class ReentrantWritabilityChangingHandler: ChannelInboundHandler {
}
private func veryNasty_blockUntilReadBufferIsNonEmpty(channel: Channel) throws {
#if !os(Windows)
struct ThisIsNotASocketChannelError: Error {}
guard let channel = channel as? SocketChannel else {
throw ThisIsNotASocketChannelError()
@@ -3652,4 +3657,5 @@ private func veryNasty_blockUntilReadBufferIsNonEmpty(channel: Channel) throws {
try NIOBSDSocket.poll(fds: &pollFd, nfds: 1, timeout: -1)
XCTAssertEqual(1, nfds)
}
#endif
}
@@ -17,6 +17,9 @@ import XCTest
@testable import NIOPosix
// This file constructs POSIX msghdr and UnsafeControlMessageCollection
// throughout, which are unsupported on Windows.
#if !os(Windows)
extension UnsafeControlMessageCollection {
fileprivate init(controlBytes: UnsafeMutableRawBufferPointer) {
let msgHdr = msghdr(
@@ -128,3 +131,4 @@ class ControlMessageTests: XCTestCase {
XCTAssertGreaterThan(storage[2].count, MemoryLayout<cmsghdr>.stride)
}
}
#endif
@@ -409,6 +409,9 @@ class DatagramChannelTests: XCTestCase {
}
}
#if !os(Windows)
// These tests use a mock overriding recvmsg(...storageLen: inout socklen_t...),
// relying on NIOCore-internal socklen_t which isn't visible on Windows.
public func testRecvMsgFailsWithECONNREFUSED() throws {
try assertRecvMsgFails(error: ECONNREFUSED, active: true)
}
@@ -491,6 +494,7 @@ class DatagramChannelTests: XCTestCase {
let ioError = try promise.futureResult.wait()
XCTAssertEqual(error, ioError.errnoCode)
}
#endif
public func testRecvMmsgFailsWithECONNREFUSED() throws {
try assertRecvMmsgFails(error: ECONNREFUSED, active: true)
@@ -605,6 +609,9 @@ class DatagramChannelTests: XCTestCase {
}
func testSettingTwoDistinctChannelOptionsWorksForDatagramChannel() throws {
#if os(Windows)
throw XCTSkip("SO_TIMESTAMP is not available on Windows")
#else
let channel = try assertNoThrowWithValue(
DatagramBootstrap(group: group)
.channelOption(.socketOption(.so_reuseaddr), value: 1)
@@ -618,6 +625,7 @@ class DatagramChannelTests: XCTestCase {
XCTAssertTrue(try getBoolSocketOption(channel: channel, level: .socket, name: .so_reuseaddr))
XCTAssertTrue(try getBoolSocketOption(channel: channel, level: .socket, name: .so_timestamp))
XCTAssertFalse(try getBoolSocketOption(channel: channel, level: .socket, name: .so_keepalive))
#endif
}
func testUnprocessedOutboundUserEventFailsOnDatagramChannel() throws {
@@ -243,6 +243,9 @@ class EchoServerClientTest: XCTestCase {
}
func testEchoVsock() throws {
#if os(Windows)
throw XCTSkip("VSOCK is not supported on Windows")
#else
try XCTSkipUnless(System.supportsVsockLoopback, "No vsock loopback transport available")
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer {
@@ -289,6 +292,7 @@ class EchoServerClientTest: XCTestCase {
try clientChannel.writeAndFlush(buffer).wait()
XCTAssertEqual(try promise.futureResult.wait(), buffer)
#endif
}
func testChannelActiveOnConnect() throws {
+13 -3
View File
@@ -795,7 +795,7 @@ final class MultiThreadedEventLoopGroupTests {
var tries = 0
while holder.loop != nil {
#expect(tries < 5, "Reference to EventLoop still alive after 5 seconds")
sleep(1)
Thread.sleep(forTimeInterval: 1)
tries += 1
}
}
@@ -1615,7 +1615,17 @@ final class MultiThreadedEventLoopGroupTests {
#expect(MultiThreadedEventLoopGroup.currentEventLoop == nil)
}
@Test
// Takes over the current thread as an event loop, which relies on the
// concurrency-takeover machinery that is unsupported on Windows.
@Test(
.disabled("Taking over the current thread as an event loop is not supported on Windows") {
#if os(Windows)
return true
#else
return false
#endif
}
)
func testWeCanDoTrulySingleThreadedNetworking() {
final class SaveReceivedByte: ChannelInboundHandler {
typealias InboundIn = ByteBuffer
@@ -1651,7 +1661,7 @@ final class MultiThreadedEventLoopGroupTests {
let receiveHandler = NIOLoopBound(SaveReceivedByte(received: received), eventLoop: loop)
ServerBootstrap(group: loop)
.serverChannelOption(ChannelOptions.socket(.init(SOL_SOCKET), .init(SO_REUSEADDR)), value: 1)
.serverChannelOption(.socketOption(.so_reuseaddr), value: 1)
.childChannelInitializer { accepted in
accepted.eventLoop.makeCompletedFuture {
try accepted.pipeline.syncOperations.addHandler(receiveHandler.value)
+2 -2
View File
@@ -282,11 +282,11 @@ class FileRegionTest: XCTestCase {
var fr2Bytes = fr1Bytes
try fh1.withUnsafeFileDescriptor { fd in
let r = try Posix.read(descriptor: fd, pointer: &fr1Bytes, size: 5)
XCTAssertEqual(r, IOResult<Int>.processed(5))
XCTAssertEqual(r, .processed(5))
}
try fh2.withUnsafeFileDescriptor { fd in
let r = try Posix.read(descriptor: fd, pointer: &fr2Bytes, size: 5)
XCTAssertEqual(r, IOResult<Int>.processed(5))
XCTAssertEqual(r, .processed(5))
}
defer {
// fr2's underlying fd must be closed by us.
@@ -26,6 +26,8 @@ import Darwin
import Glibc
#elseif canImport(Bionic)
import Bionic
#elseif os(Windows)
import WinSDK
#else
#error("The Happy Eyeballs test module was unable to identify your C library.")
#endif
+6
View File
@@ -16,6 +16,10 @@ import NIOCore
import NIOPosix
import XCTest
// These multicast tests rely on the deprecated `System.enumerateInterfaces` /
// `NIONetworkInterface` API, which is unavailable on Windows.
#if !os(Windows)
final class PromiseOnReadHandler: ChannelInboundHandler, Sendable {
typealias InboundIn = AddressedEnvelope<ByteBuffer>
@@ -802,3 +806,5 @@ final class MulticastTest: XCTestCase {
)
}
}
#endif // !os(Windows)
@@ -18,6 +18,10 @@ import XCTest
@testable import NIOCore
#if os(Windows)
import ucrt
#endif
final class NIOFileHandleTest: XCTestCase {
func testOpenCloseWorks() throws {
let pipeFDs = try Self.makePipe()
@@ -161,7 +165,11 @@ final class NIOFileHandleTest: XCTestCase {
private static func makePipe() throws -> (CInt, CInt) {
var pipeFDs: [CInt] = [-1, -1]
let err = pipeFDs.withUnsafeMutableBufferPointer { pipePtr in
#if os(Windows)
_pipe(pipePtr.baseAddress!, 4096, _O_BINARY)
#else
pipe(pipePtr.baseAddress!)
#endif
}
guard err == 0 else {
throw POSIXError(what: "pipe", errnoCode: errno)
@@ -17,6 +17,13 @@ import NIOEmbedded
import NIOPosix // NOTE: Not @testable import here -- testing public API surface.
import Testing
#if os(Windows)
import WinSDK
// `STDOUT_FILENO` is not defined on Windows; the CRT uses fd 1 for stdout.
private let STDOUT_FILENO: CInt = 1
#endif
@Suite struct NIOTransportAccessibleChannelCoreTests {
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *)
@Test func testUnderlyingSocketAccessForSocketBasedChannel() throws {
@@ -495,6 +495,9 @@ class NonBlockingFileIOTest: XCTestCase {
}
func testReadFromNonBlockingPipeFails() throws {
#if os(Windows)
throw XCTSkip("Anonymous pipes with these semantics are not available on Windows")
#else
try withPipe { readFH, writeFH in
do {
try readFH.withUnsafeFileDescriptor { readFD in
@@ -520,6 +523,7 @@ class NonBlockingFileIOTest: XCTestCase {
}
return [readFH, writeFH]
}
#endif
}
func testSeekPointerIsSetToFront() throws {
@@ -798,7 +802,11 @@ class NonBlockingFileIOTest: XCTestCase {
try fileHandle.withUnsafeFileDescriptor { fd -> ssize_t in
var data: UInt8 = 0
return withUnsafeMutableBytes(of: &data) { ptr in
#if os(Windows)
ssize_t(read(fd, ptr.baseAddress, CUnsignedInt(ptr.count)))
#else
read(fd, ptr.baseAddress, ptr.count)
#endif
}
}
)
@@ -823,7 +831,11 @@ class NonBlockingFileIOTest: XCTestCase {
try fileHandle.withUnsafeFileDescriptor { fd -> ssize_t in
var data: UInt8 = 0
return withUnsafeMutableBytes(of: &data) { ptr in
#if os(Windows)
ssize_t(read(fd, ptr.baseAddress, CUnsignedInt(ptr.count)))
#else
read(fd, ptr.baseAddress, ptr.count)
#endif
}
}
)
@@ -882,7 +894,11 @@ class NonBlockingFileIOTest: XCTestCase {
var data: UInt16 = 0
try Posix.lseek(descriptor: fd, offset: 0, whence: SEEK_SET)
let readReturn = withUnsafeMutableBytes(of: &data) { ptr in
#if os(Windows)
ssize_t(read(fd, ptr.baseAddress, CUnsignedInt(ptr.count)))
#else
read(fd, ptr.baseAddress, ptr.count)
#endif
}
XCTAssertEqual(
UInt16(bigEndian: (UInt16(UInt8(ascii: "X")) << 8) | UInt16(UInt8(ascii: "Y"))),
@@ -947,7 +963,11 @@ class NonBlockingFileIOTest: XCTestCase {
var data: UInt16 = 0
try Posix.lseek(descriptor: fd, offset: 0, whence: SEEK_SET)
let readReturn = withUnsafeMutableBytes(of: &data) { ptr in
#if os(Windows)
ssize_t(read(fd, ptr.baseAddress, CUnsignedInt(ptr.count)))
#else
read(fd, ptr.baseAddress, ptr.count)
#endif
}
XCTAssertEqual(UInt16(bigEndian: UInt16(UInt8(ascii: "Y")) << 8), data)
return readReturn
@@ -1161,6 +1181,9 @@ class NonBlockingFileIOTest: XCTestCase {
}
}
#if !os(Windows)
// These use POSIX-only NonBlockingFileIO primitives (lstat/symlink/listDirectory/
// createDirectory) and mode constants (S_IRWXU/S_IFLNK) unavailable on Windows.
func testLStat() throws {
XCTAssertNoThrow(
try withTemporaryFile(content: "hello, world") { _, path in
@@ -1311,6 +1334,7 @@ class NonBlockingFileIOTest: XCTestCase {
}
)
}
#endif
func testChunkedReadingToleratesChunkHandlersWithForeignEventLoops() throws {
let content = "hello"
@@ -1708,7 +1732,11 @@ extension NonBlockingFileIOTest {
try fileHandle.withUnsafeFileDescriptor { fd -> ssize_t in
var data: UInt8 = 0
return withUnsafeMutableBytes(of: &data) { ptr in
#if os(Windows)
ssize_t(read(fd, ptr.baseAddress, CUnsignedInt(ptr.count)))
#else
read(fd, ptr.baseAddress, ptr.count)
#endif
}
}
)
@@ -1728,7 +1756,11 @@ extension NonBlockingFileIOTest {
try fileHandle.withUnsafeFileDescriptor { fd -> ssize_t in
var data: UInt8 = 0
return withUnsafeMutableBytes(of: &data) { ptr in
#if os(Windows)
ssize_t(read(fd, ptr.baseAddress, CUnsignedInt(ptr.count)))
#else
read(fd, ptr.baseAddress, ptr.count)
#endif
}
}
)
@@ -1780,7 +1812,11 @@ extension NonBlockingFileIOTest {
var data: UInt16 = 0
try Posix.lseek(descriptor: fd, offset: 0, whence: SEEK_SET)
let readReturn = withUnsafeMutableBytes(of: &data) { ptr in
#if os(Windows)
ssize_t(read(fd, ptr.baseAddress, CUnsignedInt(ptr.count)))
#else
read(fd, ptr.baseAddress, ptr.count)
#endif
}
XCTAssertEqual(
UInt16(bigEndian: (UInt16(UInt8(ascii: "X")) << 8) | UInt16(UInt8(ascii: "Y"))),
@@ -1837,7 +1873,11 @@ extension NonBlockingFileIOTest {
var data: UInt16 = 0
try Posix.lseek(descriptor: fd, offset: 0, whence: SEEK_SET)
let readReturn = withUnsafeMutableBytes(of: &data) { ptr in
#if os(Windows)
ssize_t(read(fd, ptr.baseAddress, CUnsignedInt(ptr.count)))
#else
read(fd, ptr.baseAddress, ptr.count)
#endif
}
XCTAssertEqual(UInt16(bigEndian: UInt16(UInt8(ascii: "Y")) << 8), data)
return readReturn
@@ -1896,6 +1936,8 @@ extension NonBlockingFileIOTest {
}
}
#if !os(Windows)
// These use POSIX-only NonBlockingFileIO primitives unavailable on Windows.
func testAsyncLStat() async throws {
try await withTemporaryFile(content: "hello, world") { _, path in
let stat = try await self.fileIO.lstat(path: path)
@@ -2009,4 +2051,5 @@ extension NonBlockingFileIOTest {
}
}
}
#endif
}
@@ -20,6 +20,12 @@ import XCTest
@testable import NIOPosix
#if os(Windows)
import CNIOWindows
import WinSDK
private typealias socklen_t = WinSDK.socklen_t
#endif
extension SocketAddress {
fileprivate init(_ addr: UnsafePointer<sockaddr>) {
let erased = UnsafeRawPointer(addr)
@@ -178,8 +184,8 @@ class PendingDatagramWritesManagerTests: XCTestCase {
)
XCTAssertEqual(
expected[multiState].map { $0.1 },
ptrs.map { SocketAddress($0.msg_hdr.msg_name.assumingMemoryBound(to: sockaddr.self)) },
"in vector write \(multiState) (overall \(everythingState)), \(expected[multiState].map { $0.1 }) addresses expected but \(ptrs.map { SocketAddress($0.msg_hdr.msg_name.assumingMemoryBound(to: sockaddr.self)) }) actual",
ptrs.map { SocketAddress($0.msg_hdr.msg_name!.assumingMemoryBound(to: sockaddr.self)) },
"in vector write \(multiState) (overall \(everythingState)), \(expected[multiState].map { $0.1 }) addresses expected but \(ptrs.map { SocketAddress($0.msg_hdr.msg_name!.assumingMemoryBound(to: sockaddr.self)) }) actual",
file: (file),
line: line
)
@@ -152,6 +152,9 @@ final class PipeChannelTest: XCTestCase {
}
func testWeWorkFineWithASingleFileDescriptor() throws {
#if os(Windows)
throw XCTSkip("socketpair is not available on Windows")
#else
final class EchoHandler: ChannelInboundHandler, Sendable {
typealias InboundIn = ByteBuffer
typealias OutboundOut = ByteBuffer
@@ -205,6 +208,7 @@ final class PipeChannelTest: XCTestCase {
}
)
XCTAssertEqual(UInt8(ascii: "X"), spaceForX)
#endif
}
func testWriteEndGoingAway() throws {
@@ -18,6 +18,8 @@ import XCTest
@testable import NIOPosix
// Depends on the SAL harness, which is gated off on Windows.
#if !os(Windows)
final class SALChannelTest: XCTestCase {
func testBasicConnectedChannel() throws {
try withSALContext { context in
@@ -1128,3 +1130,4 @@ final class SALChannelTest: XCTestCase {
}
}
}
#endif
@@ -15,6 +15,8 @@
import NIOCore
import XCTest
// Depends on the SAL harness, which is gated off on Windows.
#if !os(Windows)
final class SALEventLoopTests: XCTestCase {
func testSchedulingTaskOnSleepingLoopWakesUpOnce() throws {
try withSALContext { context in
@@ -57,3 +59,4 @@ final class SALEventLoopTests: XCTestCase {
}
}
}
#endif
+7
View File
@@ -21,6 +21,8 @@ import XCTest
class SelectorTest: XCTestCase {
#if !os(Windows)
// Uses pthread_self and a raw Selector<Registration>, unavailable on Windows.
func testDeregisterWhileProcessingEvents() throws {
try assertDeregisterWhileProcessingEvents(closeAfterDeregister: false)
}
@@ -120,6 +122,7 @@ class SelectorTest: XCTestCase {
XCTAssertEqual(1, readyCount)
}
#endif
private static let testWeDoNotDeliverEventsForPreviouslyClosedChannels_numberOfChannelsToUse = 10
func testWeDoNotDeliverEventsForPreviouslyClosedChannels() throws {
@@ -422,6 +425,9 @@ class SelectorTest: XCTestCase {
}
func testTimerFDIsLevelTriggered() throws {
#if os(Windows)
throw XCTSkip("socketpair is not available on Windows")
#else
// this is a regression test for https://github.com/apple/swift-nio/issues/872
let delayToUseInMicroSeconds: Int64 = 100_000 // needs to be much greater than time it takes to EL.execute
@@ -503,5 +509,6 @@ class SelectorTest: XCTestCase {
)
sched.cancel()
XCTAssertNoThrow(try channelHasBeenClosedPromise.futureResult.wait())
#endif
}
}
+5 -1
View File
@@ -18,6 +18,10 @@ import XCTest
@testable import NIOCore
@testable import NIOPosix
#if os(Windows)
import WinSDK
#endif
class SocketAddressTest: XCTestCase {
func testDescriptionWorks() throws {
@@ -82,7 +86,7 @@ class SocketAddressTest: XCTestCase {
]
var address = sockaddr_in6()
#if os(Linux) || os(Android) // no sin6_len on Linux/Android
#if os(Linux) || os(Android) || os(Windows) // no sin6_len on Linux/Android/Windows
#else
address.sin6_len = UInt8(MemoryLayout<sockaddr_in6>.size)
#endif
+17 -1
View File
@@ -373,6 +373,9 @@ final class SocketChannelTest: XCTestCase {
}
public func testWithConfiguredStreamSocket() throws {
#if os(Windows)
throw XCTSkip("Creating a channel from a pre-connected socket is not supported on Windows")
#else
let didAccept = ConditionLock<Int>(value: 0)
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer { XCTAssertNoThrow(try group.syncShutdownGracefully()) }
@@ -415,9 +418,13 @@ final class SocketChannelTest: XCTestCase {
try serverChannel.close().wait()
try clientChannel.close().wait()
#endif
}
public func testWithConfiguredDatagramSocket() throws {
#if os(Windows)
throw XCTSkip("Creating a channel from a pre-connected socket is not supported on Windows")
#else
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer { XCTAssertNoThrow(try group.syncShutdownGracefully()) }
@@ -432,6 +439,7 @@ final class SocketChannelTest: XCTestCase {
XCTAssertEqual(true, serverChannel.isActive)
try serverChannel.close().wait()
#endif
}
public func testPendingConnectNotificationOrder() throws {
@@ -616,6 +624,9 @@ final class SocketChannelTest: XCTestCase {
}
func testSocketFlagNONBLOCKWorks() throws {
#if os(Windows)
throw XCTSkip("fcntl / O_NONBLOCK flag manipulation is not available on Windows")
#else
var socket = try assertNoThrowWithValue(try ServerSocket(protocolFamily: .inet, setNonBlocking: true))
XCTAssertNoThrow(
try socket.withUnsafeHandle { fd in
@@ -639,10 +650,11 @@ final class SocketChannelTest: XCTestCase {
}
)
XCTAssertNoThrow(try socket.close())
#endif
}
func testInstantTCPConnectionResetThrowsError() throws {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
// This test checks that we correctly fail with an error rather than
// asserting or silently ignoring if a client aborts the connection
// early with a RST before accept(). The behaviour is the same as closing the socket
@@ -750,6 +762,9 @@ final class SocketChannelTest: XCTestCase {
}
func testSetSockOptDoesNotOverrideExistingFlags() throws {
#if os(Windows)
throw XCTSkip("fcntl flag manipulation is not available on Windows")
#else
let s = try assertNoThrowWithValue(
Socket(
protocolFamily: .inet,
@@ -789,6 +804,7 @@ final class SocketChannelTest: XCTestCase {
)
XCTAssertNoThrow(try s.close())
#endif
}
func testServerChannelDoesNotBreakIfAcceptingFailsWithEINVAL() throws {
@@ -17,6 +17,10 @@ import NIOCore
import NIOPosix
import XCTest
#if os(Windows)
import WinSDK
#endif
final class SocketOptionProviderTest: XCTestCase {
var group: MultiThreadedEventLoopGroup!
var serverChannel: Channel!
@@ -203,6 +207,9 @@ final class SocketOptionProviderTest: XCTestCase {
}
func testSoIpMulticastIf() throws {
#if os(Windows)
throw XCTSkip("in_addr.s_addr is not available on Windows")
#else
guard let channel = self.ipv4DatagramChannel else {
// no multicast support
return
@@ -225,6 +232,7 @@ final class SocketOptionProviderTest: XCTestCase {
XCTAssertEqual($0.s_addr, address.s_addr)
}.wait()
)
#endif
}
func testIpMulticastTtl() throws {
@@ -55,6 +55,9 @@ import XCTest
@testable import NIOPosix
// The SAL harness is built around CInt file descriptors; on Windows socket
// handles are UInt64, which is out of scope to reconcile. Gate the whole body.
#if !os(Windows)
internal enum SAL {
fileprivate static let defaultTimeout: Double = 5
private static let debugTests: Bool = false
@@ -1146,3 +1149,4 @@ struct SyscallAssertions: @unchecked Sendable {
try self.selector.assertParkedRightNow(file: file, line: line)
}
}
#endif
@@ -18,6 +18,9 @@ import XCTest
@testable import NIOPosix
// See SyscallAbstractionLayer.swift: the SAL harness is CInt-fd based and gated
// off on Windows.
#if !os(Windows)
struct SALContext {
let eventLoop: SelectableEventLoop
private let wakeups: LockedBox<Void>
@@ -167,3 +170,4 @@ func withSALContext<R>(body: (SALContext) throws -> R) throws -> R {
let result = try body(context)
return result
}
#endif
@@ -46,6 +46,9 @@ enum TestError: Error {
case wouldBlock
}
// These syscall-wrapper performance helpers are POSIX-only: they open
// `/dev/null` and issue raw `write`/`close` calls to compare wrapper overhead.
#if !os(Windows)
func runStandalone() {
func assertFun(
condition: @autoclosure () -> Bool,
@@ -136,3 +139,4 @@ func runSystemCallWrapperPerformanceTest(
#line
)
}
#endif // !os(Windows)
+5
View File
@@ -19,6 +19,10 @@ import XCTest
@testable import NIOPosix
class SystemTest: XCTestCase {
// None of these tests apply on Windows: the syscall-wrapper perf test is
// POSIX-only, `testErrorsWorkCorrectly` uses a POSIX fd as a socket handle,
// and the rest depend on POSIX `cmsg` support.
#if !os(Windows)
func testSystemCallWrapperPerformance() throws {
try runSystemCallWrapperPerformanceTest(
testAssertFunction: XCTAssert,
@@ -184,4 +188,5 @@ class SystemTest: XCTestCase {
XCTAssertEqual(msgNum, 2)
}
}
#endif // !os(Windows)
}
@@ -57,6 +57,8 @@ class VsockAddressTest: XCTestCase {
XCTAssertNotEqual(VsockAddress(cid: 0, port: 0), .init(cid: 0, port: 1))
}
// Getting the local vsock context ID is not available on Windows.
#if !os(Windows)
func testGetLocalCID() throws {
try XCTSkipUnless(System.supportsVsockLoopback, "No vsock loopback transport available")
@@ -80,4 +82,5 @@ class VsockAddressTest: XCTestCase {
)
XCTAssertEqual(try channel.getOption(.localVsockContextID).wait(), localCID)
}
#endif
}