test_freertos_mutex.c 812 B

12345678910111213141516171819202122232425
  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "freertos/semphr.h"
  4. #include "unity.h"
  5. #include "test_utils.h"
  6. /* If assertions aren't set to fail this code still crashes, but not with an abort... */
  7. #if CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER && CONFIG_FREERTOS_ASSERT_FAIL_ABORT
  8. static void mutex_release_task(void* arg)
  9. {
  10. SemaphoreHandle_t mutex = (SemaphoreHandle_t) arg;
  11. xSemaphoreGive(mutex);
  12. TEST_FAIL_MESSAGE("should not be reached");
  13. }
  14. TEST_CASE("mutex released not by owner causes an assert", "[freertos][reset=assert,SW_CPU_RESET]")
  15. {
  16. SemaphoreHandle_t mutex = xSemaphoreCreateMutex();
  17. xSemaphoreTake(mutex, portMAX_DELAY);
  18. xTaskCreate(&mutex_release_task, "mutex_release", 2048, mutex, UNITY_FREERTOS_PRIORITY + 1, NULL);
  19. vTaskDelay(1);
  20. }
  21. #endif