Frage

Recently I've been reading into topic of test driven development and decided to give it a go with a sensor driver I need. Sensor uses SPI interface and I will implement this driver on STM32F415 processor with help of CubeMX for project generation. After generating project, I have access to HAL SPI functions such as this:

HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)

I would create a header file called 'sensor_hall.h', put this SPI function declaration in it and then generate a mock of this header using CMock.

My questions are, is this a valid approach? Should I introduce more abstraction to this? And how to deal with the first argument, pointer to SPI struct when mocking?

War es hilfreich?

Lösung

Your instincts are correct and you are proposing a valid approach. There is no need to add more abstraction into the mix here.

Assuming there is also a HAL_SPI_* function to obtain (a pointer to) a spi struct, you can use a mock-specific version of a spi struct that contains useful members for your mocks.

If the spi struct needs to be declared directly by the client code (your sensor driver), then I would just verify in the mocks that consistently the same pointer is passed in.

Lizenziert unter: CC-BY-SA mit Zuschreibung
scroll top