Skip to content

Commit 1885016

Browse files
committed
test coverage
1 parent 0a68648 commit 1885016

File tree

2 files changed

+152
-10
lines changed

2 files changed

+152
-10
lines changed

.github/workflows/coverage.yml

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ on: [push, pull_request, workflow_dispatch]
55
jobs:
66
file-changes:
77
name: Detect File Changes
8-
runs-on: 'ubuntu-latest'
9-
outputs:
8+
runs-on: ubuntu-latest
9+
outputs:
1010
checkall: ${{ steps.changes.outputs.checkall }}
1111
steps:
1212
- name: Clone
@@ -15,34 +15,66 @@ jobs:
1515
- name: Detect Changes
1616
uses: dorny/paths-filter@v3
1717
id: changes
18-
with:
18+
with:
1919
filters: ".github/file-filter.yml"
2020

2121
run:
2222
name: Coverage Test on CodeCov
2323
if: needs.file-changes.outputs.checkall == 'true'
2424
needs: file-changes
25-
runs-on: "ubuntu-latest"
25+
runs-on: ubuntu-latest
2626
steps:
2727
- name: Checkouts
2828
uses: actions/checkout@v4
2929

3030
- name: Setup Ubuntu
3131
run: |
32-
sudo apt update -y
33-
sudo apt install -y tar wget make cmake gcc g++ python3 \
34-
python3-dev "openmpi-*" libopenmpi-dev hdf5-tools \
35-
libfftw3-dev libhdf5-dev libblas-dev liblapack-dev
32+
sudo apt update -y
33+
sudo apt install -y tar wget make cmake gcc g++ python3 python3-pip \
34+
"openmpi-*" libopenmpi-dev hdf5-tools libfftw3-dev libhdf5-dev \
35+
libblas-dev liblapack-dev
36+
python3 -m pip install --upgrade pip gcovr
3637
37-
- name: Build
38+
- name: Build (with coverage)
3839
run: /bin/bash mfc.sh build -j $(nproc) --gcov
3940

4041
- name: Test
4142
run: /bin/bash mfc.sh test -a -j $(nproc)
4243

43-
- name: Upload coverage reports to Codecov
44+
- name: Generate coverage (gcovr XML)
45+
run: |
46+
# Create a stable, filtered XML that points to build-side files first
47+
gcovr \
48+
--root "${{ github.workspace }}" \
49+
--object-directory "${{ github.workspace }}/build" \
50+
--filter '.*/fypp/.+\.f90$' \
51+
--exclude '.*(tests|examples|toolchain|docs|benchmarks)/.*' \
52+
--gcov-ignore-parse-errors \
53+
--xml-pretty -o coverage.xml
54+
55+
- name: Rewrite paths from generated .fpp.f90 -> repo .fpp
56+
run: |
57+
python3 - <<'PY'
58+
import os, xml.etree.ElementTree as ET
59+
fn = "coverage.xml"
60+
t = ET.parse(fn)
61+
r = t.getroot()
62+
for c in r.iter('class'):
63+
p = c.get('filename') or ''
64+
if p.endswith('.fpp.f90'):
65+
base = os.path.basename(p).rsplit('.fpp.f90', 1)[0] + '.fpp'
66+
for sub in ('pre_process','simulation','post_process','common'):
67+
cand = os.path.join('src', sub, base)
68+
if os.path.exists(cand):
69+
c.set('filename', cand)
70+
break
71+
t.write(fn, encoding='utf-8', xml_declaration=True)
72+
PY
73+
74+
- name: Upload coverage to Codecov (XML only)
4475
uses: codecov/codecov-action@v4
4576
with:
77+
files: coverage.xml
4678
fail_ci_if_error: false
4779
verbose: true
4880
env:

