Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/add benchmark calls to tests #129

Merged
merged 16 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use wasmer::Store;
pub fn wasm_module_compile(c: &mut Criterion) {
let mut group = c.benchmark_group("wasm_module_compile");

for wasm in vec![
for wasm in [
TestWasm::Empty,
TestWasm::Io,
TestWasm::Test,
Expand All @@ -31,7 +31,7 @@ pub fn wasm_module_compile(c: &mut Criterion) {
pub fn wasm_module_deserialize_from_file(c: &mut Criterion) {
let mut group = c.benchmark_group("wasm_module_deserialize_from_file");

for wasm in vec![
for wasm in [
TestWasm::Empty,
TestWasm::Io,
TestWasm::Test,
Expand All @@ -56,7 +56,7 @@ pub fn wasm_module_deserialize_from_file(c: &mut Criterion) {
pub fn wasm_module(c: &mut Criterion) {
let mut group = c.benchmark_group("wasm_module");

for wasm in vec![
for wasm in [
TestWasm::Empty,
TestWasm::Io,
TestWasm::Test,
Expand All @@ -76,7 +76,7 @@ pub fn wasm_module(c: &mut Criterion) {
pub fn wasm_instance(c: &mut Criterion) {
let mut group = c.benchmark_group("wasm_instance");

for wasm in vec![
for wasm in [
TestWasm::Empty,
TestWasm::Io,
TestWasm::Test,
Expand Down Expand Up @@ -213,7 +213,7 @@ pub fn test_process_string(c: &mut Criterion) {

let instance_with_store = TestWasm::Test.unmetered_instance();

for n in vec![0, 1, 1_000, 1_000_000] {
for n in [0, 1, 1_000, 1_000_000] {
group.throughput(Throughput::Bytes(n));
group.sample_size(10);
let input = test_common::StringType::from(".".repeat(n.try_into().unwrap()));
Expand Down
157 changes: 150 additions & 7 deletions test/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub mod tests {
&mut store.lock().as_store_mut(),
instance,
"ignore_args_process_string",
&StringType::from(String::new()),
StringType::from(String::new()),
)
.expect("ignore_args_process_string call");
assert_eq!(String::new(), String::from(result));
Expand All @@ -254,7 +254,7 @@ pub mod tests {
&mut store.lock().as_store_mut(),
instance,
"process_string",
&StringType::from(s.clone()),
StringType::from(s.clone()),
)
.expect("process string call");

Expand All @@ -267,15 +267,15 @@ pub mod tests {
fn process_string_test() {
// use a "crazy" string that is much longer than a single wasm page to show that pagination
// and utf-8 are both working OK
let starter_string = "╰▐ ✖ 〜 ✖ ▐╯"
.repeat(usize::try_from(10_u32 * u32::try_from(std::u16::MAX).unwrap()).unwrap());
let starter_string =
"╰▐ ✖ 〜 ✖ ▐╯".repeat(usize::try_from(10_u32 * u32::from(u16::MAX)).unwrap());
let InstanceWithStore { store, instance } = TestWasm::Test.instance();
let result: StringType = guest::call(
&mut store.lock().as_store_mut(),
instance,
"process_string",
// This is by reference just to show that it can be done as borrowed or owned.
&StringType::from(starter_string.clone()),
StringType::from(starter_string.clone()),
)
.expect("process string call");

Expand Down Expand Up @@ -320,8 +320,8 @@ pub mod tests {
)
}
});
assert!(matches!(call_1.join(), Ok(_)));
assert!(matches!(call_2.join(), Ok(_)));
assert!(call_1.join().is_ok());
assert!(call_2.join().is_ok());
}

#[test]
Expand Down Expand Up @@ -535,4 +535,147 @@ pub mod tests {

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

Copy link
Member Author

@mattyg mattyg Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests below are copying the calls used in test/benches/bench.rs that were erroring.

#[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 _: test_common::BytesType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"bytes_serialize_n",
test_common::IntegerType::from(1_000_000),
)
.expect("failed deserialize");
}

#[test]
fn bytes_ret_n() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let _: test_common::BytesType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"bytes_ret_n",
test_common::IntegerType::from(1_000_000),
)
.expect("failed deserialize");
}

#[test]
fn string_serialize_n() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let _: test_common::StringType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"string_serialize_n",
test_common::IntegerType::from(1_000_000),
)
.expect("failed deserialize");
}

#[test]
fn string_ret_n() {
let InstanceWithStore { store, instance } = TestWasm::Io.instance();
let _: test_common::StringType = guest::call(
&mut store.lock().as_store_mut(),
instance.clone(),
"string_ret_n",
test_common::IntegerType::from(1_000_000),
)
.expect("failed deserialize");
}
}
Loading