Skip to content

Commit

Permalink
Merge pull request #4448 from wasmerio/add-wasi-fyi-tests
Browse files Browse the repository at this point in the history
Add wasi-fyi tests and run them in CI
  • Loading branch information
syrusakbary authored Feb 23, 2024
2 parents be3ea4f + bbdc64e commit 7812d60
Show file tree
Hide file tree
Showing 137 changed files with 19,734 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ jobs:
run: |
make test-js
test_wasi_fyi:
name: Test wasi-fyi
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
targets: "wasm32-wasi"
- name: Install wasm-pack
run: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: make test-wasi-fyi
run: |
make test-wasi-fyi
# The no_std functionality doesn't work at the moment - no point in testing it.
# - name: make test-js-core
# run: |
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ test-wasi-unit:
test-wasi:
$(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --release --tests $(compiler_features) --locked -- wasi::wasitests

test-wasi-fyi: build-wasmer
cd tests/wasi-fyi; \
./test.sh

test-integration-cli: build-wasmer build-capi package-capi-headless package distribution
cp ./dist/wasmer.tar.gz ./link.tar.gz
rustup target add wasm32-wasi
Expand Down
1 change: 1 addition & 0 deletions tests/wasi-fyi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wasm
21 changes: 21 additions & 0 deletions tests/wasi-fyi/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Casper Beyer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions tests/wasi-fyi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# WebAssembly System Interface tests for libstd
9 changes: 9 additions & 0 deletions tests/wasi-fyi/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -ueo pipefail

for input in *.rs; do
output="$(basename $input .rs).wasm"

echo "Compiling $input"
rustc +nightly --target=wasm32-wasi -o "$output" "$input"
done
3 changes: 3 additions & 0 deletions tests/wasi-fyi/env_args-many.arg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
none
some
many
10 changes: 10 additions & 0 deletions tests/wasi-fyi/env_args-many.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::env;

fn main() {
let args = env::args().collect::<Vec<String>>();
assert_eq!(args.len(), 4);
assert_eq!(args[0], "env_args-many.wasm");
assert_eq!(args[1], "none");
assert_eq!(args[2], "some");
assert_eq!(args[3], "many");
}
Empty file.
7 changes: 7 additions & 0 deletions tests/wasi-fyi/env_args-none.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::env;

fn main() {
let args = env::args().collect::<Vec<String>>();
assert_eq!(args.len(), 1);
assert_eq!(args[0], "env_args-none.wasm");
}
1 change: 1 addition & 0 deletions tests/wasi-fyi/env_args-some.arg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some
8 changes: 8 additions & 0 deletions tests/wasi-fyi/env_args-some.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::env;

fn main() {
let args = env::args().collect::<Vec<String>>();
assert_eq!(args.len(), 2);
assert_eq!(args[0], "env_args-some.wasm");
assert_eq!(args[1], "some");
}
3 changes: 3 additions & 0 deletions tests/wasi-fyi/env_vars-many.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NONE=none
SOME=some
MANY=many
10 changes: 10 additions & 0 deletions tests/wasi-fyi/env_vars-many.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::collections::HashMap;
use std::env;

fn main() {
let vars = env::vars().collect::<HashMap<String, String>>();
assert_eq!(vars.len(), 3);
assert_eq!(vars["NONE"], "none".to_string());
assert_eq!(vars["SOME"], "some".to_string());
assert_eq!(vars["MANY"], "many".to_string());
}
Empty file.
6 changes: 6 additions & 0 deletions tests/wasi-fyi/env_vars-none.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use std::env;

fn main() {
let vars = env::vars().collect::<Vec<(String, String)>>();
assert_eq!(vars.len(), 0);
}
1 change: 1 addition & 0 deletions tests/wasi-fyi/env_vars-some.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SOME=some
7 changes: 7 additions & 0 deletions tests/wasi-fyi/env_vars-some.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::env;

fn main() {
let vars = env::vars().collect::<Vec<(String, String)>>();
assert_eq!(vars.len(), 1);
assert_eq!(vars[0], ("SOME".to_string(), "some".to_string()));
}
7 changes: 7 additions & 0 deletions tests/wasi-fyi/fs_create_dir-existing-directory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::fs;

fn main() {
assert!(
fs::create_dir("/fyi/fs_create_dir-existing-directory.dir/existing_directory").is_err()
);
}
5 changes: 5 additions & 0 deletions tests/wasi-fyi/fs_create_dir-new-directory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use std::fs;

fn main() {
assert!(fs::create_dir("/fyi/fs_create_dir-new-directory.dir/new_directory").is_ok());
}
9 changes: 9 additions & 0 deletions tests/wasi-fyi/fs_file_create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::fs;

fn main() {
assert!(fs::File::create("/fyi/fs_file_create.dir/new_file").is_ok());
assert!(fs::metadata("/fyi/fs_file_create.dir/new_file")
.unwrap()
.is_file());
assert!(fs::remove_file("/fyi/fs_file_create.dir/new_file").is_ok());
}
6 changes: 6 additions & 0 deletions tests/wasi-fyi/fs_metadata-directory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use std::fs;

fn main() {
let metadata = fs::metadata("/fyi/fs_metadata-directory.dir/directory").unwrap();
assert!(metadata.is_dir());
}
6 changes: 6 additions & 0 deletions tests/wasi-fyi/fs_metadata-file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use std::fs;

fn main() {
let metadata = fs::metadata("/fyi/fs_metadata-file.dir/file").unwrap();
assert!(metadata.is_file());
}
8 changes: 8 additions & 0 deletions tests/wasi-fyi/fs_rename-directory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::fs;

fn main() {
let old_path = "/fyi/fs_rename-directory.dir/old_directory";
let new_path = "/fyi/fs_rename-directory.dir/new_directory";

assert!(fs::rename(old_path, new_path).is_ok());
}
8 changes: 8 additions & 0 deletions tests/wasi-fyi/fs_rename-file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::fs;

fn main() {
let old_path = "/fyi/fs_rename-file.dir/old_file";
let new_path = "/fyi/fs_rename-file.dir/new_file";

assert!(fs::rename(old_path, new_path).is_ok());
}
6 changes: 6 additions & 0 deletions tests/wasi-fyi/io_stderr-beowulf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use std::io;
use std::io::Write;

fn main() {
assert!(io::stderr().write_all(include_bytes!("io_stderr-beowulf.stderr")).is_ok());
}
Loading

0 comments on commit 7812d60

Please sign in to comment.