| OLD | NEW |
| 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, | 29 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, |
| 30 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface | 30 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface |
| 31 // (calling it directly, not through the RPC mechanism). | 31 // (calling it directly, not through the RPC mechanism). |
| 32 class CommandBufferHelperTest : public testing::Test { | 32 class CommandBufferHelperTest : public testing::Test { |
| 33 protected: | 33 protected: |
| 34 virtual void SetUp() { | 34 virtual void SetUp() { |
| 35 api_mock_.reset(new AsyncAPIMock); | 35 api_mock_.reset(new AsyncAPIMock); |
| 36 // ignore noops in the mock - we don't want to inspect the internals of the | 36 // ignore noops in the mock - we don't want to inspect the internals of the |
| 37 // helper. | 37 // helper. |
| 38 EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) | 38 EXPECT_CALL(*api_mock_, DoCommand(0, _, _)) |
| 39 .WillRepeatedly(Return(parse_error::kParseNoError)); | 39 .WillRepeatedly(Return(parse_error::kParseNoError)); |
| 40 | 40 |
| 41 command_buffer_.reset(new CommandBufferService); | 41 command_buffer_.reset(new CommandBufferService); |
| 42 command_buffer_->Initialize(kNumCommandEntries); | 42 command_buffer_->Initialize(kNumCommandEntries); |
| 43 Buffer ring_buffer = command_buffer_->GetRingBuffer(); | 43 Buffer ring_buffer = command_buffer_->GetRingBuffer(); |
| 44 | 44 |
| 45 parser_ = new CommandParser(ring_buffer.ptr, | 45 parser_ = new CommandParser(ring_buffer.ptr, |
| 46 ring_buffer.size, | 46 ring_buffer.size, |
| 47 0, | 47 0, |
| 48 ring_buffer.size, | 48 ring_buffer.size, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 63 virtual void TearDown() { | 63 virtual void TearDown() { |
| 64 // If the GPUProcessor posts any tasks, this forces them to run. | 64 // If the GPUProcessor posts any tasks, this forces them to run. |
| 65 MessageLoop::current()->RunAllPending(); | 65 MessageLoop::current()->RunAllPending(); |
| 66 helper_.release(); | 66 helper_.release(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Adds a command to the buffer through the helper, while adding it as an | 69 // Adds a command to the buffer through the helper, while adding it as an |
| 70 // expected call on the API mock. | 70 // expected call on the API mock. |
| 71 void AddCommandWithExpect(parse_error::ParseError _return, | 71 void AddCommandWithExpect(parse_error::ParseError _return, |
| 72 unsigned int command, | 72 unsigned int command, |
| 73 unsigned int arg_count, | 73 int arg_count, |
| 74 CommandBufferEntry *args) { | 74 CommandBufferEntry *args) { |
| 75 helper_->AddCommand(command, arg_count, args); | 75 CommandHeader header; |
| 76 header.size = arg_count + 1; |
| 77 header.command = command; |
| 78 CommandBufferEntry* cmds = helper_->GetSpace(arg_count + 1); |
| 79 CommandBufferOffset put = 0; |
| 80 cmds[put++].value_header = header; |
| 81 for (int ii = 0; ii < arg_count; ++ii) { |
| 82 cmds[put++] = args[ii]; |
| 83 } |
| 84 |
| 76 EXPECT_CALL(*api_mock_, DoCommand(command, arg_count, | 85 EXPECT_CALL(*api_mock_, DoCommand(command, arg_count, |
| 77 Truly(AsyncAPIMock::IsArgs(arg_count, args)))) | 86 Truly(AsyncAPIMock::IsArgs(arg_count, args)))) |
| 78 .InSequence(sequence_) | 87 .InSequence(sequence_) |
| 79 .WillOnce(Return(_return)); | 88 .WillOnce(Return(_return)); |
| 80 } | 89 } |
| 81 | 90 |
| 82 // Checks that the buffer from put to put+size is free in the parser. | 91 // Checks that the buffer from put to put+size is free in the parser. |
| 83 void CheckFreeSpace(CommandBufferOffset put, unsigned int size) { | 92 void CheckFreeSpace(CommandBufferOffset put, unsigned int size) { |
| 84 CommandBufferOffset parser_put = parser_->put(); | 93 CommandBufferOffset parser_put = parser_->put(); |
| 85 CommandBufferOffset parser_get = parser_->get(); | 94 CommandBufferOffset parser_get = parser_->get(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 266 |
| 258 // Check that the commands did happen. | 267 // Check that the commands did happen. |
| 259 Mock::VerifyAndClearExpectations(api_mock_.get()); | 268 Mock::VerifyAndClearExpectations(api_mock_.get()); |
| 260 | 269 |
| 261 // Check the error status. | 270 // Check the error status. |
| 262 EXPECT_FALSE(command_buffer_->GetErrorStatus()); | 271 EXPECT_FALSE(command_buffer_->GetErrorStatus()); |
| 263 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError()); | 272 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError()); |
| 264 } | 273 } |
| 265 | 274 |
| 266 } // namespace gpu | 275 } // namespace gpu |
| OLD | NEW |