Skip to content

Commit

Permalink
Fix unit tests part1 (#31)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
kateinoigakukun committed Jan 24, 2020
1 parent 6fd012e commit fc1f33c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,12 @@ public func runAllTests() {
if _isChildProcess {
_childProcess()
} else {
#if os(WASI)
// WASI doesn't support child process
var runTestsInProcess: Bool = true
#else
var runTestsInProcess: Bool = false
#endif
var filter: String?
var args = [String]()
var i = 0
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/WASI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_swift_target_library(swiftWasiPthread STATIC IS_STDLIB
Pthread.cpp
TARGET_SDKS WASI
INSTALL_IN_COMPONENT stdlib)
36 changes: 36 additions & 0 deletions stdlib/public/stubs/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,42 @@ char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {

return outBuf;
}
#elif defined(__wasi__)
#include <wasi/api.h>
#include <wasi/libc.h>
#include <stdlib.h>

SWIFT_RUNTIME_STDLIB_API
char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {
assert(outArgLen != nullptr);

if (_swift_stdlib_ProcessOverrideUnsafeArgv) {
*outArgLen = _swift_stdlib_ProcessOverrideUnsafeArgc;
return _swift_stdlib_ProcessOverrideUnsafeArgv;
}

__wasi_errno_t err;

size_t argv_buf_size;
size_t argc;
err = __wasi_args_sizes_get(&argc, &argv_buf_size);
if (err != __WASI_ERRNO_SUCCESS) return nullptr;

size_t num_ptrs = argc + 1;
char *argv_buf = (char *)malloc(argv_buf_size);
char **argv = (char **)calloc(num_ptrs, sizeof(char *));

err = __wasi_args_get((uint8_t **)argv, (uint8_t *)argv_buf);
if (err != __WASI_ERRNO_SUCCESS) {
free(argv_buf);
free(argv);
return nullptr;
}

*outArgLen = static_cast<int>(argc);

return argv;
}
#else // Add your favorite OS's command line arg grabber here.
SWIFT_RUNTIME_STDLIB_API
char ** _swift_stdlib_getUnsafeArgvArgc(int *outArgLen) {
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/mmap.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %target-run-simple-swift %t
// REQUIRES: executable_test
// UNSUPPORTED: OS=windows-msvc
// UNSUPPORTED: OS=wasi

import StdlibUnittest
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/simd_diagnostics.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %target-typecheck-verify-swift

// FIXME: No simd module on linux rdar://problem/20795411
// XFAIL: linux, windows
// XFAIL: linux, windows, wasm

import simd

Expand Down

0 comments on commit fc1f33c

Please sign in to comment.