Merge branch 'feature/freertos_check_mutex_owner' into 'master'

freertos: check that mutex is released by owner task

See merge request idf/esp-idf!4012
This commit is contained in:
Angus Gratton 2019-03-13 13:15:34 +08:00
commit 710bcbd447
6 changed files with 47 additions and 2 deletions

View file

@ -1305,6 +1305,12 @@ UT_001_43:
- ESP32_IDF
- UT_T1_1
UT_001_43:
<<: *unit_test_template
tags:
- ESP32_IDF
- UT_T1_1
UT_002_01:
<<: *unit_test_template
tags:

View file

@ -66,8 +66,7 @@ void run_tasks(const char *task1_description, void (* task1_func)(void *), const
for (i=0; i<2; i++) {
if((task1_func != NULL && i == 0) || (task2_func != NULL && i == 1)){
exit_sema[i] = xSemaphoreCreateMutex();
xSemaphoreTake(exit_sema[i], portMAX_DELAY);
exit_sema[i] = xSemaphoreCreateBinary();
}
}

View file

@ -419,4 +419,11 @@ menu "FreeRTOS"
abort the application. This option is also required for GDB backtraces and C++
exceptions to work correctly inside top-level task functions.
config FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER
bool "Check that mutex semaphore is given by owner task"
default y
help
If enabled, assert that when a mutex semaphore is given, the task giving the
semaphore is the task which is currently holding the mutex.
endmenu

View file

@ -314,5 +314,11 @@ extern void vPortCleanUpTCB ( void *pxTCB );
#endif /* def __ASSEMBLER__ */
#endif
#if CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER
#define configCHECK_MUTEX_GIVEN_BY_OWNER 1
#else
#define configCHECK_MUTEX_GIVEN_BY_OWNER 0
#endif
#endif /* FREERTOS_CONFIG_H */

View file

@ -724,6 +724,12 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
}
#endif
#if ( configUSE_MUTEXES == 1 && configCHECK_MUTEX_GIVEN_BY_OWNER == 1)
{
configASSERT(pxQueue->uxQueueType != queueQUEUE_IS_MUTEX || pxQueue->pxMutexHolder == NULL || xTaskGetCurrentTaskHandle() == pxQueue->pxMutexHolder);
}
#endif
/* This function relaxes the coding standard somewhat to allow return

View file

@ -0,0 +1,21 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "unity.h"
#include "esp_ipc.h"
#include "test_utils.h"
static void mutex_release_task(void* arg)
{
SemaphoreHandle_t mutex = (SemaphoreHandle_t) arg;
xSemaphoreGive(mutex);
TEST_FAIL_MESSAGE("should not be reached");
}
TEST_CASE("mutex released not by owner causes an assert", "[freertos][reset=abort,SW_CPU_RESET]")
{
SemaphoreHandle_t mutex = xSemaphoreCreateMutex();
xSemaphoreTake(mutex, portMAX_DELAY);
xTaskCreate(&mutex_release_task, "mutex_release", 2048, mutex, UNITY_FREERTOS_PRIORITY + 1, NULL);
vTaskDelay(1);
}