vTaskEndScheduler for testing

Hi, I am trying to build a system-level testing framework to test my code.

I’m currently using https://cmocka.org/ to do unit testing. With help of GNU --wrap to mock the FreeRTOS API.

Now I’m at a stage to perform system testing, mocking hardware-specific API, and let the RTOS do the scheduling. One issue I encountered is I want to run multiple tests in groups. So I need to call vTaskStartScheduler and vTaskEndScheduler multiple times. But the vTaskEndScheduler does not free memory allocated by task. So I need a method to either signal every task if it need to deallocate its resources or like the post Thread End - FreeRTOS suggested to have a callback function AboutToDelete.

I felt the AboutToDelete callback implementation is nicer since it’s easier to leave out in production code. And I don’t need to check for signal in every iteration of the task loop. But can’t find any reference to AboutToDelete in the API. Could someone give a hint?

For last resort, I guess I could modify the source code task.c to add this hook. But I would rather not touch it (changing code of dependent) unless I have to.

I think you are running into a fundamental model issue. FreeRTOS tasks are NOT Processes and don’t track the information needed to be cleanly killed. My suggestion is that your mocked system needs to effectively reboot the FreeRTOS system between runs, and reinitialize the system, including the heap. This puts you testing system outside the system under test.

Which FreeRTOS port are you using? (architecture and compiler).

For testing (with mocked hardware), I’m using POSIX port FreeRTOS simulator for Posix/Linux. (Running in WSL2)

With GNU toolchain for both testing and production.