datoviz架构升级

This commit is contained in:
2026-08-14 06:22:14 +08:00
parent 02c60679e4
commit ba820afbcb
45 changed files with 3800 additions and 26 deletions
@@ -1,4 +1,7 @@
#include <gtest/gtest.h>
#include <atomic>
#include <chrono>
#include <future>
#include <limits>
#include <stdexcept>
#include "Low_Latency_Strategy_Test_Types.hpp"
@@ -36,6 +39,67 @@ TEST(low_latency_strategy_test, abandons_unconsumed_cached_frame) {
}
EXPECT_EQ(strategy.counter_statistics().abandoned_frame_count, 1);
}
TEST(low_latency_strategy_test, replacement_disabled_preserves_pending_frame_and_wakes_after_renderer_acquire) {
using namespace std::chrono_literals;
Low_Latency_Test_Time_Source time_source;
Low_Latency_Test_Observer observer;
Low_Latency_Test_Strategy strategy{
Low_Latency_Test_Observer_State(observer, time_source), {60.0, false}};
{
auto frame = strategy.acquire_painter();
frame->value = 1;
}
std::promise<void> producer_started;
auto producer_started_future = producer_started.get_future();
auto producer = std::async(std::launch::async, [&] {
producer_started.set_value();
auto frame = strategy.acquire_painter();
frame->value = 2;
});
producer_started_future.wait();
EXPECT_EQ(producer.wait_for(50ms), std::future_status::timeout);
{
auto frame = strategy.acquire_renderer();
ASSERT_TRUE(frame);
EXPECT_EQ(frame->value, 1);
}
ASSERT_EQ(producer.wait_for(1s), std::future_status::ready);
producer.get();
{
auto frame = strategy.acquire_renderer();
ASSERT_TRUE(frame);
EXPECT_EQ(frame->value, 2);
}
EXPECT_EQ(strategy.counter_statistics().abandoned_frame_count, 0u);
}
TEST(low_latency_strategy_test, replacement_disabled_wakes_blocked_producer_after_explicit_discard) {
using namespace std::chrono_literals;
Low_Latency_Test_Time_Source time_source;
Low_Latency_Test_Observer observer;
Low_Latency_Test_Strategy strategy{
Low_Latency_Test_Observer_State(observer, time_source), {60.0, false}};
{
auto frame = strategy.acquire_painter();
frame->value = 1;
}
std::promise<void> producer_started;
auto producer_started_future = producer_started.get_future();
auto producer = std::async(std::launch::async, [&] {
producer_started.set_value();
auto frame = strategy.acquire_painter();
frame->value = 2;
});
producer_started_future.wait();
EXPECT_EQ(producer.wait_for(50ms), std::future_status::timeout);
EXPECT_TRUE(strategy.discard_pending_frame());
ASSERT_EQ(producer.wait_for(1s), std::future_status::ready);
producer.get();
EXPECT_EQ(strategy.counter_statistics().abandoned_frame_count, 0u);
EXPECT_EQ(strategy.counter_statistics().manually_discarded_frame_count, 1u);
}
TEST(low_latency_strategy_test, manually_discards_stale_latest_data_frame) {
Low_Latency_Test_Time_Source time_source;
Low_Latency_Test_Observer observer;
@@ -1,6 +1,8 @@
#include <gtest/gtest.h>
#include <atomic>
#include <chrono>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <vector>
@@ -44,6 +46,40 @@ TEST(manual_refresh_strategy_test, keeps_latest_prepared_frame) {
ASSERT_TRUE(frame);
EXPECT_EQ(frame->value, 2);
}
TEST(manual_refresh_strategy_test, replacement_disabled_waits_for_refresh_and_preserves_order) {
using namespace std::chrono_literals;
Manual_Refresh_Test_Strategy strategy{{}, {false}};
{
auto frame = strategy.acquire_painter();
frame->value = 1;
}
std::promise<void> producer_started;
auto producer_started_future = producer_started.get_future();
auto producer = std::async(std::launch::async, [&] {
producer_started.set_value();
auto frame = strategy.acquire_painter();
frame->value = 2;
});
producer_started_future.wait();
EXPECT_EQ(producer.wait_for(50ms), std::future_status::timeout);
ASSERT_TRUE(strategy.refresh());
ASSERT_EQ(producer.wait_for(1s), std::future_status::ready);
producer.get();
{
auto frame = strategy.acquire_renderer();
ASSERT_TRUE(frame);
EXPECT_EQ(frame->value, 1);
}
EXPECT_EQ(strategy.state().replaced_prepared_frame_count, 0u);
ASSERT_TRUE(strategy.refresh());
{
auto frame = strategy.acquire_renderer();
ASSERT_TRUE(frame);
EXPECT_EQ(frame->value, 2);
}
}
TEST(manual_refresh_strategy_test, reports_failed_refresh_without_pending_frame) {
Manual_Refresh_Test_Strategy strategy;
EXPECT_FALSE(strategy.refresh());