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 posixpath | |
12 import sys | |
13 | |
14 from build_step import BuildStep | |
15 from utils import old_gs_utils as gs_utils | |
16 from py.utils import shell_utils | |
17 | |
18 | |
19 class SKPsCapture(BuildStep): | |
20 """BuildStep that captures the buildbot SKPs.""" | |
21 | |
22 def __init__(self, timeout=10800, **kwargs): | |
23 super(SKPsCapture, self).__init__(timeout=timeout, **kwargs) | |
24 | |
25 def _get_skp_version(self): | |
26 """Find an unused SKP version.""" | |
27 current_skp_version = None | |
28 version_file = os.path.join('third_party', 'skia', 'SKP_VERSION') | |
29 with open(version_file) as f: | |
30 current_skp_version = int(f.read().rstrip()) | |
31 | |
32 # Find the first SKP version which has no uploaded SKPs. | |
33 new_version = current_skp_version + 1 | |
34 while True: | |
35 gs_path = posixpath.join( | |
36 gs_utils.DEFAULT_DEST_GSBASE, | |
37 self._storage_playback_dirs.PlaybackSkpDir(new_version)) | |
38 if not gs_utils.does_storage_object_exist(gs_path): | |
39 return new_version | |
40 new_version += 1 | |
41 | |
42 def _Run(self): | |
43 skp_version = self._get_skp_version() | |
44 print 'SKP_VERSION=%d' % skp_version | |
45 | |
46 try: | |
47 # Start Xvfb on the bot. | |
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 full_path_browser_executable = os.path.join( | |
55 os.getcwd(), self._args['browser_executable']) | |
56 | |
57 upload_dir = 'playback_%d' % skp_version | |
58 webpages_playback_cmd = [ | |
59 'python', os.path.join(os.path.dirname(os.path.realpath(__file__)), | |
60 'webpages_playback.py'), | |
61 '--page_sets', self._args['page_sets'], | |
62 '--browser_executable', full_path_browser_executable, | |
63 '--non-interactive', | |
64 '--upload_to_gs', | |
65 '--alternate_upload_dir', upload_dir, | |
66 ] | |
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 cleanup_cmd = [ | |
75 'pkill', '-9', '-f', full_path_browser_executable | |
76 ] | |
77 try: | |
78 shell_utils.run(cleanup_cmd) | |
79 except Exception: | |
80 # Do not fail the build step if the cleanup command fails. | |
81 pass | |
82 | |
83 | |
84 if '__main__' == __name__: | |
85 sys.exit(BuildStep.RunBuildStep(SKPsCapture)) | |
OLD | NEW |