Flutter Engine
fml::testing Namespace Reference

Classes

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)
 
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, MergeFailIfAlreadyMergedOrSubsumed)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, UnmergeFailsOnSubsumed)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, MergeInvokesBothWakeables)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, MergeUnmergeInvokesBothWakeablesSeparately)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, GetTasksToRunNowBlocksMerge)
 
 TEST (MessageLoopTaskQueueMergeUnmerge, FollowingTasksSwitchQueueIfFirstTaskMergesThreads)
 
 TEST (MessageLoopTaskQueue, StartsWithNoPendingTasks)
 
 TEST (MessageLoopTaskQueue, RegisterOneTask)
 
 TEST (MessageLoopTaskQueue, RegisterTwoTasksAndCount)
 
 TEST (MessageLoopTaskQueue, PreserveTaskOrdering)
 
void TestNotifyObservers (fml::TaskQueueId queue_id)
 
 TEST (MessageLoopTaskQueue, AddRemoveNotifyObservers)
 
 TEST (MessageLoopTaskQueue, WakeUpIndependentOfTime)
 
 TEST (MessageLoopTaskQueue, WokenUpWithNewerTime)
 
 TEST (MessageLoopTaskQueue, NotifyObserversWhileCreatingQueues)
 
 TEST (MessageLoopTaskQueue, QueueDoNotOwnItself)
 
 TEST (MessageLoopTaskQueue, DISABLED_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, RunExpiredTasksWhileFirstTaskMergesThreads)
 
 TEST (RasterThreadMerger, RunExpiredTasksWhileFirstTaskUnMergesThreads)
 
 TEST (RasterThreadMerger, SetMergeUnmergeCallback)
 

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 29 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::TimePoint::Now().

Referenced by TEST().

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

◆ TEST() [1/41]

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/41]

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/41]

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:143
std::string BacktraceHere(size_t offset)
Definition: backtrace.cc:57

◆ TEST() [4/41]

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() [5/41]

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

Definition at line 21 of file raster_thread_merger_unittests.cc.

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

21  {
22  fml::MessageLoop* loop1 = nullptr;
25  std::thread thread1([&loop1, &latch1, &term1]() {
28  latch1.Signal();
29  term1.Wait();
30  });
31 
32  fml::MessageLoop* loop2 = nullptr;
35  std::thread thread2([&loop2, &latch2, &term2]() {
38  latch2.Signal();
39  term2.Wait();
40  });
41 
42  latch1.Wait();
43  latch2.Wait();
44 
46  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
47  const auto raster_thread_merger_ =
48  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
49  const int kNumFramesMerged = 5;
50 
51  ASSERT_FALSE(raster_thread_merger_->IsMerged());
52 
53  raster_thread_merger_->MergeWithLease(kNumFramesMerged);
54 
55  for (int i = 0; i < kNumFramesMerged; i++) {
56  ASSERT_TRUE(raster_thread_merger_->IsMerged());
57  raster_thread_merger_->DecrementLease();
58  }
59 
60  ASSERT_FALSE(raster_thread_merger_->IsMerged());
61 
62  term1.Signal();
63  term2.Signal();
64  thread1.join();
65  thread2.join();
66 }
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() [6/41]

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

Definition at line 21 of file logging_unittests.cc.

References fml::KillProcess().

21  {
22  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
23  ASSERT_DEATH(KillProcess(), "");
24 }
void KillProcess()
Definition: logging.cc:108

◆ TEST() [7/41]

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() [8/41]

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

Definition at line 26 of file logging_unittests.cc.

References FML_UNREACHABLE.

26  {
27  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
28  ASSERT_DEATH({ FML_UNREACHABLE(); }, "");
29 }
#define FML_UNREACHABLE()
Definition: logging.h:92

◆ TEST() [9/41]

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

Definition at line 30 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

