Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Linux OS developers : do they unit test their code ?

If yes :

  • since this OS is coded in C, how do they manage to write effectively unit tests in this language ?
  • what are the "zones" in OS where unit testing is easier to write ? where is it harder ? where is it valuable ?
share|improve this question

closed as not a real question by gbjbaanb, Walter, ChrisF Aug 25 '12 at 16:03

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
There's no such thing as "Linux OS developers" - you mean kernel right? –  Mat Aug 25 '12 at 12:22
    
what's wrong with writing effectively whatever in C? –  shabunc Aug 25 '12 at 15:18
1  
@Mat : not only kernel. Shell, window manager... any part. But let's start with kernel, if you want ;-) –  MDE Aug 25 '12 at 15:53
2  
"Any part" is an immensely huge field, and most of it isn't specific to Linux at all. –  Mat Aug 25 '12 at 15:54
1  
@shabunc : nothing's wrong. If you can explain me how to write efficiently unit tests and inject mocks in c, for a shell of a kernel part for example, please tell me! –  MDE Aug 25 '12 at 15:59
show 2 more comments

1 Answer

up vote 6 down vote accepted

In general I would say that kernel code is not unit tested (I'm sure there are some exceptions). There are a few things that make kernel code difficult to unit test

  1. Kernel code generally interfaces with hardware.
  2. Kernel code does not link to the standard c library, it uses kernel specific headers etc.

You could decouple all of your functions that do not interface with the kernel API or hardware, but that has not been my experience of what actually happens.

I think most kernel code is tested using "integration tests" where command line apps are written to exercise the userspace interface to the kernel code.

Finally, C code itself can be unit tested. I write C code almost everyday and it gets unit tested.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.