Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Jul 19, 2022
1 parent b170a72 commit 8427a9d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 60 deletions.
27 changes: 25 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,29 @@ set (gtest_sources
TestFixture_TEST.cc
Util_TEST.cc
World_TEST.cc
ign_TEST.cc
comms/Broker_TEST.cc
comms/MsgManager_TEST.cc
network/NetworkConfig_TEST.cc
network/PeerTracker_TEST.cc
network/NetworkManager_TEST.cc
)

# ign_TEST and ModelCommandAPI_TEST are not supported with multi config
# CMake generators, see also cmd/CMakeLists.txt
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT GENERATOR_IS_MULTI_CONFIG)
list(APPEND gtest_sources ign_TEST.cc)
endif()


# Tests that require a valid display
set(tests_needing_display
ModelCommandAPI_TEST.cc
)

if(NOT GENERATOR_IS_MULTI_CONFIG)
list(APPEND tests_needing_display ModelCommandAPI_TEST.cc)
endif()

# Add systems that need a valid display here.
# \todo(anyone) Find a way to run these tests with a virtual display such Xvfb
# or Xdummy instead of skipping them
Expand Down Expand Up @@ -222,6 +232,19 @@ foreach(CMD_TEST
set_tests_properties(${CMD_TEST} PROPERTIES
ENVIRONMENT "${_env_vars}")

# On Windows there is no RPATH, so an alternative way for tests for finding .dll libraries
# in build directory in necessary. For regular tests, the trick is to place all libraries
# and executables in a common CMAKE_RUNTIME_OUTPUT_DIRECTORY, so that the .dll are found
# as they are in the same directory where the executable is loaded. For tests that are
# launched via ruby, this does not work, so we need to manually add CMAKE_RUNTIME_OUTPUT_DIRECTORY
# to the PATH. This is done via the ENVIRONMENT_MODIFICATION that is only available
# since CMake 3.22 . However, if an older CMake is used another trick to install the libraries
# beforehand
if (WIN32 AND CMAKE_VERSION STRGREATER "3.22")
set_tests_properties(${CMD_TEST} PROPERTIES
ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
endif()

endforeach()

add_subdirectory(cmd)
113 changes: 62 additions & 51 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Generate the ruby script.
# Note that the major version of the library is included in the name.
# Ex: cmdgazebo0.rb
set(cmd_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
set(cmd_script_configured "${cmd_script_generated}.configured")
set(cmd_script_name "cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
set(cmd_script_generated "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>_${cmd_script_name}")
set(cmd_script_configured "${CMAKE_CURRENT_BINARY_DIR}/${cmd_script_name}.configured")

# Set the library_location variable to the relative path to the library file
# within the install directory structure.
Expand All @@ -25,7 +26,7 @@ file(GENERATE
INPUT "${cmd_script_configured}")

# Install the ruby command line library in an unversioned location.
install(FILES ${cmd_script_generated} DESTINATION lib/ruby/ignition)
install(FILES ${cmd_script_generated} DESTINATION lib/ruby/ignition RENAME ${cmd_script_name})

set(ign_library_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}")

Expand All @@ -46,8 +47,9 @@ install( FILES
# Used for the installed model command version.
# Generate the ruby script that gets installed.
# Note that the major version of the library is included in the name.
set(cmd_model_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_configured "${cmd_model_script_generated}.configured")
set(cmd_model_script_name "cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_generated "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>_${cmd_model_script_name}")
set(cmd_model_script_configured "${CMAKE_CURRENT_BINARY_DIR}/${cmd_script_name}.configured")

configure_file(
"cmdmodel.rb.in"
Expand All @@ -57,7 +59,7 @@ file(GENERATE
OUTPUT "${cmd_model_script_generated}"
INPUT "${cmd_model_script_configured}")

install(FILES ${cmd_model_script_generated} DESTINATION lib/ruby/ignition)
install(FILES ${cmd_model_script_generated} DESTINATION lib/ruby/ignition RENAME ${cmd_model_script_name})

# Used for the installed version.
set(ign_model_ruby_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/ignition/cmdmodel${PROJECT_VERSION_MAJOR}")
Expand All @@ -74,55 +76,64 @@ install(FILES ${model_configured} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_IN
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
# Ex: cmdgazebo0.rb
set(cmd_script_generated_test "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
set(cmd_script_configured_test "${cmd_script_generated_test}.configured")

# Set the library_location variable to the relative path to the library file
# within the install directory structure.
set(library_location "$<TARGET_FILE:${ign_lib_target}>")

configure_file(
"cmd${IGN_DESIGNATION}.rb.in"
"${cmd_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_script_generated_test}"
INPUT "${cmd_script_configured_test}")

# Used only for internal testing.
set(ign_library_path
"${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}")

# Generate a configuration file for internal testing.
# Note that the major version of the library is included in the name.
# Ex: gazebo0.yaml
configure_file(
"${IGN_DESIGNATION}.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
# The logic is valid only for single-config CMake generators, so no script is
# generated if a multiple-config CMake geneator is used
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT GENERATOR_IS_MULTI_CONFIG)
set(cmd_script_generated_test "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb")
set(cmd_script_configured_test "${cmd_script_generated_test}.configured")

# Set the library_location variable to the relative path to the library file
# within the install directory structure.
set(library_location "$<TARGET_FILE:${ign_lib_target}>")

configure_file(
"cmd${IGN_DESIGNATION}.rb.in"
"${cmd_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_script_generated_test}"
INPUT "${cmd_script_configured_test}")

# Used only for internal testing.
set(ign_library_path
"${CMAKE_BINARY_DIR}/test/lib/ruby/ignition/cmd${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}")

# Generate a configuration file for internal testing.
# Note that the major version of the library is included in the name.
# Ex: gazebo0.yaml
configure_file(
"${IGN_DESIGNATION}.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/${IGN_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
endif()

#===============================================================================
# Generate the ruby script for internal testing.
# Note that the major version of the library is included in the name.
set(cmd_model_ruby_test_dir "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition")
set(cmd_model_script_generated_test "${cmd_model_ruby_test_dir}/cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_configured_test "${cmd_model_script_generated_test}.configured")

configure_file(
"cmdmodel.rb.in"
"${cmd_model_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_model_script_generated_test}"
INPUT "${cmd_model_script_configured_test}")

# Used for internal testing.
set(ign_model_ruby_path "${cmd_model_script_generated_test}")

configure_file(
"model.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/model${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
# The logic is valid only for single-config CMake generators, so no script is
# generated if a multiple-config CMake geneator is used
if(NOT GENERATOR_IS_MULTI_CONFIG)
set(cmd_model_ruby_test_dir "${CMAKE_BINARY_DIR}/test/lib/ruby/ignition")
set(cmd_model_script_generated_test "${cmd_model_ruby_test_dir}/cmdmodel${PROJECT_VERSION_MAJOR}.rb")
set(cmd_model_script_configured_test "${cmd_model_script_generated_test}.configured")

configure_file(
"cmdmodel.rb.in"
"${cmd_model_script_configured_test}"
@ONLY)

file(GENERATE
OUTPUT "${cmd_model_script_generated_test}"
INPUT "${cmd_model_script_configured_test}")

# Used for internal testing.
set(ign_model_ruby_path "${cmd_model_script_generated_test}")

configure_file(
"model.yaml.in"
"${CMAKE_BINARY_DIR}/test/conf/model${PROJECT_VERSION_MAJOR}.yaml" @ONLY)
endif()

#===============================================================================
# Bash completion
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/cmdgazebo.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ end

require 'optparse'
require 'erb'
require 'pathname'

# Constants.
LIBRARY_NAME = '@library_location@'
Expand Down Expand Up @@ -325,7 +326,8 @@ class Cmd
def execute(args)
options = parse(args)

if LIBRARY_NAME[0] == '/'
library_name_path = Pathname.new(LIBRARY_NAME)
if library_name_path.absolute?
# If the first character is a slash, we'll assume that we've been given an
# absolute path to the library. This is only used during test mode.
plugin = LIBRARY_NAME
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/cmdmodel.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ else
end

require 'optparse'
require 'pathname'

# Constants.
LIBRARY_NAME = '@library_location@'
Expand Down Expand Up @@ -157,7 +158,8 @@ class Cmd
options = parse(args)

# Read the plugin that handles the command.
if LIBRARY_NAME[0] == '/'
library_name_path = Pathname.new(LIBRARY_NAME)
if library_name_path.absolute?
# If the first character is a slash, we'll assume that we've been given an
# absolute path to the library. This is only used during test mode.
plugin = LIBRARY_NAME
Expand Down
13 changes: 8 additions & 5 deletions src/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ std::string customExecStr(std::string _cmd)
}

/////////////////////////////////////////////////
// See https://github.com/ignitionrobotics/ign-gazebo/issues/1175
TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(Server))
TEST(CmdLine, Server)
{
std::string cmd = kIgnCommand + " -r -v 4 --iterations 5 " +
std::string(PROJECT_SOURCE_PATH) + "/test/worlds/plugins.sdf";
Expand All @@ -75,6 +74,9 @@ TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(Server))
<< output;
}

// Disable on WIN32 as on Windows it is not support to prepend
// a command with the env variable to set
#ifndef _WIN32
// Use IGN_GAZEBO_RESOURCE_PATH instead of specifying the complete path
cmd = std::string("IGN_GAZEBO_RESOURCE_PATH=") +
PROJECT_SOURCE_PATH + "/test/worlds " + kIgnCommand +
Expand All @@ -89,10 +91,11 @@ TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(Server))
EXPECT_NE(output.find("iteration " + std::to_string(i)), std::string::npos)
<< output;
}
#endif
}

/////////////////////////////////////////////////
TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(CachedFuelWorld))
TEST(CmdLine, CachedFuelWorld)
{
std::string projectPath = std::string(PROJECT_SOURCE_PATH) + "/test/worlds";
ignition::common::setenv("IGN_FUEL_CACHE_PATH", projectPath.c_str());
Expand All @@ -106,7 +109,7 @@ TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(CachedFuelWorld))
}

/////////////////////////////////////////////////
TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(GazeboServer))
TEST(CmdLine, GazeboServer)
{
std::string cmd = kIgnCommand + " -r -v 4 --iterations 5 " +
std::string(PROJECT_SOURCE_PATH) + "/test/worlds/plugins.sdf";
Expand All @@ -123,7 +126,7 @@ TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(GazeboServer))
}

/////////////////////////////////////////////////
TEST(CmdLine, IGN_UTILS_TEST_DISABLED_ON_WIN32(Gazebo))
TEST(CmdLine, Gazebo)
{
std::string cmd = kIgnCommand + " -r -v 4 --iterations 5 " +
std::string(PROJECT_SOURCE_PATH) + "/test/worlds/plugins.sdf";
Expand Down

0 comments on commit 8427a9d

Please sign in to comment.