Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/command_executor.h" | 5 #include "gpu/command_buffer/service/command_executor.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
|
no sievers
2016/04/05 19:02:40
#include <memory>
Mostyn Bramley-Moore
2016/04/05 21:35:31
Done.
| |
| 10 #include "gpu/command_buffer/common/command_buffer_mock.h" | 10 #include "gpu/command_buffer/common/command_buffer_mock.h" |
| 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 11 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 12 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" |
| 13 #include "gpu/command_buffer/service/mocks.h" | 13 #include "gpu/command_buffer/service/mocks.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using testing::_; | 17 using testing::_; |
| 18 using testing::DoAll; | 18 using testing::DoAll; |
| 19 using testing::Invoke; | 19 using testing::Invoke; |
| 20 using testing::NiceMock; | 20 using testing::NiceMock; |
| 21 using testing::Return; | 21 using testing::Return; |
| 22 using testing::SetArgumentPointee; | 22 using testing::SetArgumentPointee; |
| 23 using testing::StrictMock; | 23 using testing::StrictMock; |
| 24 | 24 |
| 25 namespace gpu { | 25 namespace gpu { |
| 26 | 26 |
| 27 const size_t kRingBufferSize = 1024; | 27 const size_t kRingBufferSize = 1024; |
| 28 | 28 |
| 29 class CommandExecutorTest : public testing::Test { | 29 class CommandExecutorTest : public testing::Test { |
| 30 protected: | 30 protected: |
| 31 static const int32_t kTransferBufferId = 123; | 31 static const int32_t kTransferBufferId = 123; |
| 32 | 32 |
| 33 void SetUp() override { | 33 void SetUp() override { |
| 34 scoped_ptr<base::SharedMemory> shared_memory(new ::base::SharedMemory); | 34 std::unique_ptr<base::SharedMemory> shared_memory(new ::base::SharedMemory); |
| 35 shared_memory->CreateAndMapAnonymous(kRingBufferSize); | 35 shared_memory->CreateAndMapAnonymous(kRingBufferSize); |
| 36 buffer_ = static_cast<int32_t*>(shared_memory->memory()); | 36 buffer_ = static_cast<int32_t*>(shared_memory->memory()); |
| 37 shared_memory_buffer_ = | 37 shared_memory_buffer_ = |
| 38 MakeBufferFromSharedMemory(std::move(shared_memory), kRingBufferSize); | 38 MakeBufferFromSharedMemory(std::move(shared_memory), kRingBufferSize); |
| 39 memset(buffer_, 0, kRingBufferSize); | 39 memset(buffer_, 0, kRingBufferSize); |
| 40 | 40 |
| 41 command_buffer_.reset(new MockCommandBuffer); | 41 command_buffer_.reset(new MockCommandBuffer); |
| 42 | 42 |
| 43 CommandBuffer::State default_state; | 43 CommandBuffer::State default_state; |
| 44 ON_CALL(*command_buffer_.get(), GetLastState()) | 44 ON_CALL(*command_buffer_.get(), GetLastState()) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 61 } | 61 } |
| 62 | 62 |
| 63 void TearDown() override { | 63 void TearDown() override { |
| 64 // Ensure that any unexpected tasks posted by the GPU scheduler are executed | 64 // Ensure that any unexpected tasks posted by the GPU scheduler are executed |
| 65 // in order to fail the test. | 65 // in order to fail the test. |
| 66 base::MessageLoop::current()->RunUntilIdle(); | 66 base::MessageLoop::current()->RunUntilIdle(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 error::Error GetError() { return command_buffer_->GetLastState().error; } | 69 error::Error GetError() { return command_buffer_->GetLastState().error; } |
| 70 | 70 |
| 71 scoped_ptr<MockCommandBuffer> command_buffer_; | 71 std::unique_ptr<MockCommandBuffer> command_buffer_; |
| 72 scoped_refptr<Buffer> shared_memory_buffer_; | 72 scoped_refptr<Buffer> shared_memory_buffer_; |
| 73 int32_t* buffer_; | 73 int32_t* buffer_; |
| 74 scoped_ptr<gles2::MockGLES2Decoder> decoder_; | 74 std::unique_ptr<gles2::MockGLES2Decoder> decoder_; |
| 75 scoped_ptr<CommandExecutor> executor_; | 75 std::unique_ptr<CommandExecutor> executor_; |
| 76 base::MessageLoop message_loop_; | 76 base::MessageLoop message_loop_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 TEST_F(CommandExecutorTest, ExecutorDoesNothingIfRingBufferIsEmpty) { | 79 TEST_F(CommandExecutorTest, ExecutorDoesNothingIfRingBufferIsEmpty) { |
| 80 CommandBuffer::State state; | 80 CommandBuffer::State state; |
| 81 | 81 |
| 82 EXPECT_CALL(*command_buffer_, GetLastState()).WillRepeatedly(Return(state)); | 82 EXPECT_CALL(*command_buffer_, GetLastState()).WillRepeatedly(Return(state)); |
| 83 | 83 |
| 84 EXPECT_CALL(*command_buffer_, SetParseError(_)).Times(0); | 84 EXPECT_CALL(*command_buffer_, SetParseError(_)).Times(0); |
| 85 | 85 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 | 195 |
| 196 EXPECT_EQ(kRingBufferSize, executor_->GetSharedMemoryBuffer(7)->size()); | 196 EXPECT_EQ(kRingBufferSize, executor_->GetSharedMemoryBuffer(7)->size()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST_F(CommandExecutorTest, SetTokenForwardsToCommandBuffer) { | 199 TEST_F(CommandExecutorTest, SetTokenForwardsToCommandBuffer) { |
| 200 EXPECT_CALL(*command_buffer_, SetToken(7)); | 200 EXPECT_CALL(*command_buffer_, SetToken(7)); |
| 201 executor_->set_token(7); | 201 executor_->set_token(7); |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace gpu | 204 } // namespace gpu |
| OLD | NEW |