OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # coding=utf-8 | 2 # coding=utf-8 |
3 # Copyright 2012 The Swarming Authors. All rights reserved. | 3 # Copyright 2012 The Swarming Authors. All rights reserved. |
4 # Use of this source code is governed under the Apache License, Version 2.0 that | 4 # Use of this source code is governed under the Apache License, Version 2.0 that |
5 # can be found in the LICENSE file. | 5 # can be found in the LICENSE file. |
6 | 6 |
7 import functools | 7 import functools |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import os | 10 import os |
11 import shutil | 11 import shutil |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 import tempfile | 14 import tempfile |
15 import unicodedata | 15 import unicodedata |
16 import unittest | 16 import unittest |
17 | 17 |
18 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 18 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
19 sys.path.insert(0, ROOT_DIR) | 19 sys.path.insert(0, ROOT_DIR) |
20 | 20 |
21 import trace_inputs | 21 import trace_inputs |
| 22 from third_party.depot_tools import fix_encoding |
22 from utils import file_path | 23 from utils import file_path |
23 from utils import threading_utils | 24 from utils import threading_utils |
24 | 25 |
25 | 26 |
26 FILENAME = os.path.basename(__file__) | 27 FILENAME = os.path.basename(__file__) |
27 REL_DATA = os.path.join(u'tests', 'trace_inputs') | 28 REL_DATA = os.path.join(u'tests', 'trace_inputs') |
28 VERBOSE = False | 29 VERBOSE = False |
29 | 30 |
30 # TODO(maruel): Have the kernel tracer on Windows differentiate between file | 31 # TODO(maruel): Have the kernel tracer on Windows differentiate between file |
31 # read or file write. | 32 # read or file write. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 # self.naked_executable will only be naked on Windows. | 95 # self.naked_executable will only be naked on Windows. |
95 self.naked_executable = unicode(sys.executable) | 96 self.naked_executable = unicode(sys.executable) |
96 if sys.platform == 'win32': | 97 if sys.platform == 'win32': |
97 self.naked_executable = os.path.basename(sys.executable) | 98 self.naked_executable = os.path.basename(sys.executable) |
98 | 99 |
99 def tearDown(self): | 100 def tearDown(self): |
100 if self.tempdir: | 101 if self.tempdir: |
101 if VERBOSE: | 102 if VERBOSE: |
102 print 'Leaking: %s' % self.tempdir | 103 print 'Leaking: %s' % self.tempdir |
103 else: | 104 else: |
104 shutil.rmtree(self.tempdir) | 105 file_path.rmtree(self.tempdir) |
105 | 106 |
106 @staticmethod | 107 @staticmethod |
107 def get_child_command(from_data): | 108 def get_child_command(from_data): |
108 """Returns command to run the child1.py.""" | 109 """Returns command to run the child1.py.""" |
109 cmd = [sys.executable] | 110 cmd = [sys.executable] |
110 if from_data: | 111 if from_data: |
111 # When the gyp argument is specified, the command is started from --cwd | 112 # When the gyp argument is specified, the command is started from --cwd |
112 # directory. In this case, 'tests'. | 113 # directory. In this case, 'tests'. |
113 cmd.extend([os.path.join('trace_inputs', 'child1.py'), '--child-gyp']) | 114 cmd.extend([os.path.join('trace_inputs', 'child1.py'), '--child-gyp']) |
114 else: | 115 else: |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 self.assertTrue(actual['root'].pop('pid')) | 716 self.assertTrue(actual['root'].pop('pid')) |
716 self.assertEqual(expected, actual) | 717 self.assertEqual(expected, actual) |
717 trace_inputs.get_api().clean_trace(self.log) | 718 trace_inputs.get_api().clean_trace(self.log) |
718 files = sorted( | 719 files = sorted( |
719 unicodedata.normalize('NFC', i) | 720 unicodedata.normalize('NFC', i) |
720 for i in os.listdir(unicode(self.tempdir))) | 721 for i in os.listdir(unicode(self.tempdir))) |
721 self.assertEqual([filename, 'tricky_filename.py'], files) | 722 self.assertEqual([filename, 'tricky_filename.py'], files) |
722 | 723 |
723 | 724 |
724 if __name__ == '__main__': | 725 if __name__ == '__main__': |
| 726 fix_encoding.fix_encoding() |
725 VERBOSE = '-v' in sys.argv | 727 VERBOSE = '-v' in sys.argv |
726 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) | 728 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) |
727 if VERBOSE: | 729 if VERBOSE: |
728 unittest.TestCase.maxDiff = None | 730 unittest.TestCase.maxDiff = None |
729 # Necessary for the dtrace logger to work around execve() hook. See | 731 # Necessary for the dtrace logger to work around execve() hook. See |
730 # trace_inputs.py for more details. | 732 # trace_inputs.py for more details. |
731 os.environ['TRACE_INPUTS_DTRACE_ENABLE_EXECVE'] = '1' | 733 os.environ['TRACE_INPUTS_DTRACE_ENABLE_EXECVE'] = '1' |
732 print >> sys.stderr, 'Test are currently disabled' | 734 print >> sys.stderr, 'Test are currently disabled' |
733 sys.exit(0) | 735 sys.exit(0) |
734 #unittest.main() | 736 #unittest.main() |
OLD | NEW |