Download Embedded Unit Testing Framework

Transcript
do not run infinitely during test. This example already has a loop method, so this is not
needed here. To be able to run methods and do assertions from the test file, a header-file
is needed, this file is shown in Listing 3.14. In the header-file, variables are defined as
extern and methods are declared so the unit tests can access these.
2
#ifndef CLOCK_H
#define CLOCK_H
4
#include <stdbool.h>
6
extern uint32_t hours;
extern uint32_t minutes;
extern bool oldBoost;
8
10
12
void
void
void
void
GPIO_ODD_IRQHandler(void);
GPIO_EVEN_IRQHandler(void);
RTC_IRQHandler(void);
clockLoop(void);
14
16
18
#ifdef TEST
void app_main(void);
#else
int main(void);
#endif
20
#endif /* CLOCK_H */
Listing 3.14: Header-file for Example Test
The mock modules are used to verify that correct calls are done, and to inject necessary
return values. Mock modules are used for the peripheral APIs and the VDDcheck driver.
The test covers all of the code in this example, no dependencies in other drivers and
peripheral APIs are tested since mock modules are used instead. The clock example has
also some logic that is tested by unit tests. This include that time is set correct. Being
able to test all units and methods in the example should verify that the example works
as intended in the tests. That it works together with other software components and
hardware must be tested with software integration tests and integration testing.
Testing of NAND flash example
The last example that was tested using mock modules was the NAND flash example, which
is used to perform commands for reading and writing to the NAND flash memory on the
microcontroller. The commands are given to the development board and microcontroller
by writing commands over a serial interface. The examples demonstrate features in the
NAND flash driver. The example was difficult to test because of many definitions that
need to be changed for testing.
To be able to run this example on the host computer it was necessary to generate mock
modules for the NAND flash driver and the driver for the serial interface. It uses some
of the mock modules of API in emlib. In addition we could have created mock modules
for features that are used in the standard libraries of C. If verification of parameters
to printf(...) and putchar(char) is not important, stub functions can be use
instead.
38