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 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 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
| 11 #include <memory> |
| 12 |
11 #include "base/bind.h" | 13 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
13 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 15 #include "gpu/command_buffer/client/cmd_buffer_helper.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" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 | 22 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); | 86 &CommandExecutor::SetGetBuffer, base::Unretained(executor_.get()))); |
85 | 87 |
86 api_mock_->set_engine(executor_.get()); | 88 api_mock_->set_engine(executor_.get()); |
87 | 89 |
88 helper_.reset(new CommandBufferHelper(command_buffer_.get())); | 90 helper_.reset(new CommandBufferHelper(command_buffer_.get())); |
89 helper_->Initialize(kBufferSize); | 91 helper_->Initialize(kBufferSize); |
90 } | 92 } |
91 | 93 |
92 int32_t GetToken() { return command_buffer_->GetLastState().token; } | 94 int32_t GetToken() { return command_buffer_->GetLastState().token; } |
93 | 95 |
94 scoped_ptr<AsyncAPIMock> api_mock_; | 96 std::unique_ptr<AsyncAPIMock> api_mock_; |
95 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 97 scoped_refptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
96 scoped_ptr<CommandBufferService> command_buffer_; | 98 std::unique_ptr<CommandBufferService> command_buffer_; |
97 scoped_ptr<CommandExecutor> executor_; | 99 std::unique_ptr<CommandExecutor> executor_; |
98 scoped_ptr<CommandBufferHelper> helper_; | 100 std::unique_ptr<CommandBufferHelper> helper_; |
99 std::vector<const void*> set_token_arguments_; | 101 std::vector<const void*> set_token_arguments_; |
100 bool delay_set_token_; | 102 bool delay_set_token_; |
101 | 103 |
102 scoped_ptr<int8_t[]> buffer_; | 104 std::unique_ptr<int8_t[]> buffer_; |
103 int8_t* buffer_start_; | 105 int8_t* buffer_start_; |
104 base::MessageLoop message_loop_; | 106 base::MessageLoop message_loop_; |
105 }; | 107 }; |
106 | 108 |
107 #ifndef _MSC_VER | 109 #ifndef _MSC_VER |
108 const unsigned int BaseRingBufferTest::kBaseOffset; | 110 const unsigned int BaseRingBufferTest::kBaseOffset; |
109 const unsigned int BaseRingBufferTest::kBufferSize; | 111 const unsigned int BaseRingBufferTest::kBufferSize; |
110 #endif | 112 #endif |
111 | 113 |
112 // Test fixture for RingBuffer test - Creates a RingBuffer, using a | 114 // Test fixture for RingBuffer test - Creates a RingBuffer, using a |
(...skipping 11 matching lines...) Expand all Loading... |
124 helper_.get(), buffer_start_)); | 126 helper_.get(), buffer_start_)); |
125 } | 127 } |
126 | 128 |
127 void TearDown() override { | 129 void TearDown() override { |
128 // If the CommandExecutor posts any tasks, this forces them to run. | 130 // If the CommandExecutor posts any tasks, this forces them to run. |
129 base::MessageLoop::current()->RunUntilIdle(); | 131 base::MessageLoop::current()->RunUntilIdle(); |
130 | 132 |
131 BaseRingBufferTest::TearDown(); | 133 BaseRingBufferTest::TearDown(); |
132 } | 134 } |
133 | 135 |
134 scoped_ptr<RingBuffer> allocator_; | 136 std::unique_ptr<RingBuffer> allocator_; |
135 }; | 137 }; |
136 | 138 |
137 // Checks basic alloc and free. | 139 // Checks basic alloc and free. |
138 TEST_F(RingBufferTest, TestBasic) { | 140 TEST_F(RingBufferTest, TestBasic) { |
139 const unsigned int kSize = 16; | 141 const unsigned int kSize = 16; |
140 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); | 142 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); |
141 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSizeNoWaiting()); | 143 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSizeNoWaiting()); |
142 void* pointer = allocator_->Alloc(kSize); | 144 void* pointer = allocator_->Alloc(kSize); |
143 EXPECT_GE(kBufferSize, allocator_->GetOffset(pointer) - kBaseOffset + kSize); | 145 EXPECT_GE(kBufferSize, allocator_->GetOffset(pointer) - kBaseOffset + kSize); |
144 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); | 146 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeOrPendingSize()); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // Discarding the middle allocation should turn it into padding. | 426 // Discarding the middle allocation should turn it into padding. |
425 allocator_->DiscardBlock(ptr2); | 427 allocator_->DiscardBlock(ptr2); |
426 EXPECT_EQ(0u, allocator_->GetLargestFreeSizeNoWaiting()); | 428 EXPECT_EQ(0u, allocator_->GetLargestFreeSizeNoWaiting()); |
427 | 429 |
428 // Discarding the first allocation should discard the middle padding as well. | 430 // Discarding the first allocation should discard the middle padding as well. |
429 allocator_->DiscardBlock(ptr1); | 431 allocator_->DiscardBlock(ptr1); |
430 EXPECT_EQ(kAlloc1 + kAlloc2, allocator_->GetLargestFreeSizeNoWaiting()); | 432 EXPECT_EQ(kAlloc1 + kAlloc2, allocator_->GetLargestFreeSizeNoWaiting()); |
431 } | 433 } |
432 | 434 |
433 } // namespace gpu | 435 } // namespace gpu |
OLD | NEW |