Flutter Engine
fml::testing Namespace Reference

Classes

struct  TaskQueueWrapper
 A mock task queue NOT calling MessageLoop->Run() in thread. More...
 
class  TestWakeable
 

Functions

 TEST (BacktraceTest, CanGatherBacktrace)
 
 TEST (HashCombineTest, CanHash)
 
int UnreachableScopeWithoutReturnDoesNotMakeCompilerMad ()
 
int UnreachableScopeWithMacroWithoutReturnDoesNotMakeCompilerMad ()
 
 TEST (LoggingTest, UnreachableKillProcess)
 
 TEST (LoggingTest, UnreachableKillProcessWithMacro)
 
 TEST (TaskRunnerCheckerTests, RunsOnCurrentTaskRunner)
 
 TEST (TaskRunnerCheckerTests, FailsTheCheckIfOnDifferentTaskRunner)
 
 TEST (TaskRunnerCheckerTests, SameTaskRunnerRunsOnTheSameThread)
 
 TEST (TaskRunnerCheckerTests, RunsOnDifferentThreadsReturnsFalse)
 
 TEST (TaskRunnerCheckerTests, MergedTaskRunnersRunsOnTheSameThread)
 
 TEST (TaskRunnerCheckerTests, PassesRunsOnCreationTaskRunnerIfOnDifferentTaskRunner)
 
static int CountRemainingTasks (fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, AfterMergePrimaryTasksServicedOnPrimary)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, AfterMergeSecondaryTasksAlsoServicedOnPrimary)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, MergeUnmergeTasksPreserved)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, OneCanOwnMultipleQueuesAndUnmergeIndependently)
 Multiple standalone engines scene. More...
 
 TEST (MessageLoopTaskQueueMergeUnmerge, CannotMergeSameQueueToTwoDifferentOwners)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, MergeFailIfAlreadySubsumed)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, MergeFailIfAlreadyOwnsButTryToBeSubsumed)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, UnmergeFailsOnSubsumedOrNeverMerged)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, MergeInvokesBothWakeables)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, MergeUnmergeInvokesBothWakeablesSeparately)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, GetTasksToRunNowBlocksMerge)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, FollowingTasksSwitchQueueIfFirstTaskMergesThreads)
 
 TEST (MessageLoopTaskQueue, StartsWithNoPendingTasks)
 
 TEST (MessageLoopTaskQueue, RegisterOneTask)
 
 TEST (MessageLoopTaskQueue, RegisterTwoTasksAndCount)
 
 TEST (MessageLoopTaskQueue, RegisterTasksOnMergedQueuesAndCount)
 
 TEST (MessageLoopTaskQueue, PreserveTaskOrdering)
 
 TEST (MessageLoopTaskQueue, RegisterTasksOnMergedQueuesPreserveTaskOrdering)
 
 TEST (MessageLoopTaskQueue, UnmergeRespectTheOriginalTaskOrderingInQueues)
 
void TestNotifyObservers (fml::TaskQueueId queue_id)
 
 TEST (MessageLoopTaskQueue, AddRemoveNotifyObservers)
 
 TEST (MessageLoopTaskQueue, WakeUpIndependentOfTime)
 
 TEST (MessageLoopTaskQueue, WokenUpWithNewerTime)
 
 TEST (MessageLoopTaskQueue, NotifyObserversWhileCreatingQueues)
 
 TEST (MessageLoopTaskQueue, QueueDoNotOwnItself)
 
 TEST (MessageLoopTaskQueue, QueueDoNotOwnUnmergedTaskQueueId)
 
 TEST (MessageLoopTaskQueue, QueueOwnsMergedTaskQueueId)
 
 TEST (MessageLoopTaskQueue, ConcurrentQueueAndTaskCreatingCounts)
 
 TEST (MessageLoopTaskQueue, RegisterTaskWakesUpOwnerQueue)
 
 TEST (CFTest, CanCreateRefs)
 
 TEST (RasterThreadMerger, RemainMergedTillLeaseExpires)
 
 TEST (RasterThreadMerger, IsNotOnRasterizingThread)
 
 TEST (RasterThreadMerger, LeaseExtension)
 
 TEST (RasterThreadMerger, WaitUntilMerged)
 
 TEST (RasterThreadMerger, HandleTaskQueuesAreTheSame)
 
 TEST (RasterThreadMerger, Enable)
 
 TEST (RasterThreadMerger, Disable)
 
 TEST (RasterThreadMerger, IsEnabled)
 
 TEST (RasterThreadMerger, TwoMergersWithSameThreadPairShareEnabledState)
 
 TEST (RasterThreadMerger, RunExpiredTasksWhileFirstTaskMergesThreads)
 
 TEST (RasterThreadMerger, RunExpiredTasksWhileFirstTaskUnMergesThreads)
 
 TEST (RasterThreadMerger, SetMergeUnmergeCallback)
 
 TEST (RasterThreadMerger, MultipleMergersCanMergeSameThreadPair)
 
 TEST (RasterThreadMerger, TheLastCallerOfMultipleMergersCanUnmergeNow)
 
 TEST (RasterThreadMerger, TwoIndependentMergersCanMergeTwoDifferentThreadsIntoSamePlatformThread)
 
 TEST (TaskSourceTests, SimpleInitialization)
 
 TEST (TaskSourceTests, MultipleTaskGrades)
 
 TEST (TaskSourceTests, SimpleOrdering)
 
 TEST (TaskSourceTests, SimpleOrderingMultiTaskHeaps)
 
 TEST (TaskSourceTests, OrderingMultiTaskHeapsSecondaryPaused)
 

Function Documentation

◆ CountRemainingTasks()

static int fml::testing::CountRemainingTasks ( fml::RefPtr< MessageLoopTaskQueues task_queue,
const TaskQueueId queue_id,
bool  run_invocation = false 
)
static

Definition at line 30 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::ChronoTicksSinceEpoch().

Referenced by TEST().

32  {
33  const auto now = ChronoTicksSinceEpoch();
34  int count = 0;
35  fml::closure invocation;
36  do {
37  invocation = task_queue->GetNextTaskToRun(queue_id, now);
38  if (!invocation) {
39  break;
40  }
41  count++;
42  if (run_invocation) {
43  invocation();
44  }
45  } while (invocation);
46  return count;
47 }
std::function< void()> closure
Definition: closure.h:14
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [1/59]

fml::testing::TEST ( CFTest  ,
CanCreateRefs   
)

Definition at line 12 of file cf_utils_unittests.mm.

References fml::CFRef< T >::Reset().

12  {
13  CFRef<CFMutableStringRef> string(CFStringCreateMutable(kCFAllocatorDefault, 100u));
14  // Cast
15  ASSERT_TRUE(static_cast<bool>(string));
16  ASSERT_TRUE(string);
17 
18  const auto ref_count = CFGetRetainCount(string);
19 
20  // Copy & Reset
21  {
22  CFRef<CFMutableStringRef> string2 = string;
23  ASSERT_TRUE(string2);
24  ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string));
25  ASSERT_EQ(CFGetRetainCount(string2), CFGetRetainCount(string));
26 
27  string2.Reset();
28  ASSERT_FALSE(string2);
29  ASSERT_EQ(ref_count, CFGetRetainCount(string));
30  }
31 
32  // Release
33  {
34  auto string3 = string;
35  ASSERT_TRUE(string3);
36  ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string));
37  auto raw_string3 = string3.Release();
38  ASSERT_FALSE(string3);
39  ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string));
40  CFRelease(raw_string3);
41  ASSERT_EQ(ref_count, CFGetRetainCount(string));
42  }
43 
44  // Move
45  {
46  auto string_source = string;
47  ASSERT_TRUE(string_source);
48  auto string_move = std::move(string_source);
49  ASSERT_FALSE(string_source);
50  ASSERT_EQ(ref_count + 1u, CFGetRetainCount(string));
51  string_move.Reset();
52  ASSERT_EQ(ref_count, CFGetRetainCount(string));
53  }
54 
55  // Move assign.
56  {
57  auto string_move_assign = std::move(string);
58  ASSERT_FALSE(string);
59  ASSERT_EQ(ref_count, CFGetRetainCount(string_move_assign));
60  }
61 }

◆ TEST() [2/59]

fml::testing::TEST ( HashCombineTest  ,
CanHash   
)

Definition at line 12 of file hash_combine_unittests.cc.

References fml::HashCombine().

12  {
13  ASSERT_EQ(HashCombine(), HashCombine());
14  ASSERT_EQ(HashCombine("Hello"), HashCombine("Hello"));
15  ASSERT_NE(HashCombine("Hello"), HashCombine("World"));
16  ASSERT_EQ(HashCombine("Hello", "World"), HashCombine("Hello", "World"));
17  ASSERT_NE(HashCombine("World", "Hello"), HashCombine("Hello", "World"));
18  ASSERT_EQ(HashCombine(12u), HashCombine(12u));
19  ASSERT_NE(HashCombine(12u), HashCombine(12.0f));
20  ASSERT_EQ(HashCombine('a'), HashCombine('a'));
21 }
constexpr std::size_t HashCombine()
Definition: hash_combine.h:25

◆ TEST() [3/59]

fml::testing::TEST ( BacktraceTest  ,
CanGatherBacktrace   
)

Definition at line 13 of file backtrace_unittests.cc.

References fml::BacktraceHere(), and fml::IsCrashHandlingSupported().

13  {
14  if (!IsCrashHandlingSupported()) {
15  GTEST_SKIP();
16  return;
17  }
18  {
19  auto trace = BacktraceHere(0);
20  ASSERT_GT(trace.size(), 0u);
21  ASSERT_NE(trace.find("Frame 0"), std::string::npos);
22  }
23 
24  {
25  auto trace = BacktraceHere(1);
26  ASSERT_GT(trace.size(), 0u);
27  ASSERT_NE(trace.find("Frame 0"), std::string::npos);
28  }
29 
30  {
31  auto trace = BacktraceHere(2);
32  ASSERT_GT(trace.size(), 0u);
33  ASSERT_NE(trace.find("Frame 0"), std::string::npos);
34  }
35 }
bool IsCrashHandlingSupported()
Definition: backtrace.cc:148
std::string BacktraceHere(size_t offset)
Definition: backtrace.cc:58

◆ TEST() [4/59]

fml::testing::TEST ( TaskSourceTests  ,
SimpleInitialization   
)

Definition at line 18 of file task_source_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::TaskSource::GetNumPendingTasks(), fml::kUnspecified, and fml::TaskSource::RegisterTask().

18  {
19  TaskSource task_source = TaskSource(TaskQueueId(1));
20  task_source.RegisterTask(
21  {1, [] {}, ChronoTicksSinceEpoch(), TaskSourceGrade::kUnspecified});
22  ASSERT_EQ(task_source.GetNumPendingTasks(), 1u);
23 }
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [5/59]

fml::testing::TEST ( TaskRunnerCheckerTests  ,
RunsOnCurrentTaskRunner   
)

Definition at line 20 of file task_runner_checker_unittest.cc.

References fml::TaskRunnerChecker::RunsOnCreationTaskRunner().

