From 76c9e821cd6f7bbdd5c49a01112e1c19c3143d78 Mon Sep 17 00:00:00 2001 From: Alessandro Croci Date: Mon, 6 May 2024 12:48:36 +0200 Subject: [PATCH 1/2] Use absolute paths to reference models in unit tests --- tests/camera/CMakeLists.txt | 2 ++ tests/camera/CameraTest.cc | 23 +++++++++++--- tests/clock/CMakeLists.txt | 2 ++ tests/clock/ClockTest.cc | 11 ++++++- tests/commons/CMakeLists.txt | 4 +++ tests/commons/ConcurrentInstancesTest.cc | 9 +++--- .../ConfigurationParsingFromFileTest.cc | 9 +++--- .../ConfigurationParsingFromStringTest.cc | 8 ++--- tests/controlboard/CMakeLists.txt | 3 ++ tests/controlboard/ControlBoardCommonsTest.cc | 30 +++++++++++-------- ...ntrolBoardOnMultipleGazeboInstancesTest.cc | 11 ++++--- .../ControlBoardPositionControlTest.cc | 5 +++- .../ControlBoardPositionDirectControlTest.cc | 5 +++- .../ControlBoardTorqueControlTest.cc | 5 ++-- tests/forcetorque/CMakeLists.txt | 2 ++ tests/forcetorque/ForceTorqueTest.cc | 4 ++- tests/imu/CMakeLists.txt | 2 ++ tests/imu/ImuTest.cc | 3 +- tests/laser/CMakeLists.txt | 2 ++ tests/laser/LaserTest.cc | 4 ++- 20 files changed, 102 insertions(+), 42 deletions(-) diff --git a/tests/camera/CMakeLists.txt b/tests/camera/CMakeLists.txt index f135120..7232e9d 100644 --- a/tests/camera/CMakeLists.txt +++ b/tests/camera/CMakeLists.txt @@ -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}") diff --git a/tests/camera/CameraTest.cc b/tests/camera/CameraTest.cc index 002aa62..adafe77 100644 --- a/tests/camera/CameraTest.cc +++ b/tests/camera/CameraTest.cc @@ -1,8 +1,19 @@ #include + +#include +#include +#include +#include + +#include #include + #include +#include #include #include +#include +#include TEST(CameraTest, PluginTest) { @@ -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; @@ -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); @@ -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); @@ -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); diff --git a/tests/clock/CMakeLists.txt b/tests/clock/CMakeLists.txt index 2f10b57..1995a33 100644 --- a/tests/clock/CMakeLists.txt +++ b/tests/clock/CMakeLists.txt @@ -13,3 +13,5 @@ list(APPEND _env_vars "GZ_SIM_SYSTEM_PLUGIN_PATH=$ + +#include +#include +#include + +#include #include + #include #include #include @@ -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 diff --git a/tests/commons/CMakeLists.txt b/tests/commons/CMakeLists.txt index 48485ed..da65abd 100644 --- a/tests/commons/CMakeLists.txt +++ b/tests/commons/CMakeLists.txt @@ -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}") diff --git a/tests/commons/ConcurrentInstancesTest.cc b/tests/commons/ConcurrentInstancesTest.cc index 3e93527..849a166 100644 --- a/tests/commons/ConcurrentInstancesTest.cc +++ b/tests/commons/ConcurrentInstancesTest.cc @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -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(); diff --git a/tests/commons/ConfigurationParsingFromFileTest.cc b/tests/commons/ConfigurationParsingFromFileTest.cc index 17c3f85..4ea3cb9 100644 --- a/tests/commons/ConfigurationParsingFromFileTest.cc +++ b/tests/commons/ConfigurationParsingFromFileTest.cc @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -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& /*_sdf*/, gz::sim::EntityComponentManager& _ecm, diff --git a/tests/commons/ConfigurationParsingFromStringTest.cc b/tests/commons/ConfigurationParsingFromStringTest.cc index b63a0e8..1c8cfe6 100644 --- a/tests/commons/ConfigurationParsingFromStringTest.cc +++ b/tests/commons/ConfigurationParsingFromStringTest.cc @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -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& /*_sdf*/, gz::sim::EntityComponentManager& _ecm, diff --git a/tests/controlboard/CMakeLists.txt b/tests/controlboard/CMakeLists.txt index 97f3a17..52d2761 100644 --- a/tests/controlboard/CMakeLists.txt +++ b/tests/controlboard/CMakeLists.txt @@ -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() diff --git a/tests/controlboard/ControlBoardCommonsTest.cc b/tests/controlboard/ControlBoardCommonsTest.cc index f294ba7..2cc5965 100644 --- a/tests/controlboard/ControlBoardCommonsTest.cc +++ b/tests/controlboard/ControlBoardCommonsTest.cc @@ -4,9 +4,7 @@ #include -#include -#include -#include +#include #include #include #include @@ -15,9 +13,12 @@ #include #include +#include +#include #include #include #include +#include #include #include @@ -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(); @@ -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(); @@ -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 deviceIds; std::vector controlBoards; gz::common::Console::SetVerbosity(4); - gz::sim::TestFixture testFixture{sdfPath}; testFixture.OnConfigure([&](const gz::sim::Entity& _worldEntity, const std::shared_ptr& /*_sdf*/, @@ -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& /*_sdf*/, diff --git a/tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc b/tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc index 717a136..9294043 100644 --- a/tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc +++ b/tests/controlboard/ControlBoardOnMultipleGazeboInstancesTest.cc @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/tests/controlboard/ControlBoardPositionControlTest.cc b/tests/controlboard/ControlBoardPositionControlTest.cc index 1ceee8d..30f6d4a 100644 --- a/tests/controlboard/ControlBoardPositionControlTest.cc +++ b/tests/controlboard/ControlBoardPositionControlTest.cc @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/tests/controlboard/ControlBoardPositionDirectControlTest.cc b/tests/controlboard/ControlBoardPositionDirectControlTest.cc index feae5c9..f50bd59 100644 --- a/tests/controlboard/ControlBoardPositionDirectControlTest.cc +++ b/tests/controlboard/ControlBoardPositionDirectControlTest.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/tests/controlboard/ControlBoardTorqueControlTest.cc b/tests/controlboard/ControlBoardTorqueControlTest.cc index bf894d0..4407989 100644 --- a/tests/controlboard/ControlBoardTorqueControlTest.cc +++ b/tests/controlboard/ControlBoardTorqueControlTest.cc @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -40,13 +41,11 @@ class ControlBoardTorqueControlFixture : public testing::TestWithParam #include +#include #include #include @@ -22,7 +23,8 @@ TEST(ForceTorqueTest, PluginTest) gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/forcetorque/model.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf"; + gz::sim::TestFixture fixture(modelPath.string()); int iterations = 1000; fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false); diff --git a/tests/imu/CMakeLists.txt b/tests/imu/CMakeLists.txt index 183a68c..475b4ea 100644 --- a/tests/imu/CMakeLists.txt +++ b/tests/imu/CMakeLists.txt @@ -19,3 +19,5 @@ list(APPEND _env_vars "GZ_SIM_SYSTEM_PLUGIN_PATH=$ #include +#include #include #include #include @@ -26,7 +27,7 @@ class ImuFixture : public testing::Test { protected: ImuFixture() - : testFixture{"../../../tests/imu/model.sdf"} + : testFixture{(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf").string()} { gz::common::Console::SetVerbosity(4); diff --git a/tests/laser/CMakeLists.txt b/tests/laser/CMakeLists.txt index ce50f92..892529b 100644 --- a/tests/laser/CMakeLists.txt +++ b/tests/laser/CMakeLists.txt @@ -14,3 +14,5 @@ list(APPEND _env_vars "LIBGL_ALWAYS_SOFTWARE=1") set_tests_properties(LaserTest PROPERTIES ENVIRONMENT "${_env_vars}") + +target_compile_definitions(LaserTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/tests/laser/LaserTest.cc b/tests/laser/LaserTest.cc index 3e813b7..023c2c3 100644 --- a/tests/laser/LaserTest.cc +++ b/tests/laser/LaserTest.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,8 @@ TEST(LaserTest, PluginTest) gz::common::Console::SetVerbosity(4); // Instantiate test fixture - gz::sim::TestFixture fixture("../../../tests/laser/model.sdf"); + auto modelPath = std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / "model.sdf"; + gz::sim::TestFixture fixture(modelPath.string()); int iterations = 1000; fixture.Server()->Run(/*_blocking=*/true, iterations, /*_paused=*/false); From 076727a0836c41df1349888c7aa2dfe0acc4c23b Mon Sep 17 00:00:00 2001 From: Alessandro Croci Date: Mon, 13 May 2024 09:37:42 +0200 Subject: [PATCH 2/2] Add `--explicit` argument to `conda list` to be able to clone used environement --- .github/workflows/conda-forge.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/conda-forge.yml b/.github/workflows/conda-forge.yml index 0baf686..17a003e 100644 --- a/.github/workflows/conda-forge.yml +++ b/.github/workflows/conda-forge.yml @@ -67,14 +67,14 @@ 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 .. @@ -82,15 +82,15 @@ jobs: 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}