Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install the common test executables to libexec #458

Merged
merged 5 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 +24,16 @@
#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)
{
Expand All @@ -42,12 +45,17 @@ namespace physics
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;
}

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 +74,12 @@ namespace physics
}
return "";
}

private: static std::string libToTest;
};
}
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining a static variable in a header can be problematic. I recommend putting the variable in a private function and make it a singleton.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does 18f950c look?


#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.