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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
12 #include "base/test/trace_event_analyzer.h" | |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/automation/automation_proxy.h" | |
15 #include "chrome/test/automation/tab_proxy.h" | 17 #include "chrome/test/automation/tab_proxy.h" |
16 #include "chrome/test/ui/javascript_test_util.h" | 18 #include "chrome/test/ui/javascript_test_util.h" |
17 #include "chrome/test/ui/ui_perf_test.h" | 19 #include "chrome/test/ui/ui_perf_test.h" |
18 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
21 #include "ui/gfx/gl/gl_implementation.h" | |
19 #include "ui/gfx/gl/gl_switches.h" | 22 #include "ui/gfx/gl/gl_switches.h" |
20 | 23 |
21 namespace { | 24 namespace { |
22 | 25 |
23 enum FrameRateTestFlags { | 26 enum FrameRateTestFlags { |
24 kRequiresGpu = 1 << 0, // only execute test if --enable-gpu | 27 kUseGpu = 1 << 0, // Only execute test if --enable-gpu, and verify |
25 kDisableGpu = 1 << 1, // run test without gpu acceleration | 28 // that test ran on GPU. This is required for |
26 kMakeBodyComposited = 1 << 2, // force the test to use the compositor | 29 // tests that run on GPU. |
27 kDisableVsync = 1 << 3, // do not lock animation on vertical refresh | 30 kForceGpuComposited = (1 << 1) | kUseGpu, // Force the test to use the |
28 kUseReferenceBuild = 1 << 4, // run test using the reference chrome build | 31 // compositor. |
29 kInternal = 1 << 5, // Test uses internal test data | 32 kDisableVsync = 1 << 2, // Do not limit framerate to vertical refresh. |
30 kHasRedirect = 1 << 6, // Test page contains an HTML redirect | 33 // when on GPU, nor to 60hz when not on GPU. |
34 kUseReferenceBuild = 1 << 3, // Run test using the reference chrome build. | |
35 kInternal = 1 << 4, // Test uses internal test data. | |
36 kHasRedirect = 1 << 5, // Test page contains an HTML redirect. | |
31 }; | 37 }; |
32 | 38 |
33 std::string GetSuffixForTestFlags(int flags) { | 39 std::string GetSuffixForTestFlags(int flags) { |
34 std::string suffix; | 40 std::string suffix; |
35 if (flags & kMakeBodyComposited) | 41 if (flags & kForceGpuComposited) |
36 suffix += "_comp"; | 42 suffix += "_comp"; |
43 if (flags & kUseGpu) | |
44 suffix += "_gpu"; | |
37 if (flags & kDisableVsync) | 45 if (flags & kDisableVsync) |
38 suffix += "_novsync"; | 46 suffix += "_novsync"; |
39 if (flags & kDisableGpu) | |
40 suffix += "_nogpu"; | |
41 if (flags & kUseReferenceBuild) | 47 if (flags & kUseReferenceBuild) |
42 suffix += "_ref"; | 48 suffix += "_ref"; |
43 return suffix; | 49 return suffix; |
44 } | 50 } |
45 | 51 |
46 class FrameRateTest | 52 class FrameRateTest |
47 : public UIPerfTest | 53 : public UIPerfTest |
48 , public ::testing::WithParamInterface<int> { | 54 , public ::testing::WithParamInterface<int> { |
49 public: | 55 public: |
50 FrameRateTest() { | 56 FrameRateTest() { |
51 show_window_ = true; | 57 show_window_ = true; |
52 dom_automation_enabled_ = true; | 58 dom_automation_enabled_ = true; |
53 } | 59 } |
54 | 60 |
61 bool HasFlag(FrameRateTestFlags flag) const { return (GetParam() & flag); } | |
Justin Novosad
2011/11/09 15:51:23
This test will not work correctly with multi-bit f
jbates
2011/11/09 17:57:57
Done.
| |
62 | |
63 bool IsGpuAvailable() const { | |
64 return CommandLine::ForCurrentProcess()->HasSwitch("enable-gpu"); | |
65 } | |
66 | |
55 virtual FilePath GetDataPath(const std::string& name) { | 67 virtual FilePath GetDataPath(const std::string& name) { |
56 // Make sure the test data is checked out. | 68 // Make sure the test data is checked out. |
57 FilePath test_path; | 69 FilePath test_path; |
58 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 70 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
59 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); | 71 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); |
60 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); | 72 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); |
61 if (GetParam() & kInternal) { | 73 if (HasFlag(kInternal)) { |
62 test_path = test_path.Append(FILE_PATH_LITERAL("private")); | 74 test_path = test_path.Append(FILE_PATH_LITERAL("private")); |
63 } else { | 75 } else { |
64 test_path = test_path.Append(FILE_PATH_LITERAL("content")); | 76 test_path = test_path.Append(FILE_PATH_LITERAL("content")); |
65 } | 77 } |
66 test_path = test_path.AppendASCII(name); | 78 test_path = test_path.AppendASCII(name); |
67 return test_path; | 79 return test_path; |
68 } | 80 } |
69 | 81 |
70 virtual void SetUp() { | 82 virtual void SetUp() { |
71 if (GetParam() & kUseReferenceBuild) { | 83 if (HasFlag(kUseReferenceBuild)) |
72 UseReferenceBuild(); | 84 UseReferenceBuild(); |
73 } | |
74 | 85 |
75 // UI tests boot up render views starting from about:blank. This causes | 86 // UI tests boot up render views starting from about:blank. This causes |
76 // the renderer to start up thinking it cannot use the GPU. To work | 87 // the renderer to start up thinking it cannot use the GPU. To work |
77 // around that, and allow the frame rate test to use the GPU, we must | 88 // around that, and allow the frame rate test to use the GPU, we must |
78 // pass kAllowWebUICompositing. | 89 // pass kAllowWebUICompositing. |
79 launch_arguments_.AppendSwitch(switches::kAllowWebUICompositing); | 90 launch_arguments_.AppendSwitch(switches::kAllowWebUICompositing); |
80 | 91 |
81 // Some of the tests may launch http requests through JSON or AJAX | 92 // Some of the tests may launch http requests through JSON or AJAX |
82 // which causes a security error (cross domain request) when the page | 93 // which causes a security error (cross domain request) when the page |
83 // is loaded from the local file system ( file:// ). The following switch | 94 // is loaded from the local file system ( file:// ). The following switch |
84 // fixes that error. | 95 // fixes that error. |
85 launch_arguments_.AppendSwitch(switches::kAllowFileAccessFromFiles); | 96 launch_arguments_.AppendSwitch(switches::kAllowFileAccessFromFiles); |
86 | 97 |
87 if (GetParam() & kDisableGpu) { | 98 if (!HasFlag(kUseGpu)) { |
88 launch_arguments_.AppendSwitch(switches::kDisableAcceleratedCompositing); | 99 launch_arguments_.AppendSwitch(switches::kDisableAcceleratedCompositing); |
89 launch_arguments_.AppendSwitch(switches::kDisableExperimentalWebGL); | 100 launch_arguments_.AppendSwitch(switches::kDisableExperimentalWebGL); |
90 } else { | 101 } else { |
91 // This switch is required for enabling the accelerated 2d canvas on | 102 // This switch is required for enabling the accelerated 2d canvas on |
92 // Chrome versions prior to Chrome 15, which may be the case for the | 103 // Chrome versions prior to Chrome 15, which may be the case for the |
93 // reference build. | 104 // reference build. |
94 launch_arguments_.AppendSwitch(switches::kEnableAccelerated2dCanvas); | 105 launch_arguments_.AppendSwitch(switches::kEnableAccelerated2dCanvas); |
95 } | 106 } |
96 | 107 |
97 if (GetParam() & kDisableVsync) { | 108 if (HasFlag(kDisableVsync)) |
98 launch_arguments_.AppendSwitch(switches::kDisableGpuVsync); | 109 launch_arguments_.AppendSwitch(switches::kDisableGpuVsync); |
99 } | |
100 | 110 |
101 UIPerfTest::SetUp(); | 111 UIPerfTest::SetUp(); |
102 } | 112 } |
103 | 113 |
114 bool DidRunOnGpu(const std::string& json_events) { | |
115 using namespace trace_analyzer; | |
116 | |
117 // Check trace for GPU accleration. | |
118 scoped_ptr<TraceAnalyzer> analyzer(TraceAnalyzer::Create(json_events)); | |
119 | |
120 gfx::GLImplementation gl_impl = gfx::kGLImplementationNone; | |
121 const TraceEvent* gpu_event = analyzer->FindOneEvent( | |
122 Query(EVENT_NAME) == Query::String("GLES2DecoderImpl::Initialize") && | |
123 Query(EVENT_HAS_NUMBER_ARG, "GLImpl")); | |
124 if (gpu_event) | |
125 gl_impl = static_cast<gfx::GLImplementation>( | |
126 gpu_event->GetKnownArgAsInt("GLImpl")); | |
127 return (gl_impl == gfx::kGLImplementationDesktopGL || | |
128 gl_impl == gfx::kGLImplementationEGLGLES2); | |
129 } | |
130 | |
104 void RunTest(const std::string& name) { | 131 void RunTest(const std::string& name) { |
105 if ((GetParam() & kRequiresGpu) && | 132 if (HasFlag(kUseGpu) && !IsGpuAvailable()) { |
106 !CommandLine::ForCurrentProcess()->HasSwitch("enable-gpu")) { | |
107 printf("Test skipped: requires gpu\n"); | 133 printf("Test skipped: requires gpu\n"); |
108 return; | 134 return; |
109 } | 135 } |
136 | |
137 // Verify flag combinations. | |
138 ASSERT_TRUE(HasFlag(kUseGpu) || !HasFlag(kForceGpuComposited)); | |
Justin Novosad
2011/11/09 15:51:23
With this assertion in place I think it is not nec
jbates
2011/11/09 17:57:57
Done.
| |
139 ASSERT_TRUE(!HasFlag(kUseGpu) || IsGpuAvailable()); | |
140 | |
110 FilePath test_path = GetDataPath(name); | 141 FilePath test_path = GetDataPath(name); |
111 ASSERT_TRUE(file_util::DirectoryExists(test_path)) | 142 ASSERT_TRUE(file_util::DirectoryExists(test_path)) |
112 << "Missing test directory: " << test_path.value(); | 143 << "Missing test directory: " << test_path.value(); |
113 | 144 |
114 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); | 145 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); |
115 | 146 |
116 scoped_refptr<TabProxy> tab(GetActiveTab()); | 147 scoped_refptr<TabProxy> tab(GetActiveTab()); |
117 ASSERT_TRUE(tab.get()); | 148 ASSERT_TRUE(tab.get()); |
118 | 149 |
119 if (GetParam() & kHasRedirect) { | 150 // TODO(jbates): remove this check when ref builds are updated. |
151 if (!HasFlag(kUseReferenceBuild)) | |
152 ASSERT_TRUE(automation()->BeginTracing("test_gpu")); | |
153 | |
154 if (HasFlag(kHasRedirect)) { | |
120 // If the test file is known to contain an html redirect, we must block | 155 // If the test file is known to contain an html redirect, we must block |
121 // until the second navigation is complete and reacquire the active tab | 156 // until the second navigation is complete and reacquire the active tab |
122 // in order to avoid a race condition. | 157 // in order to avoid a race condition. |
123 // If the following assertion is triggered due to a timeout, it is | 158 // If the following assertion is triggered due to a timeout, it is |
124 // possible that the current test does not re-direct and therefore should | 159 // possible that the current test does not re-direct and therefore should |
125 // not have the kHasRedirect flag turned on. | 160 // not have the kHasRedirect flag turned on. |
126 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 161 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
127 tab->NavigateToURLBlockUntilNavigationsComplete( | 162 tab->NavigateToURLBlockUntilNavigationsComplete( |
128 net::FilePathToFileURL(test_path), 2)); | 163 net::FilePathToFileURL(test_path), 2)); |
129 tab = GetActiveTab(); | 164 tab = GetActiveTab(); |
130 ASSERT_TRUE(tab.get()); | 165 ASSERT_TRUE(tab.get()); |
131 } else { | 166 } else { |
132 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 167 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
133 tab->NavigateToURL(net::FilePathToFileURL(test_path))); | 168 tab->NavigateToURL(net::FilePathToFileURL(test_path))); |
134 } | 169 } |
135 | 170 |
136 // Block until initialization completes | 171 // Block until initialization completes |
137 // If the following assertion fails intermittently, it could be due to a | 172 // If the following assertion fails intermittently, it could be due to a |
138 // race condition caused by an html redirect. If that is the case, verify | 173 // race condition caused by an html redirect. If that is the case, verify |
139 // that flag kHasRedirect is enabled for the current test. | 174 // that flag kHasRedirect is enabled for the current test. |
140 ASSERT_TRUE(WaitUntilJavaScriptCondition( | 175 ASSERT_TRUE(WaitUntilJavaScriptCondition( |
141 tab, L"", L"window.domAutomationController.send(__initialized);", | 176 tab, L"", L"window.domAutomationController.send(__initialized);", |
142 TestTimeouts::large_test_timeout_ms())); | 177 TestTimeouts::large_test_timeout_ms())); |
143 | 178 |
144 if (GetParam() & kMakeBodyComposited) { | 179 if (HasFlag(kForceGpuComposited)) { |
145 ASSERT_TRUE(tab->NavigateToURLAsync( | 180 ASSERT_TRUE(tab->NavigateToURLAsync( |
146 GURL("javascript:__make_body_composited();"))); | 181 GURL("javascript:__make_body_composited();"))); |
147 } | 182 } |
148 | 183 |
149 // Start the tests. | 184 // Start the tests. |
150 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start_all();"))); | 185 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start_all();"))); |
151 | 186 |
152 // Block until the tests completes. | 187 // Block until the tests completes. |
153 ASSERT_TRUE(WaitUntilJavaScriptCondition( | 188 ASSERT_TRUE(WaitUntilJavaScriptCondition( |
154 tab, L"", L"window.domAutomationController.send(!__running_all);", | 189 tab, L"", L"window.domAutomationController.send(!__running_all);", |
155 TestTimeouts::large_test_timeout_ms())); | 190 TestTimeouts::large_test_timeout_ms())); |
156 | 191 |
192 // TODO(jbates): remove this check when ref builds are updated. | |
193 std::string json_events; | |
194 if (!HasFlag(kUseReferenceBuild)) { | |
195 ASSERT_TRUE(automation()->EndTracing(&json_events)); | |
196 | |
197 bool did_run_on_gpu = DidRunOnGpu(json_events); | |
198 bool expect_gpu = HasFlag(kUseGpu); | |
199 EXPECT_EQ(expect_gpu, did_run_on_gpu); | |
200 } | |
201 | |
157 // Read out the results. | 202 // Read out the results. |
158 std::wstring json; | 203 std::wstring json; |
159 ASSERT_TRUE(tab->ExecuteAndExtractString( | 204 ASSERT_TRUE(tab->ExecuteAndExtractString( |
160 L"", | 205 L"", |
161 L"window.domAutomationController.send(" | 206 L"window.domAutomationController.send(" |
162 L"JSON.stringify(__calc_results_total()));", | 207 L"JSON.stringify(__calc_results_total()));", |
163 &json)); | 208 &json)); |
164 | 209 |
165 std::map<std::string, std::string> results; | 210 std::map<std::string, std::string> results; |
166 ASSERT_TRUE(JsonDictionaryToMap(WideToUTF8(json), &results)); | 211 ASSERT_TRUE(JsonDictionaryToMap(WideToUTF8(json), &results)); |
(...skipping 24 matching lines...) Expand all Loading... | |
191 typedef FrameRateTest FrameRateCompositingTest; | 236 typedef FrameRateTest FrameRateCompositingTest; |
192 | 237 |
193 // Tests that trigger compositing with a -webkit-translateZ(0) | 238 // Tests that trigger compositing with a -webkit-translateZ(0) |
194 #define FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(content) \ | 239 #define FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(content) \ |
195 TEST_P(FrameRateCompositingTest, content) { \ | 240 TEST_P(FrameRateCompositingTest, content) { \ |
196 RunTest(#content); \ | 241 RunTest(#content); \ |
197 } | 242 } |
198 | 243 |
199 INSTANTIATE_TEST_CASE_P(, FrameRateCompositingTest, ::testing::Values( | 244 INSTANTIATE_TEST_CASE_P(, FrameRateCompositingTest, ::testing::Values( |
200 0, | 245 0, |
201 kMakeBodyComposited, | 246 kForceGpuComposited, |
202 kUseReferenceBuild, | 247 kUseReferenceBuild, |
203 kUseReferenceBuild | kMakeBodyComposited)); | 248 kUseReferenceBuild | kForceGpuComposited)); |
204 | 249 |
205 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); | 250 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); |
206 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); | 251 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); |
207 | 252 |
208 typedef FrameRateTest FrameRateNoVsyncCanvasInternalTest; | 253 typedef FrameRateTest FrameRateNoVsyncCanvasInternalTest; |
209 | 254 |
210 // Tests for animated 2D canvas content with and without disabling vsync | 255 // Tests for animated 2D canvas content with and without disabling vsync |
211 #define INTERNAL_FRAME_RATE_TEST_CANVAS_WITH_AND_WITHOUT_NOVSYNC(content) \ | 256 #define INTERNAL_FRAME_RATE_TEST_CANVAS_WITH_AND_WITHOUT_NOVSYNC(content) \ |
212 TEST_P(FrameRateNoVsyncCanvasInternalTest, content) { \ | 257 TEST_P(FrameRateNoVsyncCanvasInternalTest, content) { \ |
213 RunTest(#content); \ | 258 RunTest(#content); \ |
214 } \ | 259 } |
215 | 260 |
216 INSTANTIATE_TEST_CASE_P(, FrameRateNoVsyncCanvasInternalTest, ::testing::Values( | 261 INSTANTIATE_TEST_CASE_P(, FrameRateNoVsyncCanvasInternalTest, ::testing::Values( |
217 kInternal | kHasRedirect | kRequiresGpu, | 262 kInternal | kHasRedirect, |
218 kInternal | kHasRedirect | kDisableVsync | | 263 kInternal | kHasRedirect | kUseGpu, |
219 kRequiresGpu, | 264 kInternal | kHasRedirect | kUseGpu | kDisableVsync, |
220 kInternal | kHasRedirect | kDisableGpu, | 265 kUseReferenceBuild | kInternal | kHasRedirect, |
221 kInternal | kHasRedirect | kDisableGpu | | 266 kUseReferenceBuild | kInternal | kHasRedirect | kUseGpu, |
222 kUseReferenceBuild, | 267 kUseReferenceBuild | kInternal | kHasRedirect | kUseGpu | kDisableVsync)); |
223 kInternal | kHasRedirect | kUseReferenceBuild | | |
224 kRequiresGpu, | |
225 kInternal | kHasRedirect | kDisableVsync | | |
226 kRequiresGpu | kUseReferenceBuild)); | |
227 | 268 |
228 INTERNAL_FRAME_RATE_TEST_CANVAS_WITH_AND_WITHOUT_NOVSYNC(fishbowl) | 269 INTERNAL_FRAME_RATE_TEST_CANVAS_WITH_AND_WITHOUT_NOVSYNC(fishbowl) |
229 | 270 |
230 typedef FrameRateTest FrameRateGpuCanvasInternalTest; | 271 typedef FrameRateTest FrameRateGpuCanvasInternalTest; |
231 | 272 |
232 // Tests for animated 2D canvas content to be tested only with GPU | 273 // Tests for animated 2D canvas content to be tested only with GPU |
233 // acceleration. | 274 // acceleration. |
234 // tests are run with and without Vsync | 275 // tests are run with and without Vsync |
235 #define INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(content) \ | 276 #define INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(content) \ |
236 TEST_P(FrameRateGpuCanvasInternalTest, content) { \ | 277 TEST_P(FrameRateGpuCanvasInternalTest, content) { \ |
237 RunTest(#content); \ | 278 RunTest(#content); \ |
238 } \ | 279 } |
239 | 280 |
240 INSTANTIATE_TEST_CASE_P(, FrameRateGpuCanvasInternalTest, ::testing::Values( | 281 INSTANTIATE_TEST_CASE_P(, FrameRateGpuCanvasInternalTest, ::testing::Values( |
241 kInternal | kHasRedirect | kRequiresGpu, | 282 kInternal | kHasRedirect | kUseGpu, |
242 kInternal | kHasRedirect | kDisableVsync | | 283 kInternal | kHasRedirect | kUseGpu | kDisableVsync, |
243 kRequiresGpu, | 284 kUseReferenceBuild | kInternal | kHasRedirect | kUseGpu, |
244 kInternal | kHasRedirect | kUseReferenceBuild | | 285 kUseReferenceBuild | kInternal | kHasRedirect | kUseGpu | kDisableVsync)); |
245 kRequiresGpu, | |
246 kInternal | kHasRedirect | kDisableVsync | | |
247 kRequiresGpu | kUseReferenceBuild)); | |
248 | 286 |
249 INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(fireflies) | 287 INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(fireflies) |
250 INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(FishIE) | 288 INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(FishIE) |
251 INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(speedreading) | 289 INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(speedreading) |
252 | 290 |
253 } // namespace | 291 } // namespace |
OLD | NEW |