From 0cd5ae5f2e3b26e2d2d5d295c8b97e7ad7e31127 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 15 Apr 2023 17:49:08 -0400 Subject: [PATCH 1/7] remove -DLAMMPS_EXCEPTIONS and always enable the corresponding code paths --- cmake/CMakeLists.txt | 5 -- cmake/Modules/LAMMPSInterfacePlugin.cmake | 4 +- cmake/Modules/Tools.cmake | 3 -- doc/src/Build_settings.rst | 26 +++-------- doc/src/Fortran.rst | 20 +++----- doc/src/Howto_cmake.rst | 8 ++-- doc/src/Howto_pylammps.rst | 26 +++++------ doc/src/Python_error.rst | 18 ++++---- src/error.cpp | 54 ++-------------------- src/error.h | 6 --- src/info.cpp | 5 -- src/lammps.cpp | 1 - src/library.cpp | 52 ++++----------------- src/main.cpp | 18 +------- unittest/c-library/CMakeLists.txt | 7 --- unittest/c-library/test_library_config.cpp | 2 +- unittest/python/CMakeLists.txt | 11 ++--- 17 files changed, 58 insertions(+), 208 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index a71347c2c4..1c05e32d0c 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -384,11 +384,6 @@ if(NOT ${LAMMPS_MEMALIGN} STREQUAL "0") target_compile_definitions(lammps PRIVATE -DLAMMPS_MEMALIGN=${LAMMPS_MEMALIGN}) endif() -option(LAMMPS_EXCEPTIONS "enable the use of C++ exceptions for error messages (useful for library interface)" ${ENABLE_TESTING}) -if(LAMMPS_EXCEPTIONS) - target_compile_definitions(lammps PUBLIC -DLAMMPS_EXCEPTIONS) -endif() - # "hard" dependencies between packages resulting # in an error instead of skipping over files pkg_depends(ML-IAP ML-SNAP) diff --git a/cmake/Modules/LAMMPSInterfacePlugin.cmake b/cmake/Modules/LAMMPSInterfacePlugin.cmake index c1cc613496..024dc571b3 100644 --- a/cmake/Modules/LAMMPSInterfacePlugin.cmake +++ b/cmake/Modules/LAMMPSInterfacePlugin.cmake @@ -28,9 +28,7 @@ if(MSVC) add_compile_options(/Zc:__cplusplus) add_compile_options(/wd4244) add_compile_options(/wd4267) - if(LAMMPS_EXCEPTIONS) - add_compile_options(/EHsc) - endif() + add_compile_options(/EHsc) endif() add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() diff --git a/cmake/Modules/Tools.cmake b/cmake/Modules/Tools.cmake index c4c33cc40c..bc3372f2ae 100644 --- a/cmake/Modules/Tools.cmake +++ b/cmake/Modules/Tools.cmake @@ -38,9 +38,6 @@ endif() if(BUILD_LAMMPS_SHELL) find_package(PkgConfig REQUIRED) pkg_check_modules(READLINE IMPORTED_TARGET REQUIRED readline) - if(NOT LAMMPS_EXCEPTIONS) - message(WARNING "The LAMMPS shell needs LAMMPS_EXCEPTIONS enabled for full functionality") - endif() # include resource compiler to embed icons into the executable on Windows if(CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/doc/src/Build_settings.rst b/doc/src/Build_settings.rst index c2e7b94b0e..7576cae3eb 100644 --- a/doc/src/Build_settings.rst +++ b/doc/src/Build_settings.rst @@ -459,27 +459,13 @@ those systems: .. _exceptions: Exception handling when using LAMMPS as a library ------------------------------------------------------------------- +------------------------------------------------- -This setting is useful when external codes drive LAMMPS as a library. -With this option enabled, LAMMPS errors do not kill the calling code. -Instead, the call stack is unwound and control returns to the caller, -e.g. to Python. Of course, the calling code has to be set up to -*catch* exceptions thrown from within LAMMPS. - -.. tabs:: - - .. tab:: CMake build - - .. code-block:: bash - - -D LAMMPS_EXCEPTIONS=value # yes or no (default) - - .. tab:: Traditional make - - .. code-block:: make - - LMP_INC = -DLAMMPS_EXCEPTIONS +LAMMPS errors do not kill the calling code, but throw an exception. In +the C-library interface, the call stack is unwound and control returns +to the caller, e.g. to Python or a code that is coupled to LAMMPS and +the error status can be queried. When using C++ directly, the calling +code has to be set up to *catch* exceptions thrown from within LAMMPS. .. note:: diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index 92a42997b8..42840c62ee 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -2172,19 +2172,13 @@ Procedures Bound to the :f:type:`lammps` Derived Type .. versionadded:: 3Nov2022 - In case of an error, LAMMPS will either abort or throw a C++ exception. - The latter has to be :ref:`enabled at compile time `. - This function checks if exceptions were enabled. - - When using the library interface with C++ exceptions enabled, the library - interface functions will "catch" them, and the error status can then be - checked by calling :f:func:`has_error`. The most recent error message can be - retrieved via :f:func:`get_last_error_message`. - This can allow one to restart a calculation or delete and recreate - the LAMMPS instance when a C++ exception occurs. One application - of using exceptions this way is the :ref:`lammps_shell`. If C++ - exceptions are disabled and an error happens during a call to - LAMMPS or the Fortran API, the application will terminate. + When using the library interface, the library interface functions + will "catch" exceptions, and then the error status can be checked by + calling :f:func:`has_error`. The most recent error message can be + retrieved via :f:func:`get_last_error_message`. This allows to + restart a calculation or delete and recreate the LAMMPS instance when + a C++ exception occurs. One application of using exceptions this way + is the :ref:`lammps_shell`. :to: :cpp:func:`lammps_config_has_exceptions` :r has_exceptions: diff --git a/doc/src/Howto_cmake.rst b/doc/src/Howto_cmake.rst index c997aa52bf..627f9e458c 100644 --- a/doc/src/Howto_cmake.rst +++ b/doc/src/Howto_cmake.rst @@ -338,8 +338,6 @@ Some common LAMMPS specific variables - common compiler flags, for optimization or instrumentation (default:) * - ``LAMMPS_MACHINE`` - when set to ``name`` the LAMMPS executable and library will be called ``lmp_name`` and ``liblammps_name.a`` - * - ``LAMMPS_EXCEPTIONS`` - - when set to ``on`` errors will throw a C++ exception instead of aborting (default: ``off``) * - ``FFT`` - select which FFT library to use: ``FFTW3``, ``MKL``, ``KISS`` (default, unless FFTW3 is found) * - ``FFT_SINGLE`` @@ -412,9 +410,9 @@ interface (``ccmake`` or ``cmake-gui``). Using a preset to select a compiler package (``clang.cmake``, ``gcc.cmake``, ``intel.cmake``, ``oneapi.cmake``, or ``pgi.cmake``) - are an exception to the mechanism of updating the configuration incrementally, - as they will trigger a reset of cached internal CMake settings and thus - reset settings to their default values. + are an exception to the mechanism of updating the configuration + incrementally, as they will trigger a reset of cached internal CMake + settings and thus reset settings to their default values. Compilation and build targets ----------------------------- diff --git a/doc/src/Howto_pylammps.rst b/doc/src/Howto_pylammps.rst index 9a9fef5efc..2db61cd5bb 100644 --- a/doc/src/Howto_pylammps.rst +++ b/doc/src/Howto_pylammps.rst @@ -53,10 +53,10 @@ System-wide Installation Step 1: Building LAMMPS as a shared library """"""""""""""""""""""""""""""""""""""""""" -To use LAMMPS inside of Python it has to be compiled as shared library. This -library is then loaded by the Python interface. In this example we enable the -MOLECULE package and compile LAMMPS with C++ exceptions, PNG, JPEG and FFMPEG -output support enabled. +To use LAMMPS inside of Python it has to be compiled as shared +library. This library is then loaded by the Python interface. In this +example we enable the MOLECULE package and compile LAMMPS with PNG, JPEG +and FFMPEG output support enabled. Step 1a: For the CMake based build system, the steps are: @@ -66,7 +66,7 @@ Step 1a: For the CMake based build system, the steps are: cd $LAMMPS_DIR/build-shared # MPI, PNG, Jpeg, FFMPEG are auto-detected - cmake ../cmake -DPKG_MOLECULE=yes -DLAMMPS_EXCEPTIONS=yes -DBUILD_LIB=yes -DBUILD_SHARED_LIBS=yes + cmake ../cmake -DPKG_MOLECULE=yes -DBUILD_LIB=yes -DBUILD_SHARED_LIBS=yes make Step 1b: For the legacy, make based build system, the steps are: @@ -79,7 +79,7 @@ Step 1b: For the legacy, make based build system, the steps are: make yes-MOLECULE # compile shared library using Makefile - make mpi mode=shlib LMP_INC="-DLAMMPS_PNG -DLAMMPS_JPEG -DLAMMPS_FFMPEG -DLAMMPS_EXCEPTIONS" JPG_LIB="-lpng -ljpeg" + make mpi mode=shlib LMP_INC="-DLAMMPS_PNG -DLAMMPS_JPEG -DLAMMPS_FFMPEG" JPG_LIB="-lpng -ljpeg" Step 2: Installing the LAMMPS Python package """""""""""""""""""""""""""""""""""""""""""" @@ -356,18 +356,16 @@ Together with matplotlib plotting data out of LAMMPS becomes simple: Error handling with PyLammps ---------------------------- -Compiling the shared library with C++ exception support provides a better error -handling experience. Without exceptions the LAMMPS code will terminate the -current Python process with an error message. C++ exceptions allow capturing -them on the C++ side and rethrowing them on the Python side. This way you -can handle LAMMPS errors through the Python exception handling mechanism. +Using C++ exceptions in LAMMPS for errors allows capturing them on the +C++ side and rethrowing them on the Python side. This way you can handle +LAMMPS errors through the Python exception handling mechanism. .. warning:: Capturing a LAMMPS exception in Python can still mean that the - current LAMMPS process is in an illegal state and must be terminated. It is - advised to save your data and terminate the Python instance as quickly as - possible. + current LAMMPS process is in an illegal state and must be + terminated. It is advised to save your data and terminate the Python + instance as quickly as possible. Using PyLammps in IPython notebooks and Jupyter ----------------------------------------------- diff --git a/doc/src/Python_error.rst b/doc/src/Python_error.rst index 5dbd940723..f6a94c0e82 100644 --- a/doc/src/Python_error.rst +++ b/doc/src/Python_error.rst @@ -1,11 +1,11 @@ Handling LAMMPS errors -******************************* +********************** -Compiling the shared library with :ref:`C++ exception support ` provides a better error -handling experience. Without exceptions the LAMMPS code will terminate the -current Python process with an error message. C++ exceptions allow capturing -them on the C++ side and rethrowing them on the Python side. This way -LAMMPS errors can be handled through the Python exception handling mechanism. +The shared library is compiled with :ref:`C++ exception support +` to provide a better error handling experience. C++ +exceptions allow capturing errors on the C++ side and rethrowing them on +the Python side. This way LAMMPS errors can be handled through the +Python exception handling mechanism. .. code-block:: python @@ -31,6 +31,6 @@ LAMMPS errors can be handled through the Python exception handling mechanism. .. warning:: Capturing a LAMMPS exception in Python can still mean that the - current LAMMPS process is in an illegal state and must be terminated. It is - advised to save your data and terminate the Python instance as quickly as - possible. + current LAMMPS process is in an illegal state and must be + terminated. It is advised to save your data and terminate the Python + instance as quickly as possible when running in parallel with MPI. diff --git a/src/error.cpp b/src/error.cpp index 53b14e1fcc..9f0a27ff5c 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -18,10 +18,7 @@ #include "input.h" #include "output.h" #include "universe.h" - -#if defined(LAMMPS_EXCEPTIONS) #include "update.h" -#endif using namespace LAMMPS_NS; @@ -40,10 +37,8 @@ static std::string truncpath(const std::string &path) Error::Error(LAMMPS *lmp) : Pointers(lmp), numwarn(0), maxwarn(100), allwarn(0) { -#ifdef LAMMPS_EXCEPTIONS last_error_message.clear(); last_error_type = ERROR_NONE; -#endif } /* ---------------------------------------------------------------------- @@ -73,19 +68,11 @@ void Error::universe_all(const std::string &file, int line, const std::string &s } if (universe->ulogfile) fclose(universe->ulogfile); -#ifdef LAMMPS_EXCEPTIONS - // allow commands if an exception was caught in a run // update may be a null pointer when catching command line errors if (update) update->whichflag = 0; - throw LAMMPSException(mesg); -#else - KokkosLMP::finalize(); - MPI_Finalize(); - exit(1); -#endif } /* ---------------------------------------------------------------------- @@ -99,19 +86,11 @@ void Error::universe_one(const std::string &file, int line, const std::string &s universe->me,str,truncpath(file),line); if (universe->uscreen) fputs(mesg.c_str(),universe->uscreen); -#ifdef LAMMPS_EXCEPTIONS - // allow commands if an exception was caught in a run // update may be a null pointer when catching command line errors if (update) update->whichflag = 0; - throw LAMMPSAbortException(mesg, universe->uworld); -#else - KokkosLMP::finalize(); - MPI_Abort(universe->uworld,1); - exit(1); // to trick "smart" compilers into believing this does not return -#endif } /* ---------------------------------------------------------------------- @@ -155,31 +134,17 @@ void Error::all(const std::string &file, int line, const std::string &str) utils::logmesg(lmp,mesg); } -#ifdef LAMMPS_EXCEPTIONS - // allow commands if an exception was caught in a run // update may be a null pointer when catching command line errors if (update) update->whichflag = 0; - std::string msg = fmt::format("ERROR: {} ({}:{})\n", - str, truncpath(file), line); + std::string msg = fmt::format("ERROR: {} ({}:{})\n", str, truncpath(file), line); - if (universe->nworlds > 1) { + if (universe->nworlds > 1) throw LAMMPSAbortException(msg, universe->uworld); - } - - throw LAMMPSException(msg); -#else - if (output) delete output; - if (screen && screen != stdout) fclose(screen); - if (logfile) fclose(logfile); - - KokkosLMP::finalize(); - if (universe->nworlds > 1) MPI_Abort(universe->uworld,1); - MPI_Finalize(); - exit(1); -#endif + else + throw LAMMPSException(msg); } /* ---------------------------------------------------------------------- @@ -204,20 +169,11 @@ void Error::one(const std::string &file, int line, const std::string &str) if (universe->uscreen) fputs(mesg.c_str(),universe->uscreen); -#ifdef LAMMPS_EXCEPTIONS - // allow commands if an exception was caught in a run // update may be a null pointer when catching command line errors if (update) update->whichflag = 0; - throw LAMMPSAbortException(mesg, world); -#else - utils::flush_buffers(lmp); - KokkosLMP::finalize(); - MPI_Abort(world,1); - exit(1); // to trick "smart" compilers into believing this does not return -#endif } /* ---------------------------------------------------------------------- @@ -322,7 +278,6 @@ void Error::done(int status) exit(status); } -#ifdef LAMMPS_EXCEPTIONS /* ---------------------------------------------------------------------- return the last error message reported by LAMMPS (only used if compiled with -DLAMMPS_EXCEPTIONS) @@ -353,4 +308,3 @@ void Error::set_last_error(const std::string &msg, ErrorType type) last_error_message = msg; last_error_type = type; } -#endif diff --git a/src/error.h b/src/error.h index bb3d8705cb..4280b76a2a 100644 --- a/src/error.h +++ b/src/error.h @@ -15,10 +15,7 @@ #define LMP_ERROR_H #include "pointers.h" - -#ifdef LAMMPS_EXCEPTIONS #include "exceptions.h" -#endif namespace LAMMPS_NS { @@ -65,7 +62,6 @@ class Error : protected Pointers { void set_maxwarn(int val) { maxwarn = val; } void set_allwarn(int val) { allwarn = val; } -#ifdef LAMMPS_EXCEPTIONS std::string get_last_error() const; ErrorType get_last_error_type() const; void set_last_error(const std::string &msg, ErrorType type = ERROR_NORMAL); @@ -73,9 +69,7 @@ class Error : protected Pointers { private: std::string last_error_message; ErrorType last_error_type; -#endif - private: int numwarn, maxwarn, allwarn; // internal versions that accept explicit fmtlib arguments [[noreturn]] void _all(const std::string &, int, fmt::string_view, fmt::format_args args); diff --git a/src/info.cpp b/src/info.cpp index 4b9a761af5..d99cbbe562 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -298,7 +298,6 @@ void Info::command(int narg, char **arg) if (has_jpeg_support()) fputs("-DLAMMPS_JPEG\n",out); if (has_ffmpeg_support()) fputs("-DLAMMPS_FFMPEG\n",out); if (has_fft_single_support()) fputs("-DFFT_SINGLE\n",out); - if (has_exceptions()) fputs("-DLAMMPS_EXCEPTIONS\n",out); #if defined(LAMMPS_BIGBIG) fputs("-DLAMMPS_BIGBIG\n",out); @@ -1096,11 +1095,7 @@ bool Info::has_fft_single_support() { } bool Info::has_exceptions() { -#ifdef LAMMPS_EXCEPTIONS return true; -#else - return false; -#endif } bool Info::has_package(const std::string &package_name) { diff --git a/src/lammps.cpp b/src/lammps.cpp index 1c7d12f79c..4ce23f0ba2 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -1431,7 +1431,6 @@ void LAMMPS::print_config(FILE *fp) if (Info::has_jpeg_support()) fputs("-DLAMMPS_JPEG\n",fp); if (Info::has_ffmpeg_support()) fputs("-DLAMMPS_FFMPEG\n",fp); if (Info::has_fft_single_support()) fputs("-DFFT_SINGLE\n",fp); - if (Info::has_exceptions()) fputs("-DLAMMPS_EXCEPTIONS\n",fp); #if defined(LAMMPS_BIGBIG) fputs("-DLAMMPS_BIGBIG\n",fp); #elif defined(LAMMPS_SMALLBIG) diff --git a/src/library.cpp b/src/library.cpp index cc4e748f57..c30638a342 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -27,6 +27,7 @@ #include "domain.h" #include "dump.h" #include "error.h" +#include "exceptions.h" #include "fix.h" #include "fix_external.h" #include "force.h" @@ -53,10 +54,6 @@ #include -#if defined(LAMMPS_EXCEPTIONS) -#include "exceptions.h" -#endif - #if defined(LMP_PYTHON) #include #endif @@ -93,7 +90,6 @@ static void ptr_argument_warning() END_CAPTURE ------------------------------------------------------------------------- */ -#ifdef LAMMPS_EXCEPTIONS #define BEGIN_CAPTURE \ Error *error = lmp->error; \ try @@ -111,10 +107,6 @@ static void ptr_argument_warning() } catch(LAMMPSException &e) { \ error->set_last_error(e.message, ERROR_NORMAL); \ } -#else -#define BEGIN_CAPTURE -#define END_CAPTURE -#endif // ---------------------------------------------------------------------- // Library functions to create/destroy an instance of LAMMPS @@ -176,20 +168,19 @@ void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr) lammps_mpi_init(); if (ptr) ptr_argument_warning(); -#ifdef LAMMPS_EXCEPTIONS - try - { + try { lmp = new LAMMPS(argc, argv, comm); if (ptr) *ptr = (void *) lmp; - } - catch(LAMMPSException &e) { - fmt::print(stderr, "LAMMPS Exception: {}", e.message); + } catch(LAMMPSException &e) { + fprintf(stderr, "LAMMPS Exception: %s\n", e.message); + if (ptr) *ptr = nullptr; + } catch (fmt::format_error &fe) { + fprintf(stderr, "fmt::format_error: %s\n", fe.what()); + if (ptr) *ptr = nullptr; + } catch (std::exception &e) { + fprintf(stderr, "Exception: %s\n", e.what()); if (ptr) *ptr = nullptr; } -#else - lmp = new LAMMPS(argc, argv, comm); - if (ptr) *ptr = (void *) lmp; -#endif return (void *) lmp; } @@ -484,7 +475,6 @@ void lammps_error(void *handle, int error_type, const char *error_text) } END_CAPTURE -#if defined(LAMMPS_EXCEPTIONS) // with enabled exceptions the above code will simply throw an // exception and record the error message. So we have to explicitly // stop here like we do in main.cpp @@ -500,7 +490,6 @@ void lammps_error(void *handle, int error_type, const char *error_text) exit(1); } } -#endif } // ---------------------------------------------------------------------- @@ -2195,9 +2184,7 @@ void *lammps_extract_variable(void *handle, const char *name, const char *group) } } END_CAPTURE -#if defined(LAMMPS_EXCEPTIONS) return nullptr; -#endif } /* ---------------------------------------------------------------------- */ @@ -6335,26 +6322,15 @@ void lammps_force_timeout(void *handle) This function can be used to query if an error inside of LAMMPS has thrown a :ref:`C++ exception `. -.. note:: - - This function will always report "no error" when the LAMMPS library - has been compiled without ``-DLAMMPS_EXCEPTIONS``, which turns fatal - errors aborting LAMMPS into C++ exceptions. You can use the library - function :cpp:func:`lammps_config_has_exceptions` to check whether this is - the case. \endverbatim * * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. * \return 0 on no error, 1 on error. */ int lammps_has_error(void *handle) { -#ifdef LAMMPS_EXCEPTIONS LAMMPS *lmp = (LAMMPS *) handle; Error *error = lmp->error; return (error->get_last_error().empty()) ? 0 : 1; -#else - return 0; -#endif } /* ---------------------------------------------------------------------- */ @@ -6373,12 +6349,6 @@ a "2" indicates an abort that would happen only in a single MPI rank and thus may not be recoverable, as other MPI ranks may be waiting on the failing MPI ranks to send messages. -.. note:: - - This function will do nothing when the LAMMPS library has been - compiled without ``-DLAMMPS_EXCEPTIONS``, which turns errors aborting - LAMMPS into C++ exceptions. You can use the library function - :cpp:func:`lammps_config_has_exceptions` to check whether this is the case. \endverbatim * * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. @@ -6387,7 +6357,6 @@ the failing MPI ranks to send messages. * \return 1 when all ranks had the error, 2 on a single rank error. */ int lammps_get_last_error_message(void *handle, char *buffer, int buf_size) { -#ifdef LAMMPS_EXCEPTIONS LAMMPS *lmp = (LAMMPS *) handle; Error *error = lmp->error; buffer[0] = buffer[buf_size-1] = '\0'; @@ -6398,7 +6367,6 @@ int lammps_get_last_error_message(void *handle, char *buffer, int buf_size) { error->set_last_error("", ERROR_NONE); return error_type; } -#endif return 0; } diff --git a/src/main.cpp b/src/main.cpp index e3e304a0d4..3ebc710a24 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,13 +13,10 @@ #include "lammps.h" +#include "exceptions.h" #include "input.h" #include "library.h" -#if defined(LAMMPS_EXCEPTIONS) -#include "exceptions.h" -#endif - #include #include @@ -75,7 +72,6 @@ int main(int argc, char **argv) feenableexcept(FE_OVERFLOW); #endif -#ifdef LAMMPS_EXCEPTIONS try { auto lammps = new LAMMPS(argc, argv, lammps_comm); lammps->input->file(); @@ -99,18 +95,6 @@ int main(int argc, char **argv) MPI_Abort(MPI_COMM_WORLD, 1); exit(1); } -#else - try { - auto lammps = new LAMMPS(argc, argv, lammps_comm); - lammps->input->file(); - delete lammps; - } catch (fmt::format_error &fe) { - fprintf(stderr, "fmt::format_error: %s\n", fe.what()); - finalize(); - MPI_Abort(MPI_COMM_WORLD, 1); - exit(1); - } -#endif finalize(); MPI_Barrier(lammps_comm); MPI_Finalize(); diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 21b00b5c03..06bae7a2ef 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -46,13 +46,6 @@ else() endif() list(APPEND TEST_CONFIG_DEFS -DLAMMPS_HAS_MPI=${HAS_MPI}) -if(LAMMPS_EXCEPTIONS) - set(HAS_EXCEPTIONS 1) -else() - set(HAS_EXCEPTIONS 0) -endif() -list(APPEND TEST_CONFIG_DEFS -DLAMMPS_HAS_EXCEPTIONS=${HAS_EXCEPTIONS}) - foreach(WITH "JPEG" "PNG" "GZIP" "FFMPEG") if(WITH_${WITH}) set(HAS_${WITH} 1) diff --git a/unittest/c-library/test_library_config.cpp b/unittest/c-library/test_library_config.cpp index f402ffc2e9..78d6439c17 100644 --- a/unittest/c-library/test_library_config.cpp +++ b/unittest/c-library/test_library_config.cpp @@ -195,7 +195,7 @@ TEST_F(LibraryConfig, force_timeout) TEST(LAMMPSConfig, exceptions) { - EXPECT_EQ(lammps_config_has_exceptions(), LAMMPS_HAS_EXCEPTIONS); + EXPECT_EQ(lammps_config_has_exceptions(), 1); }; TEST(LAMMPSConfig, mpi_support) diff --git a/unittest/python/CMakeLists.txt b/unittest/python/CMakeLists.txt index fbd7ca0672..750716eb1a 100644 --- a/unittest/python/CMakeLists.txt +++ b/unittest/python/CMakeLists.txt @@ -86,13 +86,10 @@ if(Python_EXECUTABLE) WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) set_tests_properties(PythonOpen PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") - # some of the tests in this file will fail without exceptions enabled - if(LAMMPS_EXCEPTIONS) - add_test(NAME PythonCommands - COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-commands.py -v - WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) - set_tests_properties(PythonCommands PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") - endif() + add_test(NAME PythonCommands + COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-commands.py -v + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) + set_tests_properties(PythonCommands PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}") add_test(NAME PythonNumpy COMMAND ${PYTHON_TEST_RUNNER} ${CMAKE_CURRENT_SOURCE_DIR}/python-numpy.py -v From baeed854684cb4d0f14f3848bad6392a0d2d2c30 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 15 Apr 2023 18:03:09 -0400 Subject: [PATCH 2/7] update CMake files --- examples/COUPLE/plugin/CMakeLists.txt | 4 +--- examples/COUPLE/simple/CMakeLists.txt | 4 +--- examples/plugins/CMakeLists.txt | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/COUPLE/plugin/CMakeLists.txt b/examples/COUPLE/plugin/CMakeLists.txt index f4064d3f65..14bef44ffa 100644 --- a/examples/COUPLE/plugin/CMakeLists.txt +++ b/examples/COUPLE/plugin/CMakeLists.txt @@ -23,9 +23,7 @@ endif() # and prints lots of pointless warnings about "unsafe" functions if(MSVC) if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") - if(LAMMPS_EXCEPTIONS) - add_compile_options(/EHsc) - endif() + add_compile_options(/EHsc) endif() add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() diff --git a/examples/COUPLE/simple/CMakeLists.txt b/examples/COUPLE/simple/CMakeLists.txt index 14c253e5a1..eed9a147bd 100644 --- a/examples/COUPLE/simple/CMakeLists.txt +++ b/examples/COUPLE/simple/CMakeLists.txt @@ -18,9 +18,7 @@ endif() # and prints lots of pointless warnings about "unsafe" functions if(MSVC) if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") - if(LAMMPS_EXCEPTIONS) - add_compile_options(/EHsc) - endif() + add_compile_options(/EHsc) endif() add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt index 688835de56..ef494fe941 100644 --- a/examples/plugins/CMakeLists.txt +++ b/examples/plugins/CMakeLists.txt @@ -36,9 +36,7 @@ else() add_compile_options(/Zc:__cplusplus) add_compile_options(/wd4244) add_compile_options(/wd4267) - if(LAMMPS_EXCEPTIONS) - add_compile_options(/EHsc) - endif() + add_compile_options(/EHsc) endif() add_compile_definitions(_CRT_SECURE_NO_WARNINGS) endif() From 8086228976bcdd798ca3e7cc1a83bd578dce766d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 15 Apr 2023 21:54:13 -0400 Subject: [PATCH 3/7] make communicator protected and use accessor instead. simplify --- src/error.cpp | 9 +++------ src/error.h | 2 +- src/exceptions.h | 12 +++++++----- src/library.cpp | 10 +++++----- src/main.cpp | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/error.cpp b/src/error.cpp index 9f0a27ff5c..4aaa93aa31 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -279,8 +279,7 @@ void Error::done(int status) } /* ---------------------------------------------------------------------- - return the last error message reported by LAMMPS (only used if - compiled with -DLAMMPS_EXCEPTIONS) + return the last error message reported by LAMMPS ------------------------------------------------------------------------- */ std::string Error::get_last_error() const @@ -289,8 +288,7 @@ std::string Error::get_last_error() const } /* ---------------------------------------------------------------------- - return the type of the last error reported by LAMMPS (only used if - compiled with -DLAMMPS_EXCEPTIONS) + return the type of the last error reported by LAMMPS ------------------------------------------------------------------------- */ ErrorType Error::get_last_error_type() const @@ -300,10 +298,9 @@ ErrorType Error::get_last_error_type() const /* ---------------------------------------------------------------------- set the last error message and error type - (only used if compiled with -DLAMMPS_EXCEPTIONS) ------------------------------------------------------------------------- */ -void Error::set_last_error(const std::string &msg, ErrorType type) +void Error::set_last_error(const char *msg, ErrorType type) { last_error_message = msg; last_error_type = type; diff --git a/src/error.h b/src/error.h index 4280b76a2a..95a58c81e3 100644 --- a/src/error.h +++ b/src/error.h @@ -64,7 +64,7 @@ class Error : protected Pointers { std::string get_last_error() const; ErrorType get_last_error_type() const; - void set_last_error(const std::string &msg, ErrorType type = ERROR_NORMAL); + void set_last_error(const char *msg, ErrorType type = ERROR_NORMAL); private: std::string last_error_message; diff --git a/src/exceptions.h b/src/exceptions.h index 5c4aa99971..7d9aabfda0 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -22,21 +22,23 @@ namespace LAMMPS_NS { class LAMMPSException : public std::exception { public: - std::string message; - LAMMPSException(const std::string &msg) : message(msg) {} - const char *what() const noexcept override { return message.c_str(); } + + protected: + std::string message; }; class LAMMPSAbortException : public LAMMPSException { public: - MPI_Comm universe; - LAMMPSAbortException(const std::string &msg, MPI_Comm _universe) : LAMMPSException(msg), universe(_universe) { } + MPI_Comm get_universe() const { return universe; } + + protected: + MPI_Comm universe; }; enum ErrorType { ERROR_NONE = 0, ERROR_NORMAL = 1, ERROR_ABORT = 2 }; diff --git a/src/library.cpp b/src/library.cpp index c30638a342..135f7d65ef 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -97,15 +97,15 @@ static void ptr_argument_warning() #define END_CAPTURE \ catch(LAMMPSAbortException &ae) { \ int nprocs = 0; \ - MPI_Comm_size(ae.universe, &nprocs ); \ + MPI_Comm_size(ae.get_universe(), &nprocs ); \ \ if (nprocs > 1) { \ - error->set_last_error(ae.message, ERROR_ABORT); \ + error->set_last_error(ae.what(), ERROR_ABORT); \ } else { \ - error->set_last_error(ae.message, ERROR_NORMAL); \ + error->set_last_error(ae.what(), ERROR_NORMAL); \ } \ } catch(LAMMPSException &e) { \ - error->set_last_error(e.message, ERROR_NORMAL); \ + error->set_last_error(e.what(), ERROR_NORMAL); \ } // ---------------------------------------------------------------------- @@ -172,7 +172,7 @@ void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr) lmp = new LAMMPS(argc, argv, comm); if (ptr) *ptr = (void *) lmp; } catch(LAMMPSException &e) { - fprintf(stderr, "LAMMPS Exception: %s\n", e.message); + fprintf(stderr, "LAMMPS Exception: %s\n", e.what()); if (ptr) *ptr = nullptr; } catch (fmt::format_error &fe) { fprintf(stderr, "fmt::format_error: %s\n", fe.what()); diff --git a/src/main.cpp b/src/main.cpp index 3ebc710a24..caf1d4d53c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -78,7 +78,7 @@ int main(int argc, char **argv) delete lammps; } catch (LAMMPSAbortException &ae) { finalize(); - MPI_Abort(ae.universe, 1); + MPI_Abort(ae.get_universe(), 1); } catch (LAMMPSException &) { finalize(); MPI_Barrier(lammps_comm); From 98efb19e79f7da8ef048d0de8b5482104cdfda08 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 16 Apr 2023 12:14:59 -0400 Subject: [PATCH 4/7] simplify and modernize. apply clang-format. --- unittest/fortran/wrap_configuration.cpp | 256 +++++++++++------------- 1 file changed, 118 insertions(+), 138 deletions(-) diff --git a/unittest/fortran/wrap_configuration.cpp b/unittest/fortran/wrap_configuration.cpp index e542caf600..5fb744086e 100644 --- a/unittest/fortran/wrap_configuration.cpp +++ b/unittest/fortran/wrap_configuration.cpp @@ -1,8 +1,8 @@ // unit tests for getting LAMMPS configuration through the Fortran wrapper +#include "info.h" #include "lammps.h" #include "library.h" -#include "info.h" #ifdef LMP_PLUGIN #include "plugin.h" @@ -17,27 +17,27 @@ extern "C" { void *f_lammps_with_args(); void f_lammps_close(); int f_lammps_version(); -int f_lammps_os_info(const char*); +int f_lammps_os_info(const char *); int f_lammps_mpi_support(); int f_lammps_gzip_support(); int f_lammps_png_support(); int f_lammps_jpeg_support(); int f_lammps_ffmpeg_support(); int f_lammps_has_exceptions(); -int f_lammps_has_package(const char*); +int f_lammps_has_package(const char *); int f_lammps_package_count(); -char* f_lammps_package_name(int); -char* f_lammps_installed_packages(int); -int f_lammps_config_accelerator(const char*, const char*, const char*); +char *f_lammps_package_name(int); +char *f_lammps_installed_packages(int); +int f_lammps_config_accelerator(const char *, const char *, const char *); int f_lammps_has_gpu(); -char* f_lammps_get_gpu_info(size_t); -int f_lammps_has_style(const char*, const char*); -int f_lammps_style_count(const char*); -char* f_lammps_style_name(const char*, int); +char *f_lammps_get_gpu_info(size_t); +int f_lammps_has_style(const char *, const char *); +int f_lammps_style_count(const char *); +char *f_lammps_style_name(const char *, int); void f_setup_has_id(); -int f_lammps_has_id(const char*, const char*); -int f_lammps_id_count(const char*); -char* f_lammps_id_name(const char*, int); +int f_lammps_has_id(const char *, const char *); +int f_lammps_id_count(const char *); +char *f_lammps_id_name(const char *, int); int f_lammps_plugin_count(); int f_lammps_plugin_name(); } @@ -48,9 +48,9 @@ using ::testing::ContainsRegex; class LAMMPS_configuration : public ::testing::Test { protected: LAMMPS *lmp; - std::vector style_category = {"atom","integrate","minimize", - "pair","bond","angle","dihedral","improper","kspace","fix","compute", - "region","dump","command"}; + const std::vector style_category = { + "atom", "integrate", "minimize", "pair", "bond", "angle", "dihedral", + "improper", "kspace", "fix", "compute", "region", "dump", "command"}; void SetUp() override { @@ -119,90 +119,82 @@ TEST_F(LAMMPS_configuration, has_exceptions) TEST_F(LAMMPS_configuration, has_package) { - std::vector pkg_name = {"ADIOS","ASPHERE","ATC","AWPMD","BOCS","BODY","BPM", - "BROWNIAN","CG-DNA","CLASS2","COLLOID","COLVARS","COMPRESS","CORESHELL","DEPEND", - "DIELECTRIC","DIFFRACTION","DIPOLE","DPD-BASIC","DPD-MESO","DPD-REACT","DPD-SMOOTH","DRUDE", - "EFF","ELECTRODE","EXTRA-COMPUTE","EXTRA-DUMP","EXTRA-FIX","EXTRA-MOLECULE","EXTRA-PAIR", - "FEP","GPU","GRANULAR","H5MD","INTEL","INTEL/TEST","INTERLAYER","KIM","KOKKOS","KSPACE", - "LATBOLTZ","LATTE","MACHDYN","MAKE","MAKE/MACHINES","MAKE/MINE","MAKE/OPTIONS","MANIFOLD", - "MANYBODY","MC","MDI","MEAM","MESONT","MGPT","MISC","ML-HDNNP","ML-IAP","ML-PACE","ML-QUIP", - "ML-RANN","ML-SNAP","MOFFF","MOLECULE","MOLFILE","MPIIO","MSCG","NETCDF","OPENMP","OPT", - "ORIENT","PERI","PHONON","PLUGIN","PLUMED","POEMS","PTM","PYTHON","QEQ","QMMM","QTB", - "REACTION","REAXFF","REPLICA","RIGID","SCAFACOS","SHOCK","SMTBQ","SPH","SPIN","SRD","STUBS", - "TALLY","UEF","VORONOI","VTK","YAFF","CG-SPICA","AMOEBA"}; + // clang-format off + std::vector pkg_name = { + "ADIOS", "AMOEBA", "ASPHERE", "ATC", "AWPMD", "BOCS", "BODY", "BPM", "BROWNIAN", "CG-DNA", + "CG-SPICA", "CLASS2", "COLLOID", "COLVARS", "COMPRESS", "CORESHELL", "DEPEND", "DIELECTRIC", + "DIFFRACTION", "DIPOLE", "DPD-BASIC", "DPD-MESO", "DPD-REACT", "DPD-SMOOTH", "DRUDE", + "EFF", "ELECTRODE", "EXTRA-COMPUTE", "EXTRA-DUMP", "EXTRA-FIX", "EXTRA-MOLECULE", + "EXTRA-PAIR", "FEP", "GPU", "GRANULAR", "H5MD", "INTEL", "INTEL/TEST", "INTERLAYER", "KIM", + "KOKKOS", "KSPACE", "LATBOLTZ", "LATTE", "LEPTON", "MACHDYN", "MAKE", "MAKE/MACHINES", + "MAKE/MINE", "MAKE/OPTIONS", "MANIFOLD", "MANYBODY", "MC", "MDI", "MEAM", "MESONT", "MGPT", + "MISC", "ML-HDNNP", "ML-IAP", "ML-PACE", "ML-QUIP", "ML-RANN", "ML-SNAP", "MOFFF", + "MOLECULE", "MOLFILE", "MPIIO", "MSCG", "NETCDF", "OPENMP", "OPT", "ORIENT", "PERI", + "PHONON", "PLUGIN", "PLUMED", "POEMS", "PTM", "PYTHON", "QEQ", "QMMM", "QTB", "REACTION", + "REAXFF", "REPLICA", "RIGID", "SCAFACOS", "SHOCK", "SMTBQ", "SPH", "SPIN", "SRD", "STUBS", + "TALLY", "UEF", "VORONOI", "VTK", "YAFF" + }; + // clang-format on - for (std::size_t i = 0; i < pkg_name.size(); i++) - EXPECT_EQ(f_lammps_has_package(pkg_name[i].c_str()), - Info::has_package(pkg_name[i])); + for (std::size_t i = 0; i < pkg_name.size(); i++) + EXPECT_EQ(f_lammps_has_package(pkg_name[i].c_str()), Info::has_package(pkg_name[i])); } TEST_F(LAMMPS_configuration, package_count) { - int package_count = 0; - while (LAMMPS::installed_packages[package_count] != nullptr) - package_count++; - EXPECT_EQ(f_lammps_package_count(), package_count); + int package_count = 0; + while (LAMMPS::installed_packages[package_count] != nullptr) + package_count++; + EXPECT_EQ(f_lammps_package_count(), package_count); }; TEST_F(LAMMPS_configuration, package_name) { - int i = 0; - while (LAMMPS::installed_packages[i] != nullptr) - { - char* name = f_lammps_package_name(i+1); // 1 in Fortran is 0 in C - if (name) - EXPECT_STREQ(LAMMPS::installed_packages[i], name); - else - EXPECT_STREQ(LAMMPS::installed_packages[i], "NOT FOUND"); - std::free(name); - i++; - } + int i = 0; + while (LAMMPS::installed_packages[i] != nullptr) { + char *name = f_lammps_package_name(i + 1); // 1 in Fortran is 0 in C + if (name) + EXPECT_STREQ(LAMMPS::installed_packages[i], name); + else + EXPECT_STREQ(LAMMPS::installed_packages[i], "NOT FOUND"); + std::free(name); + i++; + } }; TEST_F(LAMMPS_configuration, installed_packages) { const char *package_name; int npackages = lammps_config_package_count(); char *pkg; - for (int i=0; i < npackages; i++) { - package_name = LAMMPS::installed_packages[i]; - pkg = f_lammps_installed_packages(i+1); - EXPECT_STREQ(package_name, pkg); - if (pkg) std::free(pkg); + for (int i = 0; i < npackages; i++) { + package_name = LAMMPS::installed_packages[i]; + pkg = f_lammps_installed_packages(i + 1); + EXPECT_STREQ(package_name, pkg); + if (pkg) std::free(pkg); } }; TEST_F(LAMMPS_configuration, config_accelerator) { - const int npackage = 4; - const int ncategory = 2; - const int nsetting_api = 7; - const int nsetting_precision = 3; - const std::string package[] = {"GPU","KOKKOS","INTEL","OPENMP"}; - const std::string category[] = {"api","precision"}; - const std::string setting_api[] = {"cuda","hip","phi","pthreads","opencl", - "openmp","serial"}; - const std::string setting_precision[] = {"double","mixed","single"}; + const std::vector package = {"GPU", "KOKKOS", "INTEL", "OPENMP"}; + const std::vector category = {"api", "precision"}; + const std::vector setting_api = {"cuda", "hip", "phi", "pthreads", + "opencl", "openmp", "serial"}; + const std::vector setting_precision = {"double", "mixed", "single"}; - for (int p=0; p < npackage; p++) - { - for (int c=0; c < ncategory; c++) - { - if (category[c] == "api") - { - for (int s=0; s < nsetting_api; s++) - EXPECT_EQ(f_lammps_config_accelerator(package[p].c_str(), category[c].c_str(), - setting_api[s].c_str()), - Info::has_accelerator_feature(package[p], category[c], setting_api[s])); + for (const auto &p : package) { + for (const auto &c : category) { + if (c == "api") { + for (const auto &s : setting_api) + EXPECT_EQ(f_lammps_config_accelerator(p.c_str(), c.c_str(), s.c_str()), + Info::has_accelerator_feature(p, c, s)); + } else if (c == "precision") { + for (const auto &s : setting_precision) + EXPECT_EQ(f_lammps_config_accelerator(p.c_str(), c.c_str(), s.c_str()), + Info::has_accelerator_feature(p, c, s)); + } } - else if (category[c] == "precision") - { - for (int s=0; s < nsetting_precision; s++) - EXPECT_EQ(f_lammps_config_accelerator(package[p].c_str(), category[c].c_str(), - setting_precision[s].c_str()), - Info::has_accelerator_feature(package[p],category[c],setting_precision[s])); - } - } - } + } }; TEST_F(LAMMPS_configuration, has_gpu) @@ -213,80 +205,70 @@ TEST_F(LAMMPS_configuration, has_gpu) TEST_F(LAMMPS_configuration, get_gpu_info) { if (!Info::has_gpu_device()) GTEST_SKIP(); - size_t n; - std::string cpp_info = Info::get_gpu_device_info(); - n = cpp_info.size(); - char* f_string; - f_string = f_lammps_get_gpu_info(n); + auto cpp_info = Info::get_gpu_device_info(); + char *f_string = f_lammps_get_gpu_info(cpp_info.size()); + EXPECT_STREQ(utils::trim(f_string).c_str(), utils::trim(cpp_info).c_str()); std::free(f_string); - if (n > 80) - { - f_string = f_lammps_get_gpu_info(80); - cpp_info.resize(80); - EXPECT_STREQ(utils::trim(f_string).c_str(), utils::trim(cpp_info).c_str()); - std::free(f_string); + if (cpp_info.size() > 80) { + f_string = f_lammps_get_gpu_info(80); + cpp_info.resize(80); + EXPECT_STREQ(utils::trim(f_string).c_str(), utils::trim(cpp_info).c_str()); + std::free(f_string); } }; TEST_F(LAMMPS_configuration, has_style) { Info info(lmp); - for (std::size_t c = 0; c < style_category.size(); c++) - { - std::vector name = - info.get_available_styles(style_category[c]); - for (std::size_t s = 0; s < name.size(); s++) - { - EXPECT_EQ(f_lammps_has_style(style_category[c].c_str(), - name[s].c_str()), info.has_style(style_category[c], name[s])); - } + for (const auto &c : style_category) { + std::vector name = info.get_available_styles(c); + for (const auto &s : name) + EXPECT_EQ(f_lammps_has_style(c.c_str(), s.c_str()), info.has_style(c, s)); } - EXPECT_EQ(f_lammps_has_style("atom","none"), 0); + EXPECT_EQ(f_lammps_has_style("atom", "none"), 0); }; TEST_F(LAMMPS_configuration, style_count) { Info info(lmp); - for (std::size_t i = 0; i < style_category.size(); i++) - EXPECT_EQ(f_lammps_style_count(style_category[i].c_str()), - info.get_available_styles(style_category[i].c_str()).size()); + for (const auto &c : style_category) + EXPECT_EQ(f_lammps_style_count(c.c_str()), info.get_available_styles(c.c_str()).size()); }; TEST_F(LAMMPS_configuration, style_name) { char *buffer; Info info(lmp); - for (std::size_t c = 0; c < style_category.size(); c++) { - int nnames = f_lammps_style_count(style_category[c].c_str()); - auto styles = info.get_available_styles(style_category[c]); + for (const auto &c : style_category) { + int nnames = f_lammps_style_count(c.c_str()); + auto styles = info.get_available_styles(c); for (int i = 0; i < nnames; i++) { - buffer = f_lammps_style_name(style_category[c].c_str(), i + 1); + buffer = f_lammps_style_name(c.c_str(), i + 1); EXPECT_STREQ(buffer, styles[i].c_str()); std::free(buffer); } } - }; TEST_F(LAMMPS_configuration, has_id) { f_setup_has_id(); - EXPECT_EQ(f_lammps_has_id("compute","com"), 0); - EXPECT_EQ(f_lammps_has_id("compute","COM"), 1); - EXPECT_EQ(f_lammps_has_id("dump","atom"), 0); - EXPECT_EQ(f_lammps_has_id("dump","1"), 1); - EXPECT_EQ(f_lammps_has_id("fix","nve"), 0); - EXPECT_EQ(f_lammps_has_id("fix","1"), 1); - EXPECT_EQ(f_lammps_has_id("group","one"), 1); - EXPECT_EQ(f_lammps_has_id("group","all"), 1); + EXPECT_EQ(f_lammps_has_id("compute", "com"), 0); + EXPECT_EQ(f_lammps_has_id("compute", "COM"), 1); + EXPECT_EQ(f_lammps_has_id("dump", "atom"), 0); + EXPECT_EQ(f_lammps_has_id("dump", "1"), 1); + EXPECT_EQ(f_lammps_has_id("fix", "nve"), 0); + EXPECT_EQ(f_lammps_has_id("fix", "1"), 1); + EXPECT_EQ(f_lammps_has_id("group", "one"), 1); + EXPECT_EQ(f_lammps_has_id("group", "all"), 1); // Skip this one (we're testing thoroughly enough; molecules require files) - //EXPECT_EQ(f_lammps_has_id("molecule") - EXPECT_EQ(f_lammps_has_id("region","simbox"), 1); - EXPECT_EQ(f_lammps_has_id("region","box"), 0); - EXPECT_EQ(f_lammps_has_id("variable","pi"), 1); - EXPECT_EQ(f_lammps_has_id("variable","PI"), 0); + // EXPECT_EQ(f_lammps_has_id("molecule") + EXPECT_EQ(f_lammps_has_id("region", "simbox"), 1); + EXPECT_EQ(f_lammps_has_id("region", "box"), 0); + EXPECT_EQ(f_lammps_has_id("variable", "pi"), 1); + EXPECT_EQ(f_lammps_has_id("variable", "PI"), 0); }; TEST_F(LAMMPS_configuration, id_count) @@ -294,9 +276,9 @@ TEST_F(LAMMPS_configuration, id_count) f_setup_has_id(); // computes: thermo_temp, thermo_press, thermo_pe, COM EXPECT_EQ(f_lammps_id_count("compute"), 4); - EXPECT_EQ(f_lammps_id_count("dump"), 1); // only the one we defined - EXPECT_EQ(f_lammps_id_count("fix"), 1); // only the one we defined - EXPECT_EQ(f_lammps_id_count("group"), 2); // "one" and "all" + EXPECT_EQ(f_lammps_id_count("dump"), 1); // only the one we defined + EXPECT_EQ(f_lammps_id_count("fix"), 1); // only the one we defined + EXPECT_EQ(f_lammps_id_count("group"), 2); // "one" and "all" EXPECT_EQ(f_lammps_id_count("molecule"), 0); EXPECT_EQ(f_lammps_id_count("region"), 1); // onle the one we created EXPECT_EQ(f_lammps_id_count("variable"), 3); // "zpos", "x", and "pi" @@ -309,54 +291,53 @@ TEST_F(LAMMPS_configuration, id_name) int nnames = f_lammps_id_count("compute"); EXPECT_EQ(nnames, 4); - name = f_lammps_id_name("compute",1); + name = f_lammps_id_name("compute", 1); EXPECT_STREQ(name, "thermo_temp"); std::free(name); - name = f_lammps_id_name("compute",2); + name = f_lammps_id_name("compute", 2); EXPECT_STREQ(name, "thermo_press"); std::free(name); - name = f_lammps_id_name("compute",3); + name = f_lammps_id_name("compute", 3); EXPECT_STREQ(name, "thermo_pe"); std::free(name); - name = f_lammps_id_name("compute",4); + name = f_lammps_id_name("compute", 4); EXPECT_STREQ(name, "COM"); std::free(name); - name = f_lammps_id_name("dump",1); + name = f_lammps_id_name("dump", 1); EXPECT_STREQ(name, "1"); std::free(name); - name = f_lammps_id_name("fix",1); + name = f_lammps_id_name("fix", 1); EXPECT_STREQ(name, "1"); std::free(name); - name = f_lammps_id_name("group",1); + name = f_lammps_id_name("group", 1); EXPECT_STREQ(name, "all"); std::free(name); - name = f_lammps_id_name("group",2); + name = f_lammps_id_name("group", 2); EXPECT_STREQ(name, "one"); std::free(name); - name = f_lammps_id_name("region",1); + name = f_lammps_id_name("region", 1); EXPECT_STREQ(name, "simbox"); std::free(name); - name = f_lammps_id_name("variable",1); + name = f_lammps_id_name("variable", 1); EXPECT_STREQ(name, "zpos"); std::free(name); - name = f_lammps_id_name("variable",2); + name = f_lammps_id_name("variable", 2); EXPECT_STREQ(name, "x"); std::free(name); - name = f_lammps_id_name("variable",3); + name = f_lammps_id_name("variable", 3); EXPECT_STREQ(name, "pi"); std::free(name); - }; TEST_F(LAMMPS_configuration, plugins) @@ -367,9 +348,8 @@ TEST_F(LAMMPS_configuration, plugins) int nplugins = f_lammps_plugin_count(); for (int n = 0; n < nplugins; n++) { lammpsplugin_t *plugin = plugin_get_info(n); - EXPECT_EQ(f_lammps_plugin_name(n+1, plugin->style, plugin->name), 1); + EXPECT_EQ(f_lammps_plugin_name(n + 1, plugin->style, plugin->name), 1); } #endif }; - } // namespace LAMMPS_NS From 5f4a80d41fd12ba2961e3a82104464553b64a1e8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 16 Apr 2023 12:34:47 -0400 Subject: [PATCH 5/7] remove obsolete unittest code specific to handling the case of lammps exceptions disabled --- .../c-library/test_library_properties.cpp | 3 --- unittest/commands/test_compute_chunk.cpp | 3 --- unittest/commands/test_compute_global.cpp | 3 --- unittest/commands/test_delete_atoms.cpp | 3 --- unittest/commands/test_groups.cpp | 3 --- unittest/commands/test_kim_commands.cpp | 3 --- unittest/commands/test_labelmap.cpp | 3 --- unittest/commands/test_lattice_region.cpp | 3 --- unittest/commands/test_regions.cpp | 3 --- unittest/commands/test_reset_atoms.cpp | 3 --- unittest/commands/test_set_property.cpp | 3 --- unittest/commands/test_simple_commands.cpp | 3 --- unittest/commands/test_variables.cpp | 3 --- unittest/cplusplus/test_advanced_utils.cpp | 3 --- unittest/cplusplus/test_error_class.cpp | 3 --- unittest/formats/test_file_operations.cpp | 3 --- unittest/formats/test_molecule_file.cpp | 3 --- .../formats/test_potential_file_reader.cpp | 3 --- unittest/formats/test_text_file_reader.cpp | 3 --- unittest/fortran/wrap_properties.cpp | 3 --- unittest/python/python-open.py | 6 +----- unittest/testing/core.h | 21 ++++++------------- unittest/utils/test_lepton.cpp | 16 +++++++------- 23 files changed, 14 insertions(+), 89 deletions(-) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index d6dd55f75e..a684ce8c27 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -461,9 +461,6 @@ TEST_F(LibraryProperties, neighlist) TEST_F(LibraryProperties, has_error) { - // need errors to throw exceptions to be able to intercept them. - if (!lammps_config_has_exceptions()) GTEST_SKIP(); - EXPECT_EQ(lammps_has_error(lmp), 0); // trigger an error, but hide output diff --git a/unittest/commands/test_compute_chunk.cpp b/unittest/commands/test_compute_chunk.cpp index 3b306ab04b..8e919c0612 100644 --- a/unittest/commands/test_compute_chunk.cpp +++ b/unittest/commands/test_compute_chunk.cpp @@ -402,9 +402,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_compute_global.cpp b/unittest/commands/test_compute_global.cpp index d7573d8d16..9f5dc5581d 100644 --- a/unittest/commands/test_compute_global.cpp +++ b/unittest/commands/test_compute_global.cpp @@ -301,9 +301,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_delete_atoms.cpp b/unittest/commands/test_delete_atoms.cpp index e348000969..7c09e7497e 100644 --- a/unittest/commands/test_delete_atoms.cpp +++ b/unittest/commands/test_delete_atoms.cpp @@ -161,9 +161,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_groups.cpp b/unittest/commands/test_groups.cpp index 57820a4548..b91a6108d9 100644 --- a/unittest/commands/test_groups.cpp +++ b/unittest/commands/test_groups.cpp @@ -469,9 +469,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_kim_commands.cpp b/unittest/commands/test_kim_commands.cpp index 2e6e758c76..5f997dccdf 100644 --- a/unittest/commands/test_kim_commands.cpp +++ b/unittest/commands/test_kim_commands.cpp @@ -683,9 +683,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_labelmap.cpp b/unittest/commands/test_labelmap.cpp index f25351e1d9..ebdab08ad3 100644 --- a/unittest/commands/test_labelmap.cpp +++ b/unittest/commands/test_labelmap.cpp @@ -299,9 +299,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_lattice_region.cpp b/unittest/commands/test_lattice_region.cpp index 8dd15396b2..da36628b7f 100644 --- a/unittest/commands/test_lattice_region.cpp +++ b/unittest/commands/test_lattice_region.cpp @@ -632,9 +632,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_regions.cpp b/unittest/commands/test_regions.cpp index 8d5134535a..370799afea 100644 --- a/unittest/commands/test_regions.cpp +++ b/unittest/commands/test_regions.cpp @@ -285,9 +285,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_reset_atoms.cpp b/unittest/commands/test_reset_atoms.cpp index a0afe36324..d09a60c886 100644 --- a/unittest/commands/test_reset_atoms.cpp +++ b/unittest/commands/test_reset_atoms.cpp @@ -806,9 +806,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_set_property.cpp b/unittest/commands/test_set_property.cpp index 62af47f2ed..36b86b3526 100644 --- a/unittest/commands/test_set_property.cpp +++ b/unittest/commands/test_set_property.cpp @@ -460,9 +460,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index db6ee3c1e7..1c995603e1 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -560,9 +560,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 8debb95b6a..530c33fcfe 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -726,9 +726,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/cplusplus/test_advanced_utils.cpp b/unittest/cplusplus/test_advanced_utils.cpp index 6b71c9ea34..0453ef0143 100644 --- a/unittest/cplusplus/test_advanced_utils.cpp +++ b/unittest/cplusplus/test_advanced_utils.cpp @@ -224,9 +224,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/cplusplus/test_error_class.cpp b/unittest/cplusplus/test_error_class.cpp index 779cbfbba6..b7eecb0337 100644 --- a/unittest/cplusplus/test_error_class.cpp +++ b/unittest/cplusplus/test_error_class.cpp @@ -125,9 +125,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (LAMMPS_NS::platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = LAMMPS_NS::utils::split_words(var); diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index d48dee34b2..f1a6ce42f5 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -618,9 +618,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = split_words(var); diff --git a/unittest/formats/test_molecule_file.cpp b/unittest/formats/test_molecule_file.cpp index 2f4336ab8a..8fe1fc1eab 100644 --- a/unittest/formats/test_molecule_file.cpp +++ b/unittest/formats/test_molecule_file.cpp @@ -409,9 +409,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = split_words(var); diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index b19c4166a1..3d14a73d31 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -323,9 +323,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = split_words(var); diff --git a/unittest/formats/test_text_file_reader.cpp b/unittest/formats/test_text_file_reader.cpp index 3146740b3a..8615b71b2a 100644 --- a/unittest/formats/test_text_file_reader.cpp +++ b/unittest/formats/test_text_file_reader.cpp @@ -166,9 +166,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); ::testing::InitGoogleMock(&argc, argv); - if (platform::mpi_vendor() == "Open MPI" && !Info::has_exceptions()) - std::cout << "Warning: using OpenMPI without exceptions. Death tests will be skipped\n"; - // handle arguments passed via environment variable if (const char *var = getenv("TEST_ARGS")) { std::vector env = split_words(var); diff --git a/unittest/fortran/wrap_properties.cpp b/unittest/fortran/wrap_properties.cpp index 50704d326a..6f2b1f64f9 100644 --- a/unittest/fortran/wrap_properties.cpp +++ b/unittest/fortran/wrap_properties.cpp @@ -123,9 +123,6 @@ TEST_F(LAMMPS_properties, extract_setting) TEST_F(LAMMPS_properties, has_error) { - // need errors to throw exceptions to be able to intercept them. - if (!lammps_config_has_exceptions()) GTEST_SKIP(); - EXPECT_EQ(f_lammps_has_error(), lammps_has_error(lmp)); EXPECT_EQ(f_lammps_has_error(), 0); diff --git a/unittest/python/python-open.py b/unittest/python/python-open.py index 3c9165b8c8..f555be25dd 100644 --- a/unittest/python/python-open.py +++ b/unittest/python/python-open.py @@ -4,7 +4,7 @@ from lammps import lammps has_mpi=False has_mpi4py=False -has_exceptions=False + try: from mpi4py import __version__ as mpi4py_version # tested to work with mpi4py versions 2 and 3 @@ -19,7 +19,6 @@ try: machine = "" lmp = lammps(name=machine) has_mpi = lmp.has_mpi_support - has_exceptions = lmp.has_exceptions lmp.close() except: pass @@ -79,7 +78,6 @@ class PythonOpen(unittest.TestCase): self.assertEqual(lmp.opened,1) lmp.close() - @unittest.skipIf(not has_exceptions,"Skipping death test since LAMMPS isn't compiled with exception support") def testUnknownCommand(self): lmp = lammps(name=self.machine) @@ -88,7 +86,6 @@ class PythonOpen(unittest.TestCase): lmp.close() - @unittest.skipIf(not has_exceptions,"Skipping death test since LAMMPS isn't compiled with exception support") def testUnknownCommandInList(self): lmp = lammps(name=self.machine) @@ -97,7 +94,6 @@ class PythonOpen(unittest.TestCase): lmp.close() - @unittest.skipIf(not has_exceptions,"Skipping death test since LAMMPS isn't compiled with exception support") def testUnknownCommandInString(self): lmp = lammps(name=self.machine) diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 272d1d21c5..88503dc188 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -32,21 +32,12 @@ using LAMMPS_NS::LAMMPSException; using ::testing::ContainsRegex; -#define TEST_FAILURE(errmsg, ...) \ - if (Info::has_exceptions()) { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_ANY_THROW({__VA_ARGS__}); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, ContainsRegex(errmsg)); \ - } else { \ - if (LAMMPS_NS::platform::mpi_vendor() != "Open MPI") { \ - ::testing::internal::CaptureStdout(); \ - ASSERT_DEATH({__VA_ARGS__}, ""); \ - auto mesg = ::testing::internal::GetCapturedStdout(); \ - ASSERT_THAT(mesg, ContainsRegex(errmsg)); \ - } else { \ - std::cerr << "[ ] [ INFO ] Skipping death test (no exception support) \n"; \ - } \ +#define TEST_FAILURE(errmsg, ...) \ + { \ + ::testing::internal::CaptureStdout(); \ + ASSERT_ANY_THROW({__VA_ARGS__}); \ + auto mesg = ::testing::internal::GetCapturedStdout(); \ + ASSERT_THAT(mesg, ContainsRegex(errmsg)); \ } // whether to print verbose output (i.e. not capturing LAMMPS screen output). diff --git a/unittest/utils/test_lepton.cpp b/unittest/utils/test_lepton.cpp index 415752c70d..7b2c86f05f 100644 --- a/unittest/utils/test_lepton.cpp +++ b/unittest/utils/test_lepton.cpp @@ -73,16 +73,14 @@ TEST_F(LeptonUtilsTest, substitute) lmp->update->reset_timestep(100LL, false); ASSERT_THAT(LeptonUtils::substitute("(2.5/v_pre)", lmp), StrEq("(2.5/0.1)")); - if (LAMMPS_NS::Info::has_exceptions()) { - bool caught = false; - try { - LeptonUtils::substitute("v_none", lmp); - } catch (std::exception &e) { - ASSERT_THAT(e.what(), StrEq("Variable none in expression v_none does not exist")); - caught = true; - } - ASSERT_TRUE(caught); + bool caught = false; + try { + LeptonUtils::substitute("v_none", lmp); + } catch (std::exception &e) { + ASSERT_THAT(e.what(), StrEq("Variable none in expression v_none does not exist")); + caught = true; } + ASSERT_TRUE(caught); } // zbl() custom function From 397f3e478623ce5a0e978c60190dcbec71bc5b6d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 3 Aug 2023 16:52:24 -0400 Subject: [PATCH 6/7] exceptions are always enabled and thus the check is no longer required --- tools/lammps-gui/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/lammps-gui/CMakeLists.txt b/tools/lammps-gui/CMakeLists.txt index b942b6c8b8..53bd5c68e4 100644 --- a/tools/lammps-gui/CMakeLists.txt +++ b/tools/lammps-gui/CMakeLists.txt @@ -13,9 +13,6 @@ option(LAMMPS_GUI_USE_PLUGIN "Load LAMMPS library dynamically at runtime" OFF) mark_as_advanced(LAMMPS_GUI_USE_PLUGIN) # checks -if(NOT LAMMPS_EXCEPTIONS) - message(FATAL_ERROR "Must enable LAMMPS_EXCEPTIONS for building the LAMMPS GUI") -endif() if(BUILD_MPI) message(FATAL_ERROR "Must disable BUILD_MPI for building the LAMMPS GUI") endif() From e3fa10ee88f39e6699329635d98d877d575e9b5b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 3 Aug 2023 17:35:05 -0400 Subject: [PATCH 7/7] add deprecation note to `lammps_config_has_exceptions()` function --- src/library.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/library.cpp b/src/library.cpp index 1f4117a489..0d8711c520 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -5468,6 +5468,13 @@ int lammps_config_has_ffmpeg_support() { /** Check whether LAMMPS errors will throw C++ exceptions. * \verbatim embed:rst + +.. deprecated:: TBD + + LAMMPS has now exceptions always enabled, so this function + will now always return 1 and can be removed from applications + using the library interface. + In case of an error, LAMMPS will either abort or throw a C++ exception. The latter has to be :ref:`enabled at compile time `. This function checks if exceptions were enabled.