forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test_helper.h
153 lines (122 loc) · 5.4 KB
/
client_test_helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Helper classes for implementing gpu client side unit tests.
#ifndef GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_
#define GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "gpu/command_buffer/client/gpu_control.h"
#include "gpu/command_buffer/common/cmd_buffer_common.h"
#include "gpu/command_buffer/common/gpu_memory_allocation.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/command_buffer/service/command_buffer_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gpu {
class FakeCommandBufferServiceBase : public CommandBufferServiceBase {
public:
static const int32_t kTransferBufferBaseId = 0x123;
static const int32_t kMaxTransferBuffers = 32;
FakeCommandBufferServiceBase();
~FakeCommandBufferServiceBase() override;
CommandBuffer::State GetState() override;
void SetReleaseCount(uint64_t release_count) override;
scoped_refptr<gpu::Buffer> GetTransferBuffer(int32_t id) override;
void SetToken(int32_t token) override;
void SetParseError(error::Error error) override;
void SetContextLostReason(error::ContextLostReason reason) override;
// Get's the Id of the next transfer buffer that will be returned
// by CreateTransferBuffer. This is useful for testing expected ids.
int32_t GetNextFreeTransferBufferId();
void FlushHelper(int32_t put_offset);
void SetGetBufferHelper(int transfer_buffer_id);
scoped_refptr<gpu::Buffer> CreateTransferBufferHelper(size_t size,
int32_t* id);
void DestroyTransferBufferHelper(int32_t id);
private:
scoped_refptr<Buffer> transfer_buffer_buffers_[kMaxTransferBuffers];
CommandBuffer::State state_;
};
class MockClientCommandBuffer : public CommandBuffer,
public FakeCommandBufferServiceBase {
public:
MockClientCommandBuffer();
~MockClientCommandBuffer() override;
State GetLastState() override;
State WaitForTokenInRange(int32_t start, int32_t end) override;
State WaitForGetOffsetInRange(uint32_t set_get_buffer_count,
int32_t start,
int32_t end) override;
void SetGetBuffer(int transfer_buffer_id) override;
scoped_refptr<gpu::Buffer> CreateTransferBuffer(size_t size,
int32_t* id) override;
// This is so we can use all the gmock functions when Flush is called.
MOCK_METHOD0(OnFlush, void());
MOCK_METHOD1(DestroyTransferBuffer, void(int32_t id));
void Flush(int32_t put_offset) override;
void OrderingBarrier(int32_t put_offset) override;
void DelegateToFake();
int32_t GetServicePutOffset() { return put_offset_; }
private:
int32_t put_offset_ = 0;
};
class MockClientCommandBufferMockFlush : public MockClientCommandBuffer {
public:
MockClientCommandBufferMockFlush();
virtual ~MockClientCommandBufferMockFlush();
MOCK_METHOD1(Flush, void(int32_t put_offset));
MOCK_METHOD1(OrderingBarrier, void(int32_t put_offset));
void DelegateToFake();
void DoFlush(int32_t put_offset);
};
class MockClientGpuControl : public GpuControl {
public:
MockClientGpuControl();
virtual ~MockClientGpuControl();
MOCK_METHOD1(SetGpuControlClient, void(GpuControlClient*));
MOCK_CONST_METHOD0(GetCapabilities, const Capabilities&());
MOCK_METHOD4(CreateImage,
int32_t(ClientBuffer buffer,
size_t width,
size_t height,
unsigned internalformat));
MOCK_METHOD1(DestroyImage, void(int32_t id));
// Workaround for move-only args in GMock.
MOCK_METHOD2(DoSignalQuery,
void(uint32_t query, base::OnceClosure* callback));
void SignalQuery(uint32_t query, base::OnceClosure callback) override {
DoSignalQuery(query, &callback);
}
MOCK_METHOD1(CreateStreamTexture, uint32_t(uint32_t));
MOCK_METHOD1(SetLock, void(base::Lock*));
MOCK_METHOD0(EnsureWorkVisible, void());
MOCK_CONST_METHOD0(GetNamespaceID, CommandBufferNamespace());
MOCK_CONST_METHOD0(GetCommandBufferID, CommandBufferId());
MOCK_METHOD0(FlushPendingWork, void());
MOCK_METHOD0(GenerateFenceSyncRelease, uint64_t());
MOCK_METHOD1(IsFenceSyncReleased, bool(uint64_t release));
// Workaround for move-only args in GMock.
MOCK_METHOD2(DoSignalSyncToken,
void(const SyncToken& sync_token, base::OnceClosure* callback));
void SignalSyncToken(const SyncToken& sync_token,
base::OnceClosure callback) override {
DoSignalSyncToken(sync_token, &callback);
}
MOCK_METHOD1(WaitSyncTokenHint, void(const SyncToken&));
MOCK_METHOD1(CanWaitUnverifiedSyncToken, bool(const SyncToken&));
MOCK_METHOD0(SetSnapshotRequested, void());
MOCK_METHOD2(CreateGpuFence,
void(uint32_t gpu_fence_id, ClientGpuFence source));
// OnceCallback isn't mockable?
void GetGpuFence(uint32_t gpu_fence_id,
base::OnceCallback<void(std::unique_ptr<gfx::GpuFence>)>
callback) override {}
private:
DISALLOW_COPY_AND_ASSIGN(MockClientGpuControl);
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_CLIENT_CLIENT_TEST_HELPER_H_