| OLD | NEW |
| 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 Loading... |
| 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 CommandParser* parser = new CommandParser(api_mock()); | 51 return new CommandParser(buffer(), |
| 52 | 52 shm_size, |
| 53 parser->SetBuffer(buffer(), shm_size, 0, command_buffer_size); | 53 0, |
| 54 return parser; | 54 command_buffer_size, |
| 55 0, |
| 56 api_mock()); |
| 55 } | 57 } |
| 56 | 58 |
| 57 unsigned int buffer_entry_count() { return 20; } | 59 unsigned int buffer_entry_count() { return 20; } |
| 58 AsyncAPIMock *api_mock() { return api_mock_.get(); } | 60 AsyncAPIMock *api_mock() { return api_mock_.get(); } |
| 59 CommandBufferEntry *buffer() { return buffer_.get(); } | 61 CommandBufferEntry *buffer() { return buffer_.get(); } |
| 60 private: | 62 private: |
| 61 unsigned int buffer_entry_count_; | 63 unsigned int buffer_entry_count_; |
| 62 scoped_ptr<AsyncAPIMock> api_mock_; | 64 scoped_ptr<AsyncAPIMock> api_mock_; |
| 63 scoped_array<CommandBufferEntry> buffer_; | 65 scoped_array<CommandBufferEntry> buffer_; |
| 64 Sequence sequence_; | 66 Sequence sequence_; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // correctly. | 281 // correctly. |
| 280 EXPECT_EQ(put_post_fail, parser->get()); | 282 EXPECT_EQ(put_post_fail, parser->get()); |
| 281 Mock::VerifyAndClearExpectations(api_mock()); | 283 Mock::VerifyAndClearExpectations(api_mock()); |
| 282 // make the second one succeed, and check that the parser recovered fine. | 284 // make the second one succeed, and check that the parser recovered fine. |
| 283 AddDoCommandExpect(error::kNoError, 4, 0, NULL); | 285 AddDoCommandExpect(error::kNoError, 4, 0, NULL); |
| 284 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands()); | 286 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands()); |
| 285 EXPECT_EQ(put, parser->get()); | 287 EXPECT_EQ(put, parser->get()); |
| 286 Mock::VerifyAndClearExpectations(api_mock()); | 288 Mock::VerifyAndClearExpectations(api_mock()); |
| 287 } | 289 } |
| 288 | 290 |
| 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 | |
| 319 } // namespace gpu | 291 } // namespace gpu |
| OLD | NEW |