Skip to content

Commit

Permalink
port: 7 to main (#564)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll authored Aug 23, 2023
2 parents c2e19a9 + d8d76d3 commit 974957f
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 59 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Add ticket to inbox
uses: technote-space/create-project-card-action@v1
uses: actions/[email protected]
with:
PROJECT: Core development
COLUMN: Inbox
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
CHECK_ORG_PROJECT: true
project-url: https://github.com/orgs/gazebosim/projects/7
github-token: ${{ secrets.TRIAGE_TOKEN }}

4 changes: 2 additions & 2 deletions src/Helpers_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ TEST(HelpersTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(renderEngine))
EXPECT_TRUE(renderEngineName().empty());

// Set the render engine GUI name
mainWindow->SetRenderEngine("ogre");
mainWindow->SetRenderEngine("ogre2");

// Has render engine
EXPECT_FALSE(renderEngineName().empty());
EXPECT_EQ("ogre", renderEngineName());
EXPECT_EQ("ogre2", renderEngineName());

// Set no render engine
mainWindow->SetRenderEngine({});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/minimal_scene/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ if (APPLE)
MinimalSceneRhiMetal.mm
PROPERTIES
COMPILE_FLAGS
"-fobjc-arc"
"-fobjc-arc -Wno-nullability-completeness"
)
endif()
4 changes: 4 additions & 0 deletions src/plugins/minimal_scene/MinimalScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,10 @@ void GzRenderer::Destroy()

// TODO(anyone) If that was the last scene, terminate engine?
}

// clean up in the rendering thread
this->dataPtr->camera.reset();
this->dataPtr->rayQuery.reset();
}

/////////////////////////////////////////////////
Expand Down
81 changes: 81 additions & 0 deletions test/helpers/RenderEngineHelper.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2023 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_GUI_RENDERENGINEHELPER_HH_
#define GZ_GUI_RENDERENGINEHELPER_HH_

#include <gtest/gtest.h>

#include <memory>
#include <string>

#include <gz/rendering/RenderEngine.hh>
#include <gz/rendering/RenderTypes.hh>

#include "gz/gui/GuiEvents.hh"

#include "TestHelper.hh"

namespace gz
{
namespace gui
{
namespace testing
{
/// \brief Get the render engine
/// This function should be called after the main window is
/// shown (mainWindow.show()). It blocks until render events
/// are received.
/// \return A pointer to the render engine or nullptr if it's not available.
static rendering::RenderEngine* getRenderEngine(
const std::string &_engine)
{
// Filter events
bool receivedPreRenderEvent{false};
bool receivedRenderEvent{false};
auto testHelper = std::make_unique<TestHelper>();
testHelper->forwardEvent = [&](QEvent *_event)
{
if (_event->type() == gui::events::PreRender::kType)
{
receivedPreRenderEvent = true;
}
if (_event->type() == gui::events::Render::kType)
{
receivedRenderEvent = true;
}
};

int sleep = 0;
int maxSleep = 30;
while (!receivedRenderEvent && sleep < maxSleep)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
QCoreApplication::processEvents();
++sleep;
}
EXPECT_TRUE(receivedPreRenderEvent);
EXPECT_TRUE(receivedRenderEvent);

// Check scene
auto engine = rendering::engine(_engine);
return engine;
}
}
}
}

#endif
4 changes: 2 additions & 2 deletions test/integration/camera_tracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
// Load plugins
const char *pluginStr =
"<plugin filename=\"MinimalScene\">"
"<engine>ogre</engine>"
"<engine>ogre2</engine>"
"<scene>banana</scene>"
"<ambient_light>1.0 0 0</ambient_light>"
"<background_color>0 1 0</background_color>"
Expand Down Expand Up @@ -119,7 +119,7 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
EXPECT_TRUE(poseMsg.has_position());
EXPECT_TRUE(poseMsg.has_orientation());

auto engine = rendering::engine("ogre");
auto engine = rendering::engine("ogre2");
ASSERT_NE(nullptr, engine);

auto scene = engine->SceneByName("banana");
Expand Down
20 changes: 8 additions & 12 deletions test/integration/marker_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <gz/utils/ExtraTestMacros.hh>

