Skip to content

Commit

Permalink
fix CTest (#2828)
Browse files Browse the repository at this point in the history
1. set `WORKING_DIRECTORY` for `runUnitTest_cc` and `runUnitTest_c`
(help find the graph files);
2. set `BUILD_RPATH` for `deepmd_cc`. (help find `deepmd_op`)

Then CTest should work, using either the `ctest` or `cmake --build .
--target test` command.

---------

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz authored Sep 18, 2023
1 parent 19c6a68 commit c92d1f1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
5 changes: 4 additions & 1 deletion source/api_c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ target_link_libraries(runUnitTests_c PRIVATE GTest::gtest_main ${LIB_DEEPMD_C}
rt coverage_config)
target_link_libraries(runUnitTests_c PRIVATE ${LIB_DEEPMD} ${LIB_DEEPMD_CC})
target_precompile_headers(runUnitTests_c PRIVATE test_utils.h [["deepmd.hpp"]])
add_test(runUnitTests_c runUnitTests_c)
add_test(
NAME runUnitTests_c
COMMAND runUnitTests_c
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(runUnitTests_c PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
install(TARGETS runUnitTests_c DESTINATION bin/)
3 changes: 2 additions & 1 deletion source/api_cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ if(Protobuf_LIBRARY)
endif()

set_target_properties(
${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}")
${libname} PROPERTIES INSTALL_RPATH "$ORIGIN;${TensorFlow_LIBRARY_PATH}"
BUILD_RPATH "$ORIGIN/../op")
target_compile_definitions(${libname} PRIVATE TF_PRIVATE)
if(CMAKE_TESTING_ENABLED)
target_link_libraries(${libname} PRIVATE coverage_config)
Expand Down
5 changes: 4 additions & 1 deletion source/api_cc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ add_executable(runUnitTests_cc ${TEST_SRC})
target_link_libraries(runUnitTests_cc GTest::gtest_main ${LIB_DEEPMD_CC} rt
coverage_config)
target_precompile_headers(runUnitTests_cc PRIVATE test_utils.h)
add_test(runUnitTest_cc runUnitTests_cc)
add_test(
NAME runUnitTest_cc
COMMAND runUnitTests_cc
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(runUnitTests_cc PROPERTIES INSTALL_RPATH "$ORIGIN/../lib")
target_compile_definitions(runUnitTests_cc PUBLIC ${prec_def})
install(TARGETS runUnitTests_cc DESTINATION bin/)
11 changes: 1 addition & 10 deletions source/install/test_cc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,4 @@ cd ${BUILD_TMP_DIR}
cmake -DINSTALL_TENSORFLOW=TRUE -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DTENSORFLOW_ROOT=${INSTALL_PREFIX} -DBUILD_TESTING:BOOL=TRUE -DLAMMPS_VERSION=stable_2Aug2023 ..
cmake --build . -j${NPROC}
cmake --install .

#------------------
# go to a subdirectory...
# TODO: detect directory of graph files
mkdir -p ${BUILD_TMP_DIR}/exec_tests
cd ${BUILD_TMP_DIR}/exec_tests

${INSTALL_PREFIX}/bin/runUnitTests_lib
${INSTALL_PREFIX}/bin/runUnitTests_cc
${INSTALL_PREFIX}/bin/runUnitTests_c
ctest --output-on-failure
11 changes: 1 addition & 10 deletions source/install/test_cc_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,4 @@ cd ${BUILD_TMP_DIR}
cmake -DINSTALL_TENSORFLOW=FALSE -DUSE_TF_PYTHON_LIBS=TRUE -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DBUILD_TESTING:BOOL=TRUE -DLAMMPS_VERSION=stable_2Aug2023 ..
cmake --build . -j${NPROC}
cmake --install .

#------------------
# go to a subdirectory...
# TODO: detect directory of graph files
mkdir -p ${BUILD_TMP_DIR}/exec_tests
cd ${BUILD_TMP_DIR}/exec_tests

${INSTALL_PREFIX}/bin/runUnitTests_lib
${INSTALL_PREFIX}/bin/runUnitTests_cc
${INSTALL_PREFIX}/bin/runUnitTests_c
ctest --output-on-failure

0 comments on commit c92d1f1

Please sign in to comment.