| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // Tests for the Command Buffer Helper. | 33 // Tests for the Command Buffer Helper. |
| 34 | 34 |
| 35 #include "base/at_exit.h" | 35 #include "base/at_exit.h" |
| 36 #include "base/message_loop.h" | 36 #include "base/message_loop.h" |
| 37 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 37 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 38 #include "gpu/command_buffer/service/mocks.h" | 38 #include "gpu/command_buffer/service/mocks.h" |
| 39 #include "gpu/command_buffer/service/command_buffer_service.h" | 39 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 40 #include "gpu/command_buffer/service/gpu_processor.h" | 40 #include "gpu/command_buffer/service/gpu_processor.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 42 |
| 43 namespace command_buffer { | 43 namespace gpu { |
| 44 | 44 |
| 45 using command_buffer::CommandBufferService; | 45 using gpu::CommandBufferService; |
| 46 using command_buffer::GPUProcessor; | 46 using gpu::GPUProcessor; |
| 47 using testing::Return; | 47 using testing::Return; |
| 48 using testing::Mock; | 48 using testing::Mock; |
| 49 using testing::Truly; | 49 using testing::Truly; |
| 50 using testing::Sequence; | 50 using testing::Sequence; |
| 51 using testing::DoAll; | 51 using testing::DoAll; |
| 52 using testing::Invoke; | 52 using testing::Invoke; |
| 53 using testing::_; | 53 using testing::_; |
| 54 | 54 |
| 55 const int32 kNumCommandEntries = 10; | 55 const int32 kNumCommandEntries = 10; |
| 56 const int32 kCommandBufferSizeBytes = kNumCommandEntries * sizeof(int32); | 56 const int32 kCommandBufferSizeBytes = |
| 57 kNumCommandEntries * sizeof(CommandBufferEntry); |
| 57 | 58 |
| 58 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, | 59 // Test fixture for CommandBufferHelper test - Creates a CommandBufferHelper, |
| 59 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface | 60 // using a CommandBufferEngine with a mock AsyncAPIInterface for its interface |
| 60 // (calling it directly, not through the RPC mechanism). | 61 // (calling it directly, not through the RPC mechanism). |
| 61 class CommandBufferHelperTest : public testing::Test { | 62 class CommandBufferHelperTest : public testing::Test { |
| 62 protected: | 63 protected: |
| 63 virtual void SetUp() { | 64 virtual void SetUp() { |
| 64 api_mock_.reset(new AsyncAPIMock); | 65 api_mock_.reset(new AsyncAPIMock); |
| 65 // ignore noops in the mock - we don't want to inspect the internals of the | 66 // ignore noops in the mock - we don't want to inspect the internals of the |
| 66 // helper. | 67 // helper. |
| 67 EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) | 68 EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) |
| 68 .WillRepeatedly(Return(parse_error::kParseNoError)); | 69 .WillRepeatedly(Return(parse_error::kParseNoError)); |
| 69 | 70 |
| 70 base::SharedMemory* ring_buffer = new base::SharedMemory; | 71 command_buffer_.reset(new CommandBufferService); |
| 71 ring_buffer->Create(std::wstring(), false, false, kCommandBufferSizeBytes); | 72 base::SharedMemory* ring_buffer = command_buffer_->Initialize( |
| 72 ring_buffer->Map(1024); | 73 kNumCommandEntries); |
| 73 | 74 |
| 74 command_buffer_.reset(new CommandBufferService); | |
| 75 command_buffer_->Initialize(ring_buffer); | |
| 76 | 75 |
| 77 parser_ = new command_buffer::CommandParser(ring_buffer->memory(), | 76 parser_ = new gpu::CommandParser(ring_buffer->memory(), |
| 78 kCommandBufferSizeBytes, | 77 kCommandBufferSizeBytes, |
| 79 0, | 78 0, |
| 80 kCommandBufferSizeBytes, | 79 kCommandBufferSizeBytes, |
| 81 0, | 80 0, |
| 82 api_mock_.get()); | 81 api_mock_.get()); |
| 83 | 82 |
| 84 scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( | 83 scoped_refptr<GPUProcessor> gpu_processor(new GPUProcessor( |
| 85 command_buffer_.get(), NULL, parser_, 1)); | 84 command_buffer_.get(), NULL, parser_, 1)); |
| 86 command_buffer_->SetPutOffsetChangeCallback(NewCallback( | 85 command_buffer_->SetPutOffsetChangeCallback(NewCallback( |
| 87 gpu_processor.get(), &GPUProcessor::ProcessCommands)); | 86 gpu_processor.get(), &GPUProcessor::ProcessCommands)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 132 } |
| 134 } | 133 } |
| 135 } | 134 } |
| 136 | 135 |
| 137 CommandBufferOffset get_helper_put() { return helper_->put_; } | 136 CommandBufferOffset get_helper_put() { return helper_->put_; } |
| 138 | 137 |
| 139 base::AtExitManager at_exit_manager_; | 138 base::AtExitManager at_exit_manager_; |
| 140 MessageLoop message_loop_; | 139 MessageLoop message_loop_; |
| 141 scoped_ptr<AsyncAPIMock> api_mock_; | 140 scoped_ptr<AsyncAPIMock> api_mock_; |
| 142 scoped_ptr<CommandBufferService> command_buffer_; | 141 scoped_ptr<CommandBufferService> command_buffer_; |
| 143 command_buffer::CommandParser* parser_; | 142 gpu::CommandParser* parser_; |
| 144 scoped_ptr<CommandBufferHelper> helper_; | 143 scoped_ptr<CommandBufferHelper> helper_; |
| 145 Sequence sequence_; | 144 Sequence sequence_; |
| 146 }; | 145 }; |
| 147 | 146 |
| 148 // Checks that commands in the buffer are properly executed, and that the | 147 // Checks that commands in the buffer are properly executed, and that the |
| 149 // status/error stay valid. | 148 // status/error stay valid. |
| 150 TEST_F(CommandBufferHelperTest, TestCommandProcessing) { | 149 TEST_F(CommandBufferHelperTest, TestCommandProcessing) { |
| 151 // Check initial state of the engine - it should have been configured by the | 150 // Check initial state of the engine - it should have been configured by the |
| 152 // helper. | 151 // helper. |
| 153 EXPECT_TRUE(parser_ != NULL); | 152 EXPECT_TRUE(parser_ != NULL); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 helper_->Finish(); | 287 helper_->Finish(); |
| 289 | 288 |
| 290 // Check that the commands did happen. | 289 // Check that the commands did happen. |
| 291 Mock::VerifyAndClearExpectations(api_mock_.get()); | 290 Mock::VerifyAndClearExpectations(api_mock_.get()); |
| 292 | 291 |
| 293 // Check the error status. | 292 // Check the error status. |
| 294 EXPECT_FALSE(command_buffer_->GetErrorStatus()); | 293 EXPECT_FALSE(command_buffer_->GetErrorStatus()); |
| 295 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError()); | 294 EXPECT_EQ(parse_error::kParseNoError, command_buffer_->ResetParseError()); |
| 296 } | 295 } |
| 297 | 296 |
| 298 } // namespace command_buffer | 297 } // namespace gpu |
| OLD | NEW |