-
Notifications
You must be signed in to change notification settings - Fork 385
Allow suppressing unsupported FFI calls #1807
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
Comments
If there is a better way of going about this please let me know, otherwise I would be happy to tackle this issue as proposed. |
That would exit the binary, and no more tests would be run... how is that helpful? |
Is each test not a separate binary already? You can run |
No, all tests of a crate run within the same process on different threads. Rustc produces a single executable that is then run as a regular program by cargo. Only doctests are an exception in that they are each separately compiled and executed directly by rustdoc. |
|
I see now. Sorry for the misunderstanding -- that definitely changes things. The general idea here is to just fail the individual test gracefully, but exiting early and hiding the fact other tests were not run is not desirable. I'm clearly not super familiar with Miri/ |
Maybe we can raise a panic instead of an unknown FFI error. Then the regular panic handler will just mark the test as failed instead of stopping the world |
Yes.
Most FFI functions are @landaire |
@oli-obk that may work. The way we run tests in Azure Pipelines is to consume output from { "type": "suite", "event": "started", "test_count": 1 }
{ "type": "test", "event": "started", "name": "tests::panic_test" }
{ "type": "test", "name": "tests::panic_test", "event": "failed", "stdout": "thread 'tests::panic_test' panicked at 'yo', src/main.rs:7:9\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" }
{ "type": "suite", "event": "failed", "passed": 0, "failed": 1, "allowed_fail": 0, "ignored": 0, "measured": 0, "filtered_out": 0, "exec_time": 0.000117601 } We could then enlighten the tool that parses test output to ignore panic-related failures as a success when passed a special flag or something.
Miri has already provided value in finding multiple instances of UB in our unsafe code.
This is certainly possible but I'd like to go back to my original points:
Additionally, it's a rather large project split across many crates with inter-dependencies. A massive refactoring for Miri is possible but is not an ideal solution IMO. An alternative solution I hadn't thought of I guess is to run each test separately via parsing the output of |
Interesting, so you have a mix of code that needs FFI and code that doesn't? This may be naive, but I figured it would usually be the case that this would be somewhat separated so that tests are, to some extend, already grouped by whether they need FFI or not. It seems like that is not the case for you.
So, this seems like an experiment worth doing. The feature would be off-by-default so its docs could mention caveats (e.g. there might be code relying on certain code not panicking, and things can go very wrong there when enabling this option). Triggering a panic in Miri is pretty easy, you just call |
We're doing some work that at the core of the application relies on Windows syscalls or other FFI boundaries. So for simple data structures and pure rust functionality we can run them cleanly, but more complicated integration tests that need to cross the FFI boundary we of course fail when this happens. Unfortunately with abstraction it may not necessarily be obvious if the API needs to make an FFI call. Even for FFI wrappers we may still have unsafe pure Rust setup that contains bugs, so exercising those tests as far as possible is still desired.
This is unfortunately the only public finding: icedland/iced#168 I can outline a couple interesting patterns that I may write a future blog post about:
I understand it's still experimental but the stacked borrows work has been the majority of issues so far. Systems engineering can be hard 😅.
I will give it a go and report back here/in Zulip. I appreciate the feedback from everyone so far. |
Panicking at the point of an FFI call I think unfortunately introduces UB: --> C:\Users\lander\.rustup\toolchains\miri\lib\rustlib\src\rust\library\core\src\panicking.rs:42:6
|
42 | }
| ^ accessing a dead local variable
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: inside `core::panicking::panic` at C:\Users\lander\.rustup\toolchains\miri\lib\rustlib\src\rust\library\core\src\panicking.rs:42:6 Here's my patch: https://gist.github.com/landaire/d1351ba8cf2f5dd23db0d0c7dc553f77 |
Let's discuss on Zulip. |
In the project I'm working on we have many tests that we'd potentially like to run with Miri in our CI/CD. These tests may invoke syscalls or other unsupported FFI operations that we would like to suppress and treat as successful tests for a few reasons:
cfg(miri)
to ignore specific tests.I believe this could be handled with the introduction of a new
-Z
variable,-Zmiri-ignore-ffi-failure
, that would simply treat these failures as an early exit with status code 0. Here's the proposed change to Miri:Click to view diff
This would require changes to
rustc_middle
as well for a new macro,throw_unsup_foreign_function
, and a new UnsupportedOpInfo variant,UnsupportedOpInfo::UnsupportedForeignFunction(String)
.The text was updated successfully, but these errors were encountered: