Skip to content

Commit d5800ad

Browse files
authored
Merge pull request #121 from cindytsai/codecov
Upload code coverage
2 parents 7e801a3 + c916eba commit d5800ad

File tree

5 files changed

+166
-8
lines changed

5 files changed

+166
-8
lines changed

.github/workflows/example-test-run.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,65 @@ jobs:
8080
make LIBYT_PATH="${{ steps.strings.outputs.install }}"
8181
OMPI_MCA_osc=sm,pt2pt mpirun -np 3 ./example DataIOTest.py
8282
83+
example-parallel-codecov:
84+
name: parallel
85+
runs-on: ${{ matrix.os }}
86+
strategy:
87+
fail-fast: false
88+
matrix:
89+
os: ['ubuntu-latest']
90+
mpi_compiler: ['openmpi']
91+
python_version: ['3.10']
92+
install_dep_command: ['sudo apt-get install -y libreadline-dev uuid-dev lcov']
93+
build_pybind11_option: ['-DUSE_PYBIND11=ON', '-DUSE_PYBIND11=OFF']
94+
95+
steps:
96+
- uses: actions/checkout@v4
97+
98+
- name: Setup MPI ${{ matrix.mpi_compiler }} environment
99+
uses: mpi4py/setup-mpi@v1
100+
with:
101+
mpi: ${{ matrix.mpi_compiler }}
102+
103+
- name: Setup Python ${{ matrix.python_version }} environment
104+
uses: actions/setup-python@v5
105+
with:
106+
python-version: ${{ matrix.python_version }}
107+
cache: 'pip'
108+
- run: |
109+
python -m pip install --upgrade pip
110+
pip install numpy mpi4py yt yt-libyt pandas
111+
112+
- name: Install other dependencies
113+
run: |
114+
${{ matrix.install_dep_command }}
115+
116+
- name: Configure and Build
117+
run: |
118+
cd ${{ github.workspace }}
119+
rm -rf build
120+
cmake -B build -S . -DINTERACTIVE_MODE=ON -DJUPYTER_KERNEL=ON -DCODE_COVERAGE=ON \
121+
${{ matrix.build_pybind11_option }}
122+
cmake --build build
123+
124+
- name: End-to-End Test - AMR Example - MPI Size 3
125+
working-directory: ${{ github.workspace }}/build/example/amr-example
126+
run: |
127+
OMPI_MCA_osc=sm,pt2pt mpirun -np 3 ./example
128+
129+
- name: Generate code coverage report
130+
working-directory: ${{ github.workspace }}/build/src/CMakeFiles/yt.dir
131+
run: |
132+
lcov --directory . --capture --ignore-errors mismatch --output-file coverage.info
133+
lcov --extract coverage.info "*/libyt/src/*" "*/libyt/include/*" -o coverage-project-only.info
134+
135+
- name: Upload code coverage report to Codecov
136+
uses: codecov/codecov-action@v5
137+
with:
138+
token: ${{ secrets.CODECOV_TOKEN }}
139+
files: ${{ github.workspace }}/build/src/CMakeFiles/yt.dir/coverage-project-only.info
140+
verbose: true
141+
83142
example-serial-test-run:
84143
name: serial
85144
runs-on: ${{ matrix.os }}
@@ -137,3 +196,56 @@ jobs:
137196
make clean
138197
make OPTIONS=-DSERIAL_MODE LIBYT_PATH="${{ steps.strings.outputs.install }}"
139198
./example DataIOTest.py
199+
200+
example-serial-codecov:
201+
name: serial
202+
runs-on: ${{ matrix.os }}
203+
strategy:
204+
fail-fast: false
205+
matrix:
206+
os: ['ubuntu-latest']
207+
python_version: ['3.10']
208+
install_dep_command: ['sudo apt-get install -y libreadline-dev uuid-dev lcov']
209+
build_pybind11_option: ['-DUSE_PYBIND11=ON', '-DUSE_PYBIND11=OFF']
210+
211+
steps:
212+
- uses: actions/checkout@v4
213+
214+
- name: Setup Python ${{ matrix.python_version }} environment
215+
uses: actions/setup-python@v5
216+
with:
217+
python-version: ${{ matrix.python_version }}
218+
cache: 'pip'
219+
- run: |
220+
python -m pip install --upgrade pip
221+
pip install numpy yt yt-libyt pandas
222+
223+
- name: Install other dependencies
224+
run: |
225+
${{ matrix.install_dep_command }}
226+
227+
- name: Configure and Build
228+
run: |
229+
cd ${{ github.workspace }}
230+
rm -rf build
231+
cmake -B build -S . -DINTERACTIVE_MODE=ON -DJUPYTER_KERNEL=ON -DSERIAL_MODE=ON -DCODE_COVERAGE=ON \
232+
${{ matrix.build_pybind11_option }}
233+
cmake --build build
234+
235+
- name: End-to-End Test - AMR Example - Serial
236+
working-directory: ${{ github.workspace }}/build/example/amr-example
237+
run: |
238+
./example
239+
240+
- name: Generate code coverage report
241+
working-directory: ${{ github.workspace }}/build/src/CMakeFiles/yt.dir
242+
run: |
243+
lcov --directory . --capture --ignore-errors mismatch --output-file coverage.info
244+
lcov --extract coverage.info "*/libyt/src/*" "*/libyt/include/*" -o coverage-project-only.info
245+
246+
- name: Upload code coverage report to Codecov
247+
uses: codecov/codecov-action@v5
248+
with:
249+
token: ${{ secrets.CODECOV_TOKEN }}
250+
files: ${{ github.workspace }}/build/src/CMakeFiles/yt.dir/coverage-project-only.info
251+
verbose: true

