Hello
I started my OS a two months ago with C, then the code started to look ugly and getting out my hand. I switched to C++ and i have used only classes to organize each module. Now every time add or edit something i start to suspect that the whole system will collapse at some point and i start to debug although there are no bugs.
I hear that unit tests are important to get confidence about the code and it's necessary for any professional code. Is that the case for OS dev and low level stuff ? if so can you guide me to some open source codes that implemented unit tests to their OS ?
thank you.
Should i write unit tests for my code ?
-
Craze Frog
- Member

- Posts: 368
- Joined: Sun Sep 23, 2007 4:52 am
Re: Should i write unit tests for my code ?
Yes that could be a good idea, at least for certain parts of the code. Especially if you have some data structure, such as linked list, tree or vector.
Simply make another program that uses this container in all ways possible, and constantly checks if it is behaving correctly.
For the simplest utility function that can help, see: http://www.cplusplus.com/reference/cassert/assert/
Simply make another program that uses this container in all ways possible, and constantly checks if it is behaving correctly.
For the simplest utility function that can help, see: http://www.cplusplus.com/reference/cassert/assert/
Re: Should i write unit tests for my code ?
The hard part now is to find out what to test for. This is nowhere near as easy as you think. Yes, we all know how a linked list should work, but what about other functionality? How do you test the physical memory allocator? It has a bug where it starts reusing already in-use memory when the well runs dry. Is your test going to find this?
In order to write unit tests, you first have to find out what the units are. So, what are the separate pieces that make up the kernel? Not every function is a unit. In order for your tests to be useful, they need to be black-box tests, so they must accept any implementation of the interface, regardless of the inner workings of the interface. In order for that to happen, you first need to know what the interface actually is.
In order to write unit tests, you first have to find out what the units are. So, what are the separate pieces that make up the kernel? Not every function is a unit. In order for your tests to be useful, they need to be black-box tests, so they must accept any implementation of the interface, regardless of the inner workings of the interface. In order for that to happen, you first need to know what the interface actually is.
Carpe diem!
Re: Should i write unit tests for my code ?
thank you both for your replays!
I guess i will try to do tests only for higher level modules and drivers.
I guess i will try to do tests only for higher level modules and drivers.
