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

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

Issue 9999003: Optimize GetBucketContents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « gpu/command_buffer/service/common_decoder.cc ('k') | no next file » | 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) 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 #include "gpu/command_buffer/service/common_decoder.h" 5 #include "gpu/command_buffer/service/common_decoder.h"
6 #include "gpu/command_buffer/service/cmd_buffer_engine.h" 6 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace gpu { 9 namespace gpu {
10 10
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 cmd.Init(kBucketId, bucket->size(), 1); 464 cmd.Init(kBucketId, bucket->size(), 1);
465 EXPECT_NE(error::kNoError, 465 EXPECT_NE(error::kNoError,
466 ExecuteImmediateCmd(cmd, sizeof(kData2))); 466 ExecuteImmediateCmd(cmd, sizeof(kData2)));
467 467
468 // Check that it fails if the size is out of range. 468 // Check that it fails if the size is out of range.
469 cmd.Init(kBucketId, 0, bucket->size() + 1); 469 cmd.Init(kBucketId, 0, bucket->size() + 1);
470 EXPECT_NE(error::kNoError, 470 EXPECT_NE(error::kNoError,
471 ExecuteImmediateCmd(cmd, sizeof(kData2))); 471 ExecuteImmediateCmd(cmd, sizeof(kData2)));
472 } 472 }
473 473
474 TEST_F(CommonDecoderTest, GetBucketSize) { 474 TEST_F(CommonDecoderTest, GetBucketStart) {
475 cmd::SetBucketSize size_cmd; 475 cmd::SetBucketSize size_cmd;
476 cmd::GetBucketSize cmd; 476 cmd::SetBucketData set_cmd;
477 cmd::GetBucketStart cmd;
477 478
478 const uint32 kBucketSize = 456; 479 static const char kData[] = "1234567890123456789";
480 static const char zero[sizeof(kData)] = { 0, };
481
482 const uint32 kBucketSize = sizeof(kData);
479 const uint32 kBucketId = 123; 483 const uint32 kBucketId = 123;
480 const uint32 kInvalidBucketId = 124; 484 const uint32 kInvalidBucketId = 124;
481 485
482 size_cmd.Init(kBucketId, kBucketSize); 486 // Put data in the bucket.
487 size_cmd.Init(kBucketId, sizeof(kData));
483 EXPECT_EQ(error::kNoError, ExecuteCmd(size_cmd)); 488 EXPECT_EQ(error::kNoError, ExecuteCmd(size_cmd));
489 const uint32 kSomeOffsetInSharedMemory = 50;
490 uint8* start = engine_.GetSharedMemoryAs<uint8*>(kSomeOffsetInSharedMemory);
491 memcpy(start, kData, sizeof(kData));
492 set_cmd.Init(kBucketId, 0, sizeof(kData),
493 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory);
494 EXPECT_EQ(error::kNoError, ExecuteCmd(set_cmd));
484 495
485 // Check that the size is correct. 496 // Check that the size is correct with no data buffer.
486 const uint32 kSomeOffsetInSharedMemory = 50;
487 uint32* memory = 497 uint32* memory =
488 engine_.GetSharedMemoryAs<uint32*>(kSomeOffsetInSharedMemory); 498 engine_.GetSharedMemoryAs<uint32*>(kSomeOffsetInSharedMemory);
489 *memory = 0x0; 499 *memory = 0x0;
490 cmd.Init(kBucketId, 500 cmd.Init(kBucketId,
491 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory); 501 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
502 0, 0, 0);
492 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 503 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
493 EXPECT_EQ(kBucketSize, *memory); 504 EXPECT_EQ(kBucketSize, *memory);
494 505
495 // Check that it fails if the bucket_id is invalid 506 // Check that the data is copied with data buffer.
507 const uint32 kDataOffsetInSharedMemory = 54;
508 uint8* data = engine_.GetSharedMemoryAs<uint8*>(kDataOffsetInSharedMemory);
509 *memory = 0x0;
510 memset(data, 0, sizeof(kData));
511 cmd.Init(kBucketId,
512 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
513 kBucketSize, MockCommandBufferEngine::kValidShmId,
514 kDataOffsetInSharedMemory);
515 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
516 EXPECT_EQ(kBucketSize, *memory);
517 EXPECT_EQ(0, memcmp(data, kData, kBucketSize));
518
519 // Check that we can get a piece.
520 *memory = 0x0;
521 memset(data, 0, sizeof(kData));
522 const uint32 kPieceSize = kBucketSize / 2;
523 cmd.Init(kBucketId,
524 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
525 kPieceSize, MockCommandBufferEngine::kValidShmId,
526 kDataOffsetInSharedMemory);
527 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
528 EXPECT_EQ(kBucketSize, *memory);
529 EXPECT_EQ(0, memcmp(data, kData, kPieceSize));
530 EXPECT_EQ(0, memcmp(data + kPieceSize, zero, sizeof(kData) - kPieceSize));
531
532 // Check that it fails if the result_id is invalid
496 cmd.Init(kInvalidBucketId, 533 cmd.Init(kInvalidBucketId,
497 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory); 534 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
535 0, 0, 0);
536 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
537
538 // Check that it fails if the data_id is invalid
539 cmd.Init(kBucketId,
540 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
541 1, MockCommandBufferEngine::kInvalidShmId, 0);
542 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
543
544 // Check that it fails if the data_size is invalid
545 cmd.Init(kBucketId,
546 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
547 1, 0, 0);
548 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
549 cmd.Init(kBucketId,
550 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
551 MockCommandBufferEngine::kBufferSize + 1,
552 MockCommandBufferEngine::kValidShmId, 0);
553 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
554
555 // Check that it fails if the data_offset is invalid
556 cmd.Init(kBucketId,
557 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
558 0, 0, 1);
559 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
560 cmd.Init(kBucketId,
561 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
562 MockCommandBufferEngine::kBufferSize,
563 MockCommandBufferEngine::kValidShmId, 1);
498 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); 564 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
499 565
500 // Check that it fails if the result size is not set to zero 566 // Check that it fails if the result size is not set to zero
501 *memory = 0x1; 567 *memory = 0x1;
502 cmd.Init(kBucketId, 568 cmd.Init(kBucketId,
503 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory); 569 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory,
570 0, 0, 0);
504 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); 571 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
505 } 572 }
506 573
507 TEST_F(CommonDecoderTest, GetBucketData) { 574 TEST_F(CommonDecoderTest, GetBucketData) {
508 cmd::SetBucketSize size_cmd; 575 cmd::SetBucketSize size_cmd;
509 cmd::SetBucketData set_cmd; 576 cmd::SetBucketData set_cmd;
510 cmd::GetBucketData cmd; 577 cmd::GetBucketData cmd;
511 578
512 static const char kData[] = "1234567890123456789"; 579 static const char kData[] = "1234567890123456789";
513 static const char zero[sizeof(kData)] = { 0, }; 580 static const char zero[sizeof(kData)] = { 0, };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); 623 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
557 624
558 // Check that it fails if the size is invalid 625 // Check that it fails if the size is invalid
559 cmd.Init(kBucketId, 0, sizeof(kData) + 1, 626 cmd.Init(kBucketId, 0, sizeof(kData) + 1,
560 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory); 627 MockCommandBufferEngine::kValidShmId, kSomeOffsetInSharedMemory);
561 EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); 628 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
562 } 629 }
563 630
564 } // namespace gpu 631 } // namespace gpu
565 632
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/common_decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698