cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / gpu / command_buffer / client / query_tracker_unittest.cc
blob800c479ec852083ef70dc9e26afc20f0eeba6061
1 // Copyright (c) 2012 The Chromium 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.
5 // Tests for the QueryTracker.
7 #include "gpu/command_buffer/client/query_tracker.h"
9 #include <GLES2/gl2ext.h>
10 #include "base/memory/scoped_ptr.h"
11 #include "gpu/command_buffer/client/client_test_helper.h"
12 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
13 #include "gpu/command_buffer/client/mapped_memory.h"
14 #include "gpu/command_buffer/common/command_buffer.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/gmock/include/gmock/gmock.h"
18 namespace gpu {
19 namespace gles2 {
21 class QuerySyncManagerTest : public testing::Test {
22 protected:
23 static const int32 kNumCommandEntries = 400;
24 static const int32 kCommandBufferSizeBytes =
25 kNumCommandEntries * sizeof(CommandBufferEntry);
27 virtual void SetUp() {
28 command_buffer_.reset(new MockClientCommandBuffer());
29 helper_.reset(new GLES2CmdHelper(command_buffer_.get()));
30 helper_->Initialize(kCommandBufferSizeBytes);
31 mapped_memory_.reset(new MappedMemoryManager(
32 helper_.get(), MappedMemoryManager::kNoLimit));
33 sync_manager_.reset(new QuerySyncManager(mapped_memory_.get()));
36 virtual void TearDown() {
37 sync_manager_.reset();
38 mapped_memory_.reset();
39 helper_.reset();
40 command_buffer_.reset();
43 scoped_ptr<CommandBuffer> command_buffer_;
44 scoped_ptr<GLES2CmdHelper> helper_;
45 scoped_ptr<MappedMemoryManager> mapped_memory_;
46 scoped_ptr<QuerySyncManager> sync_manager_;
49 TEST_F(QuerySyncManagerTest, Basic) {
50 QuerySyncManager::QueryInfo infos[4];
51 memset(&infos, 0xBD, sizeof(infos));
53 for (size_t ii = 0; ii < arraysize(infos); ++ii) {
54 EXPECT_TRUE(sync_manager_->Alloc(&infos[ii]));
55 EXPECT_NE(0, infos[ii].shm_id);
56 ASSERT_TRUE(infos[ii].sync != NULL);
57 EXPECT_EQ(0u, infos[ii].sync->process_count);
58 EXPECT_EQ(0u, infos[ii].sync->result);
61 for (size_t ii = 0; ii < arraysize(infos); ++ii) {
62 sync_manager_->Free(infos[ii]);
66 TEST_F(QuerySyncManagerTest, DontFree) {
67 QuerySyncManager::QueryInfo infos[4];
68 memset(&infos, 0xBD, sizeof(infos));
70 for (size_t ii = 0; ii < arraysize(infos); ++ii) {
71 EXPECT_TRUE(sync_manager_->Alloc(&infos[ii]));
75 class QueryTrackerTest : public testing::Test {
76 protected:
77 static const int32 kNumCommandEntries = 400;
78 static const int32 kCommandBufferSizeBytes =
79 kNumCommandEntries * sizeof(CommandBufferEntry);
81 virtual void SetUp() {
82 command_buffer_.reset(new MockClientCommandBuffer());
83 helper_.reset(new GLES2CmdHelper(command_buffer_.get()));
84 helper_->Initialize(kCommandBufferSizeBytes);
85 mapped_memory_.reset(new MappedMemoryManager(
86 helper_.get(), MappedMemoryManager::kNoLimit));
87 query_tracker_.reset(new QueryTracker(mapped_memory_.get()));
90 virtual void TearDown() {
91 query_tracker_.reset();
92 mapped_memory_.reset();
93 helper_.reset();
94 command_buffer_.reset();
97 QuerySync* GetSync(QueryTracker::Query* query) {
98 return query->info_.sync;
101 QuerySyncManager::Bucket* GetBucket(QueryTracker::Query* query) {
102 return query->info_.bucket;
105 scoped_ptr<CommandBuffer> command_buffer_;
106 scoped_ptr<GLES2CmdHelper> helper_;
107 scoped_ptr<MappedMemoryManager> mapped_memory_;
108 scoped_ptr<QueryTracker> query_tracker_;
111 TEST_F(QueryTrackerTest, Basic) {
112 const GLuint kId1 = 123;
113 const GLuint kId2 = 124;
115 // Check we can create a Query.
116 QueryTracker::Query* query = query_tracker_->CreateQuery(
117 kId1, GL_ANY_SAMPLES_PASSED_EXT);
118 ASSERT_TRUE(query != NULL);
119 // Check we can get the same Query.
120 EXPECT_EQ(query, query_tracker_->GetQuery(kId1));
121 // Check we get nothing for a non-existent query.
122 EXPECT_TRUE(query_tracker_->GetQuery(kId2) == NULL);
123 // Check we can delete the query.
124 query_tracker_->RemoveQuery(kId1);
125 // Check we get nothing for a non-existent query.
126 EXPECT_TRUE(query_tracker_->GetQuery(kId1) == NULL);
129 TEST_F(QueryTrackerTest, Query) {
130 const GLuint kId1 = 123;
131 const int32 kToken = 46;
132 const uint32 kResult = 456;
134 // Create a Query.
135 QueryTracker::Query* query = query_tracker_->CreateQuery(
136 kId1, GL_ANY_SAMPLES_PASSED_EXT);
137 ASSERT_TRUE(query != NULL);
138 EXPECT_TRUE(query->NeverUsed());
139 EXPECT_FALSE(query->Pending());
140 EXPECT_EQ(0, query->token());
141 EXPECT_EQ(0u, query->submit_count());
143 // Check MarkAsActive.
144 query->MarkAsActive();
145 EXPECT_FALSE(query->NeverUsed());
146 EXPECT_FALSE(query->Pending());
147 EXPECT_EQ(0, query->token());
148 EXPECT_EQ(1u, query->submit_count());
150 // Check MarkAsPending.
151 query->MarkAsPending(kToken);
152 EXPECT_FALSE(query->NeverUsed());
153 EXPECT_TRUE(query->Pending());
154 EXPECT_EQ(kToken, query->token());
155 EXPECT_EQ(1u, query->submit_count());
157 // Check CheckResultsAvailable.
158 EXPECT_FALSE(query->CheckResultsAvailable(helper_.get()));
159 EXPECT_FALSE(query->NeverUsed());
160 EXPECT_TRUE(query->Pending());
162 // Simulate GPU process marking it as available.
163 QuerySync* sync = GetSync(query);
164 sync->process_count = query->submit_count();
165 sync->result = kResult;
167 // Check CheckResultsAvailable.
168 EXPECT_TRUE(query->CheckResultsAvailable(helper_.get()));
169 EXPECT_EQ(kResult, query->GetResult());
170 EXPECT_FALSE(query->NeverUsed());
171 EXPECT_FALSE(query->Pending());
174 TEST_F(QueryTrackerTest, Remove) {
175 const GLuint kId1 = 123;
176 const int32 kToken = 46;
177 const uint32 kResult = 456;
179 // Create a Query.
180 QueryTracker::Query* query = query_tracker_->CreateQuery(
181 kId1, GL_ANY_SAMPLES_PASSED_EXT);
182 ASSERT_TRUE(query != NULL);
184 QuerySyncManager::Bucket* bucket = GetBucket(query);
185 EXPECT_EQ(1u, bucket->used_query_count);
187 query->MarkAsActive();
188 query->MarkAsPending(kToken);
190 query_tracker_->RemoveQuery(kId1);
191 // Check we get nothing for a non-existent query.
192 EXPECT_TRUE(query_tracker_->GetQuery(kId1) == NULL);
194 // Check that memory was not freed.
195 EXPECT_EQ(1u, bucket->used_query_count);
197 // Simulate GPU process marking it as available.
198 QuerySync* sync = GetSync(query);
199 sync->process_count = query->submit_count();
200 sync->result = kResult;
202 // Check FreeCompletedQueries.
203 query_tracker_->FreeCompletedQueries();
204 EXPECT_EQ(0u, bucket->used_query_count);
207 } // namespace gles2
208 } // namespace gpu