diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 5b4c24e20fd..1e3009e672d 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -99,3 +99,42 @@ jobs: - name: Check for EKF functional changes run: git diff --exit-code working-directory: src/modules/ekf2/test/change_indication + + # Separate from Unit Tests: the instrumented build shifts EKF float output, which + # would trip the change indication auto-commit above. + coverage: + name: Unit Test Coverage + runs-on: [runs-on,runner=8cpu-linux-x64,image=ubuntu24-full-x64,"run-id=${{ github.run_id }}",spot=false,extras=s3-cache] + container: + image: ghcr.io/px4/px4-dev:v1.17.0-rc2 + steps: + - uses: runs-on/action@v2 + - uses: actions/checkout@v6 + with: + fetch-depth: 1 + - name: Configure Git Safe Directory + run: git config --system --add safe.directory '*' + + - uses: ./.github/actions/setup-ccache + id: ccache + with: + cache-key-prefix: ccache-unittests-coverage + max-size: 300M + + - name: Build and run unit tests with coverage + env: + PX4_SBOM_DISABLE: 1 + run: make tests_coverage + + - name: Upload Coverage Information to Codecov + uses: codecov/codecov-action@v6 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: unittests + files: coverage/lcov.info + disable_search: true + + - uses: ./.github/actions/save-ccache + if: always() + with: + cache-primary-key: ${{ steps.ccache.outputs.cache-primary-key }} diff --git a/.github/workflows/sitl_tests.yml b/.github/workflows/sitl_tests.yml index c1ab6081487..7af085fe569 100644 --- a/.github/workflows/sitl_tests.yml +++ b/.github/workflows/sitl_tests.yml @@ -34,7 +34,8 @@ jobs: config: - {model: "quadx", latitude: "59.617693", longitude: "-151.145316", altitude: "48", build_type: "RelWithDebInfo" } # Alaska - {model: "hex", latitude: "47.397742", longitude: "8.545594", altitude: "488", build_type: "RelWithDebInfo" } # Zurich - - {model: "standard_vtol", latitude: "47.397742", longitude: "8.545594", altitude: "488", build_type: "Coverage" } # Zurich + # Coverage on main only; PRs reuse main's numbers through Codecov carryforward (codecov.yml) + - {model: "standard_vtol", latitude: "47.397742", longitude: "8.545594", altitude: "488", build_type: "${{ github.event_name == 'push' && 'Coverage' || 'RelWithDebInfo' }}" } # Zurich - {model: "xvert", latitude: "47.397742", longitude: "8.545594", altitude: "488", build_type: "RelWithDebInfo" } # Zurich env: PX4_CMAKE_BUILD_TYPE: ${{ matrix.config.build_type }} @@ -51,7 +52,7 @@ jobs: - uses: ./.github/actions/setup-ccache id: ccache with: - cache-key-prefix: ccache-sitl-gazebo-classic + cache-key-prefix: ccache-mavsdk-tests-${{ matrix.config.build_type }} max-size: 350M - name: Build PX4 SITL @@ -121,20 +122,17 @@ jobs: name: coredump path: px4.core - - name: Setup & Generate Coverage Report - if: contains(matrix.config.build_type, 'Coverage') + - name: Generate Coverage Report + if: matrix.config.build_type == 'Coverage' run: | - git config --global credential.helper "" # disable the keychain credential helper - git config --global --add credential.helper store # enable the local store credential helper - echo "https://x-access-token:${{ secrets.ACCESS_TOKEN }}@github.com" >> ~/.git-credentials # add credential - git config --global url."https://github.com/".insteadof git@github.com: # credentials add credential mkdir -p coverage lcov --directory build/px4_sitl_default --base-directory build/px4_sitl_default --gcov-tool gcov --capture -o coverage/lcov.info --ignore-errors negative - name: Upload Coverage Information to Codecov - if: contains(matrix.config.build_type, 'Coverage') + if: matrix.config.build_type == 'Coverage' uses: codecov/codecov-action@v6 with: token: ${{ secrets.CODECOV_TOKEN }} - flags: mavsdk - file: coverage/lcov.info + flags: sitl-vtol + files: coverage/lcov.info + disable_search: true diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake index bbc1d423cfe..6706f80e617 100644 --- a/cmake/coverage.cmake +++ b/cmake/coverage.cmake @@ -37,10 +37,10 @@ find_program(GENHTML_PATH genhtml) message(STATUS "Building for code coverage") if (CMAKE_BUILD_TYPE STREQUAL Coverage) - # Coverage instrumentation plus atomic updates + # No -fprofile-update=atomic: ccache 4.9.1 (Ubuntu 24.04) refuses to cache it, + # and racy counters only undercount hits, never drop a covered line. set(COVERAGE_FLAGS --coverage - -fprofile-update=atomic ) # Apply to every compile and link invocation diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000000..861c68afc1e --- /dev/null +++ b/codecov.yml @@ -0,0 +1,58 @@ +# Codecov configuration, see https://docs.codecov.com/docs/codecov-yaml +# +# Two uploads feed coverage: +# unittests .github/workflows/checks.yml make tests_coverage, every PR and push to main +# sitl-vtol .github/workflows/sitl_tests.yml standard_vtol MAVSDK flight, push to main only +# PRs upload unittests only; sitl-vtol is carried forward from main. + +codecov: + branch: main + +coverage: + status: + project: + default: + informational: true + patch: + default: + informational: true + +comment: + layout: "condensed_header, condensed_files, condensed_footer" + require_changes: true + +flag_management: + default_rules: + carryforward: false + individual_flags: + - name: unittests + - name: sitl-vtol + carryforward: true + +ignore: + - "build/**" + - "test/**" + - "**/test/**" + - "**/tests/**" + - "**/*Test.cpp" + - "**/*_test.cpp" + - "**/*_tests.cpp" + - "**/test_*.cpp" + # Submodules and vendored code + - "platforms/nuttx/NuttX/**" + - "src/modules/mavlink/mavlink/**" + - "src/drivers/gps/devices/**" + - "src/drivers/cyphal/libcanard/**" + - "src/drivers/uavcan/libdronecan/**" + - "src/lib/crypto/monocypher/**" + - "src/lib/crypto/libtomcrypt/**" + - "src/lib/crypto/libtommath/**" + - "src/lib/events/libevents/**" + - "src/lib/cdrstream/cyclonedds/**" + - "src/lib/cdrstream/rosidl/**" + - "src/lib/heatshrink/heatshrink/**" + - "src/lib/rl_tools/rl_tools/**" + - "src/lib/tensorflow_lite_micro/tflite_micro/**" + - "src/modules/uxrce_dds_client/Micro-XRCE-DDS-Client*/**" + - "src/modules/zenoh/zenoh-pico/**" + - "Tools/**"