ci(codecov): upload unit test coverage (#28869)

* ci(codecov): upload unit test coverage and limit SITL coverage to main

Coverage on main came from a single standard_vtol SITL flight, unit tests
were never uploaded, and the Coverage build never hit ccache because
ccache 4.9.1 (Ubuntu 24.04) rejects -fprofile-update=atomic. The flag only
keeps hit counts exact under thread races; line coverage is unaffected and
lcov already ignores the resulting negative counts.

Unit tests now build with coverage and upload as the unittests flag on
every PR and push to main. standard_vtol builds as Coverage on main only
and uploads as sitl-vtol, carried forward on PRs. codecov.yml sets the
default branch, informational project/patch statuses and ignores.
Per-build-type ccache keys stop the Coverage and RelWithDebInfo jobs from
overwriting each other's cache.

Fixes #28862

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Ramon Roche <mrpollo@gmail.com>

* ci(codecov): run unit test coverage as its own job

The Coverage build shifts EKF replay float output, so running it in the
Unit Tests job made the change indication step auto-commit new baselines
to the PR branch. Unit Tests goes back to the plain build and a separate
job produces the unittests upload. disable_search keeps the Codecov
uploader to the lcov report instead of running gcov over the build tree.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Ramon Roche <mrpollo@gmail.com>

---------

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
This commit is contained in:
Ramon Roche authored and GitHub committed 2026-09-26 19:11:53 -07:00
1 parent bf9b1610ca
commit 939b420488
4 files changed
+108 -13

No files matched your search

+39
View File
@@ -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 }}
+9 -11
View File
@@ -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
+2 -2
View File
@@ -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
+58
View File
@@ -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/**"