Skip to content

Commit

Permalink
wip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rauhul committed Feb 4, 2023
1 parent ae57151 commit 8139a39
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Sources/System/FileStatus/FileStatusOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -63,7 +65,7 @@ extension FilePath {
retryOnInterrupt: Bool
) -> Result<FileStatus, Errno> {
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)
Expand Down Expand Up @@ -177,7 +179,7 @@ extension FilePath {
followSymlinks: Bool,
retryOnInterrupt: Bool
) -> Result<Void, Errno> {
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)
Expand Down Expand Up @@ -272,7 +274,7 @@ extension FilePath {
followSymlinks: Bool,
retryOnInterrupt: Bool
) -> Result<Void, Errno> {
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)
Expand Down Expand Up @@ -368,7 +370,7 @@ extension FilePath {
followSymlinks: Bool,
retryOnInterrupt: Bool
) -> Result<Void, Errno> {
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)
Expand Down
46 changes: 45 additions & 1 deletion Tests/SystemTests/FileOperationsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ final class FileOperationsTest: XCTestCase {
let writeBuf = UnsafeRawBufferPointer(rawBuf)
let writeBufAddr = writeBuf.baseAddress

let syscallTestCases: Array<MockTestCase> = [
var syscallTestCases: Array<MockTestCase> = []
syscallTestCases += [
MockTestCase(name: "open", .interruptable, "a path", O_RDWR | O_APPEND) {
retryOnInterrupt in
_ = try FileDescriptor.open(
Expand Down Expand Up @@ -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<stat>.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() }
}

Expand Down

0 comments on commit 8139a39

Please sign in to comment.