test_tasks_snapshot.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. Test FreeRTOS support for core dump.
  3. */
  4. #include <stdio.h>
  5. #include "soc/cpu.h"
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task_snapshot.h"
  8. #include "unity.h"
  9. #include "sdkconfig.h"
  10. #define TEST_MAX_TASKS_NUM 32
  11. /* simple test to check that in normal conditions uxTaskGetSnapshotAll does not generate exception */
  12. TEST_CASE("Tasks snapshot", "[freertos]")
  13. {
  14. TaskSnapshot_t tasks[TEST_MAX_TASKS_NUM];
  15. UBaseType_t tcb_sz;
  16. #ifndef CONFIG_FREERTOS_UNICORE
  17. int other_core_id = xPortGetCoreID() == 0 ? 1 : 0;
  18. #endif
  19. // uxTaskGetSnapshotAll is supposed to be called when all tasks on both CPUs are
  20. // inactive and can not alter FreeRTOS internal tasks lists, e.g. from panic handler
  21. unsigned state = portENTER_CRITICAL_NESTED();
  22. #ifndef CONFIG_FREERTOS_UNICORE
  23. esp_cpu_stall(other_core_id);
  24. #endif
  25. UBaseType_t task_num = uxTaskGetSnapshotAll(tasks, TEST_MAX_TASKS_NUM, &tcb_sz);
  26. #ifndef CONFIG_FREERTOS_UNICORE
  27. esp_cpu_unstall(other_core_id);
  28. #endif
  29. portEXIT_CRITICAL_NESTED(state);
  30. printf("Dumped %d tasks. TCB size %d\n", task_num, tcb_sz);
  31. TEST_ASSERT_NOT_EQUAL(0, task_num);
  32. TEST_ASSERT_NOT_EQUAL(0, tcb_sz);
  33. }