20  {
21  TaskRunnerChecker checker;
22  EXPECT_EQ(checker.RunsOnCreationTaskRunner(), true);
23 }

◆ TEST() [6/59]

fml::testing::TEST ( TaskRunnerCheckerTests  ,
FailsTheCheckIfOnDifferentTaskRunner   
)

Definition at line 25 of file task_runner_checker_unittest.cc.

References fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::TaskRunnerChecker::RunsOnCreationTaskRunner(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

25  {
26  TaskRunnerChecker checker;
27  EXPECT_EQ(checker.RunsOnCreationTaskRunner(), true);
28  fml::MessageLoop* loop = nullptr;
30  std::thread anotherThread([&]() {
33  loop->GetTaskRunner()->PostTask([&]() {
34  EXPECT_EQ(checker.RunsOnCreationTaskRunner(), false);
35  latch.Signal();
36  });
37  loop->Run();
38  });
39  latch.Wait();
40  loop->Terminate();
41  anotherThread.join();
42  EXPECT_EQ(checker.RunsOnCreationTaskRunner(), true);
43 }
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27

◆ TEST() [7/59]

fml::testing::TEST ( TaskSourceTests  ,
MultipleTaskGrades   
)

Definition at line 25 of file task_source_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::TaskSource::GetNumPendingTasks(), fml::kDartMicroTasks, fml::kUnspecified, fml::kUserInteraction, and fml::TaskSource::RegisterTask().

25  {
26  TaskSource task_source = TaskSource(TaskQueueId(1));
27  task_source.RegisterTask(
28  {1, [] {}, ChronoTicksSinceEpoch(), TaskSourceGrade::kUnspecified});
29  task_source.RegisterTask(
30  {2, [] {}, ChronoTicksSinceEpoch(), TaskSourceGrade::kUserInteraction});
31  task_source.RegisterTask(
32  {3, [] {}, ChronoTicksSinceEpoch(), TaskSourceGrade::kDartMicroTasks});
33  ASSERT_EQ(task_source.GetNumPendingTasks(), 3u);
34 }
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [8/59]

fml::testing::TEST ( LoggingTest  ,
UnreachableKillProcess   
)

Definition at line 32 of file logging_unittests.cc.

References fml::KillProcess().

32  {
33  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
34  ASSERT_DEATH(KillProcess(), "");
35 }
void KillProcess()
Definition: logging.cc:142

◆ TEST() [9/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
StartsWithNoPendingTasks   
)

Definition at line 33 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

33  {
34  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
35  auto queue_id = task_queue->CreateTaskQueue();
36  ASSERT_FALSE(task_queue->HasPendingTasks(queue_id));
37 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [10/59]

fml::testing::TEST ( TaskSourceTests  ,
SimpleOrdering   
)

Definition at line 36 of file task_source_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::TimeDelta::FromMilliseconds(), fml::DelayedTask::GetTask(), fml::kUnspecified, fml::TaskSource::PopTask(), fml::TaskSource::RegisterTask(), fml::TaskSource::TopTask::task, fml::TaskSource::Top(), and value.

36  {
37  TaskSource task_source = TaskSource(TaskQueueId(1));
38  auto time_stamp = ChronoTicksSinceEpoch();
39  int value = 0;
40  task_source.RegisterTask(
41  {1, [&] { value = 1; }, time_stamp, TaskSourceGrade::kUnspecified});
42  task_source.RegisterTask({2, [&] { value = 7; },
43  time_stamp + fml::TimeDelta::FromMilliseconds(1),
44  TaskSourceGrade::kUnspecified});
45  task_source.Top().task.GetTask()();
46  task_source.PopTask(TaskSourceGrade::kUnspecified);
47  ASSERT_EQ(value, 1);
48  task_source.Top().task.GetTask()();
49  task_source.PopTask(TaskSourceGrade::kUnspecified);
50  ASSERT_EQ(value, 7);
51 }
uint8_t value
fml::TimePoint ChronoTicksSinceEpoch()
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46

◆ TEST() [11/59]

fml::testing::TEST ( LoggingTest  ,
UnreachableKillProcessWithMacro   
)

Definition at line 37 of file logging_unittests.cc.

References FML_LOG, FML_UNREACHABLE, FML_VLOG, result, fml::SetLogSettings(), and flutter::testing::TEST_F().

37  {
38  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
39  ASSERT_DEATH({ FML_UNREACHABLE(); }, "");
40 }
#define FML_UNREACHABLE()
Definition: logging.h:92

◆ TEST() [12/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
RegisterOneTask   
)

Definition at line 39 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance(), fml::TimePoint::Max(), and fml::testing::TestWakeable::TestWakeable().

39  {
40  const auto time = fml::TimePoint::Max();
41 
42  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
43  auto queue_id = task_queue->CreateTaskQueue();
44  task_queue->SetWakeable(queue_id,
45  new TestWakeable([&time](fml::TimePoint wake_time) {
46  ASSERT_TRUE(wake_time == time);
47  }));
48 
49  task_queue->RegisterTask(
50  queue_id, [] {}, time);
51  ASSERT_TRUE(task_queue->HasPendingTasks(queue_id));
52  ASSERT_TRUE(task_queue->GetNumPendingTasks(queue_id) == 1);
53 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static constexpr TimePoint Max()
Definition: time_point.h:34

◆ TEST() [13/59]

fml::testing::TEST ( TaskRunnerCheckerTests  ,
SameTaskRunnerRunsOnTheSameThread   
)

Definition at line 45 of file task_runner_checker_unittest.cc.

References fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::TaskRunner::GetTaskQueueId(), fml::MessageLoop::GetTaskRunner(), and fml::TaskRunnerChecker::RunsOnTheSameThread().

45  {
49  TaskQueueId a = loop1.GetTaskRunner()->GetTaskQueueId();
50  TaskQueueId b = loop2.GetTaskRunner()->GetTaskQueueId();
51  EXPECT_EQ(TaskRunnerChecker::RunsOnTheSameThread(a, b), true);
52 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56

◆ TEST() [14/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
AfterMergePrimaryTasksServicedOnPrimary   
)

Definition at line 49 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::ChronoTicksSinceEpoch(), and fml::MessageLoopTaskQueues::GetInstance().

50  {
51  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
52 
53  auto queue_id_1 = task_queue->CreateTaskQueue();
54  auto queue_id_2 = task_queue->CreateTaskQueue();
55 
56  task_queue->RegisterTask(
57  queue_id_1, []() {}, ChronoTicksSinceEpoch());
58  ASSERT_EQ(1u, task_queue->GetNumPendingTasks(queue_id_1));
59 
60  task_queue->Merge(queue_id_1, queue_id_2);
61  task_queue->RegisterTask(
62  queue_id_1, []() {}, ChronoTicksSinceEpoch());
63 
64  ASSERT_EQ(2u, task_queue->GetNumPendingTasks(queue_id_1));
65  ASSERT_EQ(0u, task_queue->GetNumPendingTasks(queue_id_2));
66 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [15/59]

fml::testing::TEST ( TaskSourceTests  ,
SimpleOrderingMultiTaskHeaps   
)

Definition at line 53 of file task_source_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::TimeDelta::FromMilliseconds(), fml::DelayedTask::GetTask(), fml::kDartMicroTasks, fml::kUserInteraction, fml::TaskSource::PopTask(), fml::TaskSource::RegisterTask(), fml::TaskSource::TopTask::task, fml::TaskSource::Top(), and value.

53  {
54  TaskSource task_source = TaskSource(TaskQueueId(1));
55  auto time_stamp = ChronoTicksSinceEpoch();
56  int value = 0;
57  task_source.RegisterTask(
58  {1, [&] { value = 1; }, time_stamp, TaskSourceGrade::kDartMicroTasks});
59  task_source.RegisterTask({2, [&] { value = 7; },
60  time_stamp + fml::TimeDelta::FromMilliseconds(1),
61  TaskSourceGrade::kUserInteraction});
62  auto top_task = task_source.Top();
63  top_task.task.GetTask()();
64  task_source.PopTask(top_task.task.GetTaskSourceGrade());
65  ASSERT_EQ(value, 1);
66 
67  auto second_task = task_source.Top();
68  second_task.task.GetTask()();
69  task_source.PopTask(second_task.task.GetTaskSourceGrade());
70  ASSERT_EQ(value, 7);
71 }
uint8_t value
fml::TimePoint ChronoTicksSinceEpoch()
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46

◆ TEST() [16/59]

fml::testing::TEST ( TaskRunnerCheckerTests  ,
RunsOnDifferentThreadsReturnsFalse   
)

Definition at line 54 of file task_runner_checker_unittest.cc.

References fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::TaskRunner::GetTaskQueueId(), fml::MessageLoop::GetTaskRunner(), fml::TaskRunnerChecker::RunsOnTheSameThread(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

54  {
57  TaskQueueId a = loop1.GetTaskRunner()->GetTaskQueueId();
59  std::thread anotherThread([&]() {
62  TaskQueueId b = loop2.GetTaskRunner()->GetTaskQueueId();
63  EXPECT_EQ(TaskRunnerChecker::RunsOnTheSameThread(a, b), false);
64  latch.Signal();
65  });
66  latch.Wait();
67  anotherThread.join();
68 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56

◆ TEST() [17/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
RegisterTwoTasksAndCount   
)

Definition at line 55 of file message_loop_task_queues_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::MessageLoopTaskQueues::GetInstance(), and fml::TimePoint::Max().

55  {
56  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
57  auto queue_id = task_queue->CreateTaskQueue();
58  task_queue->RegisterTask(
59  queue_id, [] {}, ChronoTicksSinceEpoch());
60  task_queue->RegisterTask(
61  queue_id, [] {}, fml::TimePoint::Max());
62  ASSERT_TRUE(task_queue->HasPendingTasks(queue_id));
63  ASSERT_TRUE(task_queue->GetNumPendingTasks(queue_id) == 2);
64 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static constexpr TimePoint Max()
Definition: time_point.h:34
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [18/59]

fml::testing::TEST ( RasterThreadMerger  ,
RemainMergedTillLeaseExpires   
)

Definition at line 58 of file raster_thread_merger_unittests.cc.

References fml::testing::TaskQueueWrapper::GetTaskQueueId().

58  {
59  TaskQueueWrapper queue1;
60  TaskQueueWrapper queue2;
61  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
62  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
63  const auto raster_thread_merger =
64  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
65  const size_t kNumFramesMerged = 5;
66 
67  ASSERT_FALSE(raster_thread_merger->IsMerged());
68 
69  raster_thread_merger->MergeWithLease(kNumFramesMerged);
70 
71  for (size_t i = 0; i < kNumFramesMerged; i++) {
72  ASSERT_TRUE(raster_thread_merger->IsMerged());
73  raster_thread_merger->DecrementLease();
74  }
75 
76  ASSERT_FALSE(raster_thread_merger->IsMerged());
77 }

◆ TEST() [19/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
RegisterTasksOnMergedQueuesAndCount   
)

Definition at line 66 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance(), and fml::TimePoint::Now().

66  {
67  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
68  auto platform_queue = task_queue->CreateTaskQueue();
69  auto raster_queue = task_queue->CreateTaskQueue();
70  // A task in platform_queue
71  task_queue->RegisterTask(
72  platform_queue, []() {}, fml::TimePoint::Now());
73  // A task in raster_queue
74  task_queue->RegisterTask(
75  raster_queue, []() {}, fml::TimePoint::Now());
76  ASSERT_TRUE(task_queue->GetNumPendingTasks(platform_queue) == 1);
77  ASSERT_TRUE(task_queue->GetNumPendingTasks(raster_queue) == 1);
78 
79  ASSERT_FALSE(task_queue->Owns(platform_queue, raster_queue));
80  task_queue->Merge(platform_queue, raster_queue);
81  ASSERT_TRUE(task_queue->Owns(platform_queue, raster_queue));
82 
83  ASSERT_TRUE(task_queue->HasPendingTasks(platform_queue));
84  ASSERT_TRUE(task_queue->GetNumPendingTasks(platform_queue) == 2);
85  // The task count of subsumed queue is 0
86  ASSERT_FALSE(task_queue->HasPendingTasks(raster_queue));
87  ASSERT_TRUE(task_queue->GetNumPendingTasks(raster_queue) == 0);
88 
89  task_queue->Unmerge(platform_queue, raster_queue);
90  ASSERT_FALSE(task_queue->Owns(platform_queue, raster_queue));
91  ASSERT_TRUE(task_queue->GetNumPendingTasks(platform_queue) == 1);
92  ASSERT_TRUE(task_queue->GetNumPendingTasks(raster_queue) == 1);
93 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static TimePoint Now()
Definition: time_point.cc:39

◆ TEST() [20/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
AfterMergeSecondaryTasksAlsoServicedOnPrimary   
)

Definition at line 68 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::ChronoTicksSinceEpoch(), and fml::MessageLoopTaskQueues::GetInstance().

69  {
70  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
71 
72  auto queue_id_1 = task_queue->CreateTaskQueue();
73  auto queue_id_2 = task_queue->CreateTaskQueue();
74 
75  task_queue->RegisterTask(
76  queue_id_2, []() {}, ChronoTicksSinceEpoch());
77  ASSERT_EQ(1u, task_queue->GetNumPendingTasks(queue_id_2));
78 
79  task_queue->Merge(queue_id_1, queue_id_2);
80  ASSERT_EQ(1u, task_queue->GetNumPendingTasks(queue_id_1));
81  ASSERT_EQ(0u, task_queue->GetNumPendingTasks(queue_id_2));
82 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [21/59]

fml::testing::TEST ( TaskRunnerCheckerTests  ,
MergedTaskRunnersRunsOnTheSameThread   
)

Definition at line 70 of file task_runner_checker_unittest.cc.

References fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::TaskRunner::GetTaskQueueId(), fml::MessageLoop::GetTaskRunner(), fml::TaskRunnerChecker::RunsOnTheSameThread(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

70  {
71  fml::MessageLoop* loop1 = nullptr;
74  std::thread thread1([&loop1, &latch1, &term1]() {
77  latch1.Signal();
78  term1.Wait();
79  });
80 
81  fml::MessageLoop* loop2 = nullptr;
84  std::thread thread2([&loop2, &latch2, &term2]() {
87  latch2.Signal();
88  term2.Wait();
89  });
90 
91  latch1.Wait();
92  latch2.Wait();
94  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
95  const auto raster_thread_merger_ =
96  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
97  const size_t kNumFramesMerged = 5;
98 
99  raster_thread_merger_->MergeWithLease(kNumFramesMerged);
100 
101  // merged, running on the same thread
102  EXPECT_EQ(TaskRunnerChecker::RunsOnTheSameThread(qid1, qid2), true);
103 
104  for (size_t i = 0; i < kNumFramesMerged; i++) {
105  ASSERT_TRUE(raster_thread_merger_->IsMerged());
106  raster_thread_merger_->DecrementLease();
107  }
108 
109  ASSERT_FALSE(raster_thread_merger_->IsMerged());
110 
111  // un-merged, not running on the same thread
112  EXPECT_EQ(TaskRunnerChecker::RunsOnTheSameThread(qid1, qid2), false);
113 
114  term1.Signal();
115  term2.Signal();
116  thread1.join();
117  thread2.join();
118 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56

◆ TEST() [22/59]

fml::testing::TEST ( TaskSourceTests  ,
OrderingMultiTaskHeapsSecondaryPaused   
)

Definition at line 73 of file task_source_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::TimeDelta::FromMilliseconds(), fml::DelayedTask::GetTask(), fml::TaskSource::IsEmpty(), fml::kDartMicroTasks, fml::kUserInteraction, fml::TaskSource::PauseSecondary(), fml::TaskSource::PopTask(), fml::TaskSource::RegisterTask(), fml::TaskSource::ResumeSecondary(), fml::TaskSource::TopTask::task, fml::TaskSource::Top(), and value.

73  {
74  TaskSource task_source = TaskSource(TaskQueueId(1));
75  auto time_stamp = ChronoTicksSinceEpoch();
76  int value = 0;
77  task_source.RegisterTask(
78  {1, [&] { value = 1; }, time_stamp, TaskSourceGrade::kDartMicroTasks});
79  task_source.RegisterTask({2, [&] { value = 7; },
80  time_stamp + fml::TimeDelta::FromMilliseconds(1),
81  TaskSourceGrade::kUserInteraction});
82 
83  task_source.PauseSecondary();
84 
85  auto top_task = task_source.Top();
86  top_task.task.GetTask()();
87  task_source.PopTask(top_task.task.GetTaskSourceGrade());
88  ASSERT_EQ(value, 7);
89 
90  ASSERT_TRUE(task_source.IsEmpty());
91 
92  task_source.ResumeSecondary();
93 
94  auto second_task = task_source.Top();
95  second_task.task.GetTask()();
96  task_source.PopTask(second_task.task.GetTaskSourceGrade());
97  ASSERT_EQ(value, 1);
98 }
uint8_t value
fml::TimePoint ChronoTicksSinceEpoch()
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46

◆ TEST() [23/59]

fml::testing::TEST ( RasterThreadMerger  ,
IsNotOnRasterizingThread   
)

Definition at line 79 of file raster_thread_merger_unittests.cc.

References fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::MessageLoop::GetCurrentTaskQueueId(), fml::TaskRunner::GetTaskQueueId(), fml::MessageLoop::GetTaskRunner(), fml::TaskRunner::PostTask(), fml::MessageLoop::Run(), fml::AutoResetWaitableEvent::Signal(), fml::MessageLoop::Terminate(), and fml::AutoResetWaitableEvent::Wait().

79  {
80  fml::MessageLoop* loop1 = nullptr;
82  std::thread thread1([&loop1, &latch1]() {
85  loop1->GetTaskRunner()->PostTask([&]() { latch1.Signal(); });
86  loop1->Run();
87  });
88 
89  fml::MessageLoop* loop2 = nullptr;
91  std::thread thread2([&loop2, &latch2]() {
94  loop2->GetTaskRunner()->PostTask([&]() { latch2.Signal(); });
95  loop2->Run();
96  });
97 
98  latch1.Wait();
99  latch2.Wait();
100 
101  fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
102  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
103  const auto raster_thread_merger =
104  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
105 
106  fml::CountDownLatch pre_merge(2), post_merge(2), post_unmerge(2);
107 
108  loop1->GetTaskRunner()->PostTask([&]() {
109  ASSERT_FALSE(raster_thread_merger->IsOnRasterizingThread());
110  ASSERT_TRUE(raster_thread_merger->IsOnPlatformThread());
111  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid1);
112  pre_merge.CountDown();
113  });
114 
115  loop2->GetTaskRunner()->PostTask([&]() {
116  ASSERT_TRUE(raster_thread_merger->IsOnRasterizingThread());
117  ASSERT_FALSE(raster_thread_merger->IsOnPlatformThread());
118  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid2);
119  pre_merge.CountDown();
120  });
121 
122  pre_merge.Wait();
123 
124  raster_thread_merger->MergeWithLease(1);
125 
126  loop1->GetTaskRunner()->PostTask([&]() {
127  ASSERT_TRUE(raster_thread_merger->IsOnRasterizingThread());
128  ASSERT_TRUE(raster_thread_merger->IsOnPlatformThread());
129  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid1);
130  post_merge.CountDown();
131  });
132 
133  loop2->GetTaskRunner()->PostTask([&]() {
134  // this will be false since this is going to be run
135  // on loop1 really.
136  ASSERT_TRUE(raster_thread_merger->IsOnRasterizingThread());
137  ASSERT_TRUE(raster_thread_merger->IsOnPlatformThread());
138  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid1);
139  post_merge.CountDown();
140  });
141 
142  post_merge.Wait();
143 
144  raster_thread_merger->DecrementLease();
145 
146  loop1->GetTaskRunner()->PostTask([&]() {
147  ASSERT_FALSE(raster_thread_merger->IsOnRasterizingThread());
148  ASSERT_TRUE(raster_thread_merger->IsOnPlatformThread());
149  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid1);
150  post_unmerge.CountDown();
151  });
152 
153  loop2->GetTaskRunner()->PostTask([&]() {
154  ASSERT_TRUE(raster_thread_merger->IsOnRasterizingThread());
155  ASSERT_FALSE(raster_thread_merger->IsOnPlatformThread());
156  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid2);
157  post_unmerge.CountDown();
158  });
159 
160  post_unmerge.Wait();
161 
162  loop1->GetTaskRunner()->PostTask([&]() { loop1->Terminate(); });
163 
164  loop2->GetTaskRunner()->PostTask([&]() { loop2->Terminate(); });
165 
166  thread1.join();
167  thread2.join();
168 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56
static TaskQueueId GetCurrentTaskQueueId()
Definition: message_loop.cc:76
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24

◆ TEST() [24/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
MergeUnmergeTasksPreserved   
)

Definition at line 84 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::ChronoTicksSinceEpoch(), and fml::MessageLoopTaskQueues::GetInstance().

84  {
85  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
86 
87  auto queue_id_1 = task_queue->CreateTaskQueue();
88  auto queue_id_2 = task_queue->CreateTaskQueue();
89 
90  task_queue->RegisterTask(
91  queue_id_1, []() {}, ChronoTicksSinceEpoch());
92  task_queue->RegisterTask(
93  queue_id_2, []() {}, ChronoTicksSinceEpoch());
94 
95  ASSERT_EQ(1u, task_queue->GetNumPendingTasks(queue_id_1));
96  ASSERT_EQ(1u, task_queue->GetNumPendingTasks(queue_id_2));
97 
98  task_queue->Merge(queue_id_1, queue_id_2);
99 
100  ASSERT_EQ(2u, task_queue->GetNumPendingTasks(queue_id_1));
101  ASSERT_EQ(0u, task_queue->GetNumPendingTasks(queue_id_2));
102 
103  task_queue->Unmerge(queue_id_1, queue_id_2);
104 
105  ASSERT_EQ(1u, task_queue->GetNumPendingTasks(queue_id_1));
106  ASSERT_EQ(1u, task_queue->GetNumPendingTasks(queue_id_2));
107 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [25/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
PreserveTaskOrdering   
)

Definition at line 95 of file message_loop_task_queues_unittests.cc.

References fml::ChronoTicksSinceEpoch(), expected_value, and fml::MessageLoopTaskQueues::GetInstance().

95  {
96  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
97  auto queue_id = task_queue->CreateTaskQueue();
98  int test_val = 0;
99 
100  // order: 0
101  task_queue->RegisterTask(
102  queue_id, [&test_val]() { test_val = 1; }, ChronoTicksSinceEpoch());
103 
104  // order: 1
105  task_queue->RegisterTask(
106  queue_id, [&test_val]() { test_val = 2; }, ChronoTicksSinceEpoch());
107 
108  const auto now = ChronoTicksSinceEpoch();
109  int expected_value = 1;
110  while (true) {
111  fml::closure invocation = task_queue->GetNextTaskToRun(queue_id, now);
112  if (!invocation) {
113  break;
114  }
115  invocation();
116  ASSERT_TRUE(test_val == expected_value);
117  expected_value++;
118  }
119 }
std::function< void()> closure
Definition: closure.h:14
static const char * expected_value
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [26/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
OneCanOwnMultipleQueuesAndUnmergeIndependently   
)

Multiple standalone engines scene.

Definition at line 110 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

111  {
112  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
113  auto queue_id_1 = task_queue->CreateTaskQueue();
114  auto queue_id_2 = task_queue->CreateTaskQueue();
115  auto queue_id_3 = task_queue->CreateTaskQueue();
116 
117  // merge
118  ASSERT_TRUE(task_queue->Merge(queue_id_1, queue_id_2));
119  ASSERT_TRUE(task_queue->Owns(queue_id_1, queue_id_2));
120  ASSERT_FALSE(task_queue->Owns(queue_id_1, queue_id_3));
121 
122  ASSERT_TRUE(task_queue->Merge(queue_id_1, queue_id_3));
123  ASSERT_TRUE(task_queue->Owns(queue_id_1, queue_id_2));
124  ASSERT_TRUE(task_queue->Owns(queue_id_1, queue_id_3));
125 
126  // unmerge
127  ASSERT_TRUE(task_queue->Unmerge(queue_id_1, queue_id_2));
128  ASSERT_FALSE(task_queue->Owns(queue_id_1, queue_id_2));
129  ASSERT_TRUE(task_queue->Owns(queue_id_1, queue_id_3));
130 
131  ASSERT_TRUE(task_queue->Unmerge(queue_id_1, queue_id_3));
132  ASSERT_FALSE(task_queue->Owns(queue_id_1, queue_id_2));
133  ASSERT_FALSE(task_queue->Owns(queue_id_1, queue_id_3));
134 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [27/59]

fml::testing::TEST ( TaskRunnerCheckerTests  ,
PassesRunsOnCreationTaskRunnerIfOnDifferentTaskRunner   
)

Definition at line 120 of file task_runner_checker_unittest.cc.

References fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::MessageLoopTaskQueues::GetInstance(), fml::TaskRunner::GetTaskQueueId(), fml::MessageLoop::GetTaskRunner(), fml::MessageLoop::Run(), fml::AutoResetWaitableEvent::Signal(), fml::MessageLoop::Terminate(), and fml::AutoResetWaitableEvent::Wait().

121  {
122  fml::MessageLoop* loop1 = nullptr;
124  std::thread thread1([&]() {
126  loop1 = &fml::MessageLoop::GetCurrent();
127  latch1.Signal();
128  loop1->Run();
129  });
130 
131  fml::MessageLoop* loop2 = nullptr;
133  std::thread thread2([&]() {
135  loop2 = &fml::MessageLoop::GetCurrent();
136  latch2.Signal();
137  loop2->Run();
138  });
139 
140  latch1.Wait();
141  latch2.Wait();
142 
143  fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
144  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
145  fml::MessageLoopTaskQueues::GetInstance()->Merge(qid1, qid2);
146 
147  std::unique_ptr<TaskRunnerChecker> checker;
148 
150  loop2->GetTaskRunner()->PostTask([&]() {
151  checker = std::make_unique<TaskRunnerChecker>();
152  EXPECT_EQ(checker->RunsOnCreationTaskRunner(), true);
153  latch3.Signal();
154  });
155  latch3.Wait();
156 
157  fml::MessageLoopTaskQueues::GetInstance()->Unmerge(qid1, qid2);
158 
160  loop2->GetTaskRunner()->PostTask([&]() {
161  EXPECT_EQ(checker->RunsOnCreationTaskRunner(), true);
162  latch4.Signal();
163  });
164  latch4.Wait();
165 
166  loop1->Terminate();
167  loop2->Terminate();
168  thread1.join();
169  thread2.join();
170 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [28/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
RegisterTasksOnMergedQueuesPreserveTaskOrdering   
)

Definition at line 121 of file message_loop_task_queues_unittests.cc.

References expected_value, fml::MessageLoopTaskQueues::GetInstance(), and fml::TimePoint::Now().

121  {
122  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
123  auto platform_queue = task_queue->CreateTaskQueue();
124  auto raster1_queue = task_queue->CreateTaskQueue();
125  auto raster2_queue = task_queue->CreateTaskQueue();
126  int test_val = 0;
127 
128  // order 0 in raster1_queue
129  task_queue->RegisterTask(
130  raster1_queue, [&test_val]() { test_val = 0; }, fml::TimePoint::Now());
131 
132  // order 1 in platform_queue
133  task_queue->RegisterTask(
134  platform_queue, [&test_val]() { test_val = 1; }, fml::TimePoint::Now());
135 
136  // order 2 in raster2_queue
137  task_queue->RegisterTask(
138  raster2_queue, [&test_val]() { test_val = 2; }, fml::TimePoint::Now());
139 
140  task_queue->Merge(platform_queue, raster1_queue);
141  ASSERT_TRUE(task_queue->Owns(platform_queue, raster1_queue));
142  task_queue->Merge(platform_queue, raster2_queue);
143  ASSERT_TRUE(task_queue->Owns(platform_queue, raster2_queue));
144  const auto now = fml::TimePoint::Now();
145  int expected_value = 0;
146  // Right order:
147  // "test_val = 0" in raster1_queue
148  // "test_val = 1" in platform_queue
149  // "test_val = 2" in raster2_queue
150  while (true) {
151  fml::closure invocation = task_queue->GetNextTaskToRun(platform_queue, now);
152  if (!invocation) {
153  break;
154  }
155  invocation();
156  ASSERT_TRUE(test_val == expected_value);
157  expected_value++;
158  }
159 }
std::function< void()> closure
Definition: closure.h:14
static const char * expected_value
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static TimePoint Now()
Definition: time_point.cc:39

◆ TEST() [29/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
CannotMergeSameQueueToTwoDifferentOwners   
)

Definition at line 136 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

137  {
138  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
139  auto queue = task_queue->CreateTaskQueue();
140  auto owner_1 = task_queue->CreateTaskQueue();
141  auto owner_2 = task_queue->CreateTaskQueue();
142 
143  ASSERT_TRUE(task_queue->Merge(owner_1, queue));
144  ASSERT_FALSE(task_queue->Merge(owner_2, queue));
145 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [30/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
MergeFailIfAlreadySubsumed   
)

Definition at line 147 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

147  {
148  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
149 
150  auto queue_id_1 = task_queue->CreateTaskQueue();
151  auto queue_id_2 = task_queue->CreateTaskQueue();
152  auto queue_id_3 = task_queue->CreateTaskQueue();
153 
154  ASSERT_TRUE(task_queue->Merge(queue_id_1, queue_id_2));
155  ASSERT_FALSE(task_queue->Merge(queue_id_2, queue_id_3));
156  ASSERT_FALSE(task_queue->Merge(queue_id_2, queue_id_1));
157 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [31/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
MergeFailIfAlreadyOwnsButTryToBeSubsumed   
)

Definition at line 159 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

160  {
161  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
162 
163  auto queue_id_1 = task_queue->CreateTaskQueue();
164  auto queue_id_2 = task_queue->CreateTaskQueue();
165  auto queue_id_3 = task_queue->CreateTaskQueue();
166 
167  task_queue->Merge(queue_id_1, queue_id_2);
168  // A recursively linked merging will fail
169  ASSERT_FALSE(task_queue->Merge(queue_id_3, queue_id_1));
170 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [32/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
UnmergeRespectTheOriginalTaskOrderingInQueues   
)

Definition at line 161 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance(), and fml::TimePoint::Now().

161  {
162  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
163  auto platform_queue = task_queue->CreateTaskQueue();
164  auto raster_queue = task_queue->CreateTaskQueue();
165  int test_val = 0;
166 
167  // order 0 in platform_queue
168  task_queue->RegisterTask(
169  platform_queue, [&test_val]() { test_val = 0; }, fml::TimePoint::Now());
170  // order 1 in platform_queue
171  task_queue->RegisterTask(
172  platform_queue, [&test_val]() { test_val = 1; }, fml::TimePoint::Now());
173  // order 2 in raster_queue
174  task_queue->RegisterTask(
175  raster_queue, [&test_val]() { test_val = 2; }, fml::TimePoint::Now());
176  // order 3 in raster_queue
177  task_queue->RegisterTask(
178  raster_queue, [&test_val]() { test_val = 3; }, fml::TimePoint::Now());
179  // order 4 in platform_queue
180  task_queue->RegisterTask(
181  platform_queue, [&test_val]() { test_val = 4; }, fml::TimePoint::Now());
182  // order 5 in raster_queue
183  task_queue->RegisterTask(
184  raster_queue, [&test_val]() { test_val = 5; }, fml::TimePoint::Now());
185 
186  ASSERT_TRUE(task_queue->Merge(platform_queue, raster_queue));
187  ASSERT_TRUE(task_queue->Owns(platform_queue, raster_queue));
188  const auto now = fml::TimePoint::Now();
189  // The right order after merged and consumed 3 tasks:
190  // "test_val = 0" in platform_queue
191  // "test_val = 1" in platform_queue
192  // "test_val = 2" in raster_queue (running on platform)
193  for (int i = 0; i < 3; i++) {
194  fml::closure invocation = task_queue->GetNextTaskToRun(platform_queue, now);
195  ASSERT_FALSE(!invocation);
196  invocation();
197  ASSERT_TRUE(test_val == i);
198  }
199  ASSERT_TRUE(task_queue->GetNumPendingTasks(platform_queue) == 3);
200  ASSERT_TRUE(task_queue->GetNumPendingTasks(raster_queue) == 0);
201 
202  ASSERT_TRUE(task_queue->Unmerge(platform_queue, raster_queue));
203  ASSERT_FALSE(task_queue->Owns(platform_queue, raster_queue));
204 
205  // The right order after unmerged and left 3 tasks:
206  // "test_val = 3" in raster_queue
207  // "test_val = 4" in platform_queue
208  // "test_val = 5" in raster_queue
209 
210  // platform_queue has 1 task left: "test_val = 4"
211  {
212  ASSERT_TRUE(task_queue->GetNumPendingTasks(platform_queue) == 1);
213  fml::closure invocation = task_queue->GetNextTaskToRun(platform_queue, now);
214  ASSERT_FALSE(!invocation);
215  invocation();
216  ASSERT_TRUE(test_val == 4);
217  ASSERT_TRUE(task_queue->GetNumPendingTasks(platform_queue) == 0);
218  }
219 
220  // raster_queue has 2 tasks left: "test_val = 3" and "test_val = 5"
221  {
222  ASSERT_TRUE(task_queue->GetNumPendingTasks(raster_queue) == 2);
223  fml::closure invocation = task_queue->GetNextTaskToRun(raster_queue, now);
224  ASSERT_FALSE(!invocation);
225  invocation();
226  ASSERT_TRUE(test_val == 3);
227  }
228  {
229  ASSERT_TRUE(task_queue->GetNumPendingTasks(raster_queue) == 1);
230  fml::closure invocation = task_queue->GetNextTaskToRun(raster_queue, now);
231  ASSERT_FALSE(!invocation);
232  invocation();
233  ASSERT_TRUE(test_val == 5);
234  ASSERT_TRUE(task_queue->GetNumPendingTasks(raster_queue) == 0);
235  }
236 }
std::function< void()> closure
Definition: closure.h:14
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static TimePoint Now()
Definition: time_point.cc:39

◆ TEST() [33/59]

fml::testing::TEST ( RasterThreadMerger  ,
LeaseExtension   
)

Definition at line 170 of file raster_thread_merger_unittests.cc.

References fml::testing::TaskQueueWrapper::GetTaskQueueId().

170  {
171  TaskQueueWrapper queue1;
172  TaskQueueWrapper queue2;
173 
174  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
175  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
176  const auto raster_thread_merger =
177  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
178  const size_t kNumFramesMerged = 5;
179 
180  ASSERT_FALSE(raster_thread_merger->IsMerged());
181 
182  raster_thread_merger->MergeWithLease(kNumFramesMerged);
183 
184  // let there be one more turn till the leases expire.
185  for (size_t i = 0; i < kNumFramesMerged - 1; i++) {
186  ASSERT_TRUE(raster_thread_merger->IsMerged());
187  raster_thread_merger->DecrementLease();
188  }
189 
190  // extend the lease once.
191  raster_thread_merger->ExtendLeaseTo(kNumFramesMerged);
192 
193  // we will NOT last for 1 extra turn, we just set it.
194  for (size_t i = 0; i < kNumFramesMerged; i++) {
195  ASSERT_TRUE(raster_thread_merger->IsMerged());
196  raster_thread_merger->DecrementLease();
197  }
198 
199  ASSERT_FALSE(raster_thread_merger->IsMerged());
200 }

◆ TEST() [34/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
UnmergeFailsOnSubsumedOrNeverMerged   
)

Definition at line 172 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

172  {
173  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
174 
175  auto queue_id_1 = task_queue->CreateTaskQueue();
176  auto queue_id_2 = task_queue->CreateTaskQueue();
177  auto queue_id_3 = task_queue->CreateTaskQueue();
178 
179  task_queue->Merge(queue_id_1, queue_id_2);
180  ASSERT_FALSE(task_queue->Unmerge(queue_id_2, queue_id_3));
181  ASSERT_FALSE(task_queue->Unmerge(queue_id_1, queue_id_3));
182  ASSERT_FALSE(task_queue->Unmerge(queue_id_3, queue_id_1));
183  ASSERT_FALSE(task_queue->Unmerge(queue_id_2, queue_id_1));
184 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [35/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
MergeInvokesBothWakeables   
)

Definition at line 186 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::CountDownLatch::CountDown(), CountRemainingTasks(), fml::MessageLoopTaskQueues::GetInstance(), fml::testing::TestWakeable::TestWakeable(), and fml::CountDownLatch::Wait().

186  {
187  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
188 
189  auto queue_id_1 = task_queue->CreateTaskQueue();
190  auto queue_id_2 = task_queue->CreateTaskQueue();
191 
192  fml::CountDownLatch latch(2);
193 
194  task_queue->SetWakeable(
195  queue_id_1,
196  new TestWakeable([&](fml::TimePoint wake_time) { latch.CountDown(); }));
197  task_queue->SetWakeable(
198  queue_id_2,
199  new TestWakeable([&](fml::TimePoint wake_time) { latch.CountDown(); }));
200 
201  task_queue->RegisterTask(
202  queue_id_1, []() {}, ChronoTicksSinceEpoch());
203 
204  task_queue->Merge(queue_id_1, queue_id_2);
205 
206  CountRemainingTasks(task_queue, queue_id_1);
207 
208  latch.Wait();
209 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()
static int CountRemainingTasks(fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)

◆ TEST() [36/59]

fml::testing::TEST ( RasterThreadMerger  ,
WaitUntilMerged   
)

Definition at line 202 of file raster_thread_merger_unittests.cc.

References fml::RasterThreadMerger::DecrementLease(), fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::TaskRunner::GetTaskQueueId(), fml::MessageLoop::GetTaskRunner(), fml::RasterThreadMerger::IsMerged(), fml::RasterThreadMerger::MergeWithLease(), fml::AutoResetWaitableEvent::Signal(), fml::AutoResetWaitableEvent::Wait(), and fml::RasterThreadMerger::WaitUntilMerged().

202  {
203  fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger;
204 
205  fml::AutoResetWaitableEvent create_thread_merger_latch;
206  fml::MessageLoop* loop_platform = nullptr;
207  fml::AutoResetWaitableEvent latch_platform;
208  fml::AutoResetWaitableEvent term_platform;
209  fml::AutoResetWaitableEvent latch_merged;
210  std::thread thread_platform([&]() {
212  loop_platform = &fml::MessageLoop::GetCurrent();
213  latch_platform.Signal();
214  create_thread_merger_latch.Wait();
215  raster_thread_merger->WaitUntilMerged();
216  latch_merged.Signal();
217  term_platform.Wait();
218  });
219 
220  const size_t kNumFramesMerged = 5;
221  fml::MessageLoop* loop_raster = nullptr;
222  fml::AutoResetWaitableEvent term_raster;
223  std::thread thread_raster([&]() {
225  loop_raster = &fml::MessageLoop::GetCurrent();
226  latch_platform.Wait();
227  fml::TaskQueueId qid_platform =
228  loop_platform->GetTaskRunner()->GetTaskQueueId();
229  fml::TaskQueueId qid_raster =
230  loop_raster->GetTaskRunner()->GetTaskQueueId();
231  raster_thread_merger =
232  fml::MakeRefCounted<fml::RasterThreadMerger>(qid_platform, qid_raster);
233  ASSERT_FALSE(raster_thread_merger->IsMerged());
234  create_thread_merger_latch.Signal();
235  raster_thread_merger->MergeWithLease(kNumFramesMerged);
236  term_raster.Wait();
237  });
238 
239  latch_merged.Wait();
240  ASSERT_TRUE(raster_thread_merger->IsMerged());
241 
242  for (size_t i = 0; i < kNumFramesMerged; i++) {
243  ASSERT_TRUE(raster_thread_merger->IsMerged());
244  raster_thread_merger->DecrementLease();
245  }
246 
247  ASSERT_FALSE(raster_thread_merger->IsMerged());
248 
249  term_platform.Signal();
250  term_raster.Signal();
251  thread_platform.join();
252  thread_raster.join();
253 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
void MergeWithLease(size_t lease_term)
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56
RasterThreadStatus DecrementLease()

◆ TEST() [37/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
MergeUnmergeInvokesBothWakeablesSeparately   
)

Definition at line 211 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::ChronoTicksSinceEpoch(), CountRemainingTasks(), fml::MessageLoopTaskQueues::GetInstance(), fml::AutoResetWaitableEvent::Signal(), fml::testing::TestWakeable::TestWakeable(), and fml::AutoResetWaitableEvent::Wait().

212  {
213  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
214 
215  auto queue_id_1 = task_queue->CreateTaskQueue();
216  auto queue_id_2 = task_queue->CreateTaskQueue();
217 
218  fml::AutoResetWaitableEvent latch_1, latch_2;
219 
220  task_queue->SetWakeable(
221  queue_id_1,
222  new TestWakeable([&](fml::TimePoint wake_time) { latch_1.Signal(); }));
223  task_queue->SetWakeable(
224  queue_id_2,
225  new TestWakeable([&](fml::TimePoint wake_time) { latch_2.Signal(); }));
226 
227  task_queue->RegisterTask(
228  queue_id_1, []() {}, ChronoTicksSinceEpoch());
229  task_queue->RegisterTask(
230  queue_id_2, []() {}, ChronoTicksSinceEpoch());
231 
232  task_queue->Merge(queue_id_1, queue_id_2);
233  task_queue->Unmerge(queue_id_1, queue_id_2);
234 
235  CountRemainingTasks(task_queue, queue_id_1);
236 
237  latch_1.Wait();
238 
239  CountRemainingTasks(task_queue, queue_id_2);
240 
241  latch_2.Wait();
242 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()
static int CountRemainingTasks(fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)

◆ TEST() [38/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
GetTasksToRunNowBlocksMerge   
)

Definition at line 244 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::ChronoTicksSinceEpoch(), CountRemainingTasks(), fml::MessageLoopTaskQueues::GetInstance(), fml::AutoResetWaitableEvent::Signal(), fml::testing::TestWakeable::TestWakeable(), and fml::AutoResetWaitableEvent::Wait().

244  {
245  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
246 
247  auto queue_id_1 = task_queue->CreateTaskQueue();
248  auto queue_id_2 = task_queue->CreateTaskQueue();
249 
250  fml::AutoResetWaitableEvent wake_up_start, wake_up_end, merge_start,
251  merge_end;
252 
253  task_queue->RegisterTask(
254  queue_id_1, []() {}, ChronoTicksSinceEpoch());
255  task_queue->SetWakeable(queue_id_1,
256  new TestWakeable([&](fml::TimePoint wake_time) {
257  wake_up_start.Signal();
258  wake_up_end.Wait();
259  }));
260 
261  std::thread tasks_to_run_now_thread(
262  [&]() { CountRemainingTasks(task_queue, queue_id_1); });
263 
264  wake_up_start.Wait();
265  bool merge_done = false;
266 
267  std::thread merge_thread([&]() {
268  merge_start.Signal();
269  task_queue->Merge(queue_id_1, queue_id_2);
270  merge_done = true;
271  merge_end.Signal();
272  });
273 
274  merge_start.Wait();
275  ASSERT_FALSE(merge_done);
276  wake_up_end.Signal();
277 
278  merge_end.Wait();
279  ASSERT_TRUE(merge_done);
280 
281  tasks_to_run_now_thread.join();
282  merge_thread.join();
283 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()
static int CountRemainingTasks(fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)

◆ TEST() [39/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
AddRemoveNotifyObservers   
)

Definition at line 247 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance(), key, and TestNotifyObservers().

247  {
248  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
249  auto queue_id = task_queue->CreateTaskQueue();
250 
251  int test_val = 0;
252  intptr_t key = 123;
253 
254  task_queue->AddTaskObserver(queue_id, key, [&test_val]() { test_val = 1; });
255  TestNotifyObservers(queue_id);
256  ASSERT_TRUE(test_val == 1);
257 
258  test_val = 0;
259  task_queue->RemoveTaskObserver(queue_id, key);
260  TestNotifyObservers(queue_id);
261  ASSERT_TRUE(test_val == 0);
262 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
void TestNotifyObservers(fml::TaskQueueId queue_id)

◆ TEST() [40/59]

fml::testing::TEST ( RasterThreadMerger  ,
HandleTaskQueuesAreTheSame   
)

Definition at line 255 of file raster_thread_merger_unittests.cc.

References fml::testing::TaskQueueWrapper::GetTaskQueueId().

255  {
256  TaskQueueWrapper queue;
257  fml::TaskQueueId qid1 = queue.GetTaskQueueId();
258  fml::TaskQueueId qid2 = qid1;
259  const auto raster_thread_merger =
260  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
261  // Statically merged.
262  ASSERT_TRUE(raster_thread_merger->IsMerged());
263 
264  // Test decrement lease and unmerge are both no-ops.
265  // The task queues should be always merged.
266  const size_t kNumFramesMerged = 5;
267  raster_thread_merger->MergeWithLease(kNumFramesMerged);
268 
269  for (size_t i = 0; i < kNumFramesMerged; i++) {
270  ASSERT_TRUE(raster_thread_merger->IsMerged());
271  raster_thread_merger->DecrementLease();
272  }
273 
274  ASSERT_TRUE(raster_thread_merger->IsMerged());
275 
276  // Wait until merged should also return immediately.
277  raster_thread_merger->WaitUntilMerged();
278  ASSERT_TRUE(raster_thread_merger->IsMerged());
279 }

◆ TEST() [41/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
WakeUpIndependentOfTime   
)

Definition at line 264 of file message_loop_task_queues_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::MessageLoopTaskQueues::GetInstance(), fml::TimePoint::Max(), and fml::testing::TestWakeable::TestWakeable().

264  {
265  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
266  auto queue_id = task_queue->CreateTaskQueue();
267 
268  int num_wakes = 0;
269  task_queue->SetWakeable(
270  queue_id, new TestWakeable(
271  [&num_wakes](fml::TimePoint wake_time) { ++num_wakes; }));
272 
273  task_queue->RegisterTask(
274  queue_id, []() {}, ChronoTicksSinceEpoch());
275  task_queue->RegisterTask(
276  queue_id, []() {}, fml::TimePoint::Max());
277 
278  ASSERT_TRUE(num_wakes == 2);
279 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static constexpr TimePoint Max()
Definition: time_point.h:34
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [42/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
WokenUpWithNewerTime   
)

Definition at line 281 of file message_loop_task_queues_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::CountDownLatch::CountDown(), fml::MessageLoopTaskQueues::GetInstance(), fml::TimePoint::Max(), fml::testing::TestWakeable::TestWakeable(), and fml::CountDownLatch::Wait().

281  {
282  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
283  auto queue_id = task_queue->CreateTaskQueue();
284  fml::CountDownLatch latch(2);
285 
286  fml::TimePoint expected = fml::TimePoint::Max();
287 
288  task_queue->SetWakeable(
289  queue_id, new TestWakeable([&latch, &expected](fml::TimePoint wake_time) {
290  ASSERT_TRUE(wake_time == expected);
291  latch.CountDown();
292  }));
293 
294  task_queue->RegisterTask(
295  queue_id, []() {}, fml::TimePoint::Max());
296 
297  const auto now = ChronoTicksSinceEpoch();
298  expected = now;
299  task_queue->RegisterTask(
300  queue_id, []() {}, now);
301 
302  latch.Wait();
303 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static constexpr TimePoint Max()
Definition: time_point.h:34
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [43/59]

fml::testing::TEST ( RasterThreadMerger  ,
Enable   
)

Definition at line 281 of file raster_thread_merger_unittests.cc.

References fml::testing::TaskQueueWrapper::GetTaskQueueId().

281  {
282  TaskQueueWrapper queue1;
283  TaskQueueWrapper queue2;
284  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
285  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
286  const auto raster_thread_merger =
287  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
288 
289  raster_thread_merger->Disable();
290  raster_thread_merger->MergeWithLease(1);
291  ASSERT_FALSE(raster_thread_merger->IsMerged());
292 
293  raster_thread_merger->Enable();
294  ASSERT_FALSE(raster_thread_merger->IsMerged());
295 
296  raster_thread_merger->MergeWithLease(1);
297  ASSERT_TRUE(raster_thread_merger->IsMerged());
298 
299  raster_thread_merger->DecrementLease();
300  ASSERT_FALSE(raster_thread_merger->IsMerged());
301 }

◆ TEST() [44/59]

fml::testing::TEST ( MessageLoopTaskQueueMergeUnmerge  ,
FollowingTasksSwitchQueueIfFirstTaskMergesThreads   
)

Definition at line 285 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::CountDownLatch::CountDown(), CountRemainingTasks(), fml::MessageLoopTaskQueues::GetInstance(), fml::testing::TestWakeable::TestWakeable(), and fml::CountDownLatch::Wait().

286  {
287  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
288 
289  auto queue_id_1 = task_queue->CreateTaskQueue();
290  auto queue_id_2 = task_queue->CreateTaskQueue();
291 
292  fml::CountDownLatch latch(2);
293 
294  task_queue->SetWakeable(
295  queue_id_1,
296  new TestWakeable([&](fml::TimePoint wake_time) { latch.CountDown(); }));
297  task_queue->SetWakeable(
298  queue_id_2,
299  new TestWakeable([&](fml::TimePoint wake_time) { latch.CountDown(); }));
300 
301  task_queue->RegisterTask(
302  queue_id_2, [&]() { task_queue->Merge(queue_id_1, queue_id_2); },
304 
305  task_queue->RegisterTask(
306  queue_id_2, []() {}, ChronoTicksSinceEpoch());
307 
308  ASSERT_EQ(CountRemainingTasks(task_queue, queue_id_2, true), 1);
309  ASSERT_EQ(CountRemainingTasks(task_queue, queue_id_1, true), 1);
310 
311  latch.Wait();
312 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()
static int CountRemainingTasks(fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)

◆ TEST() [45/59]

fml::testing::TEST ( RasterThreadMerger  ,
Disable   
)

Definition at line 303 of file raster_thread_merger_unittests.cc.

References fml::testing::TaskQueueWrapper::GetTaskQueueId(), fml::kRemainsMerged, and fml::kUnmergedNow.

303  {
304  TaskQueueWrapper queue1;
305  TaskQueueWrapper queue2;
306  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
307  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
308  const auto raster_thread_merger =
309  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
310 
311  raster_thread_merger->Disable();
312  ASSERT_FALSE(raster_thread_merger->IsMerged());
313 
314  raster_thread_merger->MergeWithLease(1);
315  ASSERT_FALSE(raster_thread_merger->IsMerged());
316 
317  raster_thread_merger->Enable();
318  raster_thread_merger->MergeWithLease(1);
319  ASSERT_TRUE(raster_thread_merger->IsMerged());
320 
321  raster_thread_merger->Disable();
322  raster_thread_merger->UnMergeNowIfLastOne();
323  ASSERT_TRUE(raster_thread_merger->IsMerged());
324 
325  {
326  auto decrement_result = raster_thread_merger->DecrementLease();
327  ASSERT_EQ(fml::RasterThreadStatus::kRemainsMerged, decrement_result);
328  }
329 
330  ASSERT_TRUE(raster_thread_merger->IsMerged());
331 
332  raster_thread_merger->Enable();
333  raster_thread_merger->UnMergeNowIfLastOne();
334  ASSERT_FALSE(raster_thread_merger->IsMerged());
335 
336  raster_thread_merger->MergeWithLease(1);
337 
338  ASSERT_TRUE(raster_thread_merger->IsMerged());
339 
340  {
341  auto decrement_result = raster_thread_merger->DecrementLease();
342  ASSERT_EQ(fml::RasterThreadStatus::kUnmergedNow, decrement_result);
343  }
344 
345  ASSERT_FALSE(raster_thread_merger->IsMerged());
346 }

◆ TEST() [46/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
NotifyObserversWhileCreatingQueues   
)

Definition at line 305 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance(), fml::AutoResetWaitableEvent::Signal(), TestNotifyObservers(), and fml::AutoResetWaitableEvent::Wait().

305  {
306  auto task_queues = fml::MessageLoopTaskQueues::GetInstance();
307  fml::TaskQueueId queue_id = task_queues->CreateTaskQueue();
308  fml::AutoResetWaitableEvent first_observer_executing, before_second_observer;
309 
310  task_queues->AddTaskObserver(queue_id, queue_id + 1, [&]() {
311  first_observer_executing.Signal();
312  before_second_observer.Wait();
313  });
314 
315  for (int i = 0; i < 100; i++) {
316  task_queues->AddTaskObserver(queue_id, queue_id + i + 2, [] {});
317  }
318 
319  std::thread notify_observers([&]() { TestNotifyObservers(queue_id); });
320 
321  first_observer_executing.Wait();
322 
323  for (int i = 0; i < 100; i++) {
324  task_queues->CreateTaskQueue();
325  }
326 
327  before_second_observer.Signal();
328  notify_observers.join();
329 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
void TestNotifyObservers(fml::TaskQueueId queue_id)

◆ TEST() [47/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
QueueDoNotOwnItself   
)

Definition at line 331 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

331  {
332  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
333  auto queue_id = task_queue->CreateTaskQueue();
334  ASSERT_FALSE(task_queue->Owns(queue_id, queue_id));
335 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [48/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
QueueDoNotOwnUnmergedTaskQueueId   
)

Definition at line 337 of file message_loop_task_queues_unittests.cc.

References fml::_kUnmerged, and fml::MessageLoopTaskQueues::GetInstance().

337  {
338  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
339  ASSERT_FALSE(task_queue->Owns(task_queue->CreateTaskQueue(), _kUnmerged));
340  ASSERT_FALSE(task_queue->Owns(_kUnmerged, task_queue->CreateTaskQueue()));
341  ASSERT_FALSE(task_queue->Owns(_kUnmerged, _kUnmerged));
342 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static const TaskQueueId _kUnmerged

◆ TEST() [49/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
QueueOwnsMergedTaskQueueId   
)

Definition at line 344 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

344  {
345  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
346  auto platform_queue = task_queue->CreateTaskQueue();
347  auto raster_queue = task_queue->CreateTaskQueue();
348  ASSERT_FALSE(task_queue->Owns(platform_queue, raster_queue));
349  ASSERT_FALSE(task_queue->Owns(raster_queue, platform_queue));
350  task_queue->Merge(platform_queue, raster_queue);
351  ASSERT_TRUE(task_queue->Owns(platform_queue, raster_queue));
352  ASSERT_FALSE(task_queue->Owns(raster_queue, platform_queue));
353 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [50/59]

fml::testing::TEST ( RasterThreadMerger  ,
IsEnabled   
)

Definition at line 348 of file raster_thread_merger_unittests.cc.

References fml::testing::TaskQueueWrapper::GetTaskQueueId().

348  {
349  TaskQueueWrapper queue1;
350  TaskQueueWrapper queue2;
351  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
352  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
353  const auto raster_thread_merger =
354  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
355  ASSERT_TRUE(raster_thread_merger->IsEnabled());
356 
357  raster_thread_merger->Disable();
358  ASSERT_FALSE(raster_thread_merger->IsEnabled());
359 
360  raster_thread_merger->Enable();
361  ASSERT_TRUE(raster_thread_merger->IsEnabled());
362 }

◆ TEST() [51/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
ConcurrentQueueAndTaskCreatingCounts   
)

Verifies that tasks can be added to task queues concurrently.

Definition at line 358 of file message_loop_task_queues_unittests.cc.

References fml::ChronoTicksSinceEpoch(), and fml::MessageLoopTaskQueues::GetInstance().

358  {
359  auto task_queues = fml::MessageLoopTaskQueues::GetInstance();
360 
361  // kThreadCount threads post kThreadTaskCount tasks each to kTaskQueuesCount
362  // task queues. Each thread picks a task queue randomly for each task.
363  constexpr size_t kThreadCount = 4;
364  constexpr size_t kTaskQueuesCount = 2;
365  constexpr size_t kThreadTaskCount = 500;
366 
367  std::vector<TaskQueueId> task_queue_ids;
368  for (size_t i = 0; i < kTaskQueuesCount; ++i) {
369  task_queue_ids.emplace_back(task_queues->CreateTaskQueue());
370  }
371 
372  ASSERT_EQ(task_queue_ids.size(), kTaskQueuesCount);
373 
374  fml::CountDownLatch tasks_posted_latch(kThreadCount);
375 
376  auto thread_main = [&]() {
377  for (size_t i = 0; i < kThreadTaskCount; i++) {
378  const auto current_task_queue_id =
379  task_queue_ids[std::rand() % kTaskQueuesCount];
380  const auto empty_task = []() {};
381  // The timepoint doesn't matter as the queue is never going to be drained.
382  const auto task_timepoint = ChronoTicksSinceEpoch();
383 
384  task_queues->RegisterTask(current_task_queue_id, empty_task,
385  task_timepoint);
386  }
387 
388  tasks_posted_latch.CountDown();
389  };
390 
391  std::vector<std::thread> threads;
392 
393  for (size_t i = 0; i < kThreadCount; i++) {
394  threads.emplace_back(std::thread{thread_main});
395  }
396 
397  ASSERT_EQ(threads.size(), kThreadCount);
398 
399  for (size_t i = 0; i < kThreadCount; i++) {
400  threads[i].join();
401  }
402 
403  // All tasks have been posted by now. Check that they are all pending.
404 
405  size_t pending_tasks = 0u;
406  std::for_each(task_queue_ids.begin(), task_queue_ids.end(),
407  [&](const auto& queue) {
408  pending_tasks += task_queues->GetNumPendingTasks(queue);
409  });
410 
411  ASSERT_EQ(pending_tasks, kThreadCount * kThreadTaskCount);
412 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()

◆ TEST() [52/59]

fml::testing::TEST ( RasterThreadMerger  ,
TwoMergersWithSameThreadPairShareEnabledState   
)

Definition at line 364 of file raster_thread_merger_unittests.cc.

References fml::RasterThreadMerger::CreateOrShareThreadMerger(), and fml::testing::TaskQueueWrapper::GetTaskQueueId().

364  {
365  TaskQueueWrapper queue1;
366  TaskQueueWrapper queue2;
367  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
368  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
369  const auto merger1 =
370  RasterThreadMerger::CreateOrShareThreadMerger(nullptr, qid1, qid2);
371  const auto merger2 =
372  RasterThreadMerger::CreateOrShareThreadMerger(merger1, qid1, qid2);
373  ASSERT_TRUE(merger1->IsEnabled());
374  ASSERT_TRUE(merger2->IsEnabled());
375 
376  merger1->Disable();
377  ASSERT_FALSE(merger1->IsEnabled());
378  ASSERT_FALSE(merger2->IsEnabled());
379 
380  merger2->Enable();
381  ASSERT_TRUE(merger1->IsEnabled());
382  ASSERT_TRUE(merger2->IsEnabled());
383 }

◆ TEST() [53/59]

fml::testing::TEST ( RasterThreadMerger  ,
RunExpiredTasksWhileFirstTaskMergesThreads   
)

Definition at line 385 of file raster_thread_merger_unittests.cc.

References fml::CountDownLatch::CountDown(), fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::MessageLoop::GetCurrentTaskQueueId(), fml::TaskRunner::GetTaskQueueId(), fml::MessageLoop::GetTaskRunner(), fml::TaskRunner::PostTask(), fml::MessageLoop::Run(), fml::AutoResetWaitableEvent::Signal(), fml::MessageLoop::Terminate(), fml::CountDownLatch::Wait(), and fml::AutoResetWaitableEvent::Wait().

385  {
386  fml::MessageLoop* loop_platform = nullptr;
388  std::thread thread_platform([&loop_platform, &latch1]() {
390  loop_platform = &fml::MessageLoop::GetCurrent();
391  loop_platform->GetTaskRunner()->PostTask([&]() { latch1.Signal(); });
392  loop_platform->Run();
393  });
394 
395  fml::MessageLoop* loop_raster = nullptr;
397  std::thread thread_raster([&loop_raster, &loop_platform, &latch1, &latch2]() {
398  latch1.Wait();
399 
401  loop_raster = &fml::MessageLoop::GetCurrent();
402  fml::TaskQueueId qid_platform =
403  loop_platform->GetTaskRunner()->GetTaskQueueId();
404  fml::TaskQueueId qid_raster =
405  loop_raster->GetTaskRunner()->GetTaskQueueId();
406  fml::CountDownLatch post_merge(2);
407  const auto raster_thread_merger =
408  fml::MakeRefCounted<fml::RasterThreadMerger>(qid_platform, qid_raster);
409  loop_raster->GetTaskRunner()->PostTask([&]() {
410  ASSERT_TRUE(raster_thread_merger->IsOnRasterizingThread());
411  ASSERT_FALSE(raster_thread_merger->IsOnPlatformThread());
412  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid_raster);
413  raster_thread_merger->MergeWithLease(1);
414  post_merge.CountDown();
415  });
416 
417  loop_raster->GetTaskRunner()->PostTask([&]() {
418  ASSERT_TRUE(raster_thread_merger->IsOnRasterizingThread());
419  ASSERT_TRUE(raster_thread_merger->IsOnPlatformThread());
420  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid_platform);
421  raster_thread_merger->DecrementLease();
422  post_merge.CountDown();
423  });
424 
425  loop_raster->RunExpiredTasksNow();
426  post_merge.Wait();
427  latch2.Signal();
428  });
429 
430  latch2.Wait();
431  loop_platform->GetTaskRunner()->PostTask(
432  [&]() { loop_platform->Terminate(); });
433 
434  thread_platform.join();
435  thread_raster.join();
436 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56
static TaskQueueId GetCurrentTaskQueueId()
Definition: message_loop.cc:76
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24

◆ TEST() [54/59]

fml::testing::TEST ( MessageLoopTaskQueue  ,
RegisterTaskWakesUpOwnerQueue   
)

Definition at line 414 of file message_loop_task_queues_unittests.cc.

References fml::ChronoTicksSinceEpoch(), fml::TimeDelta::FromMilliseconds(), fml::MessageLoopTaskQueues::GetInstance(), and fml::testing::TestWakeable::TestWakeable().

414  {
415  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
416  auto platform_queue = task_queue->CreateTaskQueue();
417  auto raster_queue = task_queue->CreateTaskQueue();
418 
419  std::vector<fml::TimePoint> wakes;
420 
421  task_queue->SetWakeable(platform_queue,
422  new TestWakeable([&wakes](fml::TimePoint wake_time) {
423  wakes.push_back(wake_time);
424  }));
425 
426  task_queue->SetWakeable(raster_queue,
427  new TestWakeable([](fml::TimePoint wake_time) {
428  // The raster queue is owned by the platform queue.
429  ASSERT_FALSE(true);
430  }));
431 
434 
435  ASSERT_EQ(0UL, wakes.size());
436 
437  task_queue->RegisterTask(
438  platform_queue, []() {}, time1);
439 
440  ASSERT_EQ(1UL, wakes.size());
441  ASSERT_EQ(time1, wakes[0]);
442 
443  task_queue->Merge(platform_queue, raster_queue);
444 
445  task_queue->RegisterTask(
446  raster_queue, []() {}, time2);
447 
448  ASSERT_EQ(3UL, wakes.size());
449  ASSERT_EQ(time1, wakes[1]);
450  ASSERT_EQ(time1, wakes[2]);
451 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
fml::TimePoint ChronoTicksSinceEpoch()
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46

◆ TEST() [55/59]

fml::testing::TEST ( RasterThreadMerger  ,
RunExpiredTasksWhileFirstTaskUnMergesThreads   
)

Definition at line 438 of file raster_thread_merger_unittests.cc.

References fml::MessageLoop::EnsureInitializedForCurrentThread(), fml::MessageLoop::GetCurrent(), fml::MessageLoop::GetCurrentTaskQueueId(), fml::TaskRunner::GetTaskQueueId(), fml::Thread::GetTaskRunner(), fml::MessageLoop::GetTaskRunner(), fml::TaskRunner::PostTask(), fml::MessageLoop::RunExpiredTasksNow(), fml::AutoResetWaitableEvent::Signal(), and fml::AutoResetWaitableEvent::Wait().

438  {
439  fml::Thread platform_thread("test_platform_thread");
440 
441  fml::AutoResetWaitableEvent raster_latch;
442  std::thread thread_raster([&]() {
445 
446  fml::TaskQueueId qid_platform =
447  platform_thread.GetTaskRunner()->GetTaskQueueId();
448  fml::TaskQueueId qid_raster =
449  loop_raster->GetTaskRunner()->GetTaskQueueId();
450 
451  fml::AutoResetWaitableEvent merge_latch;
452  const auto raster_thread_merger =
453  fml::MakeRefCounted<fml::RasterThreadMerger>(qid_platform, qid_raster);
454  loop_raster->GetTaskRunner()->PostTask([&]() {
455  raster_thread_merger->MergeWithLease(1);
456  merge_latch.Signal();
457  });
458 
459  loop_raster->RunExpiredTasksNow();
460  merge_latch.Wait();
461 
462  // threads should be merged at this point.
463  fml::AutoResetWaitableEvent unmerge_latch;
464  loop_raster->GetTaskRunner()->PostTask([&]() {
465  ASSERT_TRUE(raster_thread_merger->IsOnRasterizingThread());
466  ASSERT_TRUE(raster_thread_merger->IsOnPlatformThread());
467  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid_platform);
468  raster_thread_merger->DecrementLease();
469  unmerge_latch.Signal();
470  });
471 
472  fml::AutoResetWaitableEvent post_unmerge_latch;
473  loop_raster->GetTaskRunner()->PostTask([&]() {
474  ASSERT_TRUE(raster_thread_merger->IsOnRasterizingThread());
475  ASSERT_FALSE(raster_thread_merger->IsOnPlatformThread());
476  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid_raster);
477  post_unmerge_latch.Signal();
478  });
479 
480  unmerge_latch.Wait();
481  loop_raster->RunExpiredTasksNow();
482 
483  post_unmerge_latch.Wait();
484  raster_latch.Signal();
485  });
486 
487  raster_latch.Wait();
488  thread_raster.join();
489 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56
static TaskQueueId GetCurrentTaskQueueId()
Definition: message_loop.cc:76
void RunExpiredTasksNow()
Definition: message_loop.cc:72
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24

◆ TEST() [56/59]

fml::testing::TEST ( RasterThreadMerger  ,
SetMergeUnmergeCallback   
)

Definition at line 491 of file raster_thread_merger_unittests.cc.

References fml::testing::TaskQueueWrapper::GetTaskQueueId().

491  {
492  TaskQueueWrapper queue1;
493  TaskQueueWrapper queue2;
494  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
495  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
496 
497  const auto raster_thread_merger =
498  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
499 
500  int callbacks = 0;
501  raster_thread_merger->SetMergeUnmergeCallback(
502  [&callbacks]() { callbacks++; });
503 
504  ASSERT_EQ(0, callbacks);
505 
506  raster_thread_merger->MergeWithLease(1);
507  ASSERT_EQ(1, callbacks);
508 
509  raster_thread_merger->DecrementLease();
510  ASSERT_EQ(2, callbacks);
511 }

◆ TEST() [57/59]

fml::testing::TEST ( RasterThreadMerger  ,
MultipleMergersCanMergeSameThreadPair   
)

Definition at line 513 of file raster_thread_merger_unittests.cc.

References fml::RasterThreadMerger::CreateOrShareThreadMerger(), and fml::testing::TaskQueueWrapper::GetTaskQueueId().

513  {
514  TaskQueueWrapper queue1;
515  TaskQueueWrapper queue2;
516  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
517  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
518  // Two mergers will share one same inner merger
519  const auto raster_thread_merger1 =
521  const auto raster_thread_merger2 =
523  qid1, qid2);
524  const size_t kNumFramesMerged = 5;
525  ASSERT_FALSE(raster_thread_merger1->IsMerged());
526  ASSERT_FALSE(raster_thread_merger2->IsMerged());
527 
528  // Merge using the first merger
529  raster_thread_merger1->MergeWithLease(kNumFramesMerged);
530 
531  ASSERT_TRUE(raster_thread_merger1->IsMerged());
532  ASSERT_TRUE(raster_thread_merger2->IsMerged());
533 
534  // let there be one more turn till the leases expire.
535  for (size_t i = 0; i < kNumFramesMerged - 1; i++) {
536  // Check merge state using the two merger
537  ASSERT_TRUE(raster_thread_merger1->IsMerged());
538  ASSERT_TRUE(raster_thread_merger2->IsMerged());
539  raster_thread_merger1->DecrementLease();
540  }
541 
542  ASSERT_TRUE(raster_thread_merger1->IsMerged());
543  ASSERT_TRUE(raster_thread_merger2->IsMerged());
544 
545  // extend the lease once with the first merger
546  raster_thread_merger1->ExtendLeaseTo(kNumFramesMerged);
547 
548  // we will NOT last for 1 extra turn, we just set it.
549  for (size_t i = 0; i < kNumFramesMerged; i++) {
550  // Check merge state using the two merger
551  ASSERT_TRUE(raster_thread_merger1->IsMerged());
552  ASSERT_TRUE(raster_thread_merger2->IsMerged());
553  raster_thread_merger1->DecrementLease();
554  }
555 
556  ASSERT_FALSE(raster_thread_merger1->IsMerged());
557  ASSERT_FALSE(raster_thread_merger2->IsMerged());
558 }
static fml::RefPtr< fml::RasterThreadMerger > CreateOrShareThreadMerger(const fml::RefPtr< fml::RasterThreadMerger > &parent_merger, TaskQueueId platform_id, TaskQueueId raster_id)

◆ TEST() [58/59]

fml::testing::TEST ( RasterThreadMerger  ,
TheLastCallerOfMultipleMergersCanUnmergeNow   
)

Definition at line 560 of file raster_thread_merger_unittests.cc.

References fml::RasterThreadMerger::CreateOrShareThreadMerger(), and fml::testing::TaskQueueWrapper::GetTaskQueueId().

560  {
561  TaskQueueWrapper queue1;
562  TaskQueueWrapper queue2;
563  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
564  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
565  // Two mergers will share one same inner merger
566  const auto raster_thread_merger1 =
568  const auto raster_thread_merger2 =
570  qid1, qid2);
571  const size_t kNumFramesMerged = 5;
572  ASSERT_FALSE(raster_thread_merger1->IsMerged());
573  ASSERT_FALSE(raster_thread_merger2->IsMerged());
574 
575  // Merge using the mergers
576  raster_thread_merger1->MergeWithLease(kNumFramesMerged);
577  ASSERT_TRUE(raster_thread_merger1->IsMerged());
578  ASSERT_TRUE(raster_thread_merger2->IsMerged());
579  // Extend the second merger's lease
580  raster_thread_merger2->ExtendLeaseTo(kNumFramesMerged);
581  ASSERT_TRUE(raster_thread_merger1->IsMerged());
582  ASSERT_TRUE(raster_thread_merger2->IsMerged());
583 
584  // Two callers state becomes one caller left.
585  raster_thread_merger1->UnMergeNowIfLastOne();
586  // Check if still merged
587  ASSERT_TRUE(raster_thread_merger1->IsMerged());
588  ASSERT_TRUE(raster_thread_merger2->IsMerged());
589 
590  // One caller state becomes no callers left.
591  raster_thread_merger2->UnMergeNowIfLastOne();
592  // Check if unmerged
593  ASSERT_FALSE(raster_thread_merger1->IsMerged());
594  ASSERT_FALSE(raster_thread_merger2->IsMerged());
595 }
static fml::RefPtr< fml::RasterThreadMerger > CreateOrShareThreadMerger(const fml::RefPtr< fml::RasterThreadMerger > &parent_merger, TaskQueueId platform_id, TaskQueueId raster_id)

◆ TEST() [59/59]

fml::testing::TEST ( RasterThreadMerger  ,
TwoIndependentMergersCanMergeTwoDifferentThreadsIntoSamePlatformThread   
)

This case tests multiple standalone engines using independent merger to merge two different raster threads into the same platform thread.

Definition at line 599 of file raster_thread_merger_unittests.cc.

References fml::RasterThreadMerger::CreateOrShareThreadMerger(), and fml::testing::TaskQueueWrapper::GetTaskQueueId().

600  {
601  TaskQueueWrapper queue1;
602  TaskQueueWrapper queue2;
603  TaskQueueWrapper queue3;
604  fml::TaskQueueId qid1 = queue1.GetTaskQueueId();
605  fml::TaskQueueId qid2 = queue2.GetTaskQueueId();
606  fml::TaskQueueId qid3 = queue3.GetTaskQueueId();
607 
608  // Two mergers will NOT share same inner merger
609  const auto merger_from_2_to_1 =
611  const auto merger_from_3_to_1 =
613  qid1, qid3);
614  const size_t kNumFramesMerged = 5;
615  ASSERT_FALSE(merger_from_2_to_1->IsMerged());
616  ASSERT_FALSE(merger_from_3_to_1->IsMerged());
617 
618  // Merge thread2 into thread1
619  merger_from_2_to_1->MergeWithLease(kNumFramesMerged);
620  // Merge thread3 into thread1
621  merger_from_3_to_1->MergeWithLease(kNumFramesMerged);
622 
623  ASSERT_TRUE(merger_from_2_to_1->IsMerged());
624  ASSERT_TRUE(merger_from_3_to_1->IsMerged());
625 
626  for (size_t i = 0; i < kNumFramesMerged; i++) {
627  ASSERT_TRUE(merger_from_2_to_1->IsMerged());
628  merger_from_2_to_1->DecrementLease();
629  }
630 
631  ASSERT_FALSE(merger_from_2_to_1->IsMerged());
632  ASSERT_TRUE(merger_from_3_to_1->IsMerged());
633 
634  for (size_t i = 0; i < kNumFramesMerged; i++) {
635  ASSERT_TRUE(merger_from_3_to_1->IsMerged());
636  merger_from_3_to_1->DecrementLease();
637  }
638 
639  ASSERT_FALSE(merger_from_2_to_1->IsMerged());
640  ASSERT_FALSE(merger_from_3_to_1->IsMerged());
641 
642  merger_from_2_to_1->MergeWithLease(kNumFramesMerged);
643  ASSERT_TRUE(merger_from_2_to_1->IsMerged());
644  ASSERT_FALSE(merger_from_3_to_1->IsMerged());
645  merger_from_3_to_1->MergeWithLease(kNumFramesMerged);
646  ASSERT_TRUE(merger_from_2_to_1->IsMerged());
647  ASSERT_TRUE(merger_from_3_to_1->IsMerged());
648 
649  // Can unmerge independently
650  merger_from_2_to_1->UnMergeNowIfLastOne();
651  ASSERT_FALSE(merger_from_2_to_1->IsMerged());
652  ASSERT_TRUE(merger_from_3_to_1->IsMerged());
653 
654  // Can unmerge independently
655  merger_from_3_to_1->UnMergeNowIfLastOne();
656  ASSERT_FALSE(merger_from_2_to_1->IsMerged());
657  ASSERT_FALSE(merger_from_3_to_1->IsMerged());
658 }
static fml::RefPtr< fml::RasterThreadMerger > CreateOrShareThreadMerger(const fml::RefPtr< fml::RasterThreadMerger > &parent_merger, TaskQueueId platform_id, TaskQueueId raster_id)

◆ TestNotifyObservers()

void fml::testing::TestNotifyObservers ( fml::TaskQueueId  queue_id)

Definition at line 238 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

Referenced by TEST().

238  {
239  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
240  std::vector<fml::closure> observers =
241  task_queue->GetObserversToNotify(queue_id);
242  for (const auto& observer : observers) {
243  observer();
244  }
245 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ UnreachableScopeWithMacroWithoutReturnDoesNotMakeCompilerMad()

int fml::testing::UnreachableScopeWithMacroWithoutReturnDoesNotMakeCompilerMad ( )

Definition at line 27 of file logging_unittests.cc.

References FML_UNREACHABLE.

27  {
29  // return 0; <--- Missing but compiler is fine.
30 }
#define FML_UNREACHABLE()
Definition: logging.h:92

◆ UnreachableScopeWithoutReturnDoesNotMakeCompilerMad()

int fml::testing::UnreachableScopeWithoutReturnDoesNotMakeCompilerMad ( )

Definition at line 22 of file logging_unittests.cc.

References fml::KillProcess().

22  {
23  KillProcess();
24  // return 0; <--- Missing but compiler is fine.
25 }
void KillProcess()
Definition: logging.cc:142