Skip to content

Commit

Permalink
Install the common test executables to libexec (#458)
Browse files Browse the repository at this point in the history
* Add cmake variable to make code more readable.
* Make TestLibLoader header-only

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Dec 12, 2022
1 parent bf4cc20 commit 095b064
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 106 deletions.
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ add_subdirectory(gtest_vendor)
add_subdirectory(benchmark)
add_subdirectory(common_test)
add_subdirectory(plugins)
add_subdirectory(helpers)
add_subdirectory(integration)
add_subdirectory(performance)
add_subdirectory(regression)
Expand Down
20 changes: 12 additions & 8 deletions test/common_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set(tests
world_features
)

set(TEST_INSTALL_DIR ${CMAKE_INSTALL_LIBEXECDIR}/gz/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}/)

function(configure_common_test PHYSICS_ENGINE_NAME test_name)
add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME}
COMMAND
Expand All @@ -25,9 +27,10 @@ endfunction()
set(GZ_PHYSICS_RESOURCE_DIR "${CMAKE_SOURCE_DIR}/resources")

foreach(test ${tests})
add_executable(${TEST_TYPE}_${test} ${test}.cc)
set(test_executable "${TEST_TYPE}_${test}")
add_executable(${test_executable} ${test}.cc)

target_link_libraries(${TEST_TYPE}_${test}
target_link_libraries(${test_executable}
PUBLIC
gz-plugin${GZ_PLUGIN_VER}::loader
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
Expand All @@ -36,20 +39,21 @@ foreach(test ${tests})
${PROJECT_LIBRARY_TARGET_NAME}-mesh
gtest
gtest_main
${PROJECT_NAME}_test_lib_loader
)

target_compile_definitions(${TEST_TYPE}_${test} PRIVATE
target_compile_definitions(${test_executable} PRIVATE
"TEST_WORLD_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/worlds/\""
"GZ_PHYSICS_RESOURCE_DIR=\"${GZ_PHYSICS_RESOURCE_DIR}\""
)

install(TARGETS ${test_executable} DESTINATION ${TEST_INSTALL_DIR})

if (${BULLET_FOUND})
configure_common_test("bullet" ${TEST_TYPE}_${test})
configure_common_test("bullet-featherstone" ${TEST_TYPE}_${test})
configure_common_test("bullet" ${test_executable})
configure_common_test("bullet-featherstone" ${test_executable})
endif()
if (${DART_FOUND})
configure_common_test("dartsim" ${TEST_TYPE}_${test})
configure_common_test("dartsim" ${test_executable})
endif()
configure_common_test("tpe" ${TEST_TYPE}_${test})
configure_common_test("tpe" ${test_executable})
endforeach()
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*
*/

#include "TestLibLoader.hh"
#ifndef GZ_PHYSICS_TESTLIBLOADER_HH_
#define GZ_PHYSICS_TESTLIBLOADER_HH_

#include <iostream>
#include <string>
Expand All @@ -24,30 +24,39 @@
#include <gz/common/Filesystem.hh>
#include <gz/common/Util.hh>

std::string gz::physics::TestLibLoader::libToTest = std::string("");

namespace gz
{
namespace physics
{
bool TestLibLoader::init(int argc, char *argv[])
class TestLibLoader
{
/// brief Initialize command line arguments
/// \param[in] argc Number of arguments
/// \param[in] argv Vector with the arguments
public: static bool init(int argc, char *argv[])
{
if (argc != 2)
{
std::cerr << "Please provide the path to an engine plugin.\n"
<< "Usage " << argv[0] << " <physics engine path>\n";
return false;
}
std::string &libToTest = LibToTest();
libToTest = argv[1];
return true;
}

std::string TestLibLoader::GetLibToTest()
/// \brief Get the name of the library to test
/// \return Name of the library to test
public: static std::string GetLibToTest()
{
return libToTest;
return LibToTest();
}

std::string TestLibLoader::PhysicsEngineName(std::string _name)
/// \brief Get Physics Engine name based on the plugin name
/// \param[in] _name Plugin name
/// \return Name of the Physics Engine
std::string PhysicsEngineName(std::string _name)
{
std::vector<std::string> tokens = gz::common::split(_name, "::");
if (tokens.size() == 4)
Expand All @@ -66,5 +75,14 @@ namespace physics
}
return "";
}

private: static std::string& LibToTest()
{
static std::string libToTest = "";
return libToTest;
}
};
}
}

#endif
2 changes: 1 addition & 1 deletion test/common_test/addexternalforcetorque.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <gz/math/Vector3.hh>
#include <gz/math/eigen3/Conversions.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"
#include "../Utils.hh"

#include <gz/physics/FindFeatures.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"

#include <gz/physics/FindFeatures.hh>
#include <gz/physics/GetEntities.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/collisions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"

#include <gz/physics/FindFeatures.hh>
#include <gz/physics/RequestEngine.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/construct_empty_world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"

#include <gz/physics/ConstructEmpty.hh>
#include <gz/physics/FindFeatures.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/free_joint_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <tuple>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"

#include <gz/common/Console.hh>
#include <gz/common/Util.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/joint_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <gz/math/Helpers.hh>
#include <gz/math/eigen3/Conversions.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"
#include "../Utils.hh"

#include "gz/physics/FrameSemantics.hh"
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/kinematic_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"
#include "../Utils.hh"

#include <gz/physics/ConstructEmpty.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/link_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <gz/math/Vector3.hh>
#include <gz/math/eigen3/Conversions.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"
#include "../Utils.hh"

#include <gz/physics/FindFeatures.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/shape_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"
#include "../Utils.hh"

// Features
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/simulation_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <gz/math/eigen3/Conversions.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"
#include "../Utils.hh"

#include <gz/physics/sdf/ConstructJoint.hh>
Expand Down
2 changes: 1 addition & 1 deletion test/common_test/world_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <gz/common/Console.hh>
#include <gz/plugin/Loader.hh>

#include "../helpers/TestLibLoader.hh"
#include "TestLibLoader.hh"
#include "../Utils.hh"

#include <gz/physics/FindFeatures.hh>
Expand Down
9 changes: 0 additions & 9 deletions test/helpers/CMakeLists.txt

This file was deleted.

69 changes: 0 additions & 69 deletions test/helpers/TestLibLoader.hh

This file was deleted.

0 comments on commit 095b064

Please sign in to comment.