From 8139a39b199e71cffb1ec3c3a6dea69497717847 Mon Sep 17 00:00:00 2001 From: Rauhul Varma Date: Sun, 5 Dec 2021 16:28:29 -0800 Subject: [PATCH] wip tests --- .../FileStatus/FileStatusOperations.swift | 10 ++-- Tests/SystemTests/FileOperationsTest.swift | 46 ++++++++++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/Sources/System/FileStatus/FileStatusOperations.swift b/Sources/System/FileStatus/FileStatusOperations.swift index 33d63520..16933358 100644 --- a/Sources/System/FileStatus/FileStatusOperations.swift +++ b/Sources/System/FileStatus/FileStatusOperations.swift @@ -15,6 +15,8 @@ extension FileDescriptor { public struct ControlFlags { let rawValue: Int32 + // Test stub + public static var none: ControlFlags = ControlFlags(rawValue: 0) // Out of scope of this sketch } } @@ -63,7 +65,7 @@ extension FilePath { retryOnInterrupt: Bool ) -> Result { var result = CInterop.Stat() - let fn = followSymlinks ? system_stat : system_lstat + let fn = followSymlinks ? system_lstat : system_stat return withPlatformString { ptr in nothingOrErrno(retryOnInterrupt: retryOnInterrupt) { fn(ptr, &result) @@ -177,7 +179,7 @@ extension FilePath { followSymlinks: Bool, retryOnInterrupt: Bool ) -> Result { - let _chmod = followSymlinks ? system_chmod : system_lchmod + let _chmod = followSymlinks ? system_lchmod : system_chmod return withPlatformString { ptr in nothingOrErrno(retryOnInterrupt: retryOnInterrupt) { _chmod(ptr, permissions.rawValue) @@ -272,7 +274,7 @@ extension FilePath { followSymlinks: Bool, retryOnInterrupt: Bool ) -> Result { - let _chown = followSymlinks ? system_chown : system_lchown + let _chown = followSymlinks ? system_lchown : system_chown return withPlatformString { ptr in nothingOrErrno(retryOnInterrupt: retryOnInterrupt) { _chown(ptr, userID, groupID) @@ -368,7 +370,7 @@ extension FilePath { followSymlinks: Bool, retryOnInterrupt: Bool ) -> Result { - let _chflags = followSymlinks ? system_chflags : system_lchflags + let _chflags = followSymlinks ? system_lchflags : system_chflags return withPlatformString { ptr in nothingOrErrno(retryOnInterrupt: retryOnInterrupt) { _chflags(ptr, flags.rawValue) diff --git a/Tests/SystemTests/FileOperationsTest.swift b/Tests/SystemTests/FileOperationsTest.swift index 419e1c97..8d388127 100644 --- a/Tests/SystemTests/FileOperationsTest.swift +++ b/Tests/SystemTests/FileOperationsTest.swift @@ -28,7 +28,8 @@ final class FileOperationsTest: XCTestCase { let writeBuf = UnsafeRawBufferPointer(rawBuf) let writeBufAddr = writeBuf.baseAddress - let syscallTestCases: Array = [ + var syscallTestCases: Array = [] + syscallTestCases += [ MockTestCase(name: "open", .interruptable, "a path", O_RDWR | O_APPEND) { retryOnInterrupt in _ = try FileDescriptor.open( @@ -83,6 +84,49 @@ final class FileOperationsTest: XCTestCase { }, ] +#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) + let fp = FilePath("/") + let rawFP = fp.withPlatformString { strdup($0) } + defer { free(rawFP) } + + let stat = UnsafeMutablePointer.allocate(capacity: 1) + defer { stat.deallocate() } + + syscallTestCases += [ +// MockTestCase(name: "stat", .interruptable, rawFP) { retryOnInterrupt in +// _ = try fp.stat(followSymlinks: false, retryOnInterrupt: retryOnInterrupt) +// }, +// MockTestCase(name: "lstat", .interruptable, rawFP) { retryOnInterrupt in +// _ = try fp.stat(followSymlinks: true, retryOnInterrupt: retryOnInterrupt) +// }, +// MockTestCase(name: "fstat", .interruptable, rawFP) { retryOnInterrupt in +// _ = try fd.stat(retryOnInterrupt: retryOnInterrupt) +// }, +// MockTestCase(name: "fstatat", .interruptable, rawFP) { retryOnInterrupt in +// _ = try fp.stat(relativeTo: fd, fcntrl: .none, retryOnInterrupt: retryOnInterrupt) +// }, + // fstatat + // chmod + // lchmod + // fchmod + // fchmodat + // chown + // lchown + // fchown + // fchownat + // chflags + // lchflags + // fchflags + // umask + // mkfifo + // mknod + // mkdir + // mkdirat + // futimens + // utimensat + ] +#endif + for test in syscallTestCases { test.runAllTests() } }