Skip to content

Commit

Permalink
Merge pull request #168 from robotology/fix/conda-ci-failure
Browse files Browse the repository at this point in the history
Use absolute paths to reference models in unit tests
  • Loading branch information
xela-95 authored May 13, 2024
2 parents 870b1d9 + 076727a commit b3577c7
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 47 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/conda-forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ jobs:
- name: Print used environment
shell: bash -l {0}
run: |
micromamba list
conda list --explicit
env
- name: Configure
shell: bash -l {0}
run: |
mkdir -p build
cd build
cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DBUILD_TESTING:BOOL=ON ..
- name: Build
shell: bash -l {0}
run: |
cd build
cmake --build . --config ${{ matrix.build_type }}
cmake --build . --config ${{ matrix.build_type }}
- name: Test_ubuntu
if: contains(matrix.os, 'ubuntu')
shell: bash -l {0}
run: |
cd build
ctest -E "^LaserTest|^CameraTest|^ImuTest" --repeat until-pass:5 --output-on-failure -C ${{ matrix.build_type }} .
ctest -E "^LaserTest|^CameraTest|^ImuTest" --repeat until-pass:5 --output-on-failure -C ${{ matrix.build_type }} .
- name: Test_macos
if: contains(matrix.os, 'macos')
shell: bash -l {0}
Expand Down
2 changes: 2 additions & 0 deletions tests/camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ list(APPEND _env_vars "LIBGL_ALWAYS_SOFTWARE=1")

set_tests_properties(CameraTest PROPERTIES
ENVIRONMENT "${_env_vars}")

target_compile_definitions(CameraTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
23 changes: 19 additions & 4 deletions tests/camera/CameraTest.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#include <gtest/gtest.h>

#include <chrono>
#include <cstddef>
#include <filesystem>
#include <thread>

#include <gz/common/Console.hh>
#include <gz/sim/TestFixture.hh>

#include <yarp/dev/FrameGrabberInterfaces.h>
#include <yarp/dev/IFrameGrabberImage.h>
#include <yarp/dev/PolyDriver.h>
#include <yarp/os/Network.h>
#include <yarp/os/Property.h>
#include <yarp/sig/Image.h>

TEST(CameraTest, PluginTest)
{
Expand All @@ -12,7 +23,8 @@ TEST(CameraTest, PluginTest)
gz::common::Console::SetVerbosity(4);

// Instantiate test fixture
gz::sim::TestFixture fixture("../../../tests/camera/model.sdf");
auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf";
gz::sim::TestFixture fixture(modelPath.string());

int iterations = 1000;

Expand Down Expand Up @@ -80,7 +92,8 @@ TEST(CameraTest, HorizontalFlip)
gz::common::Console::SetVerbosity(4);

// Instantiate test fixture
gz::sim::TestFixture fixture("../../../tests/camera/model_hor_flip.sdf");
auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_hor_flip.sdf";
gz::sim::TestFixture fixture(modelPath.string());

int iterations = 1000;
fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false);
Expand Down Expand Up @@ -147,7 +160,8 @@ TEST(CameraTest, VerticalFlip)
gz::common::Console::SetVerbosity(4);

// Instantiate test fixture
gz::sim::TestFixture fixture("../../../tests/camera/model_ver_flip.sdf");
auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_ver_flip.sdf";
gz::sim::TestFixture fixture(modelPath.string());

int iterations = 1000;
fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false);
Expand Down Expand Up @@ -214,7 +228,8 @@ TEST(CameraTest, HorizontalVerticalFlip)
gz::common::Console::SetVerbosity(4);

// Instantiate test fixture
gz::sim::TestFixture fixture("../../../tests/camera/model_hor_ver_flip.sdf");
auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_hor_ver_flip.sdf";
gz::sim::TestFixture fixture(modelPath.string());

