[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / gpu / command_buffer / common / gles2_cmd_format_test.cc
blobd11b2c5d1340f36f59858cb0b3a5eaa918d10117
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
3 // found in the LICENSE file.
5 // This file contains unit tests for gles2 commmands
7 #include <limits>
9 #include "base/bind.h"
10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h"
14 #include "gpu/command_buffer/common/gles2_cmd_format.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace gpu {
18 namespace gles2 {
20 class GLES2FormatTest : public testing::Test {
21 protected:
22 static const unsigned char kInitialValue = 0xBD;
24 void SetUp() override { memset(buffer_, kInitialValue, sizeof(buffer_)); }
26 void TearDown() override {}
28 template <typename T>
29 T* GetBufferAs() {
30 return static_cast<T*>(static_cast<void*>(&buffer_));
33 void CheckBytesWritten(
34 const void* end, size_t expected_size, size_t written_size) {
35 size_t actual_size = static_cast<const unsigned char*>(end) -
36 GetBufferAs<const unsigned char>();
37 EXPECT_LT(actual_size, sizeof(buffer_));
38 EXPECT_GT(actual_size, 0u);
39 EXPECT_EQ(expected_size, actual_size);
40 EXPECT_EQ(kInitialValue, buffer_[written_size]);
41 EXPECT_NE(kInitialValue, buffer_[written_size - 1]);
44 void CheckBytesWrittenMatchesExpectedSize(
45 const void* end, size_t expected_size) {
46 CheckBytesWritten(end, expected_size, expected_size);
49 private:
50 unsigned char buffer_[1024];
53 void SignalCompletion(uint32* assigned_async_token_ptr,
54 uint32 async_token,
55 AsyncUploadSync* sync) {
56 EXPECT_EQ(async_token, *assigned_async_token_ptr);
57 sync->SetAsyncUploadToken(async_token);
60 TEST(GLES2FormatAsyncUploadSyncTest, AsyncUploadSync) {
61 const size_t kSize = 10;
62 const size_t kCount = 1000;
64 base::Thread thread("GLES2FormatUploadSyncTest - Fake Upload Thread");
65 thread.Start();
67 // Run the same test 50 times so we retest the wrap as well.
68 for (size_t test_run = 0; test_run < 50; ++test_run) {
69 AsyncUploadSync sync;
70 sync.Reset();
72 uint32 buffer_tokens[kSize];
73 memset(buffer_tokens, 0, sizeof(buffer_tokens));
75 // Start with a token large enough so that we'll wrap.
76 uint32 async_token = std::numeric_limits<uint32>::max() - kCount / 2;
78 // Set initial async token.
79 sync.SetAsyncUploadToken(async_token);
81 for (size_t i = 0; i < kCount; ++i) {
82 size_t buffer = i % kSize;
84 // Loop until previous async token has passed if any was set.
85 while (buffer_tokens[buffer] &&
86 !sync.HasAsyncUploadTokenPassed(buffer_tokens[buffer]))
87 base::PlatformThread::YieldCurrentThread();
89 // Next token, skip 0.
90 async_token++;
91 if (async_token == 0)
92 async_token++;
94 // Set the buffer's associated token.
95 buffer_tokens[buffer] = async_token;
97 // Set the async upload token on the fake upload thread and assert that
98 // the associated buffer still has the given token.
99 thread.task_runner()->PostTask(
100 FROM_HERE, base::Bind(&SignalCompletion, &buffer_tokens[buffer],
101 async_token, &sync));
104 // Flush the thread message loop before starting again.
105 base::WaitableEvent waitable(false, false);
106 thread.task_runner()->PostTask(
107 FROM_HERE,
108 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waitable)));
109 waitable.Wait();
113 // GCC requires these declarations, but MSVC requires they not be present
114 #ifndef _MSC_VER
115 const unsigned char GLES2FormatTest::kInitialValue;
116 #endif
118 #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h"
120 } // namespace gles2
121 } // namespace gpu