esp-idf/components/freertos/test/test_freertos_get_state.c
Darian Leung 883da858b0 freertos: Fix various build errors
This commit fixes various build errors in IDF (and tests) when compiling
with SMP FreeRTOS:

- Updated usage of xTaskGetIdleTaskHandle()
- Disable sysview tracing macros
- Update some task snapshot functions
- Disabled test_freertos_hooks.c test as vApplicationIdleHook() and
  vApplicationTickHook() are used.
2022-03-08 14:59:18 +08:00

81 lines
2.4 KiB
C

/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "unity.h"
#include "test_utils.h"
#define TSK_PRIORITY (UNITY_FREERTOS_PRIORITY + 1)
static TaskHandle_t blocked_task_handle;
static TaskHandle_t suspended_task_handle;
static SemaphoreHandle_t done_sem;
void test_task_get_state(void* arg)
{
//Current task should return eRunning
TEST_ASSERT(eTaskGetState(xTaskGetCurrentTaskHandle()) == eRunning);
//Idle task of current core should return eReady
#ifdef CONFIG_FREERTOS_SMP
TaskHandle_t *idle_handle_list = xTaskGetIdleTaskHandle();
TEST_ASSERT_EQUAL(eReady, eTaskGetState(idle_handle_list[xPortGetCoreID()]));
#else
TEST_ASSERT(eTaskGetState(xTaskGetIdleTaskHandle()) == eReady);
#endif
//Blocked Task should return eBlocked
TEST_ASSERT(eTaskGetState(blocked_task_handle) == eBlocked);
//Suspended Task should return eSuspended
TEST_ASSERT(eTaskGetState(suspended_task_handle) == eSuspended);
xSemaphoreGive(done_sem);
vTaskDelete(NULL);
}
void blocked_task(void *arg)
{
uint32_t notify_value;
while(1){
xTaskNotifyWait(0, 0xFFFFFFFF, &notify_value, portMAX_DELAY);
}
}
void suspended_task(void *arg)
{
while(1){
vTaskSuspend(NULL);
}
}
TEST_CASE("Test eTaskGetState", "[freertos]")
{
done_sem = xQueueCreateCountingSemaphore(portNUM_PROCESSORS, 0);
//Create blocked and suspended task
xTaskCreatePinnedToCore(blocked_task, "Blocked task", 1024, NULL, TSK_PRIORITY, &blocked_task_handle, tskNO_AFFINITY);
xTaskCreatePinnedToCore(suspended_task, "Suspended task", 1024, NULL, TSK_PRIORITY, &suspended_task_handle, tskNO_AFFINITY);
//Create testing task
for(int i = 0; i < portNUM_PROCESSORS; i++){
xTaskCreatePinnedToCore(test_task_get_state, "Test task", 1024, NULL, TSK_PRIORITY, NULL, i);
}
//Wait until done
for(int i = 0; i < portNUM_PROCESSORS; i++){
xSemaphoreTake(done_sem, portMAX_DELAY);
}
//Clean up blocked and suspended tasks
vTaskDelete(blocked_task_handle);
blocked_task_handle = NULL;
vTaskDelete(suspended_task_handle);
suspended_task_handle = NULL;
vSemaphoreDelete(done_sem);
vTaskDelay(10); //Give time for idle to actually delete the tasks
}