[修改] 增加freeRTOS
1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
@ -0,0 +1,79 @@
|
||||
# Static code analysis for coreJSON library
|
||||
This directory is made for the purpose of statically testing the MISRA C:2012 compliance of coreJSON 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/FreeRTOS/coreJSON/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/FreeRTOS/coreJSON/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:FreeRTOS/coreJSON.git ./coreJSON`
|
||||
- `cd ./coreJSON`
|
||||
- `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;
|
||||
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,42 @@
|
||||
// MISRA C-2012 Rules
|
||||
|
||||
{
|
||||
version : "2.0",
|
||||
standard : "c2012",
|
||||
title: "Coverity MISRA Configuration",
|
||||
deviations : [
|
||||
{
|
||||
deviation: "Directive 4.9",
|
||||
category: "Advisory",
|
||||
reason: "Allow inclusion of function like macros."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 2.5",
|
||||
reason: "Allow unused macros. Library headers may define macros intended for the application's use, but not used by a specific file."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 3.1",
|
||||
category: "Required",
|
||||
reason: "Allow nested comments. Documentation blocks contain comments for example code."
|
||||
},
|
||||
{
|
||||
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."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 8.13",
|
||||
category: "Advisory",
|
||||
reason: "Allow one function to have a char * argument without const qualifier."
|
||||
},
|
||||
{
|
||||
deviation: "Rule 15.4",
|
||||
category: "Advisory",
|
||||
reason: "Allow more then one break statement to terminate a loop"
|
||||
},
|
||||
{
|
||||
deviation: "Rule 19.2",
|
||||
category: "Advisory",
|
||||
reason: "Allow a union of a signed and unsigned type of identical sizes."
|
||||
},
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
# Taken from amazon-freertos repository
|
||||
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
|
||||
|
||||
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/coverage
|
||||
)
|
||||
# make the initial/baseline capture a zeroed out files
|
||||
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
|
||||
)
|
||||
file(GLOB files "${CMAKE_BINARY_DIR}/bin/tests/*")
|
||||
|
||||
set(REPORT_FILE ${CMAKE_BINARY_DIR}/utest_report.txt)
|
||||
file(WRITE ${REPORT_FILE} "")
|
||||
# execute all files in bin directory, gathering the output to show it in CI
|
||||
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)
|
||||
|
||||
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 data after running the tests
|
||||
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
|
||||
)
|
||||
|
||||
# combile baseline results (zeros) with the one after running the tests
|
||||
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
|
||||
)
|
||||
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,73 @@
|
||||
# Taken from amazon-freertos repository
|
||||
|
||||
#function to create the test executable
|
||||
function(create_test test_name
|
||||
test_src
|
||||
link_list
|
||||
dep_list
|
||||
include_list)
|
||||
include (CTest)
|
||||
get_filename_component(test_src_absolute ${test_src} ABSOLUTE)
|
||||
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
|
||||
${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(create_real_library target
|
||||
src_file
|
||||
real_include_list)
|
||||
add_library(${target} STATIC
|
||||
${src_file}
|
||||
)
|
||||
target_include_directories(${target} PUBLIC
|
||||
${real_include_list}
|
||||
)
|
||||
set_target_properties(${target} 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()
|
||||
12
kernel/FreeRTOS-Plus/Source/coreJSON/tools/unity/project.yml
Normal file
12
kernel/FreeRTOS-Plus/Source/coreJSON/tools/unity/project.yml
Normal file
@ -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