OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2014 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 | |
6 | |
7 """Run the webpages_playback automation script.""" | |
8 | |
9 | |
10 import os | |
11 import subprocess | |
12 import sys | |
13 | |
14 sys.path.insert(0, os.getcwd()) | |
15 | |
16 from common.py.utils import gs_utils | |
17 from common.py.utils import shell_utils | |
18 | |
19 | |
20 SKP_VERSION_FILE = 'SKP_VERSION' | |
21 | |
22 | |
23 def _get_skp_version(): | |
24 """Find an unused SKP version.""" | |
25 current_skp_version = None | |
26 with open(SKP_VERSION_FILE) as f: | |
27 current_skp_version = int(f.read().rstrip()) | |
28 | |
29 # Find the first SKP version which has no uploaded SKPs. | |
30 new_version = current_skp_version + 1 | |
31 while True: | |
32 gs_path = 'playback_%d/skps' % new_version | |
33 if not gs_utils.GSUtils().does_storage_object_exist('chromium-skia-gm', | |
34 gs_path): | |
35 return new_version | |
36 new_version += 1 | |
37 | |
38 | |
39 def main(chrome_src_path, browser_executable): | |
40 browser_executable = os.path.realpath(browser_executable) | |
41 skp_version = _get_skp_version() | |
42 print 'SKP_VERSION=%d' % skp_version | |
43 | |
44 if os.environ.get('CHROME_HEADLESS'): | |
45 # Start Xvfb if running on a bot. | |
46 try: | |
47 shell_utils.run('sudo Xvfb :0 -screen 0 1280x1024x24 &', shell=True) | |
48 except Exception: | |
49 # It is ok if the above command fails, it just means that DISPLAY=:0 | |
50 # is already up. | |
51 pass | |
52 | |
53 upload_dir = 'playback_%d' % skp_version | |
54 webpages_playback_cmd = [ | |
55 'python', os.path.join(os.path.dirname(os.path.realpath(__file__)), | |
56 'webpages_playback.py'), | |
57 '--page_sets', 'all', | |
58 '--browser_executable', browser_executable, | |
59 '--non-interactive', | |
60 '--upload_to_gs', | |
61 '--alternate_upload_dir', upload_dir, | |
62 '--chrome_src_path', chrome_src_path, | |
63 ] | |
64 | |
65 try: | |
66 shell_utils.run(webpages_playback_cmd) | |
67 finally: | |
68 # Clean up any leftover browser instances. This can happen if there are | |
69 # telemetry crashes, processes are not always cleaned up appropriately by | |
70 # the webpagereplay and telemetry frameworks. | |
71 procs = subprocess.check_output(['ps', 'ax']) | |
72 for line in procs.splitlines(): | |
73 if browser_executable in line: | |
74 pid = line.strip().split(' ')[0] | |
75 if pid != str(os.getpid()): | |
76 try: | |
77 shell_utils.run(['kill', '-9', pid]) | |
78 except shell_utils.CommandFailedException: | |
79 pass | |
rmistry
2014/10/17 12:44:50
Lets log the error here. I realize it was not logg
borenet
2014/10/17 13:21:43
Done. For the record, the failure should be prett
| |
80 else: | |
81 print 'Refusing to kill self.' | |
82 | |
83 print 'writing %s: %s' % (SKP_VERSION_FILE, skp_version) | |
84 with open(SKP_VERSION_FILE, 'w') as f: | |
85 f.write(str(skp_version)) | |
86 | |
87 | |
88 if '__main__' == __name__: | |
89 if len(sys.argv) != 3: | |
90 print >> sys.stderr, 'USAGE: %s <chrome src path> <browser executable>' | |
91 sys.exit(1) | |
92 main(*sys.argv[1:]) | |
OLD | NEW |