Add CodeSonar example directory

This commit is contained in:
Mark Hermeling 2024-05-23 15:58:20 +00:00
parent 27c4feff66
commit 940dad1d0c
4 changed files with 319 additions and 0 deletions

View file

@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.15)
project(codesonar)
set(FREERTOS_KERNEL_PATH "../..")
FILE(GLOB FREERTOS_KERNEL_SOURCE ${FREERTOS_KERNEL_PATH}/*.c)
FILE(GLOB FREERTOS_PORT_CODE ${FREERTOS_KERNEL_PATH}/portable/template/*.c)
# Add the freertos_config for FreeRTOS-Kernel.
add_library(freertos_config INTERFACE)
target_include_directories(freertos_config
INTERFACE
./)
if (DEFINED FREERTOS_SMP_EXAMPLE AND FREERTOS_SMP_EXAMPLE STREQUAL "1")
message(STATUS "Build FreeRTOS SMP example")
# Adding the following configurations to build SMP template port
add_compile_options( -DconfigNUMBER_OF_CORES=2 -DconfigUSE_PASSIVE_IDLE_HOOK=0 )
endif()
# Select the heap. Values between 1-5 will pick a heap.
set(FREERTOS_HEAP "3" CACHE STRING "" FORCE)
# Select the FreeRTOS port.
set(FREERTOS_PORT "TEMPLATE" CACHE STRING "" FORCE)
# Add the FreeRTOS-Kernel subdirectory.
add_subdirectory(${FREERTOS_KERNEL_PATH} FreeRTOS-Kernel)
add_executable(${PROJECT_NAME}
../cmake_example/main.c)
target_link_libraries(${PROJECT_NAME} freertos_kernel freertos_config)

View file

@ -0,0 +1,135 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* 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 FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/******************************************************************************/
/* Hardware description related definitions. **********************************/
/******************************************************************************/
#define configCPU_CLOCK_HZ ( ( unsigned long ) 20000000 )
/******************************************************************************/
/* Scheduling behaviour related definitions. **********************************/
/******************************************************************************/
#define configTICK_RATE_HZ ( 100U )
#define configUSE_PREEMPTION 1
#define configUSE_TIME_SLICING 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_TICKLESS_IDLE 1
#define configMAX_PRIORITIES 5U
#define configMINIMAL_STACK_SIZE 128U
#define configMAX_TASK_NAME_LEN 4U
#define configTICK_TYPE_WIDTH_IN_BITS TICK_TYPE_WIDTH_64_BITS
#define configIDLE_SHOULD_YIELD 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 1U
#define configQUEUE_REGISTRY_SIZE 0U
#define configENABLE_BACKWARD_COMPATIBILITY 1
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0
#define configSTACK_DEPTH_TYPE size_t
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
#define configUSE_NEWLIB_REENTRANT 0
/******************************************************************************/
/* Software timer related definitions. ****************************************/
/******************************************************************************/
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1U )
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
#define configTIMER_QUEUE_LENGTH 10U
/******************************************************************************/
/* Memory allocation related definitions. *************************************/
/******************************************************************************/
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 4096U
#define configAPPLICATION_ALLOCATED_HEAP 1
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
#define configUSE_MINI_LIST_ITEM 0
/******************************************************************************/
/* Interrupt nesting behaviour configuration. *********************************/
/******************************************************************************/
#define configKERNEL_INTERRUPT_PRIORITY 0U
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 0U
#define configMAX_API_CALL_INTERRUPT_PRIORITY 0U
/******************************************************************************/
/* Hook and callback function related definitions. ****************************/
/******************************************************************************/
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
/******************************************************************************/
/* Run time and task stats gathering related definitions. *********************/
/******************************************************************************/
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
#define configKERNEL_PROVIDED_STATIC_MEMORY 1
/******************************************************************************/
/* Definitions that include or exclude functionality. *************************/
/******************************************************************************/
#define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_QUEUE_SETS 1
#define configUSE_APPLICATION_TASK_TAG 1
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_xTaskResumeFromISR 1
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,39 @@
# MISRA Compliance for FreeRTOS-Kernel
FreeRTOS-Kernel is MISRA C:2012 compliant. This directory contains a project to
run [CodeSecure CodeSonar](https://codesecure.com/our-products/codesonar/)
for checking MISRA compliance.
Deviations from the MISRA C:2012 guidelines are documented in
[MISRA.md](../../MISRA.md) and [codesonar.con](codesonar.conf)
files.
## Getting Started
### Prerequisites
CodeSonar can be run on a large number of platforms, see the CodeSonar documentation for more information. To run CodeSonar, one would require the following step:
1. CMake version > 3.13.0 (You can check whether you have this by typing `cmake --version`).
2. GCC compiler.
- See download and installation instructions [here](https://gcc.gnu.org/install/).
3. Clone the repo using the following command:
- `git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git ./FreeRTOS-Kernel`
### Generating Report
Perform an analysis with CodeSonar through the following steps:
Singe core FreeRTOS:
~~~
cmake -B build -S examples/codesonar
~~~
SMP FreeRTOS:
~~~
cmake -B build -S examples/codesonar -DFREERTOS_SMP_EXAMPLE=1
~~~
Build and analyze the (pseudo) application:
~~~
cd build/
codesonar analyze freertos -preset misra2012 -conf-file ../examples/codesonar/codesonar.conf <hub-url> make
~~~
Generate the HTML report by going to the CodeSonar web interface for the analysis and Generate Report for MISRA 2012

View file

@ -0,0 +1,108 @@
# "deviation": "Rule 3.1",
# "reason": "We post HTTP links in code comments which contain // inside comments blocks."
WARNING_FILTER += discard class="/* in Comment" language=c
WARNING_FILTER += discard class="// in Comment" language=c
# "deviation": "Rule 14.4",
# "reason": "do while( 0 ) pattern is used in macros to prevent extra semi-colon."
WARNING_FILTER += discard class="Condition Is Not Boolean" language=c
# "deviation": "Directive 4.4",
# "reason": "Code snippet is used in comment to help explanation."
WARNING_FILTER += discard class="Commented-out Code" language=c
# "deviation": "Directive 4.5",
# "reason": "discard names that MISRA considers ambiguous."
WARNING_FILTER += discard class="Typographically Ambiguous Identifiers" language=c
# "deviation": "Directive 4.6",
# "reason": "discard port to use primitive type with typedefs."
WARNING_FILTER += discard class="Basic Numerical Type Used" language=c
# "deviation": "Directive 4.9",
# "reason": "FreeRTOS-Kernel is optimised to work on small micro-controllers. To achieve that, function-like macros are used."
WARNING_FILTER += discard class="Function-Like Macro" language=c
# "deviation": "Rule 2.3",
# "reason": "FreeRTOS defines types which is used in application."
WARNING_FILTER += discard class="Unused Type" language=c
# "deviation": "Rule 2.4",
# "reason": "discard to define unused tag."
WARNING_FILTER += discard class="Unused Tag" language=c
# "deviation": "Rule 2.5",
# "reason": "discard to define unused macro."
WARNING_FILTER += discard class="Unused Macro" language=c
# "deviation": "Rule 5.9",
# "reason": "discard to define identifier with the same name in structure and global variable."
WARNING_FILTER += discard class="Library Function Override" language=c
WARNING_FILTER += discard class="Non-unique Identifiers: Internal Name" language=c
# "deviation": "Rule 8.7",
# "reason": "API functions are not used by the library outside of the files they are defined; however, they must be externally visible in order to be used by an application."
WARNING_FILTER += discard class="Scope Could Be File Static" language=c
WARNING_FILTER += discard class="Scope Could Be Local Static" language=c
WARNING_FILTER += discard class="Declaration of Flexible Array Member" language=c
# "deviation": "Rule 8.9",
# "reason": "Allow to object to be defined in wider scope for debug purpose."
WARNING_FILTER += discard class="Scope Could Be Local Static" language=c
# "deviation": "Rule 8.13",
# "reason": "Allow to not to use const-qualified type for callback function."
WARNING_FILTER += discard class="Pointed-to Type Could Be const" language=c
# "deviation": "Rule 11.4",
# "reason": "Allow to convert between a pointer to object and an interger type for stack alignment."
WARNING_FILTER += discard class="Conversion: Pointer/Integer" language=c
# "deviation": "Rule 15.4",
# "reason": "Allow to use multiple break statements in a loop."
WARNING_FILTER += discard class="Multiple Abnormal Loop Exits" language=c
# "deviation": "Rule 15.5",
# "reason": "Allow to use multiple points of exit."
WARNING_FILTER += discard class="Misplaced Return Statement" language=c
WARNING_FILTER += discard class="Multiple Return Statements" language=c
# "deviation": "Rule 17.8",
# "reason": "Allow to update the parameters of a function."
WARNING_FILTER += discard class="Modified Parameter" language=c
# "deviation": "Rule 18.4",
# "reason": "Allow to use pointer arithmetic."
WARNING_FILTER += discard class="Pointer Arithmetic" language=c
# "deviation": "Rule 19.2",
# "reason": "Allow to use union."
WARNING_FILTER += discard class="Bit-field in Union" language=c
WARNING_FILTER += discard class="Union Type" language=c
# "deviation": "Rule 20.5",
# "reason": "Allow to use #undef for MPU wrappers."
WARNING_FILTER += discard class="Macro Undefinition of Reserved Name" language=c
WARNING_FILTER += discard class="Use of #undef" language=c
#Difference from the Coverity set
#"deviation": "Rule 1.1",
#"reason": "-Wall and -Werror throws errors for unused functions and a lot more"
WARNING_FILTER += discard class="Not All Warnings Are Enabled"
WARNING_FILTER += discard class="Warnings Not Treated As Errors"
#"deviation" : "Rule 20.1"
#"reason" : "Some code before inclusion of board specific files"
WARNING_FILTER += discard class="Code Before #include"
#"deviation": "Rule 20.2",
#"reason": "Some include paths come from different directories"
WARNING_FILTER += discard class="Dangerous Include File Name"
# we want to use _Noreturn to satisfy 17.11
WARNING_FILTER += discard class="Use of Noreturn"