Skip to content

Commit

Permalink
chore: switch static analysis to container (#423)
Browse files Browse the repository at this point in the history
* chore: update devcontainer

* chore: switch static analysis to container

* chore: use correct configurations

* chore: remove workaround for missing symlinks

When running into issues using mutation testing, please update your local devcontainer.

* chore: use correct mutation-testing preset

* chore: update CMakePresets.json

* chore: update googletest

* chore: use nproc for -j parameters

* chore: revert version update in CMakePresets.json

* deps: update mbedtls to 3.4.1 to silence warning

See: Mbed-TLS/mbedtls#7098

* chore: fix compilation with clang-15

* chore: fix remaining issues
  • Loading branch information
rjaegers authored Sep 28, 2023
1 parent e55a9d6 commit c249b3e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This devcontainer has been set-up to run docker-from-docker scenarios as per
// https://github.com/microsoft/vscode-dev-containers/tree/main/containers/docker-from-docker
"name": "amp-devcontainer",
"image": "ghcr.io/philips-software/amp-devcontainer:2.2.0",
"image": "ghcr.io/philips-software/amp-devcontainer:2.5.0",
"runArgs": ["--add-host=host.docker.internal:host-gateway"],
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" },
"mounts": [
Expand Down
35 changes: 16 additions & 19 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,20 @@ jobs:
sonar:
name: SonarCloud
runs-on: ubuntu-latest
container: ghcr.io/philips-software/amp-devcontainer:2.5.0
env:
SONAR_SCANNER_VERSION: 4.7.0.2747
SONAR_SCANNER_VERSION: 5.0.1.3006
SONAR_SERVER_URL: "https://sonarcloud.io"
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
fetch-depth: 0 # Disable shallow clone to enable blame information
persist-credentials: false
- run: sudo apt-get update && sudo apt-get install --no-install-recommends jq ninja-build xsltproc
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
- uses: BSFishy/pip-action@8f2d471d809dc20b6ada98c91910b6ae6243f318
with:
packages: gcovr==5.2
- name: Install Sonar Scanner & Mull
- name: Install Sonar Scanner
run: |
wget -qN "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip"
unzip -qqo "sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip"
echo "${PWD}/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> "$GITHUB_PATH"
wget -qN https://github.com/mull-project/mull/releases/download/0.18.0/Mull-12-0.18.0-LLVM-12.0-ubuntu-20.04.deb
sudo dpkg -i Mull-12-0.18.0-LLVM-12.0-ubuntu-20.04.deb
- uses: hendrikmuhs/ccache-action@6d1841ec156c39a52b1b23a810da917ab98da1f4 # v1.2.10
with:
key: ${{ github.job }}
Expand All @@ -47,12 +41,13 @@ jobs:
cmake --preset coverage -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset coverage
GTEST_OUTPUT="xml:${PWD}/testresults/" ctest --preset coverage
gcovr --sonarqube=coverage.xml --exclude-lines-by-pattern '.*assert\(.*\);|.*really_assert\(.*\);|.*std::abort();' --exclude-unreachable-branches --exclude-throw-branches -j 2 --exclude=.*/generated/.* --exclude=.*/examples/.* --exclude=.*/external/.* --exclude=.*/lwip/.* --exclude=.*/tracing/.* --exclude=.*/test/.*
- name: Build & Run Mutation Tests
run: |
cmake --preset mutation-testing -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset mutation-testing
ctest --preset mutation-testing
gcovr --sonarqube=coverage.xml --exclude-lines-by-pattern '.*assert\(.*\);|.*really_assert\(.*\);|.*std::abort();' --exclude-unreachable-branches --exclude-throw-branches -j "$(nproc)" --exclude=.*/generated/.* --exclude=.*/examples/.* --exclude=.*/external/.* --exclude=.*/lwip/.* --exclude=.*/tracing/.* --exclude=.*/test/.*
- uses: lukka/run-cmake@c2b72aff009141774c5a5fabe74ea46c8c04d9c4 # v10.6
with:
configurePreset: "mutation-testing"
buildPreset: "mutation-testing"
testPreset: "mutation-testing"
configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=ccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache']"
- name: Convert Results
run: |
{ echo '<testExecutions version="1">'; xsltproc .github/formatters/gtest-to-generic-execution.xslt testresults/*.xml; echo '</testExecutions>'; } | tee execution.xml > /dev/null
Expand All @@ -70,20 +65,22 @@ jobs:
codeql:
name: CodeQL
runs-on: ubuntu-latest
container: ghcr.io/philips-software/amp-devcontainer:2.5.0
permissions:
security-events: write
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
persist-credentials: false
- run: sudo apt-get update && sudo apt-get install ninja-build
- uses: hendrikmuhs/ccache-action@6d1841ec156c39a52b1b23a810da917ab98da1f4 # v1.2.10
with:
key: ${{ github.job }}
- uses: github/codeql-action/init@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2.21.9
with:
languages: cpp
- run: |
cmake --preset host -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --build --preset host-Debug
- uses: lukka/run-cmake@c2b72aff009141774c5a5fabe74ea46c8c04d9c4 # v10.6
with:
configurePreset: "host"
buildPreset: "host-Debug"
configurePresetAdditionalArgs: "['-DCMAKE_C_COMPILER_LAUNCHER=ccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache']"
- uses: github/codeql-action/analyze@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2.21.9
6 changes: 3 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
"displayName": "Configuration for Mutation Testing",
"inherits": "host",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-12",
"CMAKE_CXX_COMPILER": "clang++-12",
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"EMIL_ENABLE_MUTATION_TESTING": "On",
"EMIL_MUTATION_TESTING_RUNNER_ARGUMENTS": "--reporters;Elements;--report-dir;${sourceDir}/reports/mull"
"EMIL_MUTATION_TESTING_RUNNER_ARGUMENTS": "--allow-surviving;--reporters;Elements;--report-dir;${sourceDir}/reports/mull"
},
"generator": "Ninja"
},
Expand Down
37 changes: 13 additions & 24 deletions cmake/emil_test_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ option(EMIL_ENABLE_COVERAGE "Enable compiler flags for code coverage measurement
option(EMIL_ENABLE_MUTATION_TESTING "Enable compiler flags for mutation testing" Off)
set(EMIL_MUTATION_TESTING_RUNNER_ARGUMENTS "" CACHE STRING "Additional arguments for the mutation testing runner")

function(emil_enable_testing)
include(GoogleTest)

function(emil_fetch_googletest)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-1.12.1
)

Expand All @@ -18,6 +16,12 @@ function(emil_enable_testing)

set_target_properties(gtest gtest_main gmock gmock_main PROPERTIES FOLDER External/GoogleTest)
mark_as_advanced(BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS gmock_build_tests gtest_build_samples test_build_tests gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols)
endfunction()

function(emil_enable_testing)
include(GoogleTest)

emil_fetch_googletest()

if (EMIL_ENABLE_COVERAGE)
add_compile_options(
Expand All @@ -34,19 +38,10 @@ function(emil_enable_testing)

if (EMIL_ENABLE_MUTATION_TESTING)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CLANG_VERSION)

if(CLANG_VERSION VERSION_GREATER 15.0 OR CLANG_VERSION VERSION_EQUAL 15.0)
add_compile_options(
-g -O0 -grecord-command-line -fprofile-instr-generate -fcoverage-mapping
-fexperimental-new-pass-manager -fpass-plugin=/usr/lib/mull-ir-frontend
)
else()
add_compile_options(
-g -O0 -grecord-command-line -fprofile-instr-generate -fcoverage-mapping
-fexperimental-new-pass-manager -fpass-plugin=/usr/lib/mull-ir-frontend-12
)
endif()
add_compile_options(
-g -O0 -grecord-command-line -fprofile-instr-generate -fcoverage-mapping
-fexperimental-new-pass-manager -fpass-plugin=/usr/lib/mull-ir-frontend
)

add_link_options(-fprofile-instr-generate)
else()
Expand All @@ -68,13 +63,7 @@ function(emil_add_test target)
get_target_property(exclude ${target} EXCLUDE_FROM_ALL)
if (NOT ${exclude})
if (EMIL_ENABLE_MUTATION_TESTING)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CLANG_VERSION)

if(CLANG_VERSION VERSION_GREATER 15.0 OR CLANG_VERSION VERSION_EQUAL 15.0)
add_test(NAME ${target} COMMAND mull-runner ${EMIL_MUTATION_TESTING_RUNNER_ARGUMENTS} $<TARGET_FILE:${target}>)
else()
add_test(NAME ${target} COMMAND mull-runner-12 ${EMIL_MUTATION_TESTING_RUNNER_ARGUMENTS} $<TARGET_FILE:${target}>)
endif()
add_test(NAME ${target} COMMAND mull-runner ${EMIL_MUTATION_TESTING_RUNNER_ARGUMENTS} $<TARGET_FILE:${target}>)
else()
add_test(NAME ${target} COMMAND ${target})
endif()
Expand Down
4 changes: 4 additions & 0 deletions external/crypto/mbedtls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ function(add_mbedtls_target_properties)
foreach(target ${ARGN})
target_compile_options(${target} PUBLIC
-DMBEDTLS_CONFIG_FILE="mbedtls/mbedtls_emil_config.h"
# see https://github.com/Mbed-TLS/mbedtls/pull/6966
# mbedtls sets the -Wdocumentation flag, which is throwing warnings
# since clang-15
$<$<CXX_COMPILER_ID:Clang>:-Wno-documentation>
)

target_include_directories(${target} PUBLIC
Expand Down

0 comments on commit c249b3e

Please sign in to comment.