Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: gpu/command_buffer/client/cmd_buffer_helper_test.cc

Issue 555020: Redesigned CommandBuffer and NPDevice3D interfaces (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Tests for the Command Buffer Helper. 5 // Tests for the Command Buffer Helper.
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 9 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
10 #include "gpu/command_buffer/service/mocks.h" 10 #include "gpu/command_buffer/service/mocks.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if (put >= parser_put) { 95 if (put >= parser_put) {
96 // we're on the top side, check we are below the limit. 96 // we're on the top side, check we are below the limit.
97 EXPECT_GE(kNumCommandEntries, limit); 97 EXPECT_GE(kNumCommandEntries, limit);
98 } else { 98 } else {
99 // we're on the bottom side, check we are below get. 99 // we're on the bottom side, check we are below get.
100 EXPECT_GT(parser_get, limit); 100 EXPECT_GT(parser_get, limit);
101 } 101 }
102 } 102 }
103 } 103 }
104 104
105 int32 GetGetOffset() {
106 return command_buffer_->GetState().get_offset;
107 }
108
109 int32 GetPutOffset() {
110 return command_buffer_->GetState().put_offset;
111 }
112
113 parse_error::ParseError GetError() {
114 return command_buffer_->GetState().error;
115 }
116
105 CommandBufferOffset get_helper_put() { return helper_->put_; } 117 CommandBufferOffset get_helper_put() { return helper_->put_; }
106 118
107 base::AtExitManager at_exit_manager_; 119 base::AtExitManager at_exit_manager_;
108 MessageLoop message_loop_; 120 MessageLoop message_loop_;
109 scoped_ptr<AsyncAPIMock> api_mock_; 121 scoped_ptr<AsyncAPIMock> api_mock_;
110 scoped_ptr<CommandBufferService> command_buffer_; 122 scoped_ptr<CommandBufferService> command_buffer_;
111 CommandParser* parser_; 123 CommandParser* parser_;
112 scoped_ptr<CommandBufferHelper> helper_; 124 scoped_ptr<CommandBufferHelper> helper_;
113 Sequence sequence_; 125 Sequence sequence_;
114 }; 126 };
115 127
116 // Checks that commands in the buffer are properly executed, and that the 128 // Checks that commands in the buffer are properly executed, and that the
117 // status/error stay valid. 129 // status/error stay valid.
118 TEST_F(CommandBufferHelperTest, TestCommandProcessing) { 130 TEST_F(CommandBufferHelperTest, TestCommandProcessing) {
119 // Check initial state of the engine - it should have been configured by the 131 // Check initial state of the engine - it should have been configured by the
120 // helper. 132 // helper.
121 EXPECT_TRUE(parser_ != NULL); 133 EXPECT_TRUE(parser_ != NULL);
122 EXPECT_FALSE(command_buffer_->GetErrorStatus()); 134 EXPECT_EQ(parse_error::kParseNoError, GetError());
123 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError()); 135 EXPECT_EQ(0, GetGetOffset());
124 EXPECT_EQ(0, command_buffer_->GetGetOffset());
125 136
126 // Add 3 commands through the helper 137 // Add 3 commands through the helper
127 AddCommandWithExpect(parse_error::kParseNoError, 1, 0, NULL); 138 AddCommandWithExpect(parse_error::kParseNoError, 1, 0, NULL);
128 139
129 CommandBufferEntry args1[2]; 140 CommandBufferEntry args1[2];
130 args1[0].value_uint32 = 3; 141 args1[0].value_uint32 = 3;
131 args1[1].value_float = 4.f; 142 args1[1].value_float = 4.f;
132 AddCommandWithExpect(parse_error::kParseNoError, 2, 2, args1); 143 AddCommandWithExpect(parse_error::kParseNoError, 2, 2, args1);
133 144
134 CommandBufferEntry args2[2]; 145 CommandBufferEntry args2[2];
135 args2[0].value_uint32 = 5; 146 args2[0].value_uint32 = 5;
136 args2[1].value_float = 6.f; 147 args2[1].value_float = 6.f;
137 AddCommandWithExpect(parse_error::kParseNoError, 3, 2, args2); 148 AddCommandWithExpect(parse_error::kParseNoError, 3, 2, args2);
138 149
139 helper_->Flush(); 150 helper_->Flush();
140 // Check that the engine has work to do now. 151 // Check that the engine has work to do now.
141 EXPECT_FALSE(parser_->IsEmpty()); 152 EXPECT_FALSE(parser_->IsEmpty());
142 153
143 // Wait until it's done. 154 // Wait until it's done.
144 helper_->Finish(); 155 helper_->Finish();
145 // Check that the engine has no more work to do. 156 // Check that the engine has no more work to do.
146 EXPECT_TRUE(parser_->IsEmpty()); 157 EXPECT_TRUE(parser_->IsEmpty());
147 158
148 // Check that the commands did happen. 159 // Check that the commands did happen.
149 Mock::VerifyAndClearExpectations(api_mock_.get()); 160 Mock::VerifyAndClearExpectations(api_mock_.get());
150 161
151 // Check the error status. 162 // Check the error status.
152 EXPECT_FALSE(command_buffer_->GetErrorStatus()); 163 EXPECT_EQ(parse_error::kParseNoError, GetError());
153 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError());
154 } 164 }
155 165
156 // Checks that commands in the buffer are properly executed when wrapping the 166 // Checks that commands in the buffer are properly executed when wrapping the
157 // buffer, and that the status/error stay valid. 167 // buffer, and that the status/error stay valid.
158 TEST_F(CommandBufferHelperTest, TestCommandWrapping) { 168 TEST_F(CommandBufferHelperTest, TestCommandWrapping) {
159 // Add 5 commands of size 3 through the helper to make sure we do wrap. 169 // Add 5 commands of size 3 through the helper to make sure we do wrap.
160 CommandBufferEntry args1[2]; 170 CommandBufferEntry args1[2];
161 args1[0].value_uint32 = 3; 171 args1[0].value_uint32 = 3;
162 args1[1].value_float = 4.f; 172 args1[1].value_float = 4.f;
163 173
164 for (unsigned int i = 0; i < 5; ++i) { 174 for (unsigned int i = 0; i < 5; ++i) {
165 AddCommandWithExpect(parse_error::kParseNoError, i + 1, 2, args1); 175 AddCommandWithExpect(parse_error::kParseNoError, i + 1, 2, args1);
166 } 176 }
167 177
168 helper_->Finish(); 178 helper_->Finish();
169 // Check that the commands did happen. 179 // Check that the commands did happen.
170 Mock::VerifyAndClearExpectations(api_mock_.get()); 180 Mock::VerifyAndClearExpectations(api_mock_.get());
171 181
172 // Check the error status. 182 // Check the error status.
173 EXPECT_FALSE(command_buffer_->GetErrorStatus()); 183 EXPECT_EQ(parse_error::kParseNoError, GetError());
174 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError());
175 }
176
177
178 // Checks that commands in the buffer are properly executed, even if they
179 // generate a recoverable error. Check that the error status is properly set,
180 // and reset when queried.
181 TEST_F(CommandBufferHelperTest, TestRecoverableError) {
182 CommandBufferEntry args[2];
183 args[0].value_uint32 = 3;
184 args[1].value_float = 4.f;
185
186 // Create a command buffer with 3 commands, 2 of them generating errors
187 AddCommandWithExpect(parse_error::kParseNoError, 1, 2, args);
188 AddCommandWithExpect(parse_error::kParseUnknownCommand, 2, 2, args);
189 AddCommandWithExpect(parse_error::kParseInvalidArguments, 3, 2,
190 args);
191
192 helper_->Finish();
193 // Check that the commands did happen.
194 Mock::VerifyAndClearExpectations(api_mock_.get());
195
196 // Check that the error status was set to the first error.
197 EXPECT_EQ(parse_error::kParseUnknownCommand,
198 command_buffer_->ResetParseError());
199 // Check that the error status was reset after the query.
200 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError());
201 } 184 }
202 185
203 // Checks that asking for available entries work, and that the parser 186 // Checks that asking for available entries work, and that the parser
204 // effectively won't use that space. 187 // effectively won't use that space.
205 TEST_F(CommandBufferHelperTest, TestAvailableEntries) { 188 TEST_F(CommandBufferHelperTest, TestAvailableEntries) {
206 CommandBufferEntry args[2]; 189 CommandBufferEntry args[2];
207 args[0].value_uint32 = 3; 190 args[0].value_uint32 = 3;
208 args[1].value_float = 4.f; 191 args[1].value_float = 4.f;
209 192
210 // Add 2 commands through the helper - 8 entries 193 // Add 2 commands through the helper - 8 entries
(...skipping 11 matching lines...) Expand all
222 // Add more commands. 205 // Add more commands.
223 AddCommandWithExpect(parse_error::kParseNoError, 5, 2, args); 206 AddCommandWithExpect(parse_error::kParseNoError, 5, 2, args);
224 207
225 // Wait until everything is done done. 208 // Wait until everything is done done.
226 helper_->Finish(); 209 helper_->Finish();
227 210
228 // Check that the commands did happen. 211 // Check that the commands did happen.
229 Mock::VerifyAndClearExpectations(api_mock_.get()); 212 Mock::VerifyAndClearExpectations(api_mock_.get());
230 213
231 // Check the error status. 214 // Check the error status.
232 EXPECT_FALSE(command_buffer_->GetErrorStatus()); 215 EXPECT_EQ(parse_error::kParseNoError, GetError());
233 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError());
234 } 216 }
235 217
236 // Checks that the InsertToken/WaitForToken work. 218 // Checks that the InsertToken/WaitForToken work.
237 TEST_F(CommandBufferHelperTest, TestToken) { 219 TEST_F(CommandBufferHelperTest, TestToken) {
238 CommandBufferEntry args[2]; 220 CommandBufferEntry args[2];
239 args[0].value_uint32 = 3; 221 args[0].value_uint32 = 3;
240 args[1].value_float = 4.f; 222 args[1].value_float = 4.f;
241 223
242 // Add a first command. 224 // Add a first command.
243 AddCommandWithExpect(parse_error::kParseNoError, 3, 2, args); 225 AddCommandWithExpect(parse_error::kParseNoError, 3, 2, args);
244 // keep track of the buffer position. 226 // keep track of the buffer position.
245 CommandBufferOffset command1_put = get_helper_put(); 227 CommandBufferOffset command1_put = get_helper_put();
246 int32 token = helper_->InsertToken(); 228 int32 token = helper_->InsertToken();
247 229
248 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) 230 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _))
249 .WillOnce(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), 231 .WillOnce(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken),
250 Return(parse_error::kParseNoError))); 232 Return(parse_error::kParseNoError)));
251 // Add another command. 233 // Add another command.
252 AddCommandWithExpect(parse_error::kParseNoError, 4, 2, args); 234 AddCommandWithExpect(parse_error::kParseNoError, 4, 2, args);
253 helper_->WaitForToken(token); 235 helper_->WaitForToken(token);
254 // check that the get pointer is beyond the first command. 236 // check that the get pointer is beyond the first command.
255 EXPECT_LE(command1_put, command_buffer_->GetGetOffset()); 237 EXPECT_LE(command1_put, GetGetOffset());
256 helper_->Finish(); 238 helper_->Finish();
257 239
258 // Check that the commands did happen. 240 // Check that the commands did happen.
259 Mock::VerifyAndClearExpectations(api_mock_.get()); 241 Mock::VerifyAndClearExpectations(api_mock_.get());
260 242
261 // Check the error status. 243 // Check the error status.
262 EXPECT_FALSE(command_buffer_->GetErrorStatus()); 244 EXPECT_EQ(parse_error::kParseNoError, GetError());
263 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError());
264 } 245 }
265 246
266 } // namespace gpu 247 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.cc ('k') | gpu/command_buffer/client/fenced_allocator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698