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!

  • 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. 

  • Hello! Just checking further to see if there's a solution for this

  • Hello,

    Sorry for the long response time. I was out of the office for the last few days.
    What you mentioned about the BLE is true i.e notifications on BLE needs to be enabled. Peripheral can only access if the central enables the notification. But I think the issue here is because of the platforms( Ztest and Babblesim simulator) . I am completely unaware of this platform. So I have asked this internally if anyone has tried this under BLE. I will get back to you if I get a proper response.

    Kind Regards,

    Abhijith

  • Hello,

    Sorry we don't have an official support for Babblesim under nRF connect SDK. The babblesim simulator is just to simulate the PHY and thus run the Bluetooth activity between multiple devices. For this you can try the bsim samples under zephyr. See the samples here.

    Kind Regards,

    Abhijith

Related