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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « isolate/find_depot_tools.py ('k') | isolate/pylintrc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: isolate/isolate.py
===================================================================
--- isolate/isolate.py (revision 0)
+++ isolate/isolate.py (revision 0)
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Recreates a tree of files and run an executable in it.
+
+The executable is usually a test.
+
+On linux, starts an xvfb X session to run the executable in.
+"""
+
+import json
+import logging
+import optparse
+import os
+import re
+import subprocess
+import sys
+
+import tree_creator
+import xvfb
+
+
+class ParserError(Exception):
+ pass
+
+
+def recreate_tree(options):
+ """Reads a manifest and recreates a tree."""
+ os_map = {'cygwin': 'win32', 'linux2': 'linux', 'darwin': 'mac'}
+ platform = os_map.get(sys.platform, sys.platform)
+ infiles = ['.']
+ if options.manifest:
+ data = json.load(open(options.manifest, 'r'))
+ options.outdir = options.outdir or data['outdir']
+ options.indir = options.indir or data['indir']
+ infiles = data['infiles']
+ infiles += data.get('os', {}).get(platform, [])
+ if not options.outdir or not options.indir:
+ raise ParserError('Need at least -o and -i or -m')
+
+ outdir = {
+ 'win32': 'build',
+ 'linux': 'out',
+ 'mac': 'xcodebuild',
+ }
+ variables = {
+ 'OUTDIR': outdir[platform] + '/Debug/',
+ }
+ infiles = [i % variables for i in infiles]
+
+ action = tree_creator.HARDLINK
+ if options.dry_run:
+ action = tree_creator.DRY_RUN
+
+ def blacklist(item):
+ return (
+ re.match(r'.*\.svn$', item) != None or
+ re.match(r'.*\.pyc$', item) != None)
+
+ tree_creator.recreate_tree(
+ options.outdir, options.indir, infiles, action, blacklist)
+
+
+def run_executable(options, args):
+ env = os.environ.copy()
+ # Many tests assume a English interface...
+ env['LANGUAGE'] = 'en'
+ # Used by base/base_paths_linux.cc
+ env['CR_SOURCE_ROOT'] = os.path.abspath(options.outdir).encode()
+ unique_name = 'not_so_unique'
+ try:
+ if not options.no_x:
+ # TODO(maruel): To not hardcode out/Debug.
+ env['DISPLAY'] = xvfb.start_virtualx(
+ unique_name,
+ os.path.join(options.outdir, 'out', 'Debug'))
+ os.chdir(options.outdir)
+ logging.info('Running %s' % ' '.join(args))
+ return subprocess.call(args, env=env)
+ finally:
+ if not options.no_x:
+ xvfb.stop_virtualx(unique_name)
+
+
+def main():
+ parser = optparse.OptionParser(
+ usage='%prog [options] [test command line...]',
+ description=sys.modules[__name__].__doc__)
+ parser.allow_interspersed_args = False
+ parser.add_option('-v', '--verbose', action='count')
+ parser.add_option('--dry-run', action='store_true')
+ parser.add_option(
+ '-m', '--manifest',
+ help='json file containing the arguments.')
+ if sys.platform == 'linux2':
+ parser.add_option('--no_x', action='store_true')
+ parser.add_option('-i', '--indir')
+ parser.add_option('-o', '--outdir')
+ options, args = parser.parse_args()
+ if options.verbose == 2:
+ level = logging.DEBUG
+ elif options.verbose == 1:
+ level = logging.INFO
+ else:
+ level = logging.ERROR
+ logging.basicConfig(level=level)
+
+ if sys.platform != 'linux2':
+ options.no_x = True
+
+ try:
+ recreate_tree(options)
+ if not args:
+ return 0
+ return run_executable(options, args)
+ except ParserError, e:
+ parser.error(*e.args)
+
+
+if __name__ == '__main__':
+ sys.exit(main())
Property changes on: isolate/isolate.py
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
« 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