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

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

Issue 9835084: Implementing stateful directory tracking for dtrace on OSX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase against http://codereview.chromium.org/9834052 Created 8 years, 8 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 logging 6 import logging
7 import os 7 import os
8 import shutil 8 import shutil
9 import subprocess 9 import subprocess
10 import sys 10 import sys
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 return out 51 return out
52 52
53 @staticmethod 53 @staticmethod
54 def _gyp(): 54 def _gyp():
55 return [ 55 return [
56 '--gyp', os.path.join('data', 'trace_inputs'), 56 '--gyp', os.path.join('data', 'trace_inputs'),
57 '--product', '.', # Not tested. 57 '--product', '.', # Not tested.
58 ] 58 ]
59 59
60 def test_trace(self): 60 def test_trace(self):
61 if sys.platform == 'linux2': 61 if sys.platform not in ('linux2', 'darwin'):
62 return self._test_trace_linux() 62 print 'WARNING: unsupported: %s' % sys.platform
63 if sys.platform == 'darwin': 63 return
64 return self._test_trace_mac()
65 print 'Unsupported: %s' % sys.platform
66
67 def test_trace_gyp(self):
68 if sys.platform == 'linux2':
69 return self._test_trace_gyp_linux()
70 if sys.platform == 'darwin':
71 return self._test_trace_gyp_mac()
72 print 'Unsupported: %s' % sys.platform
73
74 def _test_trace_linux(self):
75 expected_end = [ 64 expected_end = [
76 "Interesting: 4 reduced to 3", 65 "Interesting: 4 reduced to 3",
77 " data/trace_inputs/", 66 " data/trace_inputs/",
78 " trace_inputs.py", 67 " trace_inputs.py",
79 " trace_inputs_test.py", 68 " trace_inputs_test.py",
80 ] 69 ]
81 actual = self._execute(['trace_inputs_test.py', '--child1']).splitlines() 70 actual = self._execute(['trace_inputs_test.py', '--child1']).splitlines()
82 self.assertTrue(actual[0].startswith('Tracing... [')) 71 self.assertTrue(actual[0].startswith('Tracing... ['))
83 self.assertTrue(actual[1].startswith('Loading traces... ')) 72 self.assertTrue(actual[1].startswith('Loading traces... '))
84 self.assertTrue(actual[2].startswith('Total: ')) 73 self.assertTrue(actual[2].startswith('Total: '))
85 self.assertEquals("Non existent: 0", actual[3]) 74 self.assertEquals("Non existent: 0", actual[3])
86 # Ignore any Unexpected part. 75 # Ignore any Unexpected part.
87 # TODO(maruel): Make sure there is no Unexpected part, even in the case of 76 # TODO(maruel): Make sure there is no Unexpected part, even in the case of
88 # virtualenv usage. 77 # virtualenv usage.
89 self.assertEquals(expected_end, actual[-len(expected_end):]) 78 self.assertEquals(expected_end, actual[-len(expected_end):])
90 79
91 def _test_trace_gyp_linux(self): 80 def test_trace_gyp(self):
81 if sys.platform not in ('linux2', 'darwin'):
82 print 'WARNING: unsupported: %s' % sys.platform
83 return
92 expected = ( 84 expected = (
93 "{\n" 85 "{\n"
94 " 'variables': {\n" 86 " 'variables': {\n"
95 " 'isolate_files': [\n" 87 " 'isolate_files': [\n"
96 " '<(DEPTH)/trace_inputs.py',\n" 88 " '<(DEPTH)/trace_inputs.py',\n"
97 " '<(DEPTH)/trace_inputs_test.py',\n" 89 " '<(DEPTH)/trace_inputs_test.py',\n"
98 " ],\n" 90 " ],\n"
99 " 'isolate_dirs': [\n" 91 " 'isolate_dirs': [\n"
100 " './',\n" 92 " './',\n"
101 " ],\n" 93 " ],\n"
102 " },\n" 94 " },\n"
103 "},\n") 95 "},\n")
104 actual = self._execute(self._gyp() + ['trace_inputs_test.py', '--child1']) 96 actual = self._execute(self._gyp() + ['trace_inputs_test.py', '--child1'])
105 self.assertEquals(expected, actual) 97 self.assertEquals(expected, actual)
106 98
107 def _test_trace_mac(self):
108 # It is annoying in the case of dtrace because it requires root access.
109 # TODO(maruel): BUG: Note that child.py is missing.
110 expected = (
111 "Total: 2\n"
112 "Non existent: 0\n"
113 "Interesting: 2 reduced to 2\n"
114 " trace_inputs.py\n"
115 " trace_inputs_test.py\n")
116 actual = self._execute(
117 ['trace_inputs_test.py', '--child1']).splitlines(True)
118 self.assertTrue(actual[0].startswith('Tracing... ['))
119 self.assertTrue(actual[1].startswith('Loading traces... '))
120 self.assertEquals(expected, ''.join(actual[2:]))
121
122 def _test_trace_gyp_mac(self):
123 # It is annoying in the case of dtrace because it requires root access.
124 # TODO(maruel): BUG: Note that child.py is missing.
125 expected = (
126 "{\n"
127 " 'variables': {\n"
128 " 'isolate_files': [\n"
129 " '<(DEPTH)/trace_inputs.py',\n"
130 " '<(DEPTH)/trace_inputs_test.py',\n"
131 " ],\n"
132 " 'isolate_dirs': [\n"
133 " ],\n"
134 " },\n"
135 "},\n")
136 actual = self._execute(self._gyp() + ['trace_inputs_test.py', '--child1'])
137 self.assertEquals(expected, actual)
138
139 99
140 def child1(): 100 def child1():
141 print 'child1' 101 print 'child1'
142 # Implicitly force file opening. 102 # Implicitly force file opening.
143 import trace_inputs # pylint: disable=W0612 103 import trace_inputs # pylint: disable=W0612
144 # Do not wait for the child to exit. 104 # Do not wait for the child to exit.
145 # Use relative directory. 105 # Use relative directory.
146 subprocess.Popen( 106 subprocess.Popen(
147 ['python', 'child2.py'], cwd=os.path.join('data', 'trace_inputs')) 107 ['python', 'child2.py'], cwd=os.path.join('data', 'trace_inputs'))
148 return 0 108 return 0
149 109
150 110
151 def main(): 111 def main():
152 global VERBOSE 112 global VERBOSE
153 VERBOSE = '-v' in sys.argv 113 VERBOSE = '-v' in sys.argv
154 level = logging.DEBUG if VERBOSE else logging.ERROR 114 level = logging.DEBUG if VERBOSE else logging.ERROR
155 logging.basicConfig(level=level) 115 logging.basicConfig(level=level)
156 if len(sys.argv) == 1: 116 if len(sys.argv) == 1:
157 unittest.main() 117 unittest.main()
158 118
159 if sys.argv[1] == '--child1': 119 if sys.argv[1] == '--child1':
160 return child1() 120 return child1()
161 121
162 unittest.main() 122 unittest.main()
163 123
164 124
165 if __name__ == '__main__': 125 if __name__ == '__main__':
166 sys.exit(main()) 126 sys.exit(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