Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: gpu/command_buffer/client/ring_buffer_test.cc

Issue 1542513002: Switch to standard integer types in gpu/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/command_buffer/client/ring_buffer.cc ('k') | gpu/command_buffer/client/share_group.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
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 "gpu/command_buffer/client/cmd_buffer_helper.h" 13 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
12 #include "gpu/command_buffer/service/cmd_buffer_engine.h" 14 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
13 #include "gpu/command_buffer/service/command_buffer_service.h" 15 #include "gpu/command_buffer/service/command_buffer_service.h"
14 #include "gpu/command_buffer/service/gpu_scheduler.h" 16 #include "gpu/command_buffer/service/gpu_scheduler.h"
15 #include "gpu/command_buffer/service/mocks.h" 17 #include "gpu/command_buffer/service/mocks.h"
16 #include "gpu/command_buffer/service/transfer_buffer_manager.h" 18 #include "gpu/command_buffer/service/transfer_buffer_manager.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 20
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get()))); 82 &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get())));
81 command_buffer_->SetGetBufferChangeCallback(base::Bind( 83 command_buffer_->SetGetBufferChangeCallback(base::Bind(
82 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); 84 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get())));
83 85
84 api_mock_->set_engine(gpu_scheduler_.get()); 86 api_mock_->set_engine(gpu_scheduler_.get());
85 87
86 helper_.reset(new CommandBufferHelper(command_buffer_.get())); 88 helper_.reset(new CommandBufferHelper(command_buffer_.get()));
87 helper_->Initialize(kBufferSize); 89 helper_->Initialize(kBufferSize);
88 } 90 }
89 91
90 int32 GetToken() { 92 int32_t GetToken() { return command_buffer_->GetLastState().token; }
91 return command_buffer_->GetLastState().token;
92 }
93 93
94 scoped_ptr<AsyncAPIMock> api_mock_; 94 scoped_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 scoped_ptr<CommandBufferService> command_buffer_;
97 scoped_ptr<GpuScheduler> gpu_scheduler_; 97 scoped_ptr<GpuScheduler> gpu_scheduler_;
98 scoped_ptr<CommandBufferHelper> helper_; 98 scoped_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[]> buffer_; 102 scoped_ptr<int8_t[]> buffer_;
103 int8* 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
113 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling 113 // CommandBufferHelper with a mock AsyncAPIInterface for its interface (calling
114 // it directly, not through the RPC mechanism), making sure Noops are ignored 114 // it directly, not through the RPC mechanism), making sure Noops are ignored
115 // and SetToken are properly forwarded to the engine. 115 // and SetToken are properly forwarded to the engine.
116 class RingBufferTest : public BaseRingBufferTest { 116 class RingBufferTest : public BaseRingBufferTest {
117 protected: 117 protected:
118 void SetUp() override { 118 void SetUp() override {
119 BaseRingBufferTest::SetUp(); 119 BaseRingBufferTest::SetUp();
120 120
121 buffer_.reset(new int8[kBufferSize + kBaseOffset]); 121 buffer_.reset(new int8_t[kBufferSize + kBaseOffset]);
122 buffer_start_ = buffer_.get() + kBaseOffset; 122 buffer_start_ = buffer_.get() + kBaseOffset;
123 allocator_.reset(new RingBuffer(kAlignment, kBaseOffset, kBufferSize, 123 allocator_.reset(new RingBuffer(kAlignment, kBaseOffset, kBufferSize,
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 GpuScheduler posts any tasks, this forces them to run. 128 // If the GpuScheduler 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 scoped_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());
145 EXPECT_EQ(kBufferSize - kSize, allocator_->GetLargestFreeSizeNoWaiting()); 145 EXPECT_EQ(kBufferSize - kSize, allocator_->GetLargestFreeSizeNoWaiting());
146 int32 token = helper_->InsertToken(); 146 int32_t token = helper_->InsertToken();
147 allocator_->FreePendingToken(pointer, token); 147 allocator_->FreePendingToken(pointer, token);
148 } 148 }
149 149
150 // Checks the free-pending-token mechanism. 150 // Checks the free-pending-token mechanism.
151 TEST_F(RingBufferTest, TestFreePendingToken) { 151 TEST_F(RingBufferTest, TestFreePendingToken) {
152 const unsigned int kSize = 16; 152 const unsigned int kSize = 16;
153 const unsigned int kAllocCount = kBufferSize / kSize; 153 const unsigned int kAllocCount = kBufferSize / kSize;
154 CHECK(kAllocCount * kSize == kBufferSize); 154 CHECK(kAllocCount * kSize == kBufferSize);
155 155
156 delay_set_token_ = true; 156 delay_set_token_ = true;
157 // Allocate several buffers to fill in the memory. 157 // Allocate several buffers to fill in the memory.
158 int32 tokens[kAllocCount]; 158 int32_t tokens[kAllocCount];
159 for (unsigned int ii = 0; ii < kAllocCount; ++ii) { 159 for (unsigned int ii = 0; ii < kAllocCount; ++ii) {
160 void* pointer = allocator_->Alloc(kSize); 160 void* pointer = allocator_->Alloc(kSize);
161 EXPECT_GE(kBufferSize, 161 EXPECT_GE(kBufferSize,
162 allocator_->GetOffset(pointer) - kBaseOffset + kSize); 162 allocator_->GetOffset(pointer) - kBaseOffset + kSize);
163 tokens[ii] = helper_->InsertToken(); 163 tokens[ii] = helper_->InsertToken();
164 allocator_->FreePendingToken(pointer, tokens[ii]); 164 allocator_->FreePendingToken(pointer, tokens[ii]);
165 } 165 }
166 166
167 EXPECT_EQ(kBufferSize - (kSize * kAllocCount), 167 EXPECT_EQ(kBufferSize - (kSize * kAllocCount),
168 allocator_->GetLargestFreeSizeNoWaiting()); 168 allocator_->GetLargestFreeSizeNoWaiting());
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/ring_buffer.cc ('k') | gpu/command_buffer/client/share_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698