[修改] 增加freeRTOS
1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
@ -0,0 +1,79 @@
|
||||
# Static code analysis for AWS IoT Fleet Provisioning Library
|
||||
This directory is made for the purpose of statically testing the MISRA C:2012 compliance of AWS IoT Fleet Provisioning Library using
|
||||
[Synopsys Coverity](https://www.synopsys.com/software-integrity/security-testing/static-analysis-sast.html) static analysis tool.
|
||||
To that end, this directory provides a [configuration file](https://github.com/aws/Fleet-Provisioning-for-AWS-IoT-embedded-sdk/blob/main/tools/coverity/misra.config) to use when
|
||||
building a binary for the tool to analyze.
|
||||
|
||||
> **Note**
|
||||
For generating the report as outlined below, we have used Coverity version 2018.09.
|
||||
|
||||
For details regarding the suppressed violations in the report (which can be generated using the instructions described below), please
|
||||
see the [MISRA.md](https://github.com/aws/Fleet-Provisioning-for-AWS-IoT-embedded-sdk/blob/main/MISRA.md) file.
|
||||
|
||||
## Getting Started
|
||||
### Prerequisites
|
||||
You can run this on a platform supported by Coverity. The list and other details can be found [here](https://sig-docs.synopsys.com/polaris/topics/c_coverity-compatible-platforms.html).
|
||||
To compile and run the Coverity target successfully, you must have the following:
|
||||
|
||||
1. CMake version > 3.13.0 (You can check whether you have this by typing `cmake --version`)
|
||||
2. GCC compiler
|
||||
- You can see the downloading and installation instructions [here](https://gcc.gnu.org/install/).
|
||||
3. Download the repo and include the submodules using the following commands.
|
||||
- `git clone --recurse-submodules git@github.com:aws/Fleet-Provisioning-for-AWS-IoT-embedded-sdk.git ./Fleet-Provisioning-for-AWS-IoT-embedded-sdk`
|
||||
- `cd ./Fleet-Provisioning-for-AWS-IoT-embedded-sdk`
|
||||
- `git submodule update --checkout --init --recursive`
|
||||
|
||||
### To build and run coverity:
|
||||
Go to the root directory of the library and run the following commands in 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 test
|
||||
~~~
|
||||
3. Go to the build directory and copy the coverity configuration file
|
||||
~~~
|
||||
cd build/
|
||||
~~~
|
||||
4. Build the static analysis target
|
||||
~~~
|
||||
cov-build --emit-complementary-info --dir cov-out make coverity_analysis
|
||||
~~~
|
||||
5. Go to the Coverity output directory (`cov-out`) and begin Coverity static analysis
|
||||
~~~
|
||||
cd cov-out/
|
||||
cov-analyze --dir . --coding-standard-config ../../tools/coverity/misra.config --tu-pattern "file('.*/source/.*')"
|
||||
~~~
|
||||
6. Format the errors in HTML format so that it is more readable while removing the test and build directory from the report
|
||||
~~~
|
||||
cov-format-errors --dir . --file "source" --exclude-files '(/build/|/test/)' --html-output html-out;
|
||||
~~~
|
||||
7. Format the errors in JSON format to perform a jq query to get a simplified list of any exceptions.
|
||||
NOTE: A blank output means there are no defects that aren't being suppressed by the config or inline comments.
|
||||
~~~
|
||||
cov-format-errors --dir . --file "source" --exclude-files '(/build/|/test/)' --json-output-v2 defects.json;
|
||||
echo -e "\n-------------------------Non-Suppresed Deviations, if any, Listed Below-------------------------\n";
|
||||
jq '.issues[] | .events[] | .eventTag ' defects.json | sort | uniq -c | sort -nr;
|
||||
echo -e "\n-------------------------Non-Suppresed Deviations, if any, Listed Above-------------------------\n";
|
||||
~~~
|
||||
|
||||
For your convenience the commands above are below to be copy/pasted into a UNIX command friendly terminal.
|
||||
~~~
|
||||
cov-configure --force --compiler cc --comptype gcc;
|
||||
cmake -B build -S test;
|
||||
cd build/;
|
||||
cov-build --emit-complementary-info --dir cov-out make coverity_analysis;
|
||||
cd cov-out/
|
||||
cov-analyze --dir . --coding-standard-config ../../tools/coverity/misra.config --tu-pattern "file('.*/source/.*')";
|
||||
cov-format-errors --dir . --file "source" --exclude-files '(/build/|/test/)' --html-output html-out;
|
||||
cov-format-errors --dir . --file "source" --exclude-files '(/build/|/test/)' --json-output-v2 defects.json;
|
||||
echo -e "\n-------------------------Non-Suppresed Deviations, if any, Listed Below-------------------------\n";
|
||||
jq '.issues[] | .events[] | .eventTag ' defects.json | sort | uniq -c | sort -nr;
|
||||
echo -e "\n-------------------------Non-Suppresed Deviations, if any, Listed Above-------------------------\n";
|
||||
cd ../../;
|
||||
~~~
|
||||
|
||||
You should now have the HTML formatted violations list in a directory named `build/cov-out/html-output`.
|
||||
With the current configuration and the provided project, you should not see any deviations.
|
||||
@ -0,0 +1,25 @@
|
||||
// MISRA C-2012 Rules
|
||||
{
|
||||
version : "2.0",
|
||||
standard : "c2012",
|
||||
title: "Coverity MISRA Configuration",
|
||||
deviations : [
|
||||
// Disable the following rules.
|
||||
{
|
||||
deviation: "Directive 4.9",
|
||||
reason: "Allow inclusion of function like macros. Asserts, logging, and topic string macros use function like macros."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 2.5",
|
||||
reason: "Allow unused macros. Macros defined for topic strings are not used by the library, but are part of the API."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 3.1",
|
||||
reason: "Allow nested comments. C++ style `//` comments are used in example code within Doxygen documentation blocks."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 8.7",
|
||||
reason: "API functions are not used by library. They must be externally visible in order to be used by the application."
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
cmake_minimum_required( VERSION 3.13 )
|
||||
set( BINARY_DIR ${CMAKE_BINARY_DIR} )
|
||||
|
||||
# Reset coverage counters.
|
||||
execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
|
||||
--base-directory ${CMAKE_BINARY_DIR}
|
||||
--zerocounters )
|
||||
|
||||
# Create directory for results.
|
||||
execute_process( COMMAND mkdir -p ${CMAKE_BINARY_DIR}/coverage )
|
||||
|
||||
# Generate "baseline" coverage data with zero coverage for every instrumented
|
||||
# line. This is later combined with the coverage data from test run to ensure
|
||||
# that the percentage of total lines covered is correct even when not all source
|
||||
# code files were loaded during the test.
|
||||
execute_process( COMMAND lcov --directory ${CMAKE_BINARY_DIR}
|
||||
--base-directory ${CMAKE_BINARY_DIR}
|
||||
--initial
|
||||
--capture
|
||||
--rc lcov_branch_coverage=1
|
||||
--rc genhtml_branch_coverage=1
|
||||
--output-file=${CMAKE_BINARY_DIR}/base_coverage.info )
|
||||
|
||||
# Capture all the test binaries.
|
||||
file( GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*" )
|
||||
|
||||
# Create an empty report file.
|
||||
set( REPORT_FILE ${CMAKE_BINARY_DIR}/utest_report.txt )
|
||||
file( WRITE ${REPORT_FILE} "" )
|
||||
|
||||
# Execute all test binaries and capture all the output in the report file.
|
||||
foreach( testname ${files} )
|
||||
get_filename_component( test ${testname} NAME_WLE )
|
||||
message( "Running ${testname}" )
|
||||
execute_process( COMMAND ${testname} OUTPUT_FILE ${CMAKE_BINARY_DIR}/${test}_out.txt )
|
||||
|
||||
# Append the test run output to the report file.
|
||||
file( READ ${CMAKE_BINARY_DIR}/${test}_out.txt CONTENTS )
|
||||
file( APPEND ${REPORT_FILE} "${CONTENTS}" )
|
||||
endforeach()
|
||||
|
||||
# Generate Junit style xml output.
|
||||
execute_process( COMMAND ruby
|
||||
${UNITY_DIR}/auto/parse_output.rb
|
||||
-xml ${REPORT_FILE}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
|
||||
|
||||
# Capture coverage data after test run.
|
||||
execute_process( COMMAND lcov --capture
|
||||
--rc lcov_branch_coverage=1
|
||||
--rc genhtml_branch_coverage=1
|
||||
--base-directory ${CMAKE_BINARY_DIR}
|
||||
--directory ${CMAKE_BINARY_DIR}
|
||||
--output-file ${CMAKE_BINARY_DIR}/second_coverage.info )
|
||||
|
||||
# Combine baseline coverage data (zeros) with the coverage data from test run.
|
||||
execute_process( COMMAND lcov --base-directory ${CMAKE_BINARY_DIR}
|
||||
--directory ${CMAKE_BINARY_DIR}
|
||||
--add-tracefile ${CMAKE_BINARY_DIR}/base_coverage.info
|
||||
--add-tracefile ${CMAKE_BINARY_DIR}/second_coverage.info
|
||||
--output-file ${CMAKE_BINARY_DIR}/coverage.info
|
||||
--no-external
|
||||
--rc lcov_branch_coverage=1 )
|
||||
|
||||
# Generate HTML Report.
|
||||
execute_process( COMMAND genhtml --rc lcov_branch_coverage=1
|
||||
--branch-coverage
|
||||
--output-directory ${CMAKE_BINARY_DIR}/coverage
|
||||
${CMAKE_BINARY_DIR}/coverage.info )
|
||||
@ -0,0 +1,64 @@
|
||||
# Function to create the test executable.
|
||||
function( create_test_binary_target test_name
|
||||
test_src
|
||||
link_list
|
||||
dep_list
|
||||
include_list )
|
||||
include ( CTest )
|
||||
get_filename_component( test_src_absolute ${test_src} ABSOLUTE )
|
||||
|
||||
# Generate test runner file.
|
||||
add_custom_command( OUTPUT ${test_name}_runner.c
|
||||
COMMAND ruby ${UNITY_DIR}/auto/generate_test_runner.rb
|
||||
${MODULE_ROOT_DIR}/tools/unity/project.yml
|
||||
${test_src_absolute}
|
||||
${test_name}_runner.c
|
||||
DEPENDS ${test_src} )
|
||||
|
||||
add_executable( ${test_name} ${test_src} ${test_name}_runner.c )
|
||||
|
||||
set_target_properties( ${test_name} PROPERTIES
|
||||
COMPILE_FLAG "-O0 -ggdb"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/tests"
|
||||
INSTALL_RPATH_USE_LINK_PATH TRUE
|
||||
LINK_FLAGS "-Wl,-rpath,${CMAKE_BINARY_DIR}/lib \
|
||||
-Wl,-rpath,${CMAKE_CURRENT_BINARY_DIR}/lib" )
|
||||
|
||||
target_include_directories( ${test_name} PUBLIC ${mocks_dir} ${include_list} )
|
||||
|
||||
target_link_directories( ${test_name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} )
|
||||
|
||||
# Link all libraries sent through parameters.
|
||||
foreach( link IN LISTS link_list )
|
||||
target_link_libraries( ${test_name} ${link} )
|
||||
endforeach()
|
||||
|
||||
# Add dependency to all the dep_list parameter.
|
||||
foreach( dependency IN LISTS dep_list )
|
||||
add_dependencies( ${test_name} ${dependency} )
|
||||
target_link_libraries( ${test_name} ${dependency} )
|
||||
endforeach()
|
||||
|
||||
target_link_libraries( ${test_name} -lgcov unity )
|
||||
target_link_directories( ${test_name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/lib )
|
||||
|
||||
add_test( NAME ${test_name}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/bin/tests/${test_name}
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
|
||||
endfunction()
|
||||
|
||||
# Function to create target for library under test.
|
||||
function( create_library_target target_name
|
||||
src_file
|
||||
include_list )
|
||||
add_library( ${target_name} STATIC ${src_file} )
|
||||
target_include_directories( ${target_name} PUBLIC ${include_list} )
|
||||
|
||||
set_target_properties( ${target_name} PROPERTIES
|
||||
COMPILE_FLAGS "-Wextra -Wpedantic \
|
||||
-fprofile-arcs -ftest-coverage -fprofile-generate \
|
||||
-Wno-unused-but-set-variable"
|
||||
LINK_FLAGS "-fprofile-arcs -ftest-coverage \
|
||||
-fprofile-generate "
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib )
|
||||
endfunction()
|
||||
@ -0,0 +1,12 @@
|
||||
:unity:
|
||||
:when_no_prototypes: :warn
|
||||
:enforce_strict_ordering: TRUE
|
||||
:treat_as:
|
||||
uint8: HEX8
|
||||
uint16: HEX16
|
||||
uint32: UINT32
|
||||
int8: INT8
|
||||
bool: UINT8
|
||||
:treat_externs: :exclude
|
||||
:weak: __attribute__((weak))
|
||||
:treat_externs: :include
|
||||
Reference in New Issue
Block a user