Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Unit testing; what to do about protected components? #68

Open
WilsonGiese opened this issue Sep 28, 2016 · 5 comments
Open

Unit testing; what to do about protected components? #68

WilsonGiese opened this issue Sep 28, 2016 · 5 comments
Labels

Comments

@WilsonGiese
Copy link
Contributor

WilsonGiese commented Sep 28, 2016

I was just messing around a bit, trying to add a cursor back into the new VGA code on my fork, no issues running the code in QEMU, but definitely had issues trying to access VGA hardware registers in test code. I basically broke all VGA tests by causing SIGSEGVs (woo!).

Wondering what the options are for unit testing code that needs to work so close to metal...

In school we wrote components for PintOS, but all the testing was done by running executables in user space. This worked quite well, but its really system testing, not unit testing. Without writing the kernel code to be accommodating of unit testing (lots of traits? Passing around real & mock impls), I'm not seeing how to assert on some aspects of the kernel directly.

@steveklabnik
Copy link
Member

Yes, I think this is an open and interesting question. @withoutboats had a really interesting talk at RustConf about using more traits to enable testing.

One interesting possibility here: mock out some sort of pic crate.....

@WilsonGiese
Copy link
Contributor Author

Is the @withoutboats talk available online anywhere? Not able to find it anywhere :(

@withoutboats
Copy link

withoutboats commented Sep 28, 2016

@WilsonGiese I believe it will be on the internet soon, but it seems like you understand the idea:

(lots of traits? Passing around real & mock impls)

For any interface between modules that you want to be an isolation boundary, instead of taking the other type directly, take a trait-bound type parameter, and then define mock impls in your unit tests.

I don't know anything about OSdev or I'd post a little practical example (ps. excited to learn something about it at Rust Belt Rust 😉).

@WilsonGiese
Copy link
Contributor Author

For any interface between modules that you want to be an isolation boundary, instead of taking the other type directly, take a trait-bound type parameter, and then define mock impls in your unit tests.

Yeah, this is basically what I was thinking!

I don't know anything about OSdev

I'll probably play around a little and see what I can come up with, concept seems easy enough to test

I believe it will be on the internet soon

Awesome, looking forward to listening to your talk @withoutboats 👍

@steveklabnik
Copy link
Member

(ps. excited to learn something about it at Rust Belt Rust 😉).

🎊

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants