| 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 // Tests for the Command Buffer Helper. | 5 // Tests for the Command Buffer Helper. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/transfer_buffer.h" | 7 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 8 | 8 |
| 9 #include <stddef.h> |
| 10 #include <stdint.h> |
| 11 |
| 9 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 10 #include "gpu/command_buffer/client/client_test_helper.h" | 13 #include "gpu/command_buffer/client/client_test_helper.h" |
| 11 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 14 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 12 #include "gpu/command_buffer/common/command_buffer.h" | 15 #include "gpu/command_buffer/common/command_buffer.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | |
| 15 | 18 |
| 16 using ::testing::_; | 19 using ::testing::_; |
| 17 using ::testing::AtMost; | 20 using ::testing::AtMost; |
| 18 using ::testing::Invoke; | 21 using ::testing::Invoke; |
| 19 using ::testing::Return; | 22 using ::testing::Return; |
| 20 using ::testing::SetArgPointee; | 23 using ::testing::SetArgPointee; |
| 21 using ::testing::StrictMock; | 24 using ::testing::StrictMock; |
| 22 | 25 |
| 23 namespace gpu { | 26 namespace gpu { |
| 24 | 27 |
| 25 | 28 |
| 26 class TransferBufferTest : public testing::Test { | 29 class TransferBufferTest : public testing::Test { |
| 27 protected: | 30 protected: |
| 28 static const int32 kNumCommandEntries = 400; | 31 static const int32_t kNumCommandEntries = 400; |
| 29 static const int32 kCommandBufferSizeBytes = | 32 static const int32_t kCommandBufferSizeBytes = |
| 30 kNumCommandEntries * sizeof(CommandBufferEntry); | 33 kNumCommandEntries * sizeof(CommandBufferEntry); |
| 31 static const unsigned int kStartingOffset = 64; | 34 static const unsigned int kStartingOffset = 64; |
| 32 static const unsigned int kAlignment = 4; | 35 static const unsigned int kAlignment = 4; |
| 33 static const size_t kTransferBufferSize = 256; | 36 static const size_t kTransferBufferSize = 256; |
| 34 | 37 |
| 35 TransferBufferTest() | 38 TransferBufferTest() |
| 36 : transfer_buffer_id_(0) { | 39 : transfer_buffer_id_(0) { |
| 37 } | 40 } |
| 38 | 41 |
| 39 void SetUp() override; | 42 void SetUp() override; |
| 40 void TearDown() override; | 43 void TearDown() override; |
| 41 | 44 |
| 42 virtual void Initialize(unsigned int size_to_flush) { | 45 virtual void Initialize(unsigned int size_to_flush) { |
| 43 ASSERT_TRUE(transfer_buffer_->Initialize( | 46 ASSERT_TRUE(transfer_buffer_->Initialize( |
| 44 kTransferBufferSize, | 47 kTransferBufferSize, |
| 45 kStartingOffset, | 48 kStartingOffset, |
| 46 kTransferBufferSize, | 49 kTransferBufferSize, |
| 47 kTransferBufferSize, | 50 kTransferBufferSize, |
| 48 kAlignment, | 51 kAlignment, |
| 49 size_to_flush)); | 52 size_to_flush)); |
| 50 } | 53 } |
| 51 | 54 |
| 52 MockClientCommandBufferMockFlush* command_buffer() const { | 55 MockClientCommandBufferMockFlush* command_buffer() const { |
| 53 return command_buffer_.get(); | 56 return command_buffer_.get(); |
| 54 } | 57 } |
| 55 | 58 |
| 56 scoped_ptr<MockClientCommandBufferMockFlush> command_buffer_; | 59 scoped_ptr<MockClientCommandBufferMockFlush> command_buffer_; |
| 57 scoped_ptr<CommandBufferHelper> helper_; | 60 scoped_ptr<CommandBufferHelper> helper_; |
| 58 scoped_ptr<TransferBuffer> transfer_buffer_; | 61 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 59 int32 transfer_buffer_id_; | 62 int32_t transfer_buffer_id_; |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 void TransferBufferTest::SetUp() { | 65 void TransferBufferTest::SetUp() { |
| 63 command_buffer_.reset(new StrictMock<MockClientCommandBufferMockFlush>()); | 66 command_buffer_.reset(new StrictMock<MockClientCommandBufferMockFlush>()); |
| 64 ASSERT_TRUE(command_buffer_->Initialize()); | 67 ASSERT_TRUE(command_buffer_->Initialize()); |
| 65 | 68 |
| 66 helper_.reset(new CommandBufferHelper(command_buffer())); | 69 helper_.reset(new CommandBufferHelper(command_buffer())); |
| 67 ASSERT_TRUE(helper_->Initialize(kCommandBufferSizeBytes)); | 70 ASSERT_TRUE(helper_->Initialize(kCommandBufferSizeBytes)); |
| 68 | 71 |
| 69 transfer_buffer_id_ = command_buffer()->GetNextFreeTransferBufferId(); | 72 transfer_buffer_id_ = command_buffer()->GetNextFreeTransferBufferId(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)) | 84 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)) |
| 82 .Times(1) | 85 .Times(1) |
| 83 .RetiresOnSaturation(); | 86 .RetiresOnSaturation(); |
| 84 EXPECT_CALL(*command_buffer(), OnFlush()).Times(AtMost(1)); | 87 EXPECT_CALL(*command_buffer(), OnFlush()).Times(AtMost(1)); |
| 85 EXPECT_CALL(*command_buffer(), Flush(_)).Times(AtMost(1)); | 88 EXPECT_CALL(*command_buffer(), Flush(_)).Times(AtMost(1)); |
| 86 transfer_buffer_.reset(); | 89 transfer_buffer_.reset(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 // GCC requires these declarations, but MSVC requires they not be present | 92 // GCC requires these declarations, but MSVC requires they not be present |
| 90 #ifndef _MSC_VER | 93 #ifndef _MSC_VER |
| 91 const int32 TransferBufferTest::kNumCommandEntries; | 94 const int32_t TransferBufferTest::kNumCommandEntries; |
| 92 const int32 TransferBufferTest::kCommandBufferSizeBytes; | 95 const int32_t TransferBufferTest::kCommandBufferSizeBytes; |
| 93 const unsigned int TransferBufferTest::kStartingOffset; | 96 const unsigned int TransferBufferTest::kStartingOffset; |
| 94 const unsigned int TransferBufferTest::kAlignment; | 97 const unsigned int TransferBufferTest::kAlignment; |
| 95 const size_t TransferBufferTest::kTransferBufferSize; | 98 const size_t TransferBufferTest::kTransferBufferSize; |
| 96 #endif | 99 #endif |
| 97 | 100 |
| 98 TEST_F(TransferBufferTest, Basic) { | 101 TEST_F(TransferBufferTest, Basic) { |
| 99 Initialize(0); | 102 Initialize(0); |
| 100 EXPECT_TRUE(transfer_buffer_->HaveBuffer()); | 103 EXPECT_TRUE(transfer_buffer_->HaveBuffer()); |
| 101 EXPECT_EQ(transfer_buffer_id_, transfer_buffer_->GetShmId()); | 104 EXPECT_EQ(transfer_buffer_id_, transfer_buffer_->GetShmId()); |
| 102 EXPECT_EQ( | 105 EXPECT_EQ( |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 223 } |
| 221 | 224 |
| 222 class MockClientCommandBufferCanFail : public MockClientCommandBufferMockFlush { | 225 class MockClientCommandBufferCanFail : public MockClientCommandBufferMockFlush { |
| 223 public: | 226 public: |
| 224 MockClientCommandBufferCanFail() { | 227 MockClientCommandBufferCanFail() { |
| 225 } | 228 } |
| 226 virtual ~MockClientCommandBufferCanFail() { | 229 virtual ~MockClientCommandBufferCanFail() { |
| 227 } | 230 } |
| 228 | 231 |
| 229 MOCK_METHOD2(CreateTransferBuffer, | 232 MOCK_METHOD2(CreateTransferBuffer, |
| 230 scoped_refptr<Buffer>(size_t size, int32* id)); | 233 scoped_refptr<Buffer>(size_t size, int32_t* id)); |
| 231 | 234 |
| 232 scoped_refptr<gpu::Buffer> RealCreateTransferBuffer(size_t size, int32* id) { | 235 scoped_refptr<gpu::Buffer> RealCreateTransferBuffer(size_t size, |
| 236 int32_t* id) { |
| 233 return MockCommandBufferBase::CreateTransferBuffer(size, id); | 237 return MockCommandBufferBase::CreateTransferBuffer(size, id); |
| 234 } | 238 } |
| 235 }; | 239 }; |
| 236 | 240 |
| 237 class TransferBufferExpandContractTest : public testing::Test { | 241 class TransferBufferExpandContractTest : public testing::Test { |
| 238 protected: | 242 protected: |
| 239 static const int32 kNumCommandEntries = 400; | 243 static const int32_t kNumCommandEntries = 400; |
| 240 static const int32 kCommandBufferSizeBytes = | 244 static const int32_t kCommandBufferSizeBytes = |
| 241 kNumCommandEntries * sizeof(CommandBufferEntry); | 245 kNumCommandEntries * sizeof(CommandBufferEntry); |
| 242 static const unsigned int kStartingOffset = 64; | 246 static const unsigned int kStartingOffset = 64; |
| 243 static const unsigned int kAlignment = 4; | 247 static const unsigned int kAlignment = 4; |
| 244 static const size_t kStartTransferBufferSize = 256; | 248 static const size_t kStartTransferBufferSize = 256; |
| 245 static const size_t kMaxTransferBufferSize = 1024; | 249 static const size_t kMaxTransferBufferSize = 1024; |
| 246 static const size_t kMinTransferBufferSize = 128; | 250 static const size_t kMinTransferBufferSize = 128; |
| 247 | 251 |
| 248 TransferBufferExpandContractTest() | 252 TransferBufferExpandContractTest() |
| 249 : transfer_buffer_id_(0) { | 253 : transfer_buffer_id_(0) { |
| 250 } | 254 } |
| 251 | 255 |
| 252 void SetUp() override; | 256 void SetUp() override; |
| 253 void TearDown() override; | 257 void TearDown() override; |
| 254 | 258 |
| 255 MockClientCommandBufferCanFail* command_buffer() const { | 259 MockClientCommandBufferCanFail* command_buffer() const { |
| 256 return command_buffer_.get(); | 260 return command_buffer_.get(); |
| 257 } | 261 } |
| 258 | 262 |
| 259 scoped_ptr<MockClientCommandBufferCanFail> command_buffer_; | 263 scoped_ptr<MockClientCommandBufferCanFail> command_buffer_; |
| 260 scoped_ptr<CommandBufferHelper> helper_; | 264 scoped_ptr<CommandBufferHelper> helper_; |
| 261 scoped_ptr<TransferBuffer> transfer_buffer_; | 265 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 262 int32 transfer_buffer_id_; | 266 int32_t transfer_buffer_id_; |
| 263 }; | 267 }; |
| 264 | 268 |
| 265 void TransferBufferExpandContractTest::SetUp() { | 269 void TransferBufferExpandContractTest::SetUp() { |
| 266 command_buffer_.reset(new StrictMock<MockClientCommandBufferCanFail>()); | 270 command_buffer_.reset(new StrictMock<MockClientCommandBufferCanFail>()); |
| 267 ASSERT_TRUE(command_buffer_->Initialize()); | 271 ASSERT_TRUE(command_buffer_->Initialize()); |
| 268 | 272 |
| 269 EXPECT_CALL(*command_buffer(), | 273 EXPECT_CALL(*command_buffer(), |
| 270 CreateTransferBuffer(kCommandBufferSizeBytes, _)) | 274 CreateTransferBuffer(kCommandBufferSizeBytes, _)) |
| 271 .WillOnce(Invoke( | 275 .WillOnce(Invoke( |
| 272 command_buffer(), | 276 command_buffer(), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 303 } | 307 } |
| 304 // For command buffer. | 308 // For command buffer. |
| 305 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)) | 309 EXPECT_CALL(*command_buffer(), DestroyTransferBuffer(_)) |
| 306 .Times(1) | 310 .Times(1) |
| 307 .RetiresOnSaturation(); | 311 .RetiresOnSaturation(); |
| 308 transfer_buffer_.reset(); | 312 transfer_buffer_.reset(); |
| 309 } | 313 } |
| 310 | 314 |
| 311 // GCC requires these declarations, but MSVC requires they not be present | 315 // GCC requires these declarations, but MSVC requires they not be present |
| 312 #ifndef _MSC_VER | 316 #ifndef _MSC_VER |
| 313 const int32 TransferBufferExpandContractTest::kNumCommandEntries; | 317 const int32_t TransferBufferExpandContractTest::kNumCommandEntries; |
| 314 const int32 TransferBufferExpandContractTest::kCommandBufferSizeBytes; | 318 const int32_t TransferBufferExpandContractTest::kCommandBufferSizeBytes; |
| 315 const unsigned int TransferBufferExpandContractTest::kStartingOffset; | 319 const unsigned int TransferBufferExpandContractTest::kStartingOffset; |
| 316 const unsigned int TransferBufferExpandContractTest::kAlignment; | 320 const unsigned int TransferBufferExpandContractTest::kAlignment; |
| 317 const size_t TransferBufferExpandContractTest::kStartTransferBufferSize; | 321 const size_t TransferBufferExpandContractTest::kStartTransferBufferSize; |
| 318 const size_t TransferBufferExpandContractTest::kMaxTransferBufferSize; | 322 const size_t TransferBufferExpandContractTest::kMaxTransferBufferSize; |
| 319 const size_t TransferBufferExpandContractTest::kMinTransferBufferSize; | 323 const size_t TransferBufferExpandContractTest::kMinTransferBufferSize; |
| 320 #endif | 324 #endif |
| 321 | 325 |
| 322 TEST_F(TransferBufferExpandContractTest, Expand) { | 326 TEST_F(TransferBufferExpandContractTest, Expand) { |
| 323 // Check it starts at starting size. | 327 // Check it starts at starting size. |
| 324 EXPECT_EQ( | 328 EXPECT_EQ( |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 481 |
| 478 // Check it's the default size. | 482 // Check it's the default size. |
| 479 EXPECT_EQ( | 483 EXPECT_EQ( |
| 480 kStartTransferBufferSize - kStartingOffset, | 484 kStartTransferBufferSize - kStartingOffset, |
| 481 transfer_buffer_->GetCurrentMaxAllocationWithoutRealloc()); | 485 transfer_buffer_->GetCurrentMaxAllocationWithoutRealloc()); |
| 482 } | 486 } |
| 483 | 487 |
| 484 } // namespace gpu | 488 } // namespace gpu |
| 485 | 489 |
| 486 | 490 |
| OLD | NEW |