Flutter Impeller
command_encoder_vk_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 
5 #include <thread>
6 
7 #include "flutter/testing/testing.h" // IWYU pragma: keep
8 #include "fml/synchronization/waitable_event.h"
10 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
11 
12 namespace impeller {
13 namespace testing {
14 
15 TEST(CommandEncoderVKTest, DeleteEncoderAfterThreadDies) {
16  // Tests that when a CommandEncoderVK is deleted that it will clean up its
17  // command buffers before it cleans up its command pool.
18  std::shared_ptr<std::vector<std::string>> called_functions;
19  {
20  auto context = MockVulkanContextBuilder().Build();
21  called_functions = GetMockVulkanFunctions(context->GetDevice());
22  std::shared_ptr<CommandEncoderVK> encoder;
23  std::thread thread([&] {
24  CommandEncoderFactoryVK factory(context);
25  encoder = factory.Create();
26  });
27  thread.join();
28  context->Shutdown();
29  }
30  auto destroy_pool =
31  std::find(called_functions->begin(), called_functions->end(),
32  "vkDestroyCommandPool");
33  auto free_buffers =
34  std::find(called_functions->begin(), called_functions->end(),
35  "vkFreeCommandBuffers");
36  EXPECT_TRUE(destroy_pool != called_functions->end());
37  EXPECT_TRUE(free_buffers != called_functions->end());
38  EXPECT_TRUE(free_buffers < destroy_pool);
39 }
40 
41 TEST(CommandEncoderVKTest, CleanupAfterSubmit) {
42  // This tests deleting the TrackedObjects where the thread is killed before
43  // the fence waiter has disposed of them, making sure the command buffer and
44  // its pools are deleted in that order.
45  std::shared_ptr<std::vector<std::string>> called_functions;
46  {
47  fml::AutoResetWaitableEvent wait_for_submit;
48  fml::AutoResetWaitableEvent wait_for_thread_join;
49  auto context = MockVulkanContextBuilder().Build();
50  std::thread thread([&] {
51  CommandEncoderFactoryVK factory(context);
52  std::shared_ptr<CommandEncoderVK> encoder = factory.Create();
53  encoder->Submit([&](bool success) {
54  ASSERT_TRUE(success);
55  wait_for_thread_join.Wait();
56  wait_for_submit.Signal();
57  });
58  });
59  thread.join();
60  wait_for_thread_join.Signal();
61  wait_for_submit.Wait();
62  called_functions = GetMockVulkanFunctions(context->GetDevice());
63  context->Shutdown();
64  }
65 
66  auto destroy_pool =
67  std::find(called_functions->begin(), called_functions->end(),
68  "vkDestroyCommandPool");
69  auto free_buffers =
70  std::find(called_functions->begin(), called_functions->end(),
71  "vkFreeCommandBuffers");
72  EXPECT_TRUE(destroy_pool != called_functions->end());
73  EXPECT_TRUE(free_buffers != called_functions->end());
74  EXPECT_TRUE(free_buffers < destroy_pool);
75 }
76 
77 } // namespace testing
78 } // namespace impeller
command_encoder_vk.h
impeller::CommandEncoderFactoryVK
Definition: command_encoder_vk.h:30
impeller::testing::TEST
TEST(AiksCanvasTest, EmptyCullRect)
Definition: canvas_unittests.cc:17
impeller
Definition: aiks_context.cc:10
impeller::CommandEncoderFactoryVK::Create
std::shared_ptr< CommandEncoderVK > Create()
Definition: command_encoder_vk.cc:101