aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2020-05-05 17:23:49 +0200
committerJakub Konka <kubkon@jakubkonka.com>2020-05-18 16:09:49 +0200
commitd43c08a3e517f29b3dcaf5aa7860ed185815a305 (patch)
tree9e7728c7f34c872f5ce032b131db6fcaa6077307 /test
parentfeade9ef0010b1b47d7216e786ed964d09612c2b (diff)
downloadzig-d43c08a3e517f29b3dcaf5aa7860ed185815a305.tar.gz
zig-d43c08a3e517f29b3dcaf5aa7860ed185815a305.zip
Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality in `libstd` needed to pass the `libstd` tests. As such, now by default tests targeting `wasm32-wasi` target are enabled in `test/tests.zig` module. However, they can be disabled by passing the `-Dskip-wasi=true` flag when invoking the `zig build test` command. When the flag is set to `false`, i.e., when WASI tests are included, `wasmtime` with `--dir=.` is used as the default testing command. Since the majority of `libstd` tests were relying on `fs.cwd()` call to get current working directory handle wrapped in `Dir` struct, in order to make the tests WASI-friendly, `fs.cwd()` call was replaced with `testing.getTestDir()` function which resolved to either `fs.cwd()` for non-WASI targets, or tries to fetch the preopen list from the WASI runtime and extract a preopen for '.' path. The summary of changes introduced by this commit: * implement `Dir.makeDir` and `Dir.openDir` targeting WASI * implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI * fix `os.close` and map errors in `unlinkat` * move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi` to `std.os` module * implement `lseek_{SET, CUR, END}` targeting WASI * implement `futimens` targeting WASI * implement `ftruncate` targeting WASI * implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI * make sure ANSI escape codes are _not_ used in stderr or stdout in WASI, as WASI always sanitizes stderr, and sanitizes stdout if fd is a TTY * fix specifying WASI rights when opening/creating files/dirs * tweak `AtomicFile` to be WASI-compatible * implement `os.renameatWasi` for WASI-compliant `os.renameat` function * implement sleep() targeting WASI * fix `process.getEnvMap` targeting WASI
Diffstat (limited to 'test')
-rw-r--r--test/tests.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/tests.zig b/test/tests.zig
index d5fdbd74cf..b538818634 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -52,6 +52,15 @@ const test_targets = blk: {
TestTarget{
.target = .{
+ .cpu_arch = .wasm32,
+ .os_tag = .wasi,
+ },
+ .link_libc = false,
+ .single_threaded = true,
+ },
+
+ TestTarget{
+ .target = .{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .none,
@@ -463,6 +472,7 @@ pub fn addPkgTests(
skip_single_threaded: bool,
skip_non_native: bool,
skip_libc: bool,
+ skip_wasi: bool,
is_wine_enabled: bool,
is_qemu_enabled: bool,
glibc_dir: ?[]const u8,
@@ -473,6 +483,15 @@ pub fn addPkgTests(
if (skip_non_native and !test_target.target.isNative())
continue;
+ if (skip_wasi) {
+ if (test_target.target.os_tag) |tag| {
+ if (tag == .wasi) {
+ warn("Skipping {} on wasm32-wasi.\n", .{root_src});
+ continue;
+ }
+ }
+ }
+
if (skip_libc and test_target.link_libc)
continue;
@@ -525,6 +544,7 @@ pub fn addPkgTests(
these_tests.overrideZigLibDir("lib");
these_tests.enable_wine = is_wine_enabled;
these_tests.enable_qemu = is_qemu_enabled;
+ these_tests.enable_wasmtime = !skip_wasi;
these_tests.glibc_multi_install_dir = glibc_dir;
step.dependOn(&these_tests.step);