diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index d789aaa0..9fd733d9 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -40,23 +40,44 @@ 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 . -# - 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" + 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 + make + ctest --rerun-failed --output-on-failure . diff --git a/end-to-end-tests/advection/test_host.F90 b/end-to-end-tests/advection/test_host.F90 index dfbd3c54..67399bbe 100644 --- a/end-to-end-tests/advection/test_host.F90 +++ b/end-to-end-tests/advection/test_host.F90 @@ -1131,6 +1131,21 @@ 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() + do sind = 1, num_suites if (errcode == 0) then call ccpp_final(suite_name=test_suites(sind)%suite_name, & @@ -1145,20 +1160,8 @@ subroutine test_host(retval, test_suites) end if end do - call ccpp_deallocate_dynamic_constituents() 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 7845ca79..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,21 @@ 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() + do sind = 1, num_suites if (errcode == 0) then call ccpp_final(suite_name=test_suites(sind)%suite_name, & @@ -1133,20 +1148,8 @@ subroutine test_host(retval, test_suites) end if end do - call ccpp_deallocate_dynamic_constituents() 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/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 2a1e1c84..af74f8fb 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) @@ -235,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, & @@ -245,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'