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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 import urllib2 | 44 import urllib2 |
45 import urlparse | 45 import urlparse |
46 | 46 |
47 import pyauto_functional # Must be imported before pyauto. | 47 import pyauto_functional # Must be imported before pyauto. |
48 import pyauto | 48 import pyauto |
49 import simplejson # Must be imported after pyauto; located in third_party. | 49 import simplejson # Must be imported after pyauto; located in third_party. |
50 | 50 |
51 from netflix import NetflixTestHelper | 51 from netflix import NetflixTestHelper |
52 import pyauto_utils | 52 import pyauto_utils |
53 import test_utils | 53 import test_utils |
54 import webpagereplay | |
55 from youtube import YoutubeTestHelper | 54 from youtube import YoutubeTestHelper |
56 | 55 |
57 | 56 |
58 _CHROME_BASE_DIR = os.path.abspath(os.path.join( | 57 _CHROME_BASE_DIR = os.path.abspath(os.path.join( |
59 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) | 58 os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, os.pardir)) |
60 | 59 |
61 | 60 |
62 def FormatChromePath(posix_path, **kwargs): | 61 def FormatChromePath(posix_path, **kwargs): |
63 """Convert a path relative to the Chromium root into an OS-specific path. | 62 """Convert a path relative to the Chromium root into an OS-specific path. |
64 | 63 |
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 def testIntl2File(self): | 2077 def testIntl2File(self): |
2079 self.RunPageCyclerTest('intl2', 'Intl2File') | 2078 self.RunPageCyclerTest('intl2', 'Intl2File') |
2080 | 2079 |
2081 def testMozFile(self): | 2080 def testMozFile(self): |
2082 self.RunPageCyclerTest('moz', 'MozFile') | 2081 self.RunPageCyclerTest('moz', 'MozFile') |
2083 | 2082 |
2084 def testMoz2File(self): | 2083 def testMoz2File(self): |
2085 self.RunPageCyclerTest('moz2', 'Moz2File') | 2084 self.RunPageCyclerTest('moz2', 'Moz2File') |
2086 | 2085 |
2087 | 2086 |
2088 class PageCyclerReplay(object): | |
2089 """Run page cycler tests with network simulation via Web Page Replay. | |
2090 | |
2091 Web Page Replay is a proxy that can record and "replay" web pages with | |
2092 simulated network characteristics -- without having to edit the pages | |
2093 by hand. With WPR, tests can use "real" web content, and catch | |
2094 performance issues that may result from introducing network delays and | |
2095 bandwidth throttling. | |
2096 """ | |
2097 _PATHS = { | |
2098 'archive': 'src/data/page_cycler/webpagereplay/{test_name}.wpr', | |
2099 'page_sets': 'src/tools/page_cycler/webpagereplay/tests/{test_name}.js', | |
2100 'start_page': 'src/tools/page_cycler/webpagereplay/start.html', | |
2101 'extension': 'src/tools/page_cycler/webpagereplay/extension', | |
2102 } | |
2103 | |
2104 WEBPAGEREPLAY_HOST = '127.0.0.1' | |
2105 WEBPAGEREPLAY_HTTP_PORT = 8080 | |
2106 WEBPAGEREPLAY_HTTPS_PORT = 8413 | |
2107 | |
2108 CHROME_FLAGS = webpagereplay.GetChromeFlags( | |
2109 WEBPAGEREPLAY_HOST, | |
2110 WEBPAGEREPLAY_HTTP_PORT, | |
2111 WEBPAGEREPLAY_HTTPS_PORT) + [ | |
2112 '--log-level=0', | |
2113 '--disable-background-networking', | |
2114 '--enable-experimental-extension-apis', | |
2115 '--enable-logging', | |
2116 '--enable-benchmarking', | |
2117 '--enable-net-benchmarking', | |
2118 '--metrics-recording-only', | |
2119 '--activate-on-launch', | |
2120 '--no-first-run', | |
2121 '--no-proxy-server', | |
2122 ] | |
2123 | |
2124 @classmethod | |
2125 def Path(cls, key, **kwargs): | |
2126 return FormatChromePath(cls._PATHS[key], **kwargs) | |
2127 | |
2128 @classmethod | |
2129 def ReplayServer(cls, test_name, replay_options=None): | |
2130 archive_path = cls.Path('archive', test_name=test_name) | |
2131 return webpagereplay.ReplayServer(archive_path, | |
2132 cls.WEBPAGEREPLAY_HOST, 0, | |
2133 cls.WEBPAGEREPLAY_HTTP_PORT, | |
2134 cls.WEBPAGEREPLAY_HTTPS_PORT, | |
2135 replay_options) | |
2136 | |
2137 | |
2138 class PageCyclerNetSimTest(BasePageCyclerTest): | |
2139 """Tests to run Web Page Replay backed page cycler tests.""" | |
2140 MAX_ITERATION_SECONDS = 180 | |
2141 | |
2142 def ExtraChromeFlags(self): | |
2143 """Ensures Chrome is launched with custom flags. | |
2144 | |
2145 Returns: | |
2146 A list of extra flags to pass to Chrome when it is launched. | |
2147 """ | |
2148 flags = super(PageCyclerNetSimTest, self).ExtraChromeFlags() | |
2149 flags.append('--load-extension=%s' % PageCyclerReplay.Path('extension')) | |
2150 flags.extend(PageCyclerReplay.CHROME_FLAGS) | |
2151 return flags | |
2152 | |
2153 def StartUrl(self, test_name, iterations): | |
2154 start_path = PageCyclerReplay.Path('start_page') | |
2155 start_url = 'file://%s?test=%s&iterations=%d' % ( | |
2156 start_path, test_name, iterations) | |
2157 if self.use_auto: | |
2158 start_url += '&auto=1' | |
2159 return start_url | |
2160 | |
2161 def RunPageCyclerTest(self, test_name, description): | |
2162 """Runs the specified PageCycler test. | |
2163 | |
2164 Args: | |
2165 test_name: name for archive (.wpr) and config (.js) files. | |
2166 description: a string description for the test | |
2167 """ | |
2168 replay_options = None | |
2169 with PageCyclerReplay.ReplayServer(test_name, replay_options) as server: | |
2170 if server.is_record_mode: | |
2171 self._num_iterations = 1 | |
2172 super_self = super(PageCyclerNetSimTest, self) | |
2173 super_self.RunPageCyclerTest(test_name, description) | |
2174 | |
2175 def test2012Q2(self): | |
2176 self.RunPageCyclerTest('2012Q2', '2012Q2') | |
2177 | |
2178 | |
2179 class MemoryTest(BasePerfTest): | 2087 class MemoryTest(BasePerfTest): |
2180 """Tests to measure memory consumption under different usage scenarios.""" | 2088 """Tests to measure memory consumption under different usage scenarios.""" |
2181 | 2089 |
2182 def ExtraChromeFlags(self): | 2090 def ExtraChromeFlags(self): |
2183 """Launches Chrome with custom flags. | 2091 """Launches Chrome with custom flags. |
2184 | 2092 |
2185 Returns: | 2093 Returns: |
2186 A list of extra flags to pass to Chrome when it is launched. | 2094 A list of extra flags to pass to Chrome when it is launched. |
2187 """ | 2095 """ |
2188 # Ensure Chrome assigns one renderer process to each tab. | 2096 # Ensure Chrome assigns one renderer process to each tab. |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2509 """Identifies the port number to which the server is currently bound. | 2417 """Identifies the port number to which the server is currently bound. |
2510 | 2418 |
2511 Returns: | 2419 Returns: |
2512 The numeric port number to which the server is currently bound. | 2420 The numeric port number to which the server is currently bound. |
2513 """ | 2421 """ |
2514 return self._server.server_address[1] | 2422 return self._server.server_address[1] |
2515 | 2423 |
2516 | 2424 |
2517 if __name__ == '__main__': | 2425 if __name__ == '__main__': |
2518 pyauto_functional.Main() | 2426 pyauto_functional.Main() |
OLD | NEW |