Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,21 @@ jobs:
with:
name: "Integration tests"
matrix_linux_command: "apt-get update -y -q && apt-get install -y -q lsof dnsutils netcat-openbsd net-tools curl jq && ./scripts/integration_tests.sh"

vsock-tests:
name: Vsock tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Load vsock_loopback kernel module
run: sudo modprobe vsock_loopback
- name: Build package tests
run: swift build --build-tests
- name: Run Vsock tests
shell: bash # explicitly choose bash, which ensures -o pipefail
run: swift test --filter "(?i)vsock" | tee test.out
- name: Check for skipped tests
run: test -r test.out && ! grep -i skipped test.out
2 changes: 1 addition & 1 deletion Sources/NIOPosix/VsockAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ extension VsockAddress.ContextID {
/// - On Darwin, the `ioctl()` request operates on a socket.
/// - On Linux, the `ioctl()` request operates on the `/dev/vsock` device.
///
/// - Note: On Linux, ``local`` may be a better choice.
/// - Note: The semantics of this `ioctl` vary between vsock transports on Linux; ``local`` may be more suitable.
static func getLocalContextID(_ socketFD: NIOBSDSocket.Handle) throws -> Self {
#if canImport(Darwin)
let request = CNIODarwin_IOCTL_VM_SOCKETS_GET_LOCAL_CID
Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOPosixTests/AsyncChannelBootstrapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ final class AsyncChannelBootstrapTests: XCTestCase {
// MARK: VSock

func testVSock() async throws {
try XCTSkipUnless(System.supportsVsock, "No vsock transport available")
try XCTSkipUnless(System.supportsVsockLoopback, "No vsock loopback transport available")
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 3)
defer {
try! eventLoopGroup.syncShutdownGracefully()
Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOPosixTests/EchoServerClientTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class EchoServerClientTest: XCTestCase {
}

func testEchoVsock() throws {
try XCTSkipUnless(System.supportsVsock, "No vsock transport available")
try XCTSkipUnless(System.supportsVsockLoopback, "No vsock loopback transport available")
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer {
XCTAssertNoThrow(try group.syncShutdownGracefully())
Expand Down
17 changes: 4 additions & 13 deletions Tests/NIOPosixTests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,10 @@ extension System {
}
}

static var supportsVsock: Bool {
#if canImport(Darwin) || os(Linux) || os(Android)
guard let socket = try? Socket(protocolFamily: .vsock, type: .stream) else { return false }
XCTAssertNoThrow(try socket.close())
#if !canImport(Darwin)
do {
let fd = try Posix.open(file: "/dev/vsock", oFlag: O_RDONLY | O_CLOEXEC)
try Posix.close(descriptor: fd)
} catch {
return false
}
#endif
return true
static var supportsVsockLoopback: Bool {
#if os(Linux) || os(Android)
guard let modules = try? String(contentsOf: URL(fileURLWithPath: "/proc/modules")) else { return false }
return modules.split(separator: "\n").compactMap({ $0.split(separator: " ").first }).contains("vsock_loopback")
#else
return false
#endif
Expand Down
8 changes: 4 additions & 4 deletions Tests/NIOPosixTests/VsockAddressTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class VsockAddressTest: XCTestCase {
}

func testGetLocalCID() throws {
try XCTSkipUnless(System.supportsVsock)
try XCTSkipUnless(System.supportsVsockLoopback, "No vsock loopback transport available")

let socket = try ServerSocket(protocolFamily: .vsock, setNonBlocking: true)
defer { try? socket.close() }

// Check the local CID is valid: higher than reserved values, but not VMADDR_CID_ANY.
// Check we can get the local CID using the static property on ContextID.
let localCID = try socket.withUnsafeHandle(VsockAddress.ContextID.getLocalContextID)
XCTAssertNotEqual(localCID, .any)
XCTAssertGreaterThan(localCID.rawValue, VsockAddress.ContextID.host.rawValue)

// Check the local CID from the socket matches.
XCTAssertEqual(try socket.getLocalVsockContextID(), localCID)

// Check the local CID from the channel option matches.
Expand Down