Skip to content

Commit

Permalink
Reorganize CMake Tests
Browse files Browse the repository at this point in the history
This will make it easier to add tests in the future. It also unifies the
lists of MPC-build OpenDDS CMake tests and the CMake-build tests.

Also:
- Promoted Messenger_2 CMake test to `tests/DCPS/Messenger`.
- Various cleanup to the various test CMakeLists files.
  • Loading branch information
iguessthislldo committed Nov 30, 2023
1 parent 809b147 commit 6c8ac5e
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 122 deletions.
45 changes: 1 addition & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,48 +137,5 @@ 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)
add_subdirectory(tests/cmake/generated_global)
endif()
add_subdirectory(tests)
endif()
4 changes: 2 additions & 2 deletions DevGuideExamples/DCPS/Messenger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ target_link_libraries(subscriber ${opendds_libs})
# 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 --rtps)
opendds_add_test(NAME info_repo)
opendds_add_test(NAME rtps ARGS --rtps)
40 changes: 40 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_tests)
enable_testing()

find_package(OpenDDS REQUIRED)

find_package(GTest QUIET PATHS "${OPENDDS_GTEST}")
if(NOT GTest_FOUND)
set(gtestsm "${CMAKE_CURRENT_LIST_DIR}/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)
set(INSTALL_GTEST OFF 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(cmake)
add_subdirectory(DCPS)
add_subdirectory(unit-tests)
9 changes: 9 additions & 0 deletions tests/DCPS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_tests_dcps)
enable_testing()

find_package(OpenDDS REQUIRED)

add_subdirectory(Compiler)
add_subdirectory(HelloWorld)
add_subdirectory(Messenger)
9 changes: 9 additions & 0 deletions tests/DCPS/Compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_tests_dcps_compiler)
enable_testing()

find_package(OpenDDS REQUIRED)

add_subdirectory(char_literals)
add_subdirectory(optional)
add_subdirectory(xcdr)
15 changes: 6 additions & 9 deletions tests/DCPS/Compiler/char_literals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ 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")
Expand All @@ -22,14 +19,14 @@ set_target_properties(${idl} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${idl_dir}"
)

