| 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 // This file contains the tests for the RingBuffer class. | 5 // This file contains the tests for the RingBuffer class. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/ring_buffer.h" | 7 #include "gpu/command_buffer/client/ring_buffer.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 using testing::Sequence; | 23 using testing::Sequence; |
| 24 using testing::DoAll; | 24 using testing::DoAll; |
| 25 using testing::Invoke; | 25 using testing::Invoke; |
| 26 using testing::_; | 26 using testing::_; |
| 27 | 27 |
| 28 class BaseRingBufferTest : public testing::Test { | 28 class BaseRingBufferTest : public testing::Test { |
| 29 protected: | 29 protected: |
| 30 static const unsigned int kBaseOffset = 128; | 30 static const unsigned int kBaseOffset = 128; |
| 31 static const unsigned int kBufferSize = 1024; | 31 static const unsigned int kBufferSize = 1024; |
| 32 | 32 |
| 33 class DoJumpCommand { |
| 34 public: |
| 35 explicit DoJumpCommand(CommandParser* parser) |
| 36 : parser_(parser) { |
| 37 } |
| 38 |
| 39 error::Error DoCommand( |
| 40 unsigned int command, |
| 41 unsigned int arg_count, |
| 42 const void* cmd_data) { |
| 43 const cmd::Jump* jump_cmd = static_cast<const cmd::Jump*>(cmd_data); |
| 44 parser_->set_get(jump_cmd->offset); |
| 45 return error::kNoError; |
| 46 }; |
| 47 |
| 48 private: |
| 49 CommandParser* parser_; |
| 50 }; |
| 51 |
| 33 virtual void SetUp() { | 52 virtual void SetUp() { |
| 34 api_mock_.reset(new AsyncAPIMock); | 53 api_mock_.reset(new AsyncAPIMock); |
| 35 // ignore noops in the mock - we don't want to inspect the internals of the | 54 // ignore noops in the mock - we don't want to inspect the internals of the |
| 36 // helper. | 55 // helper. |
| 37 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) | 56 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) |
| 38 .WillRepeatedly(Return(error::kNoError)); | 57 .WillRepeatedly(Return(error::kNoError)); |
| 39 // Forward the SetToken calls to the engine | 58 // Forward the SetToken calls to the engine |
| 40 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) | 59 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) |
| 41 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), | 60 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), |
| 42 Return(error::kNoError))); | 61 Return(error::kNoError))); |
| 43 | 62 |
| 44 command_buffer_.reset(new CommandBufferService); | 63 command_buffer_.reset(new CommandBufferService); |
| 45 command_buffer_->Initialize(kBufferSize); | 64 command_buffer_->Initialize(kBufferSize); |
| 46 Buffer ring_buffer = command_buffer_->GetRingBuffer(); | 65 Buffer ring_buffer = command_buffer_->GetRingBuffer(); |
| 47 | 66 |
| 48 parser_ = new CommandParser(ring_buffer.ptr, | 67 parser_ = new CommandParser(ring_buffer.ptr, |
| 49 ring_buffer.size, | 68 ring_buffer.size, |
| 50 0, | 69 0, |
| 51 ring_buffer.size, | 70 ring_buffer.size, |
| 52 0, | 71 0, |
| 53 api_mock_.get()); | 72 api_mock_.get()); |
| 54 | 73 |
| 55 gpu_scheduler_.reset(new GpuScheduler( | 74 gpu_scheduler_.reset(new GpuScheduler( |
| 56 command_buffer_.get(), NULL, parser_, INT_MAX)); | 75 command_buffer_.get(), NULL, parser_, INT_MAX)); |
| 57 command_buffer_->SetPutOffsetChangeCallback(NewCallback( | 76 command_buffer_->SetPutOffsetChangeCallback(NewCallback( |
| 58 gpu_scheduler_.get(), &GpuScheduler::PutChanged)); | 77 gpu_scheduler_.get(), &GpuScheduler::PutChanged)); |
| 59 | 78 |
| 60 api_mock_->set_engine(gpu_scheduler_.get()); | 79 api_mock_->set_engine(gpu_scheduler_.get()); |
| 80 do_jump_command_.reset(new DoJumpCommand(parser_)); |
| 81 EXPECT_CALL(*api_mock_, DoCommand(cmd::kJump, _, _)) |
| 82 .WillRepeatedly( |
| 83 Invoke(do_jump_command_.get(), &DoJumpCommand::DoCommand)); |
| 61 | 84 |
| 62 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 85 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
| 63 helper_->Initialize(kBufferSize); | 86 helper_->Initialize(kBufferSize); |
| 64 } | 87 } |
| 65 | 88 |
| 66 int32 GetToken() { | 89 int32 GetToken() { |
| 67 return command_buffer_->GetState().token; | 90 return command_buffer_->GetState().token; |
| 68 } | 91 } |
| 69 | 92 |
| 70 base::mac::ScopedNSAutoreleasePool autorelease_pool_; | 93 base::mac::ScopedNSAutoreleasePool autorelease_pool_; |
| 71 MessageLoop message_loop_; | 94 MessageLoop message_loop_; |
| 72 scoped_ptr<AsyncAPIMock> api_mock_; | 95 scoped_ptr<AsyncAPIMock> api_mock_; |
| 73 scoped_ptr<CommandBufferService> command_buffer_; | 96 scoped_ptr<CommandBufferService> command_buffer_; |
| 74 scoped_ptr<GpuScheduler> gpu_scheduler_; | 97 scoped_ptr<GpuScheduler> gpu_scheduler_; |
| 75 CommandParser* parser_; | 98 CommandParser* parser_; |
| 76 scoped_ptr<CommandBufferHelper> helper_; | 99 scoped_ptr<CommandBufferHelper> helper_; |
| 100 scoped_ptr<DoJumpCommand> do_jump_command_; |
| 77 }; | 101 }; |
| 78 | 102 |
| 79 #ifndef _MSC_VER | 103 #ifndef _MSC_VER |
| 80 const unsigned int BaseRingBufferTest::kBaseOffset; | 104 const unsigned int BaseRingBufferTest::kBaseOffset; |
| 81 const unsigned int BaseRingBufferTest::kBufferSize; | 105 const unsigned int BaseRingBufferTest::kBufferSize; |
| 82 #endif | 106 #endif |
| 83 | 107 |
| 84 // Test fixture for RingBuffer test - Creates a RingBuffer, using a | 108 // Test fixture for RingBuffer test - Creates a RingBuffer, using a |
| 85 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling | 109 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling |
| 86 // it directly, not through the RPC mechanism), making sure Noops are ignored | 110 // it directly, not through the RPC mechanism), making sure Noops are ignored |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 273 |
| 250 // This allocation will need to reclaim the space freed above, so that should | 274 // This allocation will need to reclaim the space freed above, so that should |
| 251 // process the commands until the token is passed. | 275 // process the commands until the token is passed. |
| 252 void* pointer1 = allocator_->Alloc(kSize); | 276 void* pointer1 = allocator_->Alloc(kSize); |
| 253 EXPECT_EQ(buffer_start_, static_cast<int8*>(pointer1)); | 277 EXPECT_EQ(buffer_start_, static_cast<int8*>(pointer1)); |
| 254 | 278 |
| 255 // Check that the token has indeed passed. | 279 // Check that the token has indeed passed. |
| 256 EXPECT_LE(tokens[0], GetToken()); | 280 EXPECT_LE(tokens[0], GetToken()); |
| 257 | 281 |
| 258 allocator_->FreePendingToken(pointer1, helper_->InsertToken()); | 282 allocator_->FreePendingToken(pointer1, helper_->InsertToken()); |
| 283 EXPECT_LE(command_buffer_->GetState().token, helper_->InsertToken()); |
| 259 } | 284 } |
| 260 | 285 |
| 261 } // namespace gpu | 286 } // namespace gpu |
| OLD | NEW |