diff --git a/.ci/build-kit/docker/Dockerfile b/.ci/build-kit/docker/Dockerfile new file mode 100644 index 0000000..ca655b1 --- /dev/null +++ b/.ci/build-kit/docker/Dockerfile @@ -0,0 +1,3 @@ +# syntax=docker/dockerfile:1 +ARG BASE_IMAGE_TAG=latest +FROM ghcr.io/everest/everest-ci/build-kit-base:${BASE_IMAGE_TAG} diff --git a/.ci/build-kit/install_and_test.sh b/.ci/build-kit/install_and_test.sh deleted file mode 100755 index 140ee13..0000000 --- a/.ci/build-kit/install_and_test.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -set -e - -cmake \ - -B build \ - -S "$EXT_MOUNT/source" \ - -G Ninja \ - -DBUILD_TESTING=ON \ - -DCMAKE_BUILD_TYPE=Debug \ - -DCMAKE_INSTALL_PREFIX="$WORKSPACE_PATH/dist" - -ninja -j$(nproc) -C build install - -trap "cp build/Testing/Temporary/LastTest.log /ext/ctest-report" EXIT - -ninja -j$(nproc) -C build test diff --git a/.ci/build-kit/scripts/compile.sh b/.ci/build-kit/scripts/compile.sh new file mode 100644 index 0000000..f66d276 --- /dev/null +++ b/.ci/build-kit/scripts/compile.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +cmake \ + -B "$EXT_MOUNT/build" \ + -S "$EXT_MOUNT/source" \ + -G Ninja \ + -DBUILD_TESTING=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_INSTALL_PREFIX="$EXT_MOUNT/dist" \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + +retVal=$? +if [ $retVal -ne 0 ]; then + echo "Configuring failed with return code $retVal" + exit $retVal +fi + +ninja -C "$EXT_MOUNT/build" +retVal=$? +if [ $retVal -ne 0 ]; then + echo "Compiling failed with return code $retVal" + exit $retVal +fi diff --git a/.ci/build-kit/scripts/install.sh b/.ci/build-kit/scripts/install.sh new file mode 100644 index 0000000..174dbc7 --- /dev/null +++ b/.ci/build-kit/scripts/install.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +ninja -C "$EXT_MOUNT/build" install +retVal=$? + +if [ $retVal -ne 0 ]; then + echo "Installation failed with return code $retVal" + exit $retVal +fi diff --git a/.ci/build-kit/scripts/run_coverage.sh b/.ci/build-kit/scripts/run_coverage.sh new file mode 100644 index 0000000..3a432cf --- /dev/null +++ b/.ci/build-kit/scripts/run_coverage.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +ninja \ + -C "$EXT_MOUNT/build" \ + everest-evse_security_gcovr_coverage +retValHTML=$? + +ninja \ + -C "$EXT_MOUNT/build" \ + everest-evse_security_gcovr_coverage_xml +retValXML=$? + +# Copy the generated coverage report and xml to the mounted directory in any case +cp -R "$EXT_MOUNT/build/everest-evse_security_gcovr_coverage" "$EXT_MOUNT/gcovr-coverage" +cp "$EXT_MOUNT/build/everest-evse_security_gcovr_coverage_xml.xml" "$EXT_MOUNT/gcovr-coverage-xml.xml" + +if [ $retValHTML -ne 0 ]; then + echo "Coverage HTML report failed with return code $retValHTML" + exit $retValHTML +fi + +if [ $retValXML -ne 0 ]; then + echo "Coverage XML report failed with return code $retValXML" + exit $retValXML +fi diff --git a/.ci/build-kit/scripts/run_unit_tests.sh b/.ci/build-kit/scripts/run_unit_tests.sh new file mode 100644 index 0000000..5fa1870 --- /dev/null +++ b/.ci/build-kit/scripts/run_unit_tests.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +ninja -C "$EXT_MOUNT/build" test +retVal=$? + +# Copy the LastTest.log file to the mounted directory in any case +cp "$EXT_MOUNT/build/Testing/Temporary/LastTest.log" "$EXT_MOUNT/ctest-report" + +if [ $retVal -ne 0 ]; then + echo "Unit tests failed with return code $retVal" + exit $retVal +fi diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index ead2e7f..415b94e 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -1,4 +1,4 @@ -name: Build and test libevse-security +name: Build, Lint and Test on: pull_request: {} workflow_dispatch: @@ -11,47 +11,24 @@ on: options: - 'ubuntu-22.04' - 'large-ubuntu-22.04-xxl' + schedule: + - cron: '37 13,1 * * *' jobs: - lint: - name: Lint - runs-on: ${{ inputs.runner || 'ubuntu-22.04' }} - steps: - - name: Checkout libevse-security - uses: actions/checkout@v3 - with: - path: source - - name: Run clang-format - uses: everest/everest-ci/github-actions/run-clang-format@v1.1.0 - with: - source-dir: source - extensions: hpp,cpp - exclude: cache - test: - name: Build and test libevse-security - runs-on: ${{ inputs.runner || 'ubuntu-22.04' }} - steps: - - name: Checkout libevse-security - uses: actions/checkout@v3 - with: - path: source - - name: Setup run scripts - run: | - mkdir scripts - rsync -a source/.ci/build-kit/ scripts - - name: Pull docker container - run: | - docker pull --platform=linux/x86_64 --quiet ghcr.io/everest/build-kit-alpine:latest - docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit - - name: Unit test and install - run: | - docker run \ - --volume "$(pwd):/ext" \ - --name test-container \ - build-kit run-script install_and_test - - name: Archive test results - if: always() - uses: actions/upload-artifact@v3 - with: - name: ctest-report - path: ${{ github.workspace }}/ctest-report + ci: + name: Build, Lint and Test + uses: everest/everest-ci/.github/workflows/continuous_integration.yml@v1.4.2 + permissions: + contents: read + secrets: + coverage_deploy_token: ${{ secrets.SA_GITHUB_PAT }} + with: + runner: ${{ inputs.runner || 'ubuntu-22.04' }} + artifact_deploy_target_repo: EVerest/everest.github.io + run_coverage: true + do_not_run_coverage_badge_creation: false + run_install_wheels: false + run_integration_tests: false + ctest_report_path: ctest-report + coverage_report_path: gcovr-coverage + coverage_xml_path: gcovr-coverage-xml.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index 911d050..bbdb10a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ option(USING_CUSTOM_PROVIDER "Include code for using OpenSSL 3 and the custom pr if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) set(LIBEVSE_SECURITY_BUILD_TESTING ON) + evc_include(CodeCoverage) + append_coverage_compiler_flags() endif() if(USING_TPM2 AND USING_CUSTOM_PROVIDER) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9443eb1..c1772af 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,6 +32,20 @@ add_compile_definitions(BUILD_TESTING_EVSE_SECURITY) add_test(${TEST_TARGET_NAME} ${TEST_TARGET_NAME}) +setup_target_for_coverage_gcovr_html( + NAME ${PROJECT_NAME}_gcovr_coverage + EXECUTABLE ctest + DEPENDENCIES ${TEST_TARGET_NAME} + EXCLUDE "tests/*" +) + +setup_target_for_coverage_gcovr_xml( + NAME ${PROJECT_NAME}_gcovr_coverage_xml + EXECUTABLE ctest + DEPENDENCIES ${TEST_TARGET_NAME} + EXCLUDE "tests/*" +) + install( PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/generate_test_certs.sh" PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/generate_test_certs_multi.sh"