diff --git a/.github/workflows/build-spack.yml b/.github/workflows/build-spack.yml index ac2ae2d80b..c10e7d5e31 100644 --- a/.github/workflows/build-spack.yml +++ b/.github/workflows/build-spack.yml @@ -133,17 +133,33 @@ jobs: continue-on-error: ${{matrix.special == 'clang-tidy'}} run: | ninja -v -k0 + - name: Regenerate ROOT test data + if: ${{matrix.geant == '11.0'}} + working-directory: build + run: | + ninja -v -k0 update-root-test-data - name: Run tests + id: test working-directory: build continue-on-error: ${{fromJSON(matrix.geant) < 11}} # TODO: fix failing tests run: | if [ "${{matrix.geant}}" == "11.0" ]; then - # TODO: add 11.0.4 and clhep version to tests - #export CELER_TEST_STRICT=1 - echo "warning: strict testing is disabled" + # Note this is ignored for geant4, float, clhep + export CELER_TEST_STRICT=1 fi ctest --parallel $(nproc) --timeout 15 --output-on-failure \ --test-output-size-passed=32768 --test-output-size-failed=1048576 + - name: Upload failed tests + if: ${{steps.test.outcome == 'failure'}} + uses: actions/upload-artifact@v4 + with: + name: failed-${{github.job}}-${{env.CMAKE_PRESET}}-${{matrix.geant}} + if-no-files-found: warn + retention-days: 3 + path: | + build/**/*.out.json + build/Testing/Temporary/LastTest.log + build/Testing/Temporary/LastTestsFailed.log - name: Check using build directory as install run: | . ${SPACK_VIEW}/rc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 34de11de1f..c1bf32222a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -69,9 +69,9 @@ function(celeritas_add_device_test base) endfunction() if(CELERITAS_USE_Geant4) - # Optional dependence on low-energy EM data + # Optional dependence on low-energy EM data and neutron data set(CELERITASTEST_G4ENV) - foreach(_ds G4EMLOW G4ENSDFSTATE) + foreach(_ds G4EMLOW G4ENSDFSTATE G4PARTICLEXS) list(APPEND CELERITASTEST_G4ENV "${Geant4_DATASET_${_ds}_ENVVAR}=${Geant4_DATASET_${_ds}_PATH}" ) diff --git a/test/celeritas/CMakeLists.txt b/test/celeritas/CMakeLists.txt index 331f4838ff..fa36c4d391 100644 --- a/test/celeritas/CMakeLists.txt +++ b/test/celeritas/CMakeLists.txt @@ -377,29 +377,34 @@ celeritas_add_test(user/StepCollector.test.cc # DATA UPDATE #-----------------------------------------------------------------------------# -function(celeritas_add_rootupdate_target target filename) - set(_gdml "${PROJECT_SOURCE_DIR}/test/geocel/data/${filename}.gdml") - set(_basename "${CMAKE_CURRENT_SOURCE_DIR}/data/${filename}") - if(CELERITAS_USE_Geant4) - set(_cmake_env - "${CMAKE_COMMAND}" "-E" "env" "${CELERITASTEST_G4ENV}" +set(_root_data) +if(CELERITAS_USE_Geant4 AND CELERITAS_USE_ROOT) + foreach(_filename "four-steel-slabs" "simple-cms") + set(_gdml "${PROJECT_SOURCE_DIR}/test/geocel/data/${_filename}.gdml") + set(_basename "${CMAKE_CURRENT_SOURCE_DIR}/data/${_filename}") + set(_output "${_basename}.root") + add_custom_command( + OUTPUT "${_output}" + DEPENDS + celer-export-geant + "${_gdml}" + "${_basename}.geant.json" + "${PROJECT_SOURCE_DIR}/src/celeritas/ext/RootInterfaceLinkDef.h" + COMMAND + "${CMAKE_COMMAND}" "-E" "env" ${CELERITASTEST_G4ENV} + "$" + "${_gdml}" + "${_basename}.geant.json" + "${_output}" + VERBATIM ) - else() - set(_cmake_env) - endif() - add_custom_target(${target} - COMMAND - ${_cmake_env} - "$" - "${_gdml}" - "${_basename}.geant.json" - "${_basename}.root" - VERBATIM - ) - add_dependencies(${target} celer-export-geant) -endfunction() + list(APPEND _root_data "${_output}") + endforeach() +endif() -celeritas_add_rootupdate_target(update-four-slabs four-steel-slabs) -celeritas_add_rootupdate_target(update-simple-cms simple-cms) +add_custom_target(update-root-test-data + COMMENT "Regenerate ROOT test data" + DEPENDS ${_root_data} +) #-----------------------------------------------------------------------------# diff --git a/test/celeritas/GeantTestBase.cc b/test/celeritas/GeantTestBase.cc index 3167351157..5bef4bc308 100644 --- a/test/celeritas/GeantTestBase.cc +++ b/test/celeritas/GeantTestBase.cc @@ -64,7 +64,7 @@ class GeantTestBase::CleanupGeantEnvironment : public ::testing::Environment }; //---------------------------------------------------------------------------// -//! Whether Geant4 dependencies match those on the CI build +//! Whether results should be equivalent to the CI build bool GeantTestBase::is_ci_build() { return CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_DOUBLE @@ -72,7 +72,8 @@ bool GeantTestBase::is_ci_build() && CELERITAS_UNITS == CELERITAS_UNITS_CGS && cstring_equal(celeritas_core_rng, "xorwow") && (cstring_equal(celeritas_clhep_version, "2.4.6.0") - || cstring_equal(celeritas_clhep_version, "2.4.6.4")) + || cstring_equal(celeritas_clhep_version, "2.4.6.4") + || cstring_equal(celeritas_clhep_version, "2.4.7.1")) && (cstring_equal(celeritas_geant4_version, "11.0.3") || cstring_equal(celeritas_geant4_version, "11.0.4")); } diff --git a/test/celeritas/GlobalTestBase.cc b/test/celeritas/GlobalTestBase.cc index f7b398be68..d0ad6d7af0 100644 --- a/test/celeritas/GlobalTestBase.cc +++ b/test/celeritas/GlobalTestBase.cc @@ -46,20 +46,9 @@ GlobalTestBase::~GlobalTestBase() { try { - std::string destination = "screen"; - std::ostream* os = &std::cout; - std::ofstream ofile; - if (celeritas::use_color()) - { - destination = this->make_unique_filename(".json"); - ofile.open(destination, - std::ios_base::out | std::ios_base::trunc); - os = &ofile; - } - - std::cerr << "Writing diagnostic output to " << destination - << " because test failed\n"; - this->write_output(*os); + std::string destination = this->make_unique_filename(".out.json"); + std::cerr << "Writing diagnostic output because test failed\n"; + this->write_output(); } catch (std::exception const& e) { @@ -115,20 +104,18 @@ auto GlobalTestBase::build_core() -> SPConstCore //---------------------------------------------------------------------------// void GlobalTestBase::write_output() { - std::string filename = this->make_unique_filename(".json"); - std::ofstream of(filename); - this->write_output(of); - CELER_LOG(info) << "Wrote output to " << filename; -} - -//---------------------------------------------------------------------------// -void GlobalTestBase::write_output(std::ostream& os) const -{ - JsonPimpl json_wrap; - this->output_reg()->output(&json_wrap); + std::string filename = this->make_unique_filename(".out.json"); + std::ofstream ofs(filename); + CELER_VALIDATE(ofs, << "failed to open output file at " << filename); // Print with pretty indentation - os << json_wrap.obj.dump(1) << '\n'; + { + JsonPimpl json_wrap; + this->output_reg()->output(&json_wrap); + ofs << json_wrap.obj.dump(1) << '\n'; + } + + CELER_LOG(info) << "Wrote output to " << filename; } //---------------------------------------------------------------------------// diff --git a/test/celeritas/GlobalTestBase.hh b/test/celeritas/GlobalTestBase.hh index 64d5223b37..f335e3033a 100644 --- a/test/celeritas/GlobalTestBase.hh +++ b/test/celeritas/GlobalTestBase.hh @@ -134,8 +134,6 @@ class GlobalTestBase : public Test SPOutputRegistry const& output_reg() const { return output_reg_; } //! Write output to a debug text file void write_output(); - //! Write output to a stream - void write_output(std::ostream& os) const; protected: [[nodiscard]] virtual SPConstGeo build_geometry() = 0; diff --git a/test/celeritas/data/four-steel-slabs.geant.json b/test/celeritas/data/four-steel-slabs.geant.json index 5ec95b50d6..f232ac9360 100644 --- a/test/celeritas/data/four-steel-slabs.geant.json +++ b/test/celeritas/data/four-steel-slabs.geant.json @@ -13,14 +13,14 @@ "apply_cuts": false, "lpm": true, "max_energy": [ - 1000000.0, + 100000000.0, "MeV" ], "min_energy": [ 0.0001, "MeV" ], -"msc": "urban", +"msc": "urban_wentzelvi", "rayleigh_scattering": true } diff --git a/test/celeritas/phys/ProcessBuilder.test.cc b/test/celeritas/phys/ProcessBuilder.test.cc index c24439b40d..d4b62735a7 100644 --- a/test/celeritas/phys/ProcessBuilder.test.cc +++ b/test/celeritas/phys/ProcessBuilder.test.cc @@ -71,16 +71,26 @@ class ProcessBuilderTest : public Test CELER_ENSURE(particle() && material()); } + static bool has_env(std::string const& var) + { + bool result = !celeritas::getenv(var).empty(); + if (!result && strict_testing()) + { + ADD_FAILURE() << "CI testing requires '" << var + << "' to be defined"; + } + return result; + } + static bool has_le_data() { - static bool const result = !celeritas::getenv("G4LEDATA").empty(); + static bool const result = has_env("G4LEDATA"); return result; } static bool has_neutron_data() { - static bool const result - = !celeritas::getenv("G4PARTICLEXSDATA").empty(); + static bool const result = has_env("G4PARTICLEXSDATA"); return result; } }; @@ -558,7 +568,7 @@ TEST_F(ProcessBuilderTest, neutron_elastic) } } } - + //---------------------------------------------------------------------------// } // namespace test } // namespace celeritas diff --git a/test/celeritas/user/Diagnostic.test.cc b/test/celeritas/user/Diagnostic.test.cc index f62a70faca..9d76c6590f 100644 --- a/test/celeritas/user/Diagnostic.test.cc +++ b/test/celeritas/user/Diagnostic.test.cc @@ -5,6 +5,7 @@ //---------------------------------------------------------------------------// //! \file celeritas/user/Diagnostic.test.cc //---------------------------------------------------------------------------// +#include "celeritas_cmake_strings.h" #include "corecel/cont/Span.hh" #include "corecel/io/StringUtils.hh" #include "geocel/UnitUtils.hh" @@ -170,40 +171,46 @@ TEST_F(TestEm3DiagnosticTest, host) "scat-klein-nishina gamma"}; EXPECT_VEC_EQ(expected_nonzero_action_keys, result.nonzero_action_keys); - if (this->is_ci_build() && CELERITAS_CORE_GEO == CELERITAS_CORE_GEO_VECGEOM) + if (this->is_ci_build() + && std::string(celeritas_geant4_version) == "11.0.4") { static size_type const expected_nonzero_action_counts[] = { - 121u, - 389u, - 480u, - 16u, - 57u, - 1024u, - 276u, - 290u, - 1798u, + 119u, + 398u, + 462u, + 14u, + 59u, + 1002u, + 277u, + 294u, + 1713u, 15u, 19u, - 1171u, - 1541u, - 572u, - 86u, - 26u, - 311u, + 1204u, + 1645u, + 567u, + 81u, + 24u, + 299u, }; - EXPECT_VEC_EQ(expected_nonzero_action_counts, result.nonzero_action_counts); static size_type const expected_steps[] - = {0u, 308u, 214u, 97u, 42u, 32u, 26u, 17u, 5u, 8u, 8u, - 5u, 2u, 5u, 2u, 0u, 1u, 1u, 1u, 0u, 0u, 1u, - 0u, 756u, 42u, 12u, 10u, 9u, 8u, 5u, 10u, 5u, 3u, - 7u, 10u, 10u, 11u, 13u, 4u, 4u, 4u, 3u, 3u, 23u, - 0u, 2u, 2u, 1u, 2u, 4u, 5u, 7u, 4u, 6u, 7u, - 7u, 7u, 13u, 8u, 6u, 3u, 2u, 5u, 6u, 2u, 24u}; + = {0u, 312u, 213u, 78u, 45u, 33u, 20u, 16u, 7u, 9u, 8u, + 2u, 7u, 5u, 1u, 1u, 0u, 0u, 0u, 0u, 0u, 2u, + 0u, 736u, 51u, 10u, 6u, 10u, 5u, 9u, 9u, 3u, 3u, + 7u, 12u, 6u, 11u, 15u, 3u, 5u, 5u, 4u, 3u, 22u, + 0u, 2u, 2u, 1u, 0u, 4u, 5u, 8u, 5u, 6u, 6u, + 9u, 6u, 12u, 9u, 5u, 3u, 2u, 5u, 6u, 2u, 23u}; EXPECT_VEC_EQ(expected_steps, result.steps); } + else + { + cout << "No output saved for combination of " + << test::PrintableBuildConf{} << std::endl; + result.print_expected(); + } } TEST_F(TestEm3DiagnosticTest, TEST_IF_CELER_DEVICE(device))