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

Unified Diff: chrome/test/functional/record_endure.py

Issue 10803002: Run Chrome Endure tests with network simulation via Web Page Replay. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix so that offline tests will work/Address Nirnimesh's comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/functional/record_endure.py
diff --git a/chrome/test/functional/record_endure.py b/chrome/test/functional/record_endure.py
new file mode 100755
index 0000000000000000000000000000000000000000..ce5e82305e6c9c6e8555d31a0305cb5ebf3c5b6d
--- /dev/null
+++ b/chrome/test/functional/record_endure.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Record webapp interactions using Web Page Replay for Endure test.
+
+Example:
+1) ./record_endure.py ChromeEndureGmailTest.wpr
+ perf.ChromeEndureGmailTest
+
+ The above command runs each test in perf.ChromeEndureGmailTest for
+ 30 secs and saves archive file to 'src/chrome/test/data/pyauto_private/
+ webpagereplay/ChromeEndureGmailTest.wpr' (default setting).
+
+2) ./record_endure.py --test-length=40 --out-dir='.'
+ ChromeEndureGmailTest.wpr perf.ChromeEndureGmailTest
+
+ The above command runs each test for 40 seconds and saves the archive to
+ current directory.
+
+Please make sure that the archive name matches the one that your Endure
+test will use.
+"""
+import optparse
+import os
+import subprocess
+import sys
+import perf
+import webpagereplay
+
+
+class PlainHelpFormatter(optparse.IndentedHelpFormatter):
+ """Format the help message of this script."""
+
+ def format_description(self, description):
+ if description:
+ return description + '\n'
+ else:
+ return ''
+
+
+class Recorder(object):
+ """Record webapp interactions of Endure tests via Web Page Replay."""
+
+ _PATH = {
+ 'out_dir':
+ 'src/chrome/test/data/pyauto_private/webpagereplay',
+ 'scripts':
+ 'src/chrome/test/data/chrome_endure/webpagereplay/wpr_deterministic.js',
+ 'perf_endure':
+ 'src/chrome/test/functional/perf_endure.py',
+ }
+
+ @classmethod
+ def _ParseArgs(cls):
+ parser = optparse.OptionParser(
+ usage='%prog [options] archive_name test1 [test2]...',
+ formatter=PlainHelpFormatter(),
+ description=__doc__)
+ message = 'Length of each test in seconds. Default value is 30 secs.'
+ parser.add_option('--test-length', type='int', default=30,
+ help=message)
+ message = ('Output directory of the archive. Default direcotry is ' +
+ cls._PATH['out_dir'])
+ parser.add_option('--out-dir', type='string', default=None,
+ help=message)
+ options, args = parser.parse_args()
+ if len(args) <= 1:
+ parser.error('Invalid arguments. Use --help to see usage.')
+ return options, args
+
+ @classmethod
+ def Main(cls):
+ """Set up Web Page Replay and run Endure tests."""
+ options, args = cls._ParseArgs()
+ test_length = options.test_length
+ # Use a greater value than test length to disable stats.
+ perf_stats_interval = test_length + 60
+ user_dir = os.path.abspath(options.out_dir) if options.out_dir else None
+ out_dir = user_dir or perf.FormatChromePath(
+ os.path.join(cls._PATH['out_dir']))
+ archive_path = os.path.join(out_dir, args[0])
+ tests = args[1:]
+ replay_options = [
+ '--record',
+ '--inject_scripts', perf.FormatChromePath(cls._PATH['scripts']),
+ ]
+ with webpagereplay.ReplayServer(archive_path, replay_options):
+ env = os.environ.copy()
+ env.update({
+ 'TEST_LENGTH': str(test_length),
+ 'PERF_STATS_INTERVAL': str(perf_stats_interval),
+ 'WPR_RECORD': '1',
+ 'DO_NOT_RESTART_PYTHON_FOR_PYAUTO': '1',
+ })
+
+ cmd = ['python', perf.FormatChromePath(cls._PATH['perf_endure'])]
+ cmd.extend(tests)
+ subprocess.call(cmd, env=env)
+ print 'Shutting down server.'
+ if os.path.exists(archive_path):
+ print 'Archive is saved to %s' % archive_path
+ return 0
+ else:
+ print 'Error in recording. See log: %s' % webpagereplay.LOG_PATH
+ return 1
+
+
+if __name__ == '__main__':
+ sys.exit(Recorder().Main())
« chrome/test/functional/perf_endure.py ('K') | « chrome/test/functional/perf_endure.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698