Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test refactoring part 2 #463

Merged
merged 10 commits into from
Jan 25, 2024
1 change: 1 addition & 0 deletions log/test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gz_build_tests(
ChirpParams
${PROJECT_LIBRARY_TARGET_NAME}-log
${EXTRA_TEST_LIB_DEPS}
test_config
INCLUDE_DIRS
${CMAKE_BINARY_DIR}/test/
)
Expand Down
3 changes: 2 additions & 1 deletion log/test/integration/playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#include <gz/utils/Subprocess.hh>

#include "ChirpParams.hh"
#include "test_config.hh"

#include "test_utils.hh"

static std::string partition;

Expand Down
2 changes: 1 addition & 1 deletion log/test/integration/recorder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <gz/utils/Environment.hh>
#include <gz/utils/ExtraTestMacros.hh>

#include "test_config.hh"
#include "test_utils.hh"

#include "ChirpParams.hh"

Expand Down
2 changes: 1 addition & 1 deletion src/CIface_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"
#include "test_utils.hh"

static int count;

Expand Down
10 changes: 1 addition & 9 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,10 @@ endif()
# Build the unit tests.
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}
TEST_LIST test_list
LIB_DEPS ${EXTRA_TEST_LIB_DEPS})
LIB_DEPS ${EXTRA_TEST_LIB_DEPS} test_config)

foreach(test ${test_list})

# Inform each test of its output directory so it knows where to call the
# auxiliary files from. Using a generator expression here is useful for
# multi-configuration generators, like Visual Studio.
target_compile_definitions(${test} PRIVATE
"GZ_TEST_LIBRARY_PATH=\"$<TARGET_FILE_DIR:${PROJECT_LIBRARY_TARGET_NAME}>\"")

set_property(TEST ${test} PROPERTY ENVIRONMENT "GZ_VERBOSE=1")

endforeach()

if(MSVC)
Expand Down
2 changes: 1 addition & 1 deletion src/Discovery_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "gz/utils/Environment.hh"
#include "gz/utils/ExtraTestMacros.hh"

#include "test_config.hh"
#include "test_utils.hh"

using namespace gz;
using namespace transport;
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "test_utils.hh"
#include "gtest/gtest.h"

using namespace gz;
Expand Down
1 change: 0 additions & 1 deletion src/NodeOptions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "gtest/gtest.h"

using namespace gz;
Expand Down
2 changes: 1 addition & 1 deletion src/Node_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <gz/utils/Environment.hh>

#include "gtest/gtest.h"
#include "test_config.hh"
#include "test_utils.hh"

using namespace gz;

Expand Down
21 changes: 3 additions & 18 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,15 @@ install(TARGETS ${service_executable} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/gz
# Build the unit tests.
gz_build_tests(TYPE UNIT SOURCES ${gtest_sources}
TEST_LIST test_list
LIB_DEPS ${EXTRA_TEST_LIB_DEPS})

foreach(test ${test_list})
target_link_libraries(${test} gz gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER})

# Inform each test of its output directory so it knows where to call the
# auxiliary files from. Using a generator expression here is useful for
# multi-configuration generators, like Visual Studio.
target_compile_definitions(${test} PRIVATE
"GZ_TEST_LIBRARY_PATH=\"$<TARGET_FILE_DIR:${PROJECT_LIBRARY_TARGET_NAME}>\""
"PROJECT_SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\""
"TWO_PROCS_PUBLISHER_EXE=\"$<TARGET_FILE:twoProcsPublisher_aux>\""
"TWO_PROCS_SRV_CALL_REPLIER_EXE=\"$<TARGET_FILE:twoProcsSrvCallReplier_aux>\""
"GZ_EXE=\"${HAVE_GZ_TOOLS}\""
)

endforeach()
LIB_DEPS ${EXTRA_TEST_LIB_DEPS} test_config gz gz-utils${GZ_UTILS_VER}::gz-utils${GZ_UTILS_VER})

if (TARGET UNIT_gz_TEST)

set_tests_properties(
UNIT_gz_TEST
PROPERTIES
ENVIRONMENT
"GZ_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>"
"GZ_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf/$<CONFIG>;LD_LIBRARY_PATH=\"$<TARGET_FILE_DIR:${PROJECT_LIBRARY_TARGET_NAME}>\":${LD_LIBRARY_PATH}"
)
endif()

Expand Down
39 changes: 14 additions & 25 deletions src/cmd/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,13 @@
#include "gtest/gtest.h"
#include "gz/transport/Node.hh"
#include "test_config.hh"
#include "test_utils.hh"

using namespace gz;

static std::string g_partition; // NOLINT(*)
static std::string g_topicCBStr; // NOLINT(*)

namespace
{
constexpr const char * kGzExe = GZ_EXE;
constexpr const char * kTwoProcsPublisherExe = TWO_PROCS_PUBLISHER_EXE;
constexpr const char * kTwoProcsSrvCallReplierExe =
TWO_PROCS_SRV_CALL_REPLIER_EXE;
constexpr const char * kGzVersion = GZ_VERSION_FULL;
} // namespace

//////////////////////////////////////////////////
/// \brief Provide a service.
bool srvEcho(const msgs::Int32 &_req, msgs::Int32 &_rep)
Expand All @@ -71,7 +63,7 @@ struct ProcessOutput
//////////////////////////////////////////////////
ProcessOutput custom_exec_str(const std::vector<std::string> &_args)
{
auto fullArgs = std::vector<std::string>{kGzExe};
auto fullArgs = std::vector<std::string>{test_aux::kGzExe};
std::copy(std::begin(_args), std::end(_args), std::back_inserter(fullArgs));
fullArgs.emplace_back("--force-version");
fullArgs.emplace_back(kGzVersion);
Expand Down Expand Up @@ -103,7 +95,8 @@ exec_with_retry(const std::vector<std::string> &_args,
/// \brief Check 'gz topic -l' running the advertiser on a different process.
TEST(gzTest, GZ_UTILS_TEST_DISABLED_ON_MAC(TopicList))
{
auto proc = gz::utils::Subprocess({kTwoProcsPublisherExe, g_partition});
auto proc = gz::utils::Subprocess({
test_aux::kTwoProcsPublisher, g_partition});

auto output = exec_with_retry({"topic", "-l"},
[](auto procOut){
Expand All @@ -118,7 +111,8 @@ TEST(gzTest, GZ_UTILS_TEST_DISABLED_ON_MAC(TopicList))
TEST(gzTest, TopicInfo)
{
// Launch a new publisher process that advertises a topic.
auto proc = gz::utils::Subprocess({kTwoProcsPublisherExe, g_partition});
auto proc = gz::utils::Subprocess({
test_aux::kTwoProcsPublisher, g_partition});

auto output = exec_with_retry({"topic", "-t", "/foo", "-i"},
[](auto procOut){
Expand All @@ -138,7 +132,8 @@ TEST(gzTest, TopicInfo)
TEST(gzTest, ServiceList)
{
// Launch a new responser process that advertises a service.
auto proc = gz::utils::Subprocess({kTwoProcsSrvCallReplierExe, g_partition});
auto proc = gz::utils::Subprocess({
test_aux::kTwoProcsSrvCallReplier, g_partition});

auto output = exec_with_retry({"service", "-l"},
[](auto procOut){
Expand All @@ -153,7 +148,8 @@ TEST(gzTest, ServiceList)
TEST(gzTest, ServiceInfo)
{
// Launch a new responser process that advertises a service.
auto proc = gz::utils::Subprocess({kTwoProcsSrvCallReplierExe, g_partition});
auto proc = gz::utils::Subprocess(
{test_aux::kTwoProcsSrvCallReplier, g_partition});

auto output = exec_with_retry({"service", "-s", "/foo", "-i"},
[](auto procOut){
Expand Down Expand Up @@ -320,7 +316,8 @@ TEST(gzTest, ServiceRequest)
TEST(gzTest, TopicEcho)
{
// Launch a new publisher process that advertises a topic.
auto proc = gz::utils::Subprocess({kTwoProcsPublisherExe, g_partition});
auto proc = gz::utils::Subprocess(
{test_aux::kTwoProcsPublisher, g_partition});

auto output = custom_exec_str(
{"topic", "-e", "-t", "/foo", "-d", "1.5"});
Expand All @@ -336,7 +333,8 @@ TEST(gzTest, TopicEcho)
TEST(gzTest, TopicEchoNum)
{
// Launch a new publisher process that advertises a topic.
auto proc = gz::utils::Subprocess({kTwoProcsPublisherExe, g_partition});
auto proc = gz::utils::Subprocess(
{test_aux::kTwoProcsPublisher, g_partition});

auto output = custom_exec_str(
{"topic", "-e", "-t", "/foo", "-n", "2"});
Expand Down Expand Up @@ -372,15 +370,6 @@ int main(int argc, char **argv)
// Set the partition name for this process.
gz::utils::setenv("GZ_PARTITION", g_partition);

// Make sure that we load the library recently built and not the one installed
// in your system.
// Save the current value of LD_LIBRARY_PATH.
std::string value;
gz::utils::env("LD_LIBRARY_PATH", value);
// Add the directory where Gazebo Transport has been built.
value = std::string(GZ_TEST_LIBRARY_PATH) + ":" + value;
gz::utils::setenv("LD_LIBRARY_PATH", value);

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
9 changes: 1 addition & 8 deletions src/cmd/gz_src_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,14 @@
#include <string>
#include <iostream>
#include <sstream>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/msgs/int32.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include "gz.hh"
#include "gz/transport/Node.hh"

#include <gz/utils/Environment.hh>

#include "test_config.hh"
#include "test_utils.hh"
#include "gtest/gtest.h"

using namespace gz;
Expand Down
30 changes: 26 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
configure_file (test_config.hh.in ${PROJECT_BINARY_DIR}/include/test_config.hh)
include_directories (
${PROJECT_BINARY_DIR}/include
)

add_subdirectory(gtest_vendor)
add_subdirectory(integration)
add_subdirectory(performance)
add_subdirectory(regression)

configure_file (test_config.hh.in ${PROJECT_BINARY_DIR}/include/test_config.hh)

add_library(test_config INTERFACE)
target_include_directories(test_config INTERFACE
${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/test
)

target_compile_definitions(test_config INTERFACE
# Location of the "gz" command
"GZ_EXE=\"${HAVE_GZ_TOOLS}\""
# Auxillary executables for test
"AUTH_PUB_SUB_SUBSCRIBER_INVALID_EXE=\"$<TARGET_FILE:authPubSubSubscriberInvalid_aux>\""
"FAST_PUB_EXE=\"$<TARGET_FILE:fastPub_aux>\""
"PUB_EXE=\"$<TARGET_FILE:pub_aux>\""
"PUB_THROTTLED_EXE=\"$<TARGET_FILE:pub_aux_throttled>\""
"SCOPED_TOPIC_SUBSCRIBER_EXE=\"$<TARGET_FILE:scopedTopicSubscriber_aux>\""
"TWO_PROCS_PUBLISHER_EXE=\"$<TARGET_FILE:twoProcsPublisher_aux>\""
"TWO_PROCS_PUB_SUB_SUBSCRIBER_EXE=\"$<TARGET_FILE:twoProcsPubSubSubscriber_aux>\""
"TWO_PROCS_SRV_CALL_REPLIER_EXE=\"$<TARGET_FILE:twoProcsSrvCallReplier_aux>\""
"TWO_PROCS_SRV_CALL_REPLIER_INC_EXE=\"$<TARGET_FILE:twoProcsSrvCallReplierInc_aux>\""
"TWO_PROCS_SRV_CALL_WITHOUT_INPUT_REPLIER_EXE=\"$<TARGET_FILE:twoProcsSrvCallWithoutInputReplier_aux>\""
"TWO_PROCS_SRV_CALL_WITHOUT_INPUT_REPLIER_INC_EXE=\"$<TARGET_FILE:twoProcsSrvCallWithoutInputReplierInc_aux>\""
"TWO_PROCS_SRV_CALL_WITHOUT_OUTPUT_REPLIER_EXE=\"$<TARGET_FILE:twoProcsSrvCallWithoutOutputReplier_aux>\""
"TWO_PROCS_SRV_CALL_WITHOUT_OUTPUT_REPLIER_INC_EXE=\"$<TARGET_FILE:twoProcsSrvCallWithoutOutputReplierInc_aux>\"")
24 changes: 2 additions & 22 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ endif()

gz_build_tests(TYPE INTEGRATION SOURCES ${tests}
TEST_LIST test_list
LIB_DEPS ${EXTRA_TEST_LIB_DEPS})
LIB_DEPS ${EXTRA_TEST_LIB_DEPS} test_config)

set(auxiliary_files
authPubSubSubscriberInvalid_aux
Expand All @@ -46,7 +46,7 @@ set(auxiliary_files

# Build the auxiliary files.
foreach(AUX_EXECUTABLE ${auxiliary_files})
gz_add_executable(${AUX_EXECUTABLE} ${AUX_EXECUTABLE}.cc)
gz_add_executable(${AUX_EXECUTABLE} aux/${AUX_EXECUTABLE}.cc)

# Link the libraries that we always need.
target_link_libraries(${AUX_EXECUTABLE}
Expand All @@ -56,23 +56,3 @@ foreach(AUX_EXECUTABLE ${auxiliary_files})
${EXTRA_TEST_LIB_DEPS}
)
endforeach(AUX_EXECUTABLE)


foreach(test ${test_list})
target_compile_definitions(${test} PRIVATE
"AUTH_PUB_SUB_SUBSCRIBER_INVALID_EXE=\"$<TARGET_FILE:authPubSubSubscriberInvalid_aux>\""
"FAST_PUB_EXE=\"$<TARGET_FILE:fastPub_aux>\""
"PUB_EXE=\"$<TARGET_FILE:pub_aux>\""
"PUB_THROTTLED_EXE=\"$<TARGET_FILE:pub_aux_throttled>\""
"SCOPED_TOPIC_SUBSCRIBER_EXE=\"$<TARGET_FILE:scopedTopicSubscriber_aux>\""

"TWO_PROCS_PUBLISHER_EXE=\"$<TARGET_FILE:twoProcsPublisher_aux>\""
"TWO_PROCS_PUB_SUB_SUBSCRIBER_EXE=\"$<TARGET_FILE:twoProcsPubSubSubscriber_aux>\""

"TWO_PROCS_SRV_CALL_REPLIER_EXE=\"$<TARGET_FILE:twoProcsSrvCallReplier_aux>\""
"TWO_PROCS_SRV_CALL_REPLIER_INC_EXE=\"$<TARGET_FILE:twoProcsSrvCallReplierInc_aux>\""
"TWO_PROCS_SRV_CALL_WITHOUT_INPUT_REPLIER_EXE=\"$<TARGET_FILE:twoProcsSrvCallWithoutInputReplier_aux>\""
"TWO_PROCS_SRV_CALL_WITHOUT_INPUT_REPLIER_INC_EXE=\"$<TARGET_FILE:twoProcsSrvCallWithoutInputReplierInc_aux>\""
"TWO_PROCS_SRV_CALL_WITHOUT_OUTPUT_REPLIER_EXE=\"$<TARGET_FILE:twoProcsSrvCallWithoutOutputReplier_aux>\""
"TWO_PROCS_SRV_CALL_WITHOUT_OUTPUT_REPLIER_INC_EXE=\"$<TARGET_FILE:twoProcsSrvCallWithoutOutputReplierInc_aux>\"")
endforeach()
13 changes: 2 additions & 11 deletions test/integration/authPubSub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@

#include <chrono>
#include <string>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
#include <gz/msgs/int32.pb.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include "gtest/gtest.h"
#include "gz/transport/Node.hh"
Expand All @@ -34,15 +27,13 @@
#include <gz/utils/Subprocess.hh>

#include "test_config.hh"
#include "test_utils.hh"

using namespace gz;

static std::string partition; // NOLINT(*)
static std::string g_topic = "/foo"; // NOLINT(*)

static constexpr const char * kAuthPubSubSubscriberInvalid =
AUTH_PUB_SUB_SUBSCRIBER_INVALID_EXE;

//////////////////////////////////////////////////
TEST(authPubSub, InvalidAuth)
{
Expand All @@ -58,7 +49,7 @@ TEST(authPubSub, InvalidAuth)
EXPECT_FALSE(pub.HasConnections());

auto pi = gz::utils::Subprocess(
{kAuthPubSubSubscriberInvalid, partition, "bad", "invalid"});
{test_aux::kAuthPubSubSubscriberInvalid, partition, "bad", "invalid"});

msgs::Int32 msg;
msg.set_data(1);
Expand Down
File renamed without changes.
File renamed without changes.
Loading