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

Add regression test for multiple engine reloads #704

Merged
merged 7 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions ogre/src/OgreCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void OgreCamera::Destroy()
if (!this->ogreCamera)
return;

if (this->renderTexture)
{
this->renderTexture->Destroy();
this->renderTexture = nullptr;
}

Ogre::SceneManager *ogreSceneManager;
ogreSceneManager = this->scene->OgreSceneManager();
if (ogreSceneManager == nullptr)
Expand Down
15 changes: 12 additions & 3 deletions ogre/src/OgreDepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class gz::rendering::OgreDepthCameraPrivate
/// \brief Point cloud xyz data buffer
public: float *pcdBuffer = nullptr;

/// \brief Point cloud view port
public: Ogre::Viewport *pcdViewport = nullptr;

/// \brief Point cloud material
public: MaterialPtr pcdMaterial = nullptr;

Expand Down Expand Up @@ -110,6 +107,18 @@ void OgreDepthCamera::Destroy()
this->dataPtr->colorBuffer = nullptr;
}

if (this->dataPtr->pcdTexture)
{
this->dataPtr->pcdTexture->Destroy();
this->dataPtr->pcdTexture.reset();
}

if (this->dataPtr->colorTexture)
{
this->dataPtr->colorTexture->Destroy();
this->dataPtr->colorTexture.reset();
}

if (!this->ogreCamera || !this->scene->IsInitialized())
return;

Expand Down
9 changes: 6 additions & 3 deletions ogre/src/OgreGpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

#include <gz/common/Mesh.hh>
#include <gz/common/MeshManager.hh>
#include <gz/common/SubMesh.hh>

#include <gz/math/Color.hh>
Expand Down Expand Up @@ -203,6 +202,12 @@ void OgreGpuRays::Destroy()
this->dataPtr->orthoCam = nullptr;
}

if (this->dataPtr->undistMesh)
{
delete this->dataPtr->undistMesh;
this->dataPtr->undistMesh = nullptr;
}

this->dataPtr->visual.reset();
this->dataPtr->texIdx.clear();
this->dataPtr->texCount = 0u;
Expand Down Expand Up @@ -886,8 +891,6 @@ void OgreGpuRays::CreateMesh()
mesh->AddSubMesh(*submesh);

this->dataPtr->undistMesh = mesh;

common::MeshManager::Instance()->AddMesh(this->dataPtr->undistMesh);
}

/////////////////////////////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions ogre/src/OgreRenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ OgreRenderTarget::OgreRenderTarget()
//////////////////////////////////////////////////
OgreRenderTarget::~OgreRenderTarget()
{
// TODO(anyone): clean up check null

OgreRTShaderSystem::Instance()->DetachViewport(this->ogreViewport,
this->scene);
GZ_ASSERT(this->ogreViewport == nullptr, "Destroy() not called!");
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -339,6 +336,8 @@ void OgreRenderTexture::DestroyTarget()
if (nullptr == this->ogreTexture)
return;

this->materialApplicator.reset();

OgreRTShaderSystem::Instance()->DetachViewport(this->ogreViewport,
this->scene);

Expand All @@ -351,6 +350,7 @@ void OgreRenderTexture::DestroyTarget()
auto engine = OgreRenderEngine::Instance();
engine->OgreRoot()->getRenderSystem()->_cleanupDepthBuffers(false);

this->ogreViewport = nullptr;
this->ogreTexture = nullptr;
}

Expand Down
9 changes: 6 additions & 3 deletions ogre/src/OgreThermalCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ class gz::rendering::OgreThermalCameraPrivate
/// \brief Dummy texture
public: OgreRenderTexturePtr thermalTexture;

/// \brief Point cloud texture
public: OgreRenderTexturePtr colorTexture;

/// \brief Lens distortion compositor
public: Ogre::CompositorInstance *thermalInstance = nullptr;

Expand Down Expand Up @@ -294,6 +291,12 @@ void OgreThermalCamera::Destroy()
this->dataPtr->thermalImage = nullptr;
}

if (this->dataPtr->thermalTexture)
{
this->dataPtr->thermalTexture->Destroy();
this->dataPtr->thermalTexture = nullptr;
}

if (!this->ogreCamera || !this->scene->IsInitialized())
return;

Expand Down
6 changes: 6 additions & 0 deletions ogre/src/OgreWideAngleCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ void OgreWideAngleCamera::Destroy()
this->dataPtr->wideAngleImage = nullptr;
}

if (this->dataPtr->wideAngleTexture)
{
this->dataPtr->wideAngleTexture->Destroy();
this->dataPtr->wideAngleTexture = nullptr;
}

