mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-19 22:49:06 -04:00
In some cases, the system wasn't able to turn off because the GUI service got stuck. The device was still working in the background. The cause was an empty queue in DrawCommandQueue which hang the GUI worker. The interface was modified and synchronization mechanism was removed. The thread no longer waits in dequeue(). Also changed the worker to close in the right way the logger worker.
73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include "DrawCommandsQueue.hpp"
|
|
|
|
#include <chrono>
|
|
#include <thread>
|
|
|
|
using namespace service::gui;
|
|
|
|
TEST_CASE("DrawCommandsQueueTests")
|
|
{
|
|
constexpr auto ExpectedQueueSize = 4U;
|
|
DrawCommandsQueue queue{ExpectedQueueSize};
|
|
|
|
SECTION("Enqueue")
|
|
{
|
|
queue.enqueue(DrawCommandsQueue::QueueItem{});
|
|
REQUIRE(queue.size() == 1U);
|
|
}
|
|
|
|
SECTION("Single-thread dequeue")
|
|
{
|
|
queue.enqueue(DrawCommandsQueue::QueueItem{});
|
|
REQUIRE(queue.size() == 1U);
|
|
|
|
const auto item = queue.dequeue();
|
|
REQUIRE(item->commands.empty());
|
|
REQUIRE(item->refreshMode == ::gui::RefreshModes::GUI_REFRESH_FAST);
|
|
REQUIRE(queue.size() == 0);
|
|
}
|
|
|
|
SECTION("Multi-thread dequeue")
|
|
{
|
|
std::thread thr{[&queue]() {
|
|
queue.enqueue(DrawCommandsQueue::QueueItem{});
|
|
}};
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{100});
|
|
const auto item = queue.dequeue();
|
|
if (thr.joinable()) {
|
|
thr.join();
|
|
}
|
|
|
|
REQUIRE(item->commands.empty());
|
|
REQUIRE(item->refreshMode == ::gui::RefreshModes::GUI_REFRESH_FAST);
|
|
REQUIRE(queue.size() == 0U);
|
|
}
|
|
|
|
SECTION("Clear")
|
|
{
|
|
queue.enqueue(DrawCommandsQueue::QueueItem{});
|
|
queue.enqueue(DrawCommandsQueue::QueueItem{});
|
|
REQUIRE(queue.size() == 2U);
|
|
|
|
queue.clear();
|
|
REQUIRE(queue.size() == 0);
|
|
}
|
|
|
|
SECTION("Clear and get max refresh mode")
|
|
{
|
|
queue.enqueue(DrawCommandsQueue::QueueItem{});
|
|
queue.enqueue(DrawCommandsQueue::QueueItem{{}, ::gui::RefreshModes::GUI_REFRESH_DEEP});
|
|
REQUIRE(queue.size() == 2U);
|
|
|
|
const auto maxRefreshMode = queue.getMaxRefreshModeAndClear();
|
|
REQUIRE(queue.size() == 0);
|
|
REQUIRE(maxRefreshMode == ::gui::RefreshModes::GUI_REFRESH_DEEP);
|
|
}
|
|
}
|