Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/test/chromedriver/run_py_tests.py

Issue 15979030: [chromedriver] Add some simple perf benchmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/chromedriver/run_all_tests.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """End to end tests for ChromeDriver.""" 6 """End to end tests for ChromeDriver."""
7 7
8 import base64 8 import base64
9 import optparse 9 import optparse
10 import os 10 import os
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 """Base class for testing chromedriver functionalities.""" 107 """Base class for testing chromedriver functionalities."""
108 108
109 def __init__(self, *args, **kwargs): 109 def __init__(self, *args, **kwargs):
110 super(ChromeDriverBaseTest, self).__init__(*args, **kwargs) 110 super(ChromeDriverBaseTest, self).__init__(*args, **kwargs)
111 self._drivers = [] 111 self._drivers = []
112 112
113 def tearDown(self): 113 def tearDown(self):
114 for driver in self._drivers: 114 for driver in self._drivers:
115 try: 115 try:
116 driver.Quit() 116 driver.Quit()
117 except chromedriver.ChromeDriverException: 117 except:
118 pass 118 pass
119 119
120 def CreateDriver(self, **kwargs): 120 def CreateDriver(self, server_url=None, **kwargs):
121 driver = chromedriver.ChromeDriver(_CHROMEDRIVER_SERVER_URL, 121 if server_url is None:
122 server_url = _CHROMEDRIVER_SERVER_URL
123 driver = chromedriver.ChromeDriver(server_url,
122 chrome_binary=_CHROME_BINARY, 124 chrome_binary=_CHROME_BINARY,
123 android_package=_ANDROID_PACKAGE, 125 android_package=_ANDROID_PACKAGE,
124 **kwargs) 126 **kwargs)
125 self._drivers += [driver] 127 self._drivers += [driver]
126 return driver 128 return driver
127 129
128 130
129 class ChromeDriverTest(ChromeDriverBaseTest): 131 class ChromeDriverTest(ChromeDriverBaseTest):
130 """End to end tests for ChromeDriver.""" 132 """End to end tests for ChromeDriver."""
131 133
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 603
602 Verifies that a log message is written into the specified log file. 604 Verifies that a log message is written into the specified log file.
603 """ 605 """
604 tmp_log_path = tempfile.NamedTemporaryFile() 606 tmp_log_path = tempfile.NamedTemporaryFile()
605 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name) 607 driver = self.CreateDriver(chrome_log_path=tmp_log_path.name)
606 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE) 608 driver.ExecuteScript('console.info("%s")' % self.LOG_MESSAGE)
607 driver.Quit() 609 driver.Quit()
608 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read()) 610 self.assertTrue(self.LOG_MESSAGE in open(tmp_log_path.name).read())
609 611
610 612
613 class PerfTest(ChromeDriverBaseTest):
614 """Tests for ChromeDriver perf."""
615 def setUp(self):
616 self.assertTrue(_REFERENCE_CHROMEDRIVER is not None,
617 'must supply a reference-chromedriver arg')
618
619 def _RunDriverPerfTest(self, name, test_func):
620 """Runs a perf test comparing a reference and new ChromeDriver server.
621
622 Args:
623 name: The name of the perf test.
624 test_func: Called with the server url to perform the test action. Must
625 return the time elapsed.
626 """
627 class Results(object):
628 ref = []
629 new = []
630
631 ref_server = chromedriver.Server(_REFERENCE_CHROMEDRIVER)
632 results = Results()
633 result_url_pairs = zip([results.new, results.ref],
634 [_CHROMEDRIVER_SERVER_URL, ref_server.GetUrl()])
635 for iteration in range(30):
636 for result, url in result_url_pairs:
637 result += [test_func(url)]
638 # Reverse the order for the next run.
639 result_url_pairs = result_url_pairs[::-1]
640
641 def PrintResult(build, result):
642 mean = sum(result) / len(result)
643 avg_dev = sum([abs(sample - mean) for sample in result]) / len(result)
644 print 'perf result', build, name, mean, avg_dev, result
645 util.AddBuildStepText(u'%s %s: %.3f\u00b1%.3f' % (
646 build, name, mean, avg_dev))
647
648 # Discard first result, which may be off due to cold start.
649 PrintResult('new', results.new[1:])
650 PrintResult('ref', results.ref[1:])
651
652 def testSessionStartTime(self):
653 def Run(url):
654 start = time.time()
655 driver = self.CreateDriver(url)
656 end = time.time()
657 driver.Quit()
658 return end - start
659 self._RunDriverPerfTest('session start', Run)
660
661 def testSessionStopTime(self):
662 def Run(url):
663 driver = self.CreateDriver(url)
664 start = time.time()
665 driver.Quit()
666 end = time.time()
667 return end - start
668 self._RunDriverPerfTest('session stop', Run)
669
670 def testColdExecuteScript(self):
671 def Run(url):
672 driver = self.CreateDriver(url)
673 start = time.time()
674 driver.ExecuteScript('return 1')
675 end = time.time()
676 driver.Quit()
677 return end - start
678 self._RunDriverPerfTest('cold exe js', Run)
679
611 if __name__ == '__main__': 680 if __name__ == '__main__':
612 parser = optparse.OptionParser() 681 parser = optparse.OptionParser()
613 parser.add_option( 682 parser.add_option(
614 '', '--chromedriver', 683 '', '--chromedriver',
615 help='Path to chromedriver server (REQUIRED!)') 684 help='Path to chromedriver server (REQUIRED!)')
616 parser.add_option( 685 parser.add_option(
686 '', '--reference-chromedriver',
687 help='Path to the chromedriver server')
chrisgao (Use stgao instead) 2013/06/04 20:33:27 add "reference" explicitly here? Maybe we also hav
kkania 2013/06/04 20:49:46 Done.
688 parser.add_option(
617 '', '--chrome', help='Path to a build of the chrome binary') 689 '', '--chrome', help='Path to a build of the chrome binary')
618 parser.add_option( 690 parser.add_option(
619 '', '--chrome-version', default='HEAD', 691 '', '--chrome-version', default='HEAD',
620 help='Version of chrome. Default is \'HEAD\'.') 692 help='Version of chrome. Default is \'HEAD\'.')
621 parser.add_option( 693 parser.add_option(
622 '', '--filter', type='string', default='*', 694 '', '--filter', type='string', default='*',
623 help=('Filter for specifying what tests to run, "*" will run all. E.g., ' 695 help=('Filter for specifying what tests to run, "*" will run all. E.g., '
624 '*testStartStop')) 696 '*testStartStop'))
625 parser.add_option( 697 parser.add_option(
626 '', '--android-package', help='Android package name') 698 '', '--android-package', help='Android package name')
627 options, args = parser.parse_args() 699 options, args = parser.parse_args()
628 700
629 if not options.chromedriver or not os.path.exists(options.chromedriver): 701 if not options.chromedriver or not os.path.exists(options.chromedriver):
630 parser.error('chromedriver is required or the given path is invalid.' + 702 parser.error('chromedriver is required or the given path is invalid.' +
631 'Please run "%s --help" for help' % __file__) 703 'Please run "%s --help" for help' % __file__)
632 704
633 server = chromedriver.Server(os.path.abspath(options.chromedriver)) 705 server = chromedriver.Server(os.path.abspath(options.chromedriver))
634 global _CHROMEDRIVER_SERVER_URL 706 global _CHROMEDRIVER_SERVER_URL
635 _CHROMEDRIVER_SERVER_URL = server.GetUrl() 707 _CHROMEDRIVER_SERVER_URL = server.GetUrl()
636 708
709 global _REFERENCE_CHROMEDRIVER
710 _REFERENCE_CHROMEDRIVER = options.reference_chromedriver
711
637 global _CHROME_BINARY 712 global _CHROME_BINARY
638 if options.chrome: 713 if options.chrome:
639 _CHROME_BINARY = os.path.abspath(options.chrome) 714 _CHROME_BINARY = os.path.abspath(options.chrome)
640 else: 715 else:
641 _CHROME_BINARY = None 716 _CHROME_BINARY = None
642 717
643 global _ANDROID_PACKAGE 718 global _ANDROID_PACKAGE
644 _ANDROID_PACKAGE = options.android_package 719 _ANDROID_PACKAGE = options.android_package
645 720
646 if options.filter == '*': 721 if options.filter == '*':
647 if _ANDROID_PACKAGE: 722 if _ANDROID_PACKAGE:
648 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE] 723 negative_filter = _ANDROID_NEGATIVE_FILTER[_ANDROID_PACKAGE]
649 else: 724 else:
650 negative_filter = _DESKTOP_NEGATIVE_FILTER[options.chrome_version] 725 negative_filter = _DESKTOP_NEGATIVE_FILTER[options.chrome_version]
651 options.filter = '*-' + ':__main__.'.join([''] + negative_filter) 726 options.filter = '*-' + ':__main__.'.join([''] + negative_filter)
652 727
653 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule( 728 all_tests_suite = unittest.defaultTestLoader.loadTestsFromModule(
654 sys.modules[__name__]) 729 sys.modules[__name__])
655 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter) 730 tests = unittest_util.FilterTestSuite(all_tests_suite, options.filter)
656 ChromeDriverTest.GlobalSetUp() 731 ChromeDriverTest.GlobalSetUp()
657 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests) 732 result = unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(tests)
658 ChromeDriverTest.GlobalTearDown() 733 ChromeDriverTest.GlobalTearDown()
659 sys.exit(len(result.failures) + len(result.errors)) 734 sys.exit(len(result.failures) + len(result.errors))
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/run_all_tests.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698