| 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 trace_inputs | 20 import trace_inputs |
| 21 from utils import file_path |
| 21 from utils import threading_utils | 22 from utils import threading_utils |
| 22 | 23 |
| 23 FILENAME = os.path.basename(__file__) | 24 FILENAME = os.path.basename(__file__) |
| 24 REL_DATA = os.path.join(u'tests', 'trace_inputs') | 25 REL_DATA = os.path.join(u'tests', 'trace_inputs') |
| 25 VERBOSE = False | 26 VERBOSE = False |
| 26 | 27 |
| 27 # TODO(maruel): Have the kernel tracer on Windows differentiate between file | 28 # TODO(maruel): Have the kernel tracer on Windows differentiate between file |
| 28 # read or file write. | 29 # read or file write. |
| 29 MODE_R = trace_inputs.Results.File.READ if sys.platform != 'win32' else None | 30 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 | 31 MODE_W = trace_inputs.Results.File.WRITE if sys.platform != 'win32' else None |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 # started. | 66 # started. |
| 66 self.executable = sys.executable | 67 self.executable = sys.executable |
| 67 if sys.platform == 'darwin': | 68 if sys.platform == 'darwin': |
| 68 # /usr/bin/python is a thunk executable that decides which version of | 69 # /usr/bin/python is a thunk executable that decides which version of |
| 69 # python gets executed. | 70 # python gets executed. |
| 70 suffix = '.'.join(map(str, sys.version_info[0:2])) | 71 suffix = '.'.join(map(str, sys.version_info[0:2])) |
| 71 if os.access(self.executable + suffix, os.X_OK): | 72 if os.access(self.executable + suffix, os.X_OK): |
| 72 # So it'll look like /usr/bin/python2.7 | 73 # So it'll look like /usr/bin/python2.7 |
| 73 self.executable += suffix | 74 self.executable += suffix |
| 74 | 75 |
| 75 self.real_executable = trace_inputs.get_native_path_case( | 76 self.real_executable = file_path.get_native_path_case( |
| 76 unicode(self.executable)) | 77 unicode(self.executable)) |
| 77 self.tempdir = trace_inputs.get_native_path_case( | 78 self.tempdir = file_path.get_native_path_case( |
| 78 unicode(tempfile.mkdtemp(prefix='trace_smoke_test'))) | 79 unicode(tempfile.mkdtemp(prefix='trace_smoke_test'))) |
| 79 self.log = os.path.join(self.tempdir, 'log') | 80 self.log = os.path.join(self.tempdir, 'log') |
| 80 | 81 |
| 81 # self.naked_executable will only be naked on Windows. | 82 # self.naked_executable will only be naked on Windows. |
| 82 self.naked_executable = unicode(sys.executable) | 83 self.naked_executable = unicode(sys.executable) |
| 83 if sys.platform == 'win32': | 84 if sys.platform == 'win32': |
| 84 self.naked_executable = os.path.basename(sys.executable) | 85 self.naked_executable = os.path.basename(sys.executable) |
| 85 | 86 |
| 86 def tearDown(self): | 87 def tearDown(self): |
| 87 if self.tempdir: | 88 if self.tempdir: |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 u'tests/trace_inputs/child1.py'.replace('/', os.path.sep), | 446 u'tests/trace_inputs/child1.py'.replace('/', os.path.sep), |
| 446 u'tests/trace_inputs/child2.py'.replace('/', os.path.sep), | 447 u'tests/trace_inputs/child2.py'.replace('/', os.path.sep), |
| 447 u'tests/trace_inputs/files1/'.replace('/', os.path.sep), | 448 u'tests/trace_inputs/files1/'.replace('/', os.path.sep), |
| 448 u'tests/trace_inputs/test_file.txt'.replace('/', os.path.sep), | 449 u'tests/trace_inputs/test_file.txt'.replace('/', os.path.sep), |
| 449 u'tests/trace_inputs_smoke_test.py'.replace('/', os.path.sep), | 450 u'tests/trace_inputs_smoke_test.py'.replace('/', os.path.sep), |
| 450 u'trace_inputs.py', | 451 u'trace_inputs.py', |
| 451 ] | 452 ] |
| 452 def blacklist(f): | 453 def blacklist(f): |
| 453 return f.endswith(('.pyc', 'do_not_care.txt', '.git', '.svn')) | 454 return f.endswith(('.pyc', 'do_not_care.txt', '.git', '.svn')) |
| 454 simplified = trace_inputs.extract_directories( | 455 simplified = trace_inputs.extract_directories( |
| 455 trace_inputs.get_native_path_case(unicode(ROOT_DIR)), | 456 file_path.get_native_path_case(unicode(ROOT_DIR)), |
| 456 results.files, | 457 results.files, |
| 457 blacklist) | 458 blacklist) |
| 458 self.assertEqual(files, [f.path for f in simplified]) | 459 self.assertEqual(files, [f.path for f in simplified]) |
| 459 | 460 |
| 460 def test_trace_multiple(self): | 461 def test_trace_multiple(self): |
| 461 # Starts parallel threads and trace parallel child processes simultaneously. | 462 # Starts parallel threads and trace parallel child processes simultaneously. |
| 462 # Some are started from 'tests' directory, others from this script's | 463 # Some are started from 'tests' directory, others from this script's |
| 463 # directory. One trace fails. Verify everything still goes one. | 464 # directory. One trace fails. Verify everything still goes one. |
| 464 parallel = 8 | 465 parallel = 8 |
| 465 | 466 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 | 703 |
| 703 if __name__ == '__main__': | 704 if __name__ == '__main__': |
| 704 VERBOSE = '-v' in sys.argv | 705 VERBOSE = '-v' in sys.argv |
| 705 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 706 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
| 706 if VERBOSE: | 707 if VERBOSE: |
| 707 unittest.TestCase.maxDiff = None | 708 unittest.TestCase.maxDiff = None |
| 708 # Necessary for the dtrace logger to work around execve() hook. See | 709 # Necessary for the dtrace logger to work around execve() hook. See |
| 709 # trace_inputs.py for more details. | 710 # trace_inputs.py for more details. |
| 710 os.environ['TRACE_INPUTS_DTRACE_ENABLE_EXECVE'] = '1' | 711 os.environ['TRACE_INPUTS_DTRACE_ENABLE_EXECVE'] = '1' |
| 711 unittest.main() | 712 unittest.main() |
| OLD | NEW |