diff --git a/components/freertos/app_startup.c b/components/freertos/app_startup.c index b9b60ff47b..7e4439d0b8 100644 --- a/components/freertos/app_startup.c +++ b/components/freertos/app_startup.c @@ -51,7 +51,7 @@ For now, AMP is not supported (i.e., running FreeRTOS on one core and a bare met CONFIG_FREERTOS_UNICORE and CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE should be identical. We add a check for this here. */ #if CONFIG_FREERTOS_UNICORE != CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE - #error "AMP not supported. FreeRTOS number of cores and system number of cores must be identical" +#error "AMP not supported. FreeRTOS number of cores and system number of cores must be identical" #endif // -------------------- Declarations ----------------------- diff --git a/components/freertos/heap_idf.c b/components/freertos/heap_idf.c index b6b8528943..57ff845f74 100644 --- a/components/freertos/heap_idf.c +++ b/components/freertos/heap_idf.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -30,21 +30,21 @@ #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE #if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) - #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 +#error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0 #endif #include "esp_heap_caps.h" #if !CONFIG_IDF_TARGET_LINUX - /* Memory util functions are not implemented in the Linux simulator */ - #include "esp_memory_utils.h" +/* Memory util functions are not implemented in the Linux simulator */ +#include "esp_memory_utils.h" #endif /* CONFIG_IDF_TARGET_LINUX */ #define portFREERTOS_HEAP_CAPS ( MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT ) /*-----------------------------------------------------------*/ -void * pvPortMalloc( size_t xWantedSize ) +void * pvPortMalloc(size_t xWantedSize) { void * pvReturn = NULL; @@ -52,57 +52,57 @@ void * pvPortMalloc( size_t xWantedSize ) * users need to allocate FreeRTOS objects into external RAM, they should * use the "static" equivalents of FreeRTOS API to create FreeRTOS objects * (e.g., queues). */ - pvReturn = heap_caps_malloc( xWantedSize, portFREERTOS_HEAP_CAPS ); + pvReturn = heap_caps_malloc(xWantedSize, portFREERTOS_HEAP_CAPS); return pvReturn; } /*-----------------------------------------------------------*/ -void vPortFree( void * pv ) +void vPortFree(void * pv) { - heap_caps_free( pv ); + heap_caps_free(pv); } /*-----------------------------------------------------------*/ -size_t xPortGetFreeHeapSize( void ) +size_t xPortGetFreeHeapSize(void) { - return heap_caps_get_free_size( portFREERTOS_HEAP_CAPS ); + return heap_caps_get_free_size(portFREERTOS_HEAP_CAPS); } /*-----------------------------------------------------------*/ -size_t xPortGetMinimumEverFreeHeapSize( void ) +size_t xPortGetMinimumEverFreeHeapSize(void) { - return heap_caps_get_minimum_free_size( portFREERTOS_HEAP_CAPS ); + return heap_caps_get_minimum_free_size(portFREERTOS_HEAP_CAPS); } /*-----------------------------------------------------------*/ -bool xPortCheckValidListMem( const void * ptr ) +bool xPortCheckValidListMem(const void * ptr) { - #if CONFIG_IDF_TARGET_LINUX - return true; - #else /* CONFIG_IDF_TARGET_LINUX */ - return esp_ptr_internal( ptr ) && esp_ptr_byte_accessible( ptr ); - #endif /* CONFIG_IDF_TARGET_LINUX */ +#if CONFIG_IDF_TARGET_LINUX + return true; +#else /* CONFIG_IDF_TARGET_LINUX */ + return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr); +#endif /* CONFIG_IDF_TARGET_LINUX */ } -bool xPortCheckValidTCBMem( const void * ptr ) +bool xPortCheckValidTCBMem(const void * ptr) { - #if CONFIG_IDF_TARGET_LINUX - return true; - #else /* CONFIG_IDF_TARGET_LINUX */ - return esp_ptr_internal( ptr ) && esp_ptr_byte_accessible( ptr ); - #endif /* CONFIG_IDF_TARGET_LINUX */ +#if CONFIG_IDF_TARGET_LINUX + return true; +#else /* CONFIG_IDF_TARGET_LINUX */ + return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr); +#endif /* CONFIG_IDF_TARGET_LINUX */ } -bool xPortcheckValidStackMem( const void * ptr ) +bool xPortcheckValidStackMem(const void * ptr) { - #if CONFIG_IDF_TARGET_LINUX - return true; - #else /* CONFIG_IDF_TARGET_LINUX */ - #ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY - return esp_ptr_byte_accessible( ptr ); - #else - return esp_ptr_internal( ptr ) && esp_ptr_byte_accessible( ptr ); - #endif - #endif /* CONFIG_IDF_TARGET_LINUX */ +#if CONFIG_IDF_TARGET_LINUX + return true; +#else /* CONFIG_IDF_TARGET_LINUX */ +#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY + return esp_ptr_byte_accessible(ptr); +#else + return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr); +#endif +#endif /* CONFIG_IDF_TARGET_LINUX */ } diff --git a/components/freertos/port_common.c b/components/freertos/port_common.c index d41a34fc75..3e322c9772 100644 --- a/components/freertos/port_common.c +++ b/components/freertos/port_common.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -27,7 +27,7 @@ We simply allocate the IDLE/Timer tasks memory from the FreeRTOS heap. #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, - uint32_t *pulIdleTaskStackSize ) + uint32_t *pulIdleTaskStackSize) { StaticTask_t *pxTCBBufferTemp; StackType_t *pxStackBufferTemp; @@ -37,17 +37,17 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, * If the stack grows down then allocate the stack then the TCB so the stack * does not grow into the TCB. Likewise if the stack grows up then allocate * the TCB then the stack. */ - #if (portSTACK_GROWTH > 0) +#if (portSTACK_GROWTH > 0) { pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t)); pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE); } - #else /* portSTACK_GROWTH */ +#else /* portSTACK_GROWTH */ { pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE); pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t)); } - #endif /* portSTACK_GROWTH */ +#endif /* portSTACK_GROWTH */ assert(pxTCBBufferTemp != NULL); assert(pxStackBufferTemp != NULL); @@ -59,7 +59,7 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, - uint32_t *pulTimerTaskStackSize ) + uint32_t *pulTimerTaskStackSize) { StaticTask_t *pxTCBBufferTemp; StackType_t *pxStackBufferTemp; @@ -69,17 +69,17 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, * If the stack grows down then allocate the stack then the TCB so the stack * does not grow into the TCB. Likewise if the stack grows up then allocate * the TCB then the stack. */ - #if (portSTACK_GROWTH > 0) +#if (portSTACK_GROWTH > 0) { pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t)); pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH); } - #else /* portSTACK_GROWTH */ +#else /* portSTACK_GROWTH */ { pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH); pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t)); } - #endif /* portSTACK_GROWTH */ +#endif /* portSTACK_GROWTH */ assert(pxTCBBufferTemp != NULL); assert(pxStackBufferTemp != NULL); diff --git a/components/freertos/port_systick.c b/components/freertos/port_systick.c index 20be1b8747..9297be35d1 100644 --- a/components/freertos/port_systick.c +++ b/components/freertos/port_systick.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,18 +10,18 @@ #include "FreeRTOS.h" #include "task.h" #if ( !CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) - /* Required for xTaskIncrementTickOtherCores() */ - #include "esp_private/freertos_idf_additions_priv.h" +/* Required for xTaskIncrementTickOtherCores() */ +#include "esp_private/freertos_idf_additions_priv.h" #endif /* ( !CONFIG_FREERTOS_SMP && ( configNUM_CORES > 1 ) ) */ #if CONFIG_FREERTOS_SYSTICK_USES_CCOUNT - #if CONFIG_FREERTOS_CORETIMER_0 - #define SYSTICK_INTR_ID (ETS_INTERNAL_TIMER0_INTR_SOURCE + ETS_INTERNAL_INTR_SOURCE_OFF) - #else /* CONFIG_FREERTOS_CORETIMER_1 */ - #define SYSTICK_INTR_ID (ETS_INTERNAL_TIMER1_INTR_SOURCE + ETS_INTERNAL_INTR_SOURCE_OFF) - #endif +#if CONFIG_FREERTOS_CORETIMER_0 +#define SYSTICK_INTR_ID (ETS_INTERNAL_TIMER0_INTR_SOURCE + ETS_INTERNAL_INTR_SOURCE_OFF) +#else /* CONFIG_FREERTOS_CORETIMER_1 */ +#define SYSTICK_INTR_ID (ETS_INTERNAL_TIMER1_INTR_SOURCE + ETS_INTERNAL_INTR_SOURCE_OFF) +#endif #else /* CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER */ - #define SYSTICK_INTR_ID (ETS_SYSTIMER_TARGET0_INTR_SOURCE) +#define SYSTICK_INTR_ID (ETS_SYSTIMER_TARGET0_INTR_SOURCE) #endif /* CONFIG_FREERTOS_SYSTICK_USES_CCOUNT */ BaseType_t xPortSysTickHandler(void); @@ -168,15 +168,15 @@ void SysTickIsrHandler(void *arg) */ void vPortSetupTimer(void) { - #if CONFIG_FREERTOS_SYSTICK_USES_CCOUNT - extern void _frxt_tick_timer_init(void); - extern void _xt_tick_divisor_init(void); - /* Init the tick divisor value */ - _xt_tick_divisor_init(); - _frxt_tick_timer_init(); - #else /* CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER */ - vSystimerSetup(); - #endif /* CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER */ +#if CONFIG_FREERTOS_SYSTICK_USES_CCOUNT + extern void _frxt_tick_timer_init(void); + extern void _xt_tick_divisor_init(void); + /* Init the tick divisor value */ + _xt_tick_divisor_init(); + _frxt_tick_timer_init(); +#else /* CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER */ + vSystimerSetup(); +#endif /* CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER */ } /** @@ -200,39 +200,39 @@ BaseType_t xPortSysTickHandler(void) // Call FreeRTOS Increment tick function BaseType_t xSwitchRequired; - #if CONFIG_FREERTOS_SMP - // Amazon SMP FreeRTOS requires that only core 0 calls xTaskIncrementTick() - #if ( configNUM_CORES > 1 ) - if (portGET_CORE_ID() == 0) { - xSwitchRequired = xTaskIncrementTick(); - } else { - xSwitchRequired = pdFALSE; - } - #else /* configNUM_CORES > 1 */ - xSwitchRequired = xTaskIncrementTick(); - #endif /* configNUM_CORES > 1 */ - #else /* !CONFIG_FREERTOS_SMP */ - #if ( configNUM_CORES > 1 ) - /* - Multi-core IDF FreeRTOS requires that... - - core 0 calls xTaskIncrementTick() - - core 1 calls xTaskIncrementTickOtherCores() - */ - if (xPortGetCoreID() == 0) { - xSwitchRequired = xTaskIncrementTick(); - } else { - xSwitchRequired = xTaskIncrementTickOtherCores(); - } - #else /* configNUM_CORES > 1 */ - /* - Vanilla (single core) FreeRTOS expects that xTaskIncrementTick() cannot be interrupted (i.e., no nested - interrupts). Thus we have to disable interrupts before calling it. - */ - UBaseType_t uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); - xSwitchRequired = xTaskIncrementTick(); - portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedInterruptStatus); - #endif /* configNUM_CORES > 1 */ - #endif /* !CONFIG_FREERTOS_SMP */ +#if CONFIG_FREERTOS_SMP + // Amazon SMP FreeRTOS requires that only core 0 calls xTaskIncrementTick() +#if ( configNUM_CORES > 1 ) + if (portGET_CORE_ID() == 0) { + xSwitchRequired = xTaskIncrementTick(); + } else { + xSwitchRequired = pdFALSE; + } +#else /* configNUM_CORES > 1 */ + xSwitchRequired = xTaskIncrementTick(); +#endif /* configNUM_CORES > 1 */ +#else /* !CONFIG_FREERTOS_SMP */ +#if ( configNUM_CORES > 1 ) + /* + Multi-core IDF FreeRTOS requires that... + - core 0 calls xTaskIncrementTick() + - core 1 calls xTaskIncrementTickOtherCores() + */ + if (xPortGetCoreID() == 0) { + xSwitchRequired = xTaskIncrementTick(); + } else { + xSwitchRequired = xTaskIncrementTickOtherCores(); + } +#else /* configNUM_CORES > 1 */ + /* + Vanilla (single core) FreeRTOS expects that xTaskIncrementTick() cannot be interrupted (i.e., no nested + interrupts). Thus we have to disable interrupts before calling it. + */ + UBaseType_t uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + xSwitchRequired = xTaskIncrementTick(); + portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedInterruptStatus); +#endif /* configNUM_CORES > 1 */ +#endif /* !CONFIG_FREERTOS_SMP */ // Check if yield is required if (xSwitchRequired != pdFALSE) { diff --git a/components/freertos/test_apps/freertos/kernel/event_groups/test_freertos_eventgroups.c b/components/freertos/test_apps/freertos/kernel/event_groups/test_freertos_eventgroups.c index 1deec459d0..99a136deca 100644 --- a/components/freertos/test_apps/freertos/kernel/event_groups/test_freertos_eventgroups.c +++ b/components/freertos/test_apps/freertos/kernel/event_groups/test_freertos_eventgroups.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -35,7 +35,7 @@ static void task_event_group_call_response(void *param) for (int i = 0; i < COUNT; i++) { /* Wait until the common "call" bit is set, starts off all tasks (clear on return) */ - TEST_ASSERT( xEventGroupWaitBits(eg, BIT_CALL(task_num), true, false, portMAX_DELAY) ); + TEST_ASSERT(xEventGroupWaitBits(eg, BIT_CALL(task_num), true, false, portMAX_DELAY)); /* Set our individual "response" bit */ xEventGroupSetBits(eg, BIT_RESPONSE(task_num)); @@ -78,7 +78,7 @@ TEST_CASE("FreeRTOS Event Groups", "[freertos]") /* Ensure all tasks have suspend themselves */ for (int c = 0; c < NUM_TASKS; c++) { - TEST_ASSERT( xSemaphoreTake(done_sem, 100 / portTICK_PERIOD_MS) ); + TEST_ASSERT(xSemaphoreTake(done_sem, 100 / portTICK_PERIOD_MS)); } for (int c = 0; c < NUM_TASKS; c++) { @@ -120,12 +120,12 @@ TEST_CASE("FreeRTOS Event Group Sync", "[freertos]") for (int c = 0; c < NUM_TASKS; c++) { printf("Waiting on %d (0x%08x)\n", c, BIT_RESPONSE(c)); - TEST_ASSERT( xEventGroupWaitBits(eg, BIT_RESPONSE(c), false, false, portMAX_DELAY) ); + TEST_ASSERT(xEventGroupWaitBits(eg, BIT_RESPONSE(c), false, false, portMAX_DELAY)); } /* Ensure all tasks cleaned up correctly */ for (int c = 0; c < NUM_TASKS; c++) { - TEST_ASSERT( xSemaphoreTake(done_sem, 100 / portTICK_PERIOD_MS) ); + TEST_ASSERT(xSemaphoreTake(done_sem, 100 / portTICK_PERIOD_MS)); } vSemaphoreDelete(done_sem); diff --git a/components/freertos/test_apps/freertos/kernel/freertos_test_utils.c b/components/freertos/test_apps/freertos/kernel/freertos_test_utils.c index 80ba37c788..cd356372c6 100644 --- a/components/freertos/test_apps/freertos/kernel/freertos_test_utils.c +++ b/components/freertos/test_apps/freertos/kernel/freertos_test_utils.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,63 +10,63 @@ #if ( configNUM_CORES > 1 ) - typedef struct { - const TestFunction_t pxTestCode; - void * const pvTestCodeArg; - const SemaphoreHandle_t xTaskDoneSem; - } TestArgs_t; +typedef struct { + const TestFunction_t pxTestCode; + void * const pvTestCodeArg; + const SemaphoreHandle_t xTaskDoneSem; +} TestArgs_t; - static void test_func_task( void * pvParameters ) - { - TestArgs_t * pxTestArgs = ( TestArgs_t * ) pvParameters; - /* Call the test function */ - pxTestArgs->pxTestCode( pxTestArgs->pvTestCodeArg ); - /* Indicate completion to the creation task and wait to be deleted. */ - xSemaphoreGive( pxTestArgs->xTaskDoneSem ); - vTaskSuspend( NULL ); +static void test_func_task(void * pvParameters) +{ + TestArgs_t * pxTestArgs = (TestArgs_t *) pvParameters; + /* Call the test function */ + pxTestArgs->pxTestCode(pxTestArgs->pvTestCodeArg); + /* Indicate completion to the creation task and wait to be deleted. */ + xSemaphoreGive(pxTestArgs->xTaskDoneSem); + vTaskSuspend(NULL); +} + +void vTestOnAllCores(TestFunction_t pxTestCode, void * pvTestCodeArg, uint32_t ulStackDepth, UBaseType_t uxPriority) +{ + SemaphoreHandle_t xTaskDoneSem = xSemaphoreCreateCounting(configNUM_CORES, 0); + TaskHandle_t xTaskHandles[ configNUM_CORES ]; + TestArgs_t xTestArgs = { + .pxTestCode = pxTestCode, + .pvTestCodeArg = pvTestCodeArg, + .xTaskDoneSem = xTaskDoneSem, + }; + + /* Create a separate task on each core to run the test function */ + for (BaseType_t xCoreID = 0; xCoreID < configNUM_CORES; xCoreID++) { +#if ( CONFIG_FREERTOS_SMP == 1 ) + xTaskCreateAffinitySet(test_func_task, + "task", + ulStackDepth, + (void *) &xTestArgs, + uxPriority, + (UBaseType_t)(1 << xCoreID), + &(xTaskHandles[ xCoreID ])); +#else + xTaskCreatePinnedToCore(test_func_task, + "task", + ulStackDepth, + (void *) &xTestArgs, + uxPriority, + &(xTaskHandles[ xCoreID ]), + xCoreID); +#endif } - void vTestOnAllCores( TestFunction_t pxTestCode, void * pvTestCodeArg, uint32_t ulStackDepth, UBaseType_t uxPriority ) - { - SemaphoreHandle_t xTaskDoneSem = xSemaphoreCreateCounting( configNUM_CORES, 0 ); - TaskHandle_t xTaskHandles[ configNUM_CORES ]; - TestArgs_t xTestArgs = { - .pxTestCode = pxTestCode, - .pvTestCodeArg = pvTestCodeArg, - .xTaskDoneSem = xTaskDoneSem, - }; - - /* Create a separate task on each core to run the test function */ - for( BaseType_t xCoreID = 0; xCoreID < configNUM_CORES; xCoreID++ ) { - #if ( CONFIG_FREERTOS_SMP == 1 ) - xTaskCreateAffinitySet( test_func_task, - "task", - ulStackDepth, - ( void * ) &xTestArgs, - uxPriority, - ( UBaseType_t ) ( 1 << xCoreID ), - &( xTaskHandles[ xCoreID ] ) ); - #else - xTaskCreatePinnedToCore( test_func_task, - "task", - ulStackDepth, - ( void * ) &xTestArgs, - uxPriority, - &( xTaskHandles[ xCoreID ] ), - xCoreID ); - #endif - } - - /* Wait for each tasks to complete test */ - for( BaseType_t xCoreID = 0; xCoreID < configNUM_CORES; xCoreID++ ) { - xSemaphoreTake( xTaskDoneSem, portMAX_DELAY ); - } - - /* Cleanup */ - for( BaseType_t xCoreID = 0; xCoreID < configNUM_CORES; xCoreID++ ) { - vTaskDelete( xTaskHandles[ xCoreID ] ); - } - vSemaphoreDelete( xTaskDoneSem ); + /* Wait for each tasks to complete test */ + for (BaseType_t xCoreID = 0; xCoreID < configNUM_CORES; xCoreID++) { + xSemaphoreTake(xTaskDoneSem, portMAX_DELAY); } + /* Cleanup */ + for (BaseType_t xCoreID = 0; xCoreID < configNUM_CORES; xCoreID++) { + vTaskDelete(xTaskHandles[ xCoreID ]); + } + vSemaphoreDelete(xTaskDoneSem); +} + #endif /* ( configNUM_CORES > 1 ) */ diff --git a/components/freertos/test_apps/freertos/kernel/freertos_test_utils.h b/components/freertos/test_apps/freertos/kernel/freertos_test_utils.h index fee7259d21..004d82752d 100644 --- a/components/freertos/test_apps/freertos/kernel/freertos_test_utils.h +++ b/components/freertos/test_apps/freertos/kernel/freertos_test_utils.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,24 +9,24 @@ #if ( configNUM_CORES > 1 ) - /** - * @brief Prototype for test function. - * - * A test function can be passed to vTestOnAllCores() which will run the test function from a task on each core. - */ - typedef void (* TestFunction_t)( void * ); +/** + * @brief Prototype for test function. + * + * A test function can be passed to vTestOnAllCores() which will run the test function from a task on each core. + */ +typedef void (* TestFunction_t)(void *); - /** - * @brief Run a test function on each core - * - * This function will internally create a task pinned to each core, where each task will call the provided test - * function. This function will block until all cores finish executing the test function. - * - * @param pxTestCode Test function - * @param pvTestCodeArg Argument provided to test function - * @param ulStackDepth Stack depth of the created tasks - * @param uxPriority Priority of the created tasks - */ - void vTestOnAllCores( TestFunction_t pxTestCode, void * pvTestCodeArg, uint32_t ulStackDepth, UBaseType_t uxPriority ); +/** + * @brief Run a test function on each core + * + * This function will internally create a task pinned to each core, where each task will call the provided test + * function. This function will block until all cores finish executing the test function. + * + * @param pxTestCode Test function + * @param pvTestCodeArg Argument provided to test function + * @param ulStackDepth Stack depth of the created tasks + * @param uxPriority Priority of the created tasks + */ +void vTestOnAllCores(TestFunction_t pxTestCode, void * pvTestCodeArg, uint32_t ulStackDepth, UBaseType_t uxPriority); #endif /* ( configNUM_CORES > 1 ) */ diff --git a/components/freertos/test_apps/freertos/kernel/queue/test_freertos_backported_functions.c b/components/freertos/test_apps/freertos/kernel/queue/test_freertos_backported_functions.c index 2ca77ad31e..d4644af582 100644 --- a/components/freertos/test_apps/freertos/kernel/queue/test_freertos_backported_functions.c +++ b/components/freertos/test_apps/freertos/kernel/queue/test_freertos_backported_functions.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -70,7 +70,7 @@ TEST_CASE("Test FreeRTOS backported timer functions", "[freertos]") TEST_ASSERT_UINT32_WITHIN(TICK_DELTA, tmr_ideal_exp, xTimerGetExpiryTime(tmr_handle)); //Test xTimerGetExpiryTime() - vTaskDelay(2*TMR_PERIOD_TICKS); //Delay until one shot timer has triggered + vTaskDelay(2 * TMR_PERIOD_TICKS); //Delay until one shot timer has triggered TEST_ASSERT_EQUAL(pdPASS, xTimerDelete(tmr_handle, portMAX_DELAY)); //Clean up } @@ -90,22 +90,22 @@ TEST_CASE("Test FreeRTOS backported timer functions", "[freertos]") #define DELAY_TICKS 2 static StaticQueue_t queue_buffer; //Queues, Semaphores, and Mutex use the same queue structure -static uint8_t queue_storage_area[(ITEM_SIZE*NO_OF_ITEMS)]; //Queue storage provided in separate buffer to queue struct +static uint8_t queue_storage_area[(ITEM_SIZE * NO_OF_ITEMS)]; //Queue storage provided in separate buffer to queue struct TEST_CASE("Test FreeRTOS backported Queue and Semphr functions", "[freertos]") { //Test static queue uint8_t queue_item_to_send[ITEM_SIZE]; uint8_t queue_item_received[ITEM_SIZE]; - for(int i = 0; i < ITEM_SIZE; i++){ + for (int i = 0; i < ITEM_SIZE; i++) { queue_item_to_send[i] = (0xF << i); } - QueueHandle_t handle = xQueueCreateStatic(NO_OF_ITEMS, ITEM_SIZE,(uint8_t*) &queue_storage_area, &queue_buffer); + QueueHandle_t handle = xQueueCreateStatic(NO_OF_ITEMS, ITEM_SIZE, (uint8_t*) &queue_storage_area, &queue_buffer); TEST_ASSERT_EQUAL(pdTRUE, xQueueSendToBack(handle, &queue_item_to_send, DELAY_TICKS)); vTaskDelay(1); TEST_ASSERT_EQUAL(pdTRUE, xQueueReceive(handle, queue_item_received, DELAY_TICKS)); vTaskDelay(1); - for(int i = 0; i < ITEM_SIZE; i++){ + for (int i = 0; i < ITEM_SIZE; i++) { TEST_ASSERT_EQUAL(queue_item_to_send[i], queue_item_received[i]); //Check received contents are correct } vQueueDelete(handle); //Technically not needed as deleting static queue/semphr doesn't clear static memory @@ -120,12 +120,12 @@ TEST_CASE("Test FreeRTOS backported Queue and Semphr functions", "[freertos]") //Test static counting semaphore and uxSemaphoreGetCount() handle = xSemaphoreCreateCountingStatic(NO_OF_ITEMS, 0, &queue_buffer); - for(int i = 0; i < NO_OF_ITEMS; i++){ + for (int i = 0; i < NO_OF_ITEMS; i++) { TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreGive(handle)); } vTaskDelay(1); TEST_ASSERT_EQUAL(NO_OF_ITEMS, uxSemaphoreGetCount(handle)); //Test uxSemaphoreGetCount() - for(int i = 0; i < NO_OF_ITEMS; i++){ + for (int i = 0; i < NO_OF_ITEMS; i++) { TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTake(handle, DELAY_TICKS)); } vTaskDelay(1); @@ -144,12 +144,12 @@ TEST_CASE("Test FreeRTOS backported Queue and Semphr functions", "[freertos]") //Test static mutex recursive handle = xSemaphoreCreateRecursiveMutexStatic(&queue_buffer); - for(int i = 0; i < NO_OF_ITEMS; i++){ + for (int i = 0; i < NO_OF_ITEMS; i++) { TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreTakeRecursive(handle, DELAY_TICKS)); } vTaskDelay(1); TEST_ASSERT_EQUAL_PTR((void *)xTaskGetCurrentTaskHandle(), xSemaphoreGetMutexHolder(handle)); //Current task should hold mutex - for(int i = 0; i < NO_OF_ITEMS; i++){ + for (int i = 0; i < NO_OF_ITEMS; i++) { TEST_ASSERT_EQUAL(pdTRUE, xSemaphoreGiveRecursive(handle)); } vTaskDelay(1); @@ -177,7 +177,7 @@ static void task(void *arg) TEST_CASE("Test FreeRTOS static task allocation", "[freertos]") { - for(int core = 0; core < portNUM_PROCESSORS; core++){ + for (int core = 0; core < portNUM_PROCESSORS; core++) { has_run[core] = false; //Clear has_run flag TaskHandle_t handle = xTaskCreateStaticPinnedToCore(task, "static task", STACK_SIZE, NULL, UNITY_FREERTOS_PRIORITY + 1, (StackType_t *)&task_stack, diff --git a/components/freertos/test_apps/freertos/kernel/queue/test_freertos_debug_functions.c b/components/freertos/test_apps/freertos/kernel/queue/test_freertos_debug_functions.c index 964c7bae49..e6ad5d72cd 100644 --- a/components/freertos/test_apps/freertos/kernel/queue/test_freertos_debug_functions.c +++ b/components/freertos/test_apps/freertos/kernel/queue/test_freertos_debug_functions.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -35,22 +35,22 @@ void test_queue_registry_task(void *arg) int core = xPortGetCoreID(); int offset = core * NO_OF_QUEUES_PER_CORE; //Create queues and accompanying queue names - for(int i = 0; i < NO_OF_QUEUES_PER_CORE; i++){ - handles[i + offset] = xQueueCreate(1,1); //Create queues + for (int i = 0; i < NO_OF_QUEUES_PER_CORE; i++) { + handles[i + offset] = xQueueCreate(1, 1); //Create queues names[i + offset] = calloc(QUEUE_NAME_MAX_LENGTH, sizeof(char)); sprintf(names[i + offset], "Queue%d%d", core, i); } xSemaphoreTake(start_sem[core], portMAX_DELAY); //Wait for start vQueueAddToRegistry() - for(int i = 0; i < NO_OF_QUEUES_PER_CORE; i++){ - vQueueAddToRegistry(handles[i + offset] , names[i + offset]); //Register queues to queue registry + for (int i = 0; i < NO_OF_QUEUES_PER_CORE; i++) { + vQueueAddToRegistry(handles[i + offset], names[i + offset]); //Register queues to queue registry } xSemaphoreGive(done_sem); //Signal that vQueueAddToRegistry() has completed vTaskDelay(1); xSemaphoreTake(start_sem[core], portMAX_DELAY); //Wait to start vQueueUnregisterQueue() - for(int i = 0; i < NO_OF_QUEUES_PER_CORE; i++){ + for (int i = 0; i < NO_OF_QUEUES_PER_CORE; i++) { vQueueDelete(handles[i + offset]); //Internally calls vQueueUnregisterQueue } xSemaphoreGive(done_sem); //Signal done @@ -62,44 +62,44 @@ TEST_CASE("Test FreeRTOS Queue Registry", "[freertos]") { //Create synchronization semaphores and tasks to test queue registry done_sem = xSemaphoreCreateCounting(portNUM_PROCESSORS, 0); - for(int i = 0; i < portNUM_PROCESSORS; i++){ + for (int i = 0; i < portNUM_PROCESSORS; i++) { start_sem[i] = xSemaphoreCreateBinary(); - xTaskCreatePinnedToCore(test_queue_registry_task, "testing task", 4096, NULL, UNITY_FREERTOS_PRIORITY+1, NULL, i); + xTaskCreatePinnedToCore(test_queue_registry_task, "testing task", 4096, NULL, UNITY_FREERTOS_PRIORITY + 1, NULL, i); } portDISABLE_INTERRUPTS(); - for(int i = 0; i < portNUM_PROCESSORS; i++){ + for (int i = 0; i < portNUM_PROCESSORS; i++) { xSemaphoreGive(start_sem[i]); //Trigger start } portENABLE_INTERRUPTS(); - for(int i = 0; i < portNUM_PROCESSORS; i++){ + for (int i = 0; i < portNUM_PROCESSORS; i++) { xSemaphoreTake(done_sem, portMAX_DELAY); //Wait for tasks to complete vQueueAddToRegistry } - for(int i = 0; i < NO_OF_QUEUES_TOTAL; i++){ + for (int i = 0; i < NO_OF_QUEUES_TOTAL; i++) { const char *addr = pcQueueGetName(handles[i]); TEST_ASSERT(addr == names[i]); //Check vQueueAddToRegistry was successful } portDISABLE_INTERRUPTS(); - for(int i = 0; i < portNUM_PROCESSORS; i++){ + for (int i = 0; i < portNUM_PROCESSORS; i++) { xSemaphoreGive(start_sem[i]); //Trigger start } portENABLE_INTERRUPTS(); - for(int i = 0; i < portNUM_PROCESSORS; i++){ + for (int i = 0; i < portNUM_PROCESSORS; i++) { xSemaphoreTake(done_sem, portMAX_DELAY); //Wait for tasks to complete vQueueUnregisterQueue } - for(int i = 0; i < NO_OF_QUEUES_TOTAL; i++){ + for (int i = 0; i < NO_OF_QUEUES_TOTAL; i++) { const char *addr = pcQueueGetName(handles[i]); TEST_ASSERT(addr == NULL); //Check vQueueUnregisterQueue was successful handles[i] = NULL; } //Cleanup - for(int i = 0; i < NO_OF_QUEUES_TOTAL; i++){ + for (int i = 0; i < NO_OF_QUEUES_TOTAL; i++) { free(names[i]); names[i] = NULL; } - for(int i = 0; i < portNUM_PROCESSORS; i++){ + for (int i = 0; i < portNUM_PROCESSORS; i++) { vSemaphoreDelete(start_sem[i]); start_sem[i] = NULL; } diff --git a/components/freertos/test_apps/freertos/kernel/stream_buffer/test_stream_buffers.c b/components/freertos/test_apps/freertos/kernel/stream_buffer/test_stream_buffers.c index c2c8961323..673728d813 100644 --- a/components/freertos/test_apps/freertos/kernel/stream_buffer/test_stream_buffers.c +++ b/components/freertos/test_apps/freertos/kernel/stream_buffer/test_stream_buffers.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -64,11 +64,11 @@ TEST_CASE("Stream Buffer: Send-receive tasks", "[freertos]") BaseType_t sender_core_id; BaseType_t receiver_core_id; sender_core_id = 0; - #if CONFIG_FREERTOS_UNICORE - receiver_core_id = 0; - #else - receiver_core_id = 1; - #endif +#if CONFIG_FREERTOS_UNICORE + receiver_core_id = 0; +#else + receiver_core_id = 1; +#endif TEST_ASSERT_EQUAL(pdTRUE, xTaskCreatePinnedToCore(sender_task, "sender", 4096, &test_args, UNITY_FREERTOS_PRIORITY + 2, NULL, sender_core_id)); TEST_ASSERT_EQUAL(pdTRUE, xTaskCreatePinnedToCore(receiver_task, "receiver", 4096, &test_args, UNITY_FREERTOS_PRIORITY + 1, NULL, receiver_core_id)); diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_eTaskGetState.c b/components/freertos/test_apps/freertos/kernel/tasks/test_eTaskGetState.c index cd742e0a8a..b5ba707b0c 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_eTaskGetState.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_eTaskGetState.c @@ -26,7 +26,7 @@ Expected: static void blocked_task(void *arg) { - vTaskDelay(portMAX_DELAY-1); + vTaskDelay(portMAX_DELAY - 1); // Shouldn't need to self delete, but added for extra safety vTaskDelete(NULL); } diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_hooks.c b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_hooks.c index 893647c2d1..f1af4e30d1 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_hooks.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_hooks.c @@ -81,7 +81,7 @@ void vTaskPreDeletionHook(void *pxTCB) TEST_CASE("static task cleanup hook is called based on config", "[freertos]") { - for(int i = 0; i < portNUM_PROCESSORS; i++) { + for (int i = 0; i < portNUM_PROCESSORS; i++) { printf("Creating task CPU %d\n", i); TaskHandle_t new_task = NULL; deleted_tcb = NULL; diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_psram.c b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_psram.c index 872589347b..866b4e4bba 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_psram.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_psram.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -33,32 +33,32 @@ static void task_should_never_run(void *arg) } static BaseType_t create_task(TaskFunction_t function, - size_t stack_size, - void *task_arg, - int core_num, - UBaseType_t heap_caps, - TaskHandle_t *task_handle) + size_t stack_size, + void *task_arg, + int core_num, + UBaseType_t heap_caps, + TaskHandle_t *task_handle) { #if CONFIG_FREERTOS_SMP UBaseType_t core_affinity_mask = (core_num == -1) ? tskNO_AFFINITY : 1 << core_num; return prvTaskCreateDynamicAffinitySetWithCaps(function, - "self_delete", - stack_size, - task_arg, - UNITY_FREERTOS_PRIORITY + 1, - core_affinity_mask, - heap_caps, - task_handle); + "self_delete", + stack_size, + task_arg, + UNITY_FREERTOS_PRIORITY + 1, + core_affinity_mask, + heap_caps, + task_handle); #else const BaseType_t task_core_num = (core_num == -1) ? tskNO_AFFINITY : core_num; return prvTaskCreateDynamicPinnedToCoreWithCaps(function, - "self_delete", - stack_size, - task_arg, - UNITY_FREERTOS_PRIORITY + 1, - task_core_num, - heap_caps, - task_handle); + "self_delete", + stack_size, + task_arg, + UNITY_FREERTOS_PRIORITY + 1, + task_core_num, + heap_caps, + task_handle); #endif } @@ -69,11 +69,11 @@ TEST_CASE("Out of memory failure", "[freertos][psram]") UBaseType_t HEAP_CAPS = (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); BaseType_t result = create_task(task_should_never_run, - STACK_SIZE, - (void *)xTaskGetCurrentTaskHandle(), - -1, - HEAP_CAPS, - &task_handle); + STACK_SIZE, + (void *)xTaskGetCurrentTaskHandle(), + -1, + HEAP_CAPS, + &task_handle); TEST_ASSERT_EQUAL(errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY, result); (void)task_handle; } @@ -85,11 +85,11 @@ TEST_CASE("Task with stack memory in PSRAM", "[freertos][psram]") UBaseType_t HEAP_CAPS = (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); BaseType_t result = create_task(task_delete_itself, - STACK_SIZE, - (void *)xTaskGetCurrentTaskHandle(), - -1, - HEAP_CAPS, - &task_handle); + STACK_SIZE, + (void *)xTaskGetCurrentTaskHandle(), + -1, + HEAP_CAPS, + &task_handle); TEST_ASSERT_EQUAL(pdPASS, result); // synchronize with the task to make sure we don't return too early, thus giving it enough time @@ -126,11 +126,11 @@ TEST_CASE("Task on specific core works", "[freertos][psram]") corenum_info.parent_handle = xTaskGetCurrentTaskHandle(); UBaseType_t HEAP_CAPS = (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); BaseType_t result = create_task(task_report_corenum, - STACK_SIZE, - (void *) &(corenum_info), - corenum, - HEAP_CAPS, - &task_handle); + STACK_SIZE, + (void *) & (corenum_info), + corenum, + HEAP_CAPS, + &task_handle); TEST_ASSERT_EQUAL(pdPASS, result); diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_scheduling_round_robin.c b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_scheduling_round_robin.c index 60c5d1372c..6d82048e11 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_scheduling_round_robin.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_scheduling_round_robin.c @@ -70,7 +70,7 @@ static void spin_task(void *arg) //Last iteration of the last spin task on this core. Reenable this core's tick interrupt if (total_iter_count[xPortGetCoreID()] == (NUM_PINNED_SPIN_TASK_PER_CORE * SPIN_TASK_NUM_ITER)) { - esp_cpu_intr_enable(1 <= 0; i--){ + for (int i = NO_OF_CORES - 1; i >= 0; i--) { xSemaphoreGive(test_queues[i]); } vTaskDelay(10); //Small delay to ensure semaphores are taken //Wait for done - for(int i = 0; i < NO_OF_CORES; i++){ + for (int i = 0; i < NO_OF_CORES; i++) { xSemaphoreTake(test_queues[i], portMAX_DELAY); vSemaphoreDelete(test_queues[i]); } @@ -85,7 +85,6 @@ TEST_CASE("Test freertos trace facility functions", "[freertos]") vTaskDelay(10); //Give time for idle task to clean up } - #define MAX_TASKS 15 #define TASKS_TO_CREATE 5 @@ -94,7 +93,7 @@ static TaskStatus_t *tsk_status_array; void created_task(void* arg) { - while(1){ + while (1) { vTaskDelay(100); } } @@ -102,7 +101,7 @@ void created_task(void* arg) TEST_CASE("Test freertos uxTaskGetSystemState", "[freertos]") { tsk_status_array = calloc(MAX_TASKS, sizeof(TaskStatus_t)); - for(int i = 0; i < TASKS_TO_CREATE; i++){ + for (int i = 0; i < TASKS_TO_CREATE; i++) { xTaskCreatePinnedToCore(created_task, "Created Task", 1024, NULL, TSK_PRIORITY, &created_handles[i], 0); } @@ -112,15 +111,15 @@ TEST_CASE("Test freertos uxTaskGetSystemState", "[freertos]") //Check if get system state has got all created tasks bool not_found = false; - for(int i = 0; i < TASKS_TO_CREATE; i++){ + for (int i = 0; i < TASKS_TO_CREATE; i++) { bool found = false; - for(int j = 0; j < MAX_TASKS; j++){ - if(tsk_status_array[j].xHandle == created_handles[i]){ + for (int j = 0; j < MAX_TASKS; j++) { + if (tsk_status_array[j].xHandle == created_handles[i]) { found = true; break; } } - if(!found){ + if (!found) { not_found = true; break; } @@ -128,7 +127,7 @@ TEST_CASE("Test freertos uxTaskGetSystemState", "[freertos]") TEST_ASSERT(not_found == false); //Cleanup - for(int i = 0; i < TASKS_TO_CREATE; i++){ + for (int i = 0; i < TASKS_TO_CREATE; i++) { vTaskDelete(created_handles[i]); } free(tsk_status_array); diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_preemption.c b/components/freertos/test_apps/freertos/kernel/tasks/test_preemption.c index 9751472aff..0e6546790e 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_preemption.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_preemption.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -31,7 +31,6 @@ static volatile bool flag; #define MAX_YIELD_COUNT 17000 #endif // CONFIG_FREERTOS_SMP - /* Task: - Waits for 'trigger' variable to be set - Reads the cycle count on this CPU @@ -43,7 +42,7 @@ static void task_send_to_queue(void *param) QueueHandle_t queue = (QueueHandle_t) param; uint32_t ccount; - while(!trigger) {} + while (!trigger) {} ccount = esp_cpu_get_cycle_count(); flag = true; @@ -53,7 +52,7 @@ static void task_send_to_queue(void *param) The task runs until terminated by the main task. */ - while(1) {} + while (1) {} } TEST_CASE("Yield from lower priority task, same CPU", "[freertos]") @@ -73,9 +72,9 @@ TEST_CASE("Yield from lower priority task, same CPU", "[freertos]") trigger = true; uint32_t yield_ccount, now_ccount, delta; - TEST_ASSERT( xQueueReceive(queue, &yield_ccount, 100 / portTICK_PERIOD_MS) ); + TEST_ASSERT(xQueueReceive(queue, &yield_ccount, 100 / portTICK_PERIOD_MS)); now_ccount = esp_cpu_get_cycle_count(); - TEST_ASSERT( flag ); + TEST_ASSERT(flag); delta = now_ccount - yield_ccount; printf("Yielding from lower priority task took %"PRIu32" cycles\n", delta); @@ -86,7 +85,6 @@ TEST_CASE("Yield from lower priority task, same CPU", "[freertos]") } } - #if (portNUM_PROCESSORS == 2) && !CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH TEST_CASE("Yield from lower priority task, other CPU", "[freertos]") { @@ -110,9 +108,9 @@ TEST_CASE("Yield from lower priority task, other CPU", "[freertos]") // yield_ccount is not useful in this test as it's the other core's CCOUNT // so we use trigger_ccount instead - TEST_ASSERT( xQueueReceive(queue, &yield_ccount, 100 / portTICK_PERIOD_MS) ); + TEST_ASSERT(xQueueReceive(queue, &yield_ccount, 100 / portTICK_PERIOD_MS)); now_ccount = esp_cpu_get_cycle_count(); - TEST_ASSERT( flag ); + TEST_ASSERT(flag); delta = now_ccount - trigger_ccount; printf("Yielding from task on other core took %"PRIu32" cycles\n", delta); diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_task_delay.c b/components/freertos/test_apps/freertos/kernel/tasks/test_task_delay.c index 6893640ef6..e60c9080da 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_task_delay.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_task_delay.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -64,11 +64,11 @@ static void test_vTaskDelay(void *arg) /* Check that elapsed ticks and ref clock is accurate. We allow TEST_VTASKDELAY_DELTA_TICKS of error in case * vTaskDelay() or portTEST_REF_CLOCK_GET_TIME() last long enough to cross a tick boundary */ - #if ( configUSE_16_BIT_TICKS == 1 ) - TEST_ASSERT_UINT16_WITHIN(TEST_VTASKDELAY_DELTA_TICKS, TEST_VTASKDELAY_TICKS, tick_end - tick_start); - #else - TEST_ASSERT_UINT32_WITHIN(TEST_VTASKDELAY_DELTA_TICKS, TEST_VTASKDELAY_TICKS, tick_end - tick_start); - #endif +#if ( configUSE_16_BIT_TICKS == 1 ) + TEST_ASSERT_UINT16_WITHIN(TEST_VTASKDELAY_DELTA_TICKS, TEST_VTASKDELAY_TICKS, tick_end - tick_start); +#else + TEST_ASSERT_UINT32_WITHIN(TEST_VTASKDELAY_DELTA_TICKS, TEST_VTASKDELAY_TICKS, tick_end - tick_start); +#endif TEST_ASSERT_UINT32_WITHIN(portTEST_TICKS_TO_REF_CLOCK(TEST_VTASKDELAY_DELTA_TICKS), portTEST_TICKS_TO_REF_CLOCK(TEST_VTASKDELAY_TICKS), ref_clock_end - ref_clock_start); @@ -79,12 +79,12 @@ TEST_CASE("Tasks: Test vTaskDelay", "[freertos]") { portTEST_REF_CLOCK_INIT(); - #if ( configNUM_CORES > 1 ) - vTestOnAllCores(test_vTaskDelay, NULL, configTEST_DEFAULT_STACK_SIZE, configTEST_UNITY_TASK_PRIORITY - 1); - #else - /* Test vTaskDelay directly on the current core */ - test_vTaskDelay(NULL); - #endif +#if ( configNUM_CORES > 1 ) + vTestOnAllCores(test_vTaskDelay, NULL, configTEST_DEFAULT_STACK_SIZE, configTEST_UNITY_TASK_PRIORITY - 1); +#else + /* Test vTaskDelay directly on the current core */ + test_vTaskDelay(NULL); +#endif portTEST_REF_CLOCK_DEINIT(); } @@ -144,16 +144,15 @@ static void test_vTaskDelayUntil(void *arg) tick_end = xTaskGetTickCount(); ref_clock_end = portTEST_REF_CLOCK_GET_TIME(); - /* Check that elapsed ticks and ref clock is accurate. We allow TEST_VTASKDELAYUNTIL_DELTA_TICKS of error in * case vTaskDelayUntil() or portTEST_REF_CLOCK_GET_TIME() last long enough to cross a tick boundary */ - #if ( configUSE_16_BIT_TICKS == 1 ) - TEST_ASSERT_UINT16_WITHIN(TEST_VTASKDELAYUNTIL_DELTA_TICKS, TEST_VTASKDELAYUNTIL_TICKS, tick_end - tick_start); - TEST_ASSERT_UINT16_WITHIN(TEST_VTASKDELAYUNTIL_DELTA_TICKS, tick_end, last_wake_tick); - #else - TEST_ASSERT_UINT32_WITHIN(TEST_VTASKDELAYUNTIL_DELTA_TICKS, TEST_VTASKDELAYUNTIL_TICKS, tick_end - tick_start); - TEST_ASSERT_UINT32_WITHIN(TEST_VTASKDELAYUNTIL_DELTA_TICKS, tick_end, last_wake_tick); - #endif +#if ( configUSE_16_BIT_TICKS == 1 ) + TEST_ASSERT_UINT16_WITHIN(TEST_VTASKDELAYUNTIL_DELTA_TICKS, TEST_VTASKDELAYUNTIL_TICKS, tick_end - tick_start); + TEST_ASSERT_UINT16_WITHIN(TEST_VTASKDELAYUNTIL_DELTA_TICKS, tick_end, last_wake_tick); +#else + TEST_ASSERT_UINT32_WITHIN(TEST_VTASKDELAYUNTIL_DELTA_TICKS, TEST_VTASKDELAYUNTIL_TICKS, tick_end - tick_start); + TEST_ASSERT_UINT32_WITHIN(TEST_VTASKDELAYUNTIL_DELTA_TICKS, tick_end, last_wake_tick); +#endif /* Check that the elapsed ref clock time is accurate. We allow TEST_VTASKDELAYUNTIL_DELTA_TICKS time worth of * error to account for the execution time of the ref clock functions. */ @@ -167,12 +166,12 @@ TEST_CASE("Tasks: Test vTaskDelayUntil", "[freertos]") { portTEST_REF_CLOCK_INIT(); - #if ( configNUM_CORES > 1 ) - vTestOnAllCores(test_vTaskDelayUntil, NULL, configTEST_DEFAULT_STACK_SIZE, configTEST_UNITY_TASK_PRIORITY - 1); - #else - /* Test vTaskDelay directly on the current core */ - test_vTaskDelayUntil(NULL); - #endif +#if ( configNUM_CORES > 1 ) + vTestOnAllCores(test_vTaskDelayUntil, NULL, configTEST_DEFAULT_STACK_SIZE, configTEST_UNITY_TASK_PRIORITY - 1); +#else + /* Test vTaskDelay directly on the current core */ + test_vTaskDelayUntil(NULL); +#endif portTEST_REF_CLOCK_DEINIT(); } diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_task_priorities.c b/components/freertos/test_apps/freertos/kernel/tasks/test_task_priorities.c index 707f84175e..c1480318db 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_task_priorities.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_task_priorities.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -17,7 +17,6 @@ #include "unity.h" #include "test_utils.h" - static void counter_task(void *param) { volatile uint32_t *counter = (volatile uint32_t *)param; @@ -26,7 +25,6 @@ static void counter_task(void *param) } } - TEST_CASE("Get/Set Priorities", "[freertos]") { /* Two tasks per processor */ @@ -38,7 +36,7 @@ TEST_CASE("Get/Set Priorities", "[freertos]") /* create a matrix of counter tasks on each core */ for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) { for (int task = 0; task < 2; task++) { - xTaskCreatePinnedToCore(counter_task, "count", 2048, (void *)&(counters[cpu][task]), UNITY_FREERTOS_PRIORITY - task, &(tasks[cpu][task]), cpu); + xTaskCreatePinnedToCore(counter_task, "count", 2048, (void *) & (counters[cpu][task]), UNITY_FREERTOS_PRIORITY - task, &(tasks[cpu][task]), cpu); } } @@ -65,7 +63,7 @@ TEST_CASE("Get/Set Priorities", "[freertos]") /* check priorities have swapped... */ for (int cpu = 0; cpu < portNUM_PROCESSORS; cpu++) { - TEST_ASSERT_EQUAL(UNITY_FREERTOS_PRIORITY -1, uxTaskPriorityGet(tasks[cpu][0])); + TEST_ASSERT_EQUAL(UNITY_FREERTOS_PRIORITY - 1, uxTaskPriorityGet(tasks[cpu][0])); TEST_ASSERT_EQUAL(UNITY_FREERTOS_PRIORITY, uxTaskPriorityGet(tasks[cpu][1])); } diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_task_suspend_resume.c b/components/freertos/test_apps/freertos/kernel/tasks/test_task_suspend_resume.c index be6faedbe3..0df02840a8 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_task_suspend_resume.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_task_suspend_resume.c @@ -69,7 +69,6 @@ static void test_suspend_resume(int target_core) vTaskDelete(counter_task); } - TEST_CASE("Suspend/resume task on same core", "[freertos]") { test_suspend_resume(UNITY_FREERTOS_CPU); @@ -119,7 +118,6 @@ TEST_CASE("Suspend the current running task", "[freertos]") TEST_ASSERT_TRUE(resumed); } - static volatile bool timer_isr_fired; static gptimer_handle_t gptimer = NULL; @@ -146,7 +144,6 @@ static IRAM_ATTR void task_suspend_self_with_timer(void *vp_resumed) vTaskDelete(NULL); } - /* Create a task which suspends itself, then resume it from a timer * interrupt. */ static void test_resume_task_from_isr(int target_core) diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_vTaskSuspendAll_xTaskResumeAll.c b/components/freertos/test_apps/freertos/kernel/tasks/test_vTaskSuspendAll_xTaskResumeAll.c index 1dc48cd808..1367ba2b22 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_vTaskSuspendAll_xTaskResumeAll.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_vTaskSuspendAll_xTaskResumeAll.c @@ -637,7 +637,6 @@ TEST_CASE("Test xTaskResumeAll resumes pended tasks", "[freertos]") vTaskDelay(10); } - /* --------------------------------------------------------------------------------------------------------------------- Test xTaskSuspendAll on both cores pends all tasks and xTaskResumeAll on both cores resumes all tasks @@ -790,7 +789,7 @@ void test_blocked_task(void *arg) has_run = false; // Got to blocked state - vTaskDelay( TEST_BLOCKED_TASK_DELAY_MS / portTICK_PERIOD_MS ); + vTaskDelay(TEST_BLOCKED_TASK_DELAY_MS / portTICK_PERIOD_MS); // Mark when this task runs has_run = true; diff --git a/components/freertos/test_apps/freertos/kernel/timers/test_timers.c b/components/freertos/test_apps/freertos/kernel/timers/test_timers.c index 37c170fc6c..f07bf6fda6 100644 --- a/components/freertos/test_apps/freertos/kernel/timers/test_timers.c +++ b/components/freertos/test_apps/freertos/kernel/timers/test_timers.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -16,7 +16,7 @@ static void timer_callback(TimerHandle_t timer) { volatile int *count; - count = (volatile int *)pvTimerGetTimerID( timer ); + count = (volatile int *)pvTimerGetTimerID(timer); (*count)++; printf("Callback timer %p count %p = %d\n", timer, count, *count); } @@ -30,7 +30,7 @@ TEST_CASE("Oneshot FreeRTOS timers", "[freertos]") TEST_ASSERT_EQUAL(pdFALSE, xTimerIsTimerActive(oneshot)); TEST_ASSERT_EQUAL(0, count); - TEST_ASSERT( xTimerStart(oneshot, 1) ); + TEST_ASSERT(xTimerStart(oneshot, 1)); vTaskDelay(2); /* give the timer task a chance to process the message */ TEST_ASSERT_EQUAL(pdTRUE, xTimerIsTimerActive(oneshot)); @@ -41,20 +41,19 @@ TEST_CASE("Oneshot FreeRTOS timers", "[freertos]") TEST_ASSERT_EQUAL(1, count); TEST_ASSERT_EQUAL(pdFALSE, xTimerIsTimerActive(oneshot)); - TEST_ASSERT( xTimerDelete(oneshot, 1) ); + TEST_ASSERT(xTimerDelete(oneshot, 1)); } - TEST_CASE("Recurring FreeRTOS timers", "[freertos]") { volatile int count = 0; TimerHandle_t recurring = xTimerCreate("oneshot", 100 / portTICK_PERIOD_MS, pdTRUE, - (void *)&count, timer_callback); + (void *)&count, timer_callback); TEST_ASSERT(recurring); TEST_ASSERT_EQUAL(pdFALSE, xTimerIsTimerActive(recurring)); TEST_ASSERT_EQUAL(0, count); - TEST_ASSERT( xTimerStart(recurring, 1) ); + TEST_ASSERT(xTimerStart(recurring, 1)); vTaskDelay(2); // let timer task process the queue TEST_ASSERT_EQUAL(pdTRUE, xTimerIsTimerActive(recurring)); @@ -65,7 +64,7 @@ TEST_CASE("Recurring FreeRTOS timers", "[freertos]") TEST_ASSERT_EQUAL(2, count); TEST_ASSERT_EQUAL(pdTRUE, xTimerIsTimerActive(recurring)); - TEST_ASSERT( xTimerStop(recurring, 1) ); + TEST_ASSERT(xTimerStop(recurring, 1)); TEST_ASSERT_EQUAL(2, count); @@ -73,7 +72,7 @@ TEST_CASE("Recurring FreeRTOS timers", "[freertos]") TEST_ASSERT_EQUAL(2, count); // hasn't gone up TEST_ASSERT_EQUAL(pdFALSE, xTimerIsTimerActive(recurring)); - TEST_ASSERT( xTimerDelete(recurring, 1) ); + TEST_ASSERT(xTimerDelete(recurring, 1)); } TEST_CASE("Static timer creation", "[freertos]") @@ -83,10 +82,10 @@ TEST_CASE("Static timer creation", "[freertos]") volatile int count = 0; created_timer = xTimerCreateStatic("oneshot", 100 / portTICK_PERIOD_MS, - pdTRUE, - (void *)&count, - timer_callback, - &static_timer); + pdTRUE, + (void *)&count, + timer_callback, + &static_timer); TEST_ASSERT_NOT_NULL(created_timer); } diff --git a/components/freertos/test_apps/freertos/misc/test_idf_additions.c b/components/freertos/test_apps/freertos/misc/test_idf_additions.c index ceaf2e46a4..aea2ecb2f8 100644 --- a/components/freertos/test_apps/freertos/misc/test_idf_additions.c +++ b/components/freertos/test_apps/freertos/misc/test_idf_additions.c @@ -202,7 +202,7 @@ static void IRAM_ATTR tick_hook(void) static void suspend_task(void *arg) { - TaskHandle_t main_task_hdl = ( TaskHandle_t )arg; + TaskHandle_t main_task_hdl = (TaskHandle_t)arg; /* Fetch the current core ID */ BaseType_t xCoreID = portGET_CORE_ID(); diff --git a/components/freertos/test_apps/freertos/misc/test_newlib_reent.c b/components/freertos/test_apps/freertos/misc/test_newlib_reent.c index 628e36ffa5..1ee18df689 100644 --- a/components/freertos/test_apps/freertos/misc/test_newlib_reent.c +++ b/components/freertos/test_apps/freertos/misc/test_newlib_reent.c @@ -42,8 +42,6 @@ static void tskTestRand(void *pvParameters) vTaskDelete(NULL); } - - // TODO: split this thing into separate orthogonal tests TEST_CASE("Test for per-task non-reentrant tasks", "[freertos]") { diff --git a/components/freertos/test_apps/freertos/performance/test_freertos_scheduling_time.c b/components/freertos/test_apps/freertos/performance/test_freertos_scheduling_time.c index c41f3a54e5..d0f4e3361b 100644 --- a/components/freertos/test_apps/freertos/performance/test_freertos_scheduling_time.c +++ b/components/freertos/test_apps/freertos/performance/test_freertos_scheduling_time.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -25,10 +25,11 @@ typedef struct { TaskHandle_t t1_handle; } test_context_t; -static void test_task_1(void *arg) { +static void test_task_1(void *arg) +{ test_context_t *context = (test_context_t *)arg; - for( ;; ) { + for (;;) { context->before_sched = esp_cpu_get_cycle_count(); vPortYield(); } @@ -36,7 +37,8 @@ static void test_task_1(void *arg) { vTaskDelete(NULL); } -static void test_task_2(void *arg) { +static void test_task_2(void *arg) +{ test_context_t *context = (test_context_t *)arg; uint64_t accumulator = 0; @@ -44,7 +46,7 @@ static void test_task_2(void *arg) { vTaskPrioritySet(context->t1_handle, CONFIG_UNITY_FREERTOS_PRIORITY + 1); vPortYield(); - for(int i = 0; i < NUMBER_OF_ITERATIONS; i++) { + for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) { accumulator += (esp_cpu_get_cycle_count() - context->before_sched); vPortYield(); } @@ -63,14 +65,14 @@ TEST_CASE("scheduling time test", "[freertos]") TEST_ASSERT(context.end_sema != NULL); #if !CONFIG_FREERTOS_UNICORE - xTaskCreatePinnedToCore(test_task_1, "test1" , 4096, &context, 1, &context.t1_handle,1); - xTaskCreatePinnedToCore(test_task_2, "test2" , 4096, &context, 1, NULL,1); + xTaskCreatePinnedToCore(test_task_1, "test1", 4096, &context, 1, &context.t1_handle, 1); + xTaskCreatePinnedToCore(test_task_2, "test2", 4096, &context, 1, NULL, 1); #else - xTaskCreatePinnedToCore(test_task_1, "test1" , 4096, &context, CONFIG_UNITY_FREERTOS_PRIORITY - 1, &context.t1_handle,0); - xTaskCreatePinnedToCore(test_task_2, "test2" , 4096, &context, CONFIG_UNITY_FREERTOS_PRIORITY - 1, NULL,0); + xTaskCreatePinnedToCore(test_task_1, "test1", 4096, &context, CONFIG_UNITY_FREERTOS_PRIORITY - 1, &context.t1_handle, 0); + xTaskCreatePinnedToCore(test_task_2, "test2", 4096, &context, CONFIG_UNITY_FREERTOS_PRIORITY - 1, NULL, 0); #endif BaseType_t result = xSemaphoreTake(context.end_sema, portMAX_DELAY); TEST_ASSERT_EQUAL_HEX32(pdTRUE, result); - TEST_PERFORMANCE_LESS_THAN(SCHEDULING_TIME , "%"PRIu32" cycles" ,context.cycles_to_sched); + TEST_PERFORMANCE_LESS_THAN(SCHEDULING_TIME, "%"PRIu32" cycles", context.cycles_to_sched); } diff --git a/components/freertos/test_apps/freertos/performance/test_isr_latency.c b/components/freertos/test_apps/freertos/performance/test_isr_latency.c index 7cd155a331..314a7d6263 100644 --- a/components/freertos/test_apps/freertos/performance/test_isr_latency.c +++ b/components/freertos/test_apps/freertos/performance/test_isr_latency.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -38,7 +38,8 @@ static uint32_t cycle_before_exit; static uint32_t delta_enter_cycles = 0; static uint32_t delta_exit_cycles = 0; -static void software_isr_using_parameter_vportyield(void *arg) { +static void software_isr_using_parameter_vportyield(void *arg) +{ (void)arg; BaseType_t yield; delta_enter_cycles += esp_cpu_get_cycle_count() - cycle_before_trigger; @@ -50,7 +51,8 @@ static void software_isr_using_parameter_vportyield(void *arg) { cycle_before_exit = esp_cpu_get_cycle_count(); } -static void software_isr_using_no_argument_vportyield(void *arg) { +static void software_isr_using_no_argument_vportyield(void *arg) +{ (void)arg; BaseType_t yield; delta_enter_cycles += esp_cpu_get_cycle_count() - cycle_before_trigger; @@ -58,16 +60,17 @@ static void software_isr_using_no_argument_vportyield(void *arg) { TEST_CLR_INT_MASK(1 << SW_ISR_LEVEL_1); xSemaphoreGiveFromISR(sync, &yield); - if(yield) { + if (yield) { portYIELD_FROM_ISR(); } cycle_before_exit = esp_cpu_get_cycle_count(); } -static void test_task(void *arg) { +static void test_task(void *arg) +{ (void) arg; - for(int i = 0;i < 10000; i++) { + for (int i = 0; i < 10000; i++) { cycle_before_trigger = esp_cpu_get_cycle_count(); TEST_SET_INT_MASK(1 << SW_ISR_LEVEL_1); xSemaphoreTake(sync, portMAX_DELAY); @@ -91,12 +94,12 @@ TEST_CASE("isr latency test vport-yield-from-isr with no parameter", "[freertos] TEST_ASSERT(sync != NULL); end_sema = xSemaphoreCreateBinary(); TEST_ASSERT(end_sema != NULL); - xTaskCreatePinnedToCore(test_task, "tst" , 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0); + xTaskCreatePinnedToCore(test_task, "tst", 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0); vTaskDelay(100); BaseType_t result = xSemaphoreTake(end_sema, portMAX_DELAY); TEST_ASSERT_EQUAL_HEX32(pdTRUE, result); - TEST_PERFORMANCE_LESS_THAN(ISR_ENTER_CYCLES, "%"PRIu32" cycles" ,delta_enter_cycles); - TEST_PERFORMANCE_LESS_THAN(ISR_EXIT_CYCLES, "%"PRIu32" cycles" ,delta_exit_cycles); + TEST_PERFORMANCE_LESS_THAN(ISR_ENTER_CYCLES, "%"PRIu32" cycles", delta_enter_cycles); + TEST_PERFORMANCE_LESS_THAN(ISR_EXIT_CYCLES, "%"PRIu32" cycles", delta_exit_cycles); esp_intr_free(handle); } @@ -111,11 +114,11 @@ TEST_CASE("isr latency test vport-yield-from-isr with parameter", "[freertos][ig TEST_ASSERT(sync != NULL); end_sema = xSemaphoreCreateBinary(); TEST_ASSERT(end_sema != NULL); - xTaskCreatePinnedToCore(test_task, "tst" , 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0); + xTaskCreatePinnedToCore(test_task, "tst", 4096, NULL, configMAX_PRIORITIES - 1, NULL, 0); BaseType_t result = xSemaphoreTake(end_sema, portMAX_DELAY); TEST_ASSERT_EQUAL_HEX32(pdTRUE, result); - TEST_PERFORMANCE_LESS_THAN(ISR_ENTER_CYCLES, "%"PRIu32" cycles" ,delta_enter_cycles); - TEST_PERFORMANCE_LESS_THAN(ISR_EXIT_CYCLES, "%"PRIu32" cycles" ,delta_exit_cycles); + TEST_PERFORMANCE_LESS_THAN(ISR_ENTER_CYCLES, "%"PRIu32" cycles", delta_enter_cycles); + TEST_PERFORMANCE_LESS_THAN(ISR_EXIT_CYCLES, "%"PRIu32" cycles", delta_exit_cycles); esp_intr_free(handle); } diff --git a/components/freertos/test_apps/freertos/port/test_context_save_clobber.c b/components/freertos/test_apps/freertos/port/test_context_save_clobber.c index e430a7da1d..0c9cd4213d 100644 --- a/components/freertos/test_apps/freertos/port/test_context_save_clobber.c +++ b/components/freertos/test_apps/freertos/port/test_context_save_clobber.c @@ -21,7 +21,6 @@ * when the recursive function returns. */ - /* See test_context_save_clober_func.S */ extern void test_context_save_clober_func(void); diff --git a/components/freertos/test_apps/freertos/port/test_fpu_in_task.c b/components/freertos/test_apps/freertos/port/test_fpu_in_task.c index 64ceaf06e1..b43ff356b9 100644 --- a/components/freertos/test_apps/freertos/port/test_fpu_in_task.c +++ b/components/freertos/test_apps/freertos/port/test_fpu_in_task.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -194,7 +194,6 @@ typedef struct { TaskHandle_t main; } ParamsFPU; - /** * @brief Function performing some simple calculation using several FPU registers. * The goal is to be preempted by a task that also uses the FPU on the same core. @@ -206,8 +205,7 @@ void fpu_calculation(void* arg) const float init = negative ? -1.f : 1.f; float f = init; - for(int i = 0; i < 10; i++) - { + for (int i = 0; i < 10; i++) { /* The following calculation doesn't really have any meaning, we try to use several FPU registers and operations */ float delta = negative ? -1.1f : 1.1f; for (int i = 0; i < 1000; i++) { @@ -222,7 +220,7 @@ void fpu_calculation(void* arg) * It'll have the sign of the other tasks' `f` value. * Use assert to make sure the sign is correct. Using TEST_ASSERT_TRUE triggers a stack overflow. */ - assert( (negative && f < 0.0f) || (!negative && f > 0.0f) ); + assert((negative && f < 0.0f) || (!negative && f > 0.0f)); f = init; /* Give the hand back to FreeRTOS to avoid any watchdog */ @@ -233,8 +231,6 @@ void fpu_calculation(void* arg) vTaskDelete(NULL); } - - TEST_CASE("FPU: Unsolicited context switch between tasks using FPU", "[freertos]") { /* Create two tasks that are on the same core and use the same FPU */ diff --git a/components/freertos/test_apps/freertos/port/test_fpu_watermark.c b/components/freertos/test_apps/freertos/port/test_fpu_watermark.c index 5f29540bbf..034ca5c81e 100644 --- a/components/freertos/test_apps/freertos/port/test_fpu_watermark.c +++ b/components/freertos/test_apps/freertos/port/test_fpu_watermark.c @@ -41,7 +41,6 @@ static void other_task(void* arg) vTaskDelete(NULL); } - TEST_CASE("FPU: Context save does not affect stack watermark", "[freertos]") { TaskHandle_t pvCreatedTask; @@ -56,13 +55,13 @@ TEST_CASE("FPU: Context save does not affect stack watermark", "[freertos]") /* Use the FPU unit, the context will NOT be flushed until another task starts using it */ add_floats(s_float, s_float); - xTaskCreatePinnedToCore( other_task, - "OtherTask", - 2048, - (void*) current_handle, - CONFIG_UNITY_FREERTOS_PRIORITY - 1, - &pvCreatedTask, - core_id); + xTaskCreatePinnedToCore(other_task, + "OtherTask", + 2048, + (void*) current_handle, + CONFIG_UNITY_FREERTOS_PRIORITY - 1, + &pvCreatedTask, + core_id); vTaskDelay(10); diff --git a/components/freertos/test_apps/freertos/port/test_freertos_isinisrcontext.c b/components/freertos/test_apps/freertos/port/test_freertos_isinisrcontext.c index e1be84ef7f..fba1e92c7b 100644 --- a/components/freertos/test_apps/freertos/port/test_freertos_isinisrcontext.c +++ b/components/freertos/test_apps/freertos/port/test_freertos_isinisrcontext.c @@ -24,7 +24,6 @@ static volatile int in_int_context, int_handled; - static void testint(void) { esp_rom_printf("INT!\n"); @@ -34,7 +33,6 @@ static void testint(void) int_handled++; } - static void testthread(void *arg) { in_int_context = 0; @@ -49,7 +47,6 @@ static void testthread(void *arg) vTaskDelete(NULL); } - TEST_CASE("xPortInIsrContext test", "[freertos]") { xTaskCreatePinnedToCore(testthread, "tst", 4096, NULL, 3, NULL, 0); @@ -60,5 +57,4 @@ TEST_CASE("xPortInIsrContext test", "[freertos]") #endif } - #endif diff --git a/components/freertos/test_apps/freertos/port/test_spinlocks.c b/components/freertos/test_apps/freertos/port/test_spinlocks.c index 06e887fa79..96d5ed76e2 100644 --- a/components/freertos/test_apps/freertos/port/test_spinlocks.c +++ b/components/freertos/test_apps/freertos/port/test_spinlocks.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -50,12 +50,12 @@ TEST_CASE("portMUX spinlocks (no contention)", "[freertos]") BENCHMARK_END("no contention lock"); #ifdef CONFIG_FREERTOS_UNICORE - TEST_PERFORMANCE_LESS_THAN(FREERTOS_SPINLOCK_CYCLES_PER_OP_UNICORE, "%"PRIu32" cycles/op", ((end - start)/REPEAT_OPS)); + TEST_PERFORMANCE_LESS_THAN(FREERTOS_SPINLOCK_CYCLES_PER_OP_UNICORE, "%"PRIu32" cycles/op", ((end - start) / REPEAT_OPS)); #else #if CONFIG_SPIRAM - TEST_PERFORMANCE_LESS_THAN(FREERTOS_SPINLOCK_CYCLES_PER_OP_PSRAM, "%"PRIu32" cycles/op", ((end - start)/REPEAT_OPS)); + TEST_PERFORMANCE_LESS_THAN(FREERTOS_SPINLOCK_CYCLES_PER_OP_PSRAM, "%"PRIu32" cycles/op", ((end - start) / REPEAT_OPS)); #else - TEST_PERFORMANCE_LESS_THAN(FREERTOS_SPINLOCK_CYCLES_PER_OP, "%"PRIu32" cycles/op", ((end - start)/REPEAT_OPS)); + TEST_PERFORMANCE_LESS_THAN(FREERTOS_SPINLOCK_CYCLES_PER_OP, "%"PRIu32" cycles/op", ((end - start) / REPEAT_OPS)); #endif #endif } @@ -107,8 +107,8 @@ TEST_CASE("portMUX cross-core locking", "[freertos]") xTaskCreatePinnedToCore(task_shared_value_increment, "INC0", 2048, NULL, UNITY_FREERTOS_PRIORITY + 1, NULL, UNITY_FREERTOS_CPU ? 0 : 1); xTaskCreatePinnedToCore(task_shared_value_increment, "INC1", 2048, NULL, UNITY_FREERTOS_PRIORITY + 1, NULL, UNITY_FREERTOS_CPU); - for(int i = 0; i < 2; i++) { - if(!xSemaphoreTake(done_sem, 10000/portTICK_PERIOD_MS)) { + for (int i = 0; i < 2; i++) { + if (!xSemaphoreTake(done_sem, 10000 / portTICK_PERIOD_MS)) { TEST_FAIL_MESSAGE("done_sem not released by test task"); } } @@ -139,8 +139,8 @@ void portmux_high_contention_test(uint32_t lock_malloc_caps) xTaskCreatePinnedToCore(task_shared_value_increment, "INC1", 2048, NULL, tskIDLE_PRIORITY + 1 + i, NULL, UNITY_FREERTOS_CPU); } - for(int i = 0; i < TOTAL_TASKS; i++) { - if(!xSemaphoreTake(done_sem, 10000/portTICK_PERIOD_MS)) { + for (int i = 0; i < TOTAL_TASKS; i++) { + if (!xSemaphoreTake(done_sem, 10000 / portTICK_PERIOD_MS)) { TEST_FAIL_MESSAGE("done_sem not released by test task"); } } diff --git a/components/freertos/test_apps/freertos/port/test_thread_local.c b/components/freertos/test_apps/freertos/port/test_thread_local.c index de38bee040..c16e72cd40 100644 --- a/components/freertos/test_apps/freertos/port/test_thread_local.c +++ b/components/freertos/test_apps/freertos/port/test_thread_local.c @@ -25,7 +25,6 @@ #define GET_THREADPTR(tp_dest) do { register uint32_t _tp asm("tp"); tp_dest = _tp; } while(0) #endif - static __thread int tl_test_var1; static __thread uint8_t tl_test_var2 = 55; static __thread uint16_t tl_test_var3 = 44; diff --git a/components/freertos/test_apps/freertos/port/test_xtensa_loadstore_handler.c b/components/freertos/test_apps/freertos/port/test_xtensa_loadstore_handler.c index 1618b57a95..054379e2b4 100644 --- a/components/freertos/test_apps/freertos/port/test_xtensa_loadstore_handler.c +++ b/components/freertos/test_apps/freertos/port/test_xtensa_loadstore_handler.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -55,28 +55,28 @@ TEST_CASE("LoadStore Exception handler", "[freertos]") offset32 = offset8 / 4; arr8[offset8] = val8_0; - arr8[offset8+1] = val8_1; - arr8[offset8+2] = val8_2; - arr8[offset8+3] = val8_3; + arr8[offset8 + 1] = val8_1; + arr8[offset8 + 2] = val8_2; + arr8[offset8 + 3] = val8_3; // Just to make sure compiler doesn't read stale data asm volatile("memw\n"); TEST_ASSERT_EQUAL(val8_0, arr8[offset8]); - TEST_ASSERT_EQUAL(val8_1, arr8[offset8+1]); - TEST_ASSERT_EQUAL(val8_2, arr8[offset8+2]); - TEST_ASSERT_EQUAL(val8_3, arr8[offset8+3]); + TEST_ASSERT_EQUAL(val8_1, arr8[offset8 + 1]); + TEST_ASSERT_EQUAL(val8_2, arr8[offset8 + 2]); + TEST_ASSERT_EQUAL(val8_3, arr8[offset8 + 3]); arr16[offset16] = val16_0; - arr16[offset16+1] = val16_1; - arr16[offset16+2] = val16_2; - arr16[offset16+3] = val16_3; + arr16[offset16 + 1] = val16_1; + arr16[offset16 + 2] = val16_2; + arr16[offset16 + 3] = val16_3; // Just to make sure compiler doesn't read stale data asm volatile("memw\n"); TEST_ASSERT_EQUAL(val16_0, arr16[offset16]); - TEST_ASSERT_EQUAL(val16_1, arr16[offset16+1]); - TEST_ASSERT_EQUAL(val16_2, arr16[offset16+2]); - TEST_ASSERT_EQUAL(val16_3, arr16[offset16+3]); + TEST_ASSERT_EQUAL(val16_1, arr16[offset16 + 1]); + TEST_ASSERT_EQUAL(val16_2, arr16[offset16 + 2]); + TEST_ASSERT_EQUAL(val16_3, arr16[offset16 + 3]); // LoadStoreAlignement Error @@ -112,7 +112,7 @@ TEST_CASE("LoadStore Exception handler", "[freertos]") *ptr32_2 = val2; // Just to make sure compiler doesn't read stale data - asm volatile ("memw"); + asm volatile("memw"); TEST_ASSERT_EQUAL(0x73, *ptr8_0); TEST_ASSERT_EQUAL(val0, *ptr32_0); TEST_ASSERT_EQUAL(0x73, *ptr8_1); diff --git a/tools/ci/astyle-rules.yml b/tools/ci/astyle-rules.yml index 21b758a283..c89c97d9cc 100644 --- a/tools/ci/astyle-rules.yml +++ b/tools/ci/astyle-rules.yml @@ -38,7 +38,8 @@ components_not_formatted_temporary: # To reformat the files: # - Remove the directory from this exclude list # - Run 'git add .astyle-rules.yml' - # - Run 'pre-commit run --all-files' + # - Run 'pre-commit run --all-files' to run all pre-commit hooks + # - Run 'pre-commit run astyle_py --all-files' to run only the astyle_py hook # 2. If no, move it to 'components_not_formatted_permanent' section below. check: false include: @@ -74,7 +75,6 @@ components_not_formatted_temporary: - "/components/espcoredump/" - "/components/esptool_py/" - "/components/fatfs/" - - "/components/freertos/" - "/components/hal/" - "/components/heap/" - "/components/idf_test/" @@ -152,10 +152,13 @@ components_not_formatted_permanent: - "/components/console/linenoise/" # Catch (upstream source code) - "/tools/catch/catch.hpp" - # FreeRTOS kernel files (upstream source code). + # FreeRTOS kernel files (upstream source code) - "/components/freertos/FreeRTOS-Kernel/" - "/components/freertos/FreeRTOS-Kernel-SMP/" - - "/components/freertos/FreeRTOS-Kernel-V10.5.1/" + # FreeRTOS additions to the upstream source code + - "/components/freertos/esp_additions/" + # FreeRTOS config files maintained in upstream format + - "/components/freertos/config/" # Segger SystemView (upstream source code). # Could also try to find suitable astyle options, instead. - "/components/app_trace/sys_view/Config/"