| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Basic pyauto performance tests. | 6 """Basic pyauto performance tests. |
| 7 | 7 |
| 8 For tests that need to be run for multiple iterations (e.g., so that average | 8 For tests that need to be run for multiple iterations (e.g., so that average |
| 9 and standard deviation values can be reported), the default number of iterations | 9 and standard deviation values can be reported), the default number of iterations |
| 10 run for each of these tests is specified by |_DEFAULT_NUM_ITERATIONS|. | 10 run for each of these tests is specified by |_DEFAULT_NUM_ITERATIONS|. |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 # Ignore the first iteration. | 586 # Ignore the first iteration. |
| 587 if iteration: | 587 if iteration: |
| 588 timings.append(elapsed_time) | 588 timings.append(elapsed_time) |
| 589 logging.info('Iteration %d of %d: %f milliseconds', iteration, | 589 logging.info('Iteration %d of %d: %f milliseconds', iteration, |
| 590 self._num_iterations, elapsed_time) | 590 self._num_iterations, elapsed_time) |
| 591 self.assertTrue(self._timeout_count <= self._max_timeout_count, | 591 self.assertTrue(self._timeout_count <= self._max_timeout_count, |
| 592 msg='Test exceeded automation timeout threshold.') | 592 msg='Test exceeded automation timeout threshold.') |
| 593 self.assertEqual(1 + num_tabs, self.GetTabCount(), | 593 self.assertEqual(1 + num_tabs, self.GetTabCount(), |
| 594 msg='Did not open %d new tab(s).' % num_tabs) | 594 msg='Did not open %d new tab(s).' % num_tabs) |
| 595 for _ in range(num_tabs): | 595 for _ in range(num_tabs): |
| 596 self.GetBrowserWindow(0).GetTab(1).Close(True) | 596 self.CloseTab(tab_index=1) |
| 597 | 597 |
| 598 self._PrintSummaryResults(description, timings, 'milliseconds', graph_name) | 598 self._PrintSummaryResults(description, timings, 'milliseconds', graph_name) |
| 599 | 599 |
| 600 def _LoginToGoogleAccount(self, account_key='test_google_account'): | 600 def _LoginToGoogleAccount(self, account_key='test_google_account'): |
| 601 """Logs in to a test Google account. | 601 """Logs in to a test Google account. |
| 602 | 602 |
| 603 Args: | 603 Args: |
| 604 account_key: The string key associated with the test account login | 604 account_key: The string key associated with the test account login |
| 605 credentials to use. | 605 credentials to use. |
| 606 """ | 606 """ |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 window.domAutomationController.send(JSON.stringify(result)); | 731 window.domAutomationController.send(JSON.stringify(result)); |
| 732 """ | 732 """ |
| 733 results = eval(self.ExecuteJavascript(js_get_results, tab_index=1)) | 733 results = eval(self.ExecuteJavascript(js_get_results, tab_index=1)) |
| 734 score_pattern = '(\w+): (\d+)' | 734 score_pattern = '(\w+): (\d+)' |
| 735 final_score = re.search(score_pattern, results['final_score']).group(2) | 735 final_score = re.search(score_pattern, results['final_score']).group(2) |
| 736 result_dict = {'final_score': int(final_score)} | 736 result_dict = {'final_score': int(final_score)} |
| 737 for match in re.finditer(score_pattern, results['all_results']): | 737 for match in re.finditer(score_pattern, results['all_results']): |
| 738 benchmark_name = match.group(1) | 738 benchmark_name = match.group(1) |
| 739 benchmark_score = match.group(2) | 739 benchmark_score = match.group(2) |
| 740 result_dict[benchmark_name] = int(benchmark_score) | 740 result_dict[benchmark_name] = int(benchmark_score) |
| 741 self.GetBrowserWindow(0).GetTab(1).Close(True) | 741 self.CloseTab(tab_index=1) |
| 742 return result_dict | 742 return result_dict |
| 743 | 743 |
| 744 timings = {} | 744 timings = {} |
| 745 for iteration in xrange(self._num_iterations + 1): | 745 for iteration in xrange(self._num_iterations + 1): |
| 746 result_dict = _RunBenchmarkOnce(url) | 746 result_dict = _RunBenchmarkOnce(url) |
| 747 # Ignore the first iteration. | 747 # Ignore the first iteration. |
| 748 if iteration: | 748 if iteration: |
| 749 for key, val in result_dict.items(): | 749 for key, val in result_dict.items(): |
| 750 timings.setdefault(key, []).append(val) | 750 timings.setdefault(key, []).append(val) |
| 751 logging.info('Iteration %d of %d:\n%s', iteration, self._num_iterations, | 751 logging.info('Iteration %d of %d:\n%s', iteration, self._num_iterations, |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 # Measures performance using the first demo. | 1430 # Measures performance using the first demo. |
| 1431 avg_fps = self._MeasureFpsOverTime() | 1431 avg_fps = self._MeasureFpsOverTime() |
| 1432 status1 = self._GetStdAvgAndCompare(avg_fps, desc_array[index], | 1432 status1 = self._GetStdAvgAndCompare(avg_fps, desc_array[index], |
| 1433 ref_dict) | 1433 ref_dict) |
| 1434 # Measures performance using the second demo. | 1434 # Measures performance using the second demo. |
| 1435 self.NavigateToURL(url_array[index + 1]) | 1435 self.NavigateToURL(url_array[index + 1]) |
| 1436 avg_fps = self._MeasureFpsOverTime() | 1436 avg_fps = self._MeasureFpsOverTime() |
| 1437 status2 = self._GetStdAvgAndCompare(avg_fps, desc_array[index + 1], | 1437 status2 = self._GetStdAvgAndCompare(avg_fps, desc_array[index + 1], |
| 1438 ref_dict) | 1438 ref_dict) |
| 1439 # Go Back to previous demo | 1439 # Go Back to previous demo |
| 1440 self.GetBrowserWindow(0).GetTab(0).GoBack(); | 1440 self.TabGoBack() |
| 1441 # Measures performance for first demo when moved back | 1441 # Measures performance for first demo when moved back |
| 1442 avg_fps = self._MeasureFpsOverTime() | 1442 avg_fps = self._MeasureFpsOverTime() |
| 1443 status3 = self._GetStdAvgAndCompare( | 1443 status3 = self._GetStdAvgAndCompare( |
| 1444 avg_fps, desc_array[index] + '_backward', | 1444 avg_fps, desc_array[index] + '_backward', |
| 1445 ref_dict) | 1445 ref_dict) |
| 1446 # Go Forward to previous demo | 1446 # Go Forward to previous demo |
| 1447 self.GetBrowserWindow(0).GetTab(0).GoForward(); | 1447 self.TabGoForward() |
| 1448 # Measures performance for second demo when moved forward | 1448 # Measures performance for second demo when moved forward |
| 1449 avg_fps = self._MeasureFpsOverTime() | 1449 avg_fps = self._MeasureFpsOverTime() |
| 1450 status4 = self._GetStdAvgAndCompare( | 1450 status4 = self._GetStdAvgAndCompare( |
| 1451 avg_fps, desc_array[index + 1] + '_forward', | 1451 avg_fps, desc_array[index + 1] + '_forward', |
| 1452 ref_dict) | 1452 ref_dict) |
| 1453 if not all([status1, status2, status3, status4]): | 1453 if not all([status1, status2, status3, status4]): |
| 1454 all_demos_passed = False | 1454 all_demos_passed = False |
| 1455 self.assertTrue( | 1455 self.assertTrue( |
| 1456 all_demos_passed, | 1456 all_demos_passed, |
| 1457 msg='One or more demos failed to yield an acceptable FPS value') | 1457 msg='One or more demos failed to yield an acceptable FPS value') |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 # Get the scroll test results from the webpage. | 1714 # Get the scroll test results from the webpage. |
| 1715 results_js = """ | 1715 results_js = """ |
| 1716 var __stringify = JSON.stringify || JSON.encode; | 1716 var __stringify = JSON.stringify || JSON.encode; |
| 1717 window.domAutomationController.send(__stringify({ | 1717 window.domAutomationController.send(__stringify({ |
| 1718 'first_paint_time': chrome.loadTimes().firstPaintTime - | 1718 'first_paint_time': chrome.loadTimes().firstPaintTime - |
| 1719 chrome.loadTimes().requestTime, | 1719 chrome.loadTimes().requestTime, |
| 1720 'frame_times': __frame_times, | 1720 'frame_times': __frame_times, |
| 1721 })); | 1721 })); |
| 1722 """ | 1722 """ |
| 1723 results = eval(self.ExecuteJavascript(results_js, tab_index=1)) | 1723 results = eval(self.ExecuteJavascript(results_js, tab_index=1)) |
| 1724 self.GetBrowserWindow(0).GetTab(1).Close(True) | 1724 self.CloseTab(tab_index=1) |
| 1725 return ScrollResults(results['first_paint_time'], results['frame_times']) | 1725 return ScrollResults(results['first_paint_time'], results['frame_times']) |
| 1726 | 1726 |
| 1727 def RunScrollTest(self, url, description, graph_name, setup_js=''): | 1727 def RunScrollTest(self, url, description, graph_name, setup_js=''): |
| 1728 """Runs a scroll performance test on the specified webpage. | 1728 """Runs a scroll performance test on the specified webpage. |
| 1729 | 1729 |
| 1730 Args: | 1730 Args: |
| 1731 url: The string url for the webpage on which to run the scroll test. | 1731 url: The string url for the webpage on which to run the scroll test. |
| 1732 description: A string description for the particular test being run. | 1732 description: A string description for the particular test being run. |
| 1733 graph_name: A string name for the performance graph associated with this | 1733 graph_name: A string name for the performance graph associated with this |
| 1734 test. Only used on Chrome desktop. | 1734 test. Only used on Chrome desktop. |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2350 | 2350 |
| 2351 for iteration_num in xrange(2): | 2351 for iteration_num in xrange(2): |
| 2352 for site in tabs: | 2352 for site in tabs: |
| 2353 self.AppendTab(pyauto.GURL(site)) | 2353 self.AppendTab(pyauto.GURL(site)) |
| 2354 | 2354 |
| 2355 self._RecordMemoryStats(description, | 2355 self._RecordMemoryStats(description, |
| 2356 '%dTabs%d' % (len(tabs), iteration_num + 1), | 2356 '%dTabs%d' % (len(tabs), iteration_num + 1), |
| 2357 duration) | 2357 duration) |
| 2358 | 2358 |
| 2359 for _ in xrange(len(tabs)): | 2359 for _ in xrange(len(tabs)): |
| 2360 self.GetBrowserWindow(0).GetTab(1).Close(True) | 2360 self.CloseTab(tab_index=1) |
| 2361 | 2361 |
| 2362 self._RecordMemoryStats(description, '0Tabs%d' % (iteration_num + 1), | 2362 self._RecordMemoryStats(description, '0Tabs%d' % (iteration_num + 1), |
| 2363 duration) | 2363 duration) |
| 2364 | 2364 |
| 2365 def testOpenCloseTabsControl(self): | 2365 def testOpenCloseTabsControl(self): |
| 2366 """Measures memory usage when opening/closing tabs to about:blank.""" | 2366 """Measures memory usage when opening/closing tabs to about:blank.""" |
| 2367 tabs = ['about:blank'] * 10 | 2367 tabs = ['about:blank'] * 10 |
| 2368 self._RunTest(tabs, 'MemCtrl', 15) | 2368 self._RunTest(tabs, 'MemCtrl', 15) |
| 2369 | 2369 |
| 2370 def testOpenCloseTabsLiveSites(self): | 2370 def testOpenCloseTabsLiveSites(self): |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2612 """Identifies the port number to which the server is currently bound. | 2612 """Identifies the port number to which the server is currently bound. |
| 2613 | 2613 |
| 2614 Returns: | 2614 Returns: |
| 2615 The numeric port number to which the server is currently bound. | 2615 The numeric port number to which the server is currently bound. |
| 2616 """ | 2616 """ |
| 2617 return self._server.server_address[1] | 2617 return self._server.server_address[1] |
| 2618 | 2618 |
| 2619 | 2619 |
| 2620 if __name__ == '__main__': | 2620 if __name__ == '__main__': |
| 2621 pyauto_functional.Main() | 2621 pyauto_functional.Main() |
| OLD | NEW |