Commit 7d1cae48 authored by slamm@google.com's avatar slamm@google.com

Add Web Page Replay enabled page cycler tests to pyauto.

NOTRY=true
BUG=
TEST=


Review URL: https://chromiumcodereview.appspot.com/10411011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138466 0039d316-1c4b-4281-b951-d872f2087c98
parent b60ce45e
...@@ -336,7 +336,7 @@ deps = { ...@@ -336,7 +336,7 @@ deps = {
"/trunk/tools/deps2git@128331", "/trunk/tools/deps2git@128331",
"src/third_party/webpagereplay": "src/third_party/webpagereplay":
(Var("googlecode_url") % "web-page-replay") + "/trunk@465", (Var("googlecode_url") % "web-page-replay") + "/trunk@468",
} }
......
...@@ -586,6 +586,7 @@ ...@@ -586,6 +586,7 @@
'PERFORMANCE': { 'PERFORMANCE': {
'all': [ 'all': [
'perf', 'perf',
'-perf.WebPageReplayPageCyclerTest', # Disable new test until vetted.
], ],
'win': [ 'win': [
'-perf.GPUPerfTest', # Fails. Discuss with prachij@. '-perf.GPUPerfTest', # Fails. Discuss with prachij@.
......
This diff is collapsed.
...@@ -3,17 +3,7 @@ ...@@ -3,17 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""A class to help start/stop a Web Page Replay Server. """Start and stop Web Page Replay."""
The page cycler tests use this module to run Web Page Replay
(see tools/build/scripts/slave/runtest.py).
If run from the command-line, the module will launch Web Page Replay
and the specified test:
./webpagereplay_utils.py --help # list options
./webpagereplay_utils.py 2012Q2 # run a WPR-enabled test
"""
import logging import logging
import optparse import optparse
...@@ -33,24 +23,32 @@ USER_DATA_DIR = '{TEMP}/webpagereplay_utils-chrome' ...@@ -33,24 +23,32 @@ USER_DATA_DIR = '{TEMP}/webpagereplay_utils-chrome'
# The port numbers must match those in chrome/test/perf/page_cycler_test.cc. # The port numbers must match those in chrome/test/perf/page_cycler_test.cc.
HTTP_PORT = 8080 HTTP_PORT = 8080
HTTPS_PORT = 8413 HTTPS_PORT = 8413
REPLAY_HOST='127.0.0.1'
class ReplayError(Exception): class ReplayError(Exception):
"""Catch-all exception for the module.""" """Catch-all exception for the module."""
pass pass
class ReplayNotFoundError(Exception): class ReplayNotFoundError(ReplayError):
pass pass
class ReplayNotStartedError(Exception): class ReplayNotStartedError(ReplayError):
pass pass
class ReplayLauncher(object): class ReplayServer(object):
"""Start and Stop Web Page Replay.
Example:
with ReplayServer(replay_dir, archive_path, log_dir, replay_options):
self.NavigateToURL(start_url)
self.WaitUntil(...)
"""
LOG_FILE = 'log.txt' LOG_FILE = 'log.txt'
def __init__(self, replay_dir, archive_path, log_dir, replay_options=None): def __init__(self, replay_dir, archive_path, log_dir, replay_options=None):
"""Initialize ReplayLauncher. """Initialize ReplayServer.
Args: Args:
replay_dir: directory that has replay.py and related modules. replay_dir: directory that has replay.py and related modules.
...@@ -66,7 +64,7 @@ class ReplayLauncher(object): ...@@ -66,7 +64,7 @@ class ReplayLauncher(object):
self.log_name = os.path.join(self.log_dir, self.LOG_FILE) self.log_name = os.path.join(self.log_dir, self.LOG_FILE)
self.log_fh = None self.log_fh = None
self.proxy_process = None self.replay_process = None
self.wpr_py = os.path.join(self.replay_dir, 'replay.py') self.wpr_py = os.path.join(self.replay_dir, 'replay.py')
if not os.path.exists(self.wpr_py): if not os.path.exists(self.wpr_py):
...@@ -85,23 +83,10 @@ class ReplayLauncher(object): ...@@ -85,23 +83,10 @@ class ReplayLauncher(object):
os.makedirs(self.log_dir) os.makedirs(self.log_dir)
return open(self.log_name, 'w') return open(self.log_name, 'w')
def StartServer(self):
cmd_line = [self.wpr_py]
cmd_line.extend(self.wpr_options)
# TODO(slamm): Support choosing archive on-the-fly.
cmd_line.append(self.archive_path)
self.log_fh = self._OpenLogFile()
logging.debug('Starting Web-Page-Replay: %s', cmd_line)
self.proxy_process = subprocess.Popen(
cmd_line, stdout=self.log_fh, stderr=subprocess.STDOUT)
if not self.IsStarted():
raise ReplayNotStartedError(
'Web Page Replay failed to start. See the log file: ' + self.log_name)
def IsStarted(self): def IsStarted(self):
"""Checks to see if the server is up and running.""" """Checks to see if the server is up and running."""
for _ in range(5): for _ in range(5):
if self.proxy_process.poll() is not None: if self.replay_process.poll() is not None:
# The process has exited. # The process has exited.
break break
try: try:
...@@ -115,155 +100,38 @@ class ReplayLauncher(object): ...@@ -115,155 +100,38 @@ class ReplayLauncher(object):
time.sleep(1) time.sleep(1)
return False return False
def StartServer(self):
"""Start Web Page Replay and verify that it started.
Raises:
ReplayNotStartedError if Replay start-up fails.
"""
cmd_line = [self.wpr_py]
cmd_line.extend(self.wpr_options)
cmd_line.append(self.archive_path)
self.log_fh = self._OpenLogFile()
logging.debug('Starting Web-Page-Replay: %s', cmd_line)
self.replay_process = subprocess.Popen(
cmd_line, stdout=self.log_fh, stderr=subprocess.STDOUT)
if not self.IsStarted():
raise ReplayNotStartedError(
'Web Page Replay failed to start. See the log file: ' + self.log_name)
def StopServer(self): def StopServer(self):
if self.proxy_process: """Stop Web Page Replay."""
if self.replay_process:
logging.debug('Stopping Web-Page-Replay') logging.debug('Stopping Web-Page-Replay')
# Use a SIGINT here so that it can do graceful cleanup. # Use a SIGINT here so that it can do graceful cleanup.
# Otherwise, we will leave subprocesses hanging. # Otherwise, we will leave subprocesses hanging.
self.proxy_process.send_signal(signal.SIGINT) self.replay_process.send_signal(signal.SIGINT)
self.proxy_process.wait() self.replay_process.wait()
if self.log_fh: if self.log_fh:
self.log_fh.close() self.log_fh.close()
def __enter__(self):
"""Add support for with-statement."""
self.StartServer()
class ChromiumPaths(object): def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb):
"""Collect all the path handling together.""" """Add support for with-statement."""
PATHS = { self.StopServer()
'archives': 'src/data/page_cycler/webpagereplay',
'.wpr': 'src/data/page_cycler/webpagereplay/{TEST_NAME}.wpr',
'.wpr_alt': 'src/tools/page_cycler/webpagereplay/tests/{TEST_NAME}.wpr',
'start.html': 'src/tools/page_cycler/webpagereplay/start.html',
'extension': 'src/tools/page_cycler/webpagereplay/extension',
'replay': 'src/third_party/webpagereplay',
'logs': 'src/webpagereplay_logs/{TEST_EXE_NAME}',
}
def __init__(self, **replacements):
"""Initialize ChromiumPaths.
Args:
replacements: a dict of format replacements for PATHS such as
{'TEST_NAME': '2012Q2', 'TEST_EXE_NAME': 'performance_ui_tests'}.
"""
module_dir = os.path.dirname(__file__)
self.base_dir = os.path.abspath(os.path.join(
module_dir, '..', '..', '..', '..'))
self.replacements = replacements
def __getitem__(self, key):
path_parts = [x.format(**self.replacements)
for x in self.PATHS[key].split('/')]
return os.path.join(self.base_dir, *path_parts)
def LaunchChromium(chrome_exe, chromium_paths, test_name,
is_dns_forwarded, use_auto):
"""Launch chromium to run WPR-backed page cycler tests.
These options need to be kept in sync with
src/chrome/test/perf/page_cycler_test.cc.
"""
REPLAY_HOST='127.0.0.1'
user_data_dir = USER_DATA_DIR.format(**{'TEMP': tempfile.gettempdir()})
chromium_args = [
chrome_exe,
'--load-extension=%s' % chromium_paths['extension'],
'--testing-fixed-http-port=%s' % HTTP_PORT,
'--testing-fixed-https-port=%s' % HTTPS_PORT,
'--disable-background-networking',
'--enable-experimental-extension-apis',
'--enable-file-cookies',
'--enable-logging',
'--log-level=0',
'--enable-stats-table',
'--enable-benchmarking',
'--ignore-certificate-errors',
'--metrics-recording-only',
'--activate-on-launch',
'--no-first-run',
'--no-proxy-server',
'--user-data-dir=%s' % user_data_dir,
'--window-size=1280,1024',
]
if not is_dns_forwarded:
chromium_args.append('--host-resolver-rules=MAP * %s' % REPLAY_HOST)
start_url = 'file://%s?test=%s' % (chromium_paths['start.html'], test_name)
if use_auto:
start_url += '&auto=1'
chromium_args.append(start_url)
if os.path.exists(user_data_dir):
shutil.rmtree(user_data_dir)
os.makedirs(user_data_dir)
try:
logging.debug('Starting Chrome: %s', chromium_args)
retval = subprocess.call(chromium_args)
finally:
shutil.rmtree(user_data_dir)
def main():
log_level = logging.DEBUG
logging.basicConfig(level=log_level,
format='%(asctime)s %(filename)s:%(lineno)-3d'
' %(levelname)s %(message)s',
datefmt='%y%m%d %H:%M:%S')
option_parser = optparse.OptionParser(usage=USAGE)
option_parser.add_option(
'', '--auto', action='store_true', default=False,
help='Start test automatically.')
option_parser.add_option(
'', '--replay-dir', default=None,
help='Run replay from this directory instead of tools/build/third_party.')
replay_group = optparse.OptionGroup(option_parser,
'Options for replay.py', 'These options are passed through to replay.py.')
replay_group.add_option(
'', '--record', action='store_true', default=False,
help='Record a new WPR archive.')
replay_group.add_option( # use default that does not require sudo
'', '--dns_forwarding', default=False, action='store_true',
help='Forward DNS requests to the local replay server.')
option_parser.add_option_group(replay_group)
options, args = option_parser.parse_args()
if len(args) != 2:
option_parser.error('Need CHROME_EXE and TEST_NAME.')
return 1
chrome_exe, test_name = args
if not os.path.exists(chrome_exe):
print >>sys.stderr, 'Chrome path does not exist:', chrome_exe
return 1
chromium_paths = ChromiumPaths(
TEST_NAME=test_name,
TEST_EXE_NAME='webpagereplay_utils')
if os.path.exists(chromium_paths['archives']):
archive_path = chromium_paths['.wpr']
else:
archive_path = chromium_paths['.wpr_alt']
if not os.path.exists(archive_path) and not options.record:
print >>sys.stderr, 'Archive does not exist:', archive_path
return 1
replay_options = []
if options.record:
replay_options.append('--record')
if not options.dns_forwarding:
replay_options.append('--no-dns_forwarding')
if options.replay_dir:
replay_dir = options.replay_dir
else:
replay_dir = chromium_paths['replay']
wpr = ReplayLauncher(replay_dir, archive_path,
chromium_paths['logs'], replay_options)
try:
wpr.StartServer()
LaunchChromium(chrome_exe, chromium_paths, test_name,
options.dns_forwarding, options.auto)
finally:
wpr.StopServer()
return 0
if '__main__' == __name__:
sys.exit(main())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment