Skip to content

Fix unit tests part1 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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