Flutter Engine
The Flutter Engine
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
12
13namespace impeller {
14namespace testing {
15
16TEST(CommandEncoderVKTest, DeleteEncoderAfterThreadDies) {
17 // Tests that when a CommandEncoderVK is deleted that it will clean up its
18 // command buffers before it cleans up its command pool.
19 std::shared_ptr<std::vector<std::string>> called_functions;
20 {
21 auto context = MockVulkanContextBuilder().Build();
22 called_functions = GetMockVulkanFunctions(context->GetDevice());
23 std::shared_ptr<CommandEncoderVK> encoder;
24 std::thread thread([&] {
25 CommandEncoderFactoryVK factory(context);
26 encoder = factory.Create();
27 });
28 thread.join();
29 context->Shutdown();
30 }
31 auto destroy_pool =
32 std::find(called_functions->begin(), called_functions->end(),
33 "vkDestroyCommandPool");
34 auto free_buffers =
35 std::find(called_functions->begin(), called_functions->end(),
36 "vkFreeCommandBuffers");
37 EXPECT_TRUE(destroy_pool != called_functions->end());
38 EXPECT_TRUE(free_buffers != called_functions->end());
39 EXPECT_TRUE(free_buffers < destroy_pool);
40}
41
42TEST(CommandEncoderVKTest, CleanupAfterSubmit) {
43 // This tests deleting the TrackedObjects where the thread is killed before
44 // the fence waiter has disposed of them, making sure the command buffer and
45 // its pools are deleted in that order.
46 std::shared_ptr<std::vector<std::string>> called_functions;
47 {
48 fml::AutoResetWaitableEvent wait_for_submit;
49 fml::AutoResetWaitableEvent wait_for_thread_join;
50 auto context = MockVulkanContextBuilder().Build();
51 std::thread thread([&] {
52 auto buffer = context->CreateCommandBuffer();
53 context->GetCommandQueue()->Submit(
54 {buffer}, [&](CommandBuffer::Status status) {
55 ASSERT_EQ(status, CommandBuffer::Status::kCompleted);
56 wait_for_thread_join.Wait();
57 wait_for_submit.Signal();
58 });
59 });
60 thread.join();
61 wait_for_thread_join.Signal();
62 wait_for_submit.Wait();
63 called_functions = GetMockVulkanFunctions(context->GetDevice());
64 context->Shutdown();
65 }
66
67 auto destroy_pool =
68 std::find(called_functions->begin(), called_functions->end(),
69 "vkDestroyCommandPool");
70 auto free_buffers =
71 std::find(called_functions->begin(), called_functions->end(),
72 "vkFreeCommandBuffers");
73 EXPECT_TRUE(destroy_pool != called_functions->end());
74 EXPECT_TRUE(free_buffers != called_functions->end());
75 EXPECT_TRUE(free_buffers < destroy_pool);
76}
77
78} // namespace testing
79} // namespace impeller
int find(T *array, int N, T item)
std::shared_ptr< CommandEncoderVK > Create()
std::shared_ptr< ContextVK > Build()
Create a Vulkan context with Vulkan functions mocked. The caller is given a chance to tinker on the s...
Definition: mock_vulkan.cc:912
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
std::shared_ptr< std::vector< std::string > > GetMockVulkanFunctions(VkDevice device)
Definition: mock_vulkan.cc:926
TEST(AiksCanvasTest, EmptyCullRect)
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678