Initial reorg.
This is largely the same as #305, but updated for the current tree.
This commit is contained in:
20
crates/wasi-common/wasi-common-cbindgen/tests/array_args.rs
Normal file
20
crates/wasi-common/wasi-common-cbindgen/tests/array_args.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
extern crate wasi_common_cbindgen;
|
||||
|
||||
pub use wasi_common_cbindgen::wasi_common_cbindgen;
|
||||
|
||||
#[wasi_common_cbindgen]
|
||||
fn array_args(a: &mut [u8]) {
|
||||
a[0] = 1;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut expected: &mut [u8] = &mut [0, 0];
|
||||
array_args(&mut expected);
|
||||
|
||||
let given: &mut [u8] = &mut [0, 0];
|
||||
unsafe {
|
||||
wasi_common_array_args(given.as_mut_ptr(), given.len());
|
||||
}
|
||||
|
||||
assert_eq!(given, expected);
|
||||
}
|
||||
20
crates/wasi-common/wasi-common-cbindgen/tests/mut_args.rs
Normal file
20
crates/wasi-common/wasi-common-cbindgen/tests/mut_args.rs
Normal 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_common_mut_args(raw);
|
||||
Box::from_raw(raw)
|
||||
};
|
||||
assert_eq!(*given, *expected);
|
||||
}
|
||||
12
crates/wasi-common/wasi-common-cbindgen/tests/no_args.rs
Normal file
12
crates/wasi-common/wasi-common-cbindgen/tests/no_args.rs
Normal 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_common_no_args() }, no_args());
|
||||
}
|
||||
20
crates/wasi-common/wasi-common-cbindgen/tests/ref_args.rs
Normal file
20
crates/wasi-common/wasi-common-cbindgen/tests/ref_args.rs
Normal 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_common_ref_args(raw);
|
||||
Box::from_raw(raw);
|
||||
res
|
||||
};
|
||||
assert_eq!(given, expected);
|
||||
}
|
||||
9
crates/wasi-common/wasi-common-cbindgen/tests/test.rs
Normal file
9
crates/wasi-common/wasi-common-cbindgen/tests/test.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
#[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");
|
||||
t.pass("tests/array_args.rs");
|
||||
}
|
||||
12
crates/wasi-common/wasi-common-cbindgen/tests/val_args.rs
Normal file
12
crates/wasi-common/wasi-common-cbindgen/tests/val_args.rs
Normal 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_common_val_args(1, 2) }, val_args(1, 2));
|
||||
}
|
||||
Reference in New Issue
Block a user