| 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 // This file contains the tests for the FencedAllocator class. | 5 // This file contains the tests for the FencedAllocator class. |
| 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/client/fenced_allocator.h" | 10 #include "gpu/command_buffer/client/fenced_allocator.h" |
| 11 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 11 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 12 #include "gpu/command_buffer/service/mocks.h" | 12 #include "gpu/command_buffer/service/mocks.h" |
| 13 #include "gpu/command_buffer/service/command_buffer_service.h" | 13 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 14 #include "gpu/command_buffer/service/gpu_processor.h" | 14 #include "gpu/command_buffer/service/gpu_processor.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace gpu { | 17 namespace gpu { |
| 18 | 18 |
| 19 using gpu::CommandBufferService; | |
| 20 using gpu::GPUProcessor; | |
| 21 using testing::Return; | 19 using testing::Return; |
| 22 using testing::Mock; | 20 using testing::Mock; |
| 23 using testing::Truly; | 21 using testing::Truly; |
| 24 using testing::Sequence; | 22 using testing::Sequence; |
| 25 using testing::DoAll; | 23 using testing::DoAll; |
| 26 using testing::Invoke; | 24 using testing::Invoke; |
| 27 using testing::_; | 25 using testing::_; |
| 28 | 26 |
| 29 class BaseFencedAllocatorTest : public testing::Test { | 27 class BaseFencedAllocatorTest : public testing::Test { |
| 30 protected: | 28 protected: |
| 31 static const unsigned int kBufferSize = 1024; | 29 static const unsigned int kBufferSize = 1024; |
| 32 | 30 |
| 33 virtual void SetUp() { | 31 virtual void SetUp() { |
| 34 api_mock_.reset(new AsyncAPIMock); | 32 api_mock_.reset(new AsyncAPIMock); |
| 35 // ignore noops in the mock - we don't want to inspect the internals of the | 33 // ignore noops in the mock - we don't want to inspect the internals of the |
| 36 // helper. | 34 // helper. |
| 37 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) | 35 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, 0, _)) |
| 38 .WillRepeatedly(Return(parse_error::kParseNoError)); | 36 .WillRepeatedly(Return(parse_error::kParseNoError)); |
| 39 // Forward the SetToken calls to the engine | 37 // Forward the SetToken calls to the engine |
| 40 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) | 38 EXPECT_CALL(*api_mock_.get(), DoCommand(cmd::kSetToken, 1, _)) |
| 41 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), | 39 .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), |
| 42 Return(parse_error::kParseNoError))); | 40 Return(parse_error::kParseNoError))); |
| 43 | 41 |
| 44 command_buffer_.reset(new CommandBufferService); | 42 command_buffer_.reset(new CommandBufferService); |
| 45 base::SharedMemory* ring_buffer = command_buffer_->Initialize( | 43 command_buffer_->Initialize(kBufferSize / sizeof(CommandBufferEntry)); |
| 46 kBufferSize / sizeof(CommandBufferEntry)); | 44 Buffer ring_buffer = command_buffer_->GetRingBuffer(); |
| 47 | 45 |
| 48 parser_ = new gpu::CommandParser(ring_buffer->memory(), | 46 parser_ = new CommandParser(ring_buffer.ptr, |
| 49 kBufferSize, | 47 ring_buffer.size, |
| 50 0, | 48 0, |
| 51 kBufferSize, | 49 ring_buffer.size, |
| 52 0, | 50 0, |
| 53 api_mock_.get()); | 51 api_mock_.get()); |
| 54 | 52 |
| 55 scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( | 53 scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( |
| 56 command_buffer_.get(), NULL, parser_, INT_MAX)); | 54 command_buffer_.get(), NULL, parser_, INT_MAX)); |
| 57 command_buffer_->SetPutOffsetChangeCallback(NewCallback( | 55 command_buffer_->SetPutOffsetChangeCallback(NewCallback( |
| 58 gpu_processor.get(), &GPUProcessor::ProcessCommands)); | 56 gpu_processor.get(), &GPUProcessor::ProcessCommands)); |
| 59 | 57 |
| 60 api_mock_->set_engine(gpu_processor.get()); | 58 api_mock_->set_engine(gpu_processor.get()); |
| 61 | 59 |
| 62 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 60 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
| 63 helper_->Initialize(); | 61 helper_->Initialize(); |
| 64 } | 62 } |
| 65 | 63 |
| 66 virtual void TearDown() { | 64 virtual void TearDown() { |
| 67 helper_.release(); | 65 helper_.release(); |
| 68 } | 66 } |
| 69 | 67 |
| 70 base::AtExitManager at_exit_manager_; | 68 base::AtExitManager at_exit_manager_; |
| 71 MessageLoop message_loop_; | 69 MessageLoop message_loop_; |
| 72 scoped_ptr<AsyncAPIMock> api_mock_; | 70 scoped_ptr<AsyncAPIMock> api_mock_; |
| 73 scoped_ptr<CommandBufferService> command_buffer_; | 71 scoped_ptr<CommandBufferService> command_buffer_; |
| 74 gpu::CommandParser* parser_; | 72 CommandParser* parser_; |
| 75 scoped_ptr<CommandBufferHelper> helper_; | 73 scoped_ptr<CommandBufferHelper> helper_; |
| 76 }; | 74 }; |
| 77 | 75 |
| 78 #ifndef COMPILER_MSVC | 76 #ifndef COMPILER_MSVC |
| 79 const unsigned int BaseFencedAllocatorTest::kBufferSize; | 77 const unsigned int BaseFencedAllocatorTest::kBufferSize; |
| 80 #endif | 78 #endif |
| 81 | 79 |
| 82 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a | 80 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a |
| 83 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling | 81 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling |
| 84 // it directly, not through the RPC mechanism), making sure Noops are ignored | 82 // it directly, not through the RPC mechanism), making sure Noops are ignored |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 EXPECT_LE(token, command_buffer_->GetToken()); | 454 EXPECT_LE(token, command_buffer_->GetToken()); |
| 457 | 455 |
| 458 // Free up everything. | 456 // Free up everything. |
| 459 for (unsigned int i = 0; i < kAllocCount; ++i) { | 457 for (unsigned int i = 0; i < kAllocCount; ++i) { |
| 460 allocator_->Free(pointers[i]); | 458 allocator_->Free(pointers[i]); |
| 461 EXPECT_TRUE(allocator_->CheckConsistency()); | 459 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 462 } | 460 } |
| 463 } | 461 } |
| 464 | 462 |
| 465 } // namespace gpu | 463 } // namespace gpu |
| OLD | NEW |