Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
pipeline_compile_queue_gles_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <atomic>
8#include <memory>
9#include <vector>
10
14#include "flutter/fml/thread.h"
17
18namespace impeller {
19namespace testing {
20
21namespace {
22
23std::shared_ptr<fml::BasicTaskRunner> CreateBasicTaskRunner(
24 const fml::Thread& thread) {
25 return std::make_shared<fml::WrapperBasicTaskRunner>(thread.GetTaskRunner());
26}
27
28} // namespace
29
30TEST(PipelineCompileQueueGLESTest, CreateReturnsNullWithNullTaskRunner) {
32 EXPECT_EQ(queue, nullptr);
33}
34
35TEST(PipelineCompileQueueGLESTest, CreateSucceedsWithValidTaskRunner) {
36 fml::Thread thread;
37 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
38 EXPECT_NE(queue, nullptr);
39 thread.Join();
40}
41
42TEST(PipelineCompileQueueGLESTest, PostJobDoesNothingWithNullClosure) {
43 fml::Thread thread;
44 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
45 ASSERT_NE(queue, nullptr);
46 queue->PostJob(nullptr);
47 thread.Join();
48}
49
50TEST(PipelineCompileQueueGLESTest, OnJobAddedProcessesJobsSequentially) {
51 fml::Thread thread;
52 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
53 ASSERT_NE(queue, nullptr);
54
55 std::atomic<int> completed_jobs{0};
56 fml::CountDownLatch latch(3);
57
61
65
69
70 queue->PostJobForDescriptor(desc1, [&]() {
71 std::this_thread::sleep_for(std::chrono::milliseconds(80));
72 completed_jobs++;
73 latch.CountDown();
74 });
75
76 queue->PostJobForDescriptor(desc2, [&]() {
77 std::this_thread::sleep_for(std::chrono::milliseconds(80));
78 completed_jobs++;
79 latch.CountDown();
80 });
81
82 queue->PostJobForDescriptor(desc3, [&]() {
83 std::this_thread::sleep_for(std::chrono::milliseconds(80));
84 completed_jobs++;
85 latch.CountDown();
86 });
87
88 latch.Wait();
89
90 EXPECT_EQ(completed_jobs, 3);
91
92 thread.Join();
93}
94
95TEST(PipelineCompileQueueGLESTest,
96 PostJobForDescriptorWithDuplicateRunsEagerly) {
97 fml::Thread thread;
98 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
99 ASSERT_NE(queue, nullptr);
100
101 std::atomic<int> first_job_count{0};
102 std::atomic<int> second_job_count{0};
103 fml::CountDownLatch latch(2);
104
106
107 queue->PostJobForDescriptor(desc, [&]() {
108 first_job_count++;
109 latch.CountDown();
110 });
111
112 queue->PostJobForDescriptor(desc, [&]() {
113 second_job_count++;
114 latch.CountDown();
115 });
116
117 latch.Wait();
118
119 EXPECT_EQ(first_job_count, 1);
120 EXPECT_EQ(second_job_count, 1);
121 thread.Join();
122}
123
124TEST(PipelineCompileQueueGLESTest, IsProcessingResetsAfterAllJobsComplete) {
125 fml::Thread thread;
126 auto queue = PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
127 ASSERT_NE(queue, nullptr);
128
129 fml::CountDownLatch latch(1);
130
131 queue->PostJobForDescriptor(PipelineDescriptor{},
132 [&]() { latch.CountDown(); });
133
134 latch.Wait();
135
136 fml::CountDownLatch latch2(1);
137 queue->PostJobForDescriptor(PipelineDescriptor{},
138 [&]() { latch2.CountDown(); });
139
140 latch2.Wait();
141
142 SUCCEED();
143 thread.Join();
144}
145
146TEST(PipelineCompileQueueGLESTest, DestroyQueueWithPendingTasks) {
147 fml::Thread thread;
148 std::atomic<int> completed_jobs{0};
149 fml::CountDownLatch latch(3);
150
151 {
152 auto queue =
153 PipelineCompileQueueGLES::Create(CreateBasicTaskRunner(thread));
154 ASSERT_NE(queue, nullptr);
155
156 PipelineDescriptor desc1;
159
160 PipelineDescriptor desc2;
163
164 PipelineDescriptor desc3;
167
168 queue->PostJobForDescriptor(desc1, [&]() {
169 std::this_thread::sleep_for(std::chrono::milliseconds(50));
170 completed_jobs++;
171 latch.CountDown();
172 });
173
174 queue->PostJobForDescriptor(desc2, [&]() {
175 std::this_thread::sleep_for(std::chrono::milliseconds(50));
176 completed_jobs++;
177 latch.CountDown();
178 });
179
180 queue->PostJobForDescriptor(desc3, [&]() {
181 std::this_thread::sleep_for(std::chrono::milliseconds(50));
182 completed_jobs++;
183 latch.CountDown();
184 });
185
186 // Queue will be destroyed here with pending jobs.
187 // The destructor should ensure that the pending jobs are either executed
188 // or posted to the queue's thread.
189 }
190
191 // Wait for completion of the jobs.
192 latch.Wait();
193 EXPECT_EQ(completed_jobs, 3);
194
195 thread.Join();
196}
197
198} // namespace testing
199} // namespace impeller
void Join()
Definition thread.cc:168
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition thread.cc:164
static std::shared_ptr< PipelineCompileQueueGLES > Create(std::shared_ptr< fml::BasicTaskRunner > worker_task_runner)
PipelineDescriptor & SetSampleCount(SampleCount samples)
VkQueue queue
Definition main.cc:71
TEST(FrameTimingsRecorderTest, RecordVsync)