Skip to content

Commit e912f3e

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 ef3d946 commit e912f3e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

stdlib/private/StdlibUnittest/InterceptTraps.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
// No signals support on WASI yet, see https://github.com/WebAssembly/WASI/issues/166.
14-
#if !defined(__wasi__)
1513
#include <stdio.h>
1614
#include <signal.h>
1715
#include <string.h>
18-
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
16+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__wasi__)
1917
#include <unistd.h>
2018
#endif
2119
#if defined(_WIN32)
@@ -50,8 +48,6 @@ static void CrashCatcher(int Sig) {
5048
_exit(0);
5149
}
5250

53-
#endif // __wasi__
54-
5551
#if defined(_WIN32)
5652
static LONG WINAPI
5753
VectoredCrashHandler(PEXCEPTION_POINTERS ExceptionInfo) {
@@ -74,9 +70,6 @@ void installTrapInterceptor() {
7470
// Disable buffering on stdout so that everything is printed before crashing.
7571
setbuf(stdout, 0);
7672

77-
// No signals support on WASI yet, see https://github.com/WebAssembly/WASI/issues/166.
78-
#if !defined(__wasi__)
79-
8073
#if defined(_WIN32)
8174
_set_abort_behavior(0, _WRITE_ABORT_MSG);
8275
#endif
@@ -92,6 +85,5 @@ void installTrapInterceptor() {
9285
signal(SIGBUS, CrashCatcher);
9386
signal(SIGSYS, CrashCatcher);
9487
#endif
95-
}
9688

97-
#endif // !defined(__wasi__)
89+
}

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import Foundation
2222
import Darwin
2323
#elseif canImport(Glibc)
2424
import Glibc
25+
#elseif os(WASI)
26+
import WASILibc
2527
#elseif os(Windows)
2628
import CRT
2729
import WinSDK
@@ -35,6 +37,12 @@ import ObjectiveC
3537
import _Concurrency
3638
#endif
3739

40+
#if os(WASI)
41+
let platformSupportSpawnChild = false
42+
#else
43+
let platformSupportSpawnChild = true
44+
#endif
45+
3846
extension String {
3947
/// Returns the lines in `self`.
4048
public var _lines : [String] {
@@ -1724,7 +1732,7 @@ public func runAllTests() {
17241732
if _isChildProcess {
17251733
_childProcess()
17261734
} else {
1727-
var runTestsInProcess: Bool = false
1735+
var runTestsInProcess: Bool = !platformSupportSpawnChild
17281736
var filter: String?
17291737
var args = [String]()
17301738
var i = 0
@@ -1794,7 +1802,7 @@ public func runAllTestsAsync() async {
17941802
if _isChildProcess {
17951803
await _childProcessAsync()
17961804
} else {
1797-
var runTestsInProcess: Bool = false
1805+
var runTestsInProcess: Bool = !platformSupportSpawnChild
17981806
var filter: String?
17991807
var args = [String]()
18001808
var i = 0

0 commit comments

Comments
 (0)