Controlling the Clock

Time is usually a big deal in embedded systems. Time, a volatile input, makes testing a challenge. Waiting for timed events in tests makes the tests take too long, longer than they have to be. The bottom line is that the tests have to take over the clock.

Abstracting the clock is important too. Real-time operating systems often define nonstandard time functions, and this can lead to portability problems. If you want code that runs on more than one platform, abstract the clock. The abstraction provides a perfect place to insert your fake clock. In production, use a thin adapter to convert the embedded application’s time API to the underlying OS calls. You get a shot of testability with a portability chaser.

The test ...

Get Test Driven Development for Embedded C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.