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 #include "ui/gfx/gl/gl_switches.h" | |
| 18 | 19 |
| 19 namespace { | 20 // namespace must be named so that the PrintTo overload is externally visible |
| 21 namespace perf { | |
| 20 | 22 |
| 21 class FrameRateTest : public UIPerfTest { | 23 enum FrameRateTestFlags { |
| 24 kMakeBodyComposited = 1 << 0, | |
| 25 kDisableVsync = 1 << 1, | |
| 26 kDisableGpu = 1 << 2, | |
| 27 kUseReferenceBuild = 1 << 3, | |
| 28 }; | |
| 29 | |
| 30 // Wrap flags into a class so that PrintTo can be overloaded | |
| 31 class FrameRateTestVariant { | |
| 32 public: | |
| 33 explicit FrameRateTestVariant(unsigned flags) : flags_(flags) {} | |
| 34 unsigned GetFlags() const {return flags_;} | |
| 35 private: | |
| 36 unsigned flags_; | |
| 37 }; | |
| 38 | |
| 39 void PrintTo(const FrameRateTestVariant& v, std::ostream* os) { | |
| 40 bool has_val = false; | |
| 41 | |
| 42 #define PRINTFLAG(flag_name) \ | |
| 43 if (v.GetFlags() & flag_name) { \ | |
| 44 if (has_val) { \ | |
| 45 *os << " | "; \ | |
| 46 } else { \ | |
| 47 has_val = true; \ | |
| 48 } \ | |
| 49 *os << #flag_name; \ | |
| 50 } | |
| 51 | |
| 52 PRINTFLAG(kMakeBodyComposited) | |
| 53 PRINTFLAG(kDisableVsync) | |
| 54 PRINTFLAG(kDisableGpu) | |
| 55 PRINTFLAG(kUseReferenceBuild) | |
| 56 | |
| 57 if (!has_val) { | |
| 58 *os << "0"; | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 std::string ParamTestNameSuffix(FrameRateTestVariant param, int) { | |
|
Justin Novosad
2011/10/19 19:53:41
I know this unused int param looks weird. It is s
| |
| 63 std::string suffix; | |
| 64 if (param.GetFlags() & kMakeBodyComposited) | |
| 65 suffix += "_comp"; | |
| 66 if (param.GetFlags() & kDisableVsync) | |
| 67 suffix += "_novsync"; | |
| 68 if (param.GetFlags() & kDisableGpu) | |
| 69 suffix += "_nogpu"; | |
| 70 if (param.GetFlags() & kReference) | |
| 71 suffix += "_ref"; | |
| 72 return suffix; | |
| 73 } | |
| 74 | |
| 75 class FrameRateTest | |
| 76 : public UIPerfTest | |
| 77 , public ::testing::WithParamInterface<FrameRateTestVariant> { | |
| 22 public: | 78 public: |
| 23 FrameRateTest() { | 79 FrameRateTest() { |
| 24 show_window_ = true; | 80 show_window_ = true; |
| 25 dom_automation_enabled_ = true; | 81 dom_automation_enabled_ = true; |
| 26 // Since this is a performance test, try to use the host machine's GPU | 82 // Since this is a performance test, try to use the host machine's GPU |
| 27 // instead of falling back to software-rendering. | 83 // instead of falling back to software-rendering. |
| 28 force_use_osmesa_ = false; | 84 force_use_osmesa_ = false; |
| 29 disable_accelerated_compositing_ = false; | 85 disable_accelerated_compositing_ = false; |
| 30 } | 86 } |
| 31 | 87 |
| 32 virtual FilePath GetDataPath(const std::string& name) { | 88 virtual FilePath GetDataPath(const std::string& name) { |
| 33 // Make sure the test data is checked out. | 89 // Make sure the test data is checked out. |
| 34 FilePath test_path; | 90 FilePath test_path; |
| 35 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 91 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| 36 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); | 92 test_path = test_path.Append(FILE_PATH_LITERAL("perf")); |
| 37 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); | 93 test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); |
| 38 test_path = test_path.Append(FILE_PATH_LITERAL("content")); | 94 test_path = test_path.Append(FILE_PATH_LITERAL("content")); |
| 39 test_path = test_path.AppendASCII(name); | 95 test_path = test_path.AppendASCII(name); |
| 40 return test_path; | 96 return test_path; |
| 41 } | 97 } |
| 42 | 98 |
| 43 virtual void SetUp() { | 99 virtual void SetUp() { |
| 44 // UI tests boot up render views starting from about:blank. This causes the | 100 if (GetParam().GetFlags() & kReference) { |
| 45 // renderer to start up thinking it cannot use the GPU. To work around that, | 101 UseReferenceBuild(); |
| 46 // and allow the frame rate test to use the GPU, we must pass | 102 } |
| 47 // kAllowWebUICompositing. | 103 |
| 104 // UI tests boot up render views starting from about:blank. This causes | |
| 105 // the renderer to start up thinking it cannot use the GPU. To work | |
| 106 // around that, and allow the frame rate test to use the GPU, we must | |
| 107 // pass kAllowWebUICompositing. | |
| 48 launch_arguments_.AppendSwitch(switches::kAllowWebUICompositing); | 108 launch_arguments_.AppendSwitch(switches::kAllowWebUICompositing); |
| 49 | 109 |
| 110 if (GetParam().GetFlags() & kDisableGpu) { | |
| 111 launch_arguments_.AppendSwitch(switches::kDisableAcceleratedCompositing); | |
| 112 launch_arguments_.AppendSwitch(switches::kDisableExperimentalWebGL); | |
| 113 } | |
| 114 | |
| 115 if (GetParam().GetFlags() & kDisableVsync) { | |
| 116 launch_arguments_.AppendSwitch(switches::kDisableGpuVsync); | |
| 117 } | |
| 118 | |
| 50 UIPerfTest::SetUp(); | 119 UIPerfTest::SetUp(); |
| 51 } | 120 } |
| 52 | 121 |
| 53 void RunTest(const std::string& name, | 122 void RunTest(const std::string& name) { |
| 54 const std::string& suffix, | |
| 55 bool make_body_composited) { | |
| 56 FilePath test_path = GetDataPath(name); | 123 FilePath test_path = GetDataPath(name); |
| 57 ASSERT_TRUE(file_util::DirectoryExists(test_path)) | 124 ASSERT_TRUE(file_util::DirectoryExists(test_path)) |
| 58 << "Missing test directory: " << test_path.value(); | 125 << "Missing test directory: " << test_path.value(); |
| 59 | 126 |
| 60 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); | 127 test_path = test_path.Append(FILE_PATH_LITERAL("test.html")); |
| 61 | 128 |
| 62 scoped_refptr<TabProxy> tab(GetActiveTab()); | 129 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 63 ASSERT_TRUE(tab.get()); | 130 ASSERT_TRUE(tab.get()); |
| 64 | 131 |
| 65 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 132 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 66 tab->NavigateToURL(net::FilePathToFileURL(test_path))); | 133 tab->NavigateToURL(net::FilePathToFileURL(test_path))); |
| 67 | 134 |
| 68 if (make_body_composited) { | 135 if (GetParam().GetFlags() & kMakeBodyComposited) { |
| 69 ASSERT_TRUE(tab->NavigateToURLAsync( | 136 ASSERT_TRUE(tab->NavigateToURLAsync( |
| 70 GURL("javascript:__make_body_composited();"))); | 137 GURL("javascript:__make_body_composited();"))); |
| 71 } | 138 } |
| 72 | 139 |
| 140 // Block until initialization completes. | |
| 141 ASSERT_TRUE(WaitUntilJavaScriptCondition( | |
| 142 tab, L"", L"window.domAutomationController.send(__initialized);", | |
| 143 TestTimeouts::large_test_timeout_ms())); | |
| 144 | |
| 73 // Start the tests. | 145 // Start the tests. |
| 74 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start_all();"))); | 146 ASSERT_TRUE(tab->NavigateToURLAsync(GURL("javascript:__start_all();"))); |
| 75 | 147 |
| 76 // Block until the tests completes. | 148 // Block until the tests completes. |
| 77 ASSERT_TRUE(WaitUntilJavaScriptCondition( | 149 ASSERT_TRUE(WaitUntilJavaScriptCondition( |
| 78 tab, L"", L"window.domAutomationController.send(!__running_all);", | 150 tab, L"", L"window.domAutomationController.send(!__running_all);", |
| 79 TestTimeouts::large_test_timeout_ms())); | 151 TestTimeouts::large_test_timeout_ms())); |
| 80 | 152 |
| 81 // Read out the results. | 153 // Read out the results. |
| 82 std::wstring json; | 154 std::wstring json; |
| 83 ASSERT_TRUE(tab->ExecuteAndExtractString( | 155 ASSERT_TRUE(tab->ExecuteAndExtractString( |
| 84 L"", | 156 L"", |
| 85 L"window.domAutomationController.send(" | 157 L"window.domAutomationController.send(" |
| 86 L"JSON.stringify(__calc_results_total()));", | 158 L"JSON.stringify(__calc_results_total()));", |
| 87 &json)); | 159 &json)); |
| 88 | 160 |
| 89 std::map<std::string, std::string> results; | 161 std::map<std::string, std::string> results; |
| 90 ASSERT_TRUE(JsonDictionaryToMap(WideToUTF8(json), &results)); | 162 ASSERT_TRUE(JsonDictionaryToMap(WideToUTF8(json), &results)); |
| 91 | 163 |
| 92 ASSERT_TRUE(results.find("mean") != results.end()); | 164 ASSERT_TRUE(results.find("mean") != results.end()); |
| 93 ASSERT_TRUE(results.find("sigma") != results.end()); | 165 ASSERT_TRUE(results.find("sigma") != results.end()); |
| 94 ASSERT_TRUE(results.find("gestures") != results.end()); | 166 ASSERT_TRUE(results.find("gestures") != results.end()); |
| 95 ASSERT_TRUE(results.find("means") != results.end()); | 167 ASSERT_TRUE(results.find("means") != results.end()); |
| 96 ASSERT_TRUE(results.find("sigmas") != results.end()); | 168 ASSERT_TRUE(results.find("sigmas") != results.end()); |
| 97 | 169 |
| 98 std::string trace_name = "fps" + suffix; | 170 std::string trace_name = "fps"; |
| 171 trace_name += ParamTestNameSuffix(GetParam(), 0); | |
| 99 printf("GESTURES %s: %s= [%s] [%s] [%s]\n", name.c_str(), | 172 printf("GESTURES %s: %s= [%s] [%s] [%s]\n", name.c_str(), |
| 100 trace_name.c_str(), | 173 trace_name.c_str(), |
| 101 results["gestures"].c_str(), | 174 results["gestures"].c_str(), |
| 102 results["means"].c_str(), | 175 results["means"].c_str(), |
| 103 results["sigmas"].c_str()); | 176 results["sigmas"].c_str()); |
| 104 | 177 |
| 105 std::string mean_and_error = results["mean"] + "," + results["sigma"]; | 178 std::string mean_and_error = results["mean"] + "," + results["sigma"]; |
| 106 PrintResultMeanAndError(name, "", trace_name, mean_and_error, | 179 PrintResultMeanAndError(name, "", trace_name, mean_and_error, |
| 107 "frames-per-second", true); | 180 "frames-per-second", true); |
| 108 } | 181 } |
| 109 }; | 182 }; |
| 110 | 183 |
| 111 class FrameRateTest_Reference : public FrameRateTest { | 184 FrameRateTestVariant kTestVariant_Plain(0); |
| 112 public: | 185 FrameRateTestVariant kTestVariant_Comp(kMakeBodyComposited); |
| 113 void SetUp() { | 186 FrameRateTestVariant kTestVariant_Reference(kReference); |
| 114 UseReferenceBuild(); | 187 FrameRateTestVariant kTestVariant_Comp_Reference(kMakeBodyComposited |
| 115 FrameRateTest::SetUp(); | 188 | kReference); |
| 116 } | 189 FrameRateTestVariant kTestVariant_NoVsync(kDisableVsync); |
| 117 }; | 190 FrameRateTestVariant kTestVariant_NoGpu(kDisableGpu); |
| 118 | 191 FrameRateTestVariant kTestVariant_NoVsync_Reference(kDisableVsync |
| 119 #define FRAME_RATE_TEST(content) \ | 192 | kReference); |
| 120 TEST_F(FrameRateTest, content) { \ | |
| 121 RunTest(#content, "", false); \ | |
| 122 } \ | |
| 123 TEST_F(FrameRateTest_Reference, content) { \ | |
| 124 RunTest(#content, "_ref", false); \ | |
| 125 } | |
| 126 | |
| 127 | 193 |
| 128 // Tests that trigger compositing with a -webkit-translateZ(0) | 194 // Tests that trigger compositing with a -webkit-translateZ(0) |
| 129 #define FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(content) \ | 195 #define FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(content) \ |
| 130 TEST_F(FrameRateTest, content) { \ | 196 TEST_P(FrameRateTest, content) { \ |
| 131 RunTest(#content, "", false); \ | 197 RunTest(#content); \ |
| 132 } \ | |
| 133 TEST_F(FrameRateTest, content ## _comp) { \ | |
| 134 RunTest(#content, "_comp", true); \ | |
| 135 } \ | |
| 136 TEST_F(FrameRateTest_Reference, content) { \ | |
| 137 RunTest(#content, "_ref", false); \ | |
| 138 } \ | |
| 139 TEST_F(FrameRateTest_Reference, content ## _comp) { \ | |
| 140 RunTest(#content, "_comp_ref", true); \ | |
| 141 } | 198 } |
| 142 | 199 |
| 143 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); | 200 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); |
| 144 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); | 201 FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); |
| 145 | 202 |
| 203 INSTANTIATE_TEST_CASE_P(, FrameRateTest, ::testing::Values( | |
| 204 kTestVariant_Plain, | |
| 205 kTestVariant_Comp | |
| 206 kTestVariant_Reference, | |
| 207 kTestVariant_Comp_Reference)); | |
| 208 | |
| 209 // Must use a different class name to avoid test instantiation conflicts | |
| 210 // with FrameRateTest (used above). An alias is good enough. | |
| 211 typedef FrameRateTest FrameRateCanvasTest; | |
| 212 | |
| 213 #define FRAME_RATE_TEST_ANIMATED_2D_CANVAS(content) \ | |
| 214 TEST_P(FrameRateCanvasTest, content) { \ | |
| 215 RunTest(#content); \ | |
| 216 } \ | |
| 217 | |
| 218 INSTANTIATE_TEST_CASE_P(, FrameRateCanvasTest, ::testing::Values( | |
| 219 kTestVariant_Plain, | |
| 220 kTestVariant_NoVsync, | |
| 221 kTestVariant_NoGpu | |
| 222 kTestVariant_Reference, | |
| 223 kTestVariant_NoVsync_Reference)); | |
| 224 | |
| 146 } // namespace | 225 } // namespace |
| OLD | NEW |