forked from commaai/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
220 lines (194 loc) · 7.27 KB
/
Copy pathcpp-coverage.yml
File metadata and controls
220 lines (194 loc) · 7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: C++ Coverage
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop
permissions:
contents: read
jobs:
cpp-coverage:
name: C++ Coverage Analysis
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
lfs: false
- name: Pull LFS files (via .lfsconfig endpoint)
run: git lfs pull
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential \
clang \
llvm \
g++-12 \
capnproto \
libcapnp-dev \
libzmq3-dev \
libssl-dev \
libbz2-dev \
libeigen3-dev \
libffi-dev \
libsqlite3-dev \
libzstd-dev \
portaudio19-dev \
libcurl4-openssl-dev \
libjpeg-dev \
libusb-1.0-0-dev \
libncurses5-dev \
opencl-headers \
ocl-icd-libopencl1 \
ocl-icd-opencl-dev \
qt5-qmake \
qtbase5-dev \
libqt5charts5-dev \
libqt5serialbus5-dev \
libqt5svg5-dev \
libqt5x11extras5-dev \
libqt5opengl5-dev \
libgles2-mesa-dev \
libglfw3-dev \
ffmpeg \
libavformat-dev \
libavcodec-dev \
libavdevice-dev \
libavutil-dev \
libavfilter-dev
- name: Install Python dependencies
run: uv sync --frozen --all-extras
- name: Build C++ with coverage
run: |
source .venv/bin/activate
# Build all C++ test directories with coverage instrumentation
scons -u -j$(nproc) --coverage \
openpilot/common/tests/ \
openpilot/system/loggerd/tests/ \
openpilot/system/camerad/test/ \
openpilot/selfdrive/pandad/tests/ \
openpilot/tools/cabana/tests/ \
openpilot/tools/replay/tests/
- name: Run C++ tests
run: |
export LLVM_PROFILE_FILE="default_%p.profraw"
# Core tests
./openpilot/common/tests/test_common || true
./openpilot/system/loggerd/tests/test_logger || true
./openpilot/system/camerad/test/test_ae_gray || true
./openpilot/selfdrive/pandad/tests/test_pandad_usbprotocol || true
# Tools tests
./openpilot/tools/cabana/tests/test_cabana || true
./openpilot/tools/replay/tests/test_replay || true
- name: Generate coverage reports
run: |
# Find llvm tools
LLVM_PROFDATA=$(command -v llvm-profdata-18 || command -v llvm-profdata)
LLVM_COV=$(command -v llvm-cov-18 || command -v llvm-cov)
# Merge profraw files
$LLVM_PROFDATA merge -sparse *.profraw -o coverage.profdata
# Define all test binaries
CORE_BINARIES=""
TOOLS_BINARIES=""
ALL_BINARIES=""
# Core binaries (openpilot common, system, pandad)
for bin in openpilot/common/tests/test_common openpilot/system/loggerd/tests/test_logger openpilot/system/camerad/test/test_ae_gray openpilot/selfdrive/pandad/tests/test_pandad_usbprotocol; do
if [[ -f "$bin" ]]; then
CORE_BINARIES="$CORE_BINARIES -object=$bin"
ALL_BINARIES="$ALL_BINARIES -object=$bin"
fi
done
# Tools binaries (tools/cabana, tools/replay)
for bin in openpilot/tools/cabana/tests/test_cabana openpilot/tools/replay/tests/test_replay; do
if [[ -f "$bin" ]]; then
TOOLS_BINARIES="$TOOLS_BINARIES -object=$bin"
ALL_BINARIES="$ALL_BINARIES -object=$bin"
fi
done
IGNORE_REGEX='third_party|msgq_repo|opendbc_repo|tinygrad_repo|rednose_repo|cereal'
# Generate combined lcov report
$LLVM_COV export $ALL_BINARIES -instr-profile=coverage.profdata \
-ignore-filename-regex="$IGNORE_REGEX" \
-format=lcov > cpp-coverage.lcov
# Generate component-level reports for Codecov
if [[ -n "$CORE_BINARIES" ]]; then
$LLVM_COV export $CORE_BINARIES -instr-profile=coverage.profdata \
-ignore-filename-regex="$IGNORE_REGEX" \
-format=lcov > cpp-core-coverage.lcov
fi
if [[ -n "$TOOLS_BINARIES" ]]; then
$LLVM_COV export $TOOLS_BINARIES -instr-profile=coverage.profdata \
-ignore-filename-regex="$IGNORE_REGEX" \
-format=lcov > cpp-tools-coverage.lcov
fi
# Print summary
echo "## C++ Coverage Summary" >> $GITHUB_STEP_SUMMARY
$LLVM_COV report $ALL_BINARIES -instr-profile=coverage.profdata \
-ignore-filename-regex="$IGNORE_REGEX" | tee coverage-report.txt >> $GITHUB_STEP_SUMMARY
# Extract line coverage percentage
LINE_COV=$(grep "TOTAL" coverage-report.txt | awk '{print $10}' | tr -d '%')
echo "Line coverage: ${LINE_COV}%"
echo "cpp_line_coverage=${LINE_COV}" >> $GITHUB_OUTPUT
- name: Check coverage threshold
run: |
LINE_COV=$(grep "TOTAL" coverage-report.txt | awk '{print $10}' | tr -d '%')
# Threshold set to 15% - current coverage is ~18%
# Target: 80% (see openspec/specs/code-quality/spec.md)
# TODO: Raise threshold as more C++ tests are added
THRESHOLD=15
echo "C++ line coverage: ${LINE_COV}% (threshold: ${THRESHOLD}%)"
if (( $(echo "$LINE_COV < $THRESHOLD" | bc -l) )); then
echo "::error::C++ coverage ${LINE_COV}% is below threshold ${THRESHOLD}%"
exit 1
fi
echo "::notice::C++ coverage ${LINE_COV}% meets threshold ${THRESHOLD}%"
- name: Upload core coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: cpp-core-coverage.lcov
flags: cpp-core
name: cpp-core-coverage
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload tools coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: cpp-tools-coverage.lcov
flags: cpp-tools
name: cpp-tools-coverage
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload combined coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: cpp-coverage.lcov
flags: cpp
name: cpp-coverage
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: cpp-coverage-report
path: |
cpp-coverage.lcov
cpp-core-coverage.lcov
cpp-tools-coverage.lcov
coverage.profdata
coverage-report.txt
retention-days: 7