This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52 unit testing

Dear,

is anyone of the Nordic customers here using unit testing in their nRF52 project and would be willing to share an example project/their setup? Would be awesome.

Many thanks, Josef

  • I have two kind of tests:

    1. Linux host connected to nRF52 using UART, controlling the nRF52 and running Bluez locally to connect over BLE. Everything implemented in Python and the unittest framework.

    2. Mac host connected to nRF52 using UART, controlling the nRF52 and running CoreBluetooth locally to connect over BLE. Testrunner implemented in Python and the unittest framework, CoreBluetooth stuff implemented in objective-c (but controlled by the Python code).

    The nRF52 in this case will be part of a bigger system, and in that system, it will be connected over UART. The protocol used for testing is the same as the one used in the real product. It is a custom simple messaging protocol.

  • Or you can try Segger RTT. If I understand RTT correctly one can use it for both reading user input and generating output. That also implies one needs to have a Jlink along the chain...

  • I am using CppUTest for writing tests to my code. To do this I have to mock some functions, especially the Softdevice calls. There is a parameter for this: SVCALL_AS_NORMAL_FUNCTION.

    If defined, it allows me to write my own mocks for the code using these calls. Right now some of my mocks look like this:

    // Mocks:
    extern "C"
    {
    
      uint32_t sd_ble_gatts_hvx(uint16_t conn_handle, ble_gatts_hvx_params_t const * const p_hvx_params)
      {
         return NRF_SUCCESS;
      }
    
    
    uint32_t sd_flash_page_erase(uint32_t page_number)
    {
       return NRF_SUCCESS;
    }
      uint32_t sd_flash_write(uint32_t *p_dst, uint32_t const *p_src, uint32_t size)
    {
       return NRF_SUCCESS;
    }
      uint32_t sd_evt_get(uint32_t *p_evt_id)
    {
       return NRF_SUCCESS;
    }
    
     uint32_t sd_ble_evt_get(uint8_t * 	p_dest,
    		   uint16_t * 	p_len )
    {
       return NRF_SUCCESS;
    }
    }
    
Related