Abstracting the operating system for unit test

How do others unit test embedded software? It seems only natural to me to do it on a PC, rather than on target. But that means calling stubs instead of operating system functions like send/receive message, spawn/ kill task, start/expire timer, etc

Do you just use #defines? Or how do you handle this?

Reply to
Baron Samedi
Loading thread data ...

Unit testing is almost always done in isolation. There are exceptions of course, but they are just that, exceptions.

The goal of unit testing is to test each individual function to insure that it meets the requirements and design of the function. The function under test is called by unit test code with combinations of good and bad arguments. All subroutine calls from the function under test, including OS calls, are stubbed out so that the call itself can be tested (did it occur, do they occur in the correct order, did it pass the correct parameters, etc.) and the return value is carefully controlled to allow testing of any expected return values and their handling by the subsequent code in the function.

It is most common to do all of this on another machine such as a PC, at least initially, to prove the unit test is working correctly. Depending on the application it may also be necessary to execute the unit test on the target hardware. Execution on the target is typically only required in safety-critical applications, and is used as a secondary means of verifying that the code generated by the compiler is valid.

There are many arguments on whether target testing is useful or required, and if it is, whether it is then a hybridization of unit and integration testing. Regardless of individual opinions on this, target execution of unit test code is mandatory for some safety-critical certifications.

There are also special tools available for unit testing, including Cantata and LDRA, that support test scripting and test harness creation.

--
Scott
Validated Software Corp.
Reply to
Not Really Me

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.