• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
10import os
11import subprocess
12import sys
13
14sys.path.insert(0, os.getcwd())
15
16from common.py.utils import gs_utils
17from common.py.utils import shell_utils
18
19
20SKP_VERSION_FILE = 'SKP_VERSION'
21
22
23def _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
39def main(chrome_src_path, browser_executable, dry_run):
40  browser_executable = os.path.realpath(browser_executable)
41  dry_run = (dry_run == 'True')
42  skp_version = _get_skp_version()
43  print 'SKP_VERSION=%d' % skp_version
44
45  if os.environ.get('CHROME_HEADLESS'):
46    # Start Xvfb if running on a bot.
47    try:
48      shell_utils.run('sudo Xvfb :0 -screen 0 1280x1024x24 &', shell=True)
49    except Exception:
50      # It is ok if the above command fails, it just means that DISPLAY=:0
51      # is already up.
52      pass
53
54  upload_dir = 'playback_%d' % skp_version
55  webpages_playback_cmd = [
56    'python', os.path.join(os.path.dirname(os.path.realpath(__file__)),
57                           'webpages_playback.py'),
58    '--page_sets', 'all',
59    '--browser_executable', browser_executable,
60    '--non-interactive',
61    '--upload',
62    '--alternate_upload_dir', upload_dir,
63    '--chrome_src_path', chrome_src_path,
64  ]
65  if not dry_run:
66    webpages_playback_cmd.append('--upload_to_partner_bucket')
67
68  try:
69    shell_utils.run(webpages_playback_cmd)
70  finally:
71    # Clean up any leftover browser instances. This can happen if there are
72    # telemetry crashes, processes are not always cleaned up appropriately by
73    # the webpagereplay and telemetry frameworks.
74    procs = subprocess.check_output(['ps', 'ax'])
75    for line in procs.splitlines():
76      if browser_executable in line:
77        pid = line.strip().split(' ')[0]
78        if pid != str(os.getpid()) and not 'python' in line:
79          try:
80            shell_utils.run(['kill', '-9', pid])
81          except shell_utils.CommandFailedException as e:
82            print e
83        else:
84          print 'Refusing to kill self.'
85
86  print 'writing %s: %s' % (SKP_VERSION_FILE, skp_version)
87  with open(SKP_VERSION_FILE, 'w') as f:
88    f.write(str(skp_version))
89
90
91if '__main__' == __name__:
92  if len(sys.argv) != 4:
93    print >> sys.stderr, ('USAGE: %s <chrome src path> <browser executable> '
94                          '<dry run>')
95    sys.exit(1)
96  main(*sys.argv[1:])
97