Skip to content

Commit

Permalink
Fix macOS/windows tests that fail to load library (gazebosim#60)
Browse files Browse the repository at this point in the history
* Add workflow for macos-latest
* Set test env to help find plugins

This fixes tests on macOS and windows that were failing to
find and/or load a sensor component library.

In windows CI and the macOS workflow (which runs `make test`
before `make install`) tests were failing with
the message "Unable to find sensor plugin path".
This is fixed by setting the IGN_PLUGIN_PATH in cmake to
the build folder containing the compiled plugins.

In the macOS jenkins build (which runs `make test` after
`make install`) tests were failing with the message
"SDF sensor type does not match template type". It was
difficult to track down, but it appears to be caused by
a failure to properly dlopen all the shared libraries
linked by the component plugins when a test finds an
installed component library, rather than one from the build
folder. It is fixed by setting DYLD_LIBRARY_PATH to include
the location of the installed libraries.

Fixes gazebosim#4.

* Remove redundant AddPluginPaths calls from tests

They don't work on windows, so just depend on the
environment variables set in cmake instead.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters committed Nov 19, 2020
1 parent 5cbb2d4 commit 2e63f53
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 29 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: macOS latest

on: [push, pull_request]

jobs:
build:

env:
PACKAGE: ignition-sensors4
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- run: brew config

# Needed for X11Requirement
- run: brew cask install xquartz
- name: Install base dependencies
run: |
brew tap osrf/simulation;
brew install --only-dependencies ${PACKAGE};
- run: mkdir build
- name: cmake
working-directory: build
run: cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/${PACKAGE}/HEAD
- run: make
working-directory: build
- run: make test
working-directory: build
env:
CTEST_OUTPUT_ON_FAILURE: 1
- name: make install
working-directory: build
run: |
make install;
brew link ${PACKAGE};
16 changes: 16 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,19 @@ ign_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS ${rendering_target})
ign_build_tests(TYPE UNIT SOURCES Lidar_TEST.cc LIB_DEPS ${lidar_target})
ign_build_tests(TYPE UNIT SOURCES Camera_TEST.cc LIB_DEPS ${camera_target})
ign_build_tests(TYPE UNIT SOURCES ImuSensor_TEST.cc LIB_DEPS ${imu_target})

set(plugin_test_targets)
list(APPEND plugin_test_targets "UNIT_Camera_TEST")
list(APPEND plugin_test_targets "UNIT_Lidar_TEST")
list(APPEND plugin_test_targets "UNIT_ImuSensor_TEST")

foreach(plugin_test ${plugin_test_targets})
if(TARGET ${plugin_test})
set(_env_vars)
list(APPEND _env_vars "IGN_PLUGIN_PATH=$<TARGET_FILE_DIR:${camera_target}>")
list(APPEND _env_vars "DYLD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")

set_tests_properties(${plugin_test} PROPERTIES
ENVIRONMENT "${_env_vars}")
endif()
endforeach()
12 changes: 12 additions & 0 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ ign_build_tests(TYPE INTEGRATION
${PROJECT_LIBRARY_TARGET_NAME}-imu
)

foreach(plugin_test ${dri_tests} ${tests})
get_filename_component(BINARY_NAME ${plugin_test} NAME_WE)
set(BINARY_NAME "${TEST_TYPE}_${BINARY_NAME}")
if(TARGET ${BINARY_NAME})
set(_env_vars)
list(APPEND _env_vars "IGN_PLUGIN_PATH=$<TARGET_FILE_DIR:${PROJECT_LIBRARY_TARGET_NAME}>")
list(APPEND _env_vars "DYLD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")

set_tests_properties(${BINARY_NAME} PROPERTIES
ENVIRONMENT "${_env_vars}")
endif()
endforeach()
4 changes: 0 additions & 4 deletions test/integration/air_pressure_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ TEST_F(AirPressureSensorTest, CreateAirPressure)

// create the sensor using sensor factory
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::AirPressureSensor> sensor =
sf.CreateSensor<ignition::sensors::AirPressureSensor>(airPressureSdf);
EXPECT_TRUE(sensor != nullptr);
Expand Down Expand Up @@ -167,7 +166,6 @@ TEST_F(AirPressureSensorTest, SensorReadings)
// create the sensor using sensor factory
// try creating without specifying the sensor type and then cast it
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::Sensor> s =
sf.CreateSensor(airPressureSdf);
std::unique_ptr<ignition::sensors::AirPressureSensor> sensor(
Expand Down Expand Up @@ -233,8 +231,6 @@ TEST_F(AirPressureSensorTest, Topic)

// Factory
ignition::sensors::SensorFactory factory;
factory.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH,
"lib"));

// Default topic
{
Expand Down
4 changes: 0 additions & 4 deletions test/integration/altimeter_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ TEST_F(AltimeterSensorTest, CreateAltimeter)

// create the sensor using sensor factory
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::AltimeterSensor> sensor =
sf.CreateSensor<ignition::sensors::AltimeterSensor>(altimeterSdf);
EXPECT_TRUE(sensor != nullptr);
Expand Down Expand Up @@ -173,7 +172,6 @@ TEST_F(AltimeterSensorTest, SensorReadings)
// create the sensor using sensor factory
// try creating without specifying the sensor type and then cast it
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::Sensor> s =
sf.CreateSensor(altimeterSdf);
std::unique_ptr<ignition::sensors::AltimeterSensor> sensor(
Expand Down Expand Up @@ -261,8 +259,6 @@ TEST_F(AltimeterSensorTest, Topic)

// Factory
ignition::sensors::SensorFactory factory;
factory.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH,
"lib"));

