Skip to content
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

Kernel Unit Testing #3854

Open
JADarius opened this issue Feb 16, 2024 · 4 comments
Open

Kernel Unit Testing #3854

JADarius opened this issue Feb 16, 2024 · 4 comments

Comments

@JADarius
Copy link
Contributor

I am in the process of writing unit tests for the kernel, but the module I'm writing for is dependent on external crates (for example the tock_tbf crate). My idea is to create some fake dependencies in the tests module and use conditional compiling in the struct declaration. For example, to emulate tock_tbf::types::TbfHeader inside I would rewrite the definition of ProcessStandard like so:

    #[cfg(not(test))]
    header: tock_tbf::types::TbfHeader,

    #[cfg(test)]
    header: tests::TbfHeader,

then I would create the TbfHeader struct inside the tests module and write the functions to give me the desired outputs.

I am not sure if this is the best way of writing unit tests for Tock and I would really like some feedback about this.

@lschuermann
Copy link
Member

From today's call, where we talked about this issue. An alternative approach to this could be to use traits and generics for the "real" and "mock" implementations of the different subsystems respectively. A concern that was voiced is that this generic argument would then need to be carried throughout much of Tock's codebase. A benefit would be that we would have a shared explicit interface between both implementations, which may reduce the potential for mismatches to evolve between the two implementations.

If the fact that this generic argument would need to be carried through much of Tock's codebase is the primary concern, we may be able to alleviate that by assigning a default type to that generic.

@bradjc
Copy link
Contributor

bradjc commented Feb 16, 2024

I don't think we should make Tock code harder to read and harder to write for unit testing. That feels like the wrong-way-round. We want to build the best OS to run, not to test.

If we need a stub library, like the TBF headers, that seems like a cargo.toml issue. Can't we just compile the kernel crate with a different dependency? Even if that requires some extra scripts to accomplish, that seems fine, and overall a bunch less work than propagating a generic argument everywhere.

@bradjc
Copy link
Contributor

bradjc commented Feb 16, 2024

(If you would like to have some fun propagating generic types, you can help me remove dyn from capsules. It's fun, I promise!)

@JADarius
Copy link
Contributor Author

I have some experience with removing dyn (from #3431), so it might be interesting to try removing dyn from other capsules. Do you have any starting points from where I can start?

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

No branches or pull requests

3 participants