Skip to content

Commit a66176f

Browse files
committed
Only run IORing tests if io_uring support is enabled
1 parent b93169b commit a66176f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Tests/SystemTests/IORingTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@ import SystemPackage
1010
import System
1111
#endif
1212

13+
func uringEnabled() throws -> Bool {
14+
let procPath = FilePath("/proc/sys/kernel/io_uring_disabled")
15+
let fd = try FileDescriptor.open(procPath, .readOnly)
16+
let buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: 1024, alignment: 0)
17+
_ = try fd.read(into: buffer)
18+
if buffer.load(fromByteOffset: 0, as: Int.self) == 0 {
19+
return true
20+
}
21+
return false
22+
}
23+
1324
final class IORingTests: XCTestCase {
1425
func testInit() throws {
26+
guard try uringEnabled() else { return }
1527
_ = try IORing(queueDepth: 32, flags: [])
1628
}
1729

1830
func testNop() throws {
31+
guard try uringEnabled() else { return }
1932
var ring = try IORing(queueDepth: 32, flags: [])
2033
_ = try ring.submit(linkedRequests: .nop())
2134
let completion = try ring.blockingConsumeCompletion()
@@ -51,13 +64,15 @@ final class IORingTests: XCTestCase {
5164
}
5265

5366
func testUndersizedSubmissionQueue() throws {
67+
guard try uringEnabled() else { return }
5468
var ring: IORing = try IORing(queueDepth: 1)
5569
let enqueued = ring.prepare(linkedRequests: .nop(), .nop())
5670
XCTAssertFalse(enqueued)
5771
}
5872

5973
// Exercises opening, reading, closing, registered files, registered buffers, and eventfd
6074
func testOpenReadAndWriteFixedFile() throws {
75+
guard try uringEnabled() else { return }
6176
let (parent, path) = try makeHelloWorldFile()
6277
let rawBuffer = UnsafeMutableRawBufferPointer.allocate(byteCount: 13, alignment: 16)
6378
var ring = try setupTestRing(depth: 6, fileSlots: 1, buffers: [rawBuffer])

0 commit comments

Comments
 (0)