Test-Driving the Driver

Before we looked under the hood of MockIO, Flash_Write passed a simple test where the device is immediately ready. It is not likely that the device would be ready right away. According to its specification, this device has a typical write time of ten microseconds. When the driver runs in a real device, the StatusRegister may be read hundreds or thousands of times. The driver needs to loop, waiting for the operation to complete, though we can prove the looping logic with just a few reads:

tests/IO/FlashTest.cpp
 
TEST(Flash, WriteSucceeds_NotImmediatelyReady)
 
{
 
MockIO_Expect_Write(CommandRegister, ProgramCommand);
 
MockIO_Expect_Write(address, data);
 
MockIO_Expect_ReadThenReturn(StatusRegister, 0);
 
MockIO_Expect_ReadThenReturn(StatusRegister, ...

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.