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