Skip to content
Snippets Groups Projects
Commit 01297525 authored by Vivek Dutta's avatar Vivek Dutta
Browse files

Move all static analysis tests in static_code_analysis.sh

parent 9566df31
Branches
Tags
1 merge request!26Added infer and minor cleanup
...@@ -259,9 +259,8 @@ COPY supervisord.conf /etc/supervisor/ ...@@ -259,9 +259,8 @@ COPY supervisord.conf /etc/supervisor/
RUN mkdir -p /usr/share/rpcd/schemas && \ RUN mkdir -p /usr/share/rpcd/schemas && \
mkdir -p /usr/share/rpcd/definitions mkdir -p /usr/share/rpcd/definitions
# Copy static_code_analysis script
# Copy more_test script COPY static_code_analysis.sh /usr/local/bin/static_code_analysis.sh
COPY more_test.sh /usr/local/bin/more_test.sh
# Start entrypoint # Start entrypoint
COPY entrypoint.sh /usr/local/bin/entrypoint.sh COPY entrypoint.sh /usr/local/bin/entrypoint.sh
......
...@@ -11,7 +11,12 @@ exec_cmd() ...@@ -11,7 +11,12 @@ exec_cmd()
$@ $@
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
log "Failed to run [$@]..." log "Failed to run [$@]..."
exit 1 if [ -n "${CI}" ]; then
exit 1
else
# Ignore errors for development environment
log "Ignoring the last error ..."
fi
fi fi
} }
...@@ -51,19 +56,45 @@ run_infer_analysis() ...@@ -51,19 +56,45 @@ run_infer_analysis()
exec_cmd infer --fail-on-issue --compilation-database compile_commands.json exec_cmd infer --fail-on-issue --compilation-database compile_commands.json
} }
run_flawfinder_checks()
{
exec_cmd flawfinder --minlevel 4 --error-level=4 ${FLAWFINDER_OPTIONS} ${SOURCE_FOLDER}
}
run_cpd_check()
{
exec_cmd /usr/local/pmd/bin/run.sh cpd --language c --exclude ./test/ ${CPD_OPTIONS} --files ${SOURCE_FOLDER}
}
main() main()
{ {
log "SOURCE_FOLDER: ${SOURCE_FOLDER}" log "SOURCE_FOLDER: ${SOURCE_FOLDER}"
log "COMPILATION_FIXUP: ${COMPILATION_FIXUP}" log "COMPILATION_FIXUP: ${COMPILATION_FIXUP}"
log "CPPCHECK_OPTIONS: ${CPPCHECK_OPTIONS}" log "CPPCHECK_OPTIONS: ${CPPCHECK_OPTIONS}"
log "FLAWFINDER_OPTIONS: ${FLAWFINDER_OPTIONS}"
log "CPD_OPTIONS: ${CPD_OPTIONS:=--minimum-tokens 200}"
log "" log ""
if [ -z "${SOURCE_FOLDER}" ]; then
log "SOURCE_FOLDER not defined"
if [ -n "${CI}" ]; then
log "Can't proceed without SOURCE_FOLDER in pipeline"
exit 5
else
log "Assuming current path '.' as SOURCE_FOLDER"
export SOURCE_FOLDER="."
fi
fi
# Install pre-req if present/defined # Install pre-req if present/defined
if [ -f "./gitlab-ci/install-dependencies.sh" ]; then if [ -f "./gitlab-ci/install-dependencies.sh" ]; then
log "Installing prerequisites for compilation" log "Installing prerequisites for compilation"
exec_cmd ./gitlab-ci/install-dependencies.sh exec_cmd ./gitlab-ci/install-dependencies.sh
fi fi
# Run flawfinder
run_flawfinder_checks
# Generate compilation db # Generate compilation db
generate_compilation_db generate_compilation_db
...@@ -72,11 +103,14 @@ main() ...@@ -72,11 +103,14 @@ main()
# Run cppcheck with compilation-db # Run cppcheck with compilation-db
run_cppcheck_validation run_cppcheck_validation
# Run clag analysis # Run clang analysis
run_cppcheck_clang_validation run_cppcheck_clang_validation
# Run infer analysis # Run infer analysis
run_infer_analysis run_infer_analysis
# Run CPD checks
run_cpd_check
} }
main "$@" main "$@"
variables: variables:
COMMON_IMAGE: "dev.iopsys.eu:5050/iopsys/gitlab-ci-pipeline/code-analysis:0.33" COMMON_IMAGE: "dev.iopsys.eu:5050/iopsys/gitlab-ci-pipeline/code-analysis:0.33"
FLAWFINDER_OPTIONS: "" FLAWFINDER_OPTIONS: ""
CPD_OPTIONS: "--minimum-tokens 200 --language c --exclude ./test/ --files" CPD_OPTIONS: "--minimum-tokens 200"
CPPCHECK_OPTIONS: "" CPPCHECK_OPTIONS: ""
COMPILATION_FIXUP: "" COMPILATION_FIXUP: ""
SHELL_SRC: "" SHELL_SRC: ""
...@@ -13,17 +13,12 @@ run_static_code_analysis: ...@@ -13,17 +13,12 @@ run_static_code_analysis:
stage: static_code_analysis stage: static_code_analysis
allow_failure: false allow_failure: false
script: script:
- echo "flawfinder --minlevel 4 --error-level=4 ${FLAWFINDER_OPTIONS} ${SOURCE_FOLDER}" - "static_code_analysis.sh"
- "flawfinder --minlevel 4 --error-level=4 ${FLAWFINDER_OPTIONS} ${SOURCE_FOLDER}" rules:
- echo "/usr/local/pmd/bin/run.sh cpd ${CPD_OPTIONS} ${SOURCE_FOLDER}" - if: ${SOURCE_FOLDER}
- "/usr/local/pmd/bin/run.sh cpd ${CPD_OPTIONS} ${SOURCE_FOLDER}" when: always
- echo "Run cppcheck/infer/clag/gcc to scan for more issues"
- "more_test.sh"
only:
variables:
- $SOURCE_FOLDER
artifacts: artifacts:
when: always when: on_failure
paths: paths:
- infer-out/report.txt - infer-out/report.txt
...@@ -36,6 +31,6 @@ run_shell_checks: ...@@ -36,6 +31,6 @@ run_shell_checks:
- echo "Running optional tests" - echo "Running optional tests"
- echo "Running shellcheck ${SHELLCHECK_OPTIONS} ${SHELL_SRC}" - echo "Running shellcheck ${SHELLCHECK_OPTIONS} ${SHELL_SRC}"
- "shellcheck ${SHELLCHECK_OPTIONS} ${SHELL_SRC}" - "shellcheck ${SHELLCHECK_OPTIONS} ${SHELL_SRC}"
only: rules:
variables: - if: ${SHELL_SRC}
- $SHELL_SRC when: always
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment