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

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

Issue 10446052: Add Results.Process.executable and command. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments 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') | tools/isolate/trace_inputs_test.py » ('j') | 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 cStringIO 6 import cStringIO
7 import logging 7 import logging
8 import os 8 import os
9 import shutil 9 import shutil
10 import subprocess 10 import subprocess
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 '--cwd', 'data', 129 '--cwd', 'data',
130 '--product', '.', # Not tested. 130 '--product', '.', # Not tested.
131 ] + self.command(True) 131 ] + self.command(True)
132 actual = self._execute(cmd) 132 actual = self._execute(cmd)
133 self.assertEquals(expected_buffer.getvalue(), actual) 133 self.assertEquals(expected_buffer.getvalue(), actual)
134 134
135 135
136 class TraceInputsImport(TraceInputsBase): 136 class TraceInputsImport(TraceInputsBase):
137 def setUp(self): 137 def setUp(self):
138 super(TraceInputsImport, self).setUp() 138 super(TraceInputsImport, self).setUp()
139 import trace_inputs
140 self.trace_inputs = trace_inputs
139 self.cwd = os.path.join(ROOT_DIR, u'data') 141 self.cwd = os.path.join(ROOT_DIR, u'data')
140 self.initial_cwd = self.cwd 142 self.initial_cwd = self.cwd
141 if sys.platform == 'win32': 143 if sys.platform == 'win32':
142 # Still not supported on Windows. 144 # Still not supported on Windows.
143 self.initial_cwd = None 145 self.initial_cwd = None
146 self.executable = sys.executable
147 if sys.platform == 'darwin':
148 # /usr/bin/python is a thunk executable that decides which version of
149 # python gets executed.
150 suffix = '.'.join(map(str, sys.version_info[0:2]))
151 if os.access(self.executable + suffix, os.X_OK):
152 self.executable += suffix
153 self.real_executable = self.trace_inputs.get_native_path_case(
154 self.executable)
155 if sys.platform == 'darwin':
156 # Interestingly, only OSX does resolve the symlink manually before
157 # starting the executable.
158 if os.path.islink(self.real_executable):
159 self.real_executable = os.path.normpath(
160 os.path.join(
161 os.path.dirname(self.real_executable),
162 os.readlink(self.real_executable)))
163 self.naked_executable = sys.executable
164 if sys.platform == 'win32':
165 self.naked_executable = os.path.basename(sys.executable)
166
167 def tearDown(self):
168 del self.trace_inputs
169 super(TraceInputsImport, self).tearDown()
144 170
145 # Similar to TraceInputs test fixture except that it calls the function 171 # Similar to TraceInputs test fixture except that it calls the function
146 # directly, so the Results instance can be inspected. 172 # directly, so the Results instance can be inspected.
147 # Roughly, make sure the API is stable. 173 # Roughly, make sure the API is stable.
148 def _execute(self, command): 174 def _execute(self, command):
149 # Similar to what trace_test_cases.py does. 175 # Similar to what trace_test_cases.py does.
150 import trace_inputs 176 api = self.trace_inputs.get_api()
151 api = trace_inputs.get_api() 177 _, _ = self.trace_inputs.trace(
152 _, _ = trace_inputs.trace(
153 self.log, command, self.cwd, api, True) 178 self.log, command, self.cwd, api, True)
154 # TODO(maruel): Check 179 # TODO(maruel): Check
155 #self.assertEquals(0, returncode) 180 #self.assertEquals(0, returncode)
156 #self.assertEquals('', output) 181 #self.assertEquals('', output)
157 return trace_inputs.load_trace(self.log, ROOT_DIR, api) 182 return self.trace_inputs.load_trace(self.log, ROOT_DIR, api)
158 183
159 def test_trace_wrong_path(self): 184 def test_trace_wrong_path(self):
160 # Deliberately start the trace from the wrong path. Starts it from the 185 # Deliberately start the trace from the wrong path. Starts it from the
161 # directory 'data' so 'data/data/trace_inputs/child1.py' is not accessible, 186 # directory 'data' so 'data/data/trace_inputs/child1.py' is not accessible,
162 # so child2.py process is not started. 187 # so child2.py process is not started.
163 results, simplified = self._execute(self.command(False)) 188 results, simplified = self._execute(self.command(False))
164 expected = { 189 expected = {
165 'root': { 190 'root': {
166 'children': [], 191 'children': [],
167 'command': None, 192 'command': [
168 'executable': None, 193 self.executable,
194 os.path.join('data', 'trace_inputs', 'child1.py'),
195 '--child',
196 ],
197 'executable': self.real_executable,
169 'files': [], 198 'files': [],
170 'initial_cwd': self.initial_cwd, 199 'initial_cwd': self.initial_cwd,
171 }, 200 },
172 } 201 }
173 actual = results.flatten() 202 actual = results.flatten()
174 self.assertTrue(actual['root'].pop('pid')) 203 self.assertTrue(actual['root'].pop('pid'))
175 self.assertEquals(expected, actual) 204 self.assertEquals(expected, actual)
176 self.assertEquals([], simplified) 205 self.assertEquals([], simplified)
177 206
178 def test_trace(self): 207 def test_trace(self):
179 size_t_i_s = os.stat(FULLNAME).st_size 208 size_t_i_s = os.stat(FULLNAME).st_size
180 size_t_i = os.stat(os.path.join(ROOT_DIR, 'trace_inputs.py')).st_size 209 size_t_i = os.stat(os.path.join(ROOT_DIR, 'trace_inputs.py')).st_size
181 expected = { 210 expected = {
182 'root': { 211 'root': {
183 'children': [ 212 'children': [
184 { 213 {
185 'children': [], 214 'children': [],
186 'command': None, 215 'command': ['python', 'child2.py'],
187 'executable': None, 216 'executable': self.naked_executable,
188 'files': [ 217 'files': [
189 { 218 {
190 'path': os.path.join(u'data', 'trace_inputs', 'child2.py'), 219 'path': os.path.join(u'data', 'trace_inputs', 'child2.py'),
191 'size': 776, 220 'size': 776,
192 }, 221 },
193 { 222 {
194 'path': os.path.join(u'data', 'trace_inputs', 'test_file.txt'), 223 'path': os.path.join(u'data', 'trace_inputs', 'test_file.txt'),
195 'size': 4, 224 'size': 4,
196 }, 225 },
197 ], 226 ],
198 'initial_cwd': self.initial_cwd, 227 'initial_cwd': self.initial_cwd,
199 }, 228 },
200 ], 229 ],
201 'command': None, 230 'command': [
202 'executable': None, 231 self.executable,
232 os.path.join('trace_inputs', 'child1.py'),
233 '--child-gyp',
234 ],
235 'executable': self.real_executable,
203 'files': [ 236 'files': [
204 { 237 {
205 'path': os.path.join(u'data', 'trace_inputs', 'child1.py'), 238 'path': os.path.join(u'data', 'trace_inputs', 'child1.py'),
206 'size': 1364, 239 'size': 1364,
207 }, 240 },
208 { 241 {
209 'path': u'trace_inputs.py', 242 'path': u'trace_inputs.py',
210 'size': size_t_i, 243 'size': size_t_i,
211 }, 244 },
212 { 245 {
(...skipping 15 matching lines...) Expand all
228 u'trace_inputs_smoke_test.py', 261 u'trace_inputs_smoke_test.py',
229 ] 262 ]
230 self.assertEquals(files, [f.path for f in simplified]) 263 self.assertEquals(files, [f.path for f in simplified])
231 264
232 265
233 266
234 if __name__ == '__main__': 267 if __name__ == '__main__':
235 VERBOSE = '-v' in sys.argv 268 VERBOSE = '-v' in sys.argv
236 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) 269 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
237 unittest.main() 270 unittest.main()
OLDNEW
« no previous file with comments | « tools/isolate/trace_inputs.py ('k') | tools/isolate/trace_inputs_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698