views:

111

answers:

1

I am writing C code for an AVR chip. The code is heavy on interrupt serivce routines which wait on serial ports, ADCs and timers. The ISRs write to buffers which the main loop examines when it gets to them.

I design the buffers so that ISRs can update them while the main loop is reading them. I want to verify that this works. I have unit tests to validate basic operation, but I'm not clear on how to test what happens if an interrupt fires while the main loop is read a buffer.

My unit test are really basic--some code in a main() finction. I run the tests on my Linux box.

+2  A: 

Threads?

Launch a high-priority thread which calls your ISR at some rate similar to the real thing. Then in your main, do the buffer read over and over again in a loop. Validate that the buffer read is not corrupted.

(Maybe this is more of an integration test than a pure unit test.)

AShelly
I expect it can be a lot of work using threads to simulate interrupt timing. I wonder if this type of testing is common enough that a package exists that implements it.
iter