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

Side by Side Diff: gpu/command_buffer/service/cmd_parser_test.cc

Issue 1859703002: convert //gpu to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: undo part of clang-format Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 parser. 5 // Tests for the command parser.
6 6
7 #include "gpu/command_buffer/service/cmd_parser.h"
no sievers 2016/04/05 19:02:40 nit: This can stay where it was
Mostyn Bramley-Moore 2016/04/05 21:35:31 Done.
8
7 #include <stddef.h> 9 #include <stddef.h>
8 10
11 #include <memory>
12
9 #include "base/logging.h" 13 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "gpu/command_buffer/service/cmd_parser.h"
12 #include "gpu/command_buffer/service/mocks.h" 14 #include "gpu/command_buffer/service/mocks.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace gpu { 17 namespace gpu {
16 18
17 using testing::_; 19 using testing::_;
18 using testing::Invoke; 20 using testing::Invoke;
19 using testing::Mock; 21 using testing::Mock;
20 using testing::Return; 22 using testing::Return;
21 using testing::Sequence; 23 using testing::Sequence;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 56
55 parser->SetBuffer(buffer(), shm_size, 0, command_buffer_size); 57 parser->SetBuffer(buffer(), shm_size, 0, command_buffer_size);
56 return parser; 58 return parser;
57 } 59 }
58 60
59 unsigned int buffer_entry_count() { return 20; } 61 unsigned int buffer_entry_count() { return 20; }
60 AsyncAPIMock *api_mock() { return api_mock_.get(); } 62 AsyncAPIMock *api_mock() { return api_mock_.get(); }
61 CommandBufferEntry *buffer() { return buffer_.get(); } 63 CommandBufferEntry *buffer() { return buffer_.get(); }
62 private: 64 private:
63 unsigned int buffer_entry_count_; 65 unsigned int buffer_entry_count_;
64 scoped_ptr<AsyncAPIMock> api_mock_; 66 std::unique_ptr<AsyncAPIMock> api_mock_;
65 scoped_ptr<CommandBufferEntry[]> buffer_; 67 std::unique_ptr<CommandBufferEntry[]> buffer_;
66 Sequence sequence_; 68 Sequence sequence_;
67 }; 69 };
68 70
69 // Tests initialization conditions. 71 // Tests initialization conditions.
70 TEST_F(CommandParserTest, TestInit) { 72 TEST_F(CommandParserTest, TestInit) {
71 scoped_ptr<CommandParser> parser(MakeParser(10)); 73 std::unique_ptr<CommandParser> parser(MakeParser(10));
72 EXPECT_EQ(0, parser->get()); 74 EXPECT_EQ(0, parser->get());
73 EXPECT_EQ(0, parser->put()); 75 EXPECT_EQ(0, parser->put());
74 EXPECT_TRUE(parser->IsEmpty()); 76 EXPECT_TRUE(parser->IsEmpty());
75 } 77 }
76 78
77 // Tests simple commands. 79 // Tests simple commands.
78 TEST_F(CommandParserTest, TestSimple) { 80 TEST_F(CommandParserTest, TestSimple) {
79 scoped_ptr<CommandParser> parser(MakeParser(10)); 81 std::unique_ptr<CommandParser> parser(MakeParser(10));
80 CommandBufferOffset put = parser->put(); 82 CommandBufferOffset put = parser->put();
81 CommandHeader header; 83 CommandHeader header;
82 84
83 // add a single command, no args 85 // add a single command, no args
84 header.size = 1; 86 header.size = 1;
85 header.command = 123; 87 header.command = 123;
86 buffer()[put++].value_header = header; 88 buffer()[put++].value_header = header;
87 parser->set_put(put); 89 parser->set_put(put);
88 EXPECT_EQ(put, parser->put()); 90 EXPECT_EQ(put, parser->put());
89 91
(...skipping 12 matching lines...) Expand all
102 EXPECT_EQ(put, parser->put()); 104 EXPECT_EQ(put, parser->put());
103 105
104 AddDoCommandsExpect(error::kNoError, 1, 3, 3); 106 AddDoCommandsExpect(error::kNoError, 1, 3, 3);
105 EXPECT_EQ(error::kNoError, parser->ProcessCommands(1)); 107 EXPECT_EQ(error::kNoError, parser->ProcessCommands(1));
106 EXPECT_EQ(put, parser->get()); 108 EXPECT_EQ(put, parser->get());
107 Mock::VerifyAndClearExpectations(api_mock()); 109 Mock::VerifyAndClearExpectations(api_mock());
108 } 110 }
109 111
110 // Tests having multiple commands in the buffer. 112 // Tests having multiple commands in the buffer.
111 TEST_F(CommandParserTest, TestMultipleCommands) { 113 TEST_F(CommandParserTest, TestMultipleCommands) {
112 scoped_ptr<CommandParser> parser(MakeParser(10)); 114 std::unique_ptr<CommandParser> parser(MakeParser(10));
113 CommandBufferOffset put = parser->put(); 115 CommandBufferOffset put = parser->put();
114 CommandHeader header; 116 CommandHeader header;
115 117
116 // add 2 commands, test with single ProcessCommands() 118 // add 2 commands, test with single ProcessCommands()
117 header.size = 2; 119 header.size = 2;
118 header.command = 789; 120 header.command = 789;
119 buffer()[put++].value_header = header; 121 buffer()[put++].value_header = header;
120 buffer()[put++].value_int32 = 5151; 122 buffer()[put++].value_int32 = 5151;
121 123
122 CommandBufferOffset put_cmd2 = put; 124 CommandBufferOffset put_cmd2 = put;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // 4 entries remaining. 156 // 4 entries remaining.
155 AddDoCommandsExpect( 157 AddDoCommandsExpect(
156 error::kNoError, CommandParser::kParseCommandsSlice, 4, 4); 158 error::kNoError, CommandParser::kParseCommandsSlice, 4, 4);
157 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands()); 159 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands());
158 EXPECT_EQ(put, parser->get()); 160 EXPECT_EQ(put, parser->get());
159 Mock::VerifyAndClearExpectations(api_mock()); 161 Mock::VerifyAndClearExpectations(api_mock());
160 } 162 }
161 163
162 // Tests that the parser will wrap correctly at the end of the buffer. 164 // Tests that the parser will wrap correctly at the end of the buffer.
163 TEST_F(CommandParserTest, TestWrap) { 165 TEST_F(CommandParserTest, TestWrap) {
164 scoped_ptr<CommandParser> parser(MakeParser(5)); 166 std::unique_ptr<CommandParser> parser(MakeParser(5));
165 CommandBufferOffset put = parser->put(); 167 CommandBufferOffset put = parser->put();
166 CommandHeader header; 168 CommandHeader header;
167 169
168 // add 3 commands with no args (1 word each) 170 // add 3 commands with no args (1 word each)
169 for (unsigned int i = 0; i < 3; ++i) { 171 for (unsigned int i = 0; i < 3; ++i) {
170 header.size = 1; 172 header.size = 1;
171 header.command = i; 173 header.command = i;
172 buffer()[put++].value_header = header; 174 buffer()[put++].value_header = header;
173 } 175 }
174 parser->set_put(put); 176 parser->set_put(put);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 EXPECT_EQ(put, parser->put()); 208 EXPECT_EQ(put, parser->put());
207 209
208 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands()); 210 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands());
209 EXPECT_EQ(put, parser->get()); 211 EXPECT_EQ(put, parser->get());
210 Mock::VerifyAndClearExpectations(api_mock()); 212 Mock::VerifyAndClearExpectations(api_mock());
211 } 213 }
212 214
213 // Tests error conditions. 215 // Tests error conditions.
214 TEST_F(CommandParserTest, TestError) { 216 TEST_F(CommandParserTest, TestError) {
215 const unsigned int kNumEntries = 5; 217 const unsigned int kNumEntries = 5;
216 scoped_ptr<CommandParser> parser(MakeParser(kNumEntries)); 218 std::unique_ptr<CommandParser> parser(MakeParser(kNumEntries));
217 CommandBufferOffset put = parser->put(); 219 CommandBufferOffset put = parser->put();
218 CommandHeader header; 220 CommandHeader header;
219 221
220 EXPECT_FALSE(parser->set_get(-1)); 222 EXPECT_FALSE(parser->set_get(-1));
221 EXPECT_FALSE(parser->set_get(kNumEntries)); 223 EXPECT_FALSE(parser->set_get(kNumEntries));
222 224
223 // Generate a command with size 0. 225 // Generate a command with size 0.
224 header.size = 0; 226 header.size = 0;
225 header.command = 3; 227 header.command = 3;
226 buffer()[put++].value_header = header; 228 buffer()[put++].value_header = header;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 Mock::VerifyAndClearExpectations(api_mock()); 280 Mock::VerifyAndClearExpectations(api_mock());
279 // make the second one succeed, and check that the parser recovered fine. 281 // make the second one succeed, and check that the parser recovered fine.
280 AddDoCommandsExpect( 282 AddDoCommandsExpect(
281 error::kNoError, CommandParser::kParseCommandsSlice, 1, 1); 283 error::kNoError, CommandParser::kParseCommandsSlice, 1, 1);
282 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands()); 284 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands());
283 EXPECT_EQ(put, parser->get()); 285 EXPECT_EQ(put, parser->get());
284 Mock::VerifyAndClearExpectations(api_mock()); 286 Mock::VerifyAndClearExpectations(api_mock());
285 } 287 }
286 288
287 TEST_F(CommandParserTest, SetBuffer) { 289 TEST_F(CommandParserTest, SetBuffer) {
288 scoped_ptr<CommandParser> parser(MakeParser(3)); 290 std::unique_ptr<CommandParser> parser(MakeParser(3));
289 CommandBufferOffset put = parser->put(); 291 CommandBufferOffset put = parser->put();
290 CommandHeader header; 292 CommandHeader header;
291 293
292 // add a single command, no args 294 // add a single command, no args
293 header.size = 2; 295 header.size = 2;
294 header.command = 123; 296 header.command = 123;
295 buffer()[put++].value_header = header; 297 buffer()[put++].value_header = header;
296 buffer()[put++].value_int32 = 456; 298 buffer()[put++].value_int32 = 456;
297 parser->set_put(put); 299 parser->set_put(put);
298 300
299 AddDoCommandsExpect( 301 AddDoCommandsExpect(
300 error::kNoError, CommandParser::kParseCommandsSlice, 2, 2); 302 error::kNoError, CommandParser::kParseCommandsSlice, 2, 2);
301 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands()); 303 EXPECT_EQ(error::kNoError, parser->ProcessAllCommands());
302 // We should have advanced 2 entries 304 // We should have advanced 2 entries
303 EXPECT_EQ(2, parser->get()); 305 EXPECT_EQ(2, parser->get());
304 Mock::VerifyAndClearExpectations(api_mock()); 306 Mock::VerifyAndClearExpectations(api_mock());
305 307
306 scoped_ptr<CommandBufferEntry[]> buffer2(new CommandBufferEntry[2]); 308 std::unique_ptr<CommandBufferEntry[]> buffer2(new CommandBufferEntry[2]);
307 parser->SetBuffer( 309 parser->SetBuffer(
308 buffer2.get(), sizeof(CommandBufferEntry) * 2, 0, 310 buffer2.get(), sizeof(CommandBufferEntry) * 2, 0,
309 sizeof(CommandBufferEntry) * 2); 311 sizeof(CommandBufferEntry) * 2);
310 // The put and get should have reset to 0. 312 // The put and get should have reset to 0.
311 EXPECT_EQ(0, parser->get()); 313 EXPECT_EQ(0, parser->get());
312 EXPECT_EQ(0, parser->put()); 314 EXPECT_EQ(0, parser->put());
313 } 315 }
314 316
315 } // namespace gpu 317 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698