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 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 9 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 | 1314 |
1315 TEST_P(GLES2DecoderTest, LoseContextCHROMIUMInvalidArgs1_0) { | 1315 TEST_P(GLES2DecoderTest, LoseContextCHROMIUMInvalidArgs1_0) { |
1316 EXPECT_CALL(*mock_decoder_, LoseContext(_)) | 1316 EXPECT_CALL(*mock_decoder_, LoseContext(_)) |
1317 .Times(0); | 1317 .Times(0); |
1318 cmds::LoseContextCHROMIUM cmd; | 1318 cmds::LoseContextCHROMIUM cmd; |
1319 cmd.Init(GL_GUILTY_CONTEXT_RESET_ARB, GL_NONE); | 1319 cmd.Init(GL_GUILTY_CONTEXT_RESET_ARB, GL_NONE); |
1320 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); | 1320 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); |
1321 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); | 1321 EXPECT_EQ(GL_INVALID_ENUM, GetGLError()); |
1322 } | 1322 } |
1323 | 1323 |
| 1324 class GLES2DecoderDoCommandsTest : public GLES2DecoderTest { |
| 1325 public: |
| 1326 GLES2DecoderDoCommandsTest() { |
| 1327 for (int i = 0; i < 3; i++) { |
| 1328 cmds_[i].Init(GL_BLEND); |
| 1329 } |
| 1330 entries_per_cmd_ = ComputeNumEntries(cmds_[0].ComputeSize()); |
| 1331 } |
| 1332 |
| 1333 void SetExpectationsForNCommands(int num_commands) { |
| 1334 for (int i = 0; i < num_commands; i++) |
| 1335 SetupExpectationsForEnableDisable(GL_BLEND, true); |
| 1336 } |
| 1337 |
| 1338 protected: |
| 1339 Enable cmds_[3]; |
| 1340 int entries_per_cmd_; |
| 1341 }; |
| 1342 |
| 1343 // Test that processing with 0 entries does nothing. |
| 1344 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsOneOfZero) { |
| 1345 int num_processed = -1; |
| 1346 SetExpectationsForNCommands(0); |
| 1347 EXPECT_EQ( |
| 1348 error::kNoError, |
| 1349 decoder_->DoCommands(1, &cmds_, entries_per_cmd_ * 0, &num_processed)); |
| 1350 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 1351 EXPECT_EQ(0, num_processed); |
| 1352 } |
| 1353 |
| 1354 // Test processing at granularity of single commands. |
| 1355 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsOneOfOne) { |
| 1356 int num_processed = -1; |
| 1357 SetExpectationsForNCommands(1); |
| 1358 EXPECT_EQ( |
| 1359 error::kNoError, |
| 1360 decoder_->DoCommands(1, &cmds_, entries_per_cmd_ * 1, &num_processed)); |
| 1361 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 1362 EXPECT_EQ(entries_per_cmd_, num_processed); |
| 1363 } |
| 1364 |
| 1365 // Test processing at granularity of multiple commands. |
| 1366 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsThreeOfThree) { |
| 1367 int num_processed = -1; |
| 1368 SetExpectationsForNCommands(3); |
| 1369 EXPECT_EQ( |
| 1370 error::kNoError, |
| 1371 decoder_->DoCommands(3, &cmds_, entries_per_cmd_ * 3, &num_processed)); |
| 1372 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 1373 EXPECT_EQ(entries_per_cmd_ * 3, num_processed); |
| 1374 } |
| 1375 |
| 1376 // Test processing a request smaller than available entries. |
| 1377 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsTwoOfThree) { |
| 1378 int num_processed = -1; |
| 1379 SetExpectationsForNCommands(2); |
| 1380 EXPECT_EQ( |
| 1381 error::kNoError, |
| 1382 decoder_->DoCommands(2, &cmds_, entries_per_cmd_ * 3, &num_processed)); |
| 1383 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 1384 EXPECT_EQ(entries_per_cmd_ * 2, num_processed); |
| 1385 } |
| 1386 |
| 1387 // Test that processing stops on a command with size 0. |
| 1388 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsZeroCmdSize) { |
| 1389 cmds_[1].header.size = 0; |
| 1390 int num_processed = -1; |
| 1391 SetExpectationsForNCommands(1); |
| 1392 EXPECT_EQ( |
| 1393 error::kInvalidSize, |
| 1394 decoder_->DoCommands(2, &cmds_, entries_per_cmd_ * 2, &num_processed)); |
| 1395 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 1396 EXPECT_EQ(entries_per_cmd_, num_processed); |
| 1397 } |
| 1398 |
| 1399 // Test that processing stops on a command with size greater than available. |
| 1400 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsOutOfBounds) { |
| 1401 int num_processed = -1; |
| 1402 SetExpectationsForNCommands(1); |
| 1403 EXPECT_EQ(error::kOutOfBounds, |
| 1404 decoder_->DoCommands( |
| 1405 2, &cmds_, entries_per_cmd_ * 2 - 1, &num_processed)); |
| 1406 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 1407 EXPECT_EQ(entries_per_cmd_, num_processed); |
| 1408 } |
| 1409 |
| 1410 // Test that commands with bad argument size are skipped without processing. |
| 1411 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsBadArgSize) { |
| 1412 cmds_[1].header.size += 1; |
| 1413 int num_processed = -1; |
| 1414 SetExpectationsForNCommands(1); |
| 1415 EXPECT_EQ(error::kInvalidArguments, |
| 1416 decoder_->DoCommands( |
| 1417 2, &cmds_, entries_per_cmd_ * 2 + 1, &num_processed)); |
| 1418 EXPECT_EQ(GL_NO_ERROR, GetGLError()); |
| 1419 EXPECT_EQ(entries_per_cmd_ + cmds_[1].header.size, num_processed); |
| 1420 } |
| 1421 |
1324 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderTest, ::testing::Bool()); | 1422 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderTest, ::testing::Bool()); |
1325 | 1423 |
1326 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderWithShaderTest, ::testing::Bool()); | 1424 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderWithShaderTest, ::testing::Bool()); |
1327 | 1425 |
1328 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderManualInitTest, ::testing::Bool()); | 1426 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderManualInitTest, ::testing::Bool()); |
1329 | 1427 |
1330 INSTANTIATE_TEST_CASE_P(Service, | 1428 INSTANTIATE_TEST_CASE_P(Service, |
1331 GLES2DecoderRGBBackbufferTest, | 1429 GLES2DecoderRGBBackbufferTest, |
1332 ::testing::Bool()); | 1430 ::testing::Bool()); |
1333 | 1431 |
| 1432 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderDoCommandsTest, ::testing::Bool()); |
| 1433 |
1334 } // namespace gles2 | 1434 } // namespace gles2 |
1335 } // namespace gpu | 1435 } // namespace gpu |
OLD | NEW |