Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
|
no sievers
2016/04/05 19:02:40
#include <memory>
| |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/aligned_memory.h" | 11 #include "base/memory/aligned_memory.h" |
| 12 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 12 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 13 #include "gpu/command_buffer/client/fenced_allocator.h" | 13 #include "gpu/command_buffer/client/fenced_allocator.h" |
| 14 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 14 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 15 #include "gpu/command_buffer/service/command_buffer_service.h" | 15 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 16 #include "gpu/command_buffer/service/command_executor.h" | 16 #include "gpu/command_buffer/service/command_executor.h" |
| 17 #include "gpu/command_buffer/service/mocks.h" | 17 #include "gpu/command_buffer/service/mocks.h" |
| 18 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 18 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); | 62 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); |
| 63 | 63 |
| 64 api_mock_->set_engine(executor_.get()); | 64 api_mock_->set_engine(executor_.get()); |
| 65 | 65 |
| 66 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 66 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
| 67 helper_->Initialize(kBufferSize); | 67 helper_->Initialize(kBufferSize); |
| 68 } | 68 } |
| 69 | 69 |
| 70 int32_t GetToken() { return command_buffer_->GetLastState().token; } | 70 int32_t GetToken() { return command_buffer_->GetLastState().token; } |
| 71 | 71 |
| 72 scoped_ptr<AsyncAPIMock> api_mock_; | 72 std::unique_ptr<AsyncAPIMock> api_mock_; |
| 73 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 73 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 74 scoped_ptr<CommandBufferService> command_buffer_; | 74 std::unique_ptr<CommandBufferService> command_buffer_; |
| 75 scoped_ptr<CommandExecutor> executor_; | 75 std::unique_ptr<CommandExecutor> executor_; |
| 76 scoped_ptr<CommandBufferHelper> helper_; | 76 std::unique_ptr<CommandBufferHelper> helper_; |
| 77 base::MessageLoop message_loop_; | 77 base::MessageLoop message_loop_; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 #ifndef _MSC_VER | 80 #ifndef _MSC_VER |
| 81 const unsigned int BaseFencedAllocatorTest::kBufferSize; | 81 const unsigned int BaseFencedAllocatorTest::kBufferSize; |
| 82 #endif | 82 #endif |
| 83 | 83 |
| 84 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a | 84 // Test fixture for FencedAllocator test - Creates a FencedAllocator, using a |
| 85 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling | 85 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling |
| 86 // it directly, not through the RPC mechanism), making sure Noops are ignored | 86 // it directly, not through the RPC mechanism), making sure Noops are ignored |
| 87 // and SetToken are properly forwarded to the engine. | 87 // and SetToken are properly forwarded to the engine. |
| 88 class FencedAllocatorTest : public BaseFencedAllocatorTest { | 88 class FencedAllocatorTest : public BaseFencedAllocatorTest { |
| 89 protected: | 89 protected: |
| 90 void SetUp() override { | 90 void SetUp() override { |
| 91 BaseFencedAllocatorTest::SetUp(); | 91 BaseFencedAllocatorTest::SetUp(); |
| 92 allocator_.reset(new FencedAllocator(kBufferSize, helper_.get())); | 92 allocator_.reset(new FencedAllocator(kBufferSize, helper_.get())); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void TearDown() override { | 95 void TearDown() override { |
| 96 // If the CommandExecutor posts any tasks, this forces them to run. | 96 // If the CommandExecutor posts any tasks, this forces them to run. |
| 97 base::MessageLoop::current()->RunUntilIdle(); | 97 base::MessageLoop::current()->RunUntilIdle(); |
| 98 | 98 |
| 99 EXPECT_TRUE(allocator_->CheckConsistency()); | 99 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 100 | 100 |
| 101 BaseFencedAllocatorTest::TearDown(); | 101 BaseFencedAllocatorTest::TearDown(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 scoped_ptr<FencedAllocator> allocator_; | 104 std::unique_ptr<FencedAllocator> allocator_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 // Checks basic alloc and free. | 107 // Checks basic alloc and free. |
| 108 TEST_F(FencedAllocatorTest, TestBasic) { | 108 TEST_F(FencedAllocatorTest, TestBasic) { |
| 109 allocator_->CheckConsistency(); | 109 allocator_->CheckConsistency(); |
| 110 EXPECT_FALSE(allocator_->InUse()); | 110 EXPECT_FALSE(allocator_->InUse()); |
| 111 | 111 |
| 112 const unsigned int kSize = 16; | 112 const unsigned int kSize = 16; |
| 113 FencedAllocator::Offset offset = allocator_->Alloc(kSize); | 113 FencedAllocator::Offset offset = allocator_->Alloc(kSize); |
| 114 EXPECT_TRUE(allocator_->InUse()); | 114 EXPECT_TRUE(allocator_->InUse()); |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 | 406 |
| 407 void TearDown() override { | 407 void TearDown() override { |
| 408 // If the CommandExecutor posts any tasks, this forces them to run. | 408 // If the CommandExecutor posts any tasks, this forces them to run. |
| 409 base::MessageLoop::current()->RunUntilIdle(); | 409 base::MessageLoop::current()->RunUntilIdle(); |
| 410 | 410 |
| 411 EXPECT_TRUE(allocator_->CheckConsistency()); | 411 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 412 | 412 |
| 413 BaseFencedAllocatorTest::TearDown(); | 413 BaseFencedAllocatorTest::TearDown(); |
| 414 } | 414 } |
| 415 | 415 |
| 416 scoped_ptr<FencedAllocatorWrapper> allocator_; | 416 std::unique_ptr<FencedAllocatorWrapper> allocator_; |
| 417 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; | 417 std::unique_ptr<char, base::AlignedFreeDeleter> buffer_; |
| 418 }; | 418 }; |
| 419 | 419 |
| 420 // Checks basic alloc and free. | 420 // Checks basic alloc and free. |
| 421 TEST_F(FencedAllocatorWrapperTest, TestBasic) { | 421 TEST_F(FencedAllocatorWrapperTest, TestBasic) { |
| 422 allocator_->CheckConsistency(); | 422 allocator_->CheckConsistency(); |
| 423 | 423 |
| 424 const unsigned int kSize = 16; | 424 const unsigned int kSize = 16; |
| 425 void *pointer = allocator_->Alloc(kSize); | 425 void *pointer = allocator_->Alloc(kSize); |
| 426 ASSERT_TRUE(pointer); | 426 ASSERT_TRUE(pointer); |
| 427 EXPECT_LE(buffer_.get(), static_cast<char *>(pointer)); | 427 EXPECT_LE(buffer_.get(), static_cast<char *>(pointer)); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 EXPECT_LE(token, GetToken()); | 563 EXPECT_LE(token, GetToken()); |
| 564 | 564 |
| 565 // Free up everything. | 565 // Free up everything. |
| 566 for (unsigned int i = 0; i < kAllocCount; ++i) { | 566 for (unsigned int i = 0; i < kAllocCount; ++i) { |
| 567 allocator_->Free(pointers[i]); | 567 allocator_->Free(pointers[i]); |
| 568 EXPECT_TRUE(allocator_->CheckConsistency()); | 568 EXPECT_TRUE(allocator_->CheckConsistency()); |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 | 571 |
| 572 } // namespace gpu | 572 } // namespace gpu |
| OLD | NEW |