int iterations = 1000;
fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false);
Expand Down
2 changes: 2 additions & 0 deletions tests/clock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ list(APPEND _env_vars "GZ_SIM_SYSTEM_PLUGIN_PATH=$<TARGET_FILE_DIR:gz-sim-yarp-c

set_tests_properties(ClockTest PROPERTIES
ENVIRONMENT "${_env_vars}")

target_compile_definitions(ClockTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
11 changes: 10 additions & 1 deletion tests/clock/ClockTest.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include <gtest/gtest.h>

#include <chrono>
#include <filesystem>
#include <thread>

#include <gz/common/Console.hh>
#include <gz/sim/TestFixture.hh>

#include <yarp/os/Bottle.h>
#include <yarp/os/BufferedPort.h>
#include <yarp/os/Network.h>
Expand All @@ -11,7 +18,9 @@ TEST(ClockTest, GetSimulationTimeFromClockPort)
// Maximum verbosity helps with debugging
gz::common::Console::SetVerbosity(4);
// Instantiate test fixture
gz::sim::TestFixture fixture("../../../tests/clock/model.sdf");
auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf";
gz::sim::TestFixture fixture(modelPath.string());

const int iterations = 1000;
const int deltaTns = 1e6; // 1ms
const int tolerance = 1e6; // 1ms
Expand Down
4 changes: 4 additions & 0 deletions tests/commons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ set_tests_properties(ConfigurationParsingFromStringTest PROPERTIES

set_tests_properties(ConcurrentInstancesTest PROPERTIES
ENVIRONMENT "${_env_vars}")

target_compile_definitions(ConfigurationParsingFromFileTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_compile_definitions(ConfigurationParsingFromStringTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_compile_definitions(ConcurrentInstancesTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
9 changes: 5 additions & 4 deletions tests/commons/ConcurrentInstancesTest.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>

#include <chrono>
#include <filesystem>
#include <iostream>
#include <ostream>
#include <thread>
Expand All @@ -12,10 +13,10 @@ TEST(ConcurrentInstancesTest, StartConcurrentGazeboInstancesOfDifferentModels)
{
auto plannedIterations = 1'000;

gz::sim::TestFixture fixture1("../../../tests/commons/"
"dummy_sphere.sdf");
gz::sim::TestFixture fixture2("../../../tests/commons/"
"dummy_box.sdf");
gz::sim::TestFixture fixture1(
(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "dummy_sphere.sdf").string());
gz::sim::TestFixture fixture2(
(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "dummy_box.sdf").string());
gz::common::Console::SetVerbosity(4);

fixture1.Finalize();
Expand Down
9 changes: 5 additions & 4 deletions tests/commons/ConfigurationParsingFromFileTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <gz/sim/TestFixture.hh>
#include <sdf/Element.hh>

#include <filesystem>
#include <iostream>
#include <memory>
#include <string>
Expand All @@ -26,14 +27,14 @@ TEST(ConfigurationParsingTest, LoadPluginsWithYarpConfigurationFile)
{
using namespace std::chrono_literals;

std::string modelSdfName = "model_configuration_file.sdf";
std::string sdfPath = std::string("../../../tests/commons/") + modelSdfName;
auto modelPath
= std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_configuration_file.sdf";
gz::sim::TestFixture testFixture(modelPath.string());

yarp::os::NetworkBase::setLocalMode(true);
gz::common::Console::SetVerbosity(4);
gz::sim::EntityComponentManager* ecm;

gz::sim::TestFixture testFixture{sdfPath};

testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity,
const std::shared_ptr<const sdf::Element>& /*_sdf*/,
gz::sim::EntityComponentManager& _ecm,
Expand Down
8 changes: 4 additions & 4 deletions tests/commons/ConfigurationParsingFromStringTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <gz/sim/TestFixture.hh>
#include <sdf/Element.hh>

#include <filesystem>
#include <iostream>
#include <memory>
#include <string>
Expand All @@ -23,15 +24,14 @@

TEST(ConfigurationParsingTest, LoadPluginsWithYarpConfigurationString)
{
std::string modelSdfName = "model_configuration_string.sdf";
std::string sdfPath = std::string("../../../tests/commons/") + modelSdfName;
auto modelPath
= std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model_configuration_string.sdf";
gz::sim::TestFixture testFixture(modelPath.string());
yarp::os::NetworkBase::setLocalMode(true);
gz::common::Console::SetVerbosity(4);

gz::sim::EntityComponentManager* ecm;

gz::sim::TestFixture testFixture{sdfPath};

testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity,
const std::shared_ptr<const sdf::Element>& /*_sdf*/,
gz::sim::EntityComponentManager& _ecm,
Expand Down
3 changes: 3 additions & 0 deletions tests/controlboard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ foreach(TEST ${TESTS})

set_tests_properties(${TEST} PROPERTIES
ENVIRONMENT "${_env_vars}")

target_compile_definitions(${TEST} PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")


endforeach()
30 changes: 17 additions & 13 deletions tests/controlboard/ControlBoardCommonsTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

#include <gtest/gtest.h>

#include <gz/sim/EntityComponentManager.hh>
#include <gz/sim/EventManager.hh>
#include <gz/sim/Util.hh>
#include <filesystem>
#include <iostream>
#include <memory>
#include <sdf/Element.hh>
Expand All @@ -15,9 +13,12 @@

#include <gz/common/Console.hh>
#include <gz/sim/Entity.hh>
#include <gz/sim/EntityComponentManager.hh>
#include <gz/sim/EventManager.hh>
#include <gz/sim/Joint.hh>
#include <gz/sim/Model.hh>
#include <gz/sim/TestFixture.hh>
#include <gz/sim/Util.hh>
#include <gz/sim/World.hh>

#include <yarp/dev/IControlLimits.h>
Expand All @@ -35,9 +36,10 @@ namespace test
// Checks that the control board can be configured without initial conditions
TEST(ControlBoardCommonsTest, ConfigureControlBoardWithoutInitialCondition)
{
std::string modelSdfName = "pendulum_no_initial_configuration.sdf";
auto modelPath
= std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "pendulum_no_initial_configuration.sdf";
gz::sim::TestFixture testFixture(modelPath.string());

gz::sim::TestFixture testFixture{"../../../tests/controlboard/" + modelSdfName};
gz::common::Console::SetVerbosity(4);

testFixture.Finalize();
Expand All @@ -46,9 +48,10 @@ TEST(ControlBoardCommonsTest, ConfigureControlBoardWithoutInitialCondition)
// Checks that the control board can be configured without initial conditions
TEST(ControlBoardCommonsTest, ConfigureControlBoardWithInitialCondition)
{
std::string modelSdfName = "pendulum_with_initial_configuration.sdf";
auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR)
/ "pendulum_with_initial_configuration.sdf";
gz::sim::TestFixture testFixture(modelPath.string());

gz::sim::TestFixture testFixture{"../../../tests/controlboard/" + modelSdfName};
gz::common::Console::SetVerbosity(4);

testFixture.Finalize();
Expand All @@ -57,15 +60,15 @@ TEST(ControlBoardCommonsTest, ConfigureControlBoardWithInitialCondition)
// Check that multiple control board can be congfigured for the same robot model
TEST(ControlBoardCommonsTest, ConfigureMultipleControlBoards)
{
std::string modelSdfName = "coupled_pendulum_two_controlboards.sdf";
std::string sdfPath = std::string("../../../tests/controlboard/") + modelSdfName;
auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR)
/ "coupled_pendulum_two_controlboards.sdf";
gz::sim::TestFixture testFixture(modelPath.string());

bool configured = false;
std::vector<std::string> deviceIds;
std::vector<yarp::dev::gzyarp::ControlBoardDriver*> controlBoards;

gz::common::Console::SetVerbosity(4);
gz::sim::TestFixture testFixture{sdfPath};

testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity,
const std::shared_ptr<const sdf::Element>& /*_sdf*/,
Expand Down Expand Up @@ -102,15 +105,16 @@ TEST(ControlBoardCommonsTest, ConfigureMultipleControlBoards)
// Check that joint position limits are read correctly from yarp configuration
TEST(ControlBoardCommonsTest, JointPositionLimitsForMultipleJoints)
{
std::string modelSdfName = "coupled_pendulum_two_joints_single_controlboard.sdf";
std::string sdfPath = std::string("../../../tests/controlboard/") + modelSdfName;
auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR)
/ "coupled_pendulum_two_joints_single_controlboard.sdf";
gz::sim::TestFixture testFixture(modelPath.string());

std::string deviceScopedName = "model/coupled_pendulum/controlboard_plugin_device";
yarp::dev::PolyDriver* driver;
yarp::dev::IControlLimits* iControlLimits = nullptr;
IControlBoardData* iControlBoardData = nullptr;

gz::common::Console::SetVerbosity(4);
gz::sim::TestFixture testFixture{sdfPath};

testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity,
const std::shared_ptr<const sdf::Element>& /*_sdf*/,
Expand Down
11 changes: 7 additions & 4 deletions tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <algorithm>
#include <chrono>
#include <filesystem>
#include <gtest/gtest.h>
#include <iomanip>
#include <ios>
Expand Down Expand Up @@ -59,10 +60,12 @@ TEST(ControlBoardOnMultipleGazeboInstances, StartConcurrentGazeboInstances)
unsigned int iterationsToCompleteMotion1 = 0;
unsigned int iterationsToCompleteMotion2 = 0;

gz::sim::TestFixture fixture1("../../../tests/controlboard/"
"pendulum_multiple_gz_instances.sdf");
gz::sim::TestFixture fixture2("../../../tests/controlboard/"
"pendulum_multiple_gz_instances.sdf");
gz::sim::TestFixture fixture1(
(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "pendulum_multiple_gz_instances.sdf")
.string());
gz::sim::TestFixture fixture2(
(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "pendulum_multiple_gz_instances.sdf")
.string());
gz::common::Console::SetVerbosity(4);

fixture1
Expand Down
5 changes: 4 additions & 1 deletion tests/controlboard/ControlBoardPositionControlTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <cmath>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <memory>
#include <string>
Expand Down Expand Up @@ -45,7 +46,9 @@ class ControlBoardPositionFixture : public testing::Test
protected:
// void SetUp() override
ControlBoardPositionFixture()
: testFixture{"../../../tests/controlboard/pendulum_joint_relative_to_parent_link.sdf"}
: testFixture{(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR)
/ "pendulum_joint_relative_to_parent_link.sdf")
.string()}
{
gz::common::Console::SetVerbosity(4);

Expand Down
5 changes: 4 additions & 1 deletion tests/controlboard/ControlBoardPositionDirectControlTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cmath>
#include <cstdlib>
#include <filesystem>
#include <iostream>
#include <memory>
#include <numeric>
Expand Down Expand Up @@ -48,7 +49,9 @@ class ControlBoardPositionDirectFixture : public ::testing::Test
protected:
// void SetUp() override
ControlBoardPositionDirectFixture()
: testFixture{"../../../tests/controlboard/pendulum_joint_relative_to_parent_link.sdf"}
: testFixture{(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR)
/ "pendulum_joint_relative_to_parent_link.sdf")
.string()}
{
gz::common::Console::SetVerbosity(4);

Expand Down
Loading

0 comments on commit b3577c7

Please sign in to comment.