-
Notifications
You must be signed in to change notification settings - Fork 434
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
Add rust/.kunitconfig and document unit testing #935
base: rust
Are you sure you want to change the base?
Add rust/.kunitconfig and document unit testing #935
Conversation
Thanks for adding this. I've tested it here and it all looks good to me. Apart from possibly updating the title of the unit-testing page (as Miguel suggests), this is:
That being said, I do think the plan is ultimately to support running even rust-style unit tests under KUnit, where that makes sense, so this doc will hopefully need updating to support that at some point. Equally, as you note, it'd be nice for UML support to work again -- I suspect #881 is the right shorter-term solution for that, and the ideal fix will require some more serious work on the UML side so it doesn't do as many strange things. As an aside, I'll note here (since I'm unlikely to have the time to work on it more this year), that I'd been experimenting with writing KUnit tests with Rust directly: i.e., without going through either the rust doctest/unit test features or using a C helper (which is how the doctests stuff is implemented): sulix@a7fed23 |
Definitely, the plan is to run the Rust-unit-tests in KUnit.
Thanks a lot for giving it a go! It is actually great to hear :)
About the C macros/helpers, in some cases we are looking into calling the C macros directly rather than re-implementing what they do (e.g. For the API itself (i.e. from the perspective of the user), I think it would be ideal to provide something like Rust
I think a few of us can relate... :) |
f5ea626
to
f60d3c4
Compare
As always, thanks for reviewing my patches David, I added your reviewed-by :)
I also added a reference to the KUnit docs. |
Disclaimer: I have no idea what the UML incompatibility looks like atm (is it a compile time error? strange runtime errors?). You can do so by adding either of these lines to the
Sample error
(I wish the error message here was better, but it's probably better than a strange runtime crash, and it'll happen faster) |
On my machine, it shows up as rustc itself crashing (and, when that's fixed, a bunch of very strange relocation errors from the linker). So the kunit.py So I'm all in favour of adding CONFIG_UML=n to the .kunitconfig. That being said, I have just rebased #881 (and confirmed it still works) and so it may be equally possible to just merge that and make this work on UML anyway. |
Yeah: I agree that this is a judgement call. (Personally, I mostly wanted to experiment to see if it's possible.) A part of me does think that doing this in rust rather than generating C will be easier than debugging some of the build system requirements (especially for modules), but I suspect it's too early to tell for sure.
Yeah: I think that'd be a great idea. I do think there will be a need for a more direct set of bindings to various KUnit APIs if we want to be able to use some of the more advanced KUnit features like resources (which need access to the To what extent it makes sense to have a two or three layered set of bindings (unsafe, safe-but-relatively-"direct", more-idiomatic) is something we'll no doubt work out as we go. (And it's probably off-topic to go into it further on this PR, so I'll leave it for now. :-) ) Cheers, |
Add a .kunitconfig file with the required configuration options to allow to easily run the KUnit tests without adding them manually: $ ./tools/testing/kunit/kunit.py run --kunitconfig=rust \ --make_options LLVM=1 --arch=x86_64 Note that "CONFIG_UML" is set to "n" because UML is not working at the moment [1]. [1] Rust-for-Linux#881 Reviewed-by: David Gow <[email protected]> Signed-off-by: José Expósito <[email protected]>
Explain how to run unit tests and documentation tests. Note that the documentation uses "--arch=x86_64" to run KUnit tests because UML is not working at the moment [1]. [1] Rust-for-Linux#881 Reviewed-by: David Gow <[email protected]> Signed-off-by: José Expósito <[email protected]>
f60d3c4
to
81938fa
Compare
That's a very good idea, the error even suggest to use $ ./tools/testing/kunit/kunit.py run --kunitconfig=rust --make_options LLVM=1
[12:42:55] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig LLVM=1
ERROR:root:Not all Kconfig options selected in kunitconfig were in the generated .config.
This is probably due to unsatisfied dependencies.
Missing: # CONFIG_UML is not set
Note: many Kconfig options aren't available on UML. You can try running on a different architecture with something like "--arch=x86_64". Much better than a |
I think this needs an update/rebase regarding the recently merged https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/Documentation/rust/general-information.rst?id=be412baf72402bd732e250033e03ad159d060a30 I'd propose to send this to the RFL mailing list (instead of doing a PR here) as it seems the chance of handling (merging) changes is higher, there. I found the commit message of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=a66d733da8010c732979041cd602cfceab7f587b a quite nice description. Maybe some parts, at least the first introduction part, could somehow picked? |
All changes going to upstream Linux go through the mailing list. PRs here were used before we were upstream, and nowadays are used for e.g. early reviews or to share code someone is working on.
Yeah, that would be nice. I should have probably done it directly in that commit :) |
A proposal for this: https://lore.kernel.org/rust-for-linux/[email protected]/T/#u I tried to express your authorship with the Co-developed-by :) |
Hi everyone,
This series adds a
rust/.kunitconfig
file with the required configuration options to allow to easily run the KUnit tests without adding them manually using--kconfig_add
.A similar approach is used in other subsystems, like HID or DRM, to simplify running the tests.
I found information about the
rusttest
make target in the quick start guide, but, I wasn't able to find information about how to run the documentation tests, so I added a page explaining how to do it.Note that
--arch=x86_64
is mentioned in the documentation because UML is not working at the moment. Once #881 is merged, the flag can be dropped from the documentation.cc @sulix