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

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

Issue 10444052: Add Results class to hold structured data with details about each of the child processes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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
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 unittest 9 import unittest
10 import sys 10 import sys
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 " },\n" 88 " },\n"
89 " }, {\n" 89 " }, {\n"
90 " 'variables': {\n" 90 " 'variables': {\n"
91 " },\n" 91 " },\n"
92 " }],\n" 92 " }],\n"
93 " ],\n" 93 " ],\n"
94 "}\n") 94 "}\n")
95 self._test(value, expected) 95 self._test(value, expected)
96 96
97 97
98 def join_norm(*args):
99 """Joins and normalizes path in a single step."""
100 return unicode(os.path.normpath(os.path.join(*args)))
101
102
98 if trace_inputs.get_flavor() == 'linux': 103 if trace_inputs.get_flavor() == 'linux':
99 class StraceInputs(unittest.TestCase): 104 class StraceInputs(unittest.TestCase):
100 def _test_lines( 105 @staticmethod
101 self, lines, initial_cwd, expected_files, expected_non_existent): 106 def _load_context(lines, initial_cwd):
102 context = trace_inputs.Strace.Context(lambda _: False, initial_cwd) 107 context = trace_inputs.Strace.Context(lambda _: False, initial_cwd)
103 for line in lines: 108 for line in lines:
104 context.on_line(*line) 109 context.on_line(*line)
105 actual_files, actual_non_existent = context.resolve() 110 return context.to_results().flatten()
106 self.assertEquals(sorted(expected_files), sorted(actual_files)) 111
107 self.assertEquals( 112 def _test_lines(self, lines, initial_cwd, files, command=None):
108 sorted(expected_non_existent), sorted(actual_non_existent)) 113 command = command or ['../out/unittests']
MAD 2012/05/30 20:29:36 You don't actually use command... I don't get it..
M-A Ruel 2012/05/30 22:34:10 Oops, but it's used in the next CL; https://chromi
114 expected = {
115 'root': {
116 'children': [],
117 'command': None,
118 'executable': None,
119 'files': files,
120 'initial_cwd': initial_cwd,
121 'pid': 27,
MAD 2012/05/30 20:29:36 27? A _CONST maybe? Or at least a comment... :-)
M-A Ruel 2012/05/30 22:34:10 Did both.
122 }
123 }
124 if not files:
125 expected['root']['command'] = None
126 expected['root']['executable'] = None
127 self.assertEquals(expected, self._load_context(lines, initial_cwd))
128
129 def test_execve(self):
130 lines = [
131 (27, 'execve("/home/foo_bar_user/out/unittests", '
132 '["/home/foo_bar_user/out/unittests", '
133 '"--gtest_filter=AtExitTest.Basic"], [/* 44 vars */]) = 0'),
134 (27, 'open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 8'),
135 ]
136 files = [
137 {
138 'path': u'/home/foo_bar_user/out/unittests',
139 'size': -1,
140 },
141 {
142 'path': u'/home/foo_bar_user/src/out/unittests.log',
143 'size': -1,
144 },
145 ]
146 command = [
147 '/home/foo_bar_user/out/unittests', '--gtest_filter=AtExitTest.Basic',
148 ]
149 self._test_lines(lines, '/home/foo_bar_user/src', files, command)
109 150
110 def test_empty(self): 151 def test_empty(self):
111 self._test_lines([], None, [], []) 152 try:
153 self._load_context([], None)
154 self.fail()
155 except AssertionError:
156 pass
112 157
113 def test_close(self): 158 def test_close(self):
114 lines = [ 159 lines = [
115 (90, 'close(7) = 0'), 160 (27, 'close(7) = 0'),
116 ] 161 ]
117 self._test_lines(lines, None, [], []) 162 self._test_lines(lines, '/home/foo_bar_user/src', [])
118 163
119 def test_clone(self): 164 def test_clone(self):
120 # Grand-child with relative directory. 165 # Grand-child with relative directory.
121 lines = [ 166 lines = [
122 (86, 'clone(child_stack=0, flags=CLONE_CHILD_CLEARTID' 167 (27, 'clone(child_stack=0, flags=CLONE_CHILD_CLEARTID'
123 '|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f5350f829d0) = 14'), 168 '|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f5350f829d0) = 14'),
124 (86, ') = ? <unavailable>'),
125 (14, 'clone(child_stack=0, flags=CLONE_CHILD_CLEARTID' 169 (14, 'clone(child_stack=0, flags=CLONE_CHILD_CLEARTID'
126 '|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f5350f829d0) = 70'), 170 '|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f5350f829d0) = 70'),
127 (14, 'close(75) = 0'),
128 (70, 'open("%s", O_RDONLY) = 76' % os.path.basename(FILE_NAME)), 171 (70, 'open("%s", O_RDONLY) = 76' % os.path.basename(FILE_NAME)),
129 ] 172 ]
130 files = [ 173 size = os.stat(FILE_NAME).st_size
131 FILE_NAME, 174 expected = {
132 ] 175 'root': {
133 self._test_lines(lines, ROOT_DIR, files, []) 176 'children': [
177 {
178 'children': [
179 {
180 'children': [],
181 'command': None,
182 'executable': None,
183 'files': [
184 {
185 'path': unicode(FILE_NAME),
186 'size': size,
187 },
188 ],
189 'initial_cwd': ROOT_DIR,
190 'pid': 70,
191 },
192 ],
193 'command': None,
194 'executable': None,
195 'files': [],
196 'initial_cwd': ROOT_DIR,
197 'pid': 14,
198 },
199 ],
200 'command': None,
201 'executable': None,
202 'files': [],
203 'initial_cwd': ROOT_DIR,
204 'pid': 27,
205 },
206 }
207 self.assertEquals(expected, self._load_context(lines, ROOT_DIR))
208
209 def test_clone_chdir(self):
210 # Grand-child with relative directory.
211 lines = [
212 (27, 'execve("../out/unittests", '
213 '["../out/unittests"...], [/* 44 vars */]) = 0'),
214 (27, 'clone(child_stack=0, flags=CLONE_CHILD_CLEARTID'
215 '|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f5350f829d0) = 14'),
216 (14, 'chdir("/home_foo_bar_user/path1") = 0'),
217 (14, 'clone(child_stack=0, flags=CLONE_CHILD_CLEARTID'
218 '|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f5350f829d0) = 70'),
219 (27, 'chdir("/home_foo_bar_user/path2") = 0'),
220 (70, 'open("random.txt", O_RDONLY) = 76'),
221 ]
222 expected = {
223 'root': {
224 'children': [
225 {
226 'children': [
227 {
228 'children': [],
229 'command': None,
230 'executable': None,
231 'files': [
232 {
233 'path': u'/home_foo_bar_user/path1/random.txt',
234 'size': -1,
235 },
236 ],
237 'initial_cwd': '/home_foo_bar_user/path1',
238 'pid': 70,
239 },
240 ],
241 'command': None,
242 'executable': None,
243 # This is important, since no execve call was done, it didn't
244 # touch the executable file.
245 'files': [],
246 'initial_cwd': ROOT_DIR,
247 'pid': 14,
248 },
249 ],
250 'command': None,
251 'executable': None,
252 'files': [
253 {
254 'path': join_norm(ROOT_DIR, '../out/unittests'),
255 'size': -1,
256 },
257 ],
258 'initial_cwd': ROOT_DIR,
259 'pid': 27,
260 },
261 }
262 self.assertEquals(expected, self._load_context(lines, ROOT_DIR))
134 263
135 def test_open(self): 264 def test_open(self):
136 lines = [ 265 lines = [
137 (42, 'execve("../out/unittests", ' 266 (27, 'execve("../out/unittests", '
138 '["../out/unittests"...], [/* 44 vars */]) = 0'), 267 '["../out/unittests"...], [/* 44 vars */]) = 0'),
139 (42, 'open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 8'), 268 (27, 'open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 8'),
140 ] 269 ]
141 files = [ 270 files = [
142 u'/home/foo_bar_user/out/unittests', 271 {
143 u'/home/foo_bar_user/src/out/unittests.log', 272 'path': u'/home/foo_bar_user/out/unittests',
144 ] 273 'size': -1,
145 self._test_lines(lines, '/home/foo_bar_user/src', [], files) 274 },
275 {
276 'path': u'/home/foo_bar_user/src/out/unittests.log',
277 'size': -1,
278 },
279 ]
280 self._test_lines(lines, '/home/foo_bar_user/src', files)
146 281
147 def test_open_resumed(self): 282 def test_open_resumed(self):
148 lines = [ 283 lines = [
149 (42, 'execve("../out/unittests", ' 284 (27, 'execve("../out/unittests", '
150 '["../out/unittests"...], [/* 44 vars */]) = 0'), 285 '["../out/unittests"...], [/* 44 vars */]) = 0'),
151 (42, 'open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND ' 286 (27, 'open("out/unittests.log", O_WRONLY|O_CREAT|O_APPEND '
152 '<unfinished ...>'), 287 '<unfinished ...>'),
153 (42, '<... open resumed> ) = 3'), 288 (27, '<... open resumed> ) = 3'),
154 ] 289 ]
155 files = [ 290 files = [
156 u'/home/foo_bar_user/out/unittests', 291 {
157 u'/home/foo_bar_user/src/out/unittests.log', 292 'path': u'/home/foo_bar_user/out/unittests',
158 ] 293 'size': -1,
159 self._test_lines(lines, '/home/foo_bar_user/src', [], files) 294 },
295 {
296 'path': u'/home/foo_bar_user/src/out/unittests.log',
297 'size': -1,
298 },
299 ]
300 self._test_lines(lines, '/home/foo_bar_user/src', files)
160 301
161 def test_sig_unexpected(self): 302 def test_sig_unexpected(self):
162 lines = [ 303 lines = [
163 (27, 'exit_group(0) = ?'), 304 (27, 'exit_group(0) = ?'),
164 ] 305 ]
165 self._test_lines(lines, ROOT_DIR, [], []) 306 self._test_lines(lines, '/home/foo_bar_user/src', [])
307
308 def test_stray(self):
309 lines = [
310 (27, 'execve("../out/unittests", '
311 '["../out/unittests"...], [/* 44 vars */]) = 0'),
312 (27, ') = ? <unavailable>'),
313 ]
314 files = [
315 {
316 'path': u'/home/foo_bar_user/out/unittests',
317 'size': -1,
318 },
319 ]
320 self._test_lines(lines, '/home/foo_bar_user/src', files)
166 321
167 322
168 if __name__ == '__main__': 323 if __name__ == '__main__':
169 VERBOSE = '-v' in sys.argv 324 VERBOSE = '-v' in sys.argv
170 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR) 325 logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
171 unittest.main() 326 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698