diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-12 18:33:01 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-12 18:33:01 +0000 |
commit | a1b9abbd91e5cfa56fb2649ce86709fac623f4ed (patch) | |
tree | 6fe64dc4f4cbc10fa136d1a9d99e72b4fe152eaf | |
parent | 565b85c4a792aadae8975c5284b969b05d4bb879 (diff) | |
download | chromium_src-a1b9abbd91e5cfa56fb2649ce86709fac623f4ed.zip chromium_src-a1b9abbd91e5cfa56fb2649ce86709fac623f4ed.tar.gz chromium_src-a1b9abbd91e5cfa56fb2649ce86709fac623f4ed.tar.bz2 |
Fixes the relative path when the first input file is used as the command.
Add cacheinvalidation_unittests_run. It is a good example of a unit test not
needing any data file.
Saves the json result file in a human-readable layout.
Generate the list of valid modes dynamically.
R=akalin@chromium.org,csharp@chromium.org
BUG=
TEST=
Review URL: http://codereview.chromium.org/9668042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126174 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | third_party/cacheinvalidation/README.chromium | 3 | ||||
-rw-r--r-- | third_party/cacheinvalidation/cacheinvalidation.gyp | 26 | ||||
-rwxr-xr-x | tools/isolate/isolate.py | 49 | ||||
-rwxr-xr-x | tools/isolate/isolate_test.py | 20 |
4 files changed, 74 insertions, 24 deletions
diff --git a/third_party/cacheinvalidation/README.chromium b/third_party/cacheinvalidation/README.chromium index 704c510..5ddeb10 100644 --- a/third_party/cacheinvalidation/README.chromium +++ b/third_party/cacheinvalidation/README.chromium @@ -1,9 +1,10 @@ Name: Google Cache Invalidation API Short Name: google-cache-invalidation-api URL: http://code.google.com/p/google-cache-invalidation-api/ -Version: unknown +Version: r185 License: Apache 2.0 License File: files/src/google/cacheinvalidation/COPYING +Security Critical: no Description: This is the API to talk to the Google Cache Invalidation service. diff --git a/third_party/cacheinvalidation/cacheinvalidation.gyp b/third_party/cacheinvalidation/cacheinvalidation.gyp index dce6f6e..eff4515 100644 --- a/third_party/cacheinvalidation/cacheinvalidation.gyp +++ b/third_party/cacheinvalidation/cacheinvalidation.gyp @@ -212,5 +212,31 @@ 'cacheinvalidation', ], }, + { + 'target_name': 'cacheinvalidation_unittests_run', + 'type': 'none', + 'dependencies': [ + 'cacheinvalidation_unittests', + ], + 'actions': [ + { + 'action_name': 'isolate', + 'inputs': [ + '<(PRODUCT_DIR)/cacheinvalidation_unittests<(EXECUTABLE_SUFFIX)', + ], + 'outputs': [ + '<(PRODUCT_DIR)/cacheinvalidation_unittests.results', + ], + 'action': [ + 'python', + '<(DEPTH)/tools/isolate/isolate.py', + '--mode=<(tests_run)', + '--root', '<(DEPTH)', + '--result', '<@(_outputs)', + '<@(_inputs)', + ], + }, + ], + }, ], } diff --git a/tools/isolate/isolate.py b/tools/isolate/isolate.py index 6d16b77..ae5b8f4 100755 --- a/tools/isolate/isolate.py +++ b/tools/isolate/isolate.py @@ -28,9 +28,6 @@ import tempfile import tree_creator -# Needs to be coherent with the file's docstring above. -VALID_MODES = ('check', 'hashtable', 'remap', 'run') - def relpath(path, root): """os.path.relpath() that keeps trailing slash.""" @@ -75,8 +72,17 @@ def isolate(outdir, resultfile, indir, infiles, mode, read_only, cmd): infiles = tree_creator.expand_directories( indir, infiles, lambda x: re.match(r'.*\.(svn|pyc)$', x)) + # Note the relative current directory. + # In general, this path will be the path containing the gyp file where the + # target was defined. This relative directory may be created implicitely if a + # file from this directory is needed to run the test. Otherwise it won't be + # created and the process creation will fail. It's up to the caller to create + # this directory manually before starting the test. + relative_cwd = os.path.relpath(os.getcwd(), indir) + if not cmd: - cmd = [infiles[0]] + # Note that it is exactly the reverse of relative_cwd. + cmd = [os.path.join(os.path.relpath(indir, os.getcwd()), infiles[0])] if cmd[0].endswith('.py'): cmd.insert(0, sys.executable) @@ -86,26 +92,27 @@ def isolate(outdir, resultfile, indir, infiles, mode, read_only, cmd): if not outdir: outdir = os.path.dirname(resultfile) - result = mode_fn(outdir, indir, dictfiles, read_only, cmd) + result = mode_fn(outdir, indir, dictfiles, read_only, cmd, relative_cwd) if result == 0: # Saves the resulting file. out = { 'command': cmd, + 'relative_cwd': relative_cwd, 'files': dictfiles, } with open(resultfile, 'wb') as f: - json.dump(out, f) + json.dump(out, f, indent=2, sort_keys=True) return result -def MODEcheck(outdir, indir, dictfiles, read_only, cmd): +def MODEcheck(outdir, indir, dictfiles, read_only, cmd, relative_cwd): """No-op.""" return 0 -def MODEhashtable(outdir, indir, dictfiles, read_only, cmd): - """Ignores cmd and read_only.""" +def MODEhashtable(outdir, indir, dictfiles, read_only, cmd, relative_cwd): + """Ignores read_only, cmd and relative_cwd.""" for relfile, properties in dictfiles.iteritems(): infile = os.path.join(indir, relfile) outfile = os.path.join(outdir, properties['sha-1']) @@ -118,8 +125,8 @@ def MODEhashtable(outdir, indir, dictfiles, read_only, cmd): return 0 -def MODEremap(outdir, indir, dictfiles, read_only, cmd): - """Ignores cmd.""" +def MODEremap(outdir, indir, dictfiles, read_only, cmd, relative_cwd): + """Ignores cmd and relative_cwd.""" if not outdir: outdir = tempfile.mkdtemp(prefix='isolate') tree_creator.recreate_tree( @@ -129,18 +136,19 @@ def MODEremap(outdir, indir, dictfiles, read_only, cmd): return 0 -def MODErun(outdir, indir, dictfiles, read_only, cmd): - """Ignores outdir.""" +def MODErun(outdir, indir, dictfiles, read_only, cmd, relative_cwd): + """Ignores outdir and always uses a temporary directory.""" outdir = None try: outdir = tempfile.mkdtemp(prefix='isolate') tree_creator.recreate_tree( outdir, indir, dictfiles.keys(), tree_creator.HARDLINK) + cwd = os.path.join(outdir, relative_cwd) + if not os.path.isdir(cwd): + os.makedirs(cwd) if read_only: tree_creator.make_writable(outdir, True) - # Rebase the command to the right path. - cwd = os.path.join(outdir, os.path.relpath(os.getcwd(), indir)) logging.info('Running %s, cwd=%s' % (cmd, cwd)) return subprocess.call(cmd, cwd=cwd) finally: @@ -149,7 +157,14 @@ def MODErun(outdir, indir, dictfiles, read_only, cmd): tree_creator.rmtree(outdir) +def get_valid_modes(): + """Returns the modes that can be used.""" + return sorted( + i[4:] for i in dir(sys.modules[__name__]) if i.startswith('MODE')) + + def main(): + valid_modes = get_valid_modes() parser = optparse.OptionParser( usage='%prog [options] [inputs] -- [command line]', description=sys.modules[__name__].__doc__) @@ -158,8 +173,8 @@ def main(): parser.add_option( '-v', '--verbose', action='count', default=0, help='Use multiple times') parser.add_option( - '--mode', choices=VALID_MODES, - help='Determines the action to be taken: %s' % ', '.join(VALID_MODES)) + '--mode', choices=valid_modes, + help='Determines the action to be taken: %s' % ', '.join(valid_modes)) parser.add_option( '--result', metavar='FILE', help='Output file containing the json information about inputs') diff --git a/tools/isolate/isolate_test.py b/tools/isolate/isolate_test.py index f2d9252..d2fdc7c 100755 --- a/tools/isolate/isolate_test.py +++ b/tools/isolate/isolate_test.py @@ -44,9 +44,10 @@ class Isolate(unittest.TestCase): return (min_mode | 0111) if filename.endswith('.py') else min_mode expected = { u'command': - [unicode(sys.executable), u'isolate_test.py'] + + [unicode(sys.executable)] + [unicode(x) for x in args], u'files': dict((unicode(f), {u'mode': mode(f)}) for f in files), + u'relative_cwd': u'.', } if with_hash: for filename in expected[u'files']: @@ -88,7 +89,10 @@ class Isolate(unittest.TestCase): out = out[:out.index('')] modes = [re.match(r'^ (\w+) .+', l) for l in out] modes = tuple(m.group(1) for m in modes if m) - self.assertEquals(self.isolate.VALID_MODES, modes) + # Keep the list hard coded. + expected = ('check', 'hashtable', 'remap', 'run') + self.assertEquals(expected, modes) + self.assertEquals(expected, modes) for mode in modes: self.assertTrue(hasattr(self, 'test_%s' % mode), mode) self._expected_tree([]) @@ -100,7 +104,8 @@ class Isolate(unittest.TestCase): ] self._execute(cmd) self._expected_tree(['result']) - self._expected_result(False, ['isolate_test.py'], [], False) + self._expected_result( + False, ['isolate_test.py'], ['./isolate_test.py'], False) def test_check_non_existant(self): cmd = [ @@ -136,7 +141,7 @@ class Isolate(unittest.TestCase): ] self._execute(cmd) files = ['isolate_test.py', 'data/test_file1.txt', 'data/test_file2.txt'] - data = self._expected_result(True, files, [], False) + data = self._expected_result(True, files, ['./isolate_test.py'], False) self._expected_tree( [f['sha-1'] for f in data['files'].itervalues()] + ['result']) @@ -148,7 +153,8 @@ class Isolate(unittest.TestCase): ] self._execute(cmd) self._expected_tree(['isolate_test.py', 'result']) - self._expected_result(False, ['isolate_test.py'], [], False) + self._expected_result( + False, ['isolate_test.py'], ['./isolate_test.py'], False) def test_run(self): cmd = [ @@ -159,7 +165,9 @@ class Isolate(unittest.TestCase): ] self._execute(cmd) self._expected_tree(['result']) - self._expected_result(False, ['isolate_test.py'], ['--ok'], False) + # cmd[0] is not generated from infiles[0] so it's not using a relative path. + self._expected_result( + False, ['isolate_test.py'], ['isolate_test.py', '--ok'], False) def test_run_fail(self): cmd = [ |