From 7de1b5098d80e3d6ea2f92ffd3b0c26776c9b904 Mon Sep 17 00:00:00 2001 From: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:57:49 +0530 Subject: [PATCH] Add separate compile option for tracing functionality in Posix demo (#1194) * Add compile option for enabling tracing in cmake file * --- FreeRTOS/Demo/Posix_GCC/CMakeLists.txt | 15 +++++++++--- FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h | 8 +++++- FreeRTOS/Demo/Posix_GCC/Makefile | 6 +++++ FreeRTOS/Demo/Posix_GCC/main.c | 31 +++++++++--------------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/FreeRTOS/Demo/Posix_GCC/CMakeLists.txt b/FreeRTOS/Demo/Posix_GCC/CMakeLists.txt index 4917ed3f21..199de7508b 100644 --- a/FreeRTOS/Demo/Posix_GCC/CMakeLists.txt +++ b/FreeRTOS/Demo/Posix_GCC/CMakeLists.txt @@ -10,10 +10,19 @@ else() add_compile_options( -DTRACE_ON_ENTER=0 ) endif() -if( ( COVERAGE_TEST ) OR ( NO_TRACING ) ) +if( COVERAGE_TEST ) set( COVERAGE_TEST 1 ) + set( NO_TRACING 1 ) add_compile_options( -DprojCOVERAGE_TEST=1 ) + add_compile_options( -DprojENABLE_TRACING=0 ) else() + if( NO_TRACING ) + set( NO_TRACING 1 ) + add_compile_options( -DprojENABLE_TRACING=0 ) + else() + set( NO_TRACING 0 ) + add_compile_options( -DprojENABLE_TRACING=1 ) + endif() set( COVERAGE_TEST 0 ) add_compile_options( -DprojCOVERAGE_TEST=0 ) endif() @@ -58,7 +67,7 @@ add_subdirectory( ${FREERTOS_KERNEL_PATH} ${CMAKE_CURRENT_BINARY_DIR}/FreeRTOS-K target_compile_options( freertos_kernel PRIVATE # Trace macro cast pointer to int to store memory management event - $ + $ ) file( GLOB FREERTOS_PLUS_TRACE_SOURCES ${FREERTOS_PLUS_TRACE_PATH}/*.c ${FREERTOS_PLUS_TRACE_PATH}/kernelports/FreeRTOS/*.c ) @@ -70,7 +79,7 @@ add_executable( posix_demo main_blinky.c main_full.c run-time-stats-utils.c - $<$:${FREERTOS_PLUS_TRACE_SOURCES}> + $<$:${FREERTOS_PLUS_TRACE_SOURCES}> ${CMAKE_CURRENT_LIST_DIR}/../Common/Minimal/AbortDelay.c ${CMAKE_CURRENT_LIST_DIR}/../Common/Minimal/BlockQ.c ${CMAKE_CURRENT_LIST_DIR}/../Common/Minimal/blocktim.c diff --git a/FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h b/FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h index 346b9fe786..df561108f1 100644 --- a/FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h @@ -128,6 +128,10 @@ extern void vAssertCalled( const char * const pcFileName, #error projCOVERAGE_TEST should be defined to 1 or 0 on the command line. #endif +#ifndef projENABLE_TRACING + #error projENABLE_TRACING should be defined to 1 or 0 on the command line. +#endif + #if ( projCOVERAGE_TEST == 1 ) /* Insert NOPs in empty decision paths to ensure both true and false paths @@ -154,7 +158,9 @@ extern void vAssertCalled( const char * const pcFileName, #define configUSE_MALLOC_FAILED_HOOK 1 /* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */ - #include "trcRecorder.h" + #if( projENABLE_TRACING == 1 ) + #include "trcRecorder.h" + #endif /* if ( projENABLE_TRACING == 1 ) */ #endif /* if ( projCOVERAGE_TEST == 1 ) */ /* networking definitions */ diff --git a/FreeRTOS/Demo/Posix_GCC/Makefile b/FreeRTOS/Demo/Posix_GCC/Makefile index ec5023b3bd..a3f09b1f2f 100644 --- a/FreeRTOS/Demo/Posix_GCC/Makefile +++ b/FreeRTOS/Demo/Posix_GCC/Makefile @@ -75,8 +75,14 @@ endif ifeq ($(COVERAGE_TEST),1) CPPFLAGS += -DprojCOVERAGE_TEST=1 + CPPFLAGS += -DprojENABLE_TRACING=0 CFLAGS += -Werror else + ifeq ($(NO_TRACING),1) + CPPFLAGS += -DprojENABLE_TRACING=0 + else + CPPFLAGS += -DprojENABLE_TRACING=1 + endif CPPFLAGS += -DprojCOVERAGE_TEST=0 # Trace library. SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/kernelports/FreeRTOS/trcKernelPort.c diff --git a/FreeRTOS/Demo/Posix_GCC/main.c b/FreeRTOS/Demo/Posix_GCC/main.c index a4ea05d951..52a9753c9b 100644 --- a/FreeRTOS/Demo/Posix_GCC/main.c +++ b/FreeRTOS/Demo/Posix_GCC/main.c @@ -68,7 +68,7 @@ /* Local includes. */ #include "console.h" -#if ( projCOVERAGE_TEST != 1 ) +#if ( projENABLE_TRACING == 1 ) #include #endif @@ -139,13 +139,6 @@ static void handle_sigint( int signal ); * in a different file. */ StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; -/* Notes if the trace is running or not. */ -#if ( projCOVERAGE_TEST == 1 ) - static BaseType_t xTraceRunning = pdFALSE; -#else - static BaseType_t xTraceRunning = pdTRUE; -#endif - static clockid_t cid = CLOCK_THREAD_CPUTIME_ID; /*-----------------------------------------------------------*/ @@ -155,8 +148,7 @@ int main( void ) /* SIGINT is not blocked by the posix port */ signal( SIGINT, handle_sigint ); - /* Do not include trace code when performing a code coverage analysis. */ - #if ( projCOVERAGE_TEST != 1 ) + #if ( projENABLE_TRACING == 1 ) { /* Initialise the trace recorder. Use of the trace recorder is optional. * See http://www.FreeRTOS.org/trace for more information. */ @@ -168,9 +160,9 @@ int main( void ) #if ( TRACE_ON_ENTER == 1 ) printf( "\r\nThe trace will be dumped to disk if Enter is hit.\r\n" ); - #endif + #endif /* if ( TRACE_ON_ENTER == 1 ) */ } - #endif /* if ( projCOVERAGE_TEST != 1 ) */ + #endif /* if ( projENABLE_TRACING == 1 ) */ console_init(); #if ( mainSELECTED_APPLICATION == BLINKY_DEMO ) @@ -281,10 +273,11 @@ void traceOnEnter() if( xReturn > 0 ) { - if( xTraceRunning == pdTRUE ) + #if ( projENABLE_TRACING == 1 ) { prvSaveTraceFile(); } + #endif /* if ( projENABLE_TRACING == 1 ) */ /* clear the buffer */ char buffer[ 1 ]; @@ -334,10 +327,11 @@ void vAssertCalled( const char * const pcFileName, { xPrinted = pdTRUE; - if( xTraceRunning == pdTRUE ) + #if ( projENABLE_TRACING == 1 ) { prvSaveTraceFile(); } + #endif /* if ( projENABLE_TRACING == 0 ) */ } /* You can step out of this function to debug the assertion by using @@ -353,10 +347,8 @@ void vAssertCalled( const char * const pcFileName, } /*-----------------------------------------------------------*/ -static void prvSaveTraceFile( void ) -{ - /* Tracing is not used when code coverage analysis is being performed. */ - #if ( projCOVERAGE_TEST != 1 ) +#if ( projENABLE_TRACING == 1 ) + static void prvSaveTraceFile( void ) { FILE * pxOutputFile; @@ -375,8 +367,7 @@ static void prvSaveTraceFile( void ) printf( "\r\nFailed to create trace dump file\r\n" ); } } - #endif /* if ( projCOVERAGE_TEST != 1 ) */ -} +#endif /* if ( projENABLE_TRACING == 1 ) */ /*-----------------------------------------------------------*/ /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an