From a950315ee8ed34f4106606ed3baee821f04ede77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Mon, 20 Jun 2022 20:10:19 +0100 Subject: [PATCH] Added basic architecture for common tests (#357) Signed-off-by: ahcorde --- bullet/src/EntityManagementFeatures.cc | 200 +++++++++++++++++++++++++ bullet/src/EntityManagementFeatures.hh | 90 +++++++++++ test/CMakeLists.txt | 1 + test/common_test/CMakeLists.txt | 36 +++++ test/common_test/basic_test.cc | 111 ++++++++++++++ 5 files changed, 438 insertions(+) create mode 100644 test/common_test/CMakeLists.txt create mode 100644 test/common_test/basic_test.cc diff --git a/bullet/src/EntityManagementFeatures.cc b/bullet/src/EntityManagementFeatures.cc index 43414dd6f..21fd1d6ed 100644 --- a/bullet/src/EntityManagementFeatures.cc +++ b/bullet/src/EntityManagementFeatures.cc @@ -167,7 +167,207 @@ 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..cc937edf3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,6 +45,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..c6f31669d --- /dev/null +++ b/test/common_test/CMakeLists.txt @@ -0,0 +1,36 @@ +set(TEST_TYPE "COMMON_TEST") + +set(tests + basic_test +) + +link_directories(${PROJECT_BINARY_DIR}/test) + +function(configure_common_test PHYSICS_ENGINE_NAME test_name) + add_test(NAME ${test_name}_${PHYSICS_ENGINE_NAME} + COMMAND + ${test_name} + $ + ) +endfunction() + +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 new file mode 100644 index 000000000..7ce69a2b7 --- /dev/null +++ b/test/common_test/basic_test.cc @@ -0,0 +1,111 @@ +/* + * 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 +#include +#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: 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); + + 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 " << 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) + { + 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 ""; + } + + public: static std::string libToTest; + public: gz::plugin::Loader loader; + public: std::set pluginNames; +}; + +std::string EntityManagementFeaturesTest::libToTest = std::string(""); + +///////////////////////////////////////////////// +TEST_F(EntityManagementFeaturesTest, ConstructEmptyWorld) +{ + for (const std::string &name : pluginNames) + { + std::cout << "Testing plugin: " << name << std::endl; + gz::plugin::PluginPtr plugin = loader.Instantiate(name); + + auto engine = gz::physics::RequestEngine3d::From(plugin); + ASSERT_NE(nullptr, engine); + EXPECT_TRUE(engine->GetName().find(PhysicsEngineName(name)) != + std::string::npos); + } +} + +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + EntityManagementFeaturesTest::init(argc, argv); + return RUN_ALL_TESTS(); +}