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
13 changes: 13 additions & 0 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,8 @@ public enum TestRunPredicate : CustomStringConvertible {

case haikuAny(reason: String)

case wasiAny(reason: String)

case objCRuntime(/*reason:*/ String)
case nativeRuntime(/*reason:*/ String)

Expand Down Expand Up @@ -2565,6 +2567,9 @@ public enum TestRunPredicate : CustomStringConvertible {
case .haikuAny(reason: let reason):
return "haikuAny(*, reason: \(reason))"

case .wasiAny(reason: let reason):
return "wasiAny(*, reason: \(reason))"

case .objCRuntime(let reason):
return "Objective-C runtime, reason: \(reason))"
case .nativeRuntime(let reason):
Expand Down Expand Up @@ -2947,6 +2952,14 @@ public enum TestRunPredicate : CustomStringConvertible {
return false
}

case .wasiAny:
switch _getRunningOSVersion() {
case .wasi:
return true
default:
return false
}

case .objCRuntime:
#if _runtime(_ObjC)
return true
Expand Down
68 changes: 38 additions & 30 deletions test/stdlib/UnsafeRawBufferPointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ UnsafeRawBufferPointerTestSuite.test("initFromArray") {
expectEqual(array2, array1)
}

#if !os(WASI)
// Trap tests aren't available on WASI.
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).underflow") {
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).underflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 30,
alignment: MemoryLayout<UInt64>.alignment
Expand All @@ -152,7 +151,8 @@ UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).underflow") {
expectEqualSequence([5, 4, 3],bound)
}

UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).overflow") {
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 30,
alignment: MemoryLayout<UInt64>.alignment
Expand All @@ -170,7 +170,6 @@ UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).overflow") {
expected.withUnsafeBytes { expectEqualSequence($0,buffer[0..<idx]) }
expectEqualSequence([5, 4, 3],bound)
}
#endif

UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).exact") {
let buffer = UnsafeMutableRawBufferPointer.allocate(
Expand All @@ -187,15 +186,13 @@ UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).exact") {
expectEqualSequence([5, 4, 3],bound)
}

#if !os(WASI)
// Trap tests aren't available on WASI.
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).invalidNilPtr") {
UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).invalidNilPtr")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer(start: nil, count: 0)
let source: [Int64] = [5, 4, 3, 2, 1]
expectCrashLater()
_ = buffer.initializeMemory(as: Int64.self, from: source)
}
#endif

