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 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/process_util.h" | 6 #include "base/process_util.h" |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
8 #include "base/system_monitor/system_monitor.h" | 8 #include "base/system_monitor/system_monitor.h" |
9 #include "content/browser/gamepad/gamepad_provider.h" | 9 #include "content/browser/gamepad/gamepad_provider.h" |
10 #include "content/common/gamepad_messages.h" | 10 #include "content/common/gamepad_messages.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 }; | 57 }; |
58 | 58 |
59 TEST_F(GamepadProviderTest, BasicStartStop) { | 59 TEST_F(GamepadProviderTest, BasicStartStop) { |
60 gamepad::Provider* provider = CreateProvider(); | 60 gamepad::Provider* provider = CreateProvider(); |
61 provider->Start(); | 61 provider->Start(); |
62 provider->Stop(); | 62 provider->Stop(); |
63 // Just ensure that there's no asserts on startup, shutdown, or destroy. | 63 // Just ensure that there's no asserts on startup, shutdown, or destroy. |
64 } | 64 } |
65 | 65 |
66 // http://crbug.com/105348 | 66 // http://crbug.com/105348 |
67 TEST_F(GamepadProviderTest, FLAKY_PollingAccess) { | 67 TEST_F(GamepadProviderTest, PollingAccess) { |
68 using namespace gamepad; | 68 using namespace gamepad; |
69 | 69 |
70 Provider* provider = CreateProvider(); | 70 Provider* provider = CreateProvider(); |
71 provider->Start(); | 71 provider->Start(); |
72 | 72 |
73 WebKit::WebGamepads test_data; | 73 WebKit::WebGamepads test_data; |
74 test_data.length = 1; | 74 test_data.length = 1; |
75 test_data.items[0].connected = true; | 75 test_data.items[0].connected = true; |
76 test_data.items[0].timestamp = 0; | 76 test_data.items[0].timestamp = 0; |
77 test_data.items[0].buttonsLength = 1; | 77 test_data.items[0].buttonsLength = 1; |
(...skipping 10 matching lines...) Expand all Loading... |
88 // Renderer-side, pull data out of poll buffer. | 88 // Renderer-side, pull data out of poll buffer. |
89 base::SharedMemoryHandle handle = | 89 base::SharedMemoryHandle handle = |
90 provider->GetRendererSharedMemoryHandle(base::GetCurrentProcessHandle()); | 90 provider->GetRendererSharedMemoryHandle(base::GetCurrentProcessHandle()); |
91 scoped_ptr<base::SharedMemory> shared_memory( | 91 scoped_ptr<base::SharedMemory> shared_memory( |
92 new base::SharedMemory(handle, true)); | 92 new base::SharedMemory(handle, true)); |
93 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); | 93 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); |
94 void* mem = shared_memory->memory(); | 94 void* mem = shared_memory->memory(); |
95 | 95 |
96 GamepadHardwareBuffer* hwbuf = static_cast<GamepadHardwareBuffer*>(mem); | 96 GamepadHardwareBuffer* hwbuf = static_cast<GamepadHardwareBuffer*>(mem); |
97 // See gamepad_hardware_buffer.h for details on the read discipline. | 97 // See gamepad_hardware_buffer.h for details on the read discipline. |
98 base::subtle::Atomic32 start, end; | |
99 WebKit::WebGamepads output; | 98 WebKit::WebGamepads output; |
100 int contention_count; | |
101 | 99 |
102 // Here we're attempting to test the read discipline during contention. If | 100 base::subtle::Atomic32 version; |
103 // we fail to read this many times, then the read thread is starving, and we | 101 do { |
104 // should fail the test. | 102 version = hwbuf->sequence.ReadBegin(); |
105 for (contention_count = 0; contention_count < 1000; ++contention_count) { | |
106 end = base::subtle::Acquire_Load(&hwbuf->end_marker); | |
107 memcpy(&output, &hwbuf->buffer, sizeof(output)); | 103 memcpy(&output, &hwbuf->buffer, sizeof(output)); |
108 start = base::subtle::Acquire_Load(&hwbuf->start_marker); | 104 } while (hwbuf->sequence.ReadRetry(version)); |
109 if (start == end) | 105 |
110 break; | |
111 base::PlatformThread::YieldCurrentThread(); | |
112 } | |
113 EXPECT_GT(1000, contention_count); | |
114 EXPECT_EQ(1u, output.length); | 106 EXPECT_EQ(1u, output.length); |
115 EXPECT_EQ(1u, output.items[0].buttonsLength); | 107 EXPECT_EQ(1u, output.items[0].buttonsLength); |
116 EXPECT_EQ(1.f, output.items[0].buttons[0]); | 108 EXPECT_EQ(1.f, output.items[0].buttons[0]); |
117 EXPECT_EQ(2u, output.items[0].axesLength); | 109 EXPECT_EQ(2u, output.items[0].axesLength); |
118 EXPECT_EQ(-1.f, output.items[0].axes[0]); | 110 EXPECT_EQ(-1.f, output.items[0].axes[0]); |
119 EXPECT_EQ(0.5f, output.items[0].axes[1]); | 111 EXPECT_EQ(0.5f, output.items[0].axes[1]); |
120 | 112 |
121 provider->Stop(); | 113 provider->Stop(); |
122 } | 114 } |
123 | 115 |
124 } // namespace | 116 } // namespace |
OLD | NEW |