scripts/generate_coverage.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
# MFC Coverage Generation Script
4+
# This script generates coverage reports locally using gcovr with the same
5+
# configuration as the CI workflow.
6+
7+
set -e
8+
9+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
MFC_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
11+
12+
echo "MFC Coverage Generation"
13+
echo "======================"
14+
echo "Root directory: $MFC_ROOT"
15+
echo
16+
17+
# Check if gcovr is available
18+
if ! command -v gcovr &> /dev/null; then
19+
echo "Error: gcovr is not installed. Install it with:"
20+
echo " pip install gcovr"
21+
exit 1
22+
fi
23+
24+
cd "$MFC_ROOT"
25+
26+
# Check if MFC was built with coverage
27+
if [ ! -d "build" ]; then
28+
echo "Error: No build directory found. Build MFC with coverage first:"
29+
echo " ./mfc.sh build --gcov -j \$(nproc)"
30+
exit 1
31+
fi
32+
33+
# Look for gcov files
34+
GCOV_FILES=$(find build -name "*.gcda" 2>/dev/null | wc -l)
35+
if [ "$GCOV_FILES" -eq 0 ]; then
36+
echo "Warning: No coverage data found. Run tests first:"
37+
echo " ./mfc.sh test -j \$(nproc) -f EA8FA07E -t 9E2CA336"
38+
echo
39+
fi
40+
41+
echo "Generating coverage reports..."
42+
43+
# Generate XML coverage report (same as CI)
44+
gcovr \
45+
--root "$MFC_ROOT" \
46+
--object-directory "$MFC_ROOT/build" \
47+
--filter '.*/fypp/.+\.f90$' \
48+
--exclude '.*(tests|examples|toolchain|docs|benchmarks)/.*' \
49+
--gcov-ignore-parse-errors \
50+
--xml-pretty -o coverage.xml
51+
52+
echo "Generated coverage.xml"
53+
54+
# Also generate a broader report for debugging
55+
gcovr \
56+
--root "$MFC_ROOT" \
57+
--object-directory "$MFC_ROOT/build" \
58+
--exclude '.*(tests|examples|toolchain|docs|benchmarks)/.*' \
59+
--gcov-ignore-parse-errors \
60+
--xml-pretty -o coverage_all.xml
61+
62+
echo "Generated coverage_all.xml (broader scope for debugging)"
63+
64+
# Generate HTML coverage report for local viewing
65+
gcovr \
66+
--root "$MFC_ROOT" \
67+
--object-directory "$MFC_ROOT/build" \
68+
--filter '.*/fypp/.+\.f90$' \
69+
--exclude '.*(tests|examples|toolchain|docs|benchmarks)/.*' \
70+
--gcov-ignore-parse-errors \
71+
--html-details -o coverage.html
72+
73+
echo "Generated coverage.html"
74+
75+
# Rewrite paths from generated .fpp.f90 -> repo .fpp (same as CI)
76+
python3 - <<'PY'
77+
import os, xml.etree.ElementTree as ET
78+
79+
print("Rewriting XML paths from generated .fpp.f90 to source .fpp files...")
80+
81+
fn = "coverage.xml"
82+
if not os.path.exists(fn):
83+
print(f"Error: {fn} not found")
84+
exit(1)
85+
86+
t = ET.parse(fn)
87+
r = t.getroot()
88+
remapped = 0
89+
90+
for c in r.iter('class'):
91+
p = c.get('filename') or ''
92+
if p.endswith('.fpp.f90'):
93+
base = os.path.basename(p).rsplit('.fpp.f90', 1)[0] + '.fpp'
94+
for sub in ('pre_process','simulation','post_process','common'):
95+
cand = os.path.join('src', sub, base)
96+
if os.path.exists(cand):
97+
c.set('filename', cand)
98+
remapped += 1
99+
break
100+
101+
t.write(fn, encoding='utf-8', xml_declaration=True)
102+
print(f"Remapped {remapped} file paths in coverage.xml")
103+
PY
104+
105+
echo
106+
echo "Coverage reports generated:"
107+
echo " - coverage.xml (for Codecov upload)"
108+
echo " - coverage.html (for local viewing)"
109+
echo
110+
echo "To view the HTML report, open coverage.html in your browser."

0 commit comments

Comments
 (0)