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

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

Issue 11613021: Removing the JumpRelative, Call, CallRelative and Return commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use Noops instead of Jump; Remove Jump command. Created 7 years, 11 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 | Annotate | Revision Log
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 // Tests for the Command Buffer Helper. 5 // Tests for the Command Buffer Helper.
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 10 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
(...skipping 10 matching lines...) Expand all
21 namespace gpu { 21 namespace gpu {
22 22
23 using testing::Return; 23 using testing::Return;
24 using testing::Mock; 24 using testing::Mock;
25 using testing::Truly; 25 using testing::Truly;
26 using testing::Sequence; 26 using testing::Sequence;
27 using testing::DoAll; 27 using testing::DoAll;
28 using testing::Invoke; 28 using testing::Invoke;
29 using testing::_; 29 using testing::_;
30 30
31 const int32 kTotalNumCommandEntries = 12; 31 const int32 kTotalNumCommandEntries = 10;
32 const int32 kUsableNumCommandEntries = 10;
33 const int32 kCommandBufferSizeBytes = 32 const int32 kCommandBufferSizeBytes =
34 kTotalNumCommandEntries * sizeof(CommandBufferEntry); 33 kTotalNumCommandEntries * sizeof(CommandBufferEntry);
35 const int32 kUnusedCommandId = 5; // we use 0 and 2 currently. 34 const int32 kUnusedCommandId = 5; // we use 0 and 2 currently.
36 35
37 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, 36 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper,
38 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface 37 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface
39 // (calling it directly, not through the RPC mechanism). 38 // (calling it directly, not through the RPC mechanism).
40 class CommandBufferHelperTest : public testing::Test { 39 class CommandBufferHelperTest : public testing::Test {
41 protected: 40 protected:
42 // Helper so mock can handle the Jump command.
43 class DoJumpCommand {
44 public:
45 explicit DoJumpCommand(GpuScheduler* gpu_scheduler)
46 : gpu_scheduler_(gpu_scheduler) {
47 }
48
49 error::Error DoCommand(
50 unsigned int command,
51 unsigned int arg_count,
52 const void* cmd_data) {
53 const cmd::Jump* jump_cmd = static_cast<const cmd::Jump*>(cmd_data);
54 gpu_scheduler_->parser()->set_get(jump_cmd->offset);
55 return error::kNoError;
56 };
57
58 private:
59 GpuScheduler* gpu_scheduler_;
60 };
61
62 virtual void SetUp() { 41 virtual void SetUp() {
63 api_mock_.reset(new AsyncAPIMock); 42 api_mock_.reset(new AsyncAPIMock);
64 // ignore noops in the mock - we don't want to inspect the internals of the 43 // ignore noops in the mock - we don't want to inspect the internals of the
65 // helper. 44 // helper.
66 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, _, _)) 45 EXPECT_CALL(*api_mock_, DoCommand(cmd::kNoop, _, _))
67 .WillRepeatedly(Return(error::kNoError)); 46 .WillRepeatedly(Return(error::kNoError));
68 47
69 { 48 {
70 TransferBufferManager* manager = new TransferBufferManager(); 49 TransferBufferManager* manager = new TransferBufferManager();
71 transfer_buffer_manager_.reset(manager); 50 transfer_buffer_manager_.reset(manager);
72 EXPECT_TRUE(manager->Initialize()); 51 EXPECT_TRUE(manager->Initialize());
73 } 52 }
74 command_buffer_.reset( 53 command_buffer_.reset(
75 new CommandBufferService(transfer_buffer_manager_.get())); 54 new CommandBufferService(transfer_buffer_manager_.get()));
76 EXPECT_TRUE(command_buffer_->Initialize()); 55 EXPECT_TRUE(command_buffer_->Initialize());
77 56
78 gpu_scheduler_.reset(new GpuScheduler( 57 gpu_scheduler_.reset(new GpuScheduler(
79 command_buffer_.get(), api_mock_.get(), NULL)); 58 command_buffer_.get(), api_mock_.get(), NULL));
80 command_buffer_->SetPutOffsetChangeCallback(base::Bind( 59 command_buffer_->SetPutOffsetChangeCallback(base::Bind(
81 &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get()))); 60 &GpuScheduler::PutChanged, base::Unretained(gpu_scheduler_.get())));
82 command_buffer_->SetGetBufferChangeCallback(base::Bind( 61 command_buffer_->SetGetBufferChangeCallback(base::Bind(
83 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); 62 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get())));
84 63
85 do_jump_command_.reset(new DoJumpCommand(gpu_scheduler_.get()));
86 EXPECT_CALL(*api_mock_, DoCommand(cmd::kJump, _, _))
87 .WillRepeatedly(
88 Invoke(do_jump_command_.get(), &DoJumpCommand::DoCommand));
89
90
91 api_mock_->set_engine(gpu_scheduler_.get()); 64 api_mock_->set_engine(gpu_scheduler_.get());
92 65
93 helper_.reset(new CommandBufferHelper(command_buffer_.get())); 66 helper_.reset(new CommandBufferHelper(command_buffer_.get()));
94 helper_->Initialize(kCommandBufferSizeBytes); 67 helper_->Initialize(kCommandBufferSizeBytes);
95 } 68 }
96 69
97 virtual void TearDown() { 70 virtual void TearDown() {
98 // If the GpuScheduler posts any tasks, this forces them to run. 71 // If the GpuScheduler posts any tasks, this forces them to run.
99 MessageLoop::current()->RunUntilIdle(); 72 MessageLoop::current()->RunUntilIdle();
100 } 73 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 #if defined(OS_MACOSX) 138 #if defined(OS_MACOSX)
166 base::mac::ScopedNSAutoreleasePool autorelease_pool_; 139 base::mac::ScopedNSAutoreleasePool autorelease_pool_;
167 #endif 140 #endif
168 MessageLoop message_loop_; 141 MessageLoop message_loop_;
169 scoped_ptr<AsyncAPIMock> api_mock_; 142 scoped_ptr<AsyncAPIMock> api_mock_;
170 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; 143 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
171 scoped_ptr<CommandBufferService> command_buffer_; 144 scoped_ptr<CommandBufferService> command_buffer_;
172 scoped_ptr<GpuScheduler> gpu_scheduler_; 145 scoped_ptr<GpuScheduler> gpu_scheduler_;
173 scoped_ptr<CommandBufferHelper> helper_; 146 scoped_ptr<CommandBufferHelper> helper_;
174 Sequence sequence_; 147 Sequence sequence_;
175 scoped_ptr<DoJumpCommand> do_jump_command_;
176 }; 148 };
177 149
178 // Checks that commands in the buffer are properly executed, and that the 150 // Checks that commands in the buffer are properly executed, and that the
179 // status/error stay valid. 151 // status/error stay valid.
180 TEST_F(CommandBufferHelperTest, TestCommandProcessing) { 152 TEST_F(CommandBufferHelperTest, TestCommandProcessing) {
181 // Check initial state of the engine - it should have been configured by the 153 // Check initial state of the engine - it should have been configured by the
182 // helper. 154 // helper.
183 EXPECT_TRUE(GetParser() != NULL); 155 EXPECT_TRUE(GetParser() != NULL);
184 EXPECT_EQ(error::kNoError, GetError()); 156 EXPECT_EQ(error::kNoError, GetError());
185 EXPECT_EQ(0, GetGetOffset()); 157 EXPECT_EQ(0, GetGetOffset());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 199
228 // Check the error status. 200 // Check the error status.
229 EXPECT_EQ(error::kNoError, GetError()); 201 EXPECT_EQ(error::kNoError, GetError());
230 } 202 }
231 203
232 // Checks the case where the command inserted exactly matches the space left in 204 // Checks the case where the command inserted exactly matches the space left in
233 // the command buffer. 205 // the command buffer.
234 TEST_F(CommandBufferHelperTest, TestCommandWrappingExactMultiple) { 206 TEST_F(CommandBufferHelperTest, TestCommandWrappingExactMultiple) {
235 const int32 kCommandSize = 5; 207 const int32 kCommandSize = 5;
236 const size_t kNumArgs = kCommandSize - 1; 208 const size_t kNumArgs = kCommandSize - 1;
237 COMPILE_ASSERT(kUsableNumCommandEntries % kCommandSize == 0, 209 COMPILE_ASSERT(kTotalNumCommandEntries % kCommandSize == 0,
238 Not_multiple_of_num_command_entries); 210 Not_multiple_of_num_command_entries);
239 CommandBufferEntry args1[kNumArgs]; 211 CommandBufferEntry args1[kNumArgs];
240 for (size_t ii = 0; ii < kNumArgs; ++ii) { 212 for (size_t ii = 0; ii < kNumArgs; ++ii) {
241 args1[0].value_uint32 = ii + 1; 213 args1[0].value_uint32 = ii + 1;
242 } 214 }
243 215
244 for (unsigned int i = 0; i < 5; ++i) { 216 for (unsigned int i = 0; i < 5; ++i) {
245 AddCommandWithExpect( 217 AddCommandWithExpect(
246 error::kNoError, i + kUnusedCommandId, kNumArgs, args1); 218 error::kNoError, i + kUnusedCommandId, kNumArgs, args1);
247 } 219 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 324 }
353 } 325 }
354 326
355 TEST_F(CommandBufferHelperTest, IsContextLost) { 327 TEST_F(CommandBufferHelperTest, IsContextLost) {
356 EXPECT_FALSE(helper_->IsContextLost()); 328 EXPECT_FALSE(helper_->IsContextLost());
357 command_buffer_->SetParseError(error::kGenericError); 329 command_buffer_->SetParseError(error::kGenericError);
358 EXPECT_TRUE(helper_->IsContextLost()); 330 EXPECT_TRUE(helper_->IsContextLost());
359 } 331 }
360 332
361 } // namespace gpu 333 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/cmd_buffer_helper.cc ('k') | gpu/command_buffer/client/ring_buffer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698