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

Side by Side Diff: tools/isolate/trace_inputs_smoke_test.py

Issue 10541064: Add Strace parallel support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove maxDiff Created 8 years, 6 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 | « tools/isolate/trace_inputs.py ('k') | 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
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 json 6 import json
7 import logging 7 import logging
8 import os 8 import os
9 import shutil 9 import shutil
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import tempfile 12 import tempfile
13 import unittest 13 import unittest
14 14
15 import worker_pool
16
15 FULLNAME = os.path.abspath(__file__) 17 FULLNAME = os.path.abspath(__file__)
16 ROOT_DIR = os.path.dirname(FULLNAME) 18 ROOT_DIR = os.path.dirname(FULLNAME)
17 FILENAME = os.path.basename(__file__) 19 FILENAME = os.path.basename(__file__)
18 VERBOSE = False 20 VERBOSE = False
19 21
20 22
21 class CalledProcessError(subprocess.CalledProcessError): 23 class CalledProcessError(subprocess.CalledProcessError):
22 """Makes 2.6 version act like 2.7""" 24 """Makes 2.6 version act like 2.7"""
23 def __init__(self, returncode, cmd, output, cwd): 25 def __init__(self, returncode, cmd, output, cwd):
24 super(CalledProcessError, self).__init__(returncode, cmd) 26 super(CalledProcessError, self).__init__(returncode, cmd)
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 self.assertTrue(actual['root']['children'][0].pop('pid')) 372 self.assertTrue(actual['root']['children'][0].pop('pid'))
371 self.assertEquals(expected, actual) 373 self.assertEquals(expected, actual)
372 files = [ 374 files = [
373 os.path.join(u'data', 'trace_inputs') + os.path.sep, 375 os.path.join(u'data', 'trace_inputs') + os.path.sep,
374 u'trace_inputs.py', 376 u'trace_inputs.py',
375 u'trace_inputs_smoke_test.py', 377 u'trace_inputs_smoke_test.py',
376 ] 378 ]
377 simplified = self.trace_inputs.extract_directories(ROOT_DIR, results.files) 379 simplified = self.trace_inputs.extract_directories(ROOT_DIR, results.files)
378 self.assertEquals(files, [f.path for f in simplified]) 380 self.assertEquals(files, [f.path for f in simplified])
379 381
382 def test_trace_multiple(self):
383 if sys.platform != 'linux2':
384 # TODO(maruel): Soon!
385 return
386 # Starts PARALLEL threads and trace PARALLEL child processes simultaneously.
387 # Some are started from 'data' directory, others from this script's
388 # directory. One trace fails. Verify everything still goes one.
389 PARALLEL = 8
390
391 def trace(tracer, cmd, cwd, tracename):
392 resultcode, output = tracer.trace(
393 cmd, cwd, tracename, True)
394 return (tracename, resultcode, output)
395
396 with worker_pool.ThreadPool(PARALLEL) as pool:
397 api = self.trace_inputs.get_api()
398 with api.get_tracer(self.log) as tracer:
399 pool.add_task(
400 trace, tracer, self.get_child_command(False), ROOT_DIR, 'trace1')
401 pool.add_task(
402 trace, tracer, self.get_child_command(True), self.cwd, 'trace2')
403 pool.add_task(
404 trace, tracer, self.get_child_command(False), ROOT_DIR, 'trace3')
405 pool.add_task(
406 trace, tracer, self.get_child_command(True), self.cwd, 'trace4')
407 # Have this one fail since it's started from the wrong directory.
408 pool.add_task(
409 trace, tracer, self.get_child_command(False), self.cwd, 'trace5')
410 pool.add_task(
411 trace, tracer, self.get_child_command(True), self.cwd, 'trace6')
412 pool.add_task(
413 trace, tracer, self.get_child_command(False), ROOT_DIR, 'trace7')
414 pool.add_task(
415 trace, tracer, self.get_child_command(True), self.cwd, 'trace8')
416 trace_results = pool.join()
417 actual_results = api.parse_log(
418 self.log, self.trace_inputs.get_blacklist(api))
419 self.assertEquals(8, len(trace_results))
420 self.assertEquals(8, len(actual_results))
421
422 # Convert to dict keyed on the trace name, simpler to verify.
423 trace_results = dict((i[0], i[1:]) for i in trace_results)
424 actual_results = dict((x.pop('trace'), x) for x in actual_results)
425 self.assertEquals(sorted(trace_results), sorted(actual_results))
426
427 # It'd be nice to start different kinds of processes.
428 expected_results = [
429 self._gen_dict_full(),
430 self._gen_dict_full_gyp(),
431 self._gen_dict_full(),
432 self._gen_dict_full_gyp(),
433 self._gen_dict_wrong_path(),
434 self._gen_dict_full_gyp(),
435 self._gen_dict_full(),
436 self._gen_dict_full_gyp(),
437 ]
438 self.assertEquals(len(expected_results), len(trace_results))
439
440 # See the comment above about the trace that fails because it's started from
441 # the wrong directory.
442 BUSTED = 4
443 for index, key in enumerate(sorted(actual_results)):
444 self.assertEquals('trace%d' % (index + 1), key)
445 self.assertEquals(2, len(trace_results[key]))
446 # returncode
447 self.assertEquals(0 if index != BUSTED else 2, trace_results[key][0])
448 # output
449 self.assertEquals(actual_results[key]['output'], trace_results[key][1])
450
451 self.assertEquals(['output', 'results'], sorted(actual_results[key]))
452 results = actual_results[key]['results']
453 results = results.strip_root(ROOT_DIR)
454 actual = results.flatten()
455 self.assertTrue(actual['root'].pop('pid'))
456 if index != BUSTED:
457 self.assertTrue(actual['root']['children'][0].pop('pid'))
458 self.assertEquals(expected_results[index], actual)
380 459
381 if __name__ == '__main__': 460 if __name__ == '__main__':
382 VERBOSE = '-v' in sys.argv 461 VERBOSE = '-v' in sys.argv
383 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) 462 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
384 unittest.main() 463 unittest.main()
OLDNEW
« no previous file with comments | « tools/isolate/trace_inputs.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698