Skip to content

Commit

Permalink
Use absolute paths to reference models in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xela-95 committed May 6, 2024
1 parent 870b1d9 commit 028e055
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 39 deletions.
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);

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);

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);

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);

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);

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");
gz::sim::TestFixture fixture2(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR)
/ "dummy_box.sdf");
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);

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);
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);

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);

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);

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);

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
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,10 @@ 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");
gz::sim::TestFixture fixture2(std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR)
/ "pendulum_multiple_gz_instances.sdf");
gz::common::Console::SetVerbosity(4);

fixture1
Expand Down
4 changes: 3 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,8 @@ 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"}
{
gz::common::Console::SetVerbosity(4);

Expand Down
4 changes: 3 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,8 @@ 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"}
{
gz::common::Console::SetVerbosity(4);

Expand Down
2 changes: 1 addition & 1 deletion tests/controlboard/ControlBoardTorqueControlTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ControlBoardTorqueControlFixture : public testing::TestWithParam<std::stri
protected:
// void SetUp() override
ControlBoardTorqueControlFixture()
: testFixture{"../../../tests/controlboard/" + GetParam()}
: testFixture{std::filesystem::path(CMAKE_CURRENT_SOURCE_DIR) / GetParam()}
{
std::cerr << "========== Test Parameter: " << GetParam() << std::endl;
gz::common::Console::SetVerbosity(4);
Expand Down
2 changes: 2 additions & 0 deletions tests/forcetorque/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-f

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

target_compile_definitions(ForceTorqueTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
4 changes: 3 additions & 1 deletion tests/forcetorque/ForceTorqueTest.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <chrono>
#include <cstddef>
#include <filesystem>
#include <string>
#include <thread>

Expand All @@ -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);

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

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

target_compile_definitions(ImuTest PRIVATE CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
3 changes: 2 additions & 1 deletion tests/imu/ImuTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <chrono>
#include <cstddef>
#include <filesystem>
#include <memory>
#include <string>
#include <thread>
Expand All @@ -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"}
{
gz::common::Console::SetVerbosity(4);

Expand Down
2 changes: 2 additions & 0 deletions tests/laser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

0 comments on commit 028e055

Please sign in to comment.