Skip to content

Commit a122959

Browse files
committed
Use ctest, parallelize tests, report coverage
This commit introduces a few improvements to the test framework: * Support for `ctest` Tests can now be run with: ``` ctest -j $(nproc) ``` This will automatically take care of running all the tests, including the MPI tests (with two process) and the GPU tests (if applicable). Tests run in this way are not run in parallel. Note, OpenMP threads are not accounted here, so the total number of cores used is $(nproc) * NUM_OMP_THREADS * New test tag `NoConcurrent` and new fixture `TempDirFixture` Since tests can now be run in parallel, we need to tag tests that cannot be run concurrently (e.g., because they used shared resources). A common use case of `NoConcurrent` is for file-system operations. However, this is a better way to deal with this problem: ensuring isolation and clean up of tests. To help with this, I added a new fixture, `TempDirFixture`, that automatically creates and destroy testing directories. * script to compute coverage `measure-test-coverage` is a new script that uses the ctest capabilities and lcov to distill coverage information and produce html reports. `measure-test-coverage` can be used to: 1. produce the coverage.info objects by running the tests 2. merge different coverage.info objects 3. produce the html report from the coverage.info files When run locally, `measure-test-coverage report` will probably cover most of the use cases. The need to handle different coverage.info objects might become relevant in the future for CI (if test coverage information is split across different workers) * Coverage is now computed as part of CI: With all the previous advancements, we can now compute coverage as part of CI and produce a report. The report can be downloaded from the job page on GitHub actions.
1 parent e6fe762 commit a122959

File tree

11 files changed

+832
-139
lines changed

11 files changed

+832
-139
lines changed

.github/workflows/build-and-test-linux.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ jobs:
225225
with-solver: strumpack
226226

227227
# Flaky arm builds with ubuntu 24 means we pin to ubuntu 22
228+
# (See comment above matrix)
228229
runs-on: ${{ matrix.arch == 'x86' && 'palace_ubuntu-latest_16-core' || 'ubuntu-22.04-arm' }}
229230
steps:
230231
- uses: actions/checkout@v4
@@ -248,12 +249,19 @@ jobs:
248249
sudo update-alternatives --install $(which gfortran) gfortran $(which gfortran-$GFORT_VERSION) ${GFORT_VERSION}0
249250
sudo update-alternatives --set gfortran $(which gfortran-$GFORT_VERSION)
250251
sudo update-alternatives --install $(which gcc) gcc $(which gcc-$GCC_VERSION) ${GCC_VERSION}0 \
251-
--slave $(which g++) g++ $(which g++-$GCC_VERSION)
252+
--slave $(which g++) g++ $(which g++-$GCC_VERSION) \
253+
--slave $(which gcov) gcov $(which gcov-$GCC_VERSION) \
254+
--slave $(which gcov-tool) gcov-tool $(which gcov-tool-$GCC_VERSION)
252255
sudo update-alternatives --set gcc $(which gcc-$GCC_VERSION)
253256
254257
gfortran --version
255258
gcc --version
256259
g++ --version
260+
- name: Configure LCOV
261+
if: needs.filter.outputs.test == 'true'
262+
run: |
263+
sudo apt-get install -y lcov
264+
257265
- name: Configure Open MPI
258266
if: needs.filter.outputs.test == 'true' && matrix.mpi == 'openmpi'
259267
run: |
@@ -428,6 +436,7 @@ jobs:
428436
-DPALACE_WITH_MUMPS=$WITH_MUMPS \
429437
-DPALACE_WITH_SLEPC=$WITH_SLEPC \
430438
-DPALACE_WITH_ARPACK=$WITH_ARPACK \
439+
-DPALACE_BUILD_WITH_COVERAGE=ON \
431440
-DPALACE_MFEM_USE_EXCEPTIONS=ON
432441
make -j$NUM_PROC_BUILD palace-tests
433442
@@ -454,12 +463,15 @@ jobs:
454463
export LD_LIBRARY_PATH="$AOCLROOT/lib:$LD_LIBRARY_PATH"
455464
fi
456465
457-
cd $(pwd)/palace-build/palace-build/test/unit
466+
scripts/measure-test-coverage report $(pwd)/palace-build/palace-build/test/unit/unit-tests
458467
459-
# Run Serial tests
460-
./unit-tests --skip-benchmarks
461-
# Run Parallel tests
462-
mpirun -np $NUM_PROC_TEST_MAX ./unit-tests --skip-benchmarks
468+
- name: Upload coverage report
469+
# Upload only for one representative case.
470+
if: needs.filter.outputs.test == 'true' && matrix.arch == 'x86' && matrix.compiler == 'gcc' && matrix.mpi == 'openmpi' && matrix.math-libs == 'openblas'
471+
uses: actions/upload-artifact@v4
472+
with:
473+
name: coverage-${{ matrix.arch }}-${{ matrix.compiler }}-${{ matrix.mpi }}
474+
path: palace-build/palace-build/coverage_html/
463475

464476
- name: Run regression tests for examples/
465477
if: needs.filter.outputs.test == 'true'

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ test/examples/ref/**/*.json
99
.gitlab-ci-local
1010
Manifest.toml
1111
.vscode/
12+
13+
# Coverage files
14+
*.profraw
15+
*.gcno
16+
*.gcda
17+
coverage*.info
18+
*/coverage_html/*

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,5 +220,14 @@ include(ExternalMFEM)
220220
message(STATUS "========================== Configuring Palace ==========================")
221221
include(ExternalPalace)
222222

223+
# Create CTestTestfile manually (don't use enable_testing() as it gets overwritten)
224+
file(WRITE "${CMAKE_BINARY_DIR}/CTestTestfile.cmake" "
225+
# CMake generated Testfile for Palace superbuild
226+
set(CTEST_PROJECT_NAME \"palace\")
227+
228+
# Include palace unit tests
229+
subdirs(\"palace-build/test/unit\")
230+
")
231+
223232
# Finished with superbuild configuration
224233
message(STATUS "======================= Configure stage complete =======================")

0 commit comments

Comments
 (0)