# Unit tests: how to mock nrf_drv_gpiote.h ? (_WIN32 prevents nrf.h to include my platform bitfield header)

asked 2017-09-08 15:20:28 +0100

Hello,

I'm using Ceedling, Unity + CMock to implement unit tests but I'm running into issues when it comes to mocking nrf_drv_gpiote.h.

I'm trying to test a file, call it foo.c, which includes nrf_drv_gpiote.h, therefore in my test (test_foo.c) I'll include "mock_nrf_drv_gpiote.h".

The problem is that when Ceedling builds the test I have the following kind of errors :

components/drivers_nrf/hal/nrf_gpiote.h:71:32: error: 'GPIOTE_CONFIG_POLARITY_LoToHi' undeclared here (not in a function)

I understand where this error comes from but I don't know how to get rid of it. Basically, 'GPIOTE_CONFIG_POLARITY_LoToHi' is defined in nrf52840_bitfields.h, which is included by nrf.h if _WIN32 is not defined (see the code below), but _WIN32 is automatically defined when building on Windows. So how can I run my unit test on Windows if nrf.h doesn't allow me to include what's necessary to mock nrf_drv_gpiote.h ?

As a side note, I know that some people already requested this on this forum but if you could provide a minimalist Ceedling environment (or any other test framework) for unit tests it would be greatly appreciated !

Code in nrf.h that prevents from including nrf52840_bitfields.h :

    if defined(_WIN32)
/* Do not include nrf specific files when building for PC host */
#elif defined(__unix)
/* Do not include nrf specific files when building for PC host */
#elif defined(__APPLE__)
/* Do not include nrf specific files when building for PC host */
#else

/* Device selection for device includes. */
#if defined (NRF51)
#include "nrf51.h"
#include "nrf51_bitfields.h"
#include "nrf51_deprecated.h"
#elif defined (NRF52840_XXAA)
#include "nrf52840.h"
#include "nrf52840_bitfields.h"
#include "nrf51_to_nrf52840.h"
#include "nrf52_to_nrf52840.h"
#elif defined (NRF52832_XXAA)
#include "nrf52.h"
#include "nrf52_bitfields.h"
#include "nrf51_to_nrf52.h"
#include "nrf52_name_change.h"
#else
#error "Device must be defined. See nrf.h."
#endif /* NRF51, NRF52832_XXAA, NRF52840_XXAA */

#include "compiler_abstraction.h"

#endif /* _WIN32 || __unix || __APPLE__ */

edit retag close delete

Sort by » oldest newest most voted

answered 2017-09-12 09:06:43 +0100

Hi,

We have had this issue too and our current workaround is to make a new nrf.h file for the host and then include that in the unit tests. You will find the new file in the folder "mesh/test/include/device_wrappers" and it should also make it possible to mock peripherals through nrf_mesh_cmsis_mock.h.

more

Hi Martin, thank you for your answer. I couldn't find the folder "mesh/test/include/device_wrappers" nor the file nrf_mesh_cmsis_mock.h both in the SDK 13.0.0 and 14.0.0. Is it possible that those aren't distributed with the SDK but can be found on GitHub ?

( 2017-09-12 09:38:30 +0100 )editconvert to answer

It is in mesh SDK v 0.9.2.

( 2017-09-12 10:04:13 +0100 )editconvert to answer

Thank you, that was a pain but I finally managed to get that working. I had not understood that the files in device_wrappers were used in addition to the SDK ones, I've tried to replace the ones from the SDKs with those and it obviously didn't work. I also had to add two defines : HOST and SUPPRESS_INLINE_IMPLEMENTATION and to replace the nRF51 includes in the new nrf.h with the ones for nrf52.

( 2017-09-14 11:27:14 +0100 )editconvert to answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

[hide preview]

## Recent blog posts

• ### Difference between nRF52840 Engineering A and B reference designs

Posted 2018-01-15 12:27:08 by Martin Børs-Lind
• ### [For Hire] Expert development services of custom Hardware devices | IoT solutions | Mobile Apps

Posted 2018-01-15 09:08:42 by Ilya Surinsky
• ### Rust bindings to nrf52 series

Posted 2018-01-12 23:23:07 by Coleman McFarland
• ### Show And Tell: Poly - Building an RC Airplane The Hard Way

Posted 2018-01-05 01:17:57 by Daniel Veilleux
• ### Bluetooth on a desktop computer (Windows, Mac, Linux)

Posted 2018-01-04 17:56:57 by kbaud

## Recent questions

• ### System off draws more then 80µA

Posted 2018-01-22 22:15:19 by ruetten
• ### How to add driver to an SDK example, in Segger Embedded Studio?

Posted 2018-01-22 21:37:18 by Mark Leavitt
• ### Send more than 60 characters with each call to ble_nus_string_send

Posted 2018-01-22 21:20:21 by fkoran
• ### DFU succeeds but flash is erased

Posted 2018-01-22 20:42:54 by brett_anderson
• ### Uart example stops blinking after a while

Posted 2018-01-22 19:56:29 by oliverpoc

## Stats

Asked: 2017-09-08 15:20:28 +0100

Seen: 129 times

Last updated: sep. 14 '17