From e8134e6f11d064ae109dab6b3fb7b28fd1c6e5b1 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Tue, 3 Nov 2026 09:59:44 -0700 Subject: [PATCH 1/5] Add memory-sanitizer end-to-end test in GitHub actions --- .github/workflows/end-to-end-tests.yaml | 49 +++++++++++++++++-------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index d789aaa0..27972fe7 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -45,18 +45,37 @@ jobs: make ctest --rerun-failed --output-on-failure . -# - name: Run python tests -# run: | -# BUILD_DIR=./build \ -# PYTHONPATH=test/:scripts/ \ -# pytest \ -# test/capgen_test/capgen_test_reports.py \ -# test/advection_test/advection_test_reports.py \ -# test/ddthost_test/ddthost_test_reports.py \ -# test/var_compatibility_test/var_compatibility_test_reports.py -# -# - name: Run Fortran to metadata test -# run: cd test && ./test_fortran_to_metadata.sh -# -# - name: Run offline metadata parser test -# run: cd test && ./test_offline_metadata_checker.sh + # End to end tests with memory-error detection enabled + end-to-end-tests-asan: + needs: end-to-end-tests + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v4 + with: + python-version: 3.12 + - name: Update repos and install dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential \ + libopenmpi-dev \ + gfortran-12 \ + cmake \ + python3 \ + git \ + libxml2-utils + python -m pip install --upgrade pip + pip install pytest + - name: Run end-to-end tests under AddressSanitizer + env: + # Check for memory errors (LeakSanitizer is a separate issue) + ASAN_OPTIONS: "detect_leaks=0:detect_stack_use_after_return=1" + run: | + cmake --fresh -S./end-to-end-tests -B./build \ + -DCMAKE_Fortran_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \ + -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" + cd build + make + ctest --rerun-failed --output-on-failure . From 238475cb0edeeaa82a37d457311dbc1c8e899295 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Tue, 3 Nov 2026 10:12:48 -0700 Subject: [PATCH 2/5] Bug fix in end-to-end-tests/instances_advection/main.F90 to avoid segmentation fault detected on NRL's Atlantis system with LLVM 23.1.2 --- .github/workflows/end-to-end-tests.yaml | 2 +- end-to-end-tests/instances_advection/main.F90 | 33 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index 27972fe7..d1092fa1 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -71,7 +71,7 @@ jobs: - name: Run end-to-end tests under AddressSanitizer env: # Check for memory errors (LeakSanitizer is a separate issue) - ASAN_OPTIONS: "detect_leaks=0:detect_stack_use_after_return=1" + ASAN_OPTIONS: "detect_leaks=0" run: | cmake --fresh -S./end-to-end-tests -B./build \ -DCMAKE_Fortran_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \ diff --git a/end-to-end-tests/instances_advection/main.F90 b/end-to-end-tests/instances_advection/main.F90 index 2a1e1c84..8a11cbdc 100644 --- a/end-to-end-tests/instances_advection/main.F90 +++ b/end-to-end-tests/instances_advection/main.F90 @@ -58,24 +58,23 @@ program test_instances_advection !----------------------------------------------------------------- ! 2. Build the host-registered constituent list (specific_humidity) - ! and call ccpp_register_constituents per instance. Each call - ! consumes the host_consts array (new_field sets const_index on - ! the input objects), so we re-instantiate per instance. - !----------------------------------------------------------------- + ! once and call ccpp_register_constituents per instance. + ! host_consts must outlive the constituent tables, which keep + ! pointers into it -- hence the deallocate after teardown. + !----------------------------------------------------------------- + allocate(host_consts(1)) + call host_consts(1)%instantiate( & + std_name='water_vapor_specific_humidity', & + long_name='Water vapor specific humidity', & + diag_name='QV', units='kg kg-1', & + vertical_dim='vertical_layer_dimension', advected=.true., & + default_value=0.0_kind_phys, mixing_ratio_type='wet', & + errcode=errcode, errmsg=errmsg) + if (errcode /= 0) then + write(error_unit, '(2a)') 'instantiate failed: ', trim(errmsg) + stop 1 + end if do ins = 1, ninstances - if (allocated(host_consts)) deallocate(host_consts) - allocate(host_consts(1)) - call host_consts(1)%instantiate( & - std_name='water_vapor_specific_humidity', & - long_name='Water vapor specific humidity', & - diag_name='QV', units='kg kg-1', & - vertical_dim='vertical_layer_dimension', advected=.true., & - default_value=0.0_kind_phys, mixing_ratio_type='wet', & - errcode=errcode, errmsg=errmsg) - if (errcode /= 0) then - write(error_unit, '(2a)') 'instantiate failed: ', trim(errmsg) - stop 1 - end if call ccpp_register_constituents(host_constituents=host_consts, & instance=ins, ninstances=ninstances, & errmsg=errmsg, errcode=errcode) From f049d43f9e906d980046ba043057ca03099cf7dc Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Tue, 3 Nov 2026 12:34:44 -0700 Subject: [PATCH 3/5] Bug fix in several end-to-end tests: tear down ccpp_deallocate_dynamic_constituents before calling ccpp_final --- end-to-end-tests/advection/test_host.F90 | 5 ++++- end-to-end-tests/advection_auto_clone/test_host.F90 | 5 ++++- end-to-end-tests/constituents_dim/main.F90 | 5 ++++- end-to-end-tests/instances_advection/main.F90 | 8 +++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/end-to-end-tests/advection/test_host.F90 b/end-to-end-tests/advection/test_host.F90 index dfbd3c54..fc42235d 100644 --- a/end-to-end-tests/advection/test_host.F90 +++ b/end-to-end-tests/advection/test_host.F90 @@ -1131,6 +1131,10 @@ subroutine test_host(retval, test_suites) end if end do + ! The constituent tables hold pointers into the per-suite dynamic + ! constituent buffers, which ccpp_final frees - tear down first. + call ccpp_deallocate_dynamic_constituents() + do sind = 1, num_suites if (errcode == 0) then call ccpp_final(suite_name=test_suites(sind)%suite_name, & @@ -1145,7 +1149,6 @@ subroutine test_host(retval, test_suites) end if end do - call ccpp_deallocate_dynamic_constituents() deallocate(host_constituents) if (errcode == 0) then diff --git a/end-to-end-tests/advection_auto_clone/test_host.F90 b/end-to-end-tests/advection_auto_clone/test_host.F90 index 7845ca79..c9411b11 100644 --- a/end-to-end-tests/advection_auto_clone/test_host.F90 +++ b/end-to-end-tests/advection_auto_clone/test_host.F90 @@ -1119,6 +1119,10 @@ subroutine test_host(retval, test_suites) end if end do + ! The constituent tables hold pointers into the per-suite dynamic + ! constituent buffers, which ccpp_final frees - tear down first. + call ccpp_deallocate_dynamic_constituents() + do sind = 1, num_suites if (errcode == 0) then call ccpp_final(suite_name=test_suites(sind)%suite_name, & @@ -1133,7 +1137,6 @@ subroutine test_host(retval, test_suites) end if end do - call ccpp_deallocate_dynamic_constituents() deallocate(host_constituents) if (errcode == 0) then diff --git a/end-to-end-tests/constituents_dim/main.F90 b/end-to-end-tests/constituents_dim/main.F90 index da2062ff..b6958a14 100644 --- a/end-to-end-tests/constituents_dim/main.F90 +++ b/end-to-end-tests/constituents_dim/main.F90 @@ -98,11 +98,14 @@ program test_constituents_dim errmsg=errmsg, errcode=errcode) call check('ccpp_physics_final') + ! The constituent tables hold pointers into the per-suite dynamic + ! constituent buffers, which ccpp_final frees - tear down first. + call ccpp_deallocate_dynamic_constituents() + ! ccpp_final -> suite_data_final_fields frees both suite workspaces (guarded). call ccpp_final(suite_name=trim(ccpp_suite), errmsg=errmsg, errcode=errcode) call check('ccpp_final') - call ccpp_deallocate_dynamic_constituents() deallocate(host_constituents) if (allocated(coupler_flux)) deallocate(coupler_flux) diff --git a/end-to-end-tests/instances_advection/main.F90 b/end-to-end-tests/instances_advection/main.F90 index 8a11cbdc..af74f8fb 100644 --- a/end-to-end-tests/instances_advection/main.F90 +++ b/end-to-end-tests/instances_advection/main.F90 @@ -234,6 +234,11 @@ program test_instances_advection !----------------------------------------------------------------- ! 10. Teardown. !----------------------------------------------------------------- + ! The constituent tables hold pointers into the per-suite dynamic + ! constituent buffers, which ccpp_final frees - tear down first. + do ins = 1, ninstances + call ccpp_deallocate_dynamic_constituents(instance=ins) + end do do ins = 1, ninstances call ccpp_final(suite_name=ccpp_suite, & instance=ins, ninstances=ninstances, & @@ -244,9 +249,6 @@ program test_instances_advection stop 1 end if end do - do ins = 1, ninstances - call ccpp_deallocate_dynamic_constituents(instance=ins) - end do deallocate(host_consts) write(6, '(a)') 'PASS: per-instance + constituents test' From 8f7263280df178c9d91dbd1167300d1a2bc38de4 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Tue, 3 Nov 2026 12:50:55 -0700 Subject: [PATCH 4/5] Fix advection and advection_auto_clone tests by moving code that probes ccpp-framework owned constituent properties beore tearing down the constituents --- end-to-end-tests/advection/test_host.F90 | 22 +++++++++---------- .../advection_auto_clone/test_host.F90 | 22 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/end-to-end-tests/advection/test_host.F90 b/end-to-end-tests/advection/test_host.F90 index fc42235d..67399bbe 100644 --- a/end-to-end-tests/advection/test_host.F90 +++ b/end-to-end-tests/advection/test_host.F90 @@ -1131,6 +1131,17 @@ subroutine test_host(retval, test_suites) end if end do + if (errcode == 0) then + ! Run finished without error, check answers. phys_state%q points into the + ! constituent array, so this has to happen before the teardown below. + if (compare_data(num_advected)) then + write(6, *) 'Answers are correct!' + else + write(6, *) 'Answers are not correct!' + errcode_final = -1 + end if + end if + ! The constituent tables hold pointers into the per-suite dynamic ! constituent buffers, which ccpp_final frees - tear down first. call ccpp_deallocate_dynamic_constituents() @@ -1151,17 +1162,6 @@ subroutine test_host(retval, test_suites) deallocate(host_constituents) - if (errcode == 0) then - ! Run finished without error, check answers - if (compare_data(num_advected)) then - write(6, *) 'Answers are correct!' - errcode = 0 - else - write(6, *) 'Answers are not correct!' - errcode = -1 - end if - end if - ! Make sure "final" flag is non-zero if "errcode" is: if (errcode /= 0) then errcode_final = -1 ! Notify test script that a failure occured diff --git a/end-to-end-tests/advection_auto_clone/test_host.F90 b/end-to-end-tests/advection_auto_clone/test_host.F90 index c9411b11..dd9549d4 100644 --- a/end-to-end-tests/advection_auto_clone/test_host.F90 +++ b/end-to-end-tests/advection_auto_clone/test_host.F90 @@ -1119,6 +1119,17 @@ subroutine test_host(retval, test_suites) end if end do + if (errcode == 0) then + ! Run finished without error, check answers. phys_state%q points into the + ! constituent array, so this has to happen before the teardown below. + if (compare_data(num_advected)) then + write(6, *) 'Answers are correct!' + else + write(6, *) 'Answers are not correct!' + errcode_final = -1 + end if + end if + ! The constituent tables hold pointers into the per-suite dynamic ! constituent buffers, which ccpp_final frees - tear down first. call ccpp_deallocate_dynamic_constituents() @@ -1139,17 +1150,6 @@ subroutine test_host(retval, test_suites) deallocate(host_constituents) - if (errcode == 0) then - ! Run finished without error, check answers - if (compare_data(num_advected)) then - write(6, *) 'Answers are correct!' - errcode = 0 - else - write(6, *) 'Answers are not correct!' - errcode = -1 - end if - end if - ! Make sure "final" flag is non-zero if "errcode" is: if (errcode /= 0) then errcode_final = -1 ! Notify test script that a failure occured From 8b43f7b45c61723faae64fa42ee14f0961a7f244 Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Tue, 3 Nov 2026 12:51:16 -0700 Subject: [PATCH 5/5] Bug fix for CI: use the correct GCC compiler, not the default gcc@11 --- .github/workflows/end-to-end-tests.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index d1092fa1..9fd733d9 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -40,7 +40,8 @@ jobs: which pytest - name: Run end-to-end tests run: | - cmake --fresh -S./end-to-end-tests -B./build + cmake --fresh -S./end-to-end-tests -B./build \ + -DCMAKE_Fortran_COMPILER=${{matrix.fortran-compiler}} cd build make ctest --rerun-failed --output-on-failure . @@ -74,6 +75,7 @@ jobs: ASAN_OPTIONS: "detect_leaks=0" run: | cmake --fresh -S./end-to-end-tests -B./build \ + -DCMAKE_Fortran_COMPILER=gfortran-12 \ -DCMAKE_Fortran_FLAGS="-fsanitize=address -fno-omit-frame-pointer" \ -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address" cd build