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

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

Issue 199443004: gpu: Raise GL_OUT_OF_MEMORY when BeginQueryEXT fails to allocate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: checkmem: benchmark Created 6 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
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 GLES2Implementation. 5 // Tests for GLES2Implementation.
6 6
7 #include "gpu/command_buffer/client/gles2_implementation.h" 7 #include "gpu/command_buffer/client/gles2_implementation.h"
8 8
9 #include <limits>
10
9 #include <GLES2/gl2ext.h> 11 #include <GLES2/gl2ext.h>
10 #include <GLES2/gl2extchromium.h> 12 #include <GLES2/gl2extchromium.h>
11 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
12 #include "gpu/command_buffer/client/client_test_helper.h" 14 #include "gpu/command_buffer/client/client_test_helper.h"
13 #include "gpu/command_buffer/client/program_info_manager.h" 15 #include "gpu/command_buffer/client/program_info_manager.h"
14 #include "gpu/command_buffer/client/transfer_buffer.h" 16 #include "gpu/command_buffer/client/transfer_buffer.h"
15 #include "gpu/command_buffer/common/command_buffer.h" 17 #include "gpu/command_buffer/common/command_buffer.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
18 20
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 static const GLuint kTexturesStartId = 1; 385 static const GLuint kTexturesStartId = 1;
384 static const GLuint kQueriesStartId = 1; 386 static const GLuint kQueriesStartId = 1;
385 static const GLuint kVertexArraysStartId = 1; 387 static const GLuint kVertexArraysStartId = 1;
386 388
387 typedef MockTransferBuffer::ExpectedMemoryInfo ExpectedMemoryInfo; 389 typedef MockTransferBuffer::ExpectedMemoryInfo ExpectedMemoryInfo;
388 390
389 class TestContext { 391 class TestContext {
390 public: 392 public:
391 TestContext() : commands_(NULL), token_(0) {} 393 TestContext() : commands_(NULL), token_(0) {}
392 394
393 void Initialize(ShareGroup* share_group, bool bind_generates_resource) { 395 void Initialize(ShareGroup* share_group,
396 bool bind_generates_resource,
397 bool lose_context_when_out_of_memory) {
394 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>()); 398 command_buffer_.reset(new StrictMock<MockClientCommandBuffer>());
395 ASSERT_TRUE(command_buffer_->Initialize()); 399 ASSERT_TRUE(command_buffer_->Initialize());
396 400
397 transfer_buffer_.reset( 401 transfer_buffer_.reset(
398 new MockTransferBuffer(command_buffer_.get(), 402 new MockTransferBuffer(command_buffer_.get(),
399 kTransferBufferSize, 403 kTransferBufferSize,
400 GLES2Implementation::kStartingOffset, 404 GLES2Implementation::kStartingOffset,
401 GLES2Implementation::kAlignment)); 405 GLES2Implementation::kAlignment));
402 406
403 helper_.reset(new GLES2CmdHelper(command_buffer())); 407 helper_.reset(new GLES2CmdHelper(command_buffer()));
(...skipping 28 matching lines...) Expand all
432 sizeof(cmds::GetShaderPrecisionFormat::Result) * 12); 436 sizeof(cmds::GetShaderPrecisionFormat::Result) * 12);
433 437
434 { 438 {
435 InSequence sequence; 439 InSequence sequence;
436 440
437 EXPECT_CALL(*command_buffer_, OnFlush()) 441 EXPECT_CALL(*command_buffer_, OnFlush())
438 .WillOnce(SetMemory(mem1.ptr + sizeof(int_state), int_state)) 442 .WillOnce(SetMemory(mem1.ptr + sizeof(int_state), int_state))
439 .RetiresOnSaturation(); 443 .RetiresOnSaturation();
440 GetNextToken(); // eat the token that starting up will use. 444 GetNextToken(); // eat the token that starting up will use.
441 445
442 gl_.reset( 446 gl_.reset(new GLES2Implementation(helper_.get(),
443 new GLES2Implementation(helper_.get(), 447 share_group,
444 share_group, 448 transfer_buffer_.get(),
445 transfer_buffer_.get(), 449 bind_generates_resource,
446 bind_generates_resource, 450 lose_context_when_out_of_memory,
447 gpu_control_.get())); 451 gpu_control_.get()));
448 ASSERT_TRUE(gl_->Initialize(kTransferBufferSize, 452 ASSERT_TRUE(gl_->Initialize(kTransferBufferSize,
449 kTransferBufferSize, 453 kTransferBufferSize,
450 kTransferBufferSize, 454 kTransferBufferSize,
451 GLES2Implementation::kNoLimit)); 455 GLES2Implementation::kNoLimit));
452 } 456 }
453 457
454 EXPECT_CALL(*command_buffer_, OnFlush()).Times(1).RetiresOnSaturation(); 458 EXPECT_CALL(*command_buffer_, OnFlush()).Times(1).RetiresOnSaturation();
455 helper_->CommandBufferHelper::Finish(); 459 helper_->CommandBufferHelper::Finish();
456 ::testing::Mock::VerifyAndClearExpectations(gl_.get()); 460 ::testing::Mock::VerifyAndClearExpectations(gl_.get());
457 461
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 return false; 511 return false;
508 } 512 }
509 } 513 }
510 return true; 514 return true;
511 } 515 }
512 516
513 QueryTracker::Query* GetQuery(GLuint id) { 517 QueryTracker::Query* GetQuery(GLuint id) {
514 return gl_->query_tracker_->GetQuery(id); 518 return gl_->query_tracker_->GetQuery(id);
515 } 519 }
516 520
517 void Initialize(bool bind_generates_resource) { 521 void Initialize(bool bind_generates_resource,
522 bool lose_context_when_out_of_memory) {
518 share_group_ = new ShareGroup(bind_generates_resource); 523 share_group_ = new ShareGroup(bind_generates_resource);
519 524
520 for (int i = 0; i < kNumTestContexts; i++) 525 for (int i = 0; i < kNumTestContexts; i++)
521 test_contexts_[i].Initialize(share_group_.get(), bind_generates_resource); 526 test_contexts_[i].Initialize(share_group_.get(),
527 bind_generates_resource,
528 lose_context_when_out_of_memory);
522 529
523 // Default to test context 0. 530 // Default to test context 0.
524 gpu_control_ = test_contexts_[0].gpu_control_.get(); 531 gpu_control_ = test_contexts_[0].gpu_control_.get();
525 helper_ = test_contexts_[0].helper_.get(); 532 helper_ = test_contexts_[0].helper_.get();
526 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get(); 533 transfer_buffer_ = test_contexts_[0].transfer_buffer_.get();
527 gl_ = test_contexts_[0].gl_.get(); 534 gl_ = test_contexts_[0].gl_.get();
528 commands_ = test_contexts_[0].commands_; 535 commands_ = test_contexts_[0].commands_;
529 } 536 }
530 537
531 MockClientCommandBuffer* command_buffer() const { 538 MockClientCommandBuffer* command_buffer() const {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 585
579 scoped_refptr<ShareGroup> share_group_; 586 scoped_refptr<ShareGroup> share_group_;
580 MockClientGpuControl* gpu_control_; 587 MockClientGpuControl* gpu_control_;
581 GLES2CmdHelper* helper_; 588 GLES2CmdHelper* helper_;
582 MockTransferBuffer* transfer_buffer_; 589 MockTransferBuffer* transfer_buffer_;
583 GLES2Implementation* gl_; 590 GLES2Implementation* gl_;
584 CommandBufferEntry* commands_; 591 CommandBufferEntry* commands_;
585 }; 592 };
586 593
587 void GLES2ImplementationTest::SetUp() { 594 void GLES2ImplementationTest::SetUp() {
588 Initialize(true); 595 bool bind_generates_resource = true;
596 bool lose_context_when_out_of_memory = false;
597 Initialize(bind_generates_resource, lose_context_when_out_of_memory);
589 } 598 }
590 599
591 void GLES2ImplementationTest::TearDown() { 600 void GLES2ImplementationTest::TearDown() {
592 for (int i = 0; i < kNumTestContexts; i++) 601 for (int i = 0; i < kNumTestContexts; i++)
593 test_contexts_[i].TearDown(); 602 test_contexts_[i].TearDown();
594 } 603 }
595 604
605 class GLES2ImplementationManualInitTest : public GLES2ImplementationTest {
606 protected:
607 virtual void SetUp() OVERRIDE {}
608 };
609
596 class GLES2ImplementationStrictSharedTest : public GLES2ImplementationTest { 610 class GLES2ImplementationStrictSharedTest : public GLES2ImplementationTest {
597 protected: 611 protected:
598 virtual void SetUp() OVERRIDE; 612 virtual void SetUp() OVERRIDE;
599 613
600 template <class ResApi> 614 template <class ResApi>
601 void FlushGenerationTest() { 615 void FlushGenerationTest() {
602 GLuint id1, id2, id3; 616 GLuint id1, id2, id3;
603 617
604 // Generate valid id. 618 // Generate valid id.
605 ResApi::Gen(gl_, 1, &id1); 619 ResApi::Gen(gl_, 1, &id1);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 EXPECT_NE(id1, id3); 690 EXPECT_NE(id1, id3);
677 691
678 // Lazy release triggered by another Delete. Should reuse id1. 692 // Lazy release triggered by another Delete. Should reuse id1.
679 ResApi::Delete(gl1, 1, &id2); 693 ResApi::Delete(gl1, 1, &id2);
680 ResApi::Gen(gl2, 1, &id3); 694 ResApi::Gen(gl2, 1, &id3);
681 EXPECT_EQ(id1, id3); 695 EXPECT_EQ(id1, id3);
682 } 696 }
683 }; 697 };
684 698
685 void GLES2ImplementationStrictSharedTest::SetUp() { 699 void GLES2ImplementationStrictSharedTest::SetUp() {
686 Initialize(false); 700 bool bind_generates_resource = false;
701 bool lose_context_when_out_of_memory = false;
702 Initialize(bind_generates_resource, lose_context_when_out_of_memory);
687 } 703 }
688 704
689 // GCC requires these declarations, but MSVC requires they not be present 705 // GCC requires these declarations, but MSVC requires they not be present
690 #ifndef _MSC_VER 706 #ifndef _MSC_VER
691 const uint8 GLES2ImplementationTest::kInitialValue; 707 const uint8 GLES2ImplementationTest::kInitialValue;
692 const int32 GLES2ImplementationTest::kNumCommandEntries; 708 const int32 GLES2ImplementationTest::kNumCommandEntries;
693 const int32 GLES2ImplementationTest::kCommandBufferSizeBytes; 709 const int32 GLES2ImplementationTest::kCommandBufferSizeBytes;
694 const size_t GLES2ImplementationTest::kTransferBufferSize; 710 const size_t GLES2ImplementationTest::kTransferBufferSize;
695 const GLint GLES2ImplementationTest::kMaxCombinedTextureImageUnits; 711 const GLint GLES2ImplementationTest::kMaxCombinedTextureImageUnits;
696 const GLint GLES2ImplementationTest::kMaxCubeMapTextureSize; 712 const GLint GLES2ImplementationTest::kMaxCubeMapTextureSize;
(...skipping 2396 matching lines...) Expand 10 before | Expand all | Expand 10 after
3093 GLbyte data[64]; 3109 GLbyte data[64];
3094 }; 3110 };
3095 3111
3096 Mailbox mailbox = Mailbox::Generate(); 3112 Mailbox mailbox = Mailbox::Generate();
3097 Cmds expected; 3113 Cmds expected;
3098 expected.cmd.Init(GL_TEXTURE_2D, mailbox.name); 3114 expected.cmd.Init(GL_TEXTURE_2D, mailbox.name);
3099 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 3115 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
3100 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected))); 3116 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
3101 } 3117 }
3102 3118
3119 TEST_F(GLES2ImplementationManualInitTest, LoseContextOnOOM) {
3120 bool bind_generates_resource = false;
3121 bool lose_context_when_out_of_memory = true;
3122 Initialize(bind_generates_resource, lose_context_when_out_of_memory);
3123
3124 struct Cmds {
3125 cmds::LoseContextCHROMIUM cmd;
3126 };
3127
3128 GLsizei max = std::numeric_limits<GLsizei>::max();
3129 EXPECT_CALL(*gpu_control_, CreateGpuMemoryBuffer(max, max, _, _))
3130 .WillOnce(Return(static_cast<gfx::GpuMemoryBuffer*>(NULL)));
3131 gl_->CreateImageCHROMIUM(max, max, 0);
3132 // The context should be lost.
3133 Cmds expected;
3134 expected.cmd.Init(GL_GUILTY_CONTEXT_RESET_ARB, GL_UNKNOWN_CONTEXT_RESET_ARB);
3135 EXPECT_EQ(0, memcmp(&expected, commands_, sizeof(expected)));
3136 }
3137
3138 TEST_F(GLES2ImplementationManualInitTest, NoLoseContextOnOOM) {
3139 bool bind_generates_resource = false;
3140 bool lose_context_when_out_of_memory = false;
3141 Initialize(bind_generates_resource, lose_context_when_out_of_memory);
3142
3143 struct Cmds {
3144 cmds::LoseContextCHROMIUM cmd;
3145 };
3146
3147 GLsizei max = std::numeric_limits<GLsizei>::max();
3148 EXPECT_CALL(*gpu_control_, CreateGpuMemoryBuffer(max, max, _, _))
3149 .WillOnce(Return(static_cast<gfx::GpuMemoryBuffer*>(NULL)));
3150 gl_->CreateImageCHROMIUM(max, max, 0);
3151 // The context should not be lost.
3152 EXPECT_TRUE(NoCommandsWritten());
3153 }
3154
3103 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h" 3155 #include "gpu/command_buffer/client/gles2_implementation_unittest_autogen.h"
3104 3156
3105 } // namespace gles2 3157 } // namespace gles2
3106 } // namespace gpu 3158 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/common/gles2_cmd_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698