Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
pipeline_compile_queue_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 <memory>
8
11
12namespace impeller {
13namespace testing {
14
16 public:
17 void PostJob(const fml::closure& job) override {
18 if (job) {
19 job();
20 }
21 }
22
23 void OnJobAdded() override {}
24
25 bool AddJobForTest(const PipelineDescriptor& desc, const fml::closure& job) {
26 return AddJob(desc, job);
27 }
28
30};
31
32TEST(PipelineCompileQueueTest, AddJobReturnsTrueForNewDescriptor) {
35 bool job_executed = false;
36 fml::closure job = [&job_executed]() { job_executed = true; };
37
38 bool result = queue.AddJobForTest(desc, job);
39 EXPECT_TRUE(result);
40}
41
42TEST(PipelineCompileQueueTest, AddJobReturnsFalseForDuplicateDescriptor) {
45 bool job1_executed = false;
46 bool job2_executed = false;
47 fml::closure job1 = [&job1_executed]() { job1_executed = true; };
48 fml::closure job2 = [&job2_executed]() { job2_executed = true; };
49
50 bool result1 = queue.AddJobForTest(desc, job1);
51 bool result2 = queue.AddJobForTest(desc, job2);
52
53 EXPECT_TRUE(result1);
54 EXPECT_FALSE(result2);
55}
56
57TEST(PipelineCompileQueueTest, HasPendingJobsReturnsCorrectState) {
60 fml::closure job = []() {};
61
62 EXPECT_FALSE(queue.HasPendingJobsForTest());
63
64 queue.AddJobForTest(desc, job);
65 EXPECT_TRUE(queue.HasPendingJobsForTest());
66}
67
68TEST(PipelineCompileQueueTest, PerformJobEagerlyExecutesJob) {
71 bool job_executed = false;
72 fml::closure job = [&job_executed]() { job_executed = true; };
73
74 queue.AddJobForTest(desc, job);
75 queue.PerformJobEagerly(desc);
76
77 EXPECT_TRUE(job_executed);
78 EXPECT_FALSE(queue.HasPendingJobsForTest());
79}
80
81TEST(PipelineCompileQueueTest, FinishAllJobsDrainsQueue) {
82 auto queue = std::make_shared<TestPipelineCompileQueue>();
84 bool job_executed = false;
85 fml::closure job = [&job_executed]() { job_executed = true; };
86
87 queue->AddJobForTest(desc, job);
88 EXPECT_TRUE(queue->HasPendingJobsForTest());
89
90 queue.reset();
91
92 EXPECT_TRUE(job_executed);
93}
94
95} // namespace testing
96} // namespace impeller
A task queue designed for managing compilation of pipeline state objects.
bool AddJob(const PipelineDescriptor &desc, const fml::closure &job)
Add a compilation job to the pending queue for the specified descriptor.
bool HasPendingJobs()
Check if there are any pending compilation jobs in the queue.
bool AddJobForTest(const PipelineDescriptor &desc, const fml::closure &job)
void OnJobAdded() override
Called by PostJobForDescriptor after a job has been successfully added to the queue....
void PostJob(const fml::closure &job) override
Post a compilation job to the worker task runner.
VkQueue queue
Definition main.cc:71
TEST(FrameTimingsRecorderTest, RecordVsync)
std::function< void()> closure
Definition closure.h:14