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