A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Add OOM tests for a bunch of async APIs (#12988)
Nick Fitzgeraldb7a0e9bfb90f
diff --git a/crates/fuzzing/tests/oom/func.rs b/crates/fuzzing/tests/oom/func.rsindex 5f5dcf3873..baf64bc933 100644--- a/crates/fuzzing/tests/oom/func.rs+++ b/crates/fuzzing/tests/oom/func.rs@@ -100,6 +100,38 @@ async fn func_call_async() -> Result<()> {.await}+#[tokio::test]+async fn typed_func_call_async() -> Result<()> {+ let module_bytes = {+ let mut config = Config::new();+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ Module::new(+ &engine,+ r#"(module (func (export "id") (param i32) (result i32) (local.get 0)))"#,+ )?+ .serialize()?+ };+ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ let module = unsafe { Module::deserialize(&engine, &module_bytes)? };+ let linker = Linker::<()>::new(&engine);+ let instance_pre = linker.instantiate_pre(&module)?;++ OomTest::new()+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let instance = instance_pre.instantiate_async(&mut store).await?;+ let id = instance.get_typed_func::<i32, i32>(&mut store, "id")?;+ let result = id.call_async(&mut store, 42).await?;+ assert_eq!(result, 42);+ Ok(())+ })+ .await+}+#[test]fn func_typed() -> Result<()> {let module_bytes = {diff --git a/crates/fuzzing/tests/oom/instance.rs b/crates/fuzzing/tests/oom/instance.rsindex 698612b55b..a82b64ab43 100644--- a/crates/fuzzing/tests/oom/instance.rs+++ b/crates/fuzzing/tests/oom/instance.rs@@ -67,6 +67,34 @@ fn instance_new() -> Result<()> {})}+#[tokio::test]+async fn instance_new_async() -> Result<()> {+ let module_bytes = {+ let mut config = Config::new();+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ Module::new(+ &engine,+ "(module (import \"\" \"f\" (func)) (func (export \"g\") (call 0)))",+ )?+ .serialize()?+ };+ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ let module = unsafe { Module::deserialize(&engine, &module_bytes)? };++ OomTest::new()+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let func = Func::try_wrap(&mut store, || {})?;+ let _instance = Instance::new_async(&mut store, &module, &[func.into()]).await?;+ Ok(())+ })+ .await+}+#[test]fn instance_get_export() -> Result<()> {let module_bytes = {diff --git a/crates/fuzzing/tests/oom/instance_pre.rs b/crates/fuzzing/tests/oom/instance_pre.rsindex 572c61dddb..34c2ac63c4 100644--- a/crates/fuzzing/tests/oom/instance_pre.rs+++ b/crates/fuzzing/tests/oom/instance_pre.rs@@ -48,3 +48,51 @@ fn instance_pre_instantiate() -> Result<()> {Ok(())})}++#[tokio::test]+async fn instance_pre_instantiate_async() -> Result<()> {+ let module_bytes = {+ let mut config = Config::new();+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ let module = Module::new(+ &engine,+ r#"+ (module+ (import "module" "func" (func (param i32) (result i32)))++ (memory (export "memory") 1)+ (data (i32.const 0) "a")++ (table (export "table") 1 funcref)+ (elem (i32.const 0) func 1)++ (func (export "func") (param i32) (result i32)+ (call 0 (local.get 0))+ )+ )+ "#,+ )?;+ module.serialize()?+ };++ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);++ let engine = Engine::new(&config)?;++ let mut linker = Linker::<()>::new(&engine);+ linker.func_wrap("module", "func", |x: i32| x * 2)?;++ let module = unsafe { Module::deserialize(&engine, &module_bytes)? };+ let instance_pre = linker.instantiate_pre(&module)?;++ OomTest::new()+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let _ = instance_pre.instantiate_async(&mut store).await?;+ Ok(())+ })+ .await+}diff --git a/crates/fuzzing/tests/oom/linker.rs b/crates/fuzzing/tests/oom/linker.rsindex 84c7182982..a8d527902e 100644--- a/crates/fuzzing/tests/oom/linker.rs+++ b/crates/fuzzing/tests/oom/linker.rs@@ -70,6 +70,53 @@ fn linker_instantiate_pre() -> Result<()> {})}+#[tokio::test]+async fn linker_instantiate_async() -> Result<()> {+ let module_bytes = {+ let mut config = Config::new();+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ let module = Module::new(+ &engine,+ r#"+ (module+ (import "module" "func" (func (param i32) (result i32)))++ (memory (export "memory") 1)+ (data (i32.const 0) "a")++ (table (export "table") 1 funcref)+ (elem (i32.const 0) func 1)++ (func (export "func") (param i32) (result i32)+ (call 0 (local.get 0))+ )+ )+ "#,+ )?;+ module.serialize()?+ };++ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);++ let engine = Engine::new(&config)?;++ let mut linker = Linker::<()>::new(&engine);+ linker.func_wrap("module", "func", |x: i32| x * 2)?;++ let module = unsafe { Module::deserialize(&engine, &module_bytes)? };++ OomTest::new()+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let _instance = linker.instantiate_async(&mut store, &module).await?;+ Ok(())+ })+ .await+}+#[test]fn linker_define() -> Result<()> {let mut config = Config::new();@@ -220,6 +267,34 @@ fn linker_define_name() -> Result<()> {})}+#[tokio::test]+async fn linker_module_async() -> Result<()> {+ let module_bytes = {+ let mut config = Config::new();+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ Module::new(+ &engine,+ r#"(module (func (export "f")) (memory (export "m") 1))"#,+ )?+ .serialize()?+ };+ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;+ let module = unsafe { Module::deserialize(&engine, &module_bytes)? };++ OomTest::new()+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let mut linker = Linker::<()>::new(&engine);+ linker.module_async(&mut store, "m", &module).await?;+ Ok(())+ })+ .await+}+// Note: linker_define_unknown_imports_as_traps and// linker_define_unknown_imports_as_default_values are not tested under OOM// because UnknownImportError::new uses infallible String allocationsdiff --git a/crates/fuzzing/tests/oom/memory.rs b/crates/fuzzing/tests/oom/memory.rsindex 5f5f884133..95361f52eb 100644--- a/crates/fuzzing/tests/oom/memory.rs+++ b/crates/fuzzing/tests/oom/memory.rs@@ -21,6 +21,23 @@ fn memory_new() -> Result<()> {})}+#[tokio::test]+async fn memory_new_async() -> Result<()> {+ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;++ OomTest::new()+ .allow_alloc_after_oom(true)+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let _memory = Memory::new_async(&mut store, MemoryType::new(1, None)).await?;+ Ok(())+ })+ .await+}+#[test]fn memory_grow() -> Result<()> {let mut config = Config::new();@@ -36,6 +53,24 @@ fn memory_grow() -> Result<()> {})}+#[tokio::test]+async fn memory_grow_async() -> Result<()> {+ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;++ OomTest::new()+ .allow_alloc_after_oom(true)+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let memory = Memory::new_async(&mut store, MemoryType::new(1, None)).await?;+ let _old_size = memory.grow_async(&mut store, 1).await?;+ Ok(())+ })+ .await+}+#[test]fn memory_ty() -> Result<()> {let mut config = Config::new();diff --git a/crates/fuzzing/tests/oom/table.rs b/crates/fuzzing/tests/oom/table.rsindex 5e783aeb95..b797dfe6e3 100644--- a/crates/fuzzing/tests/oom/table.rs+++ b/crates/fuzzing/tests/oom/table.rs@@ -22,6 +22,24 @@ fn table_new() -> Result<()> {})}+#[tokio::test]+async fn table_new_async() -> Result<()> {+ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;++ OomTest::new()+ .allow_alloc_after_oom(true)+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let ty = TableType::new(RefType::FUNCREF, 1, None);+ let _table = Table::new_async(&mut store, ty, Ref::Func(None)).await?;+ Ok(())+ })+ .await+}+#[test]fn table_grow() -> Result<()> {let mut config = Config::new();@@ -38,6 +56,25 @@ fn table_grow() -> Result<()> {})}+#[tokio::test]+async fn table_grow_async() -> Result<()> {+ let mut config = Config::new();+ config.enable_compiler(false);+ config.concurrency_support(false);+ let engine = Engine::new(&config)?;++ OomTest::new()+ .allow_alloc_after_oom(true)+ .test_async(|| async {+ let mut store = Store::try_new(&engine, ())?;+ let ty = TableType::new(RefType::FUNCREF, 1, None);+ let table = Table::new_async(&mut store, ty, Ref::Func(None)).await?;+ let _old_size = table.grow_async(&mut store, 4, Ref::Func(None)).await?;+ Ok(())+ })+ .await+}+#[test]fn table_set() -> Result<()> {let mut config = Config::new();