Flutter Engine
The Flutter Engine
mock_vulkan_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 "flutter/testing/testing.h" // IWYU pragma: keep
6#include "gtest/gtest.h"
8#include "vulkan/vulkan_enums.hpp"
9
10namespace impeller {
11namespace testing {
12
13TEST(MockVulkanContextTest, IsThreadSafe) {
14 // In a typical app, there is a single ContextVK per app, shared b/w threads.
15 //
16 // This test ensures that the (mock) ContextVK is thread-safe.
17 auto const context = MockVulkanContextBuilder().Build();
18
19 // Spawn two threads, and have them create a CommandPoolVK each.
20 std::thread thread1([&context]() {
21 auto const pool = context->GetCommandPoolRecycler()->Get();
23 });
24
25 std::thread thread2([&context]() {
26 auto const pool = context->GetCommandPoolRecycler()->Get();
28 });
29
30 thread1.join();
31 thread2.join();
32
33 context->Shutdown();
34}
35
36TEST(MockVulkanContextTest, DefaultFenceAlwaysReportsSuccess) {
37 auto const context = MockVulkanContextBuilder().Build();
38 auto const device = context->GetDevice();
39
40 auto fence = device.createFenceUnique({}).value;
41 EXPECT_EQ(vk::Result::eSuccess, device.getFenceStatus(*fence));
42}
43
44TEST(MockVulkanContextTest, MockedFenceReportsStatus) {
45 auto const context = MockVulkanContextBuilder().Build();
46
47 auto const device = context->GetDevice();
48 auto fence = device.createFenceUnique({}).value;
49 MockFence::SetStatus(fence, vk::Result::eNotReady);
50
51 EXPECT_EQ(vk::Result::eNotReady, device.getFenceStatus(fence.get()));
52
53 MockFence::SetStatus(fence, vk::Result::eSuccess);
54 EXPECT_EQ(vk::Result::eSuccess, device.getFenceStatus(*fence));
55}
56
57} // namespace testing
58} // namespace impeller
AutoreleasePool pool
void SetStatus(vk::Result result)
Definition: mock_vulkan.h:33
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
VkDevice device
Definition: main.cc:53
uint8_t value
const GrXPFactory * Get(SkBlendMode mode)
TEST(AiksCanvasTest, EmptyCullRect)
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678