| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding=utf-8 | 2 # coding=utf-8 |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 import tempfile | 13 import tempfile |
| 14 import unicodedata | 14 import unicodedata |
| 15 import unittest | 15 import unittest |
| 16 | 16 |
| 17 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 17 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 18 sys.path.insert(0, ROOT_DIR) | 18 sys.path.insert(0, ROOT_DIR) |
| 19 | 19 |
| 20 import run_test_cases | 20 import run_isolated |
| 21 import trace_inputs | 21 import trace_inputs |
| 22 | 22 |
| 23 FILENAME = os.path.basename(__file__) | 23 FILENAME = os.path.basename(__file__) |
| 24 REL_DATA = os.path.join(u'tests', 'trace_inputs') | 24 REL_DATA = os.path.join(u'tests', 'trace_inputs') |
| 25 VERBOSE = False | 25 VERBOSE = False |
| 26 | 26 |
| 27 # TODO(maruel): Have the kernel tracer on Windows differentiate between file | 27 # TODO(maruel): Have the kernel tracer on Windows differentiate between file |
| 28 # read or file write. | 28 # read or file write. |
| 29 MODE_R = trace_inputs.Results.File.READ if sys.platform != 'win32' else None | 29 MODE_R = trace_inputs.Results.File.READ if sys.platform != 'win32' else None |
| 30 MODE_W = trace_inputs.Results.File.WRITE if sys.platform != 'win32' else None | 30 MODE_W = trace_inputs.Results.File.WRITE if sys.platform != 'win32' else None |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 def test_trace_multiple(self): | 466 def test_trace_multiple(self): |
| 467 # Starts parallel threads and trace parallel child processes simultaneously. | 467 # Starts parallel threads and trace parallel child processes simultaneously. |
| 468 # Some are started from 'tests' directory, others from this script's | 468 # Some are started from 'tests' directory, others from this script's |
| 469 # directory. One trace fails. Verify everything still goes one. | 469 # directory. One trace fails. Verify everything still goes one. |
| 470 parallel = 8 | 470 parallel = 8 |
| 471 | 471 |
| 472 def trace(tracer, cmd, cwd, tracename): | 472 def trace(tracer, cmd, cwd, tracename): |
| 473 resultcode, output = tracer.trace(cmd, cwd, tracename, True) | 473 resultcode, output = tracer.trace(cmd, cwd, tracename, True) |
| 474 return (tracename, resultcode, output) | 474 return (tracename, resultcode, output) |
| 475 | 475 |
| 476 progress = FakeProgress() | 476 with run_isolated.ThreadPool(parallel, parallel, 0) as pool: |
| 477 with run_test_cases.ThreadPool(progress, parallel, parallel, 0) as pool: | |
| 478 api = trace_inputs.get_api() | 477 api = trace_inputs.get_api() |
| 479 with api.get_tracer(self.log) as tracer: | 478 with api.get_tracer(self.log) as tracer: |
| 480 pool.add_task( | 479 pool.add_task( |
| 481 0, trace, tracer, self.get_child_command(False), ROOT_DIR, 'trace1') | 480 0, trace, tracer, self.get_child_command(False), ROOT_DIR, 'trace1') |
| 482 pool.add_task( | 481 pool.add_task( |
| 483 0, trace, tracer, self.get_child_command(True), self.cwd, 'trace2') | 482 0, trace, tracer, self.get_child_command(True), self.cwd, 'trace2') |
| 484 pool.add_task( | 483 pool.add_task( |
| 485 0, trace, tracer, self.get_child_command(False), ROOT_DIR, 'trace3') | 484 0, trace, tracer, self.get_child_command(False), ROOT_DIR, 'trace3') |
| 486 pool.add_task( | 485 pool.add_task( |
| 487 0, trace, tracer, self.get_child_command(True), self.cwd, 'trace4') | 486 0, trace, tracer, self.get_child_command(True), self.cwd, 'trace4') |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 708 |
| 710 if __name__ == '__main__': | 709 if __name__ == '__main__': |
| 711 VERBOSE = '-v' in sys.argv | 710 VERBOSE = '-v' in sys.argv |
| 712 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 711 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
| 713 if VERBOSE: | 712 if VERBOSE: |
| 714 unittest.TestCase.maxDiff = None | 713 unittest.TestCase.maxDiff = None |
| 715 # Necessary for the dtrace logger to work around execve() hook. See | 714 # Necessary for the dtrace logger to work around execve() hook. See |
| 716 # trace_inputs.py for more details. | 715 # trace_inputs.py for more details. |
| 717 os.environ['TRACE_INPUTS_DTRACE_ENABLE_EXECVE'] = '1' | 716 os.environ['TRACE_INPUTS_DTRACE_ENABLE_EXECVE'] = '1' |
| 718 unittest.main() | 717 unittest.main() |
| OLD | NEW |