7 #include "flutter/testing/testing.h"
8 #include "fml/synchronization/waitable_event.h"
10 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
15 TEST(CommandEncoderVKTest, DeleteEncoderAfterThreadDies) {
18 std::shared_ptr<std::vector<std::string>> called_functions;
20 auto context = MockVulkanContextBuilder().Build();
21 called_functions = GetMockVulkanFunctions(context->GetDevice());
22 std::shared_ptr<CommandEncoderVK> encoder;
23 std::thread thread([&] {
25 encoder = factory.
Create();
31 std::find(called_functions->begin(), called_functions->end(),
32 "vkDestroyCommandPool");
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);
41 TEST(CommandEncoderVKTest, CleanupAfterSubmit) {
45 std::shared_ptr<std::vector<std::string>> called_functions;
47 fml::AutoResetWaitableEvent wait_for_submit;
48 fml::AutoResetWaitableEvent wait_for_thread_join;
49 auto context = MockVulkanContextBuilder().Build();
50 std::thread thread([&] {
52 std::shared_ptr<CommandEncoderVK> encoder = factory.
Create();
53 encoder->Submit([&](
bool success) {
55 wait_for_thread_join.Wait();
56 wait_for_submit.Signal();
60 wait_for_thread_join.Signal();
61 wait_for_submit.Wait();
62 called_functions = GetMockVulkanFunctions(context->GetDevice());
67 std::find(called_functions->begin(), called_functions->end(),
68 "vkDestroyCommandPool");
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);