Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / gpu / command_buffer / service / memory_program_cache_unittest.cc
blob795b0afc072fc33c3dc728ebc041f3e90eb1dd3b
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
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/memory_program_cache.h"
7 #include "base/bind.h"
8 #include "gpu/command_buffer/common/gles2_cmd_format.h"
9 #include "gpu/command_buffer/service/gl_utils.h"
10 #include "gpu/command_buffer/service/gpu_service_test.h"
11 #include "gpu/command_buffer/service/shader_manager.h"
12 #include "gpu/command_buffer/service/shader_translator.h"
13 #include "gpu/command_buffer/service/test_helper.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gl/gl_bindings.h"
16 #include "ui/gl/gl_mock.h"
18 using ::testing::_;
19 using ::testing::Invoke;
20 using ::testing::SetArgPointee;
22 namespace gpu {
23 namespace gles2 {
25 class ProgramBinaryEmulator {
26 public:
27 ProgramBinaryEmulator(GLsizei length,
28 GLenum format,
29 const char* binary)
30 : length_(length),
31 format_(format),
32 binary_(binary) { }
34 void GetProgramBinary(GLuint program,
35 GLsizei buffer_size,
36 GLsizei* length,
37 GLenum* format,
38 GLvoid* binary) {
39 if (length) {
40 *length = length_;
42 *format = format_;
43 memcpy(binary, binary_, length_);
46 void ProgramBinary(GLuint program,
47 GLenum format,
48 const GLvoid* binary,
49 GLsizei length) {
50 // format and length are verified by matcher
51 EXPECT_EQ(0, memcmp(binary_, binary, length));
54 GLsizei length() const { return length_; }
55 GLenum format() const { return format_; }
56 const char* binary() const { return binary_; }
58 private:
59 GLsizei length_;
60 GLenum format_;
61 const char* binary_;
64 class MemoryProgramCacheTest : public GpuServiceTest {
65 public:
66 static const size_t kCacheSizeBytes = 1024;
67 static const GLuint kVertexShaderClientId = 90;
68 static const GLuint kVertexShaderServiceId = 100;
69 static const GLuint kFragmentShaderClientId = 91;
70 static const GLuint kFragmentShaderServiceId = 100;
72 MemoryProgramCacheTest()
73 : cache_(new MemoryProgramCache(kCacheSizeBytes)),
74 vertex_shader_(NULL),
75 fragment_shader_(NULL),
76 shader_cache_count_(0) { }
77 ~MemoryProgramCacheTest() override { shader_manager_.Destroy(false); }
79 void ShaderCacheCb(const std::string& key, const std::string& shader) {
80 shader_cache_count_++;
81 shader_cache_shader_ = shader;
84 int32 shader_cache_count() { return shader_cache_count_; }
85 const std::string& shader_cache_shader() { return shader_cache_shader_; }
87 protected:
88 void SetUp() override {
89 GpuServiceTest::SetUpWithGLVersion("3.0", "GL_ARB_get_program_binary");
91 vertex_shader_ = shader_manager_.CreateShader(kVertexShaderClientId,
92 kVertexShaderServiceId,
93 GL_VERTEX_SHADER);
94 fragment_shader_ = shader_manager_.CreateShader(
95 kFragmentShaderClientId,
96 kFragmentShaderServiceId,
97 GL_FRAGMENT_SHADER);
98 ASSERT_TRUE(vertex_shader_ != NULL);
99 ASSERT_TRUE(fragment_shader_ != NULL);
100 AttributeMap vertex_attrib_map;
101 UniformMap vertex_uniform_map;
102 VaryingMap vertex_varying_map;
103 AttributeMap fragment_attrib_map;
104 UniformMap fragment_uniform_map;
105 VaryingMap fragment_varying_map;
107 vertex_attrib_map["a"] = TestHelper::ConstructAttribute(
108 GL_FLOAT_VEC2, 34, GL_LOW_FLOAT, false, "a");
109 vertex_uniform_map["a"] = TestHelper::ConstructUniform(
110 GL_FLOAT, 10, GL_MEDIUM_FLOAT, true, "a");
111 vertex_uniform_map["b"] = TestHelper::ConstructUniform(
112 GL_FLOAT_VEC3, 3114, GL_HIGH_FLOAT, true, "b");
113 vertex_varying_map["c"] = TestHelper::ConstructVarying(
114 GL_FLOAT_VEC4, 2, GL_HIGH_FLOAT, true, "c");
115 fragment_attrib_map["jjjbb"] = TestHelper::ConstructAttribute(
116 GL_FLOAT_MAT4, 1114, GL_MEDIUM_FLOAT, false, "jjjbb");
117 fragment_uniform_map["k"] = TestHelper::ConstructUniform(
118 GL_FLOAT_MAT2, 34413, GL_MEDIUM_FLOAT, true, "k");
119 fragment_varying_map["c"] = TestHelper::ConstructVarying(
120 GL_FLOAT_VEC4, 2, GL_HIGH_FLOAT, true, "c");
122 vertex_shader_->set_source("bbbalsldkdkdkd");
123 fragment_shader_->set_source("bbbal sldkdkdkas 134 ad");
125 TestHelper::SetShaderStates(
126 gl_.get(), vertex_shader_, true, NULL, NULL,
127 &vertex_attrib_map, &vertex_uniform_map, &vertex_varying_map,
128 NULL);
129 TestHelper::SetShaderStates(
130 gl_.get(), fragment_shader_, true, NULL, NULL,
131 &fragment_attrib_map, &fragment_uniform_map, &fragment_varying_map,
132 NULL);
135 void SetExpectationsForSaveLinkedProgram(
136 const GLint program_id,
137 ProgramBinaryEmulator* emulator) const {
138 EXPECT_CALL(*gl_.get(),
139 GetProgramiv(program_id, GL_PROGRAM_BINARY_LENGTH_OES, _))
140 .WillOnce(SetArgPointee<2>(emulator->length()));
141 EXPECT_CALL(*gl_.get(),
142 GetProgramBinary(program_id, emulator->length(), _, _, _))
143 .WillOnce(Invoke(emulator, &ProgramBinaryEmulator::GetProgramBinary));
146 void SetExpectationsForLoadLinkedProgram(
147 const GLint program_id,
148 ProgramBinaryEmulator* emulator) const {
149 EXPECT_CALL(*gl_.get(),
150 ProgramBinary(program_id,
151 emulator->format(),
153 emulator->length()))
154 .WillOnce(Invoke(emulator, &ProgramBinaryEmulator::ProgramBinary));
155 EXPECT_CALL(*gl_.get(),
156 GetProgramiv(program_id, GL_LINK_STATUS, _))
157 .WillOnce(SetArgPointee<2>(GL_TRUE));
160 void SetExpectationsForLoadLinkedProgramFailure(
161 const GLint program_id,
162 ProgramBinaryEmulator* emulator) const {
163 EXPECT_CALL(*gl_.get(),
164 ProgramBinary(program_id,
165 emulator->format(),
167 emulator->length()))
168 .WillOnce(Invoke(emulator, &ProgramBinaryEmulator::ProgramBinary));
169 EXPECT_CALL(*gl_.get(),
170 GetProgramiv(program_id, GL_LINK_STATUS, _))
171 .WillOnce(SetArgPointee<2>(GL_FALSE));
174 scoped_ptr<MemoryProgramCache> cache_;
175 ShaderManager shader_manager_;
176 Shader* vertex_shader_;
177 Shader* fragment_shader_;
178 int32 shader_cache_count_;
179 std::string shader_cache_shader_;
182 TEST_F(MemoryProgramCacheTest, CacheSave) {
183 const GLenum kFormat = 1;
184 const int kProgramId = 10;
185 const int kBinaryLength = 20;
186 char test_binary[kBinaryLength];
187 for (int i = 0; i < kBinaryLength; ++i) {
188 test_binary[i] = i;
190 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
192 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
193 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
194 fragment_shader_, NULL,
195 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
196 base::Unretained(this)));
198 EXPECT_EQ(ProgramCache::LINK_SUCCEEDED, cache_->GetLinkedProgramStatus(
199 vertex_shader_->last_compiled_signature(),
200 fragment_shader_->last_compiled_signature(),
201 NULL));
202 EXPECT_EQ(1, shader_cache_count());
205 TEST_F(MemoryProgramCacheTest, LoadProgram) {
206 const GLenum kFormat = 1;
207 const int kProgramId = 10;
208 const int kBinaryLength = 20;
209 char test_binary[kBinaryLength];
210 for (int i = 0; i < kBinaryLength; ++i) {
211 test_binary[i] = i;
213 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
215 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
216 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
217 fragment_shader_, NULL,
218 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
219 base::Unretained(this)));
221 EXPECT_EQ(ProgramCache::LINK_SUCCEEDED, cache_->GetLinkedProgramStatus(
222 vertex_shader_->last_compiled_signature(),
223 fragment_shader_->last_compiled_signature(),
224 NULL));
225 EXPECT_EQ(1, shader_cache_count());
227 cache_->Clear();
229 cache_->LoadProgram(shader_cache_shader());
230 EXPECT_EQ(ProgramCache::LINK_SUCCEEDED, cache_->GetLinkedProgramStatus(
231 vertex_shader_->last_compiled_signature(),
232 fragment_shader_->last_compiled_signature(),
233 NULL));
236 TEST_F(MemoryProgramCacheTest, CacheLoadMatchesSave) {
237 const GLenum kFormat = 1;
238 const int kProgramId = 10;
239 const int kBinaryLength = 20;
240 char test_binary[kBinaryLength];
241 for (int i = 0; i < kBinaryLength; ++i) {
242 test_binary[i] = i;
244 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
246 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
247 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
248 fragment_shader_, NULL,
249 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
250 base::Unretained(this)));
251 EXPECT_EQ(1, shader_cache_count());
253 AttributeMap vertex_attrib_map = vertex_shader_->attrib_map();
254 UniformMap vertex_uniform_map = vertex_shader_->uniform_map();
255 VaryingMap vertex_varying_map = vertex_shader_->varying_map();
256 AttributeMap fragment_attrib_map = fragment_shader_->attrib_map();
257 UniformMap fragment_uniform_map = fragment_shader_->uniform_map();
258 VaryingMap fragment_varying_map = fragment_shader_->varying_map();
260 vertex_shader_->set_attrib_map(AttributeMap());
261 vertex_shader_->set_uniform_map(UniformMap());
262 vertex_shader_->set_varying_map(VaryingMap());
263 fragment_shader_->set_attrib_map(AttributeMap());
264 fragment_shader_->set_uniform_map(UniformMap());
265 fragment_shader_->set_varying_map(VaryingMap());
267 SetExpectationsForLoadLinkedProgram(kProgramId, &emulator);
269 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_SUCCESS, cache_->LoadLinkedProgram(
270 kProgramId,
271 vertex_shader_,
272 fragment_shader_,
273 NULL,
274 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
275 base::Unretained(this))));
277 // apparently the hash_map implementation on android doesn't have the
278 // equality operator
279 #if !defined(OS_ANDROID)
280 EXPECT_EQ(vertex_attrib_map, vertex_shader_->attrib_map());
281 EXPECT_EQ(vertex_uniform_map, vertex_shader_->uniform_map());
282 EXPECT_EQ(vertex_varying_map, vertex_shader_->varying_map());
283 EXPECT_EQ(fragment_attrib_map, fragment_shader_->attrib_map());
284 EXPECT_EQ(fragment_uniform_map, fragment_shader_->uniform_map());
285 EXPECT_EQ(fragment_varying_map, fragment_shader_->varying_map());
286 #endif
289 TEST_F(MemoryProgramCacheTest, LoadProgramMatchesSave) {
290 const GLenum kFormat = 1;
291 const int kProgramId = 10;
292 const int kBinaryLength = 20;
293 char test_binary[kBinaryLength];
294 for (int i = 0; i < kBinaryLength; ++i) {
295 test_binary[i] = i;
297 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
299 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
300 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
301 fragment_shader_, NULL,
302 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
303 base::Unretained(this)));
304 EXPECT_EQ(1, shader_cache_count());
306 AttributeMap vertex_attrib_map = vertex_shader_->attrib_map();
307 UniformMap vertex_uniform_map = vertex_shader_->uniform_map();
308 VaryingMap vertex_varying_map = vertex_shader_->varying_map();
309 AttributeMap fragment_attrib_map = fragment_shader_->attrib_map();
310 UniformMap fragment_uniform_map = fragment_shader_->uniform_map();
311 VaryingMap fragment_varying_map = fragment_shader_->varying_map();
313 vertex_shader_->set_attrib_map(AttributeMap());
314 vertex_shader_->set_uniform_map(UniformMap());
315 vertex_shader_->set_varying_map(VaryingMap());
316 fragment_shader_->set_attrib_map(AttributeMap());
317 fragment_shader_->set_uniform_map(UniformMap());
318 fragment_shader_->set_varying_map(VaryingMap());
320 SetExpectationsForLoadLinkedProgram(kProgramId, &emulator);
322 cache_->Clear();
323 cache_->LoadProgram(shader_cache_shader());
325 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_SUCCESS, cache_->LoadLinkedProgram(
326 kProgramId,
327 vertex_shader_,
328 fragment_shader_,
329 NULL,
330 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
331 base::Unretained(this))));
333 // apparently the hash_map implementation on android doesn't have the
334 // equality operator
335 #if !defined(OS_ANDROID)
336 EXPECT_EQ(vertex_attrib_map, vertex_shader_->attrib_map());
337 EXPECT_EQ(vertex_uniform_map, vertex_shader_->uniform_map());
338 EXPECT_EQ(vertex_varying_map, vertex_shader_->varying_map());
339 EXPECT_EQ(fragment_attrib_map, fragment_shader_->attrib_map());
340 EXPECT_EQ(fragment_uniform_map, fragment_shader_->uniform_map());
341 EXPECT_EQ(fragment_varying_map, fragment_shader_->varying_map());
342 #endif
345 TEST_F(MemoryProgramCacheTest, LoadFailOnLinkFalse) {
346 const GLenum kFormat = 1;
347 const int kProgramId = 10;
348 const int kBinaryLength = 20;
349 char test_binary[kBinaryLength];
350 for (int i = 0; i < kBinaryLength; ++i) {
351 test_binary[i] = i;
353 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
355 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
356 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
357 fragment_shader_, NULL,
358 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
359 base::Unretained(this)));
361 SetExpectationsForLoadLinkedProgramFailure(kProgramId, &emulator);
362 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_FAILURE, cache_->LoadLinkedProgram(
363 kProgramId,
364 vertex_shader_,
365 fragment_shader_,
366 NULL,
367 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
368 base::Unretained(this))));
371 TEST_F(MemoryProgramCacheTest, LoadFailOnDifferentSource) {
372 const GLenum kFormat = 1;
373 const int kProgramId = 10;
374 const int kBinaryLength = 20;
375 char test_binary[kBinaryLength];
376 for (int i = 0; i < kBinaryLength; ++i) {
377 test_binary[i] = i;
379 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
381 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
382 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
383 fragment_shader_, NULL,
384 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
385 base::Unretained(this)));
387 const std::string vertex_orig_source = vertex_shader_->last_compiled_source();
388 vertex_shader_->set_source("different!");
389 TestHelper::SetShaderStates(gl_.get(), vertex_shader_, true);
390 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_FAILURE, cache_->LoadLinkedProgram(
391 kProgramId,
392 vertex_shader_,
393 fragment_shader_,
394 NULL,
395 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
396 base::Unretained(this))));
398 vertex_shader_->set_source(vertex_orig_source);
399 TestHelper::SetShaderStates(gl_.get(), vertex_shader_, true);
400 fragment_shader_->set_source("different!");
401 TestHelper::SetShaderStates(gl_.get(), fragment_shader_, true);
402 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_FAILURE, cache_->LoadLinkedProgram(
403 kProgramId,
404 vertex_shader_,
405 fragment_shader_,
406 NULL,
407 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
408 base::Unretained(this))));
411 TEST_F(MemoryProgramCacheTest, LoadFailOnDifferentMap) {
412 const GLenum kFormat = 1;
413 const int kProgramId = 10;
414 const int kBinaryLength = 20;
415 char test_binary[kBinaryLength];
416 for (int i = 0; i < kBinaryLength; ++i) {
417 test_binary[i] = i;
419 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
421 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
422 ProgramCache::LocationMap binding_map;
423 binding_map["test"] = 512;
424 cache_->SaveLinkedProgram(kProgramId,
425 vertex_shader_,
426 fragment_shader_,
427 &binding_map,
428 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
429 base::Unretained(this)));
431 binding_map["different!"] = 59;
432 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_FAILURE, cache_->LoadLinkedProgram(
433 kProgramId,
434 vertex_shader_,
435 fragment_shader_,
436 &binding_map,
437 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
438 base::Unretained(this))));
439 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_FAILURE, cache_->LoadLinkedProgram(
440 kProgramId,
441 vertex_shader_,
442 fragment_shader_,
443 NULL,
444 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
445 base::Unretained(this))));
448 TEST_F(MemoryProgramCacheTest, MemoryProgramCacheEviction) {
449 const GLenum kFormat = 1;
450 const int kProgramId = 10;
451 const int kBinaryLength = 20;
452 char test_binary[kBinaryLength];
453 for (int i = 0; i < kBinaryLength; ++i) {
454 test_binary[i] = i;
456 ProgramBinaryEmulator emulator1(kBinaryLength, kFormat, test_binary);
459 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator1);
460 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
461 fragment_shader_, NULL,
462 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
463 base::Unretained(this)));
465 const int kEvictingProgramId = 11;
466 const GLuint kEvictingBinaryLength = kCacheSizeBytes - kBinaryLength + 1;
468 // save old source and modify for new program
469 const std::string& old_sig = fragment_shader_->last_compiled_signature();
470 fragment_shader_->set_source("al sdfkjdk");
471 TestHelper::SetShaderStates(gl_.get(), fragment_shader_, true);
473 scoped_ptr<char[]> bigTestBinary =
474 scoped_ptr<char[]>(new char[kEvictingBinaryLength]);
475 for (size_t i = 0; i < kEvictingBinaryLength; ++i) {
476 bigTestBinary[i] = i % 250;
478 ProgramBinaryEmulator emulator2(kEvictingBinaryLength,
479 kFormat,
480 bigTestBinary.get());
482 SetExpectationsForSaveLinkedProgram(kEvictingProgramId, &emulator2);
483 cache_->SaveLinkedProgram(kEvictingProgramId,
484 vertex_shader_,
485 fragment_shader_,
486 NULL,
487 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
488 base::Unretained(this)));
490 EXPECT_EQ(ProgramCache::LINK_SUCCEEDED, cache_->GetLinkedProgramStatus(
491 vertex_shader_->last_compiled_signature(),
492 fragment_shader_->last_compiled_signature(),
493 NULL));
494 EXPECT_EQ(ProgramCache::LINK_UNKNOWN, cache_->GetLinkedProgramStatus(
495 old_sig,
496 fragment_shader_->last_compiled_signature(),
497 NULL));
500 TEST_F(MemoryProgramCacheTest, SaveCorrectProgram) {
501 const GLenum kFormat = 1;
502 const int kProgramId = 10;
503 const int kBinaryLength = 20;
504 char test_binary[kBinaryLength];
505 for (int i = 0; i < kBinaryLength; ++i) {
506 test_binary[i] = i;
508 ProgramBinaryEmulator emulator1(kBinaryLength, kFormat, test_binary);
510 vertex_shader_->set_source("different!");
511 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator1);
512 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
513 fragment_shader_, NULL,
514 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
515 base::Unretained(this)));
517 EXPECT_EQ(ProgramCache::LINK_SUCCEEDED, cache_->GetLinkedProgramStatus(
518 vertex_shader_->last_compiled_signature(),
519 fragment_shader_->last_compiled_signature(),
520 NULL));
523 TEST_F(MemoryProgramCacheTest, LoadCorrectProgram) {
524 const GLenum kFormat = 1;
525 const int kProgramId = 10;
526 const int kBinaryLength = 20;
527 char test_binary[kBinaryLength];
528 for (int i = 0; i < kBinaryLength; ++i) {
529 test_binary[i] = i;
531 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
533 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
534 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
535 fragment_shader_, NULL,
536 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
537 base::Unretained(this)));
539 EXPECT_EQ(ProgramCache::LINK_SUCCEEDED, cache_->GetLinkedProgramStatus(
540 vertex_shader_->last_compiled_signature(),
541 fragment_shader_->last_compiled_signature(),
542 NULL));
544 SetExpectationsForLoadLinkedProgram(kProgramId, &emulator);
546 fragment_shader_->set_source("different!");
547 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_SUCCESS, cache_->LoadLinkedProgram(
548 kProgramId,
549 vertex_shader_,
550 fragment_shader_,
551 NULL,
552 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
553 base::Unretained(this))));
556 TEST_F(MemoryProgramCacheTest, OverwriteOnNewSave) {
557 const GLenum kFormat = 1;
558 const int kProgramId = 10;
559 const int kBinaryLength = 20;
560 char test_binary[kBinaryLength];
561 for (int i = 0; i < kBinaryLength; ++i) {
562 test_binary[i] = i;
564 ProgramBinaryEmulator emulator(kBinaryLength, kFormat, test_binary);
566 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator);
567 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
568 fragment_shader_, NULL,
569 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
570 base::Unretained(this)));
573 char test_binary2[kBinaryLength];
574 for (int i = 0; i < kBinaryLength; ++i) {
575 test_binary2[i] = (i*2) % 250;
577 ProgramBinaryEmulator emulator2(kBinaryLength, kFormat, test_binary2);
578 SetExpectationsForSaveLinkedProgram(kProgramId, &emulator2);
579 cache_->SaveLinkedProgram(kProgramId, vertex_shader_,
580 fragment_shader_, NULL,
581 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
582 base::Unretained(this)));
584 SetExpectationsForLoadLinkedProgram(kProgramId, &emulator2);
585 EXPECT_EQ(ProgramCache::PROGRAM_LOAD_SUCCESS, cache_->LoadLinkedProgram(
586 kProgramId,
587 vertex_shader_,
588 fragment_shader_,
589 NULL,
590 base::Bind(&MemoryProgramCacheTest::ShaderCacheCb,
591 base::Unretained(this))));
594 } // namespace gles2
595 } // namespace gpu