Skip to content

Commit

Permalink
Merge branch 'add-async-core-yield-test' of https://github.com/chingl…
Browse files Browse the repository at this point in the history
…ee-iot/FreeRTOS into add-async-core-yield-test
  • Loading branch information
chinglee-iot committed Aug 20, 2024
2 parents 30c0cfb + 0f52255 commit 575d0e4
Show file tree
Hide file tree
Showing 18 changed files with 1,355 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ static UBaseType_t ulNextRand;

void main_tcp_echo_client_tasks( void )
{
BaseType_t xResult;
const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );

/*
Expand All @@ -157,8 +158,6 @@ void main_tcp_echo_client_tasks( void )
/* Initialise the network interface.*/
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\r\n" ) );

memcpy( ipLOCAL_MAC_ADDRESS, ucMACAddress, sizeof( ucMACAddress ) );

#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
extern NetworkInterface_t * pxLibslirp_FillInterfaceDescriptor( BaseType_t xEMACIndex,
NetworkInterface_t * pxInterface );
Expand All @@ -173,12 +172,14 @@ void main_tcp_echo_client_tasks( void )
}
#endif /* ( ipconfigUSE_DHCP != 0 ) */

FreeRTOS_IPInit_Multi();
xResult = FreeRTOS_IPInit_Multi();
#else /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
xResult = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#endif /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */

configASSERT( xResult == pdTRUE );

/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\n" ) );
vTaskStartScheduler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ static UBaseType_t ulNextRand;

void main_tcp_echo_client_tasks( void )
{
BaseType_t xReturn;
const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );

/*
Expand Down Expand Up @@ -180,12 +181,13 @@ void main_tcp_echo_client_tasks( void )
}
#endif /* ( ipconfigUSE_DHCP != 0 ) */

FreeRTOS_IPInit_Multi();
xReturn = FreeRTOS_IPInit_Multi();
#else /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
xReturn = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */

configASSERT( xReturn == pdTRUE );

/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\n" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ NetworkInterface_t * pxWinPcap_FillInterfaceDescriptor( BaseType_t xEMACIndex,

int main( void )
{
BaseType_t xReturn;
const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );

/*
Expand Down Expand Up @@ -314,7 +315,9 @@ int main( void )
}
#endif /* ( mainNETWORK_UP_COUNT >= 3U ) */

FreeRTOS_IPInit_Multi();
xReturn = FreeRTOS_IPInit_Multi();

configASSERT( xReturn == pdTRUE );

/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\r\n" ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ static UBaseType_t ulNextRand;

int main( void )
{
BaseType_t xResult;
const uint32_t ulLongTime_ms = 250UL;

/* Create a mutex that is used to guard against the console being accessed
Expand Down Expand Up @@ -157,13 +158,15 @@ int main( void )
xEndPoints[ 0 ].bits.bWantDHCP = pdTRUE;
}
#endif /* ( ipconfigUSE_DHCP != 0 ) */
memcpy( ipLOCAL_MAC_ADDRESS, ucMACAddress, sizeof( ucMACAddress ) );
FreeRTOS_IPInit_Multi();

xResult = FreeRTOS_IPInit_Multi();
#else /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
xResult = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */

configASSERT( xResult == pdTRUE );

/* Initialise the logging. */
uint32_t ulLoggingIPAddress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void vPlatformInitIpStack( void )
xEndPoints[ 0 ].bits.bWantDHCP = pdTRUE;
}
#endif /* ( ipconfigUSE_DHCP != 0 ) */
memcpy( ipLOCAL_MAC_ADDRESS, ucMACAddress, sizeof( ucMACAddress ) );