UnsafeRawBufferPointerTestSuite.test("initializeMemory(as:from:).validNilPtr") {
let buffer = UnsafeMutableRawBufferPointer(start: nil, count: 0)
Expand Down Expand Up @@ -305,9 +302,8 @@ UnsafeRawBufferPointerTestSuite.test("inBounds") {
expectEqualSequence(firstHalf, secondHalf)
}

#if !os(WASI)
// Trap tests aren't available on WASI.
UnsafeRawBufferPointerTestSuite.test("subscript.get.underflow") {
UnsafeRawBufferPointerTestSuite.test("subscript.get.underflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 2,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -323,7 +319,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.get.underflow") {
_ = bytes[-1]
}

UnsafeRawBufferPointerTestSuite.test("subscript.get.overflow") {
UnsafeRawBufferPointerTestSuite.test("subscript.get.overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 2,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -339,7 +336,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.get.overflow") {
_ = bytes[1]
}

UnsafeRawBufferPointerTestSuite.test("subscript.set.underflow") {
UnsafeRawBufferPointerTestSuite.test("subscript.set.underflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 2,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -355,7 +353,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.set.underflow") {
bytes[-1] = 0
}

UnsafeRawBufferPointerTestSuite.test("subscript.set.overflow") {
UnsafeRawBufferPointerTestSuite.test("subscript.set.overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 2,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -371,7 +370,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.set.overflow") {
bytes[1] = 0
}

UnsafeRawBufferPointerTestSuite.test("subscript.range.get.underflow") {
UnsafeRawBufferPointerTestSuite.test("subscript.range.get.underflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 3,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -387,7 +387,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.get.underflow") {
_ = bytes[-1..<1]
}

UnsafeRawBufferPointerTestSuite.test("subscript.range.get.overflow") {
UnsafeRawBufferPointerTestSuite.test("subscript.range.get.overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 3,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -403,7 +404,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.get.overflow") {
_ = bytes[1..<3]
}

UnsafeRawBufferPointerTestSuite.test("subscript.range.set.underflow") {
UnsafeRawBufferPointerTestSuite.test("subscript.range.set.underflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 3,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -419,7 +421,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.set.underflow") {
bytes[-1..<1] = bytes[0..<2]
}

UnsafeRawBufferPointerTestSuite.test("subscript.range.set.overflow") {
UnsafeRawBufferPointerTestSuite.test("subscript.range.set.overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 3,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -436,7 +439,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.set.overflow") {
bytes[1..<3] = bytes[0..<2]
}

UnsafeRawBufferPointerTestSuite.test("subscript.range.narrow") {
UnsafeRawBufferPointerTestSuite.test("subscript.range.narrow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 3,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -450,7 +454,8 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.narrow") {
buffer[0..<3] = buffer[0..<2]
}

UnsafeRawBufferPointerTestSuite.test("subscript.range.wide") {
UnsafeRawBufferPointerTestSuite.test("subscript.range.wide")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 3,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -463,7 +468,6 @@ UnsafeRawBufferPointerTestSuite.test("subscript.range.wide") {
// Performs a valid byte-wise copy but triggers a debug bounds check.
buffer[0..<2] = buffer[0..<3]
}
#endif

UnsafeRawBufferPointerTestSuite.test("_copyContents") {
let a = Array<UInt8>(0..<20)
Expand All @@ -477,9 +481,8 @@ UnsafeRawBufferPointerTestSuite.test("_copyContents") {
expectEqual(written, a.count)
}

#if !os(WASI)
// Trap tests aren't available on WASI.
UnsafeRawBufferPointerTestSuite.test("copyMemory.overflow") {
UnsafeRawBufferPointerTestSuite.test("copyMemory.overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 3,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -495,7 +498,6 @@ UnsafeRawBufferPointerTestSuite.test("copyMemory.overflow") {
UnsafeMutableRawBufferPointer(rebasing: bytes).copyMemory(
from: UnsafeRawBufferPointer(buffer))
}
#endif

// Use copyBytes without contiguous storage
UnsafeRawBufferPointerTestSuite.test("copyBytes.withoutContiguousStorage") {
Expand All @@ -510,9 +512,8 @@ UnsafeRawBufferPointerTestSuite.test("copyBytes.withoutContiguousStorage") {
}
}

#if !os(WASI)
// Trap tests aren't available on WASI.
UnsafeRawBufferPointerTestSuite.test("copyBytes.sequence.overflow") {
UnsafeRawBufferPointerTestSuite.test("copyBytes.sequence.overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI.")).code {
let buffer = UnsafeMutableRawBufferPointer.allocate(
byteCount: 3,
alignment: MemoryLayout<UInt>.alignment
Expand All @@ -530,6 +531,7 @@ UnsafeRawBufferPointerTestSuite.test("copyBytes.sequence.overflow") {
}

UnsafeRawBufferPointerTestSuite.test("load.before")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
.skip(.custom(
{ !_isDebugAssertConfiguration() },
reason: "This tests a debug precondition."))
Expand All @@ -542,6 +544,7 @@ UnsafeRawBufferPointerTestSuite.test("load.before")
}

UnsafeRawBufferPointerTestSuite.test("load.after")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
.skip(.custom(
{ !_isDebugAssertConfiguration() },
reason: "This tests a debug precondition.."))
Expand All @@ -566,6 +569,7 @@ UnsafeRawBufferPointerTestSuite.test("load.aligned") {
}

UnsafeRawBufferPointerTestSuite.test("load.invalid")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
.skip(.custom({ !_isDebugAssertConfiguration() }, // require debugAssert
reason: "This tests a debug precondition.."))
.code {
Expand Down Expand Up @@ -594,6 +598,7 @@ UnsafeRawBufferPointerTestSuite.test("load.unaligned")
}

UnsafeRawBufferPointerTestSuite.test("store.before")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
.skip(.custom(
{ !_isDebugAssertConfiguration() },
reason: "This tests a debug precondition.."))
Expand All @@ -605,6 +610,7 @@ UnsafeRawBufferPointerTestSuite.test("store.before")
}
}
UnsafeRawBufferPointerTestSuite.test("store.after")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
.skip(.custom(
{ !_isDebugAssertConfiguration() },
reason: "This tests a debug precondition.."))
Expand Down Expand Up @@ -641,6 +647,7 @@ UnsafeRawBufferPointerTestSuite.test("store.unaligned")
}

UnsafeRawBufferPointerTestSuite.test("store.invalid")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
.skip(.custom({ !_isDebugAssertConfiguration() }, // require debugAssert
reason: "This tests a debug precondition.."))
.require(.stdlib_5_7)
Expand All @@ -666,6 +673,7 @@ UnsafeRawBufferPointerTestSuite.test("store.valid") {
}

UnsafeRawBufferPointerTestSuite.test("copy.bytes.overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
.skip(.custom(
{ !_isDebugAssertConfiguration() },
reason: "This tests a debug precondition.."))
Expand All @@ -682,6 +690,7 @@ UnsafeRawBufferPointerTestSuite.test("copy.bytes.overflow")
}

UnsafeRawBufferPointerTestSuite.test("copy.sequence.overflow")
.skip(.wasiAny(reason: "Trap tests aren't supported on WASI."))
.skip(.custom(
{ !_isDebugAssertConfiguration() },
reason: "This tests a debug precondition.."))
Expand All @@ -695,7 +704,6 @@ UnsafeRawBufferPointerTestSuite.test("copy.sequence.overflow")
}
}
}
#endif

UnsafeRawBufferPointerTestSuite.test("copy.overlap") {
let bytes = UnsafeMutableRawBufferPointer.allocate(
Expand Down