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

Side by Side Diff: chrome/test/functional/media/cns_test_base.py

Issue 10825051: Update CNS to run on chromeperf34 and CNS tests to run on windows perf_av bot. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 """Constrained network server (CNS) test base.""" 5 """Constrained network server (CNS) test base."""
6 6
7 import logging 7 import logging
8 import os 8 import os
9 import Queue 9 import Queue
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import threading 12 import threading
13 import urllib2 13 import urllib2
14 14
15 import pyauto 15 import pyauto
16 import pyauto_paths 16 import pyauto_paths
17 17
18 WINDOWS = 'win32' in sys.platform
DaleCurtis 2012/07/27 00:49:43 Is this the right way to check this? Why not os.na
shadi 2012/07/27 01:06:25 I used sys.platform since I found it being used in
19
18 # List of commonly used network constraints settings. 20 # List of commonly used network constraints settings.
19 # Each setting is a tuppe of the form: 21 # Each setting is a tuppe of the form:
20 # ('TEST_NAME', [BANDWIDTH_Kbps, LATENCY_ms, PACKET_LOSS_%]) 22 # ('TEST_NAME', [BANDWIDTH_Kbps, LATENCY_ms, PACKET_LOSS_%])
21 # 23 #
22 # Note: The test name should satisfy the regex [\w\.-]+ (check 24 # Note: The test name should satisfy the regex [\w\.-]+ (check
23 # tools/perf_expectations/tests/perf_expectations_unittest.py for details). It 25 # tools/perf_expectations/tests/perf_expectations_unittest.py for details). It
24 # is used to name the result graphs on the dashboards. 26 # is used to name the result graphs on the dashboards.
25 # 27 #
26 # The WiFi, DSL, and Cable settings were taken from webpagetest.org as 28 # The WiFi, DSL, and Cable settings were taken from webpagetest.org as
27 # approximations of their respective real world networks. The settings were 29 # approximations of their respective real world networks. The settings were
28 # based on 2011 FCC Broadband Data report (http://www.fcc.gov/document/ 30 # based on 2011 FCC Broadband Data report (http://www.fcc.gov/document/
29 # measuring-broadband-america-report-consumer-broadband-performance-us). 31 # measuring-broadband-america-report-consumer-broadband-performance-us).
30 DialUp = ('DialUp', [56, 120, 5]) 32 DialUp = ('DialUp', [56, 120, 5])
31 Slow = ('Slow', [256, 105, 1]) 33 Slow = ('Slow', [256, 105, 1])
32 Wifi = ('Wifi', [1024, 60, 0]) 34 Wifi = ('Wifi', [1024, 60, 0])
33 DSL = ('DSL', [1541, 50, 0]) 35 DSL = ('DSL', [1541, 50, 0])
34 Cable = ('Cable', [5120, 28, 0]) 36 Cable = ('Cable', [5120, 28, 0])
35 NoConstraints = ('NoConstraints', [0, 0, 0]) 37 NoConstraints = ('NoConstraints', [0, 0, 0])
36 38
37 # Path to CNS executable relative to source root. 39 # Path to CNS executable relative to source root.
38 _CNS_PATH = os.path.join( 40 _CNS_PATH = os.path.join(
39 'media', 'tools', 'constrained_network_server', 'cns.py') 41 'media', 'tools', 'constrained_network_server', 'cns.py')
40 42
41 # Port to start the CNS on. 43 # Port to start the CNS on.
42 _CNS_PORT = 9000 44 _CNS_PORT = 9000
43 45
44 # Base CNS URL, only requires & separated parameter names appended. 46 # Base CNS URL, only requires & separated parameter names appended.
45 CNS_BASE_URL = 'http://127.0.0.1:%d/ServeConstrained?' % _CNS_PORT 47 CNS_BASE_URL = 'http://127.0.0.1:%d/ServeConstrained?' % _CNS_PORT
DaleCurtis 2012/07/27 00:49:43 if else block?
shadi 2012/07/27 01:06:25 Done.
48 if WINDOWS:
49 CNS_BASE_URL = 'http://chromeperf34.chrome:%d/ServeConstrained?' % _CNS_PORT
46 50
47 # Used for server sanity check. 51 # Used for server sanity check.
48 _TEST_VIDEO = 'roller.webm' 52 _TEST_VIDEO = 'roller.webm'
49 53
50 # Directory root to serve files from. 54 # Directory root to serve files from.
51 _ROOT_PATH = os.path.join(pyauto.PyUITest.DataDir(), 'pyauto_private', 'media') 55 _ROOT_PATH = os.path.join(pyauto.PyUITest.DataDir(), 'pyauto_private', 'media')
52 56
53 57
54 class CNSTestBase(pyauto.PyUITest): 58 class CNSTestBase(pyauto.PyUITest):
55 """CNS test base hadles startup and teardown of CNS server.""" 59 """CNS test base hadles startup and teardown of CNS server."""
56 60
57 def __init__(self, *args, **kwargs): 61 def __init__(self, *args, **kwargs):
58 """Initialize CNSTestBase by setting the arguments for CNS server. 62 """Initialize CNSTestBase by setting the arguments for CNS server.
59 63
60 Args: 64 Args:
61 Check cns.py command line argument list for details. 65 Check cns.py command line argument list for details.
62 """ 66 """
63 self._port = kwargs.get('port', _CNS_PORT) 67 self._port = kwargs.get('port', _CNS_PORT)
64 self._interface = kwargs.get('interface', 'lo') 68 self._interface = kwargs.get('interface', 'lo')
65 self._www_root = kwargs.get('www_root', _ROOT_PATH) 69 self._www_root = kwargs.get('www_root', _ROOT_PATH)
66 self._verbose = kwargs.get('verbose', True) 70 self._verbose = kwargs.get('verbose', True)
67 self._expiry_time = kwargs.get('expiry_time', 0) 71 self._expiry_time = kwargs.get('expiry_time', 0)
68 self._socket_timeout = kwargs.get('socket_timeout') 72 self._socket_timeout = kwargs.get('socket_timeout')
69 pyauto.PyUITest.__init__(self, *args, **kwargs) 73 pyauto.PyUITest.__init__(self, *args, **kwargs)
70 74
71 def setUp(self): 75 def setUp(self):
72 """Starts the Constrained Network Server (CNS).""" 76 """Ensures the Constrained Network Server (CNS) server is up and running."""
77 if WINDOWS:
78 self._SetUpWin()
79 else:
80 self._SetUpLinux()
81
82 def _SetUpWin(self):
83 """Ensures the test can connect to the external CNS server."""
84 if self.WaitUntil(self._CanAccessServer, retry_sleep=3, timeout=30,
85 debug=False):
86 pyauto.PyUITest.setUp(self)
87 else:
88 self.fail('Failed to connect to CNS.')
89
90 def _SetUpLinux(self):
91 """Starts the CNS server locally."""
73 cmd = [sys.executable, os.path.join(pyauto_paths.GetSourceDir(), _CNS_PATH), 92 cmd = [sys.executable, os.path.join(pyauto_paths.GetSourceDir(), _CNS_PATH),
74 '--port', str(self._port), 93 '--port', str(self._port),
75 '--interface', self._interface, 94 '--interface', self._interface,
76 '--www-root', self._www_root, 95 '--www-root', self._www_root,
77 '--expiry-time', str(self._expiry_time)] 96 '--expiry-time', str(self._expiry_time)]
78 97
79 if self._socket_timeout: 98 if self._socket_timeout:
80 cmd.extend(['--socket-timeout', str(self._socket_timeout)]) 99 cmd.extend(['--socket-timeout', str(self._socket_timeout)])
81 if self._verbose: 100 if self._verbose:
82 cmd.append('-v') 101 cmd.append('-v')
(...skipping 13 matching lines...) Expand all
96 """Checks if the CNS server can serve a file with no network constraints.""" 115 """Checks if the CNS server can serve a file with no network constraints."""
97 test_url = ''.join([CNS_BASE_URL, 'f=', _TEST_VIDEO]) 116 test_url = ''.join([CNS_BASE_URL, 'f=', _TEST_VIDEO])
98 try: 117 try:
99 return urllib2.urlopen(test_url) is not None 118 return urllib2.urlopen(test_url) is not None
100 except Exception: 119 except Exception:
101 return False 120 return False
102 121
103 def tearDown(self): 122 def tearDown(self):
104 """Stops the Constrained Network Server (CNS).""" 123 """Stops the Constrained Network Server (CNS)."""
105 pyauto.PyUITest.tearDown(self) 124 pyauto.PyUITest.tearDown(self)
106 logging.debug('Stopping CNS server.') 125 if not WINDOWS:
107 # Do not use process.kill(), it will not clean up cns. 126 logging.debug('Stopping CNS server.')
108 self.Kill(self._cns_process.pid) 127 # Do not use process.kill(), it will not clean up cns.
109 # Need to wait since the process logger has a lock on the process stderr. 128 self.Kill(self._cns_process.pid)
110 self._cns_process.wait() 129 # Need to wait since the process logger has a lock on the process stderr.
111 self.assertFalse(self._cns_process.returncode is None) 130 self._cns_process.wait()
112 logging.debug('CNS server stopped.') 131 self.assertFalse(self._cns_process.returncode is None)
132 logging.debug('CNS server stopped.')
113 133
114 134
115 class ProcessLogger(threading.Thread): 135 class ProcessLogger(threading.Thread):
116 """A thread to log a process's stderr output.""" 136 """A thread to log a process's stderr output."""
117 137
118 def __init__(self, process): 138 def __init__(self, process):
119 """Starts the process logger thread. 139 """Starts the process logger thread.
120 140
121 Args: 141 Args:
122 process: The process to log. 142 process: The process to log.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 """ 181 """
162 # Convert relative test path into an absolute path. 182 # Convert relative test path into an absolute path.
163 tasks = Queue.Queue() 183 tasks = Queue.Queue()
164 for file_name in test_media_files: 184 for file_name in test_media_files:
165 for series_name, settings in network_constraints_settings: 185 for series_name, settings in network_constraints_settings:
166 logging.debug('Add test: %s\tSettings: %s\tMedia: %s', series_name, 186 logging.debug('Add test: %s\tSettings: %s\tMedia: %s', series_name,
167 settings, file_name) 187 settings, file_name)
168 tasks.put((series_name, settings, file_name)) 188 tasks.put((series_name, settings, file_name))
169 189
170 return tasks 190 return tasks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698