Unfortunatley I’m putting this unit test effort on hold for the time being, because I’m not really getting anywhere with writing test cases. It basically works to create a unit with a task from a unit test and it works fine 5 times out of 6. But occasionally I get crashes from FreeRTOS when creating or delete the unit with the task. I really know too little to really point the finger to the Linux port, but I suspect there’s time gaps where a pthread accesses FreeRTOS (like during task switch where I often get an failing assert) when it’s not supposed to.
For my project’s sake I need at least some kind of integration, unit or functional test running pretty soon. So I’m switching to creating an integration test (for now). I know it does not replace a unit test as it will mostly testing things that are supposed to work and will not find flaws in each unit due to missing or bad error handling.
To respond to RAc, I think I could mimic/replace a unit’s ISR’s from e.g. a UART pretty easily. Or I could have called a higher level function to mimic an incoming string from e.g. a UART. By simply redefining “private” as “public” just above the include of the header file to be tested, I could from the unit test access any private function in the unit under test.
When I get back to doing unit tests I would probably do what gedeonag suggest, to mock out the FreeRTOS entirely and rework my units with tasks a bit so I could make function calls to the task’s loop. Like:
void MyUnit::init()
{
rtos_res = xTaskCreate(my_unit_task_entry,
"my_unit_task",
2U * TASK_STACK_SIZE_DEFAULT,
this,
TASK_PRIO_DEFAULT,
NULL);
}
void MyUnit::my_unit_task_entry(void *param)
{
MyUnit* my_unit_task_p = static_cast(param);
my_unit_task_p->my_unit_task();
}
void MyUnit::my_unit_task()
{
for ( ; ; )
{
// Wait for a work package.
my_unit_wp_t wp;
BaseType_t rtos_res = xQueueReceive(m_work_queue, &wp, portMAX_DELAY);
my_unit_task_event(&wp);
}
}
void MyUnit::my_unit_task_event(const my_unit_wp_t* const wp)
{
// Handle work package
}
Then I could call the my_unit_ttask_event() with anything from a unit test. Well, it’s a plan