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

Unit testing with Unity and SoftDevice

Hi,

I'm currently in the process of integrating unit testing into our firmware development process. I'm trying to execute on-target tests with the Unity test framework, using the Nordic-modified version provided in this post.

This has been working fine for modules which don't make calls to the softdevice, but now I'm attempting to write tests for low-level driver modules which interact directly with libraries in the SDK, all the functions return an error code telling me that the softdevice isn't enabled.

Naturally my first response was to attempt to enable the softdevice in the setUp() function called by the test harness, in the same way it's enabled in my production code:

void softdevice_init(void)
{
	ret_code_t err_code;

    nrf_clock_lf_cfg_t clock_lf_cfg =	{.source        = NRF_CLOCK_LF_SRC_RC,            \
                                    	.rc_ctiv       = 16,                                \
										.rc_temp_ctiv  = 2,                                \

										.xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}; // ignored for NRF_CLOCK_LF_SRC_RC

    NRF_LOG_DEBUG("Inside SoftDevice init\r\n");

    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);

    uint32_t ram_start = 0;
    err_code = softdevice_app_ram_start_get(&ram_start);
    APP_ERROR_CHECK(err_code);

    err_code = softdevice_enable(&ram_start);
	APP_ERROR_CHECK(err_code);

	err_code = softdevice_sys_evt_handler_set(system_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}

void setUp(void)
{
	result      = 0xffff;
	result_code = 0xffffffff;

	softdevice_init();
}

...but this just seems to make things worse, causing the entire test suite to fail due to an "unexpected reset reason", as seen in this UART output:

expected: 0x00000000
../../../../../unity_fw/app_test_runner.c:302:sam_hw_fs_init_SHOULD_return_success_ON_FIRST_CALL:FAIL:FAIL: unexpected_reset
Reset reason: 0x00000004

Do you have any advice on how the test environment can be modified to be softdevice compatible?

Thanks, Marcus

Parents Reply Children
No Data
Related