Add coverity example (#870)
* Add coverity example * Update for CI * Fix for CI 2 * Update kernel_misra.config * Rename coverity example to coverity * Update FreeRTOSConfig.h for coverity project * Update MISRA.md * Move coverity config to coverity_misra.config * Update coverity misra config * Add README.md file * Update FreeRTOSConfig.h for coverity * Fix uncrustify and spell * Update README.md for relative link path Update README.md for relative link path * Update README.md for relative link 2 * Update MISRA.md for relateive path * Fix for format * Update coverity_misra.config * Update configuration folder * Update README.md for link * Code review suggestions Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> --------- Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal> Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Co-authored-by: Soren Ptak <ptaksoren@gmail.com> Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>pull/921/head
parent
ac7fc396a0
commit
5dbfd380f0
@ -0,0 +1,39 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(coverity)
|
||||
|
||||
set(FREERTOS_KERNEL_PATH "../../")
|
||||
FILE(GLOB FREERTOS_KERNEL_SOURCE ${FREERTOS_KERNEL_PATH}*.c)
|
||||
|
||||
# Coverity incorrectly infers the type of pdTRUE and pdFALSE as boolean because
|
||||
# of their names. This generates multiple false positive warnings about type
|
||||
# mismatch. Replace pdTRUE with pdPASS and pdFALSE with pdFAIL to avoid these
|
||||
# false positive warnings. This workaround will not be needed after Coverity
|
||||
# fixes the issue of incorrectly inferring the type of pdTRUE and pdFALSE as
|
||||
# boolean.
|
||||
add_custom_target(fix_source ALL
|
||||
COMMAND sed -i -b -e 's/pdFALSE/pdFAIL/g' -e 's/pdTRUE/pdPASS/g' ${FREERTOS_KERNEL_SOURCE}
|
||||
DEPENDS ${FREERTOS_KERNEL_SOURCE})
|
||||
|
||||
# Add the freertos_config for FreeRTOS-Kernel.
|
||||
add_library(freertos_config INTERFACE)
|
||||
|
||||
target_include_directories(freertos_config
|
||||
INTERFACE
|
||||
./)
|
||||
|
||||
# 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)
|
||||
|
||||
add_dependencies(${PROJECT_NAME} fix_source)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} freertos_kernel freertos_config)
|
@ -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 */
|
@ -0,0 +1,58 @@
|
||||
# MISRA Compliance for FreeRTOS-Kernel
|
||||
FreeRTOS-Kernel is MISRA C:2012 compliant. This directory contains a project to
|
||||
run [Synopsys Coverity](https://www.synopsys.com/software-integrity/security-testing/static-analysis-sast.html)
|
||||
for checking MISRA compliance.
|
||||
|
||||
> **Note**
|
||||
Coverity version 2022.6.1 incorrectly infers the type of `pdTRUE` and `pdFALSE`
|
||||
as boolean because of their names, resulting in multiple false positive warnings
|
||||
about type mismatch. We replace `pdTRUE` with `pdPASS` and `pdFALSE` with
|
||||
`pdFAIL` to avoid these false positive warnings. This workaround will not be
|
||||
needed after Coverity fixes the issue of incorrectly inferring the type of
|
||||
`pdTRUE` and `pdFALSE` as boolean.
|
||||
|
||||
Deviations from the MISRA C:2012 guidelines are documented in
|
||||
[MISRA.md](../../MISRA.md) and [coverity_misra.config](coverity_misra.config)
|
||||
files.
|
||||
|
||||
## Getting Started
|
||||
### Prerequisites
|
||||
Coverity can be run on any platform mentioned [here](https://sig-docs.synopsys.com/polaris/topics/c_coverity-compatible-platforms.html).
|
||||
The following are the prerequisites to generate coverity report:
|
||||
|
||||
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
|
||||
Go to the root directory of the FreeRTOS-Kernel repo and run the following
|
||||
commands in a terminal:
|
||||
1. Update the compiler configuration in Coverity:
|
||||
~~~
|
||||
cov-configure --force --compiler cc --comptype gcc
|
||||
~~~
|
||||
2. Create the build files using CMake in a `build` directory:
|
||||
~~~
|
||||
cmake -B build -S examples/coverity
|
||||
~~~
|
||||
3. Build the (pseudo) application:
|
||||
~~~
|
||||
cd build/
|
||||
cov-build --emit-complementary-info --dir cov-out make
|
||||
~~~
|
||||
4. Go to the Coverity output directory (`cov-out`) and begin Coverity static
|
||||
analysis:
|
||||
~~~
|
||||
cd cov-out/
|
||||
cov-analyze --dir ./cov-out \
|
||||
--coding-standard-config ../examples/coverity/coverity_misra.config \
|
||||
--tu-pattern "file('.*/FreeRTOS/Source/[A-Za-z_]*\.c')
|
||||
~~~
|
||||
5. Generate the HTML report:
|
||||
~~~
|
||||
cov-format-errors --dir ./cov-out --html-output html-output
|
||||
~~~
|
||||
|
||||
HTML report should now be generated in a directory named `html-output`.
|
@ -0,0 +1,97 @@
|
||||
// MISRA C-2012 Rules
|
||||
|
||||
{
|
||||
version : "2.0",
|
||||
standard : "c2012",
|
||||
title: "Coverity MISRA Configuration",
|
||||
deviations : [
|
||||
// Disable the following rules.
|
||||
{
|
||||
deviation: "Rule 3.1",
|
||||
reason: "We post HTTP links in code comments which contain // inside comments blocks."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 14.4",
|
||||
reason: "do while( 0 ) pattern is used in macros to prevent extra semi-colon."
|
||||
},
|
||||
|
||||
// Disable the following advisory rules and directives.
|
||||
{
|
||||
deviation: "Directive 4.4",
|
||||
reason: "Code snippet is used in comment to help explanation."
|
||||
},
|
||||
{
|
||||
deviation: "Directive 4.5",
|
||||
reason: "Allow names that MISRA considers ambiguous."
|
||||
},
|
||||
{
|
||||
deviation: "Directive 4.6",
|
||||
reason: "Allow port to use primitive type with typedefs."
|
||||
},
|
||||
{
|
||||
deviation: "Directive 4.8",
|
||||
reason: "HeapRegion_t and HeapStats_t are used only in heap files but declared in portable.h which is included in multiple source files. As a result, these definitions appear in multiple source files where they are not used."
|
||||
},
|
||||
{
|
||||
deviation: "Directive 4.9",
|
||||
reason: "FreeRTOS-Kernel is optimised to work on small micro-controllers. To achieve that, function-like macros are used."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 2.3",
|
||||
reason: "FreeRTOS defines types which is used in application."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 2.4",
|
||||
reason: "Allow to define unused tag."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 2.5",
|
||||
reason: "Allow to define unused macro."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 5.9",
|
||||
reason: "Allow to define identifier with the same name in structure and global variable."
|
||||
},
|
||||
{
|
||||
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."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 8.9",
|
||||
reason: "Allow to object to be defined in wider scope for debug purpose."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 8.13",
|
||||
reason: "Allow to not to use const-qualified type for callback function."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 11.4",
|
||||
reason: "Allow to convert between a pointer to object and an interger type for stack alignment."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 15.4",
|
||||
reason: "Allow to use multiple break statements in a loop."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 15.5",
|
||||
reason: "Allow to use multiple points of exit."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 17.8",
|
||||
reason: "Allow to update the parameters of a function."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 18.4",
|
||||
reason: "Allow to use pointer arithmetic."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 19.2",
|
||||
reason: "Allow to use union."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 20.5",
|
||||
reason: "Allow to use #undef for MPU wrappers."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue