Skip to content

Commit

Permalink
Test/add benchmark calls to tests (#129)
Browse files Browse the repository at this point in the history
* test: create tests for wasm calls that are called by benchmarks

* test: more tests for wasm calls that are called by benchmarks

* chore: fmt + clippy

* chore: fmt

* chore: expect -> assert is_ok()

* chore: clippy

* chore: meaningless empty features

* chore: make internal-only types & crates private

* chore: make scripts executable

* chore: fmt

* fix: high-level scripts run from root directory

* chore: rename file

* chore: make internal fns private

* chore: remove dead code
  • Loading branch information
mattyg authored Dec 16, 2024
1 parent 3b0b4f3 commit f25fdbc
Showing 1 changed file with 147 additions and 0 deletions.
147 changes: 147 additions & 0 deletions test/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,151 @@ pub mod tests {

assert_eq!(result, Vec::<u8>::from([1]));
}

#[test]
fn string_input_ignored_empty_ret() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let input = test_common::StringType::from(".".repeat(1_000_000.try_into().unwrap()));
let result: test_common::StringType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"string_input_ignored_empty_ret",
&input,
)
.unwrap();
let result_string: String = result.into();

assert_eq!(result_string, "".to_string());
}

#[test]
fn string_input_args_empty_ret() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let input = test_common::StringType::from(".".repeat(1_000_000.try_into().unwrap()));
let result: test_common::StringType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"string_input_args_empty_ret",
&input,
)
.unwrap();
let result_string: String = result.into();

assert_eq!(result_string, "".to_string());
}

#[test]
fn string_input_args_echo_ret() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let input_string: String = ".".repeat(1_000_000.try_into().unwrap());
let input = test_common::StringType::from(input_string.clone());
let result: test_common::StringType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"string_input_args_echo_ret",
&input,
)
.unwrap();
let result_string: String = result.into();

assert_eq!(result_string, input_string);
}

#[test]
fn bytes_input_ignored_empty_ret() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let input = test_common::BytesType::from(vec![0; 1_000_000.try_into().unwrap()]);
let result: test_common::BytesType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"bytes_input_ignored_empty_ret",
&input,
)
.unwrap();

assert_eq!(result.inner(), Vec::<u8>::from([]));
}

#[test]
fn bytes_input_args_empty_ret() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let input = test_common::BytesType::from(vec![0; 1_000_000.try_into().unwrap()]);
let result: test_common::BytesType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"bytes_input_args_empty_ret",
&input,
)
.unwrap();

assert_eq!(result.inner(), Vec::<u8>::from([]));
}

#[test]
fn bytes_input_args_echo_ret() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let input_bytes = vec![0; 1_000_000.try_into().unwrap()];
let input = test_common::BytesType::from(input_bytes.clone());
let result: test_common::BytesType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"bytes_input_args_echo_ret",
&input,
)
.unwrap();

assert_eq!(result.inner(), input_bytes);
}

#[test]
fn bytes_serialize_n() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let res: Result<test_common::BytesType, wasmer::RuntimeError> = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"bytes_serialize_n",
test_common::IntegerType::from(1_000_000),
);

assert!(res.is_ok());
}

#[test]
fn bytes_ret_n() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let res: Result<test_common::BytesType, wasmer::RuntimeError> = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"bytes_ret_n",
test_common::IntegerType::from(1_000_000),
);

assert!(res.is_ok());
}

#[test]
fn string_serialize_n() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let res: Result<test_common::StringType, wasmer::RuntimeError> = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"string_serialize_n",
test_common::IntegerType::from(1_000_000),
);

assert!(res.is_ok());
}

#[test]
fn string_ret_n() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let res: Result<test_common::StringType, wasmer::RuntimeError> = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"string_ret_n",
test_common::IntegerType::from(1_000_000),
);

assert!(res.is_ok());
}
}

0 comments on commit f25fdbc

Please sign in to comment.