Skip to content

Commit f3491fd

Browse files
authored
Merge branch 'main' into jgrynspan/promote-windows-image-attachments-to-api
2 parents bcf7ff8 + c6512ff commit f3491fd

10 files changed

+31
-19
lines changed

Sources/Testing/Events/Recorder/Event.AdvancedConsoleOutputRecorder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ extension Event {
142142
/// The write function for this recorder.
143143
let write: @Sendable (String) -> Void
144144

145-
/// The fallback console recorder for standard output.
146-
private let _fallbackRecorder: Event.ConsoleOutputRecorder
145+
/// The base console output options.
146+
private let _baseOptions: Event.ConsoleOutputRecorder.Options
147147

148148
/// Context storage for test information and results.
149149
private let _context: Locked<_Context>
@@ -159,7 +159,7 @@ extension Event {
159159
init(options: Options = Options(), writingUsing write: @escaping @Sendable (String) -> Void) {
160160
self.options = options
161161
self.write = write
162-
self._fallbackRecorder = Event.ConsoleOutputRecorder(options: options.base, writingUsing: write)
162+
self._baseOptions = options.base
163163
self._context = Locked(rawValue: _Context())
164164
self._humanReadableRecorder = Event.HumanReadableOutputRecorder()
165165
}
@@ -258,7 +258,7 @@ extension Event.AdvancedConsoleOutputRecorder {
258258
// The hierarchical summary will be shown at the end
259259
switch eventKind {
260260
case .runStarted:
261-
let symbol = Event.Symbol.default.stringValue(options: _fallbackRecorder.options)
261+
let symbol = Event.Symbol.default.stringValue(options: _baseOptions)
262262
write("\(symbol) Test run started.\n")
263263

264264
case .runEnded:

Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ extension Event.HumanReadableOutputRecorder {
361361
comments.append("Swift Standard Library Version: \(swiftStandardLibraryVersion)")
362362
}
363363
comments.append("Swift Compiler Version: \(swiftCompilerVersion)")
364-
#if canImport(Glibc) && !os(FreeBSD) && !os(OpenBSD)
364+
#if os(Linux) && canImport(Glibc)
365365
comments.append("GNU C Library Version: \(glibcVersion)")
366366
#endif
367367
}

Sources/Testing/ExitTests/ExitStatus.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ extension ExitStatus: CustomStringConvertible {
121121
var signalName: String?
122122

123123
#if SWT_TARGET_OS_APPLE || os(FreeBSD) || os(OpenBSD) || os(Android)
124+
#if !SWT_NO_SYS_SIGNAME
124125
// These platforms define sys_signame with a size, which is imported
125126
// into Swift as a tuple.
126127
withUnsafeBytes(of: sys_signame) { sys_signame in
@@ -130,6 +131,7 @@ extension ExitStatus: CustomStringConvertible {
130131
}
131132
}
132133
}
134+
#endif
133135
#elseif os(Linux)
134136
#if !SWT_NO_DYNAMIC_LINKING
135137
signalName = _sigabbrev_np?(signal).flatMap(String.init(validatingCString:))

Sources/Testing/ExitTests/SpawnProcess.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ func spawnExecutable(
113113
withUnsafeTemporaryAllocation(of: sigset_t.self, capacity: 1) { allSignals in
114114
let allSignals = allSignals.baseAddress!
115115
sigfillset(allSignals)
116+
#if os(OpenBSD)
117+
// On OpenBSD, attempting to set the signal handler for SIGKILL or
118+
// SIGSTOP will cause the child process of a call to posix_spawn() to
119+
// exit abnormally with exit code 127. See https://man.openbsd.org/sigaction.2#ERRORS
120+
sigdelset(allSignals, SIGKILL)
121+
sigdelset(allSignals, SIGSTOP)
122+
#endif
116123
posix_spawnattr_setsigdefault(attrs, allSignals);
117124
flags |= CShort(POSIX_SPAWN_SETSIGDEF)
118125
}
@@ -137,7 +144,7 @@ func spawnExecutable(
137144
// standardized in POSIX.1-2024 (see https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_spawn_file_actions_adddup2.html
138145
// and https://www.austingroupbugs.net/view.php?id=411).
139146
_ = posix_spawn_file_actions_adddup2(fileActions, fd, fd)
140-
#if canImport(Glibc) && !os(FreeBSD) && !os(OpenBSD)
147+
#if os(Linux) && canImport(Glibc)
141148
if _slowPath(glibcVersion < VersionNumber(2, 29)) {
142149
// This system is using an older version of glibc that does not
143150
// implement FD_CLOEXEC clearing in posix_spawn_file_actions_adddup2(),

Sources/Testing/ExitTests/WaitFor.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ private let _childProcessContinuations = LockedWith<pthread_mutex_t, [pid_t: Che
8585
/// A condition variable used to suspend the waiter thread created by
8686
/// `_createWaitThread()` when there are no child processes to await.
8787
private nonisolated(unsafe) let _waitThreadNoChildrenCondition = {
88-
#if os(FreeBSD) || os(OpenBSD)
89-
let result = UnsafeMutablePointer<pthread_cond_t?>.allocate(capacity: 1)
90-
#else
9188
let result = UnsafeMutablePointer<pthread_cond_t>.allocate(capacity: 1)
92-
#endif
9389
_ = pthread_cond_init(result, nil)
9490
return result
9591
}()

Sources/Testing/Support/Locked+Platform.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ extension os_unfair_lock_s: Lockable {
3939

4040
#if os(FreeBSD) || os(OpenBSD)
4141
typealias pthread_mutex_t = _TestingInternals.pthread_mutex_t?
42+
typealias pthread_cond_t = _TestingInternals.pthread_cond_t?
4243
#endif
4344

44-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || (os(WASI) && _runtime(_multithreaded)) || os(FreeBSD) || os(OpenBSD)
45+
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || (os(WASI) && _runtime(_multithreaded))
4546
extension pthread_mutex_t: Lockable {
4647
static func initializeLock(at lock: UnsafeMutablePointer<Self>) {
4748
_ = pthread_mutex_init(lock, nil)
@@ -83,7 +84,7 @@ extension SRWLOCK: Lockable {
8384

8485
#if SWT_TARGET_OS_APPLE && !SWT_NO_OS_UNFAIR_LOCK
8586
typealias DefaultLock = os_unfair_lock
86-
#elseif SWT_TARGET_OS_APPLE || os(Linux) || os(Android) || (os(WASI) && _runtime(_multithreaded)) || os(FreeBSD) || os(OpenBSD)
87+
#elseif SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || (os(WASI) && _runtime(_multithreaded))
8788
typealias DefaultLock = pthread_mutex_t
8889
#elseif os(Windows)
8990
typealias DefaultLock = SRWLOCK

Sources/Testing/Support/Versions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ var swiftCompilerVersion: VersionNumber {
198198
)
199199
}
200200

201-
#if canImport(Glibc) && !os(FreeBSD) && !os(OpenBSD)
201+
#if os(Linux) && canImport(Glibc)
202202
/// The (runtime, not compile-time) version of glibc in use on this system.
203203
///
204204
/// This value is not part of the public interface of the testing library.

Tests/TestingTests/ABIEntryPointTests.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ struct ABIEntryPointTests {
6767
passing arguments: __CommandLineArguments_v0,
6868
recordHandler: @escaping @Sendable (_ recordJSON: UnsafeRawBufferPointer) -> Void = { _ in }
6969
) async throws -> Bool {
70-
#if !os(Linux) && !os(FreeBSD) && !os(Android) && !SWT_NO_DYNAMIC_LINKING
70+
#if !(os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android)) && !SWT_NO_DYNAMIC_LINKING
7171
// Get the ABI entry point by dynamically looking it up at runtime.
7272
//
73-
// NOTE: The standard Linux linker does not allow exporting symbols from
74-
// executables, so dlsym() does not let us find this function on that
75-
// platform when built as an executable rather than a dynamic library.
73+
// NOTE: The standard linkers on these platforms do not export symbols from
74+
// executables, so dlsym() does not let us find this function on these
75+
// platforms when built as an executable rather than a dynamic library.
7676
let abiv0_getEntryPoint = try withTestingLibraryImageAddress { testingLibrary in
7777
try #require(
7878
symbol(in: testingLibrary, named: "swt_abiv0_getEntryPoint").map {
@@ -187,8 +187,9 @@ private func withTestingLibraryImageAddress<R>(_ body: (ImageAddress?) throws ->
187187
defer {
188188
dlclose(testingLibraryAddress)
189189
}
190-
#elseif os(Linux) || os(FreeBSD) || os(Android)
191-
// When using glibc, dladdr() is only available if __USE_GNU is specified.
190+
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android)
191+
// We can't dynamically look up a function linked into the test executable on
192+
// ELF-based platforms.
192193
#elseif os(Windows)
193194
let flags = DWORD(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)
194195
try addressInTestingLibrary.withMemoryRebound(to: wchar_t.self, capacity: MemoryLayout<UnsafeRawPointer>.stride / MemoryLayout<wchar_t>.stride) { addressInTestingLibrary in

Tests/TestingTests/AdvancedConsoleOutputRecorderTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11+
#if canImport(Foundation)
1112
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
13+
import Foundation
1214

1315
@Suite("Advanced Console Output Recorder Tests")
1416
struct AdvancedConsoleOutputRecorderTests {
@@ -237,3 +239,4 @@ struct SimpleTestSuite {
237239
#expect(Bool(true))
238240
}
239241
}
242+
#endif

Tests/TestingTests/ExitTestTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ private import _TestingInternals
1616
@Test("Signal names are reported (where supported)") func signalName() {
1717
var hasSignalNames = false
1818
#if SWT_TARGET_OS_APPLE || os(FreeBSD) || os(OpenBSD) || os(Android)
19+
#if !SWT_NO_SYS_SIGNAME
1920
hasSignalNames = true
21+
#endif
2022
#elseif os(Linux) && !SWT_NO_DYNAMIC_LINKING
2123
hasSignalNames = (symbol(named: "sigabbrev_np") != nil)
2224
#endif

0 commit comments

Comments
 (0)