5#define FML_USED_ON_EMBEDDER
7#include "flutter/fml/memory/task_runner_checker.h"
11#include "flutter/fml/message_loop.h"
12#include "flutter/fml/raster_thread_merger.h"
13#include "flutter/fml/synchronization/count_down_latch.h"
14#include "flutter/fml/synchronization/waitable_event.h"
15#include "gtest/gtest.h"
20TEST(TaskRunnerCheckerTests, RunsOnCurrentTaskRunner) {
25TEST(TaskRunnerCheckerTests, FailsTheCheckIfOnDifferentTaskRunner) {
30 std::thread another_thread([&]() {
41 another_thread.join();
45TEST(TaskRunnerCheckerTests, SameTaskRunnerRunsOnTheSameThread) {
54TEST(TaskRunnerCheckerTests, RunsOnDifferentThreadsReturnsFalse) {
59 std::thread another_thread([&]() {
67 another_thread.join();
70TEST(TaskRunnerCheckerTests, MergedTaskRunnersRunsOnTheSameThread) {
74 std::thread thread1([&
loop1, &latch1, &term1]() {
84 std::thread thread2([&
loop2, &latch2, &term2]() {
95 const auto raster_thread_merger =
96 fml::MakeRefCounted<fml::RasterThreadMerger>(qid1, qid2);
97 const size_t kNumFramesMerged = 5;
99 raster_thread_merger->MergeWithLease(kNumFramesMerged);
104 for (
size_t i = 0;
i < kNumFramesMerged;
i++) {
105 ASSERT_TRUE(raster_thread_merger->IsMerged());
106 raster_thread_merger->DecrementLease();
109 ASSERT_FALSE(raster_thread_merger->IsMerged());
121 PassesRunsOnCreationTaskRunnerIfOnDifferentTaskRunner) {
124 std::thread thread1([&]() {
133 std::thread thread2([&]() {
147 std::unique_ptr<TaskRunnerChecker> checker;
150 loop2->GetTaskRunner()->PostTask([&]() {
151 checker = std::make_unique<TaskRunnerChecker>();
152 EXPECT_EQ(checker->RunsOnCreationTaskRunner(),
true);
160 loop2->GetTaskRunner()->PostTask([&]() {
161 EXPECT_EQ(checker->RunsOnCreationTaskRunner(),
true);
static void loop1(skiatest::Reporter *reporter, const char *filename)
static void loop2(skiatest::Reporter *reporter, const char *filename)
static MessageLoopTaskQueues * GetInstance()
bool Merge(TaskQueueId owner, TaskQueueId subsumed)
bool Unmerge(TaskQueueId owner, TaskQueueId subsumed)
static void EnsureInitializedForCurrentThread()
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
bool RunsOnCreationTaskRunner() const
static bool RunsOnTheSameThread(TaskQueueId queue_a, TaskQueueId queue_b)
virtual void PostTask(const fml::closure &task) override
TEST(BacktraceTest, CanGatherBacktrace)