Skip to content

Commit

Permalink
Merge pull request OpenDDS#4316 from tmayoff/cmake_tests
Browse files Browse the repository at this point in the history
Add some tests to cmake
  • Loading branch information
jrw972 authored Nov 27, 2023
2 parents f4ec88a + 97cbfc1 commit 873bc2c
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,45 @@ if(OPENDDS_BUILD_EXAMPLES OR OPENDDS_BUILD_TESTS)
add_subdirectory(DevGuideExamples/DCPS/Messenger)
endif()
if(OPENDDS_BUILD_TESTS)
find_package(GTest QUIET PATHS "${OPENDDS_GTEST}")
if(NOT GTest_FOUND)
set(gtestsm "${OPENDDS_SOURCE_DIR}/tests/googletest")
if(EXISTS "${gtestsm}/CMakeLists.txt")
message("GTest not found, using submodule")
set(fetch_args SOURCE_DIR "${gtestsm}")
else()
message("GTest not found, using clone")
set(fetch_args
GIT_REPOSITORY "https://github.com/OpenDDS/googletest"
GIT_TAG "v1.8.x"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
USES_TERMINAL_DOWNLOAD TRUE
)
endif()
FetchContent_Declare(googletest ${fetch_args})
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
if(TARGET GTest::gtest)
get_target_property(google_test_bin_dir GTest::gtest BINARY_DIR)
set(_OPENDDS_GOOGLE_TEST_DIR "${google_test_bin_dir}" CACHE INTERNAL "")
elseif(TARGET gtest)
get_target_property(google_test_bin_dir gtest BINARY_DIR)
set(_OPENDDS_GOOGLE_TEST_DIR "${google_test_bin_dir}" CACHE INTERNAL "")
endif()

add_subdirectory(tests/cmake/ace_tao_only)
if(OPENDDS_OWNERSHIP_PROFILE)
add_subdirectory(tests/cmake/Messenger)
endif()
add_subdirectory(tests/cmake/idl_compiler_tests)
add_subdirectory(tests/DCPS/Compiler/optional)
add_subdirectory(tests/cmake/include_subdir)
add_subdirectory(tests/DCPS/Compiler/char_literals)
add_subdirectory(tests/DCPS/HelloWorld)
# TODO: This test always builds shared libraries and linker complains about
# ACE/TAO libs lacking -fPIC when ACE is static.
if(OPENDDS_OWNERSHIP_PROFILE AND NOT OPENDDS_STATIC)
Expand Down
7 changes: 7 additions & 0 deletions cmake/opendds_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ function(opendds_add_test)
set(env_var_name LD_LIBRARY_PATH)
endif()
_opendds_path_list(lib_dir_list "$ENV{${env_var_name}}" "${TAO_LIB_DIR}")
if(DEFINED _OPENDDS_GOOGLE_TEST_DIR)
_opendds_path_list(lib_dir_list APPEND "${_OPENDDS_GOOGLE_TEST_DIR}")
if(CMAKE_CONFIGURATION_TYPES)
_opendds_path_list(lib_dir_list APPEND
"${_OPENDDS_GOOGLE_TEST_DIR}$<$<BOOL:$<CONFIG>>:/$<CONFIG>>")
endif()
endif()
foreach(lib_dir "${OPENDDS_LIB_DIR}" ${arg_EXTRA_LIB_DIRS})
_opendds_path_list(lib_dir_list APPEND "${lib_dir}")
if(CMAKE_CONFIGURATION_TYPES)
Expand Down
35 changes: 35 additions & 0 deletions tests/DCPS/Compiler/char_literals/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.8...3.27)
project(opendds_compiler_char_literals CXX)
enable_testing()

find_package(OpenDDS REQUIRED)
include(opendds_testing)

set(target_prefix "${PROJECT_NAME}_")
set(dst ${CMAKE_CURRENT_BINARY_DIR})
set(opendds_libs
OpenDDS::Dcps
)

# IDL Library
set(idl "${target_prefix}idl")
add_library(${idl})
opendds_target_sources(${idl} PUBLIC "test.idl" OPENDDS_IDL_OPTIONS "-Lc++11")
target_link_libraries(${idl} PUBLIC OpenDDS::Dcps)
set(idl_dir "${dst}/cpp11")
set_target_properties(${idl} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${idl_dir}"
LIBRARY_OUTPUT_DIRECTORY "${idl_dir}"
)

add_executable(opendds_compiler_char_literals_exe
"main.cpp"
)
set_target_properties(opendds_compiler_char_literals_exe PROPERTIES
OUTPUT_NAME char-literals-cpp11
RUNTIME_OUTPUT_DIRECTORY "${dst}/cpp11"
)
target_link_libraries(opendds_compiler_char_literals_exe ${opendds_libs} ${idl} gtest)

configure_file(run_test.pl . COPYONLY)
opendds_add_test(COMMAND perl run_test.pl cpp11 EXTRA_LIB_DIRS "${idl_dir}")
47 changes: 47 additions & 0 deletions tests/DCPS/HelloWorld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_hello_world CXX)
enable_testing()

find_package(OpenDDS REQUIRED)
include(opendds_testing)

set(target_prefix "${PROJECT_NAME}_")

# IDL TypeSupport Library
set(idl "${target_prefix}idl")
add_library(${idl})
opendds_target_sources(${idl} PUBLIC "HelloWorld.idl")
target_link_libraries(${idl} PUBLIC OpenDDS::Dcps)

set(opendds_libs
OpenDDS::Dcps # Core OpenDDS Library
OpenDDS::InfoRepoDiscovery OpenDDS::Tcp # For run_test.pl
OpenDDS::Rtps OpenDDS::Rtps_Udp # For run_test.pl --rtps
${idl}
)

# Publisher
set(publisher "${target_prefix}publisher")
add_executable(${publisher}
publisher.cpp
)
target_link_libraries(${publisher} ${opendds_libs})
set_target_properties(${publisher} PROPERTIES
OUTPUT_NAME publisher
)

# Subscriber
set(subscriber "${target_prefix}subscriber")
add_executable(${subscriber}
subscriber.cpp
)
target_link_libraries(${subscriber} ${opendds_libs})
set_target_properties(${subscriber} PROPERTIES
OUTPUT_NAME subscriber
)

# Testing
configure_file(run_test.pl . COPYONLY)
configure_file(rtps.ini . COPYONLY)
opendds_add_test(NAME info_repo COMMAND perl run_test.pl)
opendds_add_test(NAME rtps COMMAND perl run_test.pl ini=rtps.ini)
4 changes: 2 additions & 2 deletions tests/DCPS/HelloWorld/run_test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
$test->process('subscriber', 'subscriber');
$test->process('publisher', 'publisher');

rmtree './DCS';
rmtree('./DCS');

$test->start_process('publisher');
$test->start_process('subscriber');

exit $test->finish(30);
exit($test->finish(60));

0 comments on commit 873bc2c

Please sign in to comment.