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

Side by Side Diff: gpu/command_buffer/service/cmd_parser_test.cc

Issue 8919014: Revert "Revert 113479 - Revert "Revert 113250 - Add CommandBuffer::SetGetBuffer"" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 parser. 5 // Tests for the command parser.
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "gpu/command_buffer/service/cmd_parser.h" 9 #include "gpu/command_buffer/service/cmd_parser.h"
10 #include "gpu/command_buffer/service/mocks.h" 10 #include "gpu/command_buffer/service/mocks.h"
(...skipping 30 matching lines...) Expand all
41 .WillOnce(Return(_return)); 41 .WillOnce(Return(_return));
42 } 42 }
43 43
44 // Creates a parser, with a buffer of the specified size (in entries). 44 // Creates a parser, with a buffer of the specified size (in entries).
45 CommandParser *MakeParser(unsigned int entry_count) { 45 CommandParser *MakeParser(unsigned int entry_count) {
46 size_t shm_size = buffer_entry_count_ * 46 size_t shm_size = buffer_entry_count_ *
47 sizeof(CommandBufferEntry); // NOLINT 47 sizeof(CommandBufferEntry); // NOLINT
48 size_t command_buffer_size = entry_count * 48 size_t command_buffer_size = entry_count *
49 sizeof(CommandBufferEntry); // NOLINT 49 sizeof(CommandBufferEntry); // NOLINT
50 DCHECK_LE(command_buffer_size, shm_size); 50 DCHECK_LE(command_buffer_size, shm_size);
51 return new CommandParser(buffer(), 51 CommandParser* parser = new CommandParser(api_mock());
52 shm_size, 52
53 0, 53 parser->SetBuffer(buffer(), shm_size, 0, command_buffer_size);
54 command_buffer_size, 54 return parser;
55 0,
56 api_mock());
57 } 55 }
58 56
59 unsigned int buffer_entry_count() { return 20; } 57 unsigned int buffer_entry_count() { return 20; }
60 AsyncAPIMock *api_mock() { return api_mock_.get(); } 58 AsyncAPIMock *api_mock() { return api_mock_.get(); }
61 CommandBufferEntry *buffer() { return buffer_.get(); } 59 CommandBufferEntry *buffer() { return buffer_.get(); }
62 private: 60 private:
63 unsigned int buffer_entry_count_; 61 unsigned int buffer_entry_count_;
64 scoped_ptr<AsyncAPIMock> api_mock_; 62 scoped_ptr<AsyncAPIMock> api_mock_;
65 scoped_array<CommandBufferEntry> buffer_; 63 scoped_array<CommandBufferEntry> buffer_;
66 Sequence sequence_; 64 Sequence sequence_;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // correctly. 279 // correctly.
282 EXPECT_EQ(put_post_fail, parser->get()); 280 EXPECT_EQ(put_post_fail, parser->get());
283 Mock::VerifyAndClearExpectations(api_mock()); 281 Mock::VerifyAndClearExpectations(api_mock());
284 // make the second one succeed, and check that the parser recovered fine. 282 // make the second one succeed, and check that the parser recovered fine.
285 AddDoCommandExpect(error::kNoError, 4, 0, NULL); 283 AddDoCommandExpect(error::kNoError, 4, 0, NULL);
286 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands()); 284 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands());
287 EXPECT_EQ(put, parser->get()); 285 EXPECT_EQ(put, parser->get());
288 Mock::VerifyAndClearExpectations(api_mock()); 286 Mock::VerifyAndClearExpectations(api_mock());
289 } 287 }
290 288
289 TEST_F(CommandParserTest, SetBuffer) {
290 scoped_ptr<CommandParser> parser(MakeParser(3));
291 CommandBufferOffset put = parser->put();
292 CommandHeader header;
293
294 // add a single command, no args
295 header.size = 2;
296 header.command = 123;
297 buffer()[put++].value_header = header;
298 buffer()[put++].value_int32 = 456;
299
300 CommandBufferEntry param_array[1];
301 param_array[0].value_int32 = 456;
302
303 parser->set_put(put);
304 AddDoCommandExpect(error::kNoError, 123, 1, param_array);
305 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands());
306 // We should have advanced 2 entries
307 EXPECT_EQ(2, parser->get());
308 Mock::VerifyAndClearExpectations(api_mock());
309
310 scoped_array<CommandBufferEntry> buffer2(new CommandBufferEntry[2]);
311 parser->SetBuffer(
312 buffer2.get(), sizeof(CommandBufferEntry) * 2, 0,
313 sizeof(CommandBufferEntry) * 2);
314 // The put and get should have reset to 0.
315 EXPECT_EQ(0, parser->get());
316 EXPECT_EQ(0, parser->put());
317 }
318
291 } // namespace gpu 319 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/cmd_parser.cc ('k') | gpu/command_buffer/service/command_buffer_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698