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

Side by Side 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: Tests by default do not have WPR support. Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5 """Record webapp interactions using Web Page Replay for Endure test.
dennis_jeffrey 2012/08/03 19:39:54 add a blank line right above this
fdeng1 2012/08/06 20:58:24 Done.
6
7 Example:
dennis_jeffrey 2012/08/03 19:39:54 before giving specific examples, mention the gener
fdeng1 2012/08/06 20:58:24 Done.
8 1) ./record_endure.py ChromeEndureGmailTest.wpr
9 perf.ChromeEndureGmailTest
10
11 The above command runs each test in perf.ChromeEndureGmailTest for
12 30 secs and saves archive file to 'src/chrome/test/data/pyauto_private/
13 webpagereplay/ChromeEndureGmailTest.wpr' (default setting).
14
15 2) ./record_endure.py --test-length=40 --out-dir='.'
16 ChromeEndureGmailTest.wpr perf.ChromeEndureGmailTest
17
18 The above command runs each test for 40 seconds and saves the archive to
19 current directory.
20
21 Please make sure that the archive name matches the one that your Endure
22 test will use.
23 """
24 import optparse
dennis_jeffrey 2012/08/03 19:39:54 add a blank line right above this
fdeng1 2012/08/06 20:58:24 Done.
25 import os
26 import subprocess
27 import sys
28 import perf
dennis_jeffrey 2012/08/03 19:39:54 add a blank line right above this to separate stan
fdeng1 2012/08/06 20:58:24 Done.
29 import webpagereplay
30
31
32 class PlainHelpFormatter(optparse.IndentedHelpFormatter):
33 """Format the help message of this script."""
34
35 def format_description(self, description):
36 if description:
37 return description + '\n'
38 else:
39 return ''
40
41
42 class Recorder(object):
43 """Record webapp interactions of Endure tests via Web Page Replay."""
44
45 _PATH = {
46 'out_dir':
dennis_jeffrey 2012/08/03 19:39:54 rather than having 2 inputs to represent the archi
fdeng1 2012/08/06 20:58:24 Done.
47 'src/chrome/test/data/pyauto_private/webpagereplay',
48 'scripts':
49 'src/chrome/test/data/chrome_endure/webpagereplay/wpr_deterministic.js',
50 'perf_endure':
dennis_jeffrey 2012/08/03 19:39:54 maybe we can remove this and just assume that perf
fdeng1 2012/08/06 20:58:24 Done.
51 'src/chrome/test/functional/perf_endure.py',
52 }
53
54 @classmethod
55 def _ParseArgs(cls):
56 parser = optparse.OptionParser(
57 usage='%prog [options] archive_name test1 [test2]...',
dennis_jeffrey 2012/08/03 19:39:54 test1 --> test_or_suite_1 test2 --> test_or_suite_
fdeng1 2012/08/06 20:58:24 Done.
58 formatter=PlainHelpFormatter(),
59 description=__doc__)
60 message = 'Length of each test in seconds. Default value is 30 secs.'
61 parser.add_option('--test-length', type='int', default=30,
62 help=message)
63 message = ('Output directory of the archive. Default direcotry is ' +
64 cls._PATH['out_dir'])
65 parser.add_option('--out-dir', type='string', default=None,
66 help=message)
67 options, args = parser.parse_args()
68 if len(args) <= 1:
69 parser.error('Invalid arguments. Use --help to see usage.')
70 return options, args
71
72 @classmethod
73 def Main(cls):
74 """Set up Web Page Replay and run Endure tests."""
75 options, args = cls._ParseArgs()
76 test_length = options.test_length
77 # Use a greater value than test length to disable stats.
78 perf_stats_interval = test_length + 60
79 user_dir = os.path.abspath(options.out_dir) if options.out_dir else None
80 out_dir = user_dir or perf.FormatChromePath(
81 os.path.join(cls._PATH['out_dir']))
82 archive_path = os.path.join(out_dir, args[0])
83 tests = args[1:]
84 replay_options = [
85 '--record',
86 '--inject_scripts', perf.FormatChromePath(cls._PATH['scripts']),
87 ]
88 with webpagereplay.ReplayServer(archive_path, replay_options):
89 env = os.environ.copy()
90 env.update({
91 'TEST_LENGTH': str(test_length),
92 'PERF_STATS_INTERVAL': str(perf_stats_interval),
93 'WPR_RECORD': '1',
94 'DO_NOT_RESTART_PYTHON_FOR_PYAUTO': '1',
95 })
96
97 cmd = ['python', perf.FormatChromePath(cls._PATH['perf_endure'])]
98 cmd.extend(tests)
99 subprocess.call(cmd, env=env)
dennis_jeffrey 2012/08/03 19:39:54 i think it's possible that an archive file might s
fdeng1 2012/08/06 20:58:24 Done.
100 print 'Shutting down server.'
101 if os.path.exists(archive_path):
102 print 'Archive is saved to %s' % archive_path
103 return 0
104 else:
105 print 'Error in recording. See log: %s' % webpagereplay.LOG_PATH
106 return 1
107
108
109 if __name__ == '__main__':
110 sys.exit(Recorder().Main())
OLDNEW
« 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