| 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" |
| 11 #include "gpu/command_buffer/service/command_buffer_service.h" | 11 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 12 #include "gpu/command_buffer/service/gpu_processor.h" | 12 #include "gpu/command_buffer/service/gpu_processor.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace gpu { | 15 namespace gpu { |
| 16 | 16 |
| 17 using gpu::CommandBufferService; | |
| 18 using gpu::GPUProcessor; | |
| 19 using testing::Return; | 17 using testing::Return; |
| 20 using testing::Mock; | 18 using testing::Mock; |
| 21 using testing::Truly; | 19 using testing::Truly; |
| 22 using testing::Sequence; | 20 using testing::Sequence; |
| 23 using testing::DoAll; | 21 using testing::DoAll; |
| 24 using testing::Invoke; | 22 using testing::Invoke; |
| 25 using testing::_; | 23 using testing::_; |
| 26 | 24 |
| 27 const int32 kNumCommandEntries = 10; | 25 const int32 kNumCommandEntries = 10; |
| 28 const int32 kCommandBufferSizeBytes = | 26 const int32 kCommandBufferSizeBytes = |
| 29 kNumCommandEntries * sizeof(CommandBufferEntry); | 27 kNumCommandEntries * sizeof(CommandBufferEntry); |
| 30 | 28 |
| 31 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, | 29 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, |
| 32 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface | 30 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface |
| 33 // (calling it directly, not through the RPC mechanism). | 31 // (calling it directly, not through the RPC mechanism). |
| 34 class CommandBufferHelperTest : public testing::Test { | 32 class CommandBufferHelperTest : public testing::Test { |
| 35 protected: | 33 protected: |
| 36 virtual void SetUp() { | 34 virtual void SetUp() { |
| 37 api_mock_.reset(new AsyncAPIMock); | 35 api_mock_.reset(new AsyncAPIMock); |
| 38 // 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 |
| 39 // helper. | 37 // helper. |
| 40 EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) | 38 EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) |
| 41 .WillRepeatedly(Return(parse_error::kParseNoError)); | 39 .WillRepeatedly(Return(parse_error::kParseNoError)); |
| 42 | 40 |
| 43 command_buffer_.reset(new CommandBufferService); | 41 command_buffer_.reset(new CommandBufferService); |
| 44 base::SharedMemory* ring_buffer = command_buffer_->Initialize( | 42 command_buffer_->Initialize(kNumCommandEntries); |
| 45 kNumCommandEntries); | 43 Buffer ring_buffer = command_buffer_->GetRingBuffer(); |
| 46 | 44 |
| 47 | 45 parser_ = new CommandParser(ring_buffer.ptr, |
| 48 parser_ = new gpu::CommandParser(ring_buffer->memory(), | 46 ring_buffer.size, |
| 49 kCommandBufferSizeBytes, | 47 0, |
| 50 0, | 48 ring_buffer.size, |
| 51 kCommandBufferSizeBytes, | 49 0, |
| 52 0, | 50 api_mock_.get()); |
| 53 api_mock_.get()); | |
| 54 | 51 |
| 55 scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( | 52 scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( |
| 56 command_buffer_.get(), NULL, parser_, 1)); | 53 command_buffer_.get(), NULL, parser_, 1)); |
| 57 command_buffer_->SetPutOffsetChangeCallback(NewCallback( | 54 command_buffer_->SetPutOffsetChangeCallback(NewCallback( |
| 58 gpu_processor.get(), &GPUProcessor::ProcessCommands)); | 55 gpu_processor.get(), &GPUProcessor::ProcessCommands)); |
| 59 | 56 |
| 60 api_mock_->set_engine(gpu_processor.get()); | 57 api_mock_->set_engine(gpu_processor.get()); |
| 61 | 58 |
| 62 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 59 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
| 63 helper_->Initialize(); | 60 helper_->Initialize(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 101 } |
| 105 } | 102 } |
| 106 } | 103 } |
| 107 | 104 |
| 108 CommandBufferOffset get_helper_put() { return helper_->put_; } | 105 CommandBufferOffset get_helper_put() { return helper_->put_; } |
| 109 | 106 |
| 110 base::AtExitManager at_exit_manager_; | 107 base::AtExitManager at_exit_manager_; |
| 111 MessageLoop message_loop_; | 108 MessageLoop message_loop_; |
| 112 scoped_ptr<AsyncAPIMock> api_mock_; | 109 scoped_ptr<AsyncAPIMock> api_mock_; |
| 113 scoped_ptr<CommandBufferService> command_buffer_; | 110 scoped_ptr<CommandBufferService> command_buffer_; |
| 114 gpu::CommandParser* parser_; | 111 CommandParser* parser_; |
| 115 scoped_ptr<CommandBufferHelper> helper_; | 112 scoped_ptr<CommandBufferHelper> helper_; |
| 116 Sequence sequence_; | 113 Sequence sequence_; |
| 117 }; | 114 }; |
| 118 | 115 |
| 119 // Checks that commands in the buffer are properly executed, and that the | 116 // Checks that commands in the buffer are properly executed, and that the |
| 120 // status/error stay valid. | 117 // status/error stay valid. |
| 121 TEST_F(CommandBufferHelperTest, TestCommandProcessing) { | 118 TEST_F(CommandBufferHelperTest, TestCommandProcessing) { |
| 122 // Check initial state of the engine - it should have been configured by the | 119 // Check initial state of the engine - it should have been configured by the |
| 123 // helper. | 120 // helper. |
| 124 EXPECT_TRUE(parser_ != NULL); | 121 EXPECT_TRUE(parser_ != NULL); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 257 |
| 261 // Check that the commands did happen. | 258 // Check that the commands did happen. |
| 262 Mock::VerifyAndClearExpectations(api_mock_.get()); | 259 Mock::VerifyAndClearExpectations(api_mock_.get()); |
| 263 | 260 |
| 264 // Check the error status. | 261 // Check the error status. |
| 265 EXPECT_FALSE(command_buffer_->GetErrorStatus()); | 262 EXPECT_FALSE(command_buffer_->GetErrorStatus()); |
| 266 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError()); | 263 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError()); |
| 267 } | 264 } |
| 268 | 265 |
| 269 } // namespace gpu | 266 } // namespace gpu |
| OLD | NEW |