xResult = FreeRTOS_IPInit_Multi();
#else /* if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
/* Using the old /single /IPv4 library, or using backward compatible mode of the new /multi library. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,62 +1337,6 @@ void test_coverage_vTaskCoreAffinitySet_null_task_handle( void )
TEST_ASSERT_EQUAL( pdTRUE, xYieldPendings[ 0 ] );
}

/**
* @brief vTaskCoreAffinitySet - no new core for task which is not running.
*
* Set core mask for a not running task. The new core mask doesn't enable the task
* to run on any new core. Verify the core mask set is correct.
*
* <b>Coverage</b>
* @code{c}
* if( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE )
* {
* ...
* }
* else
* {
* if( ( uxPrevNotAllowedCores & uxCoreAffinityMask ) != 0U )
* {
* prvYieldForTask( pxTCB );
* }
* }
* @endcode
* ( taskTASK_IS_RUNNING( pxTCB ) == pdTRUE ) is false.
* ( ( uxPrevNotAllowedCores & uxCoreAffinityMask ) != 0U ) is false.
*/
void test_coverage_vTaskCoreAffinitySet_task_not_running_no_new_core( void )
{
TCB_t xTaskTCB = { NULL };
UBaseType_t uxCoreAffinityMask;
UBaseType_t uxNewCoreAffinityMask;

/* Setup the variables and structure. */
/* This task is allowed to run on core 0 and core 1 only. */
uxCoreAffinityMask = ( 1U << 0 ) | ( 1U << 1 );
vCreateStaticTestTaskAffinity( &xTaskTCB,
uxCoreAffinityMask,
tskIDLE_PRIORITY,
configNUMBER_OF_CORES,
pdFALSE );
xSchedulerRunning = pdTRUE;

/* Expectations. */
vFakePortEnterCriticalSection_StubWithCallback( NULL );
vFakePortExitCriticalSection_StubWithCallback( NULL );
vFakePortCheckIfInISR_StopIgnore();

vFakePortEnterCriticalSection_Expect();
vFakePortExitCriticalSection_Expect();

/* API call. */
/* No new core is enabled for this task. */
uxNewCoreAffinityMask = ( 1U << 0 );
vTaskCoreAffinitySet( &xTaskTCB, uxNewCoreAffinityMask );

/* Validations. */
TEST_ASSERT_EQUAL( uxNewCoreAffinityMask, xTaskTCB.uxCoreAffinityMask );
}

/**
* @brief prvYieldForTask - running task with xTaskRunState equals to configNUMBER_OF_CORES.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.13)

set(TEST_INCLUDE_PATHS ${CMAKE_CURRENT_LIST_DIR}/../../../../../tests/smp/interrupt_wait_critical)
set(TEST_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../tests/smp/interrupt_wait_critical)

add_library(interrupt_wait_critical INTERFACE)
target_sources(interrupt_wait_critical INTERFACE
${BOARD_LIBRARY_DIR}/main.c
${CMAKE_CURRENT_LIST_DIR}/interrupt_wait_critical_test_runner.c
${TEST_SOURCE_DIR}/interrupt_wait_critical.c)

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

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

add_executable(test_interrupt_wait_critical)
enable_board_functions(test_interrupt_wait_critical)
target_link_libraries(test_interrupt_wait_critical interrupt_wait_critical)
target_include_directories(test_interrupt_wait_critical PUBLIC
${BOARD_INCLUDE_PATHS})
target_compile_definitions(test_interrupt_wait_critical PRIVATE
${BOARD_DEFINES}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 only_one_task_enter_critical_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 );

extern void vRunInterruptWaitCriticalTest( void );

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

static void prvTestRunnerTask( void * pvParameters )
{
( void ) pvParameters;

/* Run test case. */
vRunInterruptWaitCriticalTest();

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,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/only_one_task_enter_critical)
set(TEST_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../../tests/smp/only_one_task_enter_critical)

add_library(only_one_task_enter_critical INTERFACE)
target_sources(only_one_task_enter_critical INTERFACE
${BOARD_LIBRARY_DIR}/main.c
${CMAKE_CURRENT_LIST_DIR}/only_one_task_enter_critical_test_runner.c
${TEST_SOURCE_DIR}/only_one_task_enter_critical.c)

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

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

add_executable(test_only_one_task_enter_critical)
enable_board_functions(test_only_one_task_enter_critical)
target_link_libraries(test_only_one_task_enter_critical only_one_task_enter_critical)
target_include_directories(test_only_one_task_enter_critical PUBLIC
${BOARD_INCLUDE_PATHS})
target_compile_definitions(test_only_one_task_enter_critical 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 only_one_task_enter_critical_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. */
vRunOnlyOneTaskEnterCriticalTest();

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

void vRunTest( void )
{
xTaskCreate( prvTestRunnerTask,
"testRunner",
configMINIMAL_STACK_SIZE,
NULL,
configMAX_PRIORITIES - 1,
NULL );
}
/*-----------------------------------------------------------*/
Loading

0 comments on commit 575d0e4

Please sign in to comment.