for (unsigned int i = 0u; i < this->dataPtr->kEnvCameraCount; ++i)
{
if (this->dataPtr->envRenderTargets[i])
Expand Down
66 changes: 39 additions & 27 deletions test/common_test/CommonRenderingTest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,41 @@ static std::tuple<std::string, std::string, std::string> GetTestParams()

if (gz::utils::env(kEngineToTestEnv, engine))
{
gz::utils::env(kEngineBackend, backend);
gz::utils::env(kEngineHeadless, headless);
}
gzdbg << "Read GZ_ENGINE_TO_TEST=" << engine << std::endl;
if (gz::utils::env(kEngineBackend, backend))
{
gzdbg << "Read GZ_ENGINE_BACKEND=" << backend << std::endl;
}

if (gz::utils::env(kEngineHeadless, headless))
{
gzdbg << "Read GZ_ENGINE_HEADLESS=" << headless << std::endl;
}
}
return {engine, backend, headless};
}

static std::map<std::string, std::string>
GetEngineParams(const std::string &_engine, const std::string &_backend, const std::string &_headless)
{
std::map<std::string, std::string> engineParams;
if (_engine == "ogre2" && _backend == "vulkan")
{
gzdbg << "Using OGRE2-VULKAN backend to test" << std::endl;
engineParams["vulkan"] = "1";
}
else if (_engine == "ogre2" && _backend == "metal")
{
gzdbg << "Using OGRE2-METAL backend to test" << std::endl;
engineParams["metal"] = "1";
}
if (!_headless.empty())
{
engineParams["headless"] = "1";
}
return engineParams;
}

/// \brief Common test fixture for all rendering tests
/// This allows for the engine, backend, and headless parameters
/// to be controlled via environment variables
Expand All @@ -59,38 +87,22 @@ class CommonRenderingTest: public testing::Test
gz::common::Console::SetVerbosity(4);

auto [envEngine, envBackend, envHeadless] = GetTestParams();

if (envEngine.empty())
{
GTEST_SKIP() << kEngineToTestEnv << " environment not set";
}

std::map<std::string, std::string> engineParams;

if (envEngine == "ogre2" && envBackend == "vulkan")
{
gzdbg << "Using OGRE2-VULKAN backend to test" << std::endl;
engineParams["vulkan"] = "1";
}
else if (envEngine == "ogre2" && envBackend == "metal")
{
gzdbg << "Using OGRE2-METAL backend to test" << std::endl;
engineParams["metal"] = "1";
}

if (!envHeadless.empty())
{
engineParams["headless"] = "1";
}

auto engineParams = GetEngineParams(envEngine, envBackend, envHeadless);
this->engineToTest = envEngine;
engine = gz::rendering::engine(this->engineToTest, engineParams);
if (!engine)
{
GTEST_FAIL() << "Engine '" << this->engineToTest << "' could not be loaded" << std::endl;
GTEST_SKIP() << "Engine '" << this->engineToTest << "' could not be loaded" << std::endl;
}
}

/// \brief Tear down the test case
/// \brief Tear down the test case
public: void TearDown() override
{
if(engine)
Expand All @@ -99,17 +111,17 @@ class CommonRenderingTest: public testing::Test
}
}

/// \brief String name of the engine to test
/// \brief String name of the engine to test
public: std::string engineToTest;

/// \brief Pointer to the rendering engine to test
/// \brief Pointer to the rendering engine to test
public: gz::rendering::RenderEngine *engine = nullptr;
};


/// \brief Check that the current engine being tested is supported.
/// If the engine is not in the set of passed arguments, the test is skipped
/// Example:
/// Example:
/// Skip test if engine is not ogre or ogre2
/// CHECK_SUPPORTED_ENGINE("ogre", "ogre2");
#define CHECK_SUPPORTED_ENGINE(...) \
Expand All @@ -118,7 +130,7 @@ if(std::unordered_set<std::string>({__VA_ARGS__}).count(this->engineToTest) == 0

/// \brief Check that the current engine being tested is unsupported
/// If the engine is in the set of passed arguments, the test is skipped
/// Example:
/// Example:
/// Skip test if engine is ogre2
/// CHECK_UNSUPPORTED_ENGINE("ogre");
#define CHECK_UNSUPPORTED_ENGINE(...) \
Expand Down
4 changes: 3 additions & 1 deletion test/common_test/Material_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "gz/rendering/ShaderType.hh"
#include "gz/rendering/Scene.hh"

#include <gz/utils/ExtraTestMacros.hh>

using namespace gz;
using namespace rendering;

Expand Down Expand Up @@ -332,7 +334,7 @@ TEST_F(MaterialTest, MaterialProperties)
}

/////////////////////////////////////////////////
TEST_F(MaterialTest, Copy)
TEST_F(MaterialTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(Copy))
{
ScenePtr scene = engine->CreateScene("copy_scene");
ASSERT_NE(nullptr, scene);
Expand Down
11 changes: 7 additions & 4 deletions test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
set(TEST_TYPE "REGRESSION")

set(tests
gz_rendering_test(
TYPE ${TEST_TYPE}
SOURCE reload_engine
LIB_DEPS
gz-plugin${GZ_PLUGIN_VER}::loader
gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
${PROJECT_LIBRARY_TARGET_NAME}
)

link_directories(${PROJECT_BINARY_DIR}/test)

gz_build_tests(TYPE REGRESSION SOURCES ${tests})
Loading