-
Notifications
You must be signed in to change notification settings - Fork 116
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
Simplify dynamic linking imports tests #818
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use anyhow::{anyhow, bail, Result}; | ||
use anyhow::{bail, Result}; | ||
use std::error::Error; | ||
use std::fmt::{self, Display, Formatter}; | ||
use std::io::{self, Cursor, Write}; | ||
|
@@ -432,63 +432,49 @@ impl Runner { | |
let module = Module::from_binary(self.linker.engine(), &self.wasm)?; | ||
let instance_name = self.plugin.namespace(); | ||
|
||
let result = module.imports().filter(|i| { | ||
if i.module() == instance_name && i.name() == "canonical_abi_realloc" { | ||
let ty = i.ty(); | ||
let f = ty.unwrap_func(); | ||
return f.params().all(|p| p.is_i32()) | ||
&& f.params().len() == 4 | ||
&& f.results().len() == 1 | ||
&& f.results().all(|r| r.is_i32()); | ||
} | ||
|
||
if i.module() == instance_name && i.name() == "eval_bytecode" { | ||
let ty = i.ty(); | ||
let f = ty.unwrap_func(); | ||
return f.params().all(|p| p.is_i32()) | ||
&& f.params().len() == 2 | ||
&& f.results().len() == 0; | ||
} | ||
|
||
if i.module() == instance_name && i.name() == "memory" { | ||
let ty = i.ty(); | ||
return ty.memory().is_some(); | ||
} | ||
|
||
false | ||
}); | ||
|
||
let count = result.count(); | ||
if count == 3 { | ||
Ok(()) | ||
} else { | ||
Err(anyhow!("Unexpected number of imports: {}", count)) | ||
} | ||
} | ||
|
||
pub fn assert_known_named_function_imports(&self) -> Result<()> { | ||
self.assert_known_base_imports()?; | ||
|
||
let module = Module::from_binary(self.linker.engine(), &self.wasm)?; | ||
let instance_name = self.plugin.namespace(); | ||
let result = module.imports().filter(|i| { | ||
if i.module() == instance_name && i.name() == "invoke" { | ||
let ty = i.ty(); | ||
let f = ty.unwrap_func(); | ||
|
||
return f.params().len() == 4 | ||
&& f.params().all(|p| p.is_i32()) | ||
&& f.results().len() == 0; | ||
} | ||
let imports = module | ||
.imports() | ||
.filter(|i| i.module() == instance_name) | ||
.collect::<Vec<_>>(); | ||
assert_eq!(4, imports.len()); | ||
|
||
let realloc = imports | ||
.iter() | ||
.find(|i| i.name() == "canonical_abi_realloc") | ||
.expect("Should have canonical_abi_realloc import"); | ||
let ty = realloc.ty(); | ||
let f = ty.unwrap_func(); | ||
assert!(f.params().all(|p| p.is_i32())); | ||
assert_eq!(4, f.params().len()); | ||
assert!(f.results().all(|p| p.is_i32())); | ||
assert_eq!(1, f.results().len()); | ||
|
||
let memory = imports | ||
.iter() | ||
.find(|i| i.name() == "memory" && i.ty().memory().is_some()); | ||
assert!(memory.is_some(), "Should have memory import"); | ||
|
||
let eval_bytecode = imports | ||
.iter() | ||
.find(|i| i.name() == "eval_bytecode") | ||
.expect("Should have eval_bytecode import"); | ||
let ty = eval_bytecode.ty(); | ||
let f = ty.unwrap_func(); | ||
assert!(f.params().all(|p| p.is_i32())); | ||
assert_eq!(2, f.params().len()); | ||
assert_eq!(0, f.results().len()); | ||
|
||
let invoke = imports | ||
.iter() | ||
.find(|i| i.name() == "invoke") | ||
.expect("Should have eval_bytecode import"); | ||
let ty = invoke.ty(); | ||
let f = ty.unwrap_func(); | ||
assert!(f.params().all(|p| p.is_i32())); | ||
assert_eq!(4, f.params().len()); | ||
assert_eq!(0, f.results().len()); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you replace the |
||
false | ||
}); | ||
let count = result.count(); | ||
if count == 1 { | ||
Ok(()) | ||
} else { | ||
Err(anyhow!("Unexpected number of imports: {}", count)) | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn assert_producers(&self) -> Result<()> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a nit, given the description of the PR, could you rename this function reflect the intention? e.g.,
ensure_expected_imports
(or something along those lines)