Chromium Code Reviews| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/test/automation/tab_proxy.h" | 14 #include "chrome/test/automation/tab_proxy.h" |
| 15 #include "chrome/test/ui/javascript_test_util.h" | 15 #include "chrome/test/ui/javascript_test_util.h" |
| 16 #include "chrome/test/ui/ui_perf_test.h" | 16 #include "chrome/test/ui/ui_perf_test.h" |
| 17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class FrameRateTest : public UIPerfTest { | 21 enum FrameRateTestFlags { |
| 22 kMakeBodyComposited = 1 << 0, | |
| 23 kDisableRaf = 1 << 1, | |
| 24 kDisableGpu = 1 << 2, | |
| 25 kReference = 1 << 3, | |
| 26 }; | |
| 27 | |
| 28 template<unsigned TestFlags> | |
| 29 class FrameRateTest_ : public UIPerfTest { | |
| 22 public: | 30 public: |
| 23 FrameRateTest() { | 31 FrameRateTest_() { |
| 24 show_window_ = true; | 32 show_window_ = true; |
| 25 dom_automation_enabled_ = true; | 33 dom_automation_enabled_ = true; |
| 26 // Since this is a performance test, try to use the host machine's GPU | 34 // Since this is a performance test, try to use the host machine's GPU |
| 27 // instead of falling back to software-rendering. | 35 // instead of falling back to software-rendering. |
| 28 force_use_osmesa_ = false; | 36 force_use_osmesa_ = false; |
| 29 disable_accelerated_compositing_ = false; | 37 disable_accelerated_compositing_ = false; |
| 30 } | 38 } |
| 31 | 39 |
| 32 virtual FilePath GetDataPath(const std::string& name) { | 40 virtual FilePath GetDataPath(const std::string& name) { |
| 33 // Make sure the test data is checked out. | 41 // Make sure the test data is checked out. |
| 34 FilePath test_path; | 42 FilePath test_path; |
| 35 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 43 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 36 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); | 44 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); |
| 37 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); | 45 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); |
| 38 test_path = test_path.Append(FILE_PATH_LITERAL("content")); | 46 test_path = test_path.Append(FILE_PATH_LITERAL("content")); |
| 39 test_path = test_path.AppendASCII(name); | 47 test_path = test_path.AppendASCII(name); |
| 40 return test_path; | 48 return test_path; |
| 41 } | 49 } |
| 42 | 50 |
| 43 virtual void SetUp() { | 51 virtual void SetUp() { |
| 44 // UI tests boot up render views starting from about:blank. This causes the | 52 if (TestFlags & kReference) { |
| 45 // renderer to start up thinking it cannot use the GPU. To work around that, | 53 UseReferenceBuild(); |
| 46 // and allow the frame rate test to use the GPU, we must pass | 54 } |
| 47 // kAllowWebUICompositing. | 55 |
| 48 launch_arguments_.AppendSwitch(switches::kAllowWebUICompositing); | 56 if (TestFlags & kDisableGpu) { |
|
nduca
2011/10/14 21:01:46
Do we have a global flag for this? @zmo might know
| |
| 57 launch_arguments_.AppendSwitch(switches::kDisableAccelerated2dCanvas); | |
| 58 launch_arguments_.AppendSwitch(switches::kDisableAcceleratedCompositing); | |
| 59 launch_arguments_.AppendSwitch(switches::kDisableAcceleratedLayers); | |
| 60 launch_arguments_.AppendSwitch(switches::kDisableAcceleratedPlugins); | |
| 61 launch_arguments_.AppendSwitch(switches::kDisableAcceleratedVideo); | |
| 62 } else { | |
| 63 // UI tests boot up render views starting from about:blank. This causes | |
| 64 // the renderer to start up thinking it cannot use the GPU. To work | |
| 65 // around that, and allow the frame rate test to use the GPU, we must | |
| 66 // pass kAllowWebUICompositing. | |
| 67 launch_arguments_.AppendSwitch(switches::kAllowWebUICompositing); | |
|
nduca
2011/10/14 21:01:46
Append this always? There's no harm in it if we pu
| |
| 68 } | |
| 49 | 69 |
| 50 UIPerfTest::SetUp(); | 70 UIPerfTest::SetUp(); |
| 51 } | 71 } |
| 52 | 72 |
| 53 void RunTest(const std::string& name, | 73 void RunTest(const std::string& name, |
| 54 const std::string& suffix, | 74 const std::string& suffix) { |
| 55 bool make_body_composited) { | |
| 56 FilePath test_path = GetDataPath(name); | 75 FilePath test_path = GetDataPath(name); |
| 57 ASSERT_TRUE(file_util::DirectoryExists(test_path)) | 76 ASSERT_TRUE(file_util::DirectoryExists(test_path)) |
| 58 << "Missing test directory: " << test_path.value(); | 77 << "Missing test directory: " << test_path.value(); |
| 59 | 78 |
| 60 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); | 79 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); |
| 61 | 80 |
| 62 scoped_refptr<TabProxy> tab(GetActiveTab()); | 81 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 63 ASSERT_TRUE(tab.get()); | 82 ASSERT_TRUE(tab.get()); |
| 64 | 83 |
| 65 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 84 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 66 tab->NavigateToURL(net::FilePathToFileURL(test_path))); | 85 tab->NavigateToURL(net::FilePathToFileURL(test_path))); |
| 67 | 86 |
| 68 if (make_body_composited) { | 87 if (TestFlags & kMakeBodyComposited) { |
| 69 ASSERT_TRUE(tab->NavigateToURLAsync( | 88 ASSERT_TRUE(tab->NavigateToURLAsync( |
| 70 GURL("javascript:__make_body_composited();"))); | 89 GURL("javascript:__make_body_composited();"))); |
| 71 } | 90 } |
| 72 | 91 |
| 92 if (TestFlags & kDisableRaf) { | |
| 93 ASSERT_TRUE(tab->NavigateToURLAsync( | |
| 94 GURL("javascript:__init_raf(false);"))); | |
| 95 } | |
| 96 | |
| 97 // Block until initialization completes. | |
| 98 ASSERT_TRUE(WaitUntilJavaScriptCondition( | |
| 99 tab, L"", L"window.domAutomationController.send(__initialized);", | |
| 100 TestTimeouts::large_test_timeout_ms())); | |
| 101 | |
| 73 // Start the tests. | 102 // Start the tests. |
| 74 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start_all();"))); | 103 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start_all();"))); |
| 75 | 104 |
| 76 // Block until the tests completes. | 105 // Block until the tests completes. |
| 77 ASSERT_TRUE(WaitUntilJavaScriptCondition( | 106 ASSERT_TRUE(WaitUntilJavaScriptCondition( |
| 78 tab, L"", L"window.domAutomationController.send(!__running_all);", | 107 tab, L"", L"window.domAutomationController.send(!__running_all);", |
| 79 TestTimeouts::large_test_timeout_ms())); | 108 TestTimeouts::large_test_timeout_ms())); |
| 80 | 109 |
| 81 // Read out the results. | 110 // Read out the results. |
| 82 std::wstring json; | 111 std::wstring json; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 101 results["gestures"].c_str(), | 130 results["gestures"].c_str(), |
| 102 results["means"].c_str(), | 131 results["means"].c_str(), |
| 103 results["sigmas"].c_str()); | 132 results["sigmas"].c_str()); |
| 104 | 133 |
| 105 std::string mean_and_error = results["mean"] + "," + results["sigma"]; | 134 std::string mean_and_error = results["mean"] + "," + results["sigma"]; |
| 106 PrintResultMeanAndError(name, "", trace_name, mean_and_error, | 135 PrintResultMeanAndError(name, "", trace_name, mean_and_error, |
| 107 "frames-per-second", true); | 136 "frames-per-second", true); |
| 108 } | 137 } |
| 109 }; | 138 }; |
| 110 | 139 |
| 111 class FrameRateTest_Reference : public FrameRateTest { | 140 typedef FrameRateTest_<0> |
|
nduca
2011/10/14 21:01:46
I think gtest has parameterized tests, though it m
| |
| 112 public: | 141 FrameRateTest; |
| 113 void SetUp() { | 142 typedef FrameRateTest_<kReference> |
| 114 UseReferenceBuild(); | 143 FrameRateTest_Reference; |
| 115 FrameRateTest::SetUp(); | 144 typedef FrameRateTest_<kMakeBodyComposited> |
| 116 } | 145 FrameRateTest_Comp; |
| 117 }; | 146 typedef FrameRateTest_<kReference | kMakeBodyComposited> |
| 147 FrameRateTest_Comp_Reference; | |
| 148 typedef FrameRateTest_<kDisableRaf> | |
| 149 FrameRateTest_NoRaf; | |
| 150 typedef FrameRateTest_<kReference | kDisableRaf> | |
| 151 FrameRateTest_NoRaf_Reference; | |
| 152 typedef FrameRateTest_<kDisableGpu> | |
| 153 FrameRateTest_NoGpu; | |
| 154 typedef FrameRateTest_<kReference | kDisableGpu> | |
| 155 FrameRateTest_NoGpu_Reference; | |
| 156 typedef FrameRateTest_<kDisableRaf | kDisableGpu> | |
| 157 FrameRateTest_NoRaf_NoGpu; | |
| 158 typedef FrameRateTest_<kReference | kDisableRaf | kDisableGpu> | |
| 159 FrameRateTest_NoRaf_NoGpu_Reference; | |
| 160 | |
| 118 | 161 |
| 119 #define FRAME_RATE_TEST(content) \ | 162 #define FRAME_RATE_TEST(content) \ |
| 120 TEST_F(FrameRateTest, content) { \ | 163 TEST_F(FrameRateTest, content) { \ |
| 121 RunTest(#content, "", false); \ | 164 RunTest(#content, ""); \ |
| 122 } \ | 165 } \ |
| 123 TEST_F(FrameRateTest_Reference, content) { \ | 166 TEST_F(FrameRateTest_Reference, content) { \ |
| 124 RunTest(#content, "_ref", false); \ | 167 RunTest(#content, "_ref"); \ |
| 125 } | 168 } |
| 126 | 169 |
| 127 | 170 |
| 128 // Tests that trigger compositing with a -webkit-translateZ(0) | 171 // Tests that trigger compositing with a -webkit-translateZ(0) |
| 129 #define FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(content) \ | 172 #define FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(content) \ |
| 130 TEST_F(FrameRateTest, content) { \ | 173 TEST_F(FrameRateTest, content) { \ |
| 131 RunTest(#content, "", false); \ | 174 RunTest(#content, ""); \ |
| 132 } \ | 175 } \ |
| 133 TEST_F(FrameRateTest, content ## _comp) { \ | 176 TEST_F(FrameRateTest_Comp, content ## _comp) { \ |
| 134 RunTest(#content, "_comp", true); \ | 177 RunTest(#content, "_comp"); \ |
| 135 } \ | 178 } \ |
| 136 TEST_F(FrameRateTest_Reference, content) { \ | 179 TEST_F(FrameRateTest_Reference, content) { \ |
| 137 RunTest(#content, "_ref", false); \ | 180 RunTest(#content, "_ref"); \ |
| 138 } \ | 181 } \ |
| 139 TEST_F(FrameRateTest_Reference, content ## _comp) { \ | 182 TEST_F(FrameRateTest_Comp_Reference, content ## _comp) { \ |
| 140 RunTest(#content, "_comp_ref", true); \ | 183 RunTest(#content, "_comp_ref"); \ |
| 141 } | 184 } |
| 142 | 185 |
| 186 // Tests for pages that have animated 2d canvas content. | |
| 187 // Tests run with and without RAF, and with and without GPU acceleration. | |
| 188 #define FRAME_RATE_TEST_ANIMATED_2D_CANVAS(content) \ | |
|
nduca
2011/10/14 21:01:46
I really think you should factor this differently.
| |
| 189 TEST_F(FrameRateTest, content) { \ | |
| 190 RunTest(#content, ""); \ | |
| 191 } \ | |
| 192 TEST_F(FrameRateTest_NoRaf, content) { \ | |
| 193 RunTest(#content, "_noraf"); \ | |
| 194 } \ | |
| 195 TEST_F(FrameRateTest_NoGpu, content) { \ | |
| 196 RunTest(#content, "_nogpu"); \ | |
| 197 } \ | |
| 198 TEST_F(FrameRateTest_NoRaf_NoGpu, content) { \ | |
| 199 RunTest(#content, "_noraf_nogpu"); \ | |
| 200 } \ | |
| 201 TEST_F(FrameRateTest_Reference, content) { \ | |
| 202 RunTest(#content, "_ref"); \ | |
| 203 } \ | |
| 204 TEST_F(FrameRateTest_NoRaf_Reference, content) { \ | |
| 205 RunTest(#content, "_noraf_ref"); \ | |
| 206 } \ | |
| 207 TEST_F(FrameRateTest_NoGpu_Reference, content) { \ | |
| 208 RunTest(#content, "_nogpu_ref"); \ | |
| 209 } \ | |
| 210 TEST_F(FrameRateTest_NoRaf_NoGpu_Reference, content) { \ | |
| 211 RunTest(#content, "_noraf_nogpu_ref"); \ | |
| 212 } \ | |
| 213 | |
| 143 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); | 214 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); |
|
nduca
2011/10/14 21:01:46
move these up next to the define?
| |
| 144 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); | 215 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); |
| 145 | 216 |
| 146 } // namespace | 217 } // namespace |
| OLD | NEW |