#include "test_config.hh" // NOLINT(build/include)
#include "../helpers/TestHelper.hh"
#include "../helpers/RenderEngineHelper.hh"
#include "gz/gui/Application.hh"
#include "gz/gui/GuiEvents.hh"
#include "gz/gui/MainWindow.hh"
Expand Down Expand Up @@ -115,7 +117,7 @@ TEST_F(MarkerManagerTestFixture,

const char *pluginMinimalSceneStr =
"<plugin filename=\"MinimalScene\">"
"<engine>ogre</engine>"
"<engine>ogre2</engine>"
"<scene>scene</scene>"
"</plugin>";

Expand All @@ -142,19 +144,10 @@ TEST_F(MarkerManagerTestFixture,
// Show, but don't exec, so we don't block
window->QuickWindow()->show();

// Check scene
auto engine = rendering::engine("ogre");
// get render engine after window is shown
auto engine = gz::gui::testing::getRenderEngine("ogre2");
ASSERT_NE(nullptr, engine);

int sleep = 0;
int maxSleep = 30;
while (0 == engine->SceneCount() && sleep < maxSleep)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
QCoreApplication::processEvents();
sleep++;
}

EXPECT_EQ(1u, engine->SceneCount());
scene = engine->SceneByName("scene");
ASSERT_NE(nullptr, scene);
Expand Down Expand Up @@ -218,4 +211,7 @@ TEST_F(MarkerManagerTestFixture,

// Cleanup
plugins.clear();
scene.reset();

window->QuickWindow()->close();
}
38 changes: 6 additions & 32 deletions test/integration/minimal_scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "test_config.hh" // NOLINT(build/include)
#include "../helpers/TestHelper.hh"
#include "../helpers/RenderEngineHelper.hh"
#include "gz/gui/Application.hh"
#include "gz/gui/GuiEvents.hh"
#include "gz/gui/Plugin.hh"
Expand Down Expand Up @@ -80,7 +81,7 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
// Load plugin
const char *pluginStr =
"<plugin filename=\"MinimalScene\">"
"<engine>ogre</engine>"
"<engine>ogre2</engine>"
"<scene>banana</scene>"
"<ambient_light>1.0 0 0</ambient_light>"
"<background_color>0 1 0</background_color>"
Expand All @@ -106,37 +107,10 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
// Show, but don't exec, so we don't block
win->QuickWindow()->show();

// Filter events
bool receivedPreRenderEvent{false};
bool receivedRenderEvent{false};
auto testHelper = std::make_unique<TestHelper>();
testHelper->forwardEvent = [&](QEvent *_event)
{
if (_event->type() == events::PreRender::kType)
{
receivedPreRenderEvent = true;
}
if (_event->type() == events::Render::kType)
{
receivedRenderEvent = true;
}
};

// Check scene
auto engine = rendering::engine("ogre");
// get render engine after window is shown
auto engine = gz::gui::testing::getRenderEngine("ogre2");
ASSERT_NE(nullptr, engine);

int sleep = 0;
int maxSleep = 30;
while (!receivedRenderEvent && sleep < maxSleep)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
QCoreApplication::processEvents();
++sleep;
}
EXPECT_TRUE(receivedPreRenderEvent);
EXPECT_TRUE(receivedRenderEvent);

EXPECT_EQ(1u, engine->SceneCount());
auto scene = engine->SceneByName("banana");
ASSERT_NE(nullptr, scene);
Expand Down Expand Up @@ -170,7 +144,7 @@ TEST(MinimalSceneTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
EXPECT_TRUE(app.RemovePlugin(pluginName));
plugins.clear();


scene.reset();
win->QuickWindow()->close();
engine->DestroyScene(scene);
EXPECT_TRUE(rendering::unloadEngine(engine->Name()));
}
10 changes: 5 additions & 5 deletions test/integration/transport_scene_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "test_config.hh" // NOLINT(build/include)
#include "../helpers/TestHelper.hh"
#include "../helpers/RenderEngineHelper.hh"
#include "gz/gui/Application.hh"
#include "gz/gui/GuiEvents.hh"
#include "gz/gui/Plugin.hh"
Expand Down Expand Up @@ -123,7 +124,7 @@ TEST(TransportSceneManagerTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
// Load plugins
const char *pluginStr =
"<plugin filename=\"MinimalScene\">"
"<engine>ogre</engine>"
"<engine>ogre2</engine>"
"<scene>banana</scene>"
"<ambient_light>1.0 0 0</ambient_light>"
"<background_color>0 1 0</background_color>"
Expand Down Expand Up @@ -154,8 +155,8 @@ TEST(TransportSceneManagerTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
// Show, but don't exec, so we don't block
win->QuickWindow()->show();

// Get scene
auto engine = rendering::engine("ogre");
// get render engine after window is shown
auto engine = gz::gui::testing::getRenderEngine("ogre2");
ASSERT_NE(nullptr, engine);

int sleep = 0;
Expand Down Expand Up @@ -259,8 +260,7 @@ TEST(TransportSceneManagerTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Config))
}
plugins.clear();

scene.reset();
win->QuickWindow()->close();
engine->DestroyScene(scene);
EXPECT_TRUE(rendering::unloadEngine(engine->Name()));
}

0 comments on commit 974957f

Please sign in to comment.