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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 class Isolate_check(IsolateBase): | 244 class Isolate_check(IsolateBase): |
237 LEVEL = isolate.NO_INFO | 245 LEVEL = isolate.NO_INFO |
238 | 246 |
239 def test_fail(self): | 247 def test_fail(self): |
240 self._execute('check', 'fail.isolate', [], False) | 248 self._execute('check', 'fail.isolate', [], False) |
241 self._expect_no_tree() | 249 self._expect_no_tree() |
242 self._expected_result(['fail.py'], None) | 250 self._expected_result(['fail.py'], None) |
243 | 251 |
244 def test_missing_trailing_slash(self): | 252 def test_missing_trailing_slash(self): |
245 try: | 253 try: |
246 self._execute('check', 'missing_trailing_slash.isolate', [], False) | 254 self._execute('check', 'missing_trailing_slash.isolate', [], False) |
nsylvain
2012/04/16 15:51:43
thanks!
| |
247 self.fail() | 255 self.fail() |
248 except subprocess.CalledProcessError: | 256 except subprocess.CalledProcessError: |
249 pass | 257 pass |
250 self._expect_no_tree() | 258 self._expect_no_tree() |
251 self._expect_no_result() | 259 self._expect_no_result() |
252 | 260 |
253 def test_non_existent(self): | 261 def test_non_existent(self): |
254 try: | 262 try: |
255 self._execute('check', 'non_existent.isolate', [], False) | 263 self._execute('check', 'non_existent.isolate', [], False) |
256 self.fail() | 264 self.fail() |
257 except subprocess.CalledProcessError: | 265 except subprocess.CalledProcessError: |
258 pass | 266 pass |
259 self._expect_no_tree() | 267 self._expect_no_tree() |
260 self._expect_no_result() | 268 self._expect_no_result() |
261 | 269 |
262 def test_no_run(self): | 270 def test_no_run(self): |
263 self._execute('check', 'no_run.isolate', [], False) | 271 self._execute('check', 'no_run.isolate', [], False) |
264 self._expect_no_tree() | 272 self._expect_no_tree() |
265 self._expected_result([], None) | 273 self._expected_result([], None) |
266 | 274 |
267 def test_touch_root(self): | 275 def test_touch_root(self): |
268 self._execute('check', 'touch_root.isolate', [], False) | 276 self._execute('check', 'touch_root.isolate', [], False) |
269 self._expect_no_tree() | 277 self._expect_no_tree() |
270 self._expected_result(['touch_root.py'], None) | 278 self._expected_result(['touch_root.py'], None) |
271 | 279 |
272 def test_with_flag(self): | 280 def test_with_flag(self): |
273 self._execute('check', 'with_flag.isolate', ['-V', 'FLAG=gyp'], False) | 281 self._execute('check', 'with_flag.isolate', ['-V', 'FLAG=gyp'], False) |
274 self._expect_no_tree() | 282 self._expect_no_tree() |
275 self._expected_result(['with_flag.py', 'gyp'], None) | 283 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'}) |
276 | 284 |
277 | 285 |
278 class Isolate_hashtable(IsolateBase): | 286 class Isolate_hashtable(IsolateBase): |
279 LEVEL = isolate.WITH_HASH | 287 LEVEL = isolate.WITH_HASH |
280 | 288 |
281 def _expected_hash_tree(self): | 289 def _expected_hash_tree(self): |
282 """Verifies the files written in the temporary directory.""" | 290 """Verifies the files written in the temporary directory.""" |
283 expected = [v['sha-1'] for v in self._gen_files(False).itervalues()] | 291 expected = [v['sha-1'] for v in self._gen_files(False).itervalues()] |
284 self.assertEquals(sorted(expected), self._result_tree()) | 292 self.assertEquals(sorted(expected), self._result_tree()) |
285 | 293 |
(...skipping 26 matching lines...) Expand all Loading... | |
312 self._expected_result([], None) | 320 self._expected_result([], None) |
313 | 321 |
314 def test_touch_root(self): | 322 def test_touch_root(self): |
315 self._execute('hashtable', 'touch_root.isolate', [], False) | 323 self._execute('hashtable', 'touch_root.isolate', [], False) |
316 self._expected_hash_tree() | 324 self._expected_hash_tree() |
317 self._expected_result(['touch_root.py'], None) | 325 self._expected_result(['touch_root.py'], None) |
318 | 326 |
319 def test_with_flag(self): | 327 def test_with_flag(self): |
320 self._execute('hashtable', 'with_flag.isolate', ['-V', 'FLAG=gyp'], False) | 328 self._execute('hashtable', 'with_flag.isolate', ['-V', 'FLAG=gyp'], False) |
321 self._expected_hash_tree() | 329 self._expected_hash_tree() |
322 self._expected_result(['with_flag.py', 'gyp'], None) | 330 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'}) |
323 | 331 |
324 | 332 |
325 class Isolate_remap(IsolateBase): | 333 class Isolate_remap(IsolateBase): |
326 LEVEL = isolate.STATS_ONLY | 334 LEVEL = isolate.STATS_ONLY |
327 | 335 |
328 def test_fail(self): | 336 def test_fail(self): |
329 self._execute('remap', 'fail.isolate', [], False) | 337 self._execute('remap', 'fail.isolate', [], False) |
330 self._expected_tree() | 338 self._expected_tree() |
331 self._expected_result(['fail.py'], None) | 339 self._expected_result(['fail.py'], None) |
332 | 340 |
(...skipping 21 matching lines...) Expand all Loading... | |
354 self._expected_result([], None) | 362 self._expected_result([], None) |
355 | 363 |
356 def test_touch_root(self): | 364 def test_touch_root(self): |
357 self._execute('remap', 'touch_root.isolate', [], False) | 365 self._execute('remap', 'touch_root.isolate', [], False) |
358 self._expected_tree() | 366 self._expected_tree() |
359 self._expected_result(['touch_root.py'], None) | 367 self._expected_result(['touch_root.py'], None) |
360 | 368 |
361 def test_with_flag(self): | 369 def test_with_flag(self): |
362 self._execute('remap', 'with_flag.isolate', ['-V', 'FLAG=gyp'], False) | 370 self._execute('remap', 'with_flag.isolate', ['-V', 'FLAG=gyp'], False) |
363 self._expected_tree() | 371 self._expected_tree() |
364 self._expected_result(['with_flag.py', 'gyp'], None) | 372 self._expected_result(['with_flag.py', 'gyp'], None, {u'FLAG': u'gyp'}) |
365 | 373 |
366 | 374 |
367 class Isolate_run(IsolateBase): | 375 class Isolate_run(IsolateBase): |
368 LEVEL = isolate.STATS_ONLY | 376 LEVEL = isolate.STATS_ONLY |
369 | 377 |
370 def _expect_empty_tree(self): | 378 def _expect_empty_tree(self): |
371 self.assertEquals([], self._result_tree()) | 379 self.assertEquals([], self._result_tree()) |
372 | 380 |
373 def test_fail(self): | 381 def test_fail(self): |
374 try: | 382 try: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 | 416 |
409 def test_touch_root(self): | 417 def test_touch_root(self): |
410 self._execute('run', 'touch_root.isolate', [], False) | 418 self._execute('run', 'touch_root.isolate', [], False) |
411 self._expect_empty_tree() | 419 self._expect_empty_tree() |
412 self._expected_result(['touch_root.py'], None) | 420 self._expected_result(['touch_root.py'], None) |
413 | 421 |
414 def test_with_flag(self): | 422 def test_with_flag(self): |
415 self._execute('run', 'with_flag.isolate', ['-V', 'FLAG=run'], False) | 423 self._execute('run', 'with_flag.isolate', ['-V', 'FLAG=run'], False) |
416 # Not sure about the empty tree, should be deleted. | 424 # Not sure about the empty tree, should be deleted. |
417 self._expect_empty_tree() | 425 self._expect_empty_tree() |
418 self._expected_result(['with_flag.py', 'run'], None) | 426 self._expected_result(['with_flag.py', 'run'], None, {u'FLAG': u'run'}) |
419 | 427 |
420 | 428 |
421 class Isolate_trace(IsolateBase): | 429 class Isolate_trace(IsolateBase): |
422 LEVEL = isolate.STATS_ONLY | 430 LEVEL = isolate.STATS_ONLY |
423 | 431 |
424 @staticmethod | 432 @staticmethod |
425 def _to_string(values): | 433 def _to_string(values): |
426 buf = cStringIO.StringIO() | 434 buf = cStringIO.StringIO() |
427 isolate.trace_inputs.pretty_print(values, buf) | 435 isolate.trace_inputs.pretty_print(values, buf) |
428 return buf.getvalue() | 436 return buf.getvalue() |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 }, | 496 }, |
489 }], | 497 }], |
490 ], | 498 ], |
491 } | 499 } |
492 self.assertEquals(self._to_string(expected), out) | 500 self.assertEquals(self._to_string(expected), out) |
493 | 501 |
494 def test_with_flag(self): | 502 def test_with_flag(self): |
495 out = self._execute( | 503 out = self._execute( |
496 'trace', 'with_flag.isolate', ['-V', 'FLAG=trace'], True) | 504 'trace', 'with_flag.isolate', ['-V', 'FLAG=trace'], True) |
497 self._expect_no_tree() | 505 self._expect_no_tree() |
498 self._expected_result(['with_flag.py', 'trace'], None) | 506 self._expected_result(['with_flag.py', 'trace'], None, {u'FLAG': u'trace'}) |
499 expected = { | 507 expected = { |
500 'conditions': [ | 508 'conditions': [ |
501 ['OS=="%s"' % isolate.trace_inputs.get_flavor(), { | 509 ['OS=="%s"' % isolate.trace_inputs.get_flavor(), { |
502 'variables': { | 510 'variables': { |
503 isolate.trace_inputs.KEY_TRACKED: [ | 511 isolate.trace_inputs.KEY_TRACKED: [ |
504 'with_flag.py', | 512 'with_flag.py', |
505 ], | 513 ], |
506 isolate.trace_inputs.KEY_UNTRACKED: [ | 514 isolate.trace_inputs.KEY_UNTRACKED: [ |
507 'files1/', | 515 'files1/', |
508 ], | 516 ], |
509 }, | 517 }, |
510 }], | 518 }], |
511 ], | 519 ], |
512 } | 520 } |
513 self.assertEquals(self._to_string(expected), out) | 521 self.assertEquals(self._to_string(expected), out) |
514 | 522 |
515 | 523 |
516 | 524 |
517 if __name__ == '__main__': | 525 if __name__ == '__main__': |
518 VERBOSE = '-v' in sys.argv | 526 VERBOSE = '-v' in sys.argv |
519 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 527 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
520 unittest.main() | 528 unittest.main() |
OLD | NEW |