summaryrefslogtreecommitdiffstats
path: root/tools/perf/perf_tools/smoothness_benchmark_unittest.py
diff options
context:
space:
mode:
authorhartmanng@chromium.org <hartmanng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-21 20:11:52 +0000
committerhartmanng@chromium.org <hartmanng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-21 20:11:52 +0000
commita5b131332508632b49d5f452bbbdf7ce1ceeeaa0 (patch)
tree5fbf2867377e72f5d74ef08b38b05aa85ccd8db9 /tools/perf/perf_tools/smoothness_benchmark_unittest.py
parentc73b501991379a6d2ef827dd2e09b0c2074966d2 (diff)
downloadchromium_src-a5b131332508632b49d5f452bbbdf7ce1ceeeaa0.zip
chromium_src-a5b131332508632b49d5f452bbbdf7ce1ceeeaa0.tar.gz
chromium_src-a5b131332508632b49d5f452bbbdf7ce1ceeeaa0.tar.bz2
Refactoring benchmarks for perf bot efficiency.
See also: https://codereview.chromium.org/11316017/ (separate patch to move scrolling logic into scrolling_interaction.py as discussed in https://codereview.chromium.org/11366197/#msg2) BUG=160149 Review URL: https://chromiumcodereview.appspot.com/11366197 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169110 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/perf/perf_tools/smoothness_benchmark_unittest.py')
-rw-r--r--tools/perf/perf_tools/smoothness_benchmark_unittest.py139
1 files changed, 139 insertions, 0 deletions
diff --git a/tools/perf/perf_tools/smoothness_benchmark_unittest.py b/tools/perf/perf_tools/smoothness_benchmark_unittest.py
new file mode 100644
index 0000000..6ee4a03
--- /dev/null
+++ b/tools/perf/perf_tools/smoothness_benchmark_unittest.py
@@ -0,0 +1,139 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+from telemetry import multi_page_benchmark
+from telemetry import multi_page_benchmark_unittest_base
+from perf_tools import smoothness_benchmark
+
+from telemetry import browser_finder
+from telemetry import options_for_unittests
+
+import os
+import urlparse
+
+class SmoothnessBenchmarkUnitTest(
+ multi_page_benchmark_unittest_base.MultiPageBenchmarkUnitTestBase):
+
+ def testFirstPaintTimeMeasurement(self):
+ ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
+
+ benchmark = smoothness_benchmark.SmoothnessBenchmark()
+ all_results = self.RunBenchmark(benchmark, ps)
+
+ self.assertEqual(0, len(all_results.page_failures))
+ self.assertEqual(1, len(all_results.page_results))
+
+ results0 = all_results.page_results[0]
+ if results0['first_paint'] == 'unsupported':
+ # This test can't run on content_shell.
+ return
+ self.assertTrue(results0['first_paint'] > 0)
+
+ def testScrollingWithGpuBenchmarkingExtension(self):
+ ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
+
+ benchmark = smoothness_benchmark.SmoothnessBenchmark()
+ all_results = self.RunBenchmark(benchmark, ps)
+
+ self.assertEqual(0, len(all_results.page_failures))
+ self.assertEqual(1, len(all_results.page_results))
+ results0 = all_results.page_results[0]
+
+ self.assertTrue('dropped_percent' in results0)
+ self.assertTrue('mean_frame_time' in results0)
+
+ def testCalcResultsFromRAFRenderStats(self):
+ rendering_stats = {'droppedFrameCount': 5,
+ 'totalTimeInSeconds': 1,
+ 'numAnimationFrames': 10,
+ 'numFramesSentToScreen': 10}
+ res = multi_page_benchmark.BenchmarkResults()
+ res.WillMeasurePage(True)
+ smoothness_benchmark.CalcScrollResults(rendering_stats, res)
+ res.DidMeasurePage()
+ self.assertEquals(50, res.page_results[0]['dropped_percent'])
+ self.assertAlmostEquals(100, res.page_results[0]['mean_frame_time'], 2)
+
+ def testCalcResultsRealRenderStats(self):
+ rendering_stats = {'numFramesSentToScreen': 60,
+ 'globalTotalTextureUploadTimeInSeconds': 0,
+ 'totalProcessingCommandsTimeInSeconds': 0,
+ 'globalTextureUploadCount': 0,
+ 'droppedFrameCount': 0,
+ 'textureUploadCount': 0,
+ 'numAnimationFrames': 10,
+ 'totalPaintTimeInSeconds': 0.35374299999999986,
+ 'globalTotalProcessingCommandsTimeInSeconds': 0,
+ 'totalTextureUploadTimeInSeconds': 0,
+ 'totalRasterizeTimeInSeconds': 0,
+ 'totalTimeInSeconds': 1.0}
+ res = multi_page_benchmark.BenchmarkResults()
+ res.WillMeasurePage(True)
+ smoothness_benchmark.CalcScrollResults(rendering_stats, res)
+ res.DidMeasurePage()
+ self.assertEquals(0, res.page_results[0]['dropped_percent'])
+ self.assertAlmostEquals(1000/60., res.page_results[0]['mean_frame_time'], 2)
+
+ def testBoundingClientRect(self):
+ options = options_for_unittests.Get()
+ browser_to_create = browser_finder.FindBrowser(options)
+ if not browser_to_create:
+ raise Exception('No browser found, cannot continue test.')
+
+ with browser_to_create.Create() as browser:
+ with browser.ConnectToNthTab(0) as tab:
+ ps = self.CreatePageSetFromFileInUnittestDataDir('blank.html')
+ parsed_url = urlparse.urlparse(ps.pages[0].url)
+ path = os.path.join(parsed_url.netloc, parsed_url.path)
+ dirname, filename = os.path.split(path)
+ browser.SetHTTPServerDirectory(dirname)
+ target_side_url = browser.http_server.UrlOf(filename)
+ tab.page.Navigate(target_side_url)
+
+ # Verify that the rect returned by getBoundingVisibleRect() in
+ # scroll.js is completely contained within the viewport. Scroll
+ # events dispatched by the benchmarks use the center of this rect
+ # as their location, and this location needs to be within the
+ # viewport bounds to correctly decide between main-thread and
+ # impl-thread scrolling. If the scrollable area were not clipped
+ # to the viewport bounds, then the instance used here (the scrollable
+ # area being more than twice as tall as the viewport) would
+ # result in a scroll location outside of the viewport bounds.
+ tab.runtime.Execute("""document.body.style.height =
+ (2 * window.innerHeight + 1) + 'px';""")
+ scroll_js_path = os.path.join(os.path.dirname(__file__), 'scroll.js')
+ scroll_js = open(scroll_js_path, 'r').read()
+ tab.runtime.Evaluate(scroll_js)
+
+ rect_bottom = int(tab.runtime.Evaluate("""
+ __ScrollTest_GetBoundingVisibleRect(document.body).top +
+ __ScrollTest_GetBoundingVisibleRect(document.body).height"""))
+ rect_right = int(tab.runtime.Evaluate("""
+ __ScrollTest_GetBoundingVisibleRect(document.body).left +
+ __ScrollTest_GetBoundingVisibleRect(document.body).width"""))
+ viewport_width = int(tab.runtime.Evaluate('window.innerWidth'))
+ viewport_height = int(tab.runtime.Evaluate('window.innerHeight'))
+
+ self.assertTrue(rect_bottom <= viewport_height)
+ self.assertTrue(rect_right <= viewport_width)
+
+class SmoothnessBenchmarkWithoutGpuBenchmarkingUnitTest(
+ multi_page_benchmark_unittest_base.MultiPageBenchmarkUnitTestBase):
+
+ def CustomizeOptionsForTest(self, options):
+ options.no_gpu_benchmarking_extension = True
+
+ def testScrollingWithoutGpuBenchmarkingExtension(self):
+ ps = self.CreatePageSetFromFileInUnittestDataDir('scrollable_page.html')
+
+ benchmark = smoothness_benchmark.SmoothnessBenchmark()
+ benchmark.use_gpu_benchmarking_extension = False
+
+ all_results = self.RunBenchmark(benchmark, ps)
+
+ self.assertEqual(0, len(all_results.page_failures))
+ self.assertEqual(1, len(all_results.page_results))
+ results0 = all_results.page_results[0]
+
+ self.assertTrue('dropped_percent' in results0)
+ self.assertTrue('mean_frame_time' in results0)