| 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 // This file contains the tests for the CommandBufferSharedState class. | 5 // This file contains the tests for the CommandBufferSharedState class. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/common/command_buffer_shared.h" | 7 #include "gpu/command_buffer/common/command_buffer_shared.h" |
| 8 | 8 |
| 9 #include <stdint.h> |
| 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/location.h" | 12 #include "base/location.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 namespace gpu { | 18 namespace gpu { |
| 17 | 19 |
| 18 class CommandBufferSharedTest : public testing::Test { | 20 class CommandBufferSharedTest : public testing::Test { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 32 | 34 |
| 33 EXPECT_LT(state.generation, 0x80000000); | 35 EXPECT_LT(state.generation, 0x80000000); |
| 34 EXPECT_EQ(state.get_offset, 0); | 36 EXPECT_EQ(state.get_offset, 0); |
| 35 EXPECT_EQ(state.token, -1); | 37 EXPECT_EQ(state.token, -1); |
| 36 EXPECT_EQ(state.error, gpu::error::kNoError); | 38 EXPECT_EQ(state.error, gpu::error::kNoError); |
| 37 EXPECT_EQ(state.context_lost_reason, gpu::error::kUnknown); | 39 EXPECT_EQ(state.context_lost_reason, gpu::error::kUnknown); |
| 38 } | 40 } |
| 39 | 41 |
| 40 static const int kSize = 100000; | 42 static const int kSize = 100000; |
| 41 | 43 |
| 42 void WriteToState(int32 *buffer, | 44 void WriteToState(int32_t* buffer, CommandBufferSharedState* shared_state) { |
| 43 CommandBufferSharedState* shared_state) { | |
| 44 CommandBuffer::State state; | 45 CommandBuffer::State state; |
| 45 for (int i = 0; i < kSize; i++) { | 46 for (int i = 0; i < kSize; i++) { |
| 46 state.token = i - 1; | 47 state.token = i - 1; |
| 47 state.get_offset = i + 1; | 48 state.get_offset = i + 1; |
| 48 state.generation = i + 2; | 49 state.generation = i + 2; |
| 49 state.error = static_cast<gpu::error::Error>(i + 3); | 50 state.error = static_cast<gpu::error::Error>(i + 3); |
| 50 // Ensure that the producer doesn't update the buffer until after the | 51 // Ensure that the producer doesn't update the buffer until after the |
| 51 // consumer reads from it. | 52 // consumer reads from it. |
| 52 EXPECT_EQ(buffer[i], 0); | 53 EXPECT_EQ(buffer[i], 0); |
| 53 | 54 |
| 54 shared_state->Write(state); | 55 shared_state->Write(state); |
| 55 } | 56 } |
| 56 } | 57 } |
| 57 | 58 |
| 58 TEST_F(CommandBufferSharedTest, TestConsistency) { | 59 TEST_F(CommandBufferSharedTest, TestConsistency) { |
| 59 scoped_ptr<int32[]> buffer; | 60 scoped_ptr<int32_t[]> buffer; |
| 60 buffer.reset(new int32[kSize]); | 61 buffer.reset(new int32_t[kSize]); |
| 61 base::Thread consumer("Reader Thread"); | 62 base::Thread consumer("Reader Thread"); |
| 62 | 63 |
| 63 memset(buffer.get(), 0, kSize * sizeof(int32)); | 64 memset(buffer.get(), 0, kSize * sizeof(int32_t)); |
| 64 | 65 |
| 65 consumer.Start(); | 66 consumer.Start(); |
| 66 consumer.task_runner()->PostTask( | 67 consumer.task_runner()->PostTask( |
| 67 FROM_HERE, base::Bind(&WriteToState, buffer.get(), shared_state_.get())); | 68 FROM_HERE, base::Bind(&WriteToState, buffer.get(), shared_state_.get())); |
| 68 | 69 |
| 69 CommandBuffer::State last_state; | 70 CommandBuffer::State last_state; |
| 70 while (1) { | 71 while (1) { |
| 71 CommandBuffer::State state = last_state; | 72 CommandBuffer::State state = last_state; |
| 72 | 73 |
| 73 shared_state_->Read(&state); | 74 shared_state_->Read(&state); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 87 EXPECT_EQ(state.error, state.get_offset + 2); | 88 EXPECT_EQ(state.error, state.get_offset + 2); |
| 88 | 89 |
| 89 if (state.get_offset == kSize) | 90 if (state.get_offset == kSize) |
| 90 break; | 91 break; |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 | 95 |
| 95 } // namespace gpu | 96 } // namespace gpu |
| 96 | 97 |
| OLD | NEW |