| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 154 |
| 155 // Tests GetLargestFreeSizeNoWaiting | 155 // Tests GetLargestFreeSizeNoWaiting |
| 156 TEST_F(RingBufferTest, TestGetLargestFreeSizeNoWaiting) { | 156 TEST_F(RingBufferTest, TestGetLargestFreeSizeNoWaiting) { |
| 157 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSizeNoWaiting()); | 157 EXPECT_EQ(kBufferSize, allocator_->GetLargestFreeSizeNoWaiting()); |
| 158 | 158 |
| 159 RingBuffer::Offset offset = allocator_->Alloc(kBufferSize); | 159 RingBuffer::Offset offset = allocator_->Alloc(kBufferSize); |
| 160 EXPECT_EQ(0u, allocator_->GetLargestFreeSizeNoWaiting()); | 160 EXPECT_EQ(0u, allocator_->GetLargestFreeSizeNoWaiting()); |
| 161 allocator_->FreePendingToken(offset, helper_.get()->InsertToken()); | 161 allocator_->FreePendingToken(offset, helper_.get()->InsertToken()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 TEST_F(RingBufferTest, TestFreeBug) { |
| 165 // The first and second allocations must not match. |
| 166 const unsigned int kAlloc1 = 10; |
| 167 const unsigned int kAlloc2 = 20; |
| 168 RingBuffer::Offset offset = allocator_->Alloc(kAlloc1); |
| 169 EXPECT_EQ(kBufferSize - kAlloc1, allocator_->GetLargestFreeSizeNoWaiting()); |
| 170 allocator_->FreePendingToken(offset, helper_.get()->InsertToken()); |
| 171 offset = allocator_->Alloc(kAlloc2); |
| 172 EXPECT_EQ(kBufferSize - kAlloc1 - kAlloc2, |
| 173 allocator_->GetLargestFreeSizeNoWaiting()); |
| 174 allocator_->FreePendingToken(offset, helper_.get()->InsertToken()); |
| 175 offset = allocator_->Alloc(kBufferSize); |
| 176 EXPECT_EQ(0u, allocator_->GetLargestFreeSizeNoWaiting()); |
| 177 allocator_->FreePendingToken(offset, helper_.get()->InsertToken()); |
| 178 } |
| 179 |
| 164 // Test fixture for RingBufferWrapper test - Creates a | 180 // Test fixture for RingBufferWrapper test - Creates a |
| 165 // RingBufferWrapper, using a CommandBufferHelper with a mock | 181 // RingBufferWrapper, using a CommandBufferHelper with a mock |
| 166 // AsyncAPIInterface for its interface (calling it directly, not through the | 182 // AsyncAPIInterface for its interface (calling it directly, not through the |
| 167 // RPC mechanism), making sure Noops are ignored and SetToken are properly | 183 // RPC mechanism), making sure Noops are ignored and SetToken are properly |
| 168 // forwarded to the engine. | 184 // forwarded to the engine. |
| 169 class RingBufferWrapperTest : public BaseRingBufferTest { | 185 class RingBufferWrapperTest : public BaseRingBufferTest { |
| 170 protected: | 186 protected: |
| 171 virtual void SetUp() { | 187 virtual void SetUp() { |
| 172 BaseRingBufferTest::SetUp(); | 188 BaseRingBufferTest::SetUp(); |
| 173 | 189 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 void* pointer1 = allocator_->Alloc(kSize); | 263 void* pointer1 = allocator_->Alloc(kSize); |
| 248 EXPECT_EQ(buffer_start_, static_cast<int8*>(pointer1)); | 264 EXPECT_EQ(buffer_start_, static_cast<int8*>(pointer1)); |
| 249 | 265 |
| 250 // Check that the token has indeed passed. | 266 // Check that the token has indeed passed. |
| 251 EXPECT_LE(tokens[0], GetToken()); | 267 EXPECT_LE(tokens[0], GetToken()); |
| 252 | 268 |
| 253 allocator_->FreePendingToken(pointer1, helper_.get()->InsertToken()); | 269 allocator_->FreePendingToken(pointer1, helper_.get()->InsertToken()); |
| 254 } | 270 } |
| 255 | 271 |
| 256 } // namespace gpu | 272 } // namespace gpu |
| OLD | NEW |