OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 unit tests for gles2 commmands | 5 // This file contains unit tests for gles2 commmands |
6 | 6 |
7 #include <limits> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/synchronization/waitable_event.h" | |
11 #include "base/threading/thread.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 8 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
14 | 9 |
15 namespace gpu { | 10 namespace gpu { |
16 namespace gles2 { | 11 namespace gles2 { |
17 | 12 |
18 class GLES2FormatTest : public testing::Test { | 13 class GLES2FormatTest : public testing::Test { |
19 protected: | 14 protected: |
20 static const unsigned char kInitialValue = 0xBD; | 15 static const unsigned char kInitialValue = 0xBD; |
21 | 16 |
(...skipping 22 matching lines...) Expand all Loading... |
44 | 39 |
45 void CheckBytesWrittenMatchesExpectedSize( | 40 void CheckBytesWrittenMatchesExpectedSize( |
46 const void* end, size_t expected_size) { | 41 const void* end, size_t expected_size) { |
47 CheckBytesWritten(end, expected_size, expected_size); | 42 CheckBytesWritten(end, expected_size, expected_size); |
48 } | 43 } |
49 | 44 |
50 private: | 45 private: |
51 unsigned char buffer_[1024]; | 46 unsigned char buffer_[1024]; |
52 }; | 47 }; |
53 | 48 |
54 void SignalCompletion(uint32* assigned_async_token_ptr, | |
55 uint32 async_token, | |
56 AsyncUploadSync* sync) { | |
57 EXPECT_EQ(async_token, *assigned_async_token_ptr); | |
58 sync->SetAsyncUploadToken(async_token); | |
59 } | |
60 | |
61 TEST(GLES2FormatAsyncUploadSyncTest, AsyncUploadSync) { | |
62 const size_t kSize = 10; | |
63 const size_t kCount = 1000; | |
64 | |
65 base::Thread thread("GLES2FormatUploadSyncTest - Fake Upload Thread"); | |
66 thread.Start(); | |
67 | |
68 // Run the same test 50 times so we retest the wrap as well. | |
69 for (size_t test_run = 0; test_run < 50; ++test_run) { | |
70 AsyncUploadSync sync; | |
71 sync.Reset(); | |
72 | |
73 uint32 buffer_tokens[kSize]; | |
74 memset(buffer_tokens, 0, sizeof(buffer_tokens)); | |
75 | |
76 // Start with a token large enough so that we'll wrap. | |
77 uint32 async_token = std::numeric_limits<uint32>::max() - kCount / 2; | |
78 | |
79 // Set initial async token. | |
80 sync.SetAsyncUploadToken(async_token); | |
81 | |
82 for (size_t i = 0; i < kCount; ++i) { | |
83 size_t buffer = i % kSize; | |
84 | |
85 // Loop until previous async token has passed if any was set. | |
86 while (buffer_tokens[buffer] && | |
87 !sync.HasAsyncUploadTokenPassed(buffer_tokens[buffer])) | |
88 base::PlatformThread::YieldCurrentThread(); | |
89 | |
90 // Next token, skip 0. | |
91 async_token++; | |
92 if (async_token == 0) | |
93 async_token++; | |
94 | |
95 // Set the buffer's associated token. | |
96 buffer_tokens[buffer] = async_token; | |
97 | |
98 // Set the async upload token on the fake upload thread and assert that | |
99 // the associated buffer still has the given token. | |
100 thread.message_loop()->PostTask(FROM_HERE, | |
101 base::Bind(&SignalCompletion, | |
102 &buffer_tokens[buffer], | |
103 async_token, | |
104 &sync)); | |
105 } | |
106 | |
107 // Flush the thread message loop before starting again. | |
108 base::WaitableEvent waitable(false, false); | |
109 thread.message_loop()->PostTask(FROM_HERE, | |
110 base::Bind(&base::WaitableEvent::Signal, | |
111 base::Unretained(&waitable))); | |
112 waitable.Wait(); | |
113 } | |
114 } | |
115 | |
116 // GCC requires these declarations, but MSVC requires they not be present | 49 // GCC requires these declarations, but MSVC requires they not be present |
117 #ifndef _MSC_VER | 50 #ifndef _MSC_VER |
118 const unsigned char GLES2FormatTest::kInitialValue; | 51 const unsigned char GLES2FormatTest::kInitialValue; |
119 #endif | 52 #endif |
120 | 53 |
121 #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h" | 54 #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h" |
122 | 55 |
123 } // namespace gles2 | 56 } // namespace gles2 |
124 } // namespace gpu | 57 } // namespace gpu |
125 | 58 |
OLD | NEW |