diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index eb10fa34d..acef804c8 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,7 +6,8 @@ Before merging your code, please check the following: * [ ] you have added a line describing your changes to the Changelog; * [ ] you have added unit tests for any new or improved feature; -* [ ] In case you updated dependencies, you have checked pdi/docs/CheckList.md +* [ ] in case you updated dependencies, you have checked pdi/docs/CheckList.md; +* [ ] in case of a change in pdi.h, this same change must be reflected in no-pdi/include/pdi.h; * you have checked your code format: - [ ] you have checked that you respect all conventions specified in CONTRIBUTING.md; - [ ] you have checked that the indentation and formatting conforms to the `.clang-format`; diff --git a/AUTHORS b/AUTHORS index adbd8c042..5e486aea8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,7 +7,8 @@ each sub-project (including PDI itself) is located in the dedicated sub-project AUTHORS file. Julian Auriac - CEA (julian.auriac@cea.fr) -* fix CI bug where tests.xml file could not be written +* Add pdi deactivation option +* Fix CI bug where tests.xml file could not be written Julien Bigot - CEA (julien.bigot@cea.fr) * Maintainer (Dec. 2014 - ...) @@ -25,7 +26,7 @@ François-Xavier Mordant - CEA (francois-xavier.mordant@cea.fr) * Bug fix, JSON plugin Jacques Morice - CEA (jacques.morice@cea.fr) -* fix the directory of hdf5 library for rhel +* Fix the directory of hdf5 library for rhel Thomas Padioleau - CEA (thomas.padioleau@cea.fr) * Added macOS CI diff --git a/CHANGELOG.md b/CHANGELOG.md index d57fab790..0788a928d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Added +* Add "no-pdi", including the header no-pdi/include/pdi.h, which allows to + disable PDI effects while keeping code syntax unchanged. + [#438](https://github.com/pdidev/pdi/issues/438) * Added macOS CI for PDI, decl_hdf5, mpi, serialize, set_value, user_code and trace plugins [#556](https://github.com/pdidev/pdi/issues/556) diff --git a/bin/build_and_run_all_tests b/bin/build_and_run_all_tests index 2393a46ac..4cc3e1efb 100755 --- a/bin/build_and_run_all_tests +++ b/bin/build_and_run_all_tests @@ -37,17 +37,30 @@ set -xe SRCDIR="${PWD}" -TEST_DIR="${TEST_DIR:-${PWD}}" -cd "${TEST_DIR}" +# Prepare working directories +TEST_DIR_WITH_PDI="${TEST_DIR_WITH_PDI:-${PWD}}" +cd "${TEST_DIR_WITH_PDI}" cd "$(mktemp -d pdibuild.XXXXX)" -TEST_DIR="${PWD}" +TEST_DIR_ROOT="${PWD}" + +mkdir no_pdi +cd no_pdi +TEST_DIR_NO_PDI="${PWD}" + +cd "${TEST_DIR_ROOT}" +mkdir with_pdi +cd with_pdi +TEST_DIR_WITH_PDI="${PWD}" + +cd "${TEST_DIR_ROOT}" +mkdir api_pdi +cd api_pdi +TEST_DIR_API="${PWD}" cd "${SRCDIR}" cd "$(dirname "$0")/.." SRCDIR="${PWD}" -cd "${TEST_DIR}" - # Gather options @@ -122,8 +135,27 @@ fi -# Configure, build & test +# Configure, build & test for pdi +cd "${TEST_DIR_WITH_PDI}" cmake -DDIST_PROFILE=Devel ${CMAKE_FLAGS} "${SRCDIR}" make ${MAKEFLAGS} ctest --output-on-failure --timeout 90 ${CTEST_FLAGS} ${EXCLUDED_PDI_TESTS:+-E $EXCLUDED_PDI_TESTS} + +RELATIVE_NO_PDI_PATH="no-pdi" +if ldconfig -p | grep -q libparaconf; then + # Configure, build & test for pdi's example with CMAKE_PREFIX_PATH (find_package) for no-pdi, with Paraconf + + cd "${TEST_DIR_NO_PDI}" + cmake -DBUILD_DECL_HDF5_PLUGIN=OFF -DBUILD_DECL_NETCDF_PLUGIN=OFF -DBUILD_JSON_PLUGIN=OFF -DBUILD_FORTRAN=OFF -DBUILD_PYTHON=OFF -DCMAKE_PREFIX_PATH="${SRCDIR}/${RELATIVE_NO_PDI_PATH}" "${SRCDIR}/example" + make ${MAKEFLAGS} + ctest --output-on-failure --timeout 90 ${CTEST_FLAGS} -R PDI_example_trace_C +fi + +# Configure, build & test for no-pdi's specific tests with CMAKE_PREFIX_PATH (find_package), with or without Paraconf + +cd "${TEST_DIR_API}" +NO_PDI_TESTS="test_api_C test_api_CXX" +cmake -DBUILD_DECL_HDF5_PLUGIN=OFF -DBUILD_DECL_NETCDF_PLUGIN=OFF -DCMAKE_PREFIX_PATH="${SRCDIR}/${RELATIVE_NO_PDI_PATH}" "${SRCDIR}/tests" +make ${MAKEFLAGS} +ctest --output-on-failure --timeout 90 ${CTEST_FLAGS} -R ${NO_PDI_TESTS} diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 11d6ee7e8..59625bcfe 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (C) 2015-2024 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# Copyright (C) 2015-2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) # Copyright (C) 2020 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC) # All rights reserved. # @@ -32,6 +32,7 @@ project(pdi_examples LANGUAGES C) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") set(MPI_COMPONENTS C) +set(paraconf_COMPONENTS C) set(PDI_COMPONENTS C) if("${BUILD_FORTRAN}") @@ -48,6 +49,7 @@ endif() # Includes include(CTest) find_package(MPI REQUIRED COMPONENTS ${MPI_COMPONENTS}) +find_package(paraconf REQUIRED COMPONENTS ${paraconf_COMPONENTS}) find_package(PDI REQUIRED COMPONENTS ${PDI_COMPONENTS}) find_library(LIB_M m DOC "The math library") @@ -77,7 +79,8 @@ endif() add_executable(PDI_example_C example.c) -target_link_libraries(PDI_example_C PDI::PDI_C MPI::MPI_C m) +target_link_libraries(PDI_example_C paraconf::paraconf PDI::PDI_C MPI::MPI_C m) + if("${BUILD_FORTRAN}") add_executable(PDI_example_F example.F90) diff --git a/example/README.md b/example/README.md index 3b5752e3c..5675b362a 100644 --- a/example/README.md +++ b/example/README.md @@ -117,3 +117,10 @@ Above instruction will share `iter` and `main_field`, call `newiter` event and t This is the place when plugins will read/write our data. We have covered the logic behind the %PDI example. Now you can start the \ref Hands_on. + +## PDI deactivation {#pdi_deactivation} + +Use `no-pdi` instead of `pdi` when building with: +```bash +cmake -DCMAKE_MODULE_PATH=/no-pdi/cmake .. +``` diff --git a/no-pdi/CMakeLists.txt b/no-pdi/CMakeLists.txt new file mode 100644 index 000000000..42b11fbc9 --- /dev/null +++ b/no-pdi/CMakeLists.txt @@ -0,0 +1,33 @@ +#============================================================================= +# Copyright (C) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the names of CEA, nor the names of the contributors may be used to +# endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +cmake_minimum_required(VERSION 3.16...3.29) +project(PDI LANGUAGES C CXX) + +include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/PDIConfig.cmake") diff --git a/no-pdi/cmake/PDIConfig.cmake b/no-pdi/cmake/PDIConfig.cmake new file mode 100644 index 000000000..d6f41154e --- /dev/null +++ b/no-pdi/cmake/PDIConfig.cmake @@ -0,0 +1,42 @@ +#============================================================================= +# Copyright (C) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the names of CEA, nor the names of the contributors may be used to +# endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +add_library(PDI_C INTERFACE) +add_library(PDI::pdi ALIAS PDI_C) +add_library(PDI::PDI_C ALIAS PDI_C) + +set_target_properties(PDI_C PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/../include" +) + +find_package(paraconf 1.0.0 COMPONENTS C) + +if(paraconf_FOUND) + add_compile_definitions(PARACONF_FOUND) +endif() diff --git a/no-pdi/cmake/PDIConfigVersion.cmake b/no-pdi/cmake/PDIConfigVersion.cmake new file mode 100644 index 000000000..3d88162a4 --- /dev/null +++ b/no-pdi/cmake/PDIConfigVersion.cmake @@ -0,0 +1,30 @@ +#============================================================================= +# Copyright (C) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# * Neither the names of CEA, nor the names of the contributors may be used to +# endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +#============================================================================= + +set(PDI_VERSION "1.9.2") diff --git a/no-pdi/include/pdi.h b/no-pdi/include/pdi.h new file mode 100644 index 000000000..bf486d90b --- /dev/null +++ b/no-pdi/include/pdi.h @@ -0,0 +1,297 @@ +/******************************************************************************* +* Copyright (C) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of CEA nor the names of its contributors may be used to +* endorse or promote products derived from this software without specific +* prior written permission. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ + +/** \file pdi.h for deactivation + * + * C user API + * + * The user facing API is the interface offered by PDI to C application + * developers. + * + * \defgroup init_final Initialization and finalization + * + * The initialization and finalization part of the API is used to setup PDI, + * release its resources and check version information. + * + * \defgroup annotation Code annotation + * + * The code annotation API is the main interface to use in the code. + * + * It offers functions that can be called from code with no side effect by + * default and that can therefore be considered as annotations. + * + * \defgroup error Error handling + * + * The error handling API supports checking the error status of PDI. + * + * By default, errors in PDI C API are signaled by a return code of type + * PDI_status_t and an error message can be retrieved with the PDI_errmsg + * function. This default behavior can be changed by replacing the error handler + * with the PDI_errhandler function. + * + */ + +#ifndef PDI_H_ +#define PDI_H_ + +#ifdef PARACONF_FOUND +#include +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** \addtogroup error + * \{ + */ + +/** Error codes of PDI + */ +typedef enum PDI_status_e { + /// everything went well + PDI_OK = 0, + /// on an input call, no such data is available + PDI_UNAVAILABLE, + /// The configuration file is invalid + PDI_ERR_CONFIG, + /// A value expression is invalid + PDI_ERR_VALUE, + /// Tried to load a non-existing plugin + PDI_ERR_PLUGIN, + /// Implementation limitation (typically an unimplemented feature) + PDI_ERR_IMPL, + /// A system error occured (OS, etc.) + PDI_ERR_SYSTEM, + /** A call to a function has been made at a wrong time (e.g. closing an + * unopened transaction) + */ + PDI_ERR_STATE, + /// A conflict of onwership over a content has been raised + PDI_ERR_RIGHT, + /// Invalid type error + PDI_ERR_TYPE + +} PDI_status_t; + +/** Type of a callback function used when an error occurs + * \param status the error code + * \param message the human-readable error message + * \param context a user-provided context + */ +typedef void (*PDI_errfunc_f)(PDI_status_t status, const char* message, void* context); + +/** Definition of an error handler + */ +typedef struct PDI_errhandler_s { + /// The function to handle the error (none if NULL) + PDI_errfunc_f func; + + /// the context that will be provided to the function + void* context; + +} PDI_errhandler_t; + +/** Does nothing + */ +static const PDI_errhandler_t PDI_NULL_HANDLER = {NULL, NULL}; + +/** Prints the error message and aborts if the status is invalid + */ +static const PDI_errhandler_t PDI_ASSERT_HANDLER = {NULL, NULL}; + +/** Prints the error message and continue if the status is invalid + */ +static const PDI_errhandler_t PDI_WARN_HANDLER = {NULL, NULL}; + +/** Return a human-readabe message describing the last error that occured in PDI + */ +static inline const char* PDI_errmsg(void) +{ + return ""; +} + +/** Sets the error handler to use + */ +static inline PDI_errhandler_t PDI_errhandler(PDI_errhandler_t handler) +{ + return PDI_NULL_HANDLER; +} + +/// \} + +/** \addtogroup init_final Initialization and finalization + * + * The initialization and finalization part of the API is used to setup PDI, + * release its resources and check version information. + * \{ + */ + +/** Initializes PDI + */ +#ifdef PARACONF_FOUND + +static inline PDI_status_t PDI_init(PC_tree_t conf) +{ + return PDI_OK; +} +#endif // PARACONF_FOUND + +/** Finalizes PDI + * \return an error status + */ +static inline PDI_status_t PDI_finalize(void) +{ + return PDI_OK; +} + +/** Checks PDI API version + */ +static inline PDI_status_t PDI_version(unsigned long* provided, unsigned long expected) +{ + return PDI_OK; +} + +/// \} + +/** \addtogroup annotation + * \{ + */ + +/** + * Access directions + */ +typedef enum PDI_inout_e { + /// No data transfert + PDI_NONE = 0, + /// data tranfer from PDI to the main code + PDI_IN = 1, + /// data transfer from the main code to PDI + PDI_OUT = 2, + /// data transfer in both direction + PDI_INOUT = 3 + +} PDI_inout_t; + +/** Shares some data with PDI. The user code should not modify it before + * a call to either PDI_release or PDI_reclaim. + */ +static inline PDI_status_t PDI_share(const char* name, const void* data, PDI_inout_t access) +{ + return PDI_OK; +} + +/** Requests for PDI to access a data buffer. + */ +static inline PDI_status_t PDI_access(const char* name, void** buffer, PDI_inout_t inout) +{ + return PDI_OK; +} + +/** Releases ownership of a data shared with PDI. PDI is then responsible to + * free the associated memory whenever necessary. + */ +static inline PDI_status_t PDI_release(const char* name) +{ + return PDI_OK; +} + +/** Reclaims ownership of a data buffer shared with PDI. PDI does not manage + * the buffer memory anymore. + */ +static inline PDI_status_t PDI_reclaim(const char* name) +{ + return PDI_OK; +} + +/** Triggers a PDI "event" + */ +static inline PDI_status_t PDI_event(const char* event) +{ + return PDI_OK; +} + +/** Shortly exposes some data to PDI. Equivalent to PDI_share + PDI_reclaim. + */ +static inline PDI_status_t PDI_expose(const char* name, const void* data, PDI_inout_t access) +{ + return PDI_OK; +} + +/** Performs multiple exposes at once. All the data is shared in order they were specified + * and reclaimed in reversed order after an event is triggered. + * + * NULL argument indicates an end of the list. + */ +static inline PDI_status_t PDI_multi_expose(const char* event_name, const char* name, const void* data, PDI_inout_t access, ...) +{ + return PDI_OK; +} + +#ifdef PDI_WITH_DEPRECATED + +/** Begin a transaction in which all PDI_expose calls are grouped. + * + * This requires a call to PDI_transaction_end to close the transaction. + * + * \deprecated the transaction part of the API is deprecated, the + * PDI_multi_expose function should be used instead. + * + * \see PDI_expose the function used to expose data inside the transaction + * \see PDI_transaction_end the function used to end the transaction + * + * \return an error status + */ +static inline PDI_status_t PDI_transaction_begin(const char* name) +{ + return PDI_OK; +} + +/** Ends the previously opened transaction. + * + * \deprecated the transaction part of the API is deprecated, the + * PDI_multi_expose function should be used instead. + * + * \see PDI_transaction_begin the function used to start the transaction + * \see PDI_expose the function used to expose data inside the transaction + * + * \return an error status + */ +static inline PDI_status_t PDI_transaction_end(void) +{ + return PDI_OK; +} + +#endif // PDI_WITH_DEPRECATED + +/// \} + +#ifdef __cplusplus +} // extern C +#endif + + +#endif // PDI_H_ diff --git a/pdi/docs/CheckList.md b/pdi/docs/CheckList.md index 55a09dc78..5436535d8 100644 --- a/pdi/docs/CheckList.md +++ b/pdi/docs/CheckList.md @@ -24,6 +24,7 @@ To publish a new minor or major release: * start from the main branch * change the version in `pdi/VERSION` * change the version in `pdi/docs/Source_installation.md` +* all versions changes (including PDI itself and CMake) must be reflected on no-pdi * go over all `CHANGELOG.md` files and mark the just released version * commit these changes into a new version branch (`v${X}.${Y}`) * tag the new release: `git tag -m "PDI release ${X}.${Y}.0" -s "${X}.${Y}.0"` diff --git a/pdi/docs/Using_PDI.md b/pdi/docs/Using_PDI.md index 000fc3865..9d93dc71c 100644 --- a/pdi/docs/Using_PDI.md +++ b/pdi/docs/Using_PDI.md @@ -38,6 +38,8 @@ If source files (of application that uses %PDI) and specification tree file are For C make sure that source files that use %PDI API are including `pdi.h` header file. For Fortran make sure that source files that use %PDI API are using `%PDI` module file (`USE %PDI`). +%PDI can be disabled by using the `no-pdi` directory (see section ["How to deactivate PDI"](#deactivate_pdi)). + ### Compiling by hand {#compiling_by_hand} To compile application, linker flag `-lpdi` must be used. @@ -93,3 +95,23 @@ plugins in 4 steps (it will use the first plugin found): 2. `plugin_path` subtree in specification tree: \ref plugin_path_map_node, 3. Relative path of used %PDI shared object `libpdi.so`, 4. `LD_LIBRARY_PATH` environment variable that is colon separated list. + +## How to deactivate PDI {#deactivate_pdi} + +### Using the no-pdi directory with an available Paraconf + +You may use the no-pdi mock folder instead of the real PDI to compile your +application. The only modification you need to make is to add the +CMAKE_PREFIX_PATH option to your CMake command : +```bash +cmake . -your-usual-cmake-compile-options -DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:+${CMAKE_PREFIX_PATH}:}/no-pdi" +``` +The no-pdi directory can be copied out of the pdi repository, for convenience. + +If Paraconf is missing from your system, you need to remove all calls to it +from your application. +This contains its inclusion (`#include ` in C/C++, for example), +its use by PDI via `PDI_init`, and direct calls to Paraconf API. + +%PDI can be re-enabled by reverting those modifications, +using cmake again without specifying a path to no-pdi. diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1706d200b..188dfae2d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,6 @@ #============================================================================= # Copyright (C) 2020 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC) -# Copyright (C) 2020-2024 Commissariat a l'energie atomique et aux energies alternatives (CEA) +# Copyright (C) 2020-2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ #============================================================================= cmake_minimum_required(VERSION 3.16...3.29) -project(pdi_tests LANGUAGES C) +project(pdi_tests LANGUAGES C CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") set(RUNTEST_DIR "${CMAKE_CURRENT_LIST_DIR}/../cmake/runtest-dir") @@ -32,10 +32,13 @@ set(RUNTEST_DIR "${CMAKE_CURRENT_LIST_DIR}/../cmake/runtest-dir") option(BUILD_DECL_HDF5_PLUGIN "Build Decl'HDF5 plug-in" ON) option(BUILD_SERIALIZE_PLUGIN "Build Serialize plug-in" ON) -# Includes include(CTest) -# PDI +find_package(paraconf 1.0.0 COMPONENTS C) +if(paraconf_FOUND) + add_compile_definitions(PARACONF_FOUND) +endif() + find_package(PDI REQUIRED COMPONENTS C) if("${BUILD_DECL_HDF5_PLUGIN}" AND "${BUILD_SERIALIZE_PLUGIN}") @@ -64,3 +67,19 @@ target_link_libraries(test_05_C PDI::PDI_C) add_test(NAME test_05_C COMMAND "$" "${CMAKE_CURRENT_SOURCE_DIR}/test_05.yml") endif("${BUILD_DECL_NETCDF_PLUGIN}" AND "${BUILD_SERIALIZE_PLUGIN}") + +add_executable(test_api_C test_api.c) +if(paraconf_FOUND) + target_link_libraries(test_api_C paraconf::paraconf PDI::PDI_C) +else() + target_link_libraries(test_api_C PDI::PDI_C) +endif() +add_test(NAME test_api_C COMMAND "$") + +add_executable(test_api_CXX test_api.cpp) +if(paraconf_FOUND) + target_link_libraries(test_api_CXX paraconf::paraconf PDI::PDI_C) +else() + target_link_libraries(test_api_CXX PDI::PDI_C) +endif() +add_test(NAME test_api_CXX COMMAND "$") diff --git a/tests/test_api.c b/tests/test_api.c new file mode 100644 index 000000000..c6119fe87 --- /dev/null +++ b/tests/test_api.c @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (C) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "test_api.h" + +int main(int argc, char* argv[]) +{ + tests(argc, argv); + printf("Disabled PDI ok for C.\n"); +} diff --git a/tests/test_api.cpp b/tests/test_api.cpp new file mode 100644 index 000000000..4b0bdb5c5 --- /dev/null +++ b/tests/test_api.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (C) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "test_api.h" + +#include + +int main(int argc, char* argv[]) +{ + tests(argc, argv); + std::cout << "Disabled PDI ok for C++." << std::endl; +} diff --git a/tests/test_api.h b/tests/test_api.h new file mode 100644 index 000000000..e332db05a --- /dev/null +++ b/tests/test_api.h @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (C) 2025 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#ifdef __cplusplus +#include +#include +#include +#else +#include +#include +#include +#endif +#ifdef PARACONF_FOUND +#include +#endif + +void share() //share +{ + int to_share[2] = {1, 1}; + if (PDI_OK != PDI_share("to_share", to_share, PDI_OUT)) { + fprintf(stderr, "*** Error: no-pdi share\n"); + exit(EXIT_FAILURE); + } +} + +void access() //share/access +{ + int to_access[2] = {1, 1}; + PDI_share("to_access", to_access, PDI_OUT); + if (PDI_OK != PDI_access("to_access", (void**)&to_access, PDI_IN)) { + fprintf(stderr, "*** Error: no-pdi access\n"); + exit(EXIT_FAILURE); + } +} + +void release() //share/release +{ + int to_release[2] = {1, 1}; + PDI_share("to_release", to_release, PDI_OUT); + PDI_access("to_release", (void**)&to_release, PDI_IN); + if (PDI_OK != PDI_release("to_release")) { + fprintf(stderr, "*** Error: no-pdi release\n"); + exit(EXIT_FAILURE); + } +} + +void reclaim() //share/reclaim +{ + int to_reclaim[2] = {1, 1}; + PDI_share("to_reclaim", to_reclaim, PDI_OUT); + if (PDI_OK != PDI_reclaim("to_reclaim")) { + fprintf(stderr, "*** Error: no-pdi reclaim\n"); + exit(EXIT_FAILURE); + } +} + +void event() +{ + if (PDI_OK != PDI_event("event_one")) { + fprintf(stderr, "*** Error: no-pdi event\n"); + exit(EXIT_FAILURE); + } +} + +void expose() +{ + int to_expose[2] = {1, 1}; + if (PDI_OK != PDI_expose("to_expose", to_expose, PDI_OUT)) { + fprintf(stderr, "*** Error: no-pdi expose\n"); + exit(EXIT_FAILURE); + } +} + +void multi_expose() +{ + int to_multi_expose[2] = {1, 1}; + int to_multi_expose_two[2] = {2, 2}; + if (PDI_OK + != PDI_multi_expose("event_two", "to_multi_expose", &to_multi_expose, PDI_OUT, "to_multi_expose_two", to_multi_expose_two, PDI_OUT, NULL)) + { + fprintf(stderr, "*** Error: no-pdi multi_expose\n"); + exit(EXIT_FAILURE); + } +} + +void errhandler() +{ + PDI_errhandler_t current_handler = PDI_errhandler(PDI_NULL_HANDLER); + if (NULL != current_handler.context) { + fprintf(stderr, "*** Error: no-pdi errhandler\n"); + exit(EXIT_FAILURE); + } +} + +int tests(int argc, char* argv[]) +{ +#ifdef PARACONF_FOUND + static const char* CONFIG_YAML + = "logging: trace \n" + "data: \n" + " to_share: {type: array, subtype: int, size: 2} \n" + " to_access: {type: array, subtype: int, size: 2} \n" + " to_release: {type: array, subtype: int, size: 2} \n" + " to_reclaim: {type: array, subtype: int, size: 2} \n" + " to_expose: {type: array, subtype: int, size: 2} \n" + " to_multi_expose: {type: array, subtype: int, size: 2} \n" + " to_multi_expose_two: {type: array, subtype: int, size: 2} \n"; + + if (PDI_OK != PDI_init(PC_parse_string(CONFIG_YAML))) { + fprintf(stderr, "*** Error: no-pdi initialisation\n"); + exit(EXIT_FAILURE); + } +#endif // PARACONF_FOUND + + const char* errmsg = PDI_errmsg(); + if (strcmp(errmsg, "") != 0) { + fprintf(stderr, "*** Error: no-pdi errmsg\n"); + exit(EXIT_FAILURE); + } + + errhandler(); + + share(); + access(); + release(); + reclaim(); + event(); + expose(); + multi_expose(); + + if (PDI_OK != PDI_finalize()) { + fprintf(stderr, "*** Error: no-pdi finalisation\n"); + exit(EXIT_FAILURE); + } + + return EXIT_SUCCESS; +}