Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Fix: invalid time-point comparison between each from different clock source #42409

Merged
Merged
Changes from all 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
37 changes: 25 additions & 12 deletions shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#define FML_USED_ON_EMBEDDER

#include <algorithm>
#include <chrono>
#include <ctime>
#include <future>
#include <memory>
#include <thread>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -676,10 +678,14 @@ static void CheckFrameTimings(const std::vector<FrameTiming>& timings,
}

TEST_F(ShellTest, ReportTimingsIsCalled) {
fml::TimePoint start = fml::TimePoint::Now();
auto settings = CreateSettingsForFixture();
std::unique_ptr<Shell> shell = CreateShell(settings);

// We MUST put |start| after |CreateShell| because the clock source will be
// reset through |TimePoint::SetClockSource()| in
// |DartVMInitializer::Initialize()| within |CreateShell()|.
fml::TimePoint start = fml::TimePoint::Now();

// Create the surface needed by rasterizer
PlatformViewNotifyCreated(shell.get());

Expand Down Expand Up @@ -726,19 +732,10 @@ TEST_F(ShellTest, ReportTimingsIsCalled) {
}

TEST_F(ShellTest, FrameRasterizedCallbackIsCalled) {
fml::TimePoint start = fml::TimePoint::Now();

auto settings = CreateSettingsForFixture();
fml::AutoResetWaitableEvent timingLatch;
FrameTiming timing;

for (auto phase : FrameTiming::kPhases) {
timing.Set(phase, fml::TimePoint());
// Check that the time points are initially smaller than start, so
// CheckFrameTimings will fail if they're not properly set later.
ASSERT_TRUE(timing.Get(phase) < start);
}

FrameTiming timing;
fml::AutoResetWaitableEvent timingLatch;
settings.frame_rasterized_callback = [&timing,
&timingLatch](const FrameTiming& t) {
timing = t;
Expand All @@ -747,6 +744,22 @@ TEST_F(ShellTest, FrameRasterizedCallbackIsCalled) {

std::unique_ptr<Shell> shell = CreateShell(settings);

// Wait to make |start| bigger than zero
using namespace std::chrono_literals;
std::this_thread::sleep_for(1ms);

// We MUST put |start| after |CreateShell()| because the clock source will be
// reset through |TimePoint::SetClockSource()| in
// |DartVMInitializer::Initialize()| within |CreateShell()|.
fml::TimePoint start = fml::TimePoint::Now();

for (auto phase : FrameTiming::kPhases) {
timing.Set(phase, fml::TimePoint());
// Check that the time points are initially smaller than start, so
// CheckFrameTimings will fail if they're not properly set later.
ASSERT_TRUE(timing.Get(phase) < start);
}

// Create the surface needed by rasterizer
PlatformViewNotifyCreated(shell.get());

Expand Down