// Default topic
{
Expand Down
1 change: 0 additions & 1 deletion test/integration/camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void CameraSensorTest::ImagesWithBuiltinSDF(const std::string &_renderEngine)

// do the test
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));

ignition::sensors::CameraSensor *sensor =
mgr.CreateSensor<ignition::sensors::CameraSensor>(sensorPtr);
Expand Down
1 change: 0 additions & 1 deletion test/integration/depth_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ void DepthCameraSensorTest::ImagesWithBuiltinSDF(

// do the test
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));

ignition::sensors::DepthCameraSensor *depthSensor =
mgr.CreateSensor<ignition::sensors::DepthCameraSensor>(sensorPtr);
Expand Down
6 changes: 0 additions & 6 deletions test/integration/gpu_lidar_sensor_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ void GpuLidarSensorTest::CreateGpuLidar(const std::string &_renderEngine)

// Create a sensor manager
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));

// Create an scene with a box in it
scene->SetAmbientLight(0.3, 0.3, 0.3);
Expand Down Expand Up @@ -318,7 +317,6 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine)

// Create a sensor manager
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));

// Create a GpuLidarSensor
ignition::sensors::GpuLidarSensor *sensor =
Expand Down Expand Up @@ -462,7 +460,6 @@ void GpuLidarSensorTest::TestThreeBoxes(const std::string &_renderEngine)

// Create a sensor manager
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));

// Create a GpuLidarSensors
ignition::sensors::GpuLidarSensor *sensor1 =
Expand Down Expand Up @@ -608,7 +605,6 @@ void GpuLidarSensorTest::VerticalLidar(const std::string &_renderEngine)

// Create a sensor manager
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));

// Create a GpuLidarSensor
ignition::sensors::GpuLidarSensor *sensor =
Expand Down Expand Up @@ -726,7 +722,6 @@ void GpuLidarSensorTest::ManualUpdate(const std::string &_renderEngine)

// Create a sensor manager
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));

// Create a GpuLidarSensors
ignition::sensors::GpuLidarSensor *sensor1 =
Expand Down Expand Up @@ -819,7 +814,6 @@ void GpuLidarSensorTest::Topic(const std::string &_renderEngine)

// Create a GpuLidarSensor
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));


// Default topic
Expand Down
4 changes: 0 additions & 4 deletions test/integration/imu_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ TEST_F(ImuSensorTest, CreateImu)

// create the sensor using sensor factory
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::ImuSensor> sensor =
sf.CreateSensor<ignition::sensors::ImuSensor>(imuSdf);
EXPECT_TRUE(sensor != nullptr);
Expand Down Expand Up @@ -108,7 +107,6 @@ TEST_F(ImuSensorTest, SensorReadings)
// create the sensor using sensor factory
// try creating without specifying the sensor type and then cast it
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::Sensor> s =
sf.CreateSensor(imuSdf);
std::unique_ptr<ignition::sensors::ImuSensor> sensor(
Expand Down Expand Up @@ -237,8 +235,6 @@ TEST_F(ImuSensorTest, Topic)

// Factory
ignition::sensors::SensorFactory factory;
factory.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH,
"lib"));

// Default topic
{
Expand Down
4 changes: 0 additions & 4 deletions test/integration/logical_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ TEST_F(LogicalCameraSensorTest, CreateLogicalCamera)

// create the sensor using sensor factory
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::LogicalCameraSensor> sensor =
sf.CreateSensor<ignition::sensors::LogicalCameraSensor>(logicalCameraSdf);
EXPECT_TRUE(sensor != nullptr);
Expand Down Expand Up @@ -144,7 +143,6 @@ TEST_F(LogicalCameraSensorTest, DetectBox)
// create the sensor using sensor factory
// try creating without specifying the sensor type and then cast it
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::Sensor> s =
sf.CreateSensor(logicalCameraSdf);
std::unique_ptr<ignition::sensors::LogicalCameraSensor> sensor(
Expand Down Expand Up @@ -245,8 +243,6 @@ TEST_F(LogicalCameraSensorTest, Topic)

// Factory
ignition::sensors::SensorFactory factory;
factory.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH,
"lib"));

// Default topic
{
Expand Down
4 changes: 0 additions & 4 deletions test/integration/magnetometer_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ TEST_F(MagnetometerSensorTest, CreateMagnetometer)

// create the sensor using sensor factory
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::MagnetometerSensor> sensor =
sf.CreateSensor<ignition::sensors::MagnetometerSensor>(magnetometerSdf);
EXPECT_TRUE(sensor != nullptr);
Expand Down Expand Up @@ -179,7 +178,6 @@ TEST_F(MagnetometerSensorTest, SensorReadings)
// create the sensor using sensor factory
// try creating without specifying the sensor type and then cast it
ignition::sensors::SensorFactory sf;
sf.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));
std::unique_ptr<ignition::sensors::Sensor> s =
sf.CreateSensor(magnetometerSdf);
std::unique_ptr<ignition::sensors::MagnetometerSensor> sensor(
Expand Down Expand Up @@ -296,8 +294,6 @@ TEST_F(MagnetometerSensorTest, Topic)

// Factory
ignition::sensors::SensorFactory factory;
factory.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH,
"lib"));

// Default topic
{
Expand Down
1 change: 0 additions & 1 deletion test/integration/rgbd_camera_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ void RgbdCameraSensorTest::ImagesWithBuiltinSDF(

// do the test
ignition::sensors::Manager mgr;
mgr.AddPluginPaths(ignition::common::joinPaths(PROJECT_BUILD_PATH, "lib"));

ignition::sensors::RgbdCameraSensor *rgbdSensor =
mgr.CreateSensor<ignition::sensors::RgbdCameraSensor>(sensorPtr);
Expand Down

0 comments on commit 2e63f53

Please sign in to comment.