Skip to content

Commit f4fbad5

Browse files
Fix unit tests part1 (swiftlang#31)
* [WASM] Disable mmap test case for WASI OS due to lack of WASI API * [WASM] Disable simd test case for WASI OS simd api maybe stable in future https://github.com/WebAssembly/simd * [WASM] Fix to build pthread pollyfill only when wasi sdk * [WASM] Implement parsing command line arguments * [WASM] Run StdlibUnittest in process instead of child proc
1 parent 119a61b commit f4fbad5

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,12 @@ public func runAllTests() {
14491449
if _isChildProcess {
14501450
_childProcess()
14511451
} else {
1452+
#if os(WASI)
1453+
// WASI doesn't support child process
1454+
var runTestsInProcess: Bool = true
1455+
#else
14521456
var runTestsInProcess: Bool = false
1457+
#endif
14531458
var filter: String?
14541459
var args = [String]()
14551460
var i = 0

stdlib/public/WASI/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_swift_target_library(swiftWasiPthread STATIC IS_STDLIB
22
Pthread.cpp
3+
TARGET_SDKS WASI
34
INSTALL_IN_COMPONENT stdlib)

stdlib/public/stubs/CommandLine.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,42 @@ char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {
206206

207207
return outBuf;
208208
}
209+
#elif defined(__wasi__)
210+
#include <wasi/api.h>
211+
#include <wasi/libc.h>
212+
#include <stdlib.h>
213+
214+
SWIFT_RUNTIME_STDLIB_API
215+
char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {
216+
assert(outArgLen != nullptr);
217+
218+
if (_swift_stdlib_ProcessOverrideUnsafeArgv) {
219+
*outArgLen = _swift_stdlib_ProcessOverrideUnsafeArgc;
220+
return _swift_stdlib_ProcessOverrideUnsafeArgv;
221+
}
222+
223+
__wasi_errno_t err;
224+
225+
size_t argv_buf_size;
226+
size_t argc;
227+
err = __wasi_args_sizes_get(&argc, &argv_buf_size);
228+
if (err != __WASI_ERRNO_SUCCESS) return nullptr;
229+
230+
size_t num_ptrs = argc + 1;
231+
char *argv_buf = (char *)malloc(argv_buf_size);
232+
char **argv = (char **)calloc(num_ptrs, sizeof(char *));
233+
234+
err = __wasi_args_get((uint8_t **)argv, (uint8_t *)argv_buf);
235+
if (err != __WASI_ERRNO_SUCCESS) {
236+
free(argv_buf);
237+
free(argv);
238+
return nullptr;
239+
}
240+
241+
*outArgLen = static_cast<int>(argc);
242+
243+
return argv;
244+
}
209245
#else // Add your favorite OS's command line arg grabber here.
210246
SWIFT_RUNTIME_STDLIB_API
211247
char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {

test/stdlib/mmap.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-run-simple-swift %t
22
// REQUIRES: executable_test
33
// UNSUPPORTED: OS=windows-msvc
4+
// UNSUPPORTED: OS=wasi
45

56
import StdlibUnittest
67
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)

test/stdlib/simd_diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift
22

33
// FIXME: No simd module on linux rdar://problem/20795411
4-
// XFAIL: linux, windows
4+
// XFAIL: linux, windows, wasm
55

66
import simd
77

0 commit comments

Comments
 (0)