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

Side by Side Diff: isolate/isolate.py

Issue 9148004: Add script to run a test in a separate read-only directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: Created 8 years, 11 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
« no previous file with comments | « isolate/find_depot_tools.py ('k') | isolate/pylintrc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
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
6 """Recreates a tree of files and run an executable in it.
7
8 The executable is usually a test.
9
10 On linux, starts an xvfb X session to run the executable in.
11 """
12
13 import json
14 import logging
15 import optparse
16 import os
17 import re
18 import subprocess
19 import sys
20
21 import tree_creator
22 import xvfb
23
24
25 class ParserError(Exception):
26 pass
27
28
29 def recreate_tree(options):
30 """Reads a manifest and recreates a tree."""
31 os_map = {'cygwin': 'win32', 'linux2': 'linux', 'darwin': 'mac'}
32 platform = os_map.get(sys.platform, sys.platform)
33 infiles = ['.']
34 if options.manifest:
35 data = json.load(open(options.manifest, 'r'))
36 options.outdir = options.outdir or data['outdir']
37 options.indir = options.indir or data['indir']
38 infiles = data['infiles']
39 infiles += data.get('os', {}).get(platform, [])
40 if not options.outdir or not options.indir:
41 raise ParserError('Need at least -o and -i or -m')
42
43 outdir = {
44 'win32': 'build',
45 'linux': 'out',
46 'mac': 'xcodebuild',
47 }
48 variables = {
49 'OUTDIR': outdir[platform] + '/Debug/',
50 }
51 infiles = [i % variables for i in infiles]
52
53 action = tree_creator.HARDLINK
54 if options.dry_run:
55 action = tree_creator.DRY_RUN
56
57 def blacklist(item):
58 return (
59 re.match(r'.*\.svn$', item) != None or
60 re.match(r'.*\.pyc$', item) != None)
61
62 tree_creator.recreate_tree(
63 options.outdir, options.indir, infiles, action, blacklist)
64
65
66 def run_executable(options, args):
67 env = os.environ.copy()
68 # Many tests assume a English interface...
69 env['LANGUAGE'] = 'en'
70 # Used by base/base_paths_linux.cc
71 env['CR_SOURCE_ROOT'] = os.path.abspath(options.outdir).encode()
72 unique_name = 'not_so_unique'
73 try:
74 if not options.no_x:
75 # TODO(maruel): To not hardcode out/Debug.
76 env['DISPLAY'] = xvfb.start_virtualx(
77 unique_name,
78 os.path.join(options.outdir, 'out', 'Debug'))
79 os.chdir(options.outdir)
80 logging.info('Running %s' % ' '.join(args))
81 return subprocess.call(args, env=env)
82 finally:
83 if not options.no_x:
84 xvfb.stop_virtualx(unique_name)
85
86
87 def main():
88 parser = optparse.OptionParser(
89 usage='%prog [options] [test command line...]',
90 description=sys.modules[__name__].__doc__)
91 parser.allow_interspersed_args = False
92 parser.add_option('-v', '--verbose', action='count')
93 parser.add_option('--dry-run', action='store_true')
94 parser.add_option(
95 '-m', '--manifest',
96 help='json file containing the arguments.')
97 if sys.platform == 'linux2':
98 parser.add_option('--no_x', action='store_true')
99 parser.add_option('-i', '--indir')
100 parser.add_option('-o', '--outdir')
101 options, args = parser.parse_args()
102 if options.verbose == 2:
103 level = logging.DEBUG
104 elif options.verbose == 1:
105 level = logging.INFO
106 else:
107 level = logging.ERROR
108 logging.basicConfig(level=level)
109
110 if sys.platform != 'linux2':
111 options.no_x = True
112
113 try:
114 recreate_tree(options)
115 if not args:
116 return 0
117 return run_executable(options, args)
118 except ParserError, e:
119 parser.error(*e.args)
120
121
122 if __name__ == '__main__':
123 sys.exit(main())
OLDNEW
« no previous file with comments | « isolate/find_depot_tools.py ('k') | isolate/pylintrc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698