Skip to content

Use the new Android overlay in the tests and update some Bionic declarations #3009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2024
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
11 changes: 1 addition & 10 deletions Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,12 @@ internal func libc_confstr(
#endif

/// fts(3)
#if os(Android)
internal func libc_fts_open(
_ path: [UnsafeMutablePointer<CInterop.PlatformChar>],
_ options: CInt
) -> UnsafeMutablePointer<CInterop.FTS> {
fts_open(path, options, nil)!
}
#else
internal func libc_fts_open(
_ path: [UnsafeMutablePointer<CInterop.PlatformChar>?],
_ options: CInt
) -> UnsafeMutablePointer<CInterop.FTS> {
fts_open(path, options, nil)
fts_open(path, options, nil)!
}
#endif

/// fts(3)
internal func libc_fts_read(
Expand Down
18 changes: 14 additions & 4 deletions Sources/NIOPosix/System.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,20 @@ private let sysWritev = sysWritev_wrapper
#elseif !os(Windows)
private let sysWritev: @convention(c) (Int32, UnsafePointer<iovec>?, CInt) -> CLong = writev
#endif
#if !os(Windows)
#if canImport(Android)
private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>, CInt) -> ssize_t = recvmsg
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These nullability annotations were added with NDK 27 this summer, so adapt these networking APIs for that.

private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>, CInt) -> ssize_t = sendmsg
#elseif !os(Windows)
private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>?, CInt) -> ssize_t = recvmsg
private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>?, CInt) -> ssize_t = sendmsg
#endif
private let sysDup: @convention(c) (CInt) -> CInt = dup
#if !os(Windows)
#if canImport(Android)
private let sysGetpeername:
@convention(c) (CInt, UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) -> CInt = getpeername
private let sysGetsockname:
@convention(c) (CInt, UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) -> CInt = getsockname
#elseif !os(Windows)
private let sysGetpeername:
@convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getpeername
private let sysGetsockname:
Expand All @@ -141,7 +149,9 @@ private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>) -> CUnsigned
#else
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>?) -> CUnsignedInt = if_nametoindex
#endif
#if !os(Windows)
#if canImport(Android)
private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer<CInt>) -> CInt = socketpair
#elseif !os(Windows)
private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer<CInt>?) -> CInt = socketpair
#endif

Expand Down Expand Up @@ -1000,7 +1010,7 @@ internal enum Posix {
socketVector: UnsafeMutablePointer<CInt>?
) throws {
_ = try syscall(blocking: false) {
sysSocketpair(domain.rawValue, type.rawValue, protocolSubtype.rawValue, socketVector)
sysSocketpair(domain.rawValue, type.rawValue, protocolSubtype.rawValue, socketVector!)
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import XCTest
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Bionic)
import Bionic
#elseif canImport(Android)
import Android
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed a couple months ago, the compiler started requiring different imports after the Foundation rewrite this summer.

#else
#error("The Concurrency helpers test module was unable to identify your C library.")
#endif
Expand Down
4 changes: 4 additions & 0 deletions Tests/NIOCoreTests/XCTest+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import NIOCore
import XCTest

#if canImport(Android)
import Android
#endif

func assert(
_ condition: @autoclosure () -> Bool,
within time: TimeAmount,
Expand Down
4 changes: 4 additions & 0 deletions Tests/NIOEmbeddedTests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import NIOConcurrencyHelpers
import NIOCore
import XCTest

#if canImport(Android)
import Android
#endif

// FIXME: Duplicated with NIO
func assert(
_ condition: @autoclosure () -> Bool,
Expand Down
10 changes: 5 additions & 5 deletions Tests/NIOFileSystemTests/FileInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import _NIOFileSystem
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Bionic)
import Bionic
#elseif canImport(Android)
import Android
#endif

final class FileInfoTests: XCTestCase {
Expand All @@ -44,7 +44,7 @@ final class FileInfoTests: XCTestCase {
status.st_birthtimespec = timespec(tv_sec: 3, tv_nsec: 0)
status.st_flags = 11
status.st_gen = 12
#elseif canImport(Glibc) || canImport(Bionic)
#elseif canImport(Glibc) || canImport(Android)
status.st_atim = timespec(tv_sec: 0, tv_nsec: 0)
status.st_mtim = timespec(tv_sec: 1, tv_nsec: 0)
status.st_ctim = timespec(tv_sec: 2, tv_nsec: 0)
Expand Down Expand Up @@ -98,7 +98,7 @@ final class FileInfoTests: XCTestCase {
assertNotEqualAfterMutation { $0.platformSpecificStatus!.st_birthtimespec.tv_sec += 1 }
assertNotEqualAfterMutation { $0.platformSpecificStatus!.st_flags += 1 }
assertNotEqualAfterMutation { $0.platformSpecificStatus!.st_gen += 1 }
#elseif canImport(Glibc) || canImport(Bionic)
#elseif canImport(Glibc) || canImport(Android)
assertNotEqualAfterMutation { $0.platformSpecificStatus!.st_atim.tv_sec += 1 }
assertNotEqualAfterMutation { $0.platformSpecificStatus!.st_mtim.tv_sec += 1 }
assertNotEqualAfterMutation { $0.platformSpecificStatus!.st_ctim.tv_sec += 1 }
Expand Down Expand Up @@ -151,7 +151,7 @@ final class FileInfoTests: XCTestCase {
}
assertDifferentHashValueAfterMutation { $0.platformSpecificStatus!.st_flags += 1 }
assertDifferentHashValueAfterMutation { $0.platformSpecificStatus!.st_gen += 1 }
#elseif canImport(Glibc) || canImport(Bionic)
#elseif canImport(Glibc) || canImport(Android)
assertDifferentHashValueAfterMutation { $0.platformSpecificStatus!.st_atim.tv_sec += 1 }
assertDifferentHashValueAfterMutation { $0.platformSpecificStatus!.st_mtim.tv_sec += 1 }
assertDifferentHashValueAfterMutation { $0.platformSpecificStatus!.st_ctim.tv_sec += 1 }
Expand Down
2 changes: 2 additions & 0 deletions Tests/NIOFileSystemTests/FileTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import XCTest
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Android)
import Android
#endif

final class FileTypeTests: XCTestCase {
Expand Down
Loading