7 #include "flutter/testing/testing.h"
8 #include "fml/synchronization/waitable_event.h"
10 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
16 TEST(CommandEncoderVKTest, DeleteEncoderAfterThreadDies) {
19 std::shared_ptr<std::vector<std::string>> called_functions;
21 auto context = MockVulkanContextBuilder().Build();
22 called_functions = GetMockVulkanFunctions(context->GetDevice());
23 std::shared_ptr<CommandEncoderVK> encoder;
24 std::thread thread([&] {
26 encoder = factory.
Create();
32 std::find(called_functions->begin(), called_functions->end(),
33 "vkDestroyCommandPool");
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);
42 TEST(CommandEncoderVKTest, CleanupAfterSubmit) {
46 std::shared_ptr<std::vector<std::string>> called_functions;
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(
56 wait_for_thread_join.Wait();
57 wait_for_submit.Signal();
61 wait_for_thread_join.Signal();
62 wait_for_submit.Wait();
63 called_functions = GetMockVulkanFunctions(context->GetDevice());
68 std::find(called_functions->begin(), called_functions->end(),
69 "vkDestroyCommandPool");
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);