-
Notifications
You must be signed in to change notification settings - Fork 3
Add framework to write detection tests #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
Conversation
Very cool that works great!
|
Yeah my reasoning was that testing is internal and when we (at some future point) maybe test complicated things, a user shouldn't think that those really are examples on how the crate works.
Sounds like a good idea! will look into this. Maybe i will print a warning or something like that.
I couldn't figure out how. I need some way to run the files while still providing them with the needed dependecies.
For renaming the tests themselves, sure i didn't put much thought into the names. |
This comment was marked as outdated.
This comment was marked as outdated.
Apparently the build script runs before my test runner runs, so i now check if rtsan is supported even if it's not enabled. Then i set I am not able to test this in an unsupported environment (i don't want to setup a windows VM). |
Ohh yeah sorry about that. I added a dependency (libtest-mimic) but didn't update the Cargo.lock. Should be fixed now. |
About the folder |
That doesn't seem to compile. It tells me i need to add a [[bin]] section to the Cargo.toml for every binary target. This would kind of defeat the purpose of the automatic test detection and collection. Ubunto fails because it doesn't have Rust 1.82, while i apparently upgraded to packages that require this. (That's what i gathered from the log) I will try to downgrade the cargo.lock a bit. |
We can also update the MSRV to 1.82, I would switch to Rust 2024 edition anyways at one point which requires a newer version. |
https://github.com/realtime-sanitizer/rtsan-standalone-rs/tree/stephan/detection-tests Here I made it work without without specifying a While playing a bit around with the code I think I prefer the following:
[workspace]
members = ["crates/rtsan-standalone-sys", "tests/detection-tests"]
Command::new("cargo")
.args(["run", "-p", "detection-tests", "--bin", &name])
.env("RTSAN_ENABLE", "1") For me this is a bit cleaner, how do you feel about those changes? |
If we switch to a workspace this isn't a problem anymore. I don't know why but apparently inside this inner crate Cargo chose a too new version of something and in the workspace it chose a correct version. The changes you suggested sound good. I pulled from your branch to here. I also added a toolchain.toml to be sure that we really stay compatible with our MSRV and don't increase it on accident. |
One thing to be aware of: If any of the tests fail to compile they will be shown as a success. The way i noticed this usually was because the tests ran way too fast. The best way to solve this is probably checking the output of the test. In a earlier version of this i did this with regex and i will probably introduce it again with a second PR to not make this one bigger than it already is. |
Why are we using
from the log output. So it uses 1.81 instead of beta. which is also why it fails. I will probably remove the toolchain file again. |
Yeah we just have to change the github action to use the same MSRV that is contained in the main Cargo.toml |
No i mean it makes sense to test with a new compiler. and when testing with a new compiler it also makes sense to update dependencies. That way you can be sure that it will continue to work when updating. |
Okay great. And the CI verifies now that the windows test is running and prints the warning. |
Could you just remove the .gitignore entry that I forgot? Then I will merge it! :) |
Every file in tests/detection-tests/src/bin will be built and run with the sanitizer enabled when doing cargo test. On platforms without rtsan support these tests will be skipped and a warning will be printed. Currently the only thing that is being checked is, that the process exits unsuccesfully.
I had a patch that also allowed specifying a regex at the beginning of the file that would be checked against the process output, but to make this PR smaller i removed it again.
I have moved the detection tests to not be a part of the workspace anymore, because it felt weird to have a workspace member just for testing. This does make it a bit reliant on the precise paths of the folders and it leads to slower compilation as the target dir isn't shared anymore. If you would like it the other way better i can easily change it back.Due to dependecy issues it is part of the workspace again.
I experimented a bit with Cargo script (which is currently nightly), but i couldn't find a way to make it work. I believe that in theory that could remove the need for a seperate crate.
I used libtest_mimic, it would maybe be possible to simplfy this by using datatest, which does the file detection automatically, but the code is pretty simple, so i thought this was better than an opaque macro, which datatest provides.
Would close #6