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

Side by Side Diff: gpu/command_buffer/common/command_buffer_shared_test.cc

Issue 9380037: Use shared memory to update the renderer's view of the command buffer state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix hang when last_state_.error accidentally overwritten Created 8 years, 10 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
(Empty)
1
2 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 // This file contains the tests for the CommandBufferSharedState class.
7
8 #include "gpu/command_buffer/common/command_buffer_shared.h"
9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/thread.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace gpu {
15
16 class CommandBufferSharedTest : public testing::Test {
17 protected:
18
19 virtual void SetUp() {
20 shared_state_.reset(new CommandBufferSharedState());
21 shared_state_->Initialize();
22 }
23
24 scoped_ptr<CommandBufferSharedState> shared_state_;
25 };
26
27 TEST_F(CommandBufferSharedTest, TestBasic) {
28 CommandBuffer::State state;
29
30 shared_state_->Read(&state);
31
32 EXPECT_LT(state.generation, 0x80000000);
33 EXPECT_EQ(state.get_offset, 0);
34 EXPECT_EQ(state.put_offset, 0);
35 EXPECT_EQ(state.token, -1);
36 EXPECT_EQ(state.error, gpu::error::kNoError);
37 EXPECT_EQ(state.context_lost_reason, gpu::error::kUnknown);
38 }
39
40 static const int kSize = 100000;
41
42 void WriteToState(int32 *buffer,
43 CommandBufferSharedState* shared_state) {
44 CommandBuffer::State state;
45 for (int i = 0; i < kSize; i++) {
46 state.token = i - 1;
47 state.get_offset = i + 1;
48 state.generation = i + 2;
49 state.error = static_cast<gpu::error::Error>(i + 3);
50 // Ensure that the producer doesn't update the buffer until after the
51 // consumer reads from it.
52 EXPECT_EQ(buffer[i], 0);
53
54 shared_state->Write(state);
55 }
56 }
57
58 TEST_F(CommandBufferSharedTest, TestConsistency) {
59 scoped_array<int32> buffer;
60 buffer.reset(new int32[kSize]);
61 base::Thread consumer("Reader Thread");
62
63 memset(buffer.get(), 0, kSize * sizeof(int32));
64
65 consumer.Start();
66 consumer.message_loop()->PostTask(
67 FROM_HERE, base::Bind(&WriteToState, buffer.get(),
68 shared_state_.get()));
69
70 CommandBuffer::State last_state;
71 while (1) {
72 CommandBuffer::State state = last_state;
73
74 shared_state_->Read(&state);
75
76 if (state.generation < last_state.generation)
77 continue;
78
79 if (state.get_offset >= 1) {
80 buffer[state.get_offset - 1] = 1;
81 // Check that the state is consistent
82 EXPECT_LE(last_state.token, state.token);
83 EXPECT_LE(last_state.generation, state.generation);
84 last_state = state;
85 EXPECT_EQ(state.token, state.get_offset - 2);
86 EXPECT_EQ(state.generation,
87 static_cast<unsigned int>(state.get_offset) + 1);
88 EXPECT_EQ(state.error, state.get_offset + 2);
89
90 if (state.get_offset == kSize)
91 break;
92 }
93 }
94 }
95
96 } // namespace gpu
97
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/command_buffer_shared.h ('k') | gpu/command_buffer/service/command_buffer_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698