OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/strings/string_number_conversions.h" | |
9 #include "gpu/command_buffer/common/gles2_cmd_format.h" | |
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | |
11 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | |
12 #include "gpu/command_buffer/service/context_group.h" | |
13 #include "gpu/command_buffer/service/gl_surface_mock.h" | |
14 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" | |
15 #include "gpu/command_buffer/service/gpu_switches.h" | |
16 #include "gpu/command_buffer/service/mocks.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 #include "ui/gl/gl_mock.h" | |
19 | |
20 using ::gfx::MockGLInterface; | |
21 using ::testing::_; | |
22 using ::testing::DoAll; | |
23 using ::testing::InSequence; | |
24 using ::testing::Invoke; | |
25 using ::testing::MatcherCast; | |
26 using ::testing::Mock; | |
27 using ::testing::Pointee; | |
28 using ::testing::Return; | |
29 using ::testing::SaveArg; | |
30 using ::testing::SetArrayArgument; | |
31 using ::testing::SetArgumentPointee; | |
32 using ::testing::SetArgPointee; | |
33 using ::testing::StrEq; | |
34 using ::testing::StrictMock; | |
35 | |
36 namespace gpu { | |
37 namespace gles2 { | |
38 | |
39 using namespace cmds; | |
40 | |
41 class GLES2DecoderDrawOOMTest : public GLES2DecoderManualInitTest { | |
42 protected: | |
43 void Init(bool has_robustness) { | |
44 InitState init; | |
45 init.lose_context_when_out_of_memory = true; | |
46 if (has_robustness) | |
47 init.extensions = "GL_ARB_robustness"; | |
48 InitDecoder(init); | |
49 SetupDefaultProgram(); | |
50 } | |
51 | |
52 void Draw(GLenum reset_status, | |
53 error::ContextLostReason expected_other_reason) { | |
54 const GLsizei kFakeLargeCount = 0x1234; | |
55 SetupTexture(); | |
56 if (context_->WasAllocatedUsingRobustnessExtension()) { | |
57 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()) | |
58 .WillOnce(Return(reset_status)); | |
59 } | |
60 AddExpectationsForSimulatedAttrib0WithError(kFakeLargeCount, 0, | |
61 GL_OUT_OF_MEMORY); | |
62 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation(); | |
63 // Other contexts in the group should be lost also. | |
64 EXPECT_CALL(*mock_decoder_, MarkContextLost(expected_other_reason)) | |
65 .Times(1) | |
66 .RetiresOnSaturation(); | |
67 DrawArrays cmd; | |
68 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount); | |
69 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd)); | |
70 } | |
71 }; | |
72 | |
73 // Test that we lose context. | |
74 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonOOM) { | |
75 Init(false); // without robustness | |
76 const error::ContextLostReason expected_reason_for_other_contexts = | |
77 error::kOutOfMemory; | |
78 Draw(GL_NO_ERROR, expected_reason_for_other_contexts); | |
79 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); | |
80 EXPECT_TRUE(decoder_->WasContextLost()); | |
81 EXPECT_EQ(error::kOutOfMemory, decoder_->GetContextLostReason()); | |
82 } | |
83 | |
84 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsNoError) { | |
85 Init(true); // with robustness | |
86 // If the reset status is NO_ERROR, we should be signaling kOutOfMemory. | |
87 const error::ContextLostReason expected_reason_for_other_contexts = | |
88 error::kOutOfMemory; | |
89 Draw(GL_NO_ERROR, expected_reason_for_other_contexts); | |
90 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); | |
91 EXPECT_TRUE(decoder_->WasContextLost()); | |
92 EXPECT_EQ(error::kOutOfMemory, decoder_->GetContextLostReason()); | |
93 } | |
94 | |
95 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsGuilty) { | |
96 Init(true); | |
97 // If there was a reset, it should override kOutOfMemory. | |
98 const error::ContextLostReason expected_reason_for_other_contexts = | |
99 error::kUnknown; | |
100 Draw(GL_GUILTY_CONTEXT_RESET_ARB, expected_reason_for_other_contexts); | |
101 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); | |
102 EXPECT_TRUE(decoder_->WasContextLost()); | |
103 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason()); | |
104 } | |
105 | |
106 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsUnknown) { | |
107 Init(true); | |
108 // If there was a reset, it should override kOutOfMemory. | |
109 const error::ContextLostReason expected_reason_for_other_contexts = | |
110 error::kUnknown; | |
111 Draw(GL_UNKNOWN_CONTEXT_RESET_ARB, expected_reason_for_other_contexts); | |
112 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); | |
113 EXPECT_TRUE(decoder_->WasContextLost()); | |
114 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason()); | |
115 } | |
116 | |
117 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderDrawOOMTest, ::testing::Bool()); | |
118 | |
119 class GLES2DecoderLostContextTest : public GLES2DecoderManualInitTest { | |
120 protected: | |
121 void Init(bool has_robustness) { | |
122 InitState init; | |
123 if (has_robustness) | |
124 init.extensions = "GL_ARB_robustness"; | |
125 InitDecoder(init); | |
126 } | |
127 | |
128 void InitWithVirtualContextsAndRobustness() { | |
129 base::CommandLine command_line(0, NULL); | |
130 command_line.AppendSwitchASCII( | |
131 switches::kGpuDriverBugWorkarounds, | |
132 base::IntToString(USE_VIRTUALIZED_GL_CONTEXTS)); | |
133 InitState init; | |
134 init.extensions = "GL_ARB_robustness"; | |
135 InitDecoderWithCommandLine(init, &command_line); | |
136 } | |
137 | |
138 void DoGetErrorWithContextLost(GLenum reset_status) { | |
139 DCHECK(context_->HasExtension("GL_ARB_robustness")); | |
140 EXPECT_CALL(*gl_, GetError()) | |
141 .WillOnce(Return(GL_CONTEXT_LOST_KHR)) | |
Ken Russell (switch to Gerrit)
2015/04/24 02:39:41
As you discovered and pointed out offline, the CON
no sievers
2015/04/24 18:52:47
Good point, the test looks a bit wrong that way. I
| |
142 .RetiresOnSaturation(); | |
143 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()) | |
144 .WillOnce(Return(reset_status)); | |
145 cmds::GetError cmd; | |
146 cmd.Init(shared_memory_id_, shared_memory_offset_); | |
147 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd)); | |
148 EXPECT_EQ(static_cast<GLuint>(GL_NO_ERROR), *GetSharedMemoryAs<GLenum*>()); | |
149 } | |
150 | |
151 void ClearCurrentDecoderError() { | |
152 DCHECK(decoder_->WasContextLost()); | |
153 EXPECT_CALL(*gl_, GetError()) | |
154 .WillOnce(Return(GL_CONTEXT_LOST_KHR)) | |
155 .RetiresOnSaturation(); | |
156 cmds::GetError cmd; | |
157 cmd.Init(shared_memory_id_, shared_memory_offset_); | |
158 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd)); | |
159 } | |
160 }; | |
161 | |
162 TEST_P(GLES2DecoderLostContextTest, LostFromMakeCurrent) { | |
163 Init(false); // without robustness | |
164 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(false)); | |
165 decoder_->MakeCurrent(); | |
166 EXPECT_TRUE(decoder_->WasContextLost()); | |
167 EXPECT_EQ(error::kMakeCurrentFailed, decoder_->GetContextLostReason()); | |
168 | |
169 // We didn't process commands, so we need to clear the decoder error, | |
170 // so that we can shut down cleanly. | |
171 ClearCurrentDecoderError(); | |
172 } | |
173 | |
174 TEST_P(GLES2DecoderLostContextTest, LostFromMakeCurrentWithRobustness) { | |
175 Init(true); // with robustness | |
176 // If we can't make the context current, we cannot query the robustness | |
177 // extension. | |
178 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()).Times(0); | |
179 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(false)); | |
180 decoder_->MakeCurrent(); | |
181 EXPECT_TRUE(decoder_->WasContextLost()); | |
182 EXPECT_FALSE(decoder_->WasContextLostByRobustnessExtension()); | |
183 EXPECT_EQ(error::kMakeCurrentFailed, decoder_->GetContextLostReason()); | |
184 | |
185 // We didn't process commands, so we need to clear the decoder error, | |
186 // so that we can shut down cleanly. | |
187 ClearCurrentDecoderError(); | |
188 } | |
189 | |
190 TEST_P(GLES2DecoderLostContextTest, LostFromResetAfterMakeCurrent) { | |
191 Init(true); // with robustness | |
192 InSequence seq; | |
193 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(true)); | |
194 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()) | |
195 .WillOnce(Return(GL_GUILTY_CONTEXT_RESET_ARB)); | |
196 decoder_->MakeCurrent(); | |
197 EXPECT_TRUE(decoder_->WasContextLost()); | |
198 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension()); | |
199 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason()); | |
200 | |
201 // We didn't process commands, so we need to clear the decoder error, | |
202 // so that we can shut down cleanly. | |
203 ClearCurrentDecoderError(); | |
204 } | |
205 | |
206 TEST_P(GLES2DecoderLostContextTest, LoseGuiltyFromGLError) { | |
207 Init(true); | |
208 // Always expect other contexts to be signaled as 'kUnknown' since we can't | |
209 // query their status without making them current. | |
210 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)) | |
211 .Times(1); | |
212 DoGetErrorWithContextLost(GL_GUILTY_CONTEXT_RESET_ARB); | |
213 EXPECT_TRUE(decoder_->WasContextLost()); | |
214 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension()); | |
215 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason()); | |
216 } | |
217 | |
218 TEST_P(GLES2DecoderLostContextTest, LoseInnocentFromGLError) { | |
219 Init(true); | |
220 // Always expect other contexts to be signaled as 'kUnknown' since we can't | |
221 // query their status without making them current. | |
222 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)) | |
223 .Times(1); | |
224 DoGetErrorWithContextLost(GL_INNOCENT_CONTEXT_RESET_ARB); | |
225 EXPECT_TRUE(decoder_->WasContextLost()); | |
226 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension()); | |
227 EXPECT_EQ(error::kInnocent, decoder_->GetContextLostReason()); | |
228 } | |
229 | |
230 TEST_P(GLES2DecoderLostContextTest, LoseVirtualContextWithRobustness) { | |
231 InitWithVirtualContextsAndRobustness(); | |
232 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)) | |
233 .Times(1); | |
234 // Signal guilty.... | |
235 DoGetErrorWithContextLost(GL_GUILTY_CONTEXT_RESET_ARB); | |
236 EXPECT_TRUE(decoder_->WasContextLost()); | |
237 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension()); | |
238 // ...but make sure we don't pretend, since for virtual contexts we don't | |
239 // know if this was really the guilty client. | |
240 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason()); | |
241 } | |
242 | |
243 TEST_P(GLES2DecoderLostContextTest, LoseGroupFromRobustness) { | |
244 // If one context in a group is lost through robustness, | |
245 // the other ones should also get lost and query the reset status. | |
246 Init(true); | |
247 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)) | |
248 .Times(1); | |
249 // There should be no GL calls, since we might not have a current context. | |
250 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()).Times(0); | |
251 LoseContexts(error::kUnknown); | |
252 EXPECT_TRUE(decoder_->WasContextLost()); | |
253 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason()); | |
254 | |
255 // We didn't process commands, so we need to clear the decoder error, | |
256 // so that we can shut down cleanly. | |
257 ClearCurrentDecoderError(); | |
258 } | |
259 | |
260 INSTANTIATE_TEST_CASE_P(Service, | |
261 GLES2DecoderLostContextTest, | |
262 ::testing::Bool()); | |
263 | |
264 } // namespace gles2 | |
265 } // namespace gpu | |
OLD | NEW |