30  {
31  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
32  auto queue_id = task_queue->CreateTaskQueue();
33  ASSERT_FALSE(task_queue->HasPendingTasks(queue_id));
34 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [10/41]

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

Definition at line 36 of file message_loop_task_queues_unittests.cc.

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

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

◆ TEST() [11/41]

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

Definition at line 45 of file task_runner_checker_unittest.cc.

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

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

◆ TEST() [12/41]

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

Definition at line 48 of file message_loop_task_queues_merge_unmerge_unittests.cc.

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

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

◆ TEST() [13/41]

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

Definition at line 52 of file message_loop_task_queues_unittests.cc.

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

52  {
53  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
54  auto queue_id = task_queue->CreateTaskQueue();
55  task_queue->RegisterTask(
56  queue_id, [] {}, fml::TimePoint::Now());
57  task_queue->RegisterTask(
58  queue_id, [] {}, fml::TimePoint::Max());
59  ASSERT_TRUE(task_queue->HasPendingTasks(queue_id));
60  ASSERT_TRUE(task_queue->GetNumPendingTasks(queue_id) == 2);
61 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static constexpr TimePoint Max()
Definition: time_point.h:32
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [14/41]

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

Definition at line 53 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().

53  {
55  TaskQueueId a = loop1.GetTaskRunner()->GetTaskQueueId();
57  std::thread anotherThread([&]() {
60  TaskQueueId b = loop2.GetTaskRunner()->GetTaskQueueId();
61  EXPECT_EQ(TaskRunnerChecker::RunsOnTheSameThread(a, b), false);
62  latch.Signal();
63  });
64  latch.Wait();
65  anotherThread.join();
66 }
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() [15/41]

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

Definition at line 63 of file message_loop_task_queues_unittests.cc.

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

63  {
64  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
65  auto queue_id = task_queue->CreateTaskQueue();
66  int test_val = 0;
67 
68  // order: 0
69  task_queue->RegisterTask(
70  queue_id, [&test_val]() { test_val = 1; }, fml::TimePoint::Now());
71 
72  // order: 1
73  task_queue->RegisterTask(
74  queue_id, [&test_val]() { test_val = 2; }, fml::TimePoint::Now());
75 
76  const auto now = fml::TimePoint::Now();
77  int expected_value = 1;
78  for (;;) {
79  fml::closure invocation = task_queue->GetNextTaskToRun(queue_id, now);
80  if (!invocation) {
81  break;
82  }
83  invocation();
84  ASSERT_TRUE(test_val == expected_value);
85  expected_value++;
86  }
87 }
std::function< void()> closure
Definition: closure.h:14
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
const char * expected_value
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [16/41]

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

Definition at line 67 of file message_loop_task_queues_merge_unmerge_unittests.cc.

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

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

◆ TEST() [17/41]

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

Definition at line 68 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().

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

◆ TEST() [18/41]

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

Definition at line 68 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().

68  {
69  fml::MessageLoop* loop1 = nullptr;
72  std::thread thread1([&loop1, &latch1, &term1]() {
75  latch1.Signal();
76  term1.Wait();
77  });
78 
79  fml::MessageLoop* loop2 = nullptr;
82  std::thread thread2([&loop2, &latch2, &term2]() {
85  latch2.Signal();
86  term2.Wait();
87  });
88 
89  latch1.Wait();
90  latch2.Wait();
92  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
93  const auto raster_thread_merger_ =
94  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
95  const int kNumFramesMerged = 5;
96 
97  raster_thread_merger_->MergeWithLease(kNumFramesMerged);
98 
99  // merged, running on the same thread
100  EXPECT_EQ(TaskRunnerChecker::RunsOnTheSameThread(qid1, qid2), true);
101 
102  for (int i = 0; i < kNumFramesMerged; i++) {
103  ASSERT_TRUE(raster_thread_merger_->IsMerged());
104  raster_thread_merger_->DecrementLease();
105  }
106 
107  ASSERT_FALSE(raster_thread_merger_->IsMerged());
108 
109  // un-merged, not running on the same thread
110  EXPECT_EQ(TaskRunnerChecker::RunsOnTheSameThread(qid1, qid2), false);
111 
112  term1.Signal();
113  term2.Signal();
114  thread1.join();
115  thread2.join();
116 }
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() [19/41]

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

Definition at line 83 of file message_loop_task_queues_merge_unmerge_unittests.cc.

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

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

◆ TEST() [20/41]

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

Definition at line 98 of file message_loop_task_queues_unittests.cc.

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

98  {
99  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
100  auto queue_id = task_queue->CreateTaskQueue();
101 
102  int test_val = 0;
103  intptr_t key = 123;
104 
105  task_queue->AddTaskObserver(queue_id, key, [&test_val]() { test_val = 1; });
106  TestNotifyObservers(queue_id);
107  ASSERT_TRUE(test_val == 1);
108 
109  test_val = 0;
110  task_queue->RemoveTaskObserver(queue_id, key);
111  TestNotifyObservers(queue_id);
112  ASSERT_TRUE(test_val == 0);
113 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
void TestNotifyObservers(fml::TaskQueueId queue_id)

◆ TEST() [21/41]

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

Definition at line 108 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

108  {
109  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
110 
111  auto queue_id_1 = task_queue->CreateTaskQueue();
112  auto queue_id_2 = task_queue->CreateTaskQueue();
113  auto queue_id_3 = task_queue->CreateTaskQueue();
114 
115  task_queue->Merge(queue_id_1, queue_id_2);
116 
117  ASSERT_FALSE(task_queue->Merge(queue_id_1, queue_id_3));
118  ASSERT_FALSE(task_queue->Merge(queue_id_2, queue_id_3));
119 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [22/41]

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

Definition at line 115 of file message_loop_task_queues_unittests.cc.

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

115  {
116  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
117  auto queue_id = task_queue->CreateTaskQueue();
118 
119  int num_wakes = 0;
120  task_queue->SetWakeable(
121  queue_id, new TestWakeable(
122  [&num_wakes](fml::TimePoint wake_time) { ++num_wakes; }));
123 
124  task_queue->RegisterTask(
125  queue_id, []() {}, fml::TimePoint::Now());
126  task_queue->RegisterTask(
127  queue_id, []() {}, fml::TimePoint::Max());
128 
129  ASSERT_TRUE(num_wakes == 2);
130 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static constexpr TimePoint Max()
Definition: time_point.h:32
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [23/41]

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

Definition at line 121 of file message_loop_task_queues_merge_unmerge_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

121  {
122  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
123 
124  auto queue_id_1 = task_queue->CreateTaskQueue();
125  auto queue_id_2 = task_queue->CreateTaskQueue();
126 
127  task_queue->Merge(queue_id_1, queue_id_2);
128 
129  ASSERT_FALSE(task_queue->Unmerge(queue_id_2));
130 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [24/41]

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

Definition at line 132 of file message_loop_task_queues_merge_unmerge_unittests.cc.

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

132  {
133  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
134 
135  auto queue_id_1 = task_queue->CreateTaskQueue();
136  auto queue_id_2 = task_queue->CreateTaskQueue();
137 
138  fml::CountDownLatch latch(2);
139 
140  task_queue->SetWakeable(
141  queue_id_1,
142  new TestWakeable([&](fml::TimePoint wake_time) { latch.CountDown(); }));
143  task_queue->SetWakeable(
144  queue_id_2,
145  new TestWakeable([&](fml::TimePoint wake_time) { latch.CountDown(); }));
146 
147  task_queue->RegisterTask(
148  queue_id_1, []() {}, fml::TimePoint::Now());
149 
150  task_queue->Merge(queue_id_1, queue_id_2);
151 
152  CountRemainingTasks(task_queue, queue_id_1);
153 
154  latch.Wait();
155 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static int CountRemainingTasks(fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [25/41]

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

Definition at line 132 of file message_loop_task_queues_unittests.cc.

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

132  {
133  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
134  auto queue_id = task_queue->CreateTaskQueue();
135  fml::CountDownLatch latch(2);
136 
137  fml::TimePoint expected = fml::TimePoint::Max();
138 
139  task_queue->SetWakeable(
140  queue_id, new TestWakeable([&latch, &expected](fml::TimePoint wake_time) {
141  ASSERT_TRUE(wake_time == expected);
142  latch.CountDown();
143  }));
144 
145  task_queue->RegisterTask(
146  queue_id, []() {}, fml::TimePoint::Max());
147 
148  const auto now = fml::TimePoint::Now();
149  expected = now;
150  task_queue->RegisterTask(
151  queue_id, []() {}, now);
152 
153  latch.Wait();
154 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static constexpr TimePoint Max()
Definition: time_point.h:32
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [26/41]

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

Definition at line 156 of file message_loop_task_queues_unittests.cc.

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

156  {
157  auto task_queues = fml::MessageLoopTaskQueues::GetInstance();
158  fml::TaskQueueId queue_id = task_queues->CreateTaskQueue();
159  fml::AutoResetWaitableEvent first_observer_executing, before_second_observer;
160 
161  task_queues->AddTaskObserver(queue_id, queue_id + 1, [&]() {
162  first_observer_executing.Signal();
163  before_second_observer.Wait();
164  });
165 
166  for (int i = 0; i < 100; i++) {
167  task_queues->AddTaskObserver(queue_id, queue_id + i + 2, [] {});
168  }
169 
170  std::thread notify_observers([&]() { TestNotifyObservers(queue_id); });
171 
172  first_observer_executing.Wait();
173 
174  for (int i = 0; i < 100; i++) {
175  task_queues->CreateTaskQueue();
176  }
177 
178  before_second_observer.Signal();
179  notify_observers.join();
180 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
void TestNotifyObservers(fml::TaskQueueId queue_id)

◆ TEST() [27/41]

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

Definition at line 157 of file message_loop_task_queues_merge_unmerge_unittests.cc.

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

158  {
159  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
160 
161  auto queue_id_1 = task_queue->CreateTaskQueue();
162  auto queue_id_2 = task_queue->CreateTaskQueue();
163 
164  fml::AutoResetWaitableEvent latch_1, latch_2;
165 
166  task_queue->SetWakeable(
167  queue_id_1,
168  new TestWakeable([&](fml::TimePoint wake_time) { latch_1.Signal(); }));
169  task_queue->SetWakeable(
170  queue_id_2,
171  new TestWakeable([&](fml::TimePoint wake_time) { latch_2.Signal(); }));
172 
173  task_queue->RegisterTask(
174  queue_id_1, []() {}, fml::TimePoint::Now());
175  task_queue->RegisterTask(
176  queue_id_2, []() {}, fml::TimePoint::Now());
177 
178  task_queue->Merge(queue_id_1, queue_id_2);
179  task_queue->Unmerge(queue_id_1);
180 
181  CountRemainingTasks(task_queue, queue_id_1);
182 
183  latch_1.Wait();
184 
185  CountRemainingTasks(task_queue, queue_id_2);
186 
187  latch_2.Wait();
188 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static int CountRemainingTasks(fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [28/41]

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

Definition at line 159 of file raster_thread_merger_unittests.cc.

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

159  {
160  fml::MessageLoop* loop1 = nullptr;
163  std::thread thread1([&loop1, &latch1, &term1]() {
165  loop1 = &fml::MessageLoop::GetCurrent();
166  latch1.Signal();
167  term1.Wait();
168  });
169 
170  fml::MessageLoop* loop2 = nullptr;
173  std::thread thread2([&loop2, &latch2, &term2]() {
175  loop2 = &fml::MessageLoop::GetCurrent();
176  latch2.Signal();
177  term2.Wait();
178  });
179 
180  latch1.Wait();
181  latch2.Wait();
182 
183  fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
184  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
185  const auto raster_thread_merger_ =
186  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
187  const int kNumFramesMerged = 5;
188 
189  ASSERT_FALSE(raster_thread_merger_->IsMerged());
190 
191  raster_thread_merger_->MergeWithLease(kNumFramesMerged);
192 
193  // let there be one more turn till the leases expire.
194  for (int i = 0; i < kNumFramesMerged - 1; i++) {
195  ASSERT_TRUE(raster_thread_merger_->IsMerged());
196  raster_thread_merger_->DecrementLease();
197  }
198 
199  // extend the lease once.
200  raster_thread_merger_->ExtendLeaseTo(kNumFramesMerged);
201 
202  // we will NOT last for 1 extra turn, we just set it.
203  for (int i = 0; i < kNumFramesMerged; i++) {
204  ASSERT_TRUE(raster_thread_merger_->IsMerged());
205  raster_thread_merger_->DecrementLease();
206  }
207 
208  ASSERT_FALSE(raster_thread_merger_->IsMerged());
209 
210  term1.Signal();
211  term2.Signal();
212  thread1.join();
213  thread2.join();
214 }
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() [29/41]

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

Definition at line 182 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

182  {
183  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
184  auto queue_id = task_queue->CreateTaskQueue();
185  ASSERT_FALSE(task_queue->Owns(queue_id, queue_id));
186 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ TEST() [30/41]

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

Definition at line 190 of file message_loop_task_queues_merge_unmerge_unittests.cc.

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

190  {
191  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
192 
193  auto queue_id_1 = task_queue->CreateTaskQueue();
194  auto queue_id_2 = task_queue->CreateTaskQueue();
195 
196  fml::AutoResetWaitableEvent wake_up_start, wake_up_end, merge_start,
197  merge_end;
198 
199  task_queue->RegisterTask(
200  queue_id_1, []() {}, fml::TimePoint::Now());
201  task_queue->SetWakeable(queue_id_1,
202  new TestWakeable([&](fml::TimePoint wake_time) {
203  wake_up_start.Signal();
204  wake_up_end.Wait();
205  }));
206 
207  std::thread tasks_to_run_now_thread(
208  [&]() { CountRemainingTasks(task_queue, queue_id_1); });
209 
210  wake_up_start.Wait();
211  bool merge_done = false;
212 
213  std::thread merge_thread([&]() {
214  merge_start.Signal();
215  task_queue->Merge(queue_id_1, queue_id_2);
216  merge_done = true;
217  merge_end.Signal();
218  });
219 
220  merge_start.Wait();
221  ASSERT_FALSE(merge_done);
222  wake_up_end.Signal();
223 
224  merge_end.Wait();
225  ASSERT_TRUE(merge_done);
226 
227  tasks_to_run_now_thread.join();
228  merge_thread.join();
229 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static int CountRemainingTasks(fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [31/41]

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

Definition at line 191 of file message_loop_task_queues_unittests.cc.

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

191  {
192  auto task_queues = fml::MessageLoopTaskQueues::GetInstance();
193  const int base_queue_id = task_queues->CreateTaskQueue();
194 
195  const int num_queues = 100;
196  std::atomic_bool created[num_queues * 3];
197  std::atomic_int num_tasks[num_queues * 3];
198  std::mutex task_count_mutex[num_queues * 3];
199  std::atomic_int done = 0;
200 
201  for (int i = 0; i < num_queues * 3; i++) {
202  num_tasks[i] = 0;
203  created[i] = false;
204  }
205 
206  auto creation_func = [&] {
207  for (int i = 0; i < num_queues; i++) {
208  fml::TaskQueueId queue_id = task_queues->CreateTaskQueue();
209  int limit = queue_id - base_queue_id;
210  created[limit] = true;
211 
212  for (int cur_q = 1; cur_q < limit; cur_q++) {
213  if (created[cur_q]) {
214  std::scoped_lock counter(task_count_mutex[cur_q]);
215  int cur_num_tasks = rand() % 10;
216  for (int k = 0; k < cur_num_tasks; k++) {
217  task_queues->RegisterTask(
218  fml::TaskQueueId(base_queue_id + cur_q), [] {},
220  }
221  num_tasks[cur_q] += cur_num_tasks;
222  }
223  }
224  }
225  done++;
226  };
227 
228  std::thread creation_1(creation_func);
229  std::thread creation_2(creation_func);
230 
231  while (done < 2) {
232  for (int i = 0; i < num_queues * 3; i++) {
233  if (created[i]) {
234  std::scoped_lock counter(task_count_mutex[i]);
235  int num_pending = task_queues->GetNumPendingTasks(
236  fml::TaskQueueId(base_queue_id + i));
237  int num_added = num_tasks[i];
238  ASSERT_EQ(num_pending, num_added);
239  }
240  }
241  }
242 
243  creation_1.join();
244  creation_2.join();
245 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [32/41]

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

Definition at line 216 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().

216  {
217  fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger;
218 
219  fml::AutoResetWaitableEvent create_thread_merger_latch;
220  fml::MessageLoop* loop_platform = nullptr;
221  fml::AutoResetWaitableEvent latch_platform;
222  fml::AutoResetWaitableEvent term_platform;
223  fml::AutoResetWaitableEvent latch_merged;
224  std::thread thread_platform([&]() {
226  loop_platform = &fml::MessageLoop::GetCurrent();
227  latch_platform.Signal();
228  create_thread_merger_latch.Wait();
229  raster_thread_merger->WaitUntilMerged();
230  latch_merged.Signal();
231  term_platform.Wait();
232  });
233 
234  const int kNumFramesMerged = 5;
235  fml::MessageLoop* loop_raster = nullptr;
236  fml::AutoResetWaitableEvent term_raster;
237  std::thread thread_raster([&]() {
239  loop_raster = &fml::MessageLoop::GetCurrent();
240  latch_platform.Wait();
241  fml::TaskQueueId qid_platform =
242  loop_platform->GetTaskRunner()->GetTaskQueueId();
243  fml::TaskQueueId qid_raster =
244  loop_raster->GetTaskRunner()->GetTaskQueueId();
245  raster_thread_merger =
246  fml::MakeRefCounted<fml::RasterThreadMerger>(qid_platform, qid_raster);
247  ASSERT_FALSE(raster_thread_merger->IsMerged());
248  create_thread_merger_latch.Signal();
249  raster_thread_merger->MergeWithLease(kNumFramesMerged);
250  term_raster.Wait();
251  });
252 
253  latch_merged.Wait();
254  ASSERT_TRUE(raster_thread_merger->IsMerged());
255 
256  for (int i = 0; i < kNumFramesMerged; i++) {
257  ASSERT_TRUE(raster_thread_merger->IsMerged());
258  raster_thread_merger->DecrementLease();
259  }
260 
261  ASSERT_FALSE(raster_thread_merger->IsMerged());
262 
263  term_platform.Signal();
264  term_raster.Signal();
265  thread_platform.join();
266  thread_raster.join();
267 }
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() [33/41]

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

Definition at line 231 of file message_loop_task_queues_merge_unmerge_unittests.cc.

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

232  {
233  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
234 
235  auto queue_id_1 = task_queue->CreateTaskQueue();
236  auto queue_id_2 = task_queue->CreateTaskQueue();
237 
238  fml::CountDownLatch latch(2);
239 
240  task_queue->SetWakeable(
241  queue_id_1,
242  new TestWakeable([&](fml::TimePoint wake_time) { latch.CountDown(); }));
243  task_queue->SetWakeable(
244  queue_id_2,
245  new TestWakeable([&](fml::TimePoint wake_time) { latch.CountDown(); }));
246 
247  task_queue->RegisterTask(
248  queue_id_2, [&]() { task_queue->Merge(queue_id_1, queue_id_2); },
250 
251  task_queue->RegisterTask(
252  queue_id_2, []() {}, fml::TimePoint::Now());
253 
254  ASSERT_EQ(CountRemainingTasks(task_queue, queue_id_2, true), 1);
255  ASSERT_EQ(CountRemainingTasks(task_queue, queue_id_1, true), 1);
256 
257  latch.Wait();
258 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static int CountRemainingTasks(fml::RefPtr< MessageLoopTaskQueues > task_queue, const TaskQueueId &queue_id, bool run_invocation=false)
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [34/41]

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

Definition at line 247 of file message_loop_task_queues_unittests.cc.

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

247  {
248  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
249  auto platform_queue = task_queue->CreateTaskQueue();
250  auto raster_queue = task_queue->CreateTaskQueue();
251 
252  std::vector<fml::TimePoint> wakes;
253 
254  task_queue->SetWakeable(platform_queue,
255  new TestWakeable([&wakes](fml::TimePoint wake_time) {
256  wakes.push_back(wake_time);
257  }));
258 
259  task_queue->SetWakeable(raster_queue,
260  new TestWakeable([](fml::TimePoint wake_time) {
261  // The raster queue is owned by the platform queue.
262  ASSERT_FALSE(true);
263  }));
264 
267 
268  ASSERT_EQ(0UL, wakes.size());
269 
270  task_queue->RegisterTask(
271  platform_queue, []() {}, time1);
272 
273  ASSERT_EQ(1UL, wakes.size());
274  ASSERT_EQ(time1, wakes[0]);
275 
276  task_queue->Merge(platform_queue, raster_queue);
277 
278  task_queue->RegisterTask(
279  raster_queue, []() {}, time2);
280 
281  ASSERT_EQ(3UL, wakes.size());
282  ASSERT_EQ(time1, wakes[1]);
283  ASSERT_EQ(time1, wakes[2]);
284 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()
static constexpr TimeDelta FromMilliseconds(int64_t millis)
Definition: time_delta.h:46
static TimePoint Now()
Definition: time_point.cc:26

◆ TEST() [35/41]

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

Definition at line 269 of file raster_thread_merger_unittests.cc.

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

269  {
270  fml::MessageLoop* loop1 = nullptr;
273  std::thread thread1([&loop1, &latch1, &term1]() {
275  loop1 = &fml::MessageLoop::GetCurrent();
276  latch1.Signal();
277  term1.Wait();
278  });
279 
280  latch1.Wait();
281 
282  fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
283  fml::TaskQueueId qid2 = qid1;
284  const auto raster_thread_merger_ =
285  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
286  // Statically merged.
287  ASSERT_TRUE(raster_thread_merger_->IsMerged());
288 
289  // Test decrement lease and unmerge are both no-ops.
290  // The task queues should be always merged.
291  const int kNumFramesMerged = 5;
292  raster_thread_merger_->MergeWithLease(kNumFramesMerged);
293 
294  for (int i = 0; i < kNumFramesMerged; i++) {
295  ASSERT_TRUE(raster_thread_merger_->IsMerged());
296  raster_thread_merger_->DecrementLease();
297  }
298 
299  ASSERT_TRUE(raster_thread_merger_->IsMerged());
300 
301  // Wait until merged should also return immediately.
302  raster_thread_merger_->WaitUntilMerged();
303  ASSERT_TRUE(raster_thread_merger_->IsMerged());
304 
305  term1.Signal();
306  thread1.join();
307 }
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() [36/41]

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

Definition at line 309 of file raster_thread_merger_unittests.cc.

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

309  {
310  fml::MessageLoop* loop1 = nullptr;
313  std::thread thread1([&loop1, &latch1, &term1]() {
315  loop1 = &fml::MessageLoop::GetCurrent();
316  latch1.Signal();
317  term1.Wait();
318  });
319 
320  fml::MessageLoop* loop2 = nullptr;
323  std::thread thread2([&loop2, &latch2, &term2]() {
325  loop2 = &fml::MessageLoop::GetCurrent();
326  latch2.Signal();
327  term2.Wait();
328  });
329 
330  latch1.Wait();
331  latch2.Wait();
332 
333  fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
334  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
335  const auto raster_thread_merger_ =
336  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
337 
338  raster_thread_merger_->Disable();
339  raster_thread_merger_->MergeWithLease(1);
340  ASSERT_FALSE(raster_thread_merger_->IsMerged());
341 
342  raster_thread_merger_->Enable();
343  ASSERT_FALSE(raster_thread_merger_->IsMerged());
344 
345  raster_thread_merger_->MergeWithLease(1);
346  ASSERT_TRUE(raster_thread_merger_->IsMerged());
347 
348  raster_thread_merger_->DecrementLease();
349  ASSERT_FALSE(raster_thread_merger_->IsMerged());
350 
351  term1.Signal();
352  term2.Signal();
353  thread1.join();
354  thread2.join();
355 }
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() [37/41]

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

Definition at line 357 of file raster_thread_merger_unittests.cc.

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

357  {
358  fml::MessageLoop* loop1 = nullptr;
361  std::thread thread1([&loop1, &latch1, &term1]() {
363  loop1 = &fml::MessageLoop::GetCurrent();
364  latch1.Signal();
365  term1.Wait();
366  });
367 
368  fml::MessageLoop* loop2 = nullptr;
371  std::thread thread2([&loop2, &latch2, &term2]() {
373  loop2 = &fml::MessageLoop::GetCurrent();
374  latch2.Signal();
375  term2.Wait();
376  });
377 
378  latch1.Wait();
379  latch2.Wait();
380 
381  fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
382  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
383  const auto raster_thread_merger_ =
384  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
385 
386  raster_thread_merger_->Disable();
387  ASSERT_FALSE(raster_thread_merger_->IsMerged());
388 
389  raster_thread_merger_->MergeWithLease(1);
390  ASSERT_FALSE(raster_thread_merger_->IsMerged());
391 
392  raster_thread_merger_->Enable();
393  raster_thread_merger_->MergeWithLease(1);
394  ASSERT_TRUE(raster_thread_merger_->IsMerged());
395 
396  raster_thread_merger_->Disable();
397  raster_thread_merger_->UnMergeNow();
398  ASSERT_TRUE(raster_thread_merger_->IsMerged());
399 
400  {
401  auto decrement_result = raster_thread_merger_->DecrementLease();
402  ASSERT_EQ(fml::RasterThreadStatus::kRemainsMerged, decrement_result);
403  }
404 
405  ASSERT_TRUE(raster_thread_merger_->IsMerged());
406 
407  raster_thread_merger_->Enable();
408  raster_thread_merger_->UnMergeNow();
409  ASSERT_FALSE(raster_thread_merger_->IsMerged());
410 
411  raster_thread_merger_->MergeWithLease(1);
412 
413  ASSERT_TRUE(raster_thread_merger_->IsMerged());
414 
415  {
416  auto decrement_result = raster_thread_merger_->DecrementLease();
417  ASSERT_EQ(fml::RasterThreadStatus::kUnmergedNow, decrement_result);
418  }
419 
420  ASSERT_FALSE(raster_thread_merger_->IsMerged());
421 
422  term1.Signal();
423  term2.Signal();
424  thread1.join();
425  thread2.join();
426 }
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() [38/41]

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

Definition at line 428 of file raster_thread_merger_unittests.cc.

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

428  {
429  fml::MessageLoop* loop1 = nullptr;
432  std::thread thread1([&loop1, &latch1, &term1]() {
434  loop1 = &fml::MessageLoop::GetCurrent();
435  latch1.Signal();
436  term1.Wait();
437  });
438 
439  fml::MessageLoop* loop2 = nullptr;
442  std::thread thread2([&loop2, &latch2, &term2]() {
444  loop2 = &fml::MessageLoop::GetCurrent();
445  latch2.Signal();
446  term2.Wait();
447  });
448 
449  latch1.Wait();
450  latch2.Wait();
451 
452  fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
453  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
454  const auto raster_thread_merger_ =
455  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
456  ASSERT_TRUE(raster_thread_merger_->IsEnabled());
457 
458  raster_thread_merger_->Disable();
459  ASSERT_FALSE(raster_thread_merger_->IsEnabled());
460 
461  raster_thread_merger_->Enable();
462  ASSERT_TRUE(raster_thread_merger_->IsEnabled());
463 
464  term1.Signal();
465  term2.Signal();
466  thread1.join();
467  thread2.join();
468 }
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() [39/41]

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

Definition at line 470 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().

470  {
471  fml::MessageLoop* loop_platform = nullptr;
473  std::thread thread_platform([&loop_platform, &latch1]() {
475  loop_platform = &fml::MessageLoop::GetCurrent();
476  loop_platform->GetTaskRunner()->PostTask([&]() { latch1.Signal(); });
477  loop_platform->Run();
478  });
479 
480  fml::MessageLoop* loop_raster = nullptr;
482  std::thread thread_raster([&loop_raster, &loop_platform, &latch1, &latch2]() {
483  latch1.Wait();
484 
486  loop_raster = &fml::MessageLoop::GetCurrent();
487  fml::TaskQueueId qid_platform =
488  loop_platform->GetTaskRunner()->GetTaskQueueId();
489  fml::TaskQueueId qid_raster =
490  loop_raster->GetTaskRunner()->GetTaskQueueId();
491  fml::CountDownLatch post_merge(2);
492  const auto raster_thread_merger_ =
493  fml::MakeRefCounted<fml::RasterThreadMerger>(qid_platform, qid_raster);
494  loop_raster->GetTaskRunner()->PostTask([&]() {
495  ASSERT_TRUE(raster_thread_merger_->IsOnRasterizingThread());
496  ASSERT_FALSE(raster_thread_merger_->IsOnPlatformThread());
497  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid_raster);
498  raster_thread_merger_->MergeWithLease(1);
499  post_merge.CountDown();
500  });
501 
502  loop_raster->GetTaskRunner()->PostTask([&]() {
503  ASSERT_TRUE(raster_thread_merger_->IsOnRasterizingThread());
504  ASSERT_TRUE(raster_thread_merger_->IsOnPlatformThread());
505  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid_platform);
506  raster_thread_merger_->DecrementLease();
507  post_merge.CountDown();
508  });
509 
510  loop_raster->RunExpiredTasksNow();
511  post_merge.Wait();
512  latch2.Signal();
513  });
514 
515  latch2.Wait();
516  loop_platform->GetTaskRunner()->PostTask(
517  [&]() { loop_platform->Terminate(); });
518 
519  thread_platform.join();
520  thread_raster.join();
521 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24
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

◆ TEST() [40/41]

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

Definition at line 523 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().

523  {
524  fml::MessageLoop* loop_platform = nullptr;
526  std::thread thread_platform([&loop_platform, &latch1]() {
528  loop_platform = &fml::MessageLoop::GetCurrent();
529  loop_platform->GetTaskRunner()->PostTask([&]() { latch1.Signal(); });
530  loop_platform->Run();
531  });
532 
533  fml::MessageLoop* loop_raster = nullptr;
535  std::thread thread_raster([&loop_raster, &loop_platform, &latch1, &latch2]() {
536  latch1.Wait();
537 
539  loop_raster = &fml::MessageLoop::GetCurrent();
540  fml::TaskQueueId qid_platform =
541  loop_platform->GetTaskRunner()->GetTaskQueueId();
542  fml::TaskQueueId qid_raster =
543  loop_raster->GetTaskRunner()->GetTaskQueueId();
544  fml::CountDownLatch post_merge(2);
545 
546  const auto raster_thread_merger_ =
547  fml::MakeRefCounted<fml::RasterThreadMerger>(qid_platform, qid_raster);
548  loop_raster->GetTaskRunner()->PostTask([&]() {
549  raster_thread_merger_->MergeWithLease(1);
550  post_merge.CountDown();
551  });
552 
553  loop_raster->RunExpiredTasksNow();
554 
555  loop_raster->GetTaskRunner()->PostTask([&]() {
556  ASSERT_TRUE(raster_thread_merger_->IsOnRasterizingThread());
557  ASSERT_TRUE(raster_thread_merger_->IsOnPlatformThread());
558  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid_platform);
559  raster_thread_merger_->DecrementLease();
560  post_merge.CountDown();
561  });
562 
563  loop_raster->GetTaskRunner()->PostTask([&]() {
564  ASSERT_TRUE(raster_thread_merger_->IsOnRasterizingThread());
565  ASSERT_FALSE(raster_thread_merger_->IsOnPlatformThread());
566  ASSERT_EQ(fml::MessageLoop::GetCurrentTaskQueueId(), qid_platform);
567  post_merge.CountDown();
568  });
569 
570  loop_raster->RunExpiredTasksNow();
571  post_merge.Wait();
572  latch2.Signal();
573  });
574 
575  latch2.Wait();
576  loop_platform->GetTaskRunner()->PostTask(
577  [&]() { loop_platform->Terminate(); });
578 
579  thread_platform.join();
580  thread_raster.join();
581 }
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24
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

◆ TEST() [41/41]

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

Definition at line 583 of file raster_thread_merger_unittests.cc.

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

583  {
584  fml::MessageLoop* loop1 = nullptr;
587  std::thread thread1([&loop1, &latch1, &term1]() {
589  loop1 = &fml::MessageLoop::GetCurrent();
590  latch1.Signal();
591  term1.Wait();
592  });
593 
594  fml::MessageLoop* loop2 = nullptr;
597  std::thread thread2([&loop2, &latch2, &term2]() {
599  loop2 = &fml::MessageLoop::GetCurrent();
600  latch2.Signal();
601  term2.Wait();
602  });
603 
604  latch1.Wait();
605  latch2.Wait();
606 
607  fml::TaskQueueId qid1 = loop1->GetTaskRunner()->GetTaskQueueId();
608  fml::TaskQueueId qid2 = loop2->GetTaskRunner()->GetTaskQueueId();
609 
610  const auto raster_thread_merger =
611  fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
612 
613  int callbacks = 0;
614  raster_thread_merger->SetMergeUnmergeCallback(
615  [&callbacks]() { callbacks++; });
616 
617  ASSERT_EQ(0, callbacks);
618 
619  raster_thread_merger->MergeWithLease(1);
620  ASSERT_EQ(1, callbacks);
621 
622  raster_thread_merger->DecrementLease();
623  ASSERT_EQ(2, callbacks);
624 
625  term1.Signal();
626  term2.Signal();
627  thread1.join();
628  thread2.join();
629 }
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

◆ TestNotifyObservers()

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

Definition at line 89 of file message_loop_task_queues_unittests.cc.

References fml::MessageLoopTaskQueues::GetInstance().

Referenced by TEST().

89  {
90  auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
91  std::vector<fml::closure> observers =
92  task_queue->GetObserversToNotify(queue_id);
93  for (const auto& observer : observers) {
94  observer();
95  }
96 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

◆ UnreachableScopeWithMacroWithoutReturnDoesNotMakeCompilerMad()

int fml::testing::UnreachableScopeWithMacroWithoutReturnDoesNotMakeCompilerMad ( )

Definition at line 16 of file logging_unittests.cc.

References FML_UNREACHABLE.

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

◆ UnreachableScopeWithoutReturnDoesNotMakeCompilerMad()

int fml::testing::UnreachableScopeWithoutReturnDoesNotMakeCompilerMad ( )

Definition at line 11 of file logging_unittests.cc.

References fml::KillProcess().

11  {
12  KillProcess();
13  // return 0; <--- Missing but compiler is fine.
14 }
void KillProcess()
Definition: logging.cc:108