Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 284189b

Browse files
committed
added test
1 parent 393d73a commit 284189b

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

impeller/renderer/backend/vulkan/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ impeller_component("vulkan_unittests") {
99
testonly = true
1010
sources = [
1111
"blit_command_vk_unittests.cc",
12+
"command_encoder_vk_unittests.cc",
1213
"context_vk_unittests.cc",
1314
"pass_bindings_cache_unittests.cc",
1415
"test/mock_vulkan.cc",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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"
8+
#include "impeller/renderer/backend/vulkan/command_encoder_vk.h"
9+
#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
10+
11+
namespace impeller {
12+
namespace testing {
13+
14+
TEST(CommandEncoderVKTest, DeleteEncoderAfterThreadDies) {
15+
std::shared_ptr<std::vector<std::string>> called_functions;
16+
{
17+
auto context = CreateMockVulkanContext();
18+
called_functions = GetMockVulkanFunctions(context->GetDevice());
19+
std::shared_ptr<CommandEncoderVK> encoder;
20+
std::thread thread([&] {
21+
CommandEncoderFactoryVK factory(context);
22+
encoder = factory.Create();
23+
});
24+
thread.join();
25+
}
26+
auto destroy_pool =
27+
std::find(called_functions->begin(), called_functions->end(),
28+
"vkDestroyCommandPool");
29+
auto free_buffers =
30+
std::find(called_functions->begin(), called_functions->end(),
31+
"vkFreeCommandBuffers");
32+
EXPECT_TRUE(destroy_pool != called_functions->end());
33+
EXPECT_TRUE(free_buffers != called_functions->end());
34+
EXPECT_TRUE(free_buffers < destroy_pool);
35+
}
36+
37+
} // namespace testing
38+
} // namespace impeller

impeller/renderer/backend/vulkan/test/mock_vulkan.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,21 @@ void vkCmdSetViewport(VkCommandBuffer commandBuffer,
346346
mock_command_buffer->called_functions_->push_back("vkCmdSetViewport");
347347
}
348348

349+
void vkFreeCommandBuffers(VkDevice device,
350+
VkCommandPool commandPool,
351+
uint32_t commandBufferCount,
352+
const VkCommandBuffer* pCommandBuffers) {
353+
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
354+
mock_device->called_functions_->push_back("vkFreeCommandBuffers");
355+
}
356+
357+
void vkDestroyCommandPool(VkDevice device,
358+
VkCommandPool commandPool,
359+
const VkAllocationCallbacks* pAllocator) {
360+
MockDevice* mock_device = reinterpret_cast<MockDevice*>(device);
361+
mock_device->called_functions_->push_back("vkDestroyCommandPool");
362+
}
363+
349364
PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
350365
const char* pName) {
351366
if (strcmp("vkEnumerateInstanceExtensionProperties", pName) == 0) {
@@ -424,6 +439,10 @@ PFN_vkVoidFunction GetMockVulkanProcAddress(VkInstance instance,
424439
return (PFN_vkVoidFunction)vkCmdSetScissor;
425440
} else if (strcmp("vkCmdSetViewport", pName) == 0) {
426441
return (PFN_vkVoidFunction)vkCmdSetViewport;
442+
} else if (strcmp("vkDestroyCommandPool", pName) == 0) {
443+
return (PFN_vkVoidFunction)vkDestroyCommandPool;
444+
} else if (strcmp("vkFreeCommandBuffers", pName) == 0) {
445+
return (PFN_vkVoidFunction)vkFreeCommandBuffers;
427446
}
428447
return noop;
429448
}

0 commit comments

Comments
 (0)