-
Notifications
You must be signed in to change notification settings - Fork 15
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
Testing #15
Comments
I was about to add an issue on this topic as well :)
Point 1 at the very least makes me wonder about "wasm intrinsics" such as the print or assert functions, and how to model them from Rust, maybe @brson already had thoughts here ? |
|
@kripken here's the validation errors https://gist.github.com/lqd/9a1bc7548b2841495ecb4b2a4e397cf8 it could just be some vs2015 shenanigans (like the linker removing your code...) getting the C api calls might take a bit more time |
Thanks, I see what's going wrong here, it's an interaction between the relooper and |
I imagine both wasm-specific intrinsics and emscripten runtime calls will require modifying the compiler in someway. For wasm intrinsics it may be appropriate to define them as rustc 'platform intrinsics'. I don't know exactly how they are defined but this PR is adding a bunch. In the short term I think it's best to hack around it and not try to solve the problem upstream. As an example of a hacky way to do it, mir2wasm could transform calls to the following into calls to an intrinsic:
That's the same as a typical rust intrinsic declaration, but it's got an attribute on it that tells mir2wasm to do its own magic. |
If these behave like C functions then in Rust we can probably declare them as regular "C" extern fns.
If this is a different entry point than normal compilation I suggest it be done by having mir2wasm interpret a custom attribute, like
Setting up the kind of testing we need here, where each test is a single Rust source file that is processed on some arbitrary way, will take some customization of Rust's test framework. The way I might set this up is to make a directory of test cases (not |
Yes, they behave exactly as C externs. |
Then maybe something like
so we'd just call it like |
@lqd that looks right to me. I'd expect you to write that code by hand in the Rust source, and mir2wasm to generate a C-ABI call to an external function, just like any other C call. It'll probably involve calling some binaryen function to declare an extern with that name, then using the normal function call path to call it. |
Seems like we could translate all externs like that into wasm imports, which is what external callable code is, basically. The only extra thing is that imports use a 2-level namespace, and for test printing, the module is And more generally, for importing other wasm modules, it would be nice to be able to specify for a rust extern which module it is from, then the translation to a wasm import is clear. Could that be annotated somehow in the rust source? |
@brson indeed, and I already have the "import, and call print" part working, I'll just need to look for the extern in the mir blocks |
Being able to run the interpreter directly after compiling would now be super useful, with |
Ok, adding that to the binaryen c api in WebAssembly/binaryen#601 |
@kripken oooh sorry I meant doing it manually in mir2wasm like I mentioned on IRC, launching binaryen-shell after the build. It'll however be helpful for testing for sure, so thank you :) |
No problem, I've been thinking about it since yesterday anyhow. My main concern was code size in libbinaryen, but I realized that we're going to need the interpreter in there anyhow for other reasons (planned optimizations). So there is really no downside, and it was just 10 minutes of work to add :) |
This change makes `cargo test` no longer fail, although it also doesn't test much that's useful. It includes updates so that packages build against the nightly Rust we are using. This also pulls over some changes from miri ot let the test harness find the version of Rust selected by `rustup`. Possibly useful for testing (Issue brson#15).
Run tests in binaryen interpreter, check output (#15)
@kripken any clear ideas yet on how to support imports? Will it support defining the wasm module also? Currently it seems like I need to add code manually to trans.rs. |
@axic yeah right now only the spectest's print works and is harcoded in trans. |
Still early here, but might be nice to add testing at some point.
One option is to check output
.wast
files for identity.Another is to also execute them, for example, testing that fibonacci(5) has the right output. This is actually not that hard, we need to
(import $print_i32 "spectest" "print" (param i32))
for printing ani32
, for example. Thespectest
module is a special module that is supported in wasm test runners (it won't be supported on the web, but could be polyfilled).call_import
to print values.start
method (BinaryenSetStart
), avoid(void)
function that is called when the module is loaded.binaryen-shell test.wast
will load the module and run the start method.The text was updated successfully, but these errors were encountered: