Skip to content

Commit

Permalink
Add package.xml, fix gz sdf tests on Windows (#1374)
Browse files Browse the repository at this point in the history
The `gz sdf` tests are fixed by 
* fixing dll path issue with Ruby on windows
* Setting home path

---------

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
  • Loading branch information
azeey authored Apr 19, 2024
1 parent 1c0bc30 commit 3e93e68
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 37 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/package_xml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Validate package.xml

on:
pull_request:

jobs:
package-xml:
runs-on: ubuntu-latest
name: Validate package.xml
steps:
- uses: gazebo-tooling/action-gz-ci/validate_package_xml@jammy
32 changes: 32 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<package format="2">
<name>sdformat14</name>
<version>14.1.1</version>
<description>SDFormat is an XML file format that describes environments, objects, and robots
in a manner suitable for robotic applications</description>

<maintainer email="addisu@openrobotics.org">Addisu Z. Taddese</maintainer>
<maintainer email="scpeters@openrobotics.org">Steve Peters</maintainer>

<license>Apache License 2.0</license>

<url type="website">https://github.com/gazebosim/sdformat</url>

<buildtool_depend>cmake</buildtool_depend>
<build_depend>gz-cmake3</build_depend>
<depend>gz-math7</depend>
<depend>gz-utils2</depend>
<depend>tinyxml2</depend>
<depend>liburdfdom-dev</depend>
<depend>pybind11-dev</depend>

<exec_depend>gz-tools2</exec_depend>

<test_depend>libxml2-utils</test_depend>
<test_depend>python3-psutil</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>cmake</build_type>
</export>
</package>
6 changes: 0 additions & 6 deletions src/Console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ using namespace sdf;
static std::shared_ptr<Console> myself;
static std::mutex g_instance_mutex;

/// \todo Output disabled for windows, to allow tests to pass. We should
/// disable output just for tests on windows.
#ifndef _WIN32
static bool g_quiet = false;
#else
static bool g_quiet = true;
#endif

static Console::ConsoleStream g_NullStream(nullptr);

Expand Down
8 changes: 7 additions & 1 deletion src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ set(cmd_script_configured "${CMAKE_CURRENT_BINARY_DIR}/cmd${PROJECT_NAME}.rb.con

# Set the library_location variable to the relative path to the library file
# within the install directory structure.
set(library_location "../../../${CMAKE_INSTALL_LIBDIR}/$<TARGET_FILE_NAME:${PROJECT_NAME}>")
if (MSVC)
set(library_location_prefix "${CMAKE_INSTALL_BINDIR}")
else()
set(library_location_prefix "${CMAKE_INSTALL_LIBDIR}")
endif()

set(library_location "../../../${library_location_prefix}/$<TARGET_FILE_NAME:${PROJECT_NAME}>")

configure_file(
"cmd${PROJECT_NAME_NO_VERSION_LOWER}.rb.in"
Expand Down
16 changes: 12 additions & 4 deletions src/cmd/cmdsdformat.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ else
end

require 'optparse'
require 'pathname'


# Constants.
LIBRARY_NAME = '@library_location@'
Expand Down Expand Up @@ -174,9 +176,7 @@ class Cmd
# puts options

# Read the plugin that handles the command.
if LIBRARY_NAME[0] == '/'
# 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.
if Pathname.new(LIBRARY_NAME).absolute?
plugin = LIBRARY_NAME
else
# We're assuming that the library path is relative to the current
Expand All @@ -185,10 +185,18 @@ class Cmd
end
conf_version = LIBRARY_VERSION

if defined? RubyInstaller
# RubyInstaller does not search for dlls in PATH or the directory that tests are running from,
# so we'll add the parent directory of the plugin to the search path.
# https://github.com/oneclick/rubyinstaller2/wiki/For-gem-developers#-dll-loading
RubyInstaller::Runtime.add_dll_directory(File.dirname(plugin))
end

begin
Importer.dlload plugin
rescue DLError
rescue DLError => error
puts "Library error: [#{plugin}] not found."
puts "DLError: #{error.message}"
exit(-1)
end

Expand Down
58 changes: 32 additions & 26 deletions src/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::string custom_exec_str(std::string _cmd)
}

/////////////////////////////////////////////////
TEST(checkUnrecognizedElements, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(checkUnrecognizedElements, SDF)
{
// Check an SDFormat file with unrecognized elements
{
Expand Down Expand Up @@ -120,7 +120,7 @@ TEST(checkUnrecognizedElements, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(check, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(check, SDF)
{
// Check a good SDF file
{
Expand Down Expand Up @@ -1011,7 +1011,7 @@ TEST(check, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(check_shapes_sdf, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(check_shapes_sdf, SDF)
{
{
const auto path =
Expand All @@ -1035,7 +1035,7 @@ TEST(check_shapes_sdf, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(check_model_sdf, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(check_model_sdf, SDF)
{
// Check a good SDF file by passing the absolute path
{
Expand All @@ -1062,7 +1062,7 @@ TEST(check_model_sdf, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(describe, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(describe, SDF)
{
// Get the description
std::string output =
Expand All @@ -1074,7 +1074,7 @@ TEST(describe, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(print, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print, SDF)
{
// Check a good SDF file
{
Expand Down Expand Up @@ -1103,7 +1103,7 @@ TEST(print, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(print_rotations_in_degrees, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_rotations_in_degrees, SDF)
{
const std::string path =
sdf::testing::TestFile("sdf", "rotations_in_degrees.sdf");
Expand Down Expand Up @@ -1171,7 +1171,7 @@ TEST(print_rotations_in_degrees, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(print_rotations_in_radians, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_rotations_in_radians, SDF)
{
const std::string path =
sdf::testing::TestFile("sdf", "rotations_in_radians.sdf");
Expand Down Expand Up @@ -1239,7 +1239,7 @@ TEST(print_rotations_in_radians, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(print_rotations_in_quaternions, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_rotations_in_quaternions, SDF)
{
const auto path = sdf::testing::TestFile(
"sdf", "rotations_in_quaternions.sdf");
Expand Down Expand Up @@ -1308,7 +1308,7 @@ TEST(print_rotations_in_quaternions, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(print_includes_rotations_in_degrees, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_includes_rotations_in_degrees, SDF)
{
// Set SDF_PATH so that included models can be found
gz::utils::setenv(
Expand Down Expand Up @@ -1379,7 +1379,7 @@ TEST(print_includes_rotations_in_degrees, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(print_includes_rotations_in_radians, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_includes_rotations_in_radians, SDF)
{
// Set SDF_PATH so that included models can be found
gz::utils::setenv(
Expand Down Expand Up @@ -1450,8 +1450,7 @@ TEST(print_includes_rotations_in_radians, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(print_includes_rotations_in_quaternions,
GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_includes_rotations_in_quaternions, SDF)
{
// Set SDF_PATH so that included models can be found
gz::utils::setenv(
Expand Down Expand Up @@ -1523,8 +1522,7 @@ TEST(print_includes_rotations_in_quaternions,
}

/////////////////////////////////////////////////
TEST(print_rotations_in_unnormalized_degrees,
GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_rotations_in_unnormalized_degrees, SDF)
{
const std::string path =
sdf::testing::TestFile("sdf", "rotations_in_unnormalized_degrees.sdf");
Expand Down Expand Up @@ -1595,8 +1593,7 @@ TEST(print_rotations_in_unnormalized_degrees,
}

/////////////////////////////////////////////////
TEST(print_rotations_in_unnormalized_radians,
GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_rotations_in_unnormalized_radians, SDF)
{
const std::string path =
sdf::testing::TestFile("sdf", "rotations_in_unnormalized_radians.sdf");
Expand Down Expand Up @@ -1664,7 +1661,7 @@ TEST(print_rotations_in_unnormalized_radians,
}

/////////////////////////////////////////////////
TEST(shuffled_cmd_flags, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(shuffled_cmd_flags, SDF)
{
const std::string path =
sdf::testing::TestFile("sdf", "rotations_in_unnormalized_radians.sdf");
Expand Down Expand Up @@ -1713,8 +1710,7 @@ TEST(shuffled_cmd_flags, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
}

/////////////////////////////////////////////////
TEST(print_snap_to_degrees_tolerance_too_high,
GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(print_snap_to_degrees_tolerance_too_high, SDF)
{
const std::string path = sdf::testing::TestFile(
"sdf",
Expand All @@ -1731,7 +1727,7 @@ TEST(print_snap_to_degrees_tolerance_too_high,
}

/////////////////////////////////////////////////
TEST(GraphCmd, GZ_UTILS_TEST_DISABLED_ON_WIN32(WorldPoseRelativeTo))
TEST(GraphCmd, WorldPoseRelativeTo)
{
// world pose relative_to graph
const std::string path =
Expand Down Expand Up @@ -1780,7 +1776,7 @@ TEST(GraphCmd, GZ_UTILS_TEST_DISABLED_ON_WIN32(WorldPoseRelativeTo))
}

/////////////////////////////////////////////////
TEST(GraphCmd, GZ_UTILS_TEST_DISABLED_ON_WIN32(ModelPoseRelativeTo))
TEST(GraphCmd, ModelPoseRelativeTo)
{
const auto path =
sdf::testing::TestFile("sdf", "model_relative_to_nested_reference.sdf");
Expand Down Expand Up @@ -1857,7 +1853,7 @@ TEST(GraphCmd, GZ_UTILS_TEST_DISABLED_ON_WIN32(ModelPoseRelativeTo))
}

/////////////////////////////////////////////////
TEST(GraphCmd, GZ_UTILS_TEST_DISABLED_ON_WIN32(WorldFrameAttachedTo))
TEST(GraphCmd, WorldFrameAttachedTo)
{
const auto path =
sdf::testing::TestFile("sdf", "world_nested_frame_attached_to.sdf");
Expand Down Expand Up @@ -1903,7 +1899,7 @@ TEST(GraphCmd, GZ_UTILS_TEST_DISABLED_ON_WIN32(WorldFrameAttachedTo))
}

/////////////////////////////////////////////////
TEST(GraphCmd, GZ_UTILS_TEST_DISABLED_ON_WIN32(ModelFrameAttachedTo))
TEST(GraphCmd, ModelFrameAttachedTo)
{
const auto path =
sdf::testing::TestFile("sdf", "model_nested_frame_attached_to.sdf");
Expand Down Expand Up @@ -1955,7 +1951,7 @@ TEST(GraphCmd, GZ_UTILS_TEST_DISABLED_ON_WIN32(ModelFrameAttachedTo))
// Disable on arm
#if !defined __ARM_ARCH
/////////////////////////////////////////////////
TEST(inertial_stats, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
TEST(inertial_stats, SDF)
{
std::string expectedOutput =
"Inertial statistics for model: test_model\n"
Expand Down Expand Up @@ -2043,7 +2039,7 @@ TEST(inertial_stats, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))

//////////////////////////////////////////////////
/// \brief Check help message and bash completion script for consistent flags
TEST(HelpVsCompletionFlags, SDF)
TEST(HelpVsCompletionFlags, GZ_UTILS_TEST_DISABLED_ON_WIN32(SDF))
{
// Flags in help message
std::string helpOutput = custom_exec_str(GzCommand() + " sdf --help");
Expand Down Expand Up @@ -2098,6 +2094,16 @@ int main(int argc, char **argv)
gz::utils::setenv("LD_LIBRARY_PATH", testLibraryPath);
#endif

// temporarily set HOME
std::string homeDir;
sdf::testing::TestTmpPath(homeDir);

#ifdef _WIN32
gz::utils::setenv("HOMEPATH", homeDir);
#else
gz::utils::setenv("HOME", homeDir);
#endif

::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 3e93e68

Please sign in to comment.