Skip to content

Commit 9f1dd45

Browse files
committed
CI: add code coverage workflow
1 parent ddd9c1a commit 9f1dd45

1 file changed

Lines changed: 156 additions & 0 deletions

File tree

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: Code Coverage
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'main', 'release/**' ]
6+
pull_request:
7+
branches: [ '*' ]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build_wolfssl:
16+
name: Build wolfSSL
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
steps:
20+
- name: Checkout wolfSSL
21+
uses: actions/checkout@v6
22+
with:
23+
repository: wolfssl/wolfssl
24+
path: wolfssl
25+
26+
- name: Build wolfSSL
27+
working-directory: ./wolfssl
28+
run: |
29+
./autogen.sh
30+
./configure --enable-wolfssh --enable-keygen --enable-pkcallbacks
31+
make -j$(nproc)
32+
sudo make install
33+
sudo ldconfig
34+
35+
- name: tar build-dir
36+
run: tar -zcf wolfssl-install.tgz /usr/local/lib/libwolfssl* /usr/local/include/wolfssl
37+
38+
- name: Upload built lib
39+
uses: actions/upload-artifact@v7
40+
with:
41+
name: wolfssl-coverage
42+
path: wolfssl-install.tgz
43+
retention-days: 5
44+
45+
# Use clang to report line, branch, function and MC/DC coverage in one run.
46+
coverage:
47+
name: Coverage
48+
runs-on: ubuntu-latest
49+
timeout-minutes: 30
50+
needs: build_wolfssl
51+
steps:
52+
- name: Checkout wolfSSH
53+
uses: actions/checkout@v6
54+
55+
# clang 18 is the min: -fcoverage-mcdc does not exist before it.
56+
- name: Install clang and LLVM coverage tools
57+
run: |
58+
sudo apt-get update
59+
sudo apt-get install -y clang-18 llvm-18 libclang-rt-18-dev
60+
61+
- name: Download wolfSSL
62+
uses: actions/download-artifact@v8
63+
with:
64+
name: wolfssl-coverage
65+
66+
- name: Install wolfSSL
67+
run: |
68+
sudo tar -xzf wolfssl-install.tgz -C /
69+
sudo ldconfig
70+
71+
# -O0 keeps line and branch attribution honest; atomic counters are
72+
# required because several tests drive client and server on separate
73+
# threads, and the default non-atomic updates lose increments.
74+
- name: Build wolfSSH
75+
run: |
76+
./autogen.sh
77+
./configure --enable-all CC=clang-18 \
78+
CFLAGS="-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc -fprofile-update=atomic -O0 -g" \
79+
LDFLAGS="-fprofile-instr-generate"
80+
make -j$(nproc)
81+
82+
# %p in the pattern keeps forked servers from overwriting the raw
83+
# profile of the client that spawned them.
84+
- name: Run tests
85+
run: |
86+
mkdir -p prof
87+
LLVM_PROFILE_FILE="$PWD/prof/%p-%m.profraw" \
88+
timeout -k 30 1200 make check
89+
90+
- name: Report coverage
91+
run: |
92+
llvm-profdata-18 merge -sparse prof/*.profraw -o wolfssh.profdata
93+
# llvm-cov takes one binary positionally and the rest via -object.
94+
# Tests linking the shared library are libtool wrapper scripts, so
95+
# take the real binary from .libs when one is there.
96+
first=""
97+
args=()
98+
for t in tests/*.test; do
99+
real="tests/.libs/$(basename "$t")"
100+
[ -x "$real" ] || real="$t"
101+
if [ -z "$first" ]; then first="$real"; else args+=(-object "$real"); fi
102+
done
103+
ignore='(tests|examples|apps)/.*|.*/include/wolfssl/.*|.*/wolfssh/.*\.h'
104+
llvm-cov-18 report "$first" "${args[@]}" \
105+
-instr-profile=wolfssh.profdata \
106+
--show-mcdc-summary \
107+
--ignore-filename-regex="$ignore" | tee coverage-report.txt
108+
llvm-cov-18 show "$first" "${args[@]}" \
109+
-instr-profile=wolfssh.profdata \
110+
--show-mcdc --format=html --output-dir=coverage-html \
111+
--ignore-filename-regex="$ignore"
112+
# lcov text for any external dashboard that consumes it.
113+
llvm-cov-18 export "$first" "${args[@]}" \
114+
-instr-profile=wolfssh.profdata \
115+
--format=lcov \
116+
--ignore-filename-regex="$ignore" > coverage.lcov
117+
{
118+
echo '### Coverage'
119+
echo '```'
120+
cat coverage-report.txt
121+
echo '```'
122+
} >> "$GITHUB_STEP_SUMMARY"
123+
124+
- name: Upload coverage report
125+
uses: actions/upload-artifact@v7
126+
with:
127+
name: coverage-report
128+
path: |
129+
coverage-report.txt
130+
coverage.lcov
131+
coverage-html/
132+
retention-days: 30
133+
134+
- name: Show test logs on failure
135+
if: failure()
136+
run: |
137+
echo "=== test-suite.log ==="
138+
cat test-suite.log || true
139+
for f in tests/*.log scripts/*.log; do
140+
[ -f "$f" ] || continue
141+
echo ""
142+
echo "=== $f ==="
143+
cat "$f"
144+
done
145+
146+
- name: Upload failure logs
147+
if: failure()
148+
uses: actions/upload-artifact@v7
149+
with:
150+
name: wolfssh-coverage-logs
151+
path: |
152+
test-suite.log
153+
tests/*.log
154+
scripts/*.log
155+
config.log
156+
retention-days: 5

0 commit comments

Comments
 (0)