Add ability to run CLIF IR using clif-util run [-v] {file}*#872
Add ability to run CLIF IR using clif-util run [-v] {file}*#872abrown wants to merge 1 commit intobytecodealliance:masterfrom
clif-util run [-v] {file}*#872Conversation
bjorn3
left a comment
There was a problem hiding this comment.
+1000 This was on my own todo list :)
b1798da to
647f256
Compare
|
Interesting idea. I remember @sunfishcode was saying we should use SimpleJIT for testing the runtime behavior and correctness of Cranelift in the past; we just never got to it. I think doing it directly with clif-util makes sense. I've made a list of things that came to mind while reading this code, and could be addressed either in this PR or in subsequent ones. I'd be worried that testing only specific signatures could mean a lot of missing test coverage for calls to functions with other signatures; but then having to deal with the Rust ABI is a bit unfortunate. Having functions that return only booleans, means that we can use a helper function to test that a call works, but we stay in Cranelift jit territory (and if there are consistent errors within Cranelift, they couldn't be caught). Which might be good enough for a start.
This would be good to have in automation too, but we'd need to limit running the runtime tests to automation host architectures that are supported by Cranelift. And by not having much control over Travis CI, not sure we can run on e.g. ARM64 in the future. Worth nothing at least.
Also to be entirely useful, I wonder if this shouldn't run the function in another process, in case the called function causes a segfault / other kind of hard crash. Otherwise, this means the first function that crashes causes the rest of the functions to not run, which is unfortunate.
|
|
|
For your information, I have been discussing this approach with @abrown over IRC, and suggested to use a single and only signature for function calls as a feature. If you want to check the generated code for making a function call with a given ABI, this can already be done without the need for executing the code, with ordinary tests using So executing the code is just a matter of being able to call a single function. What I initially suggested was to have a I think the approach taken here goes in the right direction. So, even if it feels incomplete on many aspects, we should probably not block this work with too many wishes.
|
|
Yeah yeah, I wasn't suggesting to mandate all of this before merging. More thinking about the running in different processes part had me realize that it'd be nice to have this, in two modes: 1. for running the tests in CI where each test is run in its own process (to not crash the test process itself), 2. for debugging tests, we would probably prefer something as is right now, that is, a test (or collection of tests) running in the test process itself, so it's easier to run within gdb/rr etc. |
|
I'm all for I am interested in using SimpleJIT here but someone will have to help me out. I looked at it for a moment but how to use it was obscured by the module-level stuff--I really just needed |
|
The more I think about it, the more unclear it is that we can actually use SimpleJIT for this, especially considering how simple the code in the |
|
@sunfishcode rebased this on current master; should be ready to review. |
bnjbvr
left a comment
There was a problem hiding this comment.
Agreed having a first form of this would be quite useful actually. Some small suggestions here, let me know what you think about these, and then let's merge it. Thanks for doing this!
| fn iterate_files(files: Vec<String>) -> impl Iterator<Item = PathBuf> { | ||
| files | ||
| .into_iter() | ||
| .flat_map(WalkDir::new) |
There was a problem hiding this comment.
This is lovely. (Could require uniquing the names, if some path trees actually intersect.)
There was a problem hiding this comment.
To avoid running twice? Or we could just run things twice... 😄
|
@bnjbvr, I've resolved the issues above and pushed to https://github.com/abrown/cranelift/tree/clif-filetests-test-run so that we can merge as a part of #890. |
This PR allows users to execute CLIF functions from the command line by running
clif-util run [-v] {file}*. It will look for functions with a signature like() -> boolthat have arun:comment after them, compile them with the host machine'sTargetIsa, and succeed if the function returnstrue. If the function returnsfalsethis utility keeps track of the number of failures much likeclif-util test. I hoped to use this utility to verify that sequences of instructions (e.g. my SIMD changes) actually execute correctly on a host machine.