7

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 ?
mathieu
  • 197
  • 1
  • 6
  • 1
    There's no such thing as "Linux OS developers" - you mean kernel right? – Mat Aug 25 '12 at 12:22
  • 1
    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 ;-) – mathieu 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! – mathieu Aug 25 '12 at 15:59
  • @Mat : I understand. What's your suggestion to narrow this huge field ? Which part is more pertinent to start with ? – mathieu Aug 25 '12 at 16:04
  • @MDE: To be precise, the term Linux indicates the kernel. The rest of the system is mostly developed by GNU, and in fact the correct term for indicating the operating system would be GNU/Linux (i.e. the GNU operating system running on the Linux kernel). – Giorgio Aug 25 '12 at 16:06

1 Answers1

9

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.

ssgriffonuser
  • 361
  • 2
  • 4