.github/workflows/unit-test.yml

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Since some of the classes is still coupled to MPI, we need to run the unit tests with/without MPI.
2+
# Also upload the code coverage report to codecov
23

34
name: unit test
45

@@ -26,9 +27,10 @@ jobs:
2627
os: ['ubuntu-latest']
2728
mpi_compiler: ['openmpi', 'mpich']
2829
python_version: ['3.10']
30+
lcov_cmd: ['--ignore-errors mismatch']
2931
build_options:
30-
- "-DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DUSE_PYBIND11=ON"
31-
- "-DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DUSE_PYBIND11=OFF"
32+
- "-DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DCODE_COVERAGE=ON -DUSE_PYBIND11=ON"
33+
- "-DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DCODE_COVERAGE=ON -DUSE_PYBIND11=OFF"
3234

3335
steps:
3436
- uses: actions/checkout@v4
@@ -58,7 +60,7 @@ jobs:
5860
5961
- name: Install other dependencies
6062
run: |
61-
sudo apt-get install -y libreadline-dev
63+
sudo apt-get install -y libreadline-dev lcov
6264
6365
- name: Set reusable strings
6466
id: strings
@@ -92,6 +94,19 @@ jobs:
9294
run: |
9395
OMPI_MCA_osc=sm,pt2pt mpirun -np 3 ./TestDataStructureAmrWithCommMpi
9496
97+
- name: Generate code coverage report
98+
working-directory: ${{ steps.strings.outputs.build-output-dir }}/src/CMakeFiles/yt.dir
99+
run: |
100+
lcov --directory . --capture ${{ matrix.lcov_cmd }} --output-file coverage.info
101+
lcov --extract coverage.info "*/libyt/src/*" "*/libyt/include/*" -o coverage-project-only.info
102+
103+
- name: Upload code coverage report to Codecov
104+
uses: codecov/codecov-action@v5
105+
with:
106+
token: ${{ secrets.CODECOV_TOKEN }}
107+
files: ${{ steps.strings.outputs.build-output-dir }}/src/CMakeFiles/yt.dir/coverage-project-only.info
108+
verbose: true
109+
95110
unit-test:
96111
name: serial
97112
runs-on: ${{ matrix.os }}
@@ -101,16 +116,17 @@ jobs:
101116
matrix:
102117
os: ['ubuntu-latest']
103118
python_version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
119+
lcov_cmd: ['--ignore-errors mismatch']
104120
build_options:
105-
- "-DSERIAL_MODE=ON -DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DUSE_PYBIND11=ON"
106-
- "-DSERIAL_MODE=ON -DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DUSE_PYBIND11=OFF"
121+
- "-DSERIAL_MODE=ON -DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DCODE_COVERAGE=ON -DUSE_PYBIND11=ON"
122+
- "-DSERIAL_MODE=ON -DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DCODE_COVERAGE=ON -DUSE_PYBIND11=OFF"
107123
include:
108124
- os: ubuntu-22.04
109125
python_version: '3.7'
110-
build_options: "-DSERIAL_MODE=ON -DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DUSE_PYBIND11=ON"
126+
build_options: "-DSERIAL_MODE=ON -DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DCODE_COVERAGE=ON -DUSE_PYBIND11=ON"
111127
- os: ubuntu-22.04
112128
python_version: '3.7'
113-
build_options: "-DSERIAL_MODE=ON -DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DUSE_PYBIND11=OFF"
129+
build_options: "-DSERIAL_MODE=ON -DINTERACTIVE_MODE=ON -DLIBYT_RUN_TEST=ON -DCODE_COVERAGE=ON -DUSE_PYBIND11=OFF"
114130

115131
steps:
116132
- uses: actions/checkout@v4
@@ -127,7 +143,7 @@ jobs:
127143
128144
- name: Install other dependencies
129145
run: |
130-
sudo apt-get install -y libreadline-dev
146+
sudo apt-get install -y libreadline-dev lcov
131147
132148
- name: Set reusable strings
133149
id: strings
@@ -160,3 +176,16 @@ jobs:
160176
working-directory: ${{ steps.strings.outputs.build-output-dir }}/test/unit_test
161177
run: |
162178
./TestDataStructureAmr
179+
180+
- name: Generate code coverage report
181+
working-directory: ${{ steps.strings.outputs.build-output-dir }}/src/CMakeFiles/yt.dir
182+
run: |
183+
lcov --directory . --capture ${{ matrix.lcov_cmd }} --output-file coverage.info
184+
lcov --extract coverage.info "*/libyt/src/*" "*/libyt/include/*" -o coverage-project-only.info
185+
186+
- name: Upload code coverage report to Codecov
187+
uses: codecov/codecov-action@v5
188+
with:
189+
token: ${{ secrets.CODECOV_TOKEN }}
190+
files: ${{ steps.strings.outputs.build-output-dir }}/src/CMakeFiles/yt.dir/coverage-project-only.info
191+
verbose: true

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(VALGRIND_PATH "" CACHE PATH "Path to valgrind installation prefix (-DLIB
4444

4545
option(LIBYT_RUN_TEST "Run unit test" OFF)
4646
option(LIBYT_RUN_MEMORY_PROFILE "Run memory profile" OFF)
47+
option(CODE_COVERAGE "Enable coverage reporting" OFF)
4748

4849
## set path for dependencies ##
4950
set(Python_ROOT_DIR ${PYTHON_PATH})

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![unit test](https://github.com/yt-project/libyt/actions/workflows/unit-test.yml/badge.svg?branch=main)](https://github.com/yt-project/libyt/actions/workflows/unit-test.yml)
55
[![memory profile](https://github.com/yt-project/libyt/actions/workflows/memory-profile.yml/badge.svg?branch=main)](https://github.com/yt-project/libyt/actions/workflows/memory-profile.yml)
66
[![Documentation Status](https://readthedocs.org/projects/libyt/badge/?version=latest)](https://libyt.readthedocs.io/en/latest/?badge=latest)
7+
[![codecov](https://codecov.io/gh/yt-project/libyt/graph/badge.svg?token=NRYLAipewN)](https://codecov.io/gh/yt-project/libyt)
78

89
`libyt` is an open source C library for simulation, that allows researchers to analyze and visualize data using [`yt`](https://yt-project.org/) or other Python packages in parallel during simulation runtime.
910

src/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ add_library(
5858
yt_set_UserParameter.cpp
5959
)
6060

61+
# set code coverage and add yt as target
62+
add_library(coverage_config INTERFACE)
63+
if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
64+
# Add required flags (GCC & LLVM/Clang)
65+
target_compile_options(
66+
coverage_config
67+
INTERFACE
68+
-O0 # no optimization
69+
-g # generate debug info
70+
--coverage # sets all required flags
71+
)
72+
target_link_options(coverage_config INTERFACE --coverage)
73+
endif (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
74+
target_link_libraries(yt PUBLIC coverage_config)
75+
6176
# set and print options and apply compile definition -D
6277
function (set_option option_name)
6378
if (${option_name})

0 commit comments

Comments
 (0)