add_executable(opendds_compiler_char_literals_exe
"main.cpp"
)
set_target_properties(opendds_compiler_char_literals_exe PROPERTIES
# Executable
set(exe "${target_prefix}exe")
add_executable(${exe} "main.cpp")
set_target_properties(${exe} PROPERTIES
OUTPUT_NAME char-literals-cpp11
RUNTIME_OUTPUT_DIRECTORY "${dst}/cpp11"
)
target_link_libraries(opendds_compiler_char_literals_exe ${opendds_libs} ${idl} gtest)
target_link_libraries(${exe} OpenDDS::Dcps ${idl} gtest)

configure_file(run_test.pl . COPYONLY)
opendds_add_test(COMMAND perl run_test.pl cpp11 EXTRA_LIB_DIRS "${idl_dir}")
opendds_add_test(ARGS cpp11 EXTRA_LIB_DIRS "${idl_dir}")
16 changes: 5 additions & 11 deletions tests/DCPS/HelloWorld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ set(opendds_libs

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

# Subscriber
set(subscriber "${target_prefix}subscriber")
add_executable(${subscriber}
subscriber.cpp
)
add_executable(${subscriber} subscriber.cpp)
target_link_libraries(${subscriber} ${opendds_libs})
set_target_properties(${subscriber} PROPERTIES
OUTPUT_NAME subscriber
Expand All @@ -43,5 +37,5 @@ set_target_properties(${subscriber} PROPERTIES
# 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)
opendds_add_test(NAME info_repo)
opendds_add_test(NAME rtps ARGS ini=rtps.ini)
Original file line number Diff line number Diff line change
@@ -1,58 +1,38 @@
# Distributed under the OpenDDS License. See accompanying LICENSE
# file or http://www.opendds.org/license.html for details.
#
# This file is setup the way it is for testing purposes. For a cleaner example
# see DevGuideExamples/DCPS/Messenger/CMakeLists.txt
cmake_minimum_required(VERSION 3.8...3.27)
project(opendds_messenger_2 CXX)
project(opendds_tests_dcps_messenger CXX)
enable_testing()

set(OPENDDS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../..")
find_package(OpenDDS REQUIRED)
find_package(OpenDDS REQUIRED ownership_profile)
include(opendds_testing)

if(NOT OPENDDS_OWNERSHIP_PROFILE)
message(FATAL_ERROR "This test requires OpenDDS to be built with Ownership Profile enabled")
endif()

set(target_prefix "${PROJECT_NAME}_")
set(publisher "${target_prefix}publisher")
set(subscriber "${target_prefix}subscriber")
set(stack_subscriber "${target_prefix}stack_subscriber")
set(messenger "${target_prefix}messenger")

set(src "${CMAKE_CURRENT_SOURCE_DIR}/../../../DCPS/Messenger")
set(dst ${CMAKE_CURRENT_BINARY_DIR})
set(all_targets ${publisher} ${subscriber} ${stack_subscriber} ${messenger})

foreach(file
Messenger.idl subscriber.cpp stack_subscriber.cpp publisher.cpp Args.h
DataReaderListener.cpp DataReaderListener.h)
configure_file(${src}/${file} ${dst}/${file} COPYONLY)
endforeach()

# Messenger library
add_library(${messenger})
set_target_properties(${messenger}
PROPERTIES OUTPUT_NAME messenger
)
opendds_target_sources(${messenger} PUBLIC "${dst}/Messenger.idl")
opendds_target_sources(${messenger} PUBLIC Messenger.idl)
target_link_libraries(${messenger} PUBLIC OpenDDS::Dcps)

# Publisher
add_executable(${publisher}
"${dst}/publisher.cpp"
)
add_executable(${publisher} publisher.cpp)
set_target_properties(${publisher}
PROPERTIES OUTPUT_NAME publisher
)
target_link_libraries(${publisher} ${messenger} OpenDDS::OpenDDS OpenDDS::TestUtils)

# Subscriber with heap-allocated entities
add_executable(${subscriber}
"${dst}/subscriber.cpp"
"${dst}/DataReaderListener.h"
"${dst}/DataReaderListener.cpp"
subscriber.cpp
DataReaderListener.h
DataReaderListener.cpp
)
set_target_properties(${subscriber}
PROPERTIES OUTPUT_NAME subscriber
Expand All @@ -61,18 +41,18 @@ target_link_libraries(${subscriber} ${messenger} OpenDDS::OpenDDS)

# Subscriber with stack-allocated entities
add_executable(${stack_subscriber}
"${dst}/stack_subscriber.cpp"
"${dst}/DataReaderListener.h"
"${dst}/DataReaderListener.cpp"
stack_subscriber.cpp
DataReaderListener.h
DataReaderListener.cpp
)
set_target_properties(${stack_subscriber}
PROPERTIES OUTPUT_NAME stack_subscriber
)
target_link_libraries(${stack_subscriber} ${messenger} OpenDDS::OpenDDS)

# Testing
configure_file("${src}/run_test.pl" . COPYONLY)
set(OPENDDS_CONFIG_DIR "${src}")
configure_file(run_test.pl . COPYONLY)
set(OPENDDS_CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
opendds_add_test(NAME tcp)
opendds_add_test(NAME default_tcp ARGS default_tcp)
opendds_add_test(NAME thread_per ARGS thread_per)
Expand All @@ -88,6 +68,8 @@ opendds_add_test(NAME rtps_disc ARGS rtps_disc)
opendds_add_test(NAME rtps_disc_tcp ARGS rtps_disc_tcp)
opendds_add_test(NAME rtps_disc_tcp_thread_per ARGS rtps_disc_tcp thread_per)
opendds_add_test(NAME rtps_disc_tcp_udp ARGS rtps_disc_tcp_udp)
opendds_add_test(NAME rtps_disc_half_sec_pub ARGS rtps_disc_half_sec_pub)
opendds_add_test(NAME rtps_disc_half_sec_sub ARGS rtps_disc_half_sec_sub)
opendds_add_test(NAME rtps_disc_sec ARGS rtps_disc_sec)
if(OPENDDS_SECURITY)
opendds_add_test(NAME rtps_disc_half_sec_pub ARGS rtps_disc_half_sec_pub)
opendds_add_test(NAME rtps_disc_half_sec_sub ARGS rtps_disc_half_sec_sub)
opendds_add_test(NAME rtps_disc_sec ARGS rtps_disc_sec)
endif()
29 changes: 19 additions & 10 deletions tests/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_cmake_tests_root_project)
project(opendds_tests_cmake)
enable_testing()

find_package(OpenDDS REQUIRED)

configure_file("CTestCustom.cmake" "." COPYONLY)
if(NOT OPENDDS_IS_BEING_BUILT)
configure_file("CTestCustom.cmake" "." COPYONLY)

add_subdirectory(
"../../DevGuideExamples/DCPS/Messenger"
"${CMAKE_CURRENT_SOURCE_DIR}/../../DevGuideExamples/DCPS/Messenger/build")

if(OPENDDS_QT AND OPENDDS_CXX11)
add_subdirectory(
"../../examples/DCPS/ishapes"
"${CMAKE_CURRENT_SOURCE_DIR}/../../examples/DCPS/ishapes/build")
"../../DevGuideExamples/DCPS/Messenger"
"${CMAKE_CURRENT_SOURCE_DIR}/../../DevGuideExamples/DCPS/Messenger/build")

if(OPENDDS_QT AND OPENDDS_CXX11)
add_subdirectory(
"../../examples/DCPS/ishapes"
"${CMAKE_CURRENT_SOURCE_DIR}/../../examples/DCPS/ishapes/build")
endif()

add_subdirectory(install)

if(OPENDDS_OWNERSHIP_PROFILE)
add_subdirectory("../DCPS/Messenger" "${CMAKE_CURRENT_SOURCE_DIR}/../DCPS/Messenger/build")
endif()
endif()

if(NOT ${CMAKE_VERSION} VERSION_LESS "3.8.2")
if(OPENDDS_OWNERSHIP_PROFILE)
add_subdirectory(Messenger)
# TODO: This test always builds shared libraries and linker complains about
# ACE/TAO libs lacking -fPIC when ACE is static.
if(NOT OPENDDS_STATIC)
add_subdirectory(generated_global)
endif()
Expand All @@ -32,4 +42,3 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS "3.8.2")
endif()

add_subdirectory(include_subdir)
add_subdirectory(install)
2 changes: 1 addition & 1 deletion tests/cmake/Messenger/C++11_Messenger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ target_link_libraries(${subscriber} ${opendds_libs} ${idl})

# run_test.pl
configure_file("${src}/run_test.pl" "." COPYONLY)
opendds_add_test(COMMAND perl run_test.pl EXTRA_LIB_DIRS "${idl_dir}")
opendds_add_test(EXTRA_LIB_DIRS "${idl_dir}")
1 change: 0 additions & 1 deletion tests/cmake/Messenger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.3...3.27)
project(opendds_messenger_tests)

add_subdirectory(Messenger_1)
add_subdirectory(Messenger_2)
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio 10.*")
add_subdirectory(Messenger_Space)
endif()
Expand Down
2 changes: 1 addition & 1 deletion tests/cmake/Messenger/Messenger_1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ endforeach()

# Testing
configure_file("${src}/run_test.pl" . COPYONLY)
opendds_add_test(COMMAND perl run_test.pl)
opendds_add_test()
5 changes: 2 additions & 3 deletions tests/cmake/Nested_IDL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ project(opendds_nested_idl CXX)
enable_testing()

find_package(OpenDDS REQUIRED)
include(opendds_testing)

set(target_prefix "${PROJECT_NAME}_")

Expand Down Expand Up @@ -48,8 +49,6 @@ target_link_libraries(${ecu_exe} OpenDDS::Dcps ${ecu_lib})

# Testing
configure_file("run_test.pl" "." COPYONLY)
add_test(NAME "${target_prefix}test"
COMMAND perl run_test.pl $<$<BOOL:$<CONFIG>>:-ExeSubDir> $<CONFIG>
)
opendds_add_test()

_opendds_restore_cache()
6 changes: 1 addition & 5 deletions tests/cmake/ace_tao_only/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ add_executable(${client} ${client_files})
set_target_properties(${client} PROPERTIES OUTPUT_NAME MessengerClient)
target_link_libraries(${client} ${idl})

if(CMAKE_CONFIGURATION_TYPES)
opendds_add_test(COMMAND perl run_test.pl $<$<BOOL:$<CONFIG>>:-ExeSubDir> $<CONFIG>)
else()
opendds_add_test(COMMAND perl run_test.pl)
endif()
opendds_add_test()

_opendds_restore_cache()

0 comments on commit 6c8ac5e

Please sign in to comment.