From 42aec9e77899177c7c9fdc90d6cbff9af3154c2e Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Fri, 2 Dec 2022 14:01:57 -0800 Subject: [PATCH 1/4] common_test: add test_executable variable This makes the cmake code more readable. Signed-off-by: Steve Peters --- test/common_test/CMakeLists.txt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/common_test/CMakeLists.txt b/test/common_test/CMakeLists.txt index 7489026ef..89054a577 100644 --- a/test/common_test/CMakeLists.txt +++ b/test/common_test/CMakeLists.txt @@ -25,9 +25,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} @@ -39,17 +40,17 @@ foreach(test ${tests}) ${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}\"" ) 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() From 57ec5eb7c8e3e5b96ffc5b4cb8eb21dd7027dac9 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 8 Dec 2022 14:04:12 -0800 Subject: [PATCH 2/4] Make TestLibLoader header-only Signed-off-by: Steve Peters --- test/CMakeLists.txt | 1 - test/common_test/CMakeLists.txt | 1 - .../TestLibLoader.hh} | 29 ++++++-- test/common_test/addexternalforcetorque.cc | 2 +- test/common_test/basic_test.cc | 2 +- test/common_test/collisions.cc | 2 +- test/common_test/construct_empty_world.cc | 2 +- test/common_test/free_joint_features.cc | 2 +- test/common_test/joint_features.cc | 2 +- test/common_test/kinematic_features.cc | 2 +- test/common_test/link_features.cc | 2 +- test/common_test/shape_features.cc | 2 +- test/common_test/simulation_features.cc | 2 +- test/common_test/world_features.cc | 2 +- test/helpers/CMakeLists.txt | 9 --- test/helpers/TestLibLoader.hh | 69 ------------------- 16 files changed, 33 insertions(+), 98 deletions(-) rename test/{helpers/TestLibLoader.cc => common_test/TestLibLoader.hh} (71%) delete mode 100644 test/helpers/CMakeLists.txt delete mode 100644 test/helpers/TestLibLoader.hh diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ed0e79427..5e1e3e0ec 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/common_test/CMakeLists.txt b/test/common_test/CMakeLists.txt index 89054a577..042d79ab7 100644 --- a/test/common_test/CMakeLists.txt +++ b/test/common_test/CMakeLists.txt @@ -37,7 +37,6 @@ foreach(test ${tests}) ${PROJECT_LIBRARY_TARGET_NAME}-mesh gtest gtest_main - ${PROJECT_NAME}_test_lib_loader ) target_compile_definitions(${test_executable} PRIVATE diff --git a/test/helpers/TestLibLoader.cc b/test/common_test/TestLibLoader.hh similarity index 71% rename from test/helpers/TestLibLoader.cc rename to test/common_test/TestLibLoader.hh index e30002b09..99709c7a1 100644 --- a/test/helpers/TestLibLoader.cc +++ b/test/common_test/TestLibLoader.hh @@ -14,8 +14,8 @@ * limitations under the License. * */ - -#include "TestLibLoader.hh" +#ifndef GZ_PHYSICS_TESTLIBLOADER_HH_ +#define GZ_PHYSICS_TESTLIBLOADER_HH_ #include #include @@ -24,13 +24,16 @@ #include #include -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) { @@ -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 tokens = gz::common::split(_name, "::"); if (tokens.size() == 4) @@ -66,5 +74,12 @@ namespace physics } return ""; } + + private: static std::string libToTest; +}; } } + +std::string gz::physics::TestLibLoader::libToTest = std::string(""); + +#endif diff --git a/test/common_test/addexternalforcetorque.cc b/test/common_test/addexternalforcetorque.cc index 5017c96a8..fab35842b 100644 --- a/test/common_test/addexternalforcetorque.cc +++ b/test/common_test/addexternalforcetorque.cc @@ -24,7 +24,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include "../Utils.hh" #include diff --git a/test/common_test/basic_test.cc b/test/common_test/basic_test.cc index 55689e527..a3b91d87b 100644 --- a/test/common_test/basic_test.cc +++ b/test/common_test/basic_test.cc @@ -19,7 +19,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include #include diff --git a/test/common_test/collisions.cc b/test/common_test/collisions.cc index cec88e309..48189718c 100644 --- a/test/common_test/collisions.cc +++ b/test/common_test/collisions.cc @@ -19,7 +19,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include #include diff --git a/test/common_test/construct_empty_world.cc b/test/common_test/construct_empty_world.cc index 6e1575db5..a2974aaba 100644 --- a/test/common_test/construct_empty_world.cc +++ b/test/common_test/construct_empty_world.cc @@ -19,7 +19,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include #include diff --git a/test/common_test/free_joint_features.cc b/test/common_test/free_joint_features.cc index accc0f64f..9292fe66a 100644 --- a/test/common_test/free_joint_features.cc +++ b/test/common_test/free_joint_features.cc @@ -18,7 +18,7 @@ #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include #include diff --git a/test/common_test/joint_features.cc b/test/common_test/joint_features.cc index ece26cc34..85274aea2 100644 --- a/test/common_test/joint_features.cc +++ b/test/common_test/joint_features.cc @@ -24,7 +24,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include "../Utils.hh" #include "gz/physics/FrameSemantics.hh" diff --git a/test/common_test/kinematic_features.cc b/test/common_test/kinematic_features.cc index 727b56038..c479800a7 100644 --- a/test/common_test/kinematic_features.cc +++ b/test/common_test/kinematic_features.cc @@ -19,7 +19,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include "../Utils.hh" #include diff --git a/test/common_test/link_features.cc b/test/common_test/link_features.cc index 7db992e68..2da18d74b 100644 --- a/test/common_test/link_features.cc +++ b/test/common_test/link_features.cc @@ -24,7 +24,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include "../Utils.hh" #include diff --git a/test/common_test/shape_features.cc b/test/common_test/shape_features.cc index 6d9abe8c0..4f1f9ff60 100644 --- a/test/common_test/shape_features.cc +++ b/test/common_test/shape_features.cc @@ -19,7 +19,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include "../Utils.hh" // Features diff --git a/test/common_test/simulation_features.cc b/test/common_test/simulation_features.cc index 7022fe408..a1692ee2b 100644 --- a/test/common_test/simulation_features.cc +++ b/test/common_test/simulation_features.cc @@ -25,7 +25,7 @@ #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include "../Utils.hh" #include diff --git a/test/common_test/world_features.cc b/test/common_test/world_features.cc index e15fb01fb..a359cded7 100644 --- a/test/common_test/world_features.cc +++ b/test/common_test/world_features.cc @@ -19,7 +19,7 @@ #include #include -#include "../helpers/TestLibLoader.hh" +#include "TestLibLoader.hh" #include "../Utils.hh" #include diff --git a/test/helpers/CMakeLists.txt b/test/helpers/CMakeLists.txt deleted file mode 100644 index a7e33775b..000000000 --- a/test/helpers/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_library(${PROJECT_NAME}_test_lib_loader SHARED - TestLibLoader.cc -) -target_compile_definitions(${PROJECT_NAME}_test_lib_loader PRIVATE -DTestLibLoader_EXPORTS) -target_link_libraries(${PROJECT_NAME}_test_lib_loader - PUBLIC - ${PROJECT_LIBRARY_TARGET_NAME} - gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER} -) diff --git a/test/helpers/TestLibLoader.hh b/test/helpers/TestLibLoader.hh deleted file mode 100644 index fe7da2c50..000000000 --- a/test/helpers/TestLibLoader.hh +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2022 Open Source Robotics Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef GZ_PHYSICS_TESTLIBLOADER_HH_ -#define GZ_PHYSICS_TESTLIBLOADER_HH_ - -#include - -#ifndef _WIN32 -# define TestLibLoader_EXPORTS_API -#else -# if (defined(TestLibLoader_EXPORTS)) -# define TestLibLoader_EXPORTS_API __declspec(dllexport) -# else -# define TestLibLoader_EXPORTS_API __declspec(dllimport) -# endif -#endif - -// This is necessary because of using stl types here. It is completely safe, because -// a) the member is not accessible from the outside -// b) there are no inline functions. -#ifdef _WIN32 -# pragma warning(push) -# pragma warning(disable:4251) -#endif - -namespace gz -{ -namespace physics -{ -class TestLibLoader_EXPORTS_API 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[]); - - /// \brief Get the name of the library to test - /// \return Name of the library to test - public: static std::string GetLibToTest(); - - /// \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); - - private: static std::string libToTest; -}; -} -} - -#ifdef _WIN32 -# pragma warning(pop) -#endif - -#endif From 45ddfac9f7fb14afdb3ef9b5b2be09b65ebf7064 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Fri, 2 Dec 2022 14:02:46 -0800 Subject: [PATCH 3/4] Install COMMON_TEST_* executables to libexec Also build the test_lib_loader as static library since the tests link against it. Signed-off-by: Steve Peters --- test/common_test/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/common_test/CMakeLists.txt b/test/common_test/CMakeLists.txt index 042d79ab7..0b43b8b25 100644 --- a/test/common_test/CMakeLists.txt +++ b/test/common_test/CMakeLists.txt @@ -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 @@ -44,6 +46,8 @@ foreach(test ${tests}) "GZ_PHYSICS_RESOURCE_DIR=\"${GZ_PHYSICS_RESOURCE_DIR}\"" ) + install(TARGETS ${test_executable} DESTINATION ${TEST_INSTALL_DIR}) + if (${BULLET_FOUND}) configure_common_test("bullet" ${test_executable}) configure_common_test("bullet-featherstone" ${test_executable}) From 18f950c48f4a5a3171ce026e54cc920e06523d6f Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Fri, 9 Dec 2022 16:29:58 -0800 Subject: [PATCH 4/4] Fix static string initialization Signed-off-by: Steve Peters --- test/common_test/TestLibLoader.hh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/common_test/TestLibLoader.hh b/test/common_test/TestLibLoader.hh index 99709c7a1..87d73054a 100644 --- a/test/common_test/TestLibLoader.hh +++ b/test/common_test/TestLibLoader.hh @@ -41,6 +41,7 @@ class TestLibLoader << "Usage " << argv[0] << " \n"; return false; } + std::string &libToTest = LibToTest(); libToTest = argv[1]; return true; } @@ -49,7 +50,7 @@ class TestLibLoader /// \return Name of the library to test public: static std::string GetLibToTest() { - return libToTest; + return LibToTest(); } /// \brief Get Physics Engine name based on the plugin name @@ -75,11 +76,13 @@ class TestLibLoader return ""; } - private: static std::string libToTest; + private: static std::string& LibToTest() + { + static std::string libToTest = ""; + return libToTest; + } }; } } -std::string gz::physics::TestLibLoader::libToTest = std::string(""); - #endif