Skip to content

Commit

Permalink
Add SMP schedule equal priority on target test (FreeRTOS#1170)
Browse files Browse the repository at this point in the history
* Add SMP schedule equal priority on target test

* Remove unnecessary config

* Fix spelling format and header

* Code review suggestions

Signed-off-by: Gaurav Aggarwal <[email protected]>

---------

Signed-off-by: Gaurav Aggarwal <[email protected]>
Co-authored-by: Gaurav Aggarwal <[email protected]>
Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
Co-authored-by: Rahul Kar <[email protected]>
  • Loading branch information
4 people authored Feb 8, 2024
1 parent 3878dd9 commit 2f85ed9
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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/schedule_equal_priority)
set(TEST_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../tests/smp/schedule_equal_priority)

add_library(schedule_equal_priority INTERFACE)
target_sources(schedule_equal_priority INTERFACE
${BOARD_LIBRARY_DIR}/main.c
${CMAKE_CURRENT_LIST_DIR}/schedule_equal_priority_test_runner.c
${TEST_SOURCE_DIR}/schedule_equal_priority.c)

target_include_directories(schedule_equal_priority INTERFACE
${CMAKE_CURRENT_LIST_DIR}/../../..
${TEST_INCLUDE_PATHS}
)

target_link_libraries(schedule_equal_priority INTERFACE
FreeRTOS-Kernel
FreeRTOS-Kernel-Heap4
${BOARD_LINK_LIBRARIES})

add_executable(test_schedule_equal_priority)
enable_board_functions(test_schedule_equal_priority)
target_link_libraries(test_schedule_equal_priority schedule_equal_priority)
target_include_directories(test_schedule_equal_priority PUBLIC
${BOARD_INCLUDE_PATHS})
target_compile_definitions(test_schedule_equal_priority PRIVATE
${BOARD_DEFINES}
)
Original file line number Diff line number Diff line change
@@ -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 schedule_equal_priority_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. */
vRunScheduleEqualPriorityTest();

vTaskDelete( NULL );
}
/*-----------------------------------------------------------*/

void vRunTest( void )
{
xTaskCreate( prvTestRunnerTask,
"testRunner",
configMINIMAL_STACK_SIZE,
NULL,
configMAX_PRIORITIES - 1,
NULL );
}
/*-----------------------------------------------------------*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* 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 schedule_equal_priority.c
* @brief The scheduler shall schedule tasks of equal priority in a round robin fashion.
*
* Procedure:
* - Create ( num of cores + 1 ) tasks ( T0~Tn ). Priority T0 = T1 = ... = Tn-1 = Tn.
* - All tasks are running in busy loop.
* Expected:
* - Equal priority tasks are scheduled in a round robin fashion when configUSE_TIME_SLICING
* is set to 1. Verify that all the test tasks get chance to run.
*/

/* 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_TICKS ( ( configNUMBER_OF_CORES + 1U ) * 2U )

/**
* @brief Nop operation for busy looping.
*/
#ifndef portNOP
#define TEST_NOP() __asm volatile ( "nop" )
#else
#define TEST_NOP portNOP
#endif
/*-----------------------------------------------------------*/

#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 ( configUSE_TIME_SLICING != 1 )
#error configUSE_TIME_SLICING must be enabled by including test_config.h in FreeRTOSConfig.h.
#endif /* if configUSE_TIME_SLICING != 1 */

#if ( configMAX_PRIORITIES <= 2 )
#error configMAX_PRIORITIES must be larger than 2 to avoid scheduling idle tasks unexpectedly.
#endif /* if ( configMAX_PRIORITIES <= 2 ) */
/*-----------------------------------------------------------*/

/**
* @brief Test case "schedule equal priority tasks.".
*/
void Test_ScheduleEqualPriority( void );

/**
* @brief Function that implements a never blocking FreeRTOS task.
*/
static void prvEverRunningTask( void * pvParameters );
/*-----------------------------------------------------------*/

/**
* @brief Handles of the tasks created in this test.
*/
static TaskHandle_t xTaskHandles[ configNUMBER_OF_CORES + 1 ];

/**
* @brief Flags to indicate that all ever running tasks get a chance to run.
*/
static BaseType_t xTaskRun[ configNUMBER_OF_CORES + 1 ];
/*-----------------------------------------------------------*/

static void prvEverRunningTask( void * pvParameters )
{
BaseType_t * pxTaskRun = ( ( BaseType_t * ) pvParameters );

/* Set the flag for testRunner to check whether all tasks have run. */
if( pxTaskRun != NULL )
{
*pxTaskRun = pdTRUE;
}

for( ; ; )
{
/* Always running, put asm here to avoid optimization by compiler. */
TEST_NOP();
}
}
/*-----------------------------------------------------------*/

void Test_ScheduleEqualPriority( void )
{
uint32_t i;
BaseType_t xTaskCreationResult;

/* Create ( configNUMBER_OF_CORES + 1 ) low priority tasks. */
for( i = 0; i < ( configNUMBER_OF_CORES + 1 ); i++ )
{
xTaskCreationResult = xTaskCreate( prvEverRunningTask,
"EverRun",
configMINIMAL_STACK_SIZE,
&( xTaskRun[ i ] ),
configMAX_PRIORITIES - 2,
&( xTaskHandles[ i ] ) );

TEST_ASSERT_EQUAL_MESSAGE( pdPASS, xTaskCreationResult, "Task creation failed." );
}

/* TEST_TIMEOUT_TICKS is long enough to run each task. */
vTaskDelay( TEST_TIMEOUT_TICKS );

for( i = 0; i < ( configNUMBER_OF_CORES + 1 ); i++ )
{
/* After timeout, all tasks must have been scheduled at least once and
* have set their corresponding flag to pdTRUE. */
TEST_ASSERT_EQUAL( pdTRUE, xTaskRun[ i ] );
}
}
/*-----------------------------------------------------------*/

/* Runs before every test, put init calls here. */
void setUp( void )
{
uint32_t i;

for( i = 0; i < ( configNUMBER_OF_CORES + 1 ); i++ )
{
xTaskRun[ i ] = pdFALSE;
xTaskHandles[ i ] = NULL;
}
}
/*-----------------------------------------------------------*/

/* 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 + 1 ); i++ )
{
if( xTaskHandles[ i ] != NULL )
{
vTaskDelete( xTaskHandles[ i ] );
xTaskHandles[ i ] = NULL;
}
}
}
/*-----------------------------------------------------------*/

/**
* @brief Entry point for test runner to run schedule equal priority test.
*/
void vRunScheduleEqualPriorityTest( void )
{
UNITY_BEGIN();

RUN_TEST( Test_ScheduleEqualPriority );

UNITY_END();
}
/*-----------------------------------------------------------*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 configUSE_TIME_SLICING
#undef configUSE_TIME_SLICING
#endif /* ifdef configUSE_TIME_SLICING */

#ifdef configUSE_PREEMPTION
#undef configUSE_PREEMPTION
#endif /* ifdef configUSE_PREEMPTION */

#define configUSE_TIME_SLICING 1
#define configUSE_PREEMPTION 1

/*-----------------------------------------------------------*/

/**
* @brief Entry point for test runner to run schedule equal priority test.
*/
void vRunScheduleEqualPriorityTest( void );

/*-----------------------------------------------------------*/

#endif /* ifndef TEST_CONFIG_H */

0 comments on commit 2f85ed9

Please sign in to comment.