nRF Connect with Zephyr Testing Framework: Mocking central role connection to test BLE peripheral UART

Hello!

I am trying to develop tests with Zephyr Ztest framework to determine proper code coverage. Part of my functions invoke BLE NUS send and receive. For this to work properly and verify BLE portion is correct, I'm trying to find ways to mock the central connection that the device would connect to.

Are there any example codes or methods that I could mock the central connection that the testing code would connect to? This is so that the mocked central role can do things like enable TX notifications so the nus_send would go through.

Thanks!

Parents
  • Hello,

    Sorry for the late response it was a holiday week here in Norway So we were very thinly staffed.

    I am not that familiar with your Zephyr Ztest framework you mentioned. So far what I understood while reading your query is that you want to check whether the NUS is working properly on  both end (central and peripheral) Please correct me if I am wrong or missing anything.

    For this you can look at central_UART sample or Peripheral_UART. Both of this sample can be tested by using nRF connect mobile Application.

    Kind Regards,

    Abhijith 

  • Hi Menon,

    Not exactly what I was thinking. Here's an example:

    advertising_configured = advertising_init();

    zassert_equal(advertising_configured, 0, "Advertising not configured properly");

    So for this we read the return value to determine advertising_init was successful, and can use a the BabbleSim simulator to verify bluetooth functionality is correct without needing a device.

    Now, when I try to check that say bt_nus_send is correct, I get the error return: -12 (-EINVAL)

    From what I have seen, it's because TX notifications aren't enabled (could be wrong about this interpretation), but to do that, you would normally have a central device handshake and enable. 

    I would like to see if it's possible to mock the central device within the same tests. 

Reply
  • Hi Menon,

    Not exactly what I was thinking. Here's an example:

    advertising_configured = advertising_init();

    zassert_equal(advertising_configured, 0, "Advertising not configured properly");

    So for this we read the return value to determine advertising_init was successful, and can use a the BabbleSim simulator to verify bluetooth functionality is correct without needing a device.

    Now, when I try to check that say bt_nus_send is correct, I get the error return: -12 (-EINVAL)

    From what I have seen, it's because TX notifications aren't enabled (could be wrong about this interpretation), but to do that, you would normally have a central device handshake and enable. 

    I would like to see if it's possible to mock the central device within the same tests. 

Children
No Data
Related