From 30f463e75ad06212bc606479169592c33c165a70 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 15 Jun 2022 16:16:01 +0200 Subject: [PATCH 1/7] Added basic architecture for common tests Signed-off-by: ahcorde --- bullet/src/EntityManagementFeatures.cc | 199 +++++++++++++++++++++++++ bullet/src/EntityManagementFeatures.hh | 90 +++++++++++ test/CMakeLists.txt | 3 + test/common_test/CMakeLists.txt | 19 +++ test/common_test/basic_test.cc | 75 ++++++++++ test/test_common_config.h.in | 57 +++++++ 6 files changed, 443 insertions(+) create mode 100644 test/common_test/CMakeLists.txt create mode 100644 test/common_test/basic_test.cc create mode 100644 test/test_common_config.h.in diff --git a/bullet/src/EntityManagementFeatures.cc b/bullet/src/EntityManagementFeatures.cc index 43414dd6f..5a91d73ab 100644 --- a/bullet/src/EntityManagementFeatures.cc +++ b/bullet/src/EntityManagementFeatures.cc @@ -167,7 +167,206 @@ bool EntityManagementFeatures::RemoveModelByName( return false; } +const std::string &EntityManagementFeatures::GetEngineName(const Identity &) const +{ + static const std::string engineName = "bullet"; + return engineName; +} + +std::size_t EntityManagementFeatures::GetEngineIndex(const Identity &) const +{ + return 0; +} + +std::size_t EntityManagementFeatures::GetWorldCount(const Identity &) const +{ + return worlds.size(); +} + +Identity EntityManagementFeatures::GetWorld( + const Identity &, std::size_t) const +{ + return this->GenerateIdentity(0); +} + +Identity EntityManagementFeatures::GetWorld( + const Identity &, const std::string &) const +{ + return this->GenerateIdentity(0); +} + +const std::string &EntityManagementFeatures::GetWorldName( + const Identity &) const +{ + static const std::string worldName = "bullet"; + return worldName; +} + +std::size_t EntityManagementFeatures::GetWorldIndex(const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetEngineOfWorld(const Identity &) const +{ + return this->GenerateIdentity(0); +} + +std::size_t EntityManagementFeatures::GetModelCount( + const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetModel( + const Identity &, std::size_t) const +{ + return this->GenerateIdentity(0); +} + +Identity EntityManagementFeatures::GetModel( + const Identity &, const std::string &) const +{ + return this->GenerateIdentity(0); +} + +const std::string &EntityManagementFeatures::GetModelName( + const Identity &) const +{ + static const std::string modelName = "bulletModel"; + return modelName; +} + +std::size_t EntityManagementFeatures::GetModelIndex(const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetWorldOfModel(const Identity &) const +{ + return this->GenerateIdentity(0); +} + +std::size_t EntityManagementFeatures::GetNestedModelCount( + const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetNestedModel( + const Identity &, std::size_t ) const +{ + return this->GenerateIdentity(0); +} + +Identity EntityManagementFeatures::GetNestedModel( + const Identity &, const std::string &) const +{ + return this->GenerateIdentity(0); +} + +std::size_t EntityManagementFeatures::GetLinkCount(const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetLink( + const Identity &, std::size_t) const +{ + return this->GenerateIdentity(0); +} + +Identity EntityManagementFeatures::GetLink( + const Identity &, const std::string &) const + +{ + return this->GenerateIdentity(0); +} + +std::size_t EntityManagementFeatures::GetJointCount(const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetJoint( + const Identity &, std::size_t ) const +{ + return this->GenerateIdentity(0); +} + +Identity EntityManagementFeatures::GetJoint( + const Identity &, const std::string &) const +{ + return this->GenerateIdentity(0); +} + +const std::string &EntityManagementFeatures::GetLinkName( + const Identity &) const +{ + static const std::string linkName = "bulletLink"; + return linkName; +} + +std::size_t EntityManagementFeatures::GetLinkIndex(const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetModelOfLink(const Identity &) const +{ + return this->GenerateIdentity(0); +} +std::size_t EntityManagementFeatures::GetShapeCount(const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetShape( + const Identity &, std::size_t) const +{ + return this->GenerateIdentity(0); +} + +Identity EntityManagementFeatures::GetShape( + const Identity &, const std::string &) const +{ + return this->GenerateIdentity(0); +} + +const std::string &EntityManagementFeatures::GetJointName( + const Identity &) const +{ + static const std::string jointName = "bulletJoint"; + return jointName; +} + +std::size_t EntityManagementFeatures::GetJointIndex(const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetModelOfJoint(const Identity &) const +{ + return this->GenerateIdentity(0); +} + +const std::string &EntityManagementFeatures::GetShapeName( + const Identity &) const +{ + static const std::string shapeName = "bulletShape"; + return shapeName; +} + +std::size_t EntityManagementFeatures::GetShapeIndex(const Identity &) const +{ + return 0; +} + +Identity EntityManagementFeatures::GetLinkOfShape(const Identity &) const +{ + return this->GenerateIdentity(0); +} } // namespace bullet } // namespace physics } // namespace gz diff --git a/bullet/src/EntityManagementFeatures.hh b/bullet/src/EntityManagementFeatures.hh index 1b19f3da3..51eac7175 100644 --- a/bullet/src/EntityManagementFeatures.hh +++ b/bullet/src/EntityManagementFeatures.hh @@ -32,6 +32,7 @@ namespace physics { namespace bullet { struct EntityManagementFeatureList : gz::physics::FeatureList< + GetEntities, RemoveModelFromWorld, ConstructEmptyWorldFeature > { }; @@ -56,6 +57,95 @@ class EntityManagementFeatures : // ----- Construct empty entities ----- public: Identity ConstructEmptyWorld( const Identity &_engineID, const std::string & _name) override; + + // ----- Get entities ----- + public: const std::string &GetEngineName(const Identity &) const override; + public: std::size_t GetEngineIndex(const Identity &) const override; + + public: std::size_t GetWorldCount(const Identity &) const override; + + public: Identity GetWorld( + const Identity &, std::size_t _worldIndex) const override; + + public: Identity GetWorld( + const Identity &, const std::string &_worldName) const override; + + public: const std::string &GetWorldName( + const Identity &_worldID) const override; + + public: std::size_t GetWorldIndex(const Identity &_worldID) const override; + + public: Identity GetEngineOfWorld(const Identity &_worldID) const override; + + public: std::size_t GetModelCount( + const Identity &_worldID) const override; + + public: Identity GetModel( + const Identity &_worldID, std::size_t _modelIndex) const override; + + public: Identity GetModel( + const Identity &_worldID, const std::string &_modelName) const override; + + public: const std::string &GetModelName( + const Identity &_modelID) const override; + + public: std::size_t GetModelIndex(const Identity &_modelID) const override; + + public: Identity GetWorldOfModel(const Identity &_modelID) const override; + + public: std::size_t GetNestedModelCount( + const Identity &_modelID) const override; + + public: Identity GetNestedModel( + const Identity &_modelID, std::size_t _modelIndex) const override; + + public: Identity GetNestedModel( + const Identity &_modelID, const std::string &_modelName) const override; + + public: std::size_t GetLinkCount(const Identity &_modelID) const override; + + public: Identity GetLink( + const Identity &_modelID, std::size_t _linkIndex) const override; + + public: Identity GetLink( + const Identity &_modelID, const std::string &_linkName) const override; + + public: std::size_t GetJointCount(const Identity &_modelID) const override; + + public: Identity GetJoint( + const Identity &_modelID, std::size_t _jointIndex) const override; + + public: Identity GetJoint( + const Identity &_modelID, const std::string &_jointName) const override; + + public: const std::string &GetLinkName( + const Identity &_linkID) const override; + + public: std::size_t GetLinkIndex(const Identity &_linkID) const override; + + public: Identity GetModelOfLink(const Identity &_linkID) const override; + + public: std::size_t GetShapeCount(const Identity &_linkID) const override; + + public: Identity GetShape( + const Identity &_linkID, std::size_t _shapeIndex) const override; + + public: Identity GetShape( + const Identity &_linkID, const std::string &_shapeName) const override; + + public: const std::string &GetJointName( + const Identity &_jointID) const override; + + public: std::size_t GetJointIndex(const Identity &_jointID) const override; + + public: Identity GetModelOfJoint(const Identity &_jointID) const override; + + public: const std::string &GetShapeName( + const Identity &_shapeID) const override; + + public: std::size_t GetShapeIndex(const Identity &_shapeID) const override; + + public: Identity GetLinkOfShape(const Identity &_shapeID) const override; }; } // namespace bullet diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0b421b737..871b3d25c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,6 +9,8 @@ include_directories ( ${CMAKE_BINARY_DIR}/include ) +configure_file (test_common_config.h.in ${PROJECT_BINARY_DIR}/test_common_config.h) + # Build gtest add_library(gtest STATIC gtest/src/gtest-all.cc) add_library(gtest_main STATIC gtest/src/gtest_main.cc) @@ -45,6 +47,7 @@ ExternalProject_Add( ) add_subdirectory(benchmark) +add_subdirectory(common_test) add_subdirectory(plugins) add_subdirectory(integration) add_subdirectory(performance) diff --git a/test/common_test/CMakeLists.txt b/test/common_test/CMakeLists.txt new file mode 100644 index 000000000..515c5e4de --- /dev/null +++ b/test/common_test/CMakeLists.txt @@ -0,0 +1,19 @@ +set(TEST_TYPE "COMMON_TEST") + +set(tests + basic_test +) + +link_directories(${PROJECT_BINARY_DIR}/test) + +set(PHYSICS_COMPONENTS bullet dartsim tpe) + +ign_build_tests( + TYPE + COMMON_TEST + SOURCES + ${tests} + LIB_DEPS + ignition-plugin${IGN_PLUGIN_VER}::loader + ignition-common5::ignition-common5 +) diff --git a/test/common_test/basic_test.cc b/test/common_test/basic_test.cc new file mode 100644 index 000000000..cc4c3b2f6 --- /dev/null +++ b/test/common_test/basic_test.cc @@ -0,0 +1,75 @@ +/* + * 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. + * +*/ +#include + +#include "test_common_config.h" // NOLINT(build/include) + +#include +#include +#include + +#include +#include + +class EntityManagementFeaturesTest: + public testing::Test, + public testing::WithParamInterface +{ + // Documentation inherited + public: void SetUp() override + { + gz::common::Console::SetVerbosity(4); + + gz::plugin::Loader loader; + std::string pluginPath = gz::common::joinPaths(GZ_PHYSICS_TEST_PLUGIN_PATH, + std::string("libignition-physics6-") + std::string(GetParam()) + + std::string("-plugin.so")); + loader.LoadLib(pluginPath); + + std::string physicsPluginName = GetParam(); + if (std::string(GetParam()) == "tpe") + { + physicsPluginName = GetParam() + std::string("plugin"); + } + + physicsPlugin = + loader.Instantiate(std::string("gz::physics::") + + physicsPluginName + + std::string("::Plugin")); + } + + public: gz::plugin::PluginPtr physicsPlugin; +}; + +// The features that an engine must have to be loaded by this loader. +using Features = gz::physics::FeatureList< + gz::physics::GetEngineInfo +>; + +///////////////////////////////////////////////// +TEST_P(EntityManagementFeaturesTest, ConstructEmptyWorld) +{ + auto engine = + gz::physics::RequestEngine3d::From(physicsPlugin); + + ASSERT_NE(nullptr, engine); + EXPECT_TRUE(engine->GetName().find(GetParam()) != std::string::npos); +} + +INSTANTIATE_TEST_CASE_P(EntityManagementFeatures, EntityManagementFeaturesTest, + PHYSICS_ENGINE_VALUES, + gz::physics::PrintToStringParam()); diff --git a/test/test_common_config.h.in b/test/test_common_config.h.in new file mode 100644 index 000000000..8781a9d4f --- /dev/null +++ b/test/test_common_config.h.in @@ -0,0 +1,57 @@ +#ifndef GZ_PHYSICS_TEST_CONFIG_HH_ +#define GZ_PHYSICS_TEST_CONFIG_HH_ + +#define PROJECT_SOURCE_PATH "${PROJECT_SOURCE_DIR}" +#define PROJECT_BUILD_PATH "${PROJECT_BINARY_DIR}" +#define GZ_PHYSICS_TEST_PLUGIN_PATH "${CMAKE_BINARY_DIR}/lib" + +/// \brief Helper macro to instantiate gtest for different engines +#define PHYSICS_ENGINE_VALUES ::testing::ValuesIn(\ + gz::physics::TestValues()) + +static const std::vector kPhysicsEngineTestValues + {"bullet", "dartsim", "tpe"}; + +#include +#include + +namespace gz +{ + namespace physics + { + /// \brief Helper function used with INSTANTIATE_TEST_CASE_P. + struct PrintToStringParam + { + template + std::string operator()(const ::testing::TestParamInfo &_info) const + { + return static_cast(_info.param); + } + }; + + /// \brief Helper function used with ::testing::Values + /// Checks env variable for physics engine values to be used in tests. + /// If env variable exists, it overrides the default physics engine values + std::vector TestValues() + { + std::string envTestValueStr; + if (!common::env("PHYSICS_ENGINE_VALUES", envTestValueStr)) + return kPhysicsEngineTestValues; + static std::vector physicsEngineEnvTestValues + = common::split(envTestValueStr, ","); + if (physicsEngineEnvTestValues.empty()) + { + std::cerr << "Error parsing 'PHYSICS_ENGINE_VALUES'. " + << "Using default test values" << std::endl; + return kPhysicsEngineTestValues; + } + std::vector values; + values.resize(physicsEngineEnvTestValues.size()); + for (unsigned int i = 0; i < physicsEngineEnvTestValues.size(); ++i) + values[i] = physicsEngineEnvTestValues[i].c_str(); + return values; + } + } +} + +#endif From dd6f502ca25a7b3a29fba7ce461a02e297685730 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 15 Jun 2022 16:39:03 +0200 Subject: [PATCH 2/7] make linters happy Signed-off-by: ahcorde --- bullet/src/EntityManagementFeatures.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bullet/src/EntityManagementFeatures.cc b/bullet/src/EntityManagementFeatures.cc index 5a91d73ab..21fd1d6ed 100644 --- a/bullet/src/EntityManagementFeatures.cc +++ b/bullet/src/EntityManagementFeatures.cc @@ -167,7 +167,8 @@ bool EntityManagementFeatures::RemoveModelByName( return false; } -const std::string &EntityManagementFeatures::GetEngineName(const Identity &) const +const std::string &EntityManagementFeatures::GetEngineName( + const Identity &) const { static const std::string engineName = "bullet"; return engineName; From 481e6c9458c8fd94e6255678497ab818fe779968 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 16 Jun 2022 21:11:47 +0200 Subject: [PATCH 3/7] improve cmake logic Signed-off-by: ahcorde --- test/CMakeLists.txt | 2 -- test/common_test/CMakeLists.txt | 35 +++++++++++++++----- test/common_test/basic_test.cc | 40 ++++++++++++----------- test/test_common_config.h.in | 57 --------------------------------- 4 files changed, 48 insertions(+), 86 deletions(-) delete mode 100644 test/test_common_config.h.in diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 871b3d25c..cc937edf3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,8 +9,6 @@ include_directories ( ${CMAKE_BINARY_DIR}/include ) -configure_file (test_common_config.h.in ${PROJECT_BINARY_DIR}/test_common_config.h) - # Build gtest add_library(gtest STATIC gtest/src/gtest-all.cc) add_library(gtest_main STATIC gtest/src/gtest_main.cc) diff --git a/test/common_test/CMakeLists.txt b/test/common_test/CMakeLists.txt index 515c5e4de..251749944 100644 --- a/test/common_test/CMakeLists.txt +++ b/test/common_test/CMakeLists.txt @@ -6,14 +6,33 @@ set(tests link_directories(${PROJECT_BINARY_DIR}/test) -set(PHYSICS_COMPONENTS bullet dartsim tpe) +function(configure_common_test PHYSICS_ENGINE_NAME test_name) + set(_env_vars) + add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME} COMMAND ${test_name}) + list(APPEND _env_vars "LIB_TO_TEST=${GZ_PHYSICS_ENGINE_INSTALL_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_LIBRARY_TARGET_NAME}-${PHYSICS_ENGINE_NAME}-plugin${CMAKE_SHARED_LIBRARY_SUFFIX}") + list(APPEND _env_vars "PHYSICS_ENGINE_NAME=${PHYSICS_ENGINE_NAME}") + set_tests_properties(${test_name}_${PHYSICS_ENGINE_NAME} + PROPERTIES + ENVIRONMENT "${_env_vars}") +endfunction() -ign_build_tests( - TYPE - COMMON_TEST - SOURCES - ${tests} - LIB_DEPS +foreach(test ${tests}) + add_executable(${TEST_TYPE}_${test} ${test}.cc) + + target_link_libraries(${TEST_TYPE}_${test} + PUBLIC ignition-plugin${IGN_PLUGIN_VER}::loader ignition-common5::ignition-common5 -) + ${PROJECT_LIBRARY_TARGET_NAME} + gtest + gtest_main + ) + + if (${BULLET_FOUND}) + configure_common_test("bullet" ${TEST_TYPE}_${test}) + endif() + if (${DART_FOUND}) + configure_common_test("dartsim" ${TEST_TYPE}_${test}) + endif() + configure_common_test("tpe" ${TEST_TYPE}_${test}) +endforeach() diff --git a/test/common_test/basic_test.cc b/test/common_test/basic_test.cc index cc4c3b2f6..4c9016ad1 100644 --- a/test/common_test/basic_test.cc +++ b/test/common_test/basic_test.cc @@ -16,10 +16,9 @@ */ #include -#include "test_common_config.h" // NOLINT(build/include) - #include #include +#include #include #include @@ -34,25 +33,32 @@ class EntityManagementFeaturesTest: { gz::common::Console::SetVerbosity(4); + if (!gz::common::env("PHYSICS_ENGINE_NAME", physicsEngineName)) + { + FAIL(); + } + std::string libToTest; + if (!gz::common::env("LIB_TO_TEST", libToTest)) + { + FAIL(); + } + gz::plugin::Loader loader; - std::string pluginPath = gz::common::joinPaths(GZ_PHYSICS_TEST_PLUGIN_PATH, - std::string("libignition-physics6-") + std::string(GetParam()) + - std::string("-plugin.so")); - loader.LoadLib(pluginPath); + loader.LoadLib(libToTest); - std::string physicsPluginName = GetParam(); - if (std::string(GetParam()) == "tpe") + std::string physicsEnginePluginName = physicsEngineName; + if (physicsEngineName == "tpe") { - physicsPluginName = GetParam() + std::string("plugin"); + physicsEnginePluginName = "tpeplugin"; } - physicsPlugin = - loader.Instantiate(std::string("gz::physics::") + - physicsPluginName + - std::string("::Plugin")); + loader.Instantiate("gz::physics::" + + physicsEnginePluginName + + "::Plugin"); } public: gz::plugin::PluginPtr physicsPlugin; + public: std::string physicsEngineName; }; // The features that an engine must have to be loaded by this loader. @@ -61,15 +67,11 @@ using Features = gz::physics::FeatureList< >; ///////////////////////////////////////////////// -TEST_P(EntityManagementFeaturesTest, ConstructEmptyWorld) +TEST_F(EntityManagementFeaturesTest, ConstructEmptyWorld) { auto engine = gz::physics::RequestEngine3d::From(physicsPlugin); ASSERT_NE(nullptr, engine); - EXPECT_TRUE(engine->GetName().find(GetParam()) != std::string::npos); + EXPECT_TRUE(engine->GetName().find(physicsEngineName) != std::string::npos); } - -INSTANTIATE_TEST_CASE_P(EntityManagementFeatures, EntityManagementFeaturesTest, - PHYSICS_ENGINE_VALUES, - gz::physics::PrintToStringParam()); diff --git a/test/test_common_config.h.in b/test/test_common_config.h.in deleted file mode 100644 index 8781a9d4f..000000000 --- a/test/test_common_config.h.in +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef GZ_PHYSICS_TEST_CONFIG_HH_ -#define GZ_PHYSICS_TEST_CONFIG_HH_ - -#define PROJECT_SOURCE_PATH "${PROJECT_SOURCE_DIR}" -#define PROJECT_BUILD_PATH "${PROJECT_BINARY_DIR}" -#define GZ_PHYSICS_TEST_PLUGIN_PATH "${CMAKE_BINARY_DIR}/lib" - -/// \brief Helper macro to instantiate gtest for different engines -#define PHYSICS_ENGINE_VALUES ::testing::ValuesIn(\ - gz::physics::TestValues()) - -static const std::vector kPhysicsEngineTestValues - {"bullet", "dartsim", "tpe"}; - -#include -#include - -namespace gz -{ - namespace physics - { - /// \brief Helper function used with INSTANTIATE_TEST_CASE_P. - struct PrintToStringParam - { - template - std::string operator()(const ::testing::TestParamInfo &_info) const - { - return static_cast(_info.param); - } - }; - - /// \brief Helper function used with ::testing::Values - /// Checks env variable for physics engine values to be used in tests. - /// If env variable exists, it overrides the default physics engine values - std::vector TestValues() - { - std::string envTestValueStr; - if (!common::env("PHYSICS_ENGINE_VALUES", envTestValueStr)) - return kPhysicsEngineTestValues; - static std::vector physicsEngineEnvTestValues - = common::split(envTestValueStr, ","); - if (physicsEngineEnvTestValues.empty()) - { - std::cerr << "Error parsing 'PHYSICS_ENGINE_VALUES'. " - << "Using default test values" << std::endl; - return kPhysicsEngineTestValues; - } - std::vector values; - values.resize(physicsEngineEnvTestValues.size()); - for (unsigned int i = 0; i < physicsEngineEnvTestValues.size(); ++i) - values[i] = physicsEngineEnvTestValues[i].c_str(); - return values; - } - } -} - -#endif From 4b0005c19103220cef1a6a0428ed0b18ec369e05 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 17 Jun 2022 12:49:24 +0200 Subject: [PATCH 4/7] Fixed CI Signed-off-by: ahcorde --- test/common_test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common_test/CMakeLists.txt b/test/common_test/CMakeLists.txt index 251749944..f3a1bc483 100644 --- a/test/common_test/CMakeLists.txt +++ b/test/common_test/CMakeLists.txt @@ -9,7 +9,7 @@ link_directories(${PROJECT_BINARY_DIR}/test) function(configure_common_test PHYSICS_ENGINE_NAME test_name) set(_env_vars) add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME} COMMAND ${test_name}) - list(APPEND _env_vars "LIB_TO_TEST=${GZ_PHYSICS_ENGINE_INSTALL_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_LIBRARY_TARGET_NAME}-${PHYSICS_ENGINE_NAME}-plugin${CMAKE_SHARED_LIBRARY_SUFFIX}") + list(APPEND _env_vars "LIB_TO_TEST=${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_LIBRARY_TARGET_NAME}-${PHYSICS_ENGINE_NAME}-plugin${CMAKE_SHARED_LIBRARY_SUFFIX}") list(APPEND _env_vars "PHYSICS_ENGINE_NAME=${PHYSICS_ENGINE_NAME}") set_tests_properties(${test_name}_${PHYSICS_ENGINE_NAME} PROPERTIES From 1f48f3aead7cfea6948fb4d980e7c3f840badadb Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 17 Jun 2022 16:32:50 +0200 Subject: [PATCH 5/7] Added feedback Signed-off-by: ahcorde --- test/common_test/CMakeLists.txt | 1 - test/common_test/basic_test.cc | 64 ++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/test/common_test/CMakeLists.txt b/test/common_test/CMakeLists.txt index f3a1bc483..00b282da3 100644 --- a/test/common_test/CMakeLists.txt +++ b/test/common_test/CMakeLists.txt @@ -10,7 +10,6 @@ function(configure_common_test PHYSICS_ENGINE_NAME test_name) set(_env_vars) add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME} COMMAND ${test_name}) list(APPEND _env_vars "LIB_TO_TEST=${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_LIBRARY_TARGET_NAME}-${PHYSICS_ENGINE_NAME}-plugin${CMAKE_SHARED_LIBRARY_SUFFIX}") - list(APPEND _env_vars "PHYSICS_ENGINE_NAME=${PHYSICS_ENGINE_NAME}") set_tests_properties(${test_name}_${PHYSICS_ENGINE_NAME} PROPERTIES ENVIRONMENT "${_env_vars}") diff --git a/test/common_test/basic_test.cc b/test/common_test/basic_test.cc index 4c9016ad1..0b0e4e009 100644 --- a/test/common_test/basic_test.cc +++ b/test/common_test/basic_test.cc @@ -21,9 +21,15 @@ #include #include +#include #include #include +// The features that an engine must have to be loaded by this loader. +using Features = gz::physics::FeatureList< + gz::physics::GetEngineInfo +>; + class EntityManagementFeaturesTest: public testing::Test, public testing::WithParamInterface @@ -33,45 +39,55 @@ class EntityManagementFeaturesTest: { gz::common::Console::SetVerbosity(4); - if (!gz::common::env("PHYSICS_ENGINE_NAME", physicsEngineName)) - { - FAIL(); - } std::string libToTest; if (!gz::common::env("LIB_TO_TEST", libToTest)) { FAIL(); } - gz::plugin::Loader loader; - loader.LoadLib(libToTest); + auto plugins = loader.LoadLib(libToTest); - std::string physicsEnginePluginName = physicsEngineName; - if (physicsEngineName == "tpe") + pluginNames = gz::physics::FindFeatures3d::From(loader); + if (pluginNames.empty()) { - physicsEnginePluginName = "tpeplugin"; + FAIL() << "No plugins with required features found in " << libToTest; } - physicsPlugin = - loader.Instantiate("gz::physics::" + - physicsEnginePluginName + - "::Plugin"); } - public: gz::plugin::PluginPtr physicsPlugin; - public: std::string physicsEngineName; -}; + /// \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) + { + std::string physicsEngineName = tokens[2]; + std::string physicsEnginePluginName = physicsEngineName; + if (physicsEngineName == "tpeplugin") + { + physicsEnginePluginName = "tpe"; + } + return physicsEnginePluginName; + } + return ""; + } -// The features that an engine must have to be loaded by this loader. -using Features = gz::physics::FeatureList< - gz::physics::GetEngineInfo ->; + public: gz::plugin::Loader loader; + public: std::set pluginNames; +}; ///////////////////////////////////////////////// TEST_F(EntityManagementFeaturesTest, ConstructEmptyWorld) { - auto engine = - gz::physics::RequestEngine3d::From(physicsPlugin); + for (const std::string &name : pluginNames) + { + std::cout << "Testing plugin: " << name << std::endl; + gz::plugin::PluginPtr plugin = loader.Instantiate(name); - ASSERT_NE(nullptr, engine); - EXPECT_TRUE(engine->GetName().find(physicsEngineName) != std::string::npos); + auto engine = gz::physics::RequestEngine3d::From(plugin); + ASSERT_NE(nullptr, engine); + EXPECT_TRUE(engine->GetName().find(PhysicsEngineName(name)) != + std::string::npos); + } } From 02e62faa527544d9d2a54d78a1804ade75025c33 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 20 Jun 2022 15:43:24 +0200 Subject: [PATCH 6/7] Added feedback Signed-off-by: ahcorde --- test/common_test/basic_test.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/common_test/basic_test.cc b/test/common_test/basic_test.cc index 0b0e4e009..54834a3e3 100644 --- a/test/common_test/basic_test.cc +++ b/test/common_test/basic_test.cc @@ -16,8 +16,8 @@ */ #include -#include #include +#include #include #include @@ -31,8 +31,7 @@ using Features = gz::physics::FeatureList< >; class EntityManagementFeaturesTest: - public testing::Test, - public testing::WithParamInterface + public testing::Test { // Documentation inherited public: void SetUp() override @@ -47,6 +46,8 @@ class EntityManagementFeaturesTest: auto plugins = loader.LoadLib(libToTest); + // TODO(ahcorde): We should also run the 3f, 2d, and 2f variants of + // FindFeatures pluginNames = gz::physics::FindFeatures3d::From(loader); if (pluginNames.empty()) { From 851004847da1add2fb1887dc92d775d3fc63d6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Mon, 20 Jun 2022 18:58:23 +0100 Subject: [PATCH 7/7] Suggestion: Added basic architecture for common tests with cmd arguments (#359) * Added basic architecture for common tests with cmd arguments Signed-off-by: ahcorde --- test/common_test/CMakeLists.txt | 11 +++++------ test/common_test/basic_test.cc | 33 +++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/test/common_test/CMakeLists.txt b/test/common_test/CMakeLists.txt index 00b282da3..c6f31669d 100644 --- a/test/common_test/CMakeLists.txt +++ b/test/common_test/CMakeLists.txt @@ -7,12 +7,11 @@ set(tests link_directories(${PROJECT_BINARY_DIR}/test) function(configure_common_test PHYSICS_ENGINE_NAME test_name) - set(_env_vars) - add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME} COMMAND ${test_name}) - list(APPEND _env_vars "LIB_TO_TEST=${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_LIBRARY_TARGET_NAME}-${PHYSICS_ENGINE_NAME}-plugin${CMAKE_SHARED_LIBRARY_SUFFIX}") - set_tests_properties(${test_name}_${PHYSICS_ENGINE_NAME} - PROPERTIES - ENVIRONMENT "${_env_vars}") + add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME} + COMMAND + ${test_name} + $ + ) endfunction() foreach(test ${tests}) diff --git a/test/common_test/basic_test.cc b/test/common_test/basic_test.cc index 54834a3e3..7ce69a2b7 100644 --- a/test/common_test/basic_test.cc +++ b/test/common_test/basic_test.cc @@ -33,25 +33,32 @@ using Features = gz::physics::FeatureList< class EntityManagementFeaturesTest: public testing::Test { + public: static void init(int argc, char *argv[]) + { + if (argc != 2) + FAIL() << "Please provide the path to an engine plugin.\n" + << "Usage COMMON_TEST_basic_test \n"; + libToTest = argv[1]; + } + + static std::string GetLibToTest() + { + return libToTest; + } + // Documentation inherited public: void SetUp() override { gz::common::Console::SetVerbosity(4); - std::string libToTest; - if (!gz::common::env("LIB_TO_TEST", libToTest)) - { - FAIL(); - } - - auto plugins = loader.LoadLib(libToTest); + auto plugins = loader.LoadLib(EntityManagementFeaturesTest::GetLibToTest()); // TODO(ahcorde): We should also run the 3f, 2d, and 2f variants of // FindFeatures pluginNames = gz::physics::FindFeatures3d::From(loader); if (pluginNames.empty()) { - FAIL() << "No plugins with required features found in " << libToTest; + FAIL() << "No plugins with required features found in " << GetLibToTest(); } } @@ -74,10 +81,13 @@ class EntityManagementFeaturesTest: return ""; } + public: static std::string libToTest; public: gz::plugin::Loader loader; public: std::set pluginNames; }; +std::string EntityManagementFeaturesTest::libToTest = std::string(""); + ///////////////////////////////////////////////// TEST_F(EntityManagementFeaturesTest, ConstructEmptyWorld) { @@ -92,3 +102,10 @@ TEST_F(EntityManagementFeaturesTest, ConstructEmptyWorld) std::string::npos); } } + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + EntityManagementFeaturesTest::init(argc, argv); + return RUN_ALL_TESTS(); +}