OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import cStringIO | 6 import cStringIO |
7 import hashlib | 7 import hashlib |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 v[u'timestamp'] = int(round(filestats.st_mtime)) | 112 v[u'timestamp'] = int(round(filestats.st_mtime)) |
113 | 113 |
114 if self.LEVEL >= isolate.WITH_HASH: | 114 if self.LEVEL >= isolate.WITH_HASH: |
115 for filename in files: | 115 for filename in files: |
116 # Calculate our hash. | 116 # Calculate our hash. |
117 h = hashlib.sha1() | 117 h = hashlib.sha1() |
118 h.update(open(os.path.join(root_dir, filename), 'rb').read()) | 118 h.update(open(os.path.join(root_dir, filename), 'rb').read()) |
119 files[filename][u'sha-1'] = unicode(h.hexdigest()) | 119 files[filename][u'sha-1'] = unicode(h.hexdigest()) |
120 return files | 120 return files |
121 | 121 |
122 def _expected_result(self, args, read_only): | 122 def _expected_result(self, args, read_only, extra_vars=None): |
123 """Verifies self.result contains the expected data.""" | 123 """Verifies self.result contains the expected data.""" |
| 124 flavor = isolate.trace_inputs.get_flavor() |
124 expected = { | 125 expected = { |
125 u'files': self._gen_files(read_only), | 126 u'files': self._gen_files(read_only), |
| 127 u'read_only': read_only, |
126 u'relative_cwd': unicode(RELATIVE_CWD[self.case()]), | 128 u'relative_cwd': unicode(RELATIVE_CWD[self.case()]), |
127 u'read_only': read_only, | 129 u'resultdir': os.path.dirname(self.result), |
| 130 u'resultfile': self.result, |
| 131 u'variables': { |
| 132 u'EXECUTABLE_SUFFIX': '.exe' if flavor == 'win' else '', |
| 133 u'OS': unicode(flavor), |
| 134 }, |
128 } | 135 } |
| 136 expected['variables'].update(extra_vars or {}) |
129 if args: | 137 if args: |
130 expected[u'command'] = [u'python'] + [unicode(x) for x in args] | 138 expected[u'command'] = [u'python'] + [unicode(x) for x in args] |
131 else: | 139 else: |
132 expected[u'command'] = [] | 140 expected[u'command'] = [] |
133 | 141 |
134 self.assertEquals(expected, json.load(open(self.result, 'rb'))) | 142 self.assertEquals(expected, json.load(open(self.result, 'rb'))) |
135 return expected | 143 return expected |
136 | 144 |
137 def _expect_no_result(self): | 145 def _expect_no_result(self): |
138 self.assertFalse(os.path.exists(self.result)) | 146 self.assertFalse(os.path.exists(self.result)) |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 self._expected_result([], None) | 269 self._expected_result([], None) |
262 | 270 |
263 def test_touch_root(self): | 271 def test_touch_root(self): |
264 self._execute() | 272 self._execute() |
265 self._expect_no_tree() | 273 self._expect_no_tree() |
266 self._expected_result(['touch_root.py'], None) | 274 self._expected_result(['touch_root.py'], None) |
267 | 275 |
268 def test_with_flag(self): | 276 def test_with_flag(self): |
269 self._execute(['-V', 'FLAG=gyp']) | 277 self._execute(['-V', 'FLAG=gyp']) |
270 self._expect_no_tree() | 278 self._expect_no_tree() |
271 self._expected_result(['with_flag.py', 'gyp'], None) | 279 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'}) |
272 | 280 |
273 | 281 |
274 class Isolate_hashtable(IsolateBase): | 282 class Isolate_hashtable(IsolateBase): |
275 LEVEL = isolate.WITH_HASH | 283 LEVEL = isolate.WITH_HASH |
276 | 284 |
277 def _expected_hash_tree(self): | 285 def _expected_hash_tree(self): |
278 """Verifies the files written in the temporary directory.""" | 286 """Verifies the files written in the temporary directory.""" |
279 expected = [v['sha-1'] for v in self._gen_files(False).itervalues()] | 287 expected = [v['sha-1'] for v in self._gen_files(False).itervalues()] |
280 self.assertEquals(sorted(expected), self._result_tree()) | 288 self.assertEquals(sorted(expected), self._result_tree()) |
281 | 289 |
(...skipping 26 matching lines...) Expand all Loading... |
308 self._expected_result([], None) | 316 self._expected_result([], None) |
309 | 317 |
310 def test_touch_root(self): | 318 def test_touch_root(self): |
311 self._execute() | 319 self._execute() |
312 self._expected_hash_tree() | 320 self._expected_hash_tree() |
313 self._expected_result(['touch_root.py'], None) | 321 self._expected_result(['touch_root.py'], None) |
314 | 322 |
315 def test_with_flag(self): | 323 def test_with_flag(self): |
316 self._execute(['-V', 'FLAG=gyp']) | 324 self._execute(['-V', 'FLAG=gyp']) |
317 self._expected_hash_tree() | 325 self._expected_hash_tree() |
318 self._expected_result(['with_flag.py', 'gyp'], None) | 326 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'}) |
319 | 327 |
320 | 328 |
321 class Isolate_remap(IsolateBase): | 329 class Isolate_remap(IsolateBase): |
322 LEVEL = isolate.STATS_ONLY | 330 LEVEL = isolate.STATS_ONLY |
323 | 331 |
324 def test_fail(self): | 332 def test_fail(self): |
325 self._execute() | 333 self._execute() |
326 self._expected_tree() | 334 self._expected_tree() |
327 self._expected_result(['fail.py'], None) | 335 self._expected_result(['fail.py'], None) |
328 | 336 |
(...skipping 21 matching lines...) Expand all Loading... |
350 self._expected_result([], None) | 358 self._expected_result([], None) |
351 | 359 |
352 def test_touch_root(self): | 360 def test_touch_root(self): |
353 self._execute() | 361 self._execute() |
354 self._expected_tree() | 362 self._expected_tree() |
355 self._expected_result(['touch_root.py'], None) | 363 self._expected_result(['touch_root.py'], None) |
356 | 364 |
357 def test_with_flag(self): | 365 def test_with_flag(self): |
358 self._execute(['-V', 'FLAG=gyp']) | 366 self._execute(['-V', 'FLAG=gyp']) |
359 self._expected_tree() | 367 self._expected_tree() |
360 self._expected_result(['with_flag.py', 'gyp'], None) | 368 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'}) |
361 | 369 |
362 | 370 |
363 class Isolate_run(IsolateBase): | 371 class Isolate_run(IsolateBase): |
364 LEVEL = isolate.STATS_ONLY | 372 LEVEL = isolate.STATS_ONLY |
365 | 373 |
366 def _expect_empty_tree(self): | 374 def _expect_empty_tree(self): |
367 self.assertEquals([], self._result_tree()) | 375 self.assertEquals([], self._result_tree()) |
368 | 376 |
369 def test_fail(self): | 377 def test_fail(self): |
370 try: | 378 try: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 412 |
405 def test_touch_root(self): | 413 def test_touch_root(self): |
406 self._execute() | 414 self._execute() |
407 self._expect_empty_tree() | 415 self._expect_empty_tree() |
408 self._expected_result(['touch_root.py'], None) | 416 self._expected_result(['touch_root.py'], None) |
409 | 417 |
410 def test_with_flag(self): | 418 def test_with_flag(self): |
411 self._execute(['-V', 'FLAG=run']) | 419 self._execute(['-V', 'FLAG=run']) |
412 # Not sure about the empty tree, should be deleted. | 420 # Not sure about the empty tree, should be deleted. |
413 self._expect_empty_tree() | 421 self._expect_empty_tree() |
414 self._expected_result(['with_flag.py', 'run'], None) | 422 self._expected_result(['with_flag.py', 'run'], None, {u'FLAG': u'run'}) |
415 | 423 |
416 | 424 |
417 class Isolate_trace(IsolateBase): | 425 class Isolate_trace(IsolateBase): |
418 LEVEL = isolate.STATS_ONLY | 426 LEVEL = isolate.STATS_ONLY |
419 | 427 |
420 @staticmethod | 428 @staticmethod |
421 def _to_string(values): | 429 def _to_string(values): |
422 buf = cStringIO.StringIO() | 430 buf = cStringIO.StringIO() |
423 isolate.trace_inputs.pretty_print(values, buf) | 431 isolate.trace_inputs.pretty_print(values, buf) |
424 return buf.getvalue() | 432 return buf.getvalue() |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 ], | 491 ], |
484 }, | 492 }, |
485 }], | 493 }], |
486 ], | 494 ], |
487 } | 495 } |
488 self.assertEquals(self._to_string(expected), out) | 496 self.assertEquals(self._to_string(expected), out) |
489 | 497 |
490 def test_with_flag(self): | 498 def test_with_flag(self): |
491 out = self._execute(['-V', 'FLAG=trace'], True) | 499 out = self._execute(['-V', 'FLAG=trace'], True) |
492 self._expect_no_tree() | 500 self._expect_no_tree() |
493 self._expected_result(['with_flag.py', 'trace'], None) | 501 self._expected_result(['with_flag.py', 'trace'], None, {u'FLAG': u'trace'}) |
494 expected = { | 502 expected = { |
495 'conditions': [ | 503 'conditions': [ |
496 ['OS=="%s"' % isolate.trace_inputs.get_flavor(), { | 504 ['OS=="%s"' % isolate.trace_inputs.get_flavor(), { |
497 'variables': { | 505 'variables': { |
498 isolate.trace_inputs.KEY_TRACKED: [ | 506 isolate.trace_inputs.KEY_TRACKED: [ |
499 'with_flag.py', | 507 'with_flag.py', |
500 ], | 508 ], |
501 isolate.trace_inputs.KEY_UNTRACKED: [ | 509 isolate.trace_inputs.KEY_UNTRACKED: [ |
502 'files1/', | 510 'files1/', |
503 ], | 511 ], |
504 }, | 512 }, |
505 }], | 513 }], |
506 ], | 514 ], |
507 } | 515 } |
508 self.assertEquals(self._to_string(expected), out) | 516 self.assertEquals(self._to_string(expected), out) |
509 | 517 |
510 | 518 |
511 | 519 |
512 if __name__ == '__main__': | 520 if __name__ == '__main__': |
513 VERBOSE = '-v' in sys.argv | 521 VERBOSE = '-v' in sys.argv |
514 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 522 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
515 unittest.main() | 523 unittest.main() |
OLD | NEW |