Skip to content

Commit 86ea091

Browse files
kateinoigakukunrunner
authored andcommitted
[wasm][test] Fix build of StdlibUnittest on WASI
WASI platform doesn't support crash interception and spawning threads/processes. So this patch disables interception support and subprocess spawning. The later patch will disable crash tests in each test case.
1 parent d829fe0 commit 86ea091

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

stdlib/private/StdlibUnittest/InterceptTraps.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ static void CrashCatcher(int Sig) {
5050
_exit(0);
5151
}
5252

53-
#endif // __wasi__
54-
5553
#if defined(_WIN32)
5654
static LONG WINAPI
5755
VectoredCrashHandler(PEXCEPTION_POINTERS ExceptionInfo) {
@@ -92,6 +90,8 @@ void installTrapInterceptor() {
9290
signal(SIGBUS, CrashCatcher);
9391
signal(SIGSYS, CrashCatcher);
9492
#endif
95-
}
9693

9794
#endif // !defined(__wasi__)
95+
}
96+
97+
#endif // !defined(__wasi__)

stdlib/private/StdlibUnittest/RaceTest.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838

3939
import SwiftPrivate
4040
import SwiftPrivateLibcExtras
41+
#if !os(WASI)
4142
import SwiftPrivateThreadExtras
43+
#endif
4244
#if canImport(Darwin)
4345
import Darwin
4446
#elseif canImport(Glibc)

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313

1414
import SwiftPrivate
15+
#if !os(WASI)
1516
import SwiftPrivateThreadExtras
17+
#endif
1618
import SwiftPrivateLibcExtras
1719

1820
#if canImport(Darwin)
@@ -22,6 +24,8 @@ import Foundation
2224
import Darwin
2325
#elseif canImport(Glibc)
2426
import Glibc
27+
#elseif os(WASI)
28+
import WASILibc
2529
#elseif os(Windows)
2630
import CRT
2731
import WinSDK
@@ -35,6 +39,12 @@ import ObjectiveC
3539
import _Concurrency
3640
#endif
3741

42+
#if os(WASI)
43+
let platformSupportSpawnChild = false
44+
#else
45+
let platformSupportSpawnChild = true
46+
#endif
47+
3848
extension String {
3949
/// Returns the lines in `self`.
4050
public var _lines : [String] {
@@ -855,8 +865,10 @@ var _testSuiteNameToIndex: [String : Int] = [:]
855865
let _stdlibUnittestStreamPrefix = "__STDLIB_UNITTEST__"
856866
let _crashedPrefix = "CRASHED:"
857867

868+
#if !os(WASI)
858869
@_silgen_name("installTrapInterceptor")
859870
func _installTrapInterceptor()
871+
#endif
860872

861873
#if _runtime(_ObjC)
862874
@objc protocol _StdlibUnittestNSException {
@@ -867,7 +879,9 @@ func _installTrapInterceptor()
867879
// Avoid serializing references to objc_setUncaughtExceptionHandler in SIL.
868880
@inline(never)
869881
func _childProcess() {
882+
#if !os(WASI)
870883
_installTrapInterceptor()
884+
#endif
871885

872886
#if _runtime(_ObjC)
873887
objc_setUncaughtExceptionHandler {
@@ -923,7 +937,9 @@ func _childProcess() {
923937
@available(SwiftStdlib 5.1, *)
924938
@inline(never)
925939
func _childProcessAsync() async {
940+
#if !os(WASI)
926941
_installTrapInterceptor()
942+
#endif
927943

928944
#if _runtime(_ObjC)
929945
objc_setUncaughtExceptionHandler {
@@ -1724,7 +1740,7 @@ public func runAllTests() {
17241740
if _isChildProcess {
17251741
_childProcess()
17261742
} else {
1727-
var runTestsInProcess: Bool = false
1743+
var runTestsInProcess: Bool = !platformSupportSpawnChild
17281744
var filter: String?
17291745
var args = [String]()
17301746
var i = 0
@@ -1794,7 +1810,7 @@ public func runAllTestsAsync() async {
17941810
if _isChildProcess {
17951811
await _childProcessAsync()
17961812
} else {
1797-
var runTestsInProcess: Bool = false
1813+
var runTestsInProcess: Bool = !platformSupportSpawnChild
17981814
var filter: String?
17991815
var args = [String]()
18001816
var i = 0

0 commit comments

Comments
 (0)