Flutter Engine
The Flutter Engine
resource_manager_vk_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 <sys/types.h>
6#include <functional>
7#include <memory>
8#include <utility>
9#include "fml/closure.h"
11#include "gtest/gtest.h"
13
14namespace impeller {
15namespace testing {
16
17// While expected to be a singleton per context, the class does not enforce it.
18TEST(ResourceManagerVKTest, CreatesANewInstance) {
19 auto const a = ResourceManagerVK::Create();
20 auto const b = ResourceManagerVK::Create();
21 EXPECT_NE(a, b);
22}
23
24TEST(ResourceManagerVKTest, ReclaimMovesAResourceAndDestroysIt) {
26
27 auto waiter = fml::AutoResetWaitableEvent();
28 auto dead = false;
29 auto rattle = fml::ScopedCleanupClosure([&waiter]() { waiter.Signal(); });
30
31 // Not killed immediately.
32 EXPECT_FALSE(waiter.IsSignaledForTest());
33
34 {
36 manager, std::move(rattle));
37 }
38
39 waiter.Wait();
40}
41
42// Regression test for https://github.com/flutter/flutter/issues/134482.
43TEST(ResourceManagerVKTest, TerminatesWhenOutOfScope) {
44 // Originally, this shared_ptr was never destroyed, and the thread never
45 // terminated. This test ensures that the thread terminates when the
46 // ResourceManagerVK is out of scope.
47 std::weak_ptr<ResourceManagerVK> manager;
48
49 {
50 auto shared = ResourceManagerVK::Create();
51 manager = shared;
52 }
53
54 // The thread should have terminated.
55 EXPECT_EQ(manager.lock(), nullptr);
56}
57
58TEST(ResourceManagerVKTest, IsThreadSafe) {
59 // In a typical app, there is a single ResourceManagerVK per app, shared b/w
60 // threads.
61 //
62 // This test ensures that the ResourceManagerVK is thread-safe.
63 std::weak_ptr<ResourceManagerVK> manager;
64
65 {
67
68 // Spawn two threads, and have them both put resources into the manager.
69 struct MockResource {};
70
71 std::thread thread1([&manager]() {
73 });
74
75 std::thread thread2([&manager]() {
77 });
78
79 thread1.join();
80 thread2.join();
81 }
82
83 // The thread should have terminated.
84 EXPECT_EQ(manager.lock(), nullptr);
85}
86
87} // namespace testing
88} // namespace impeller
static SkString resource(SkPDFResourceType type, int index)
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition: closure.h:32
static std::shared_ptr< ResourceManagerVK > Create()
Creates a shared resource manager (a dedicated thread).
A unique handle to a resource which will be reclaimed by the specified resource manager.
static bool b
struct MyStruct a[10]
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font manager
Definition: switches.h:218
TEST(AiksCanvasTest, EmptyCullRect)