Add sanity tests

This commit is contained in:
Jakub Konka
2019-05-14 13:27:46 +02:00
committed by Dan Gohman
parent 7f3c325cdf
commit 9ad16cc702
7 changed files with 79 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]
fn mut_args(a: &mut usize) {
*a = *a + 1
}
fn main() {
let mut expected = Box::new(2);
mut_args(expected.as_mut());
let given = unsafe {
let given = Box::new(2);
let raw = Box::into_raw(given);
__wasi_mut_args(raw);
Box::from_raw(raw)
};
assert_eq!(*given, *expected);
}

View File

@@ -0,0 +1,12 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]
fn no_args() -> u32 {
0
}
fn main() {
assert_eq!(unsafe { __wasi_no_args() }, no_args());
}

View File

@@ -0,0 +1,20 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]
fn ref_args(a: &usize) -> usize {
a + 1
}
fn main() {
let a = Box::new(2);
let expected = ref_args(a.as_ref());
let given = unsafe {
let raw = Box::into_raw(a);
let res = __wasi_ref_args(raw);
Box::from_raw(raw);
res
};
assert_eq!(given, expected);
}

View File

@@ -0,0 +1,8 @@
#[test]
fn tests() {
let t = trybuild::TestCases::new();
t.pass("tests/no_args.rs");
t.pass("tests/val_args.rs");
t.pass("tests/ref_args.rs");
t.pass("tests/mut_args.rs");
}

View File

@@ -0,0 +1,12 @@
extern crate wasi_common_cbindgen;
pub use wasi_common_cbindgen::wasi_common_cbindgen;
#[wasi_common_cbindgen]
fn val_args(a: usize, b: usize) -> usize {
a + b
}
fn main() {
assert_eq!(unsafe { __wasi_val_args(1, 2) }, val_args(1, 2));
}