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