Skip to content

Commit

Permalink
allow c++ tests to run without internet (deepmodeling#785)
Browse files Browse the repository at this point in the history
* fix bug when trying to find gtest in cmake

* link librt explicitly

* add script to test cc without installing tf
  • Loading branch information
y1xiaoc authored Jun 22, 2021
1 parent 44d49f3 commit b15944d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
8 changes: 4 additions & 4 deletions source/api_cc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ else()
endif()

if (USE_CUDA_TOOLKIT)
target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} deepmd_op_cuda coverage_config)
target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} rt deepmd_op_cuda coverage_config)
elseif(USE_ROCM_TOOLKIT)
target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} deepmd_op_rocm coverage_config)
target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} rt deepmd_op_rocm coverage_config)
else()
target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} coverage_config)
target_link_libraries(runUnitTests gtest gtest_main ${libname} ${apiname} ${opname} pthread ${TensorFlow_LIBRARY} rt coverage_config)
endif()

add_test( runUnitTests runUnitTests )

find_package(GTest)
if(NOT GTEST_LIBRARY)
if(NOT GTEST_LIBRARIES)
configure_file(../../cmake/googletest.cmake.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
Expand Down
33 changes: 33 additions & 0 deletions source/install/test_cc_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set -e

#------------------

SCRIPT_PATH=$(dirname $(realpath -s $0))
NPROC=$(nproc --all)

#------------------

BUILD_TMP_DIR=${SCRIPT_PATH}/../build_tests
mkdir -p ${BUILD_TMP_DIR}
cd ${BUILD_TMP_DIR}
cmake ../lib/tests
make -j${NPROC}

#------------------
${BUILD_TMP_DIR}/runUnitTests


#------------------

echo "try to find tensorflow in ${tensorflow_root}"
BUILD_TMP_DIR=${SCRIPT_PATH}/../build_cc_tests
INSTALL_PREFIX=${SCRIPT_PATH}/../../dp
mkdir -p ${BUILD_TMP_DIR}
mkdir -p ${INSTALL_PREFIX}
cd ${BUILD_TMP_DIR}
cmake -DINSTALL_TENSORFLOW=FALSE -DTENSORFLOW_ROOT=${tensorflow_root} ../api_cc/tests
make -j${NPROC}

#------------------
cd ${SCRIPT_PATH}/../api_cc/tests
${BUILD_TMP_DIR}/runUnitTests
2 changes: 1 addition & 1 deletion source/lib/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ add_test( runUnitTests runUnitTests )
# )

find_package(GTest)
if(NOT GTEST_LIBRARY)
if(NOT GTEST_LIBRARIES)
configure_file(../../cmake/googletest.cmake.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
Expand Down

0 comments on commit b15944d

Please sign in to comment.