Add SMP disable multiple priorities on target test (#1171)

* Add SMP disable multiple priorities on target test

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com>
pull/1172/head^2
chinglee-iot 11 months ago committed by GitHub
parent 731a4f05fd
commit ec0eae4c0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.13)
project(example C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(TEST_INCLUDE_PATHS ${CMAKE_CURRENT_LIST_DIR}/../../../../../tests/smp/disable_multiple_priorities)
set(TEST_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../tests/smp/disable_multiple_priorities)
add_library(disable_multiple_priorities INTERFACE)
target_sources(disable_multiple_priorities INTERFACE
${BOARD_LIBRARY_DIR}/main.c
${CMAKE_CURRENT_LIST_DIR}/disable_multiple_priorities_test_runner.c
${TEST_SOURCE_DIR}/disable_multiple_priorities.c)
target_include_directories(disable_multiple_priorities INTERFACE
${CMAKE_CURRENT_LIST_DIR}/../../..
${TEST_INCLUDE_PATHS}
)
target_link_libraries(disable_multiple_priorities INTERFACE
FreeRTOS-Kernel
FreeRTOS-Kernel-Heap4
${BOARD_LINK_LIBRARIES})
add_executable(test_disable_multiple_priorities)
enable_board_functions(test_disable_multiple_priorities)
target_link_libraries(test_disable_multiple_priorities disable_multiple_priorities)
target_include_directories(test_disable_multiple_priorities PUBLIC
${BOARD_INCLUDE_PATHS})
target_compile_definitions(test_disable_multiple_priorities PRIVATE
${BOARD_DEFINES}
)

@ -0,0 +1,73 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/**
* @file disable_multiple_priorities_test_runner.c
* @brief The implementation of main function to start test runner task.
*
* Procedure:
* - Initialize environment.
* - Run the test case.
*/
/* Kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Unit testing support functions. */
#include "unity.h"
/* Pico includes. */
#include "pico/multicore.h"
#include "pico/stdlib.h"
/*-----------------------------------------------------------*/
static void prvTestRunnerTask( void * pvParameters );
/*-----------------------------------------------------------*/
static void prvTestRunnerTask( void * pvParameters )
{
( void ) pvParameters;
/* Run test case. */
vRunDisableMultiplePrioritiesTest();
vTaskDelete( NULL );
}
/*-----------------------------------------------------------*/
void vRunTest( void )
{
xTaskCreate( prvTestRunnerTask,
"testRunner",
configMINIMAL_STACK_SIZE,
NULL,
configMAX_PRIORITIES - 1,
NULL );
}
/*-----------------------------------------------------------*/

@ -0,0 +1,244 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/**
* @file disable_multiple_priorities.c
* @brief The user shall be able to configure the scheduler to not run a
* lower priority task and a higher priority task simultaneously.
*
* Procedure:
* - Create ( num of cores ) test tasks ( T0~Tn-1 ). Priority T0 > T1 > ... > Tn-2 > Tn-1.
* - Verify the following conditions:
* - for each task Ti in [T0..Tn-1]:
* - Tasks T0~Ti-1 are in suspended state.
* - Task Ti is running.
* - Tasks Ti+1~Tn-1 are in ready state.
* - Suspend task Ti.
* Expected:
* - Only one task is running at the same time since all the test test tasks
* are of different priorities.
*/
/* Standard includes. */
#include <stdint.h>
/* Kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Unit testing support functions. */
#include "unity.h"
/*-----------------------------------------------------------*/
/**
* @brief Timeout value to stop test.
*/
#define TEST_TIMEOUT_MS ( 1000 )
/*-----------------------------------------------------------*/
#if ( configNUMBER_OF_CORES < 2 )
#error This test is for FreeRTOS SMP and therefore, requires at least 2 cores.
#endif /* if configNUMBER_OF_CORES != 2 */
#if ( configRUN_MULTIPLE_PRIORITIES != 0 )
#error configRUN_MULTIPLE_PRIORITIES must be disabled by including test_config.h in FreeRTOSConfig.h.
#endif /* if configRUN_MULTIPLE_PRIORITIES != 0 */
#if ( configUSE_CORE_AFFINITY != 0 )
#error configUSE_CORE_AFFINITY must be disabled by including test_config.h in FreeRTOSConfig.h.
#endif /* if configUSE_CORE_AFFINITY != 0 */
#if ( configMAX_PRIORITIES <= ( configNUMBER_OF_CORES + 2 ) )
#error This test creates tasks with different priority, requires configMAX_PRIORITIES to be larger than configNUMBER_OF_CORES.
#endif /* if ( configMAX_PRIORITIES <= ( configNUMBER_OF_CORES + 2 ) ) */
/*-----------------------------------------------------------*/
/**
* @brief Test case "Disable Multiple Priorities".
*/
void Test_DisableMultiplePriorities( void );
/**
* @brief Task function that verifies that it is the only running task.
*/
static void prvCheckRunningTask( void * pvParameters );
/*-----------------------------------------------------------*/
/**
* @brief Handles of the tasks created in this test.
*/
static TaskHandle_t xTaskHandles[ configNUMBER_OF_CORES ];
/**
* @brief Indexes of the tasks created in this test.
*/
static uint32_t xTaskIndexes[ configNUMBER_OF_CORES ];
/**
* @brief Test results.
*/
static BaseType_t xTestResults[ configNUMBER_OF_CORES ] = { pdFAIL };
/*-----------------------------------------------------------*/
static void prvCheckRunningTask( void * pvParameters )
{
uint32_t i = 0;
uint32_t currentTaskIdx = *( ( uint32_t * ) pvParameters );
eTaskState taskState;
BaseType_t xTestResult = pdPASS;
for( i = 0; i < configNUMBER_OF_CORES; i++ )
{
/* All the test tasks are created by the test runner task which runs
* at the highest priority. The test runs with multiple priorities
* disabled. Therefore, xTaskHandles[ i ] can not be NULL because none
* of the test tasks can run until the test runner task has created all
* the tasks and then blocked itself by calling vTaskDelay. Return
* pdFAIL in xTestResults to indicate test failure if any of the test
* task is not created yet. */
if( xTaskHandles[ i ] == NULL )
{
xTestResult = pdFAIL;
}
else
{
taskState = eTaskGetState( xTaskHandles[ i ] );
if( i > currentTaskIdx )
{
/* Tasks with index greater than current task are of lower
* priority than the current task and must be in the ready
* state. */
if( taskState != eReady )
{
xTestResult = pdFAIL;
}
}
else if( i == currentTaskIdx )
{
/* Current task must be running. */
if( taskState != eRunning )
{
xTestResult = pdFAIL;
}
}
else
{
/* Tasks with index smaller than current task are of higher
* priority than the current task and must be in the suspended
* state. */
if( taskState != eSuspended )
{
xTestResult = pdFAIL;
}
}
}
if( xTestResult != pdPASS )
{
break;
}
}
xTestResults[ currentTaskIdx ] = xTestResult;
/* Suspend the test task itself. */
vTaskSuspend( NULL );
}
/*-----------------------------------------------------------*/
void Test_DisableMultiplePriorities( void )
{
uint32_t i;
BaseType_t xTaskCreationResult;
/* Create configNUMBER_OF_CORES low priority tasks. */
for( i = 0; i < configNUMBER_OF_CORES; i++ )
{
xTaskCreationResult = xTaskCreate( prvCheckRunningTask,
"CheckRunning",
configMINIMAL_STACK_SIZE * 2,
&xTaskIndexes[ i ],
configMAX_PRIORITIES - 2 - i,
&xTaskHandles[ i ] );
TEST_ASSERT_EQUAL_MESSAGE( pdPASS, xTaskCreationResult, "Task creation failed." );
}
/* Waiting for all the test tasks. */
vTaskDelay( pdMS_TO_TICKS( TEST_TIMEOUT_MS ) );
/* Verify test results for all the tasks. */
for( i = 0; i < configNUMBER_OF_CORES; i++ )
{
TEST_ASSERT_EQUAL_MESSAGE( pdPASS, xTestResults[ i ], "Task test result is pdFAIL" );
}
}
/*-----------------------------------------------------------*/
/* Runs before every test, put init calls here. */
void setUp( void )
{
uint32_t i;
/* Initialize variables. */
for( i = 0; i < configNUMBER_OF_CORES; i++ )
{
xTaskHandles[ i ] = NULL;
xTaskIndexes[ i ] = i;
}
}
/*-----------------------------------------------------------*/
/* Runs after every test, put clean-up calls here. */
void tearDown( void )
{
uint32_t i;
/* Delete all the tasks. */
for( i = 0; i < configNUMBER_OF_CORES; i++ )
{
if( xTaskHandles[ i ] != NULL )
{
vTaskDelete( xTaskHandles[ i ] );
xTaskHandles[ i ] = NULL;
}
}
}
/*-----------------------------------------------------------*/
/**
* @brief Entry point for test runner to run disable multiple priorities test.
*/
void vRunDisableMultiplePrioritiesTest( void )
{
UNITY_BEGIN();
RUN_TEST( Test_DisableMultiplePriorities );
UNITY_END();
}
/*-----------------------------------------------------------*/

@ -0,0 +1,73 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef TEST_CONFIG_H
#define TEST_CONFIG_H
/* This file must be included at the end of the FreeRTOSConfig.h. It contains
* any FreeRTOS specific configurations that the test requires. */
#ifdef configRUN_MULTIPLE_PRIORITIES
#undef configRUN_MULTIPLE_PRIORITIES
#endif /* ifdef configRUN_MULTIPLE_PRIORITIES */
#ifdef configUSE_CORE_AFFINITY
#undef configUSE_CORE_AFFINITY
#endif /* ifdef configUSE_CORE_AFFINITY */
#ifdef configUSE_MINIMAL_IDLE_HOOK
#undef configUSE_MINIMAL_IDLE_HOOK
#endif /* ifdef configUSE_MINIMAL_IDLE_HOOK */
#ifdef configUSE_TASK_PREEMPTION_DISABLE
#undef configUSE_TASK_PREEMPTION_DISABLE
#endif /* ifdef configUSE_TASK_PREEMPTION_DISABLE */
#ifdef configUSE_TIME_SLICING
#undef configUSE_TIME_SLICING
#endif /* ifdef configUSE_TIME_SLICING */
#ifdef configUSE_PREEMPTION
#undef configUSE_PREEMPTION
#endif /* ifdef configUSE_PREEMPTION */
#define configRUN_MULTIPLE_PRIORITIES 0
#define configUSE_CORE_AFFINITY 0
#define configUSE_MINIMAL_IDLE_HOOK 0
#define configUSE_TASK_PREEMPTION_DISABLE 0
#define configUSE_TIME_SLICING 1
#define configUSE_PREEMPTION 1
/*-----------------------------------------------------------*/
/**
* @brief Entry point for test runner to run disable multiple priorities test.
*/
void vRunDisableMultiplePrioritiesTest( void );
/*-----------------------------------------------------------*/
#endif /* ifndef TEST_CONFIG_H */
Loading…
Cancel
Save