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

Simplify dynamic linking imports tests #818

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

jeffcharles
Copy link
Collaborator

Description of the change

Simplifies the test code for checking the imports that dynamically linked modules have. At the moment, we always import canonical_abi_realloc, memory, eval_bytecode, and invoke, so we don't need separate tests for dynamically linked modules that have named exports.

Why am I making this change?

I'm going to need to adjust how we check the imports to exclude eval_bytecode and reduce the number of expected imports for certain dynamically linked modules in an upcoming PR and wanted to refactor the test suite outside of that PR first.

Checklist

  • I've updated the relevant CHANGELOG files if necessary. Changes to javy-cli and javy-plugin do not require updating CHANGELOG files.
  • I've updated the relevant crate versions if necessary. Versioning policy for library crates
  • I've updated documentation including crate documentation if necessary.

@@ -432,63 +432,49 @@ impl Runner {
let module = Module::from_binary(self.linker.engine(), &self.wasm)?;
Copy link
Member

@saulecabrera saulecabrera Nov 6, 2024

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)

Comment on lines 435 to 475
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());
Copy link
Member

Choose a reason for hiding this comment

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

Could you replace the asserts with bail! or Err(anyhow::Error)? I get that we're asserting and that the runner is mostly used in tests, however, I'd like to ensure that errors are recoverable here so that failures can bubble up with as much as context as possible to the test invoking them.

Copy link
Member

@saulecabrera saulecabrera left a comment

Choose a reason for hiding this comment

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

Thanks!

@jeffcharles jeffcharles merged commit 4943399 into main Nov 6, 2024
7 checks passed
@jeffcharles jeffcharles deleted the jc.simplify-dylib-imports-tests branch November 6, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants