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

Side by Side Diff: build/find_isolated_tests.py

Issue 180153005: Add a script that can discover *.isolated files in a directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 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 Scans build output directory for .isolated files, calculates their SHA1
8 hashes, stores final list in JSON document and then removes *.isolated files
9 found (to ensure no stale *.isolated stay around on the next build).
10
11 Used to figure out what tests were build in isolated mode to trigger these
12 tests to run on swarming.
13
14 For more info see:
15 https://sites.google.com/a/chromium.org/dev/developers/testing/isolated-testing
16 """
17
18 import glob
19 import hashlib
20 import json
21 import optparse
22 import os
23 import re
24 import sys
25
26
27 def hash_file(filepath):
28 """Calculates the hash of a file without reading it all in memory at once."""
29 digest = hashlib.sha1()
30 with open(filepath, 'rb') as f:
31 while True:
32 chunk = f.read(1024*1024)
33 if not chunk:
34 break
35 digest.update(chunk)
36 return digest.hexdigest()
37
38
39 def main():
40 parser = optparse.OptionParser(usage='%prog path [options]')
M-A Ruel 2014/02/28 18:56:04 I like description=sys.modules[__name__].__doc__,
Vadim Sh. 2014/02/28 19:12:18 Done.
41 parser.add_option('--output-json', help='File to dump JSON results into.')
42 options, args = parser.parse_args()
43
44 if len(args) != 1:
45 parser.error('Missing path.')
M-A Ruel 2014/02/28 18:56:04 s/path/build output directory/
Vadim Sh. 2014/02/28 19:12:18 Done.
46 outdir = args[0]
47
48 result = {}
49
50 # Get the file hash values and output the pair.
51 for filepath in sorted(glob.glob(os.path.join(outdir, '*.isolated'))):
52 test_name = os.path.splitext(os.path.basename(filepath))[0]
53 if re.match(r'^.+?\.\d$', test_name):
54 # It's a split .isolated file, e.g. foo.0.isolated. Ignore these.
55 continue
56
57 sha1_hash = hash_file(filepath)
58 os.remove(filepath)
59 if not options.output_json:
M-A Ruel 2014/02/28 18:56:04 If you don't plan to use the --output_json flag, d
Vadim Sh. 2014/02/28 19:12:18 That is actually exactly what I'm going to use. Ma
M-A Ruel 2014/02/28 19:14:00 Ok. Note that I do like flags in general, so you c
Vadim Sh. 2014/02/28 19:23:20 Good idea. Done.
60 print('%s %s' % (test_name, sha1_hash))
61 # TODO(csharp): Remove both the message and the deletion once the isolate
62 # tracked dependencies are inputs for the isolated files.
63 print('Deleted %s to ensure it is regenerated by the next build.' %
64 filepath)
65 else:
66 result[test_name] = sha1_hash
67
68 if options.output_json:
69 with open(options.output_json, 'wb') as f:
70 json.dump(result, f)
71
72 return 0
73
74
75 if __name__ == '__main__':
76 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698