Skip to content

Commit

Permalink
Do not call extract_directories() in load_trace() anymore.
Browse files Browse the repository at this point in the history
There will be cases where this is not wanted.

NOTRY=true
[email protected]
BUG=
TEST=


Review URL: https://chromiumcodereview.appspot.com/10536019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140652 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
[email protected] committed Jun 5, 2012
1 parent 49742b3 commit e47aee0
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 20 deletions.
3 changes: 2 additions & 1 deletion tools/isolate/isolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ def MODEtrace(_outdir, state):
logfile,
True)

_, simplified = trace_inputs.load_trace(logfile, state.root_dir, api)
results = trace_inputs.load_trace(logfile, state.root_dir, api)
simplified = trace_inputs.extract_directories(state.root_dir, results.files)
variables = isolate_common.generate_dict(
(f.path for f in simplified),
state.result.relative_cwd,
Expand Down
7 changes: 3 additions & 4 deletions tools/isolate/trace_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2406,8 +2406,7 @@ def load_trace(logfile, root_dir, api):
results = api.parse_log(logfile, get_blacklist(api))
if root_dir:
results = results.strip_root(root_dir)
simplified = extract_directories(root_dir, results.files)
return results, simplified
return results


def CMDclean(parser, args):
Expand Down Expand Up @@ -2467,8 +2466,8 @@ def CMDread(parser, args):

api = get_api()
try:
results, simplified = load_trace(options.log, options.root_dir, api)

results = load_trace(options.log, options.root_dir, api)
simplified = extract_directories(options.root_dir, results.files)
if options.json:
write_json(sys.stdout, results.flatten(), False)
else:
Expand Down
89 changes: 75 additions & 14 deletions tools/isolate/trace_inputs_smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def setUp(self):
# - OSX replaces /usr/bin/python with /usr/bin/python2.7.
self.cwd = os.path.join(ROOT_DIR, u'data')
self.initial_cwd = self.cwd
self.expected_cwd = ROOT_DIR
if sys.platform == 'win32':
# Not supported on Windows.
self.initial_cwd = None
self.expected_cwd = None

# There's 3 kinds of references to python, self.executable,
# self.real_executable and self.naked_executable. It depends how python was
Expand Down Expand Up @@ -236,12 +238,11 @@ def _execute(self, command):
#self.assertEquals('', output)
return self.trace_inputs.load_trace(self.log, ROOT_DIR, api)

def test_trace_wrong_path(self):
# Deliberately start the trace from the wrong path. Starts it from the
# directory 'data' so 'data/data/trace_inputs/child1.py' is not accessible,
# so child2.py process is not started.
results, simplified = self._execute(self.get_child_command(False))
expected = {
def _gen_dict_wrong_path(self):
"""Returns the expected flattened Results when child1.py is called with the
wrong relative path.
"""
return {
'root': {
'children': [],
'command': [
Expand All @@ -254,13 +255,60 @@ def test_trace_wrong_path(self):
'initial_cwd': self.initial_cwd,
},
}
actual = results.flatten()
self.assertTrue(actual['root'].pop('pid'))
self.assertEquals(expected, actual)
self.assertEquals([], simplified)

def test_trace(self):
expected = {
def _gen_dict_full(self):
"""Returns the expected flattened Results when child1.py is called with
--child.
"""
return {
'root': {
'children': [
{
'children': [],
'command': ['python', 'child2.py'],
'executable': self.naked_executable,
'files': [
{
'path': os.path.join(u'data', 'trace_inputs', 'child2.py'),
'size': self._size(u'data', 'trace_inputs', 'child2.py'),
},
{
'path': os.path.join(u'data', 'trace_inputs', 'test_file.txt'),
'size': 4,
},
],
'initial_cwd': self.expected_cwd,
},
],
'command': [
self.executable,
os.path.join('data', 'trace_inputs', 'child1.py'),
'--child',
],
'executable': self.real_executable,
'files': [
{
'path': os.path.join(u'data', 'trace_inputs', 'child1.py'),
'size': self._size(u'data', 'trace_inputs', 'child1.py'),
},
{
'path': u'trace_inputs.py',
'size': self._size('trace_inputs.py'),
},
{
'path': u'trace_inputs_smoke_test.py',
'size': self._size('trace_inputs_smoke_test.py'),
},
],
'initial_cwd': self.expected_cwd,
},
}

def _gen_dict_full_gyp(self):
"""Returns the expected flattened Results when child1.py is called with
--child-gyp.
"""
return {
'root': {
'children': [
{
Expand Down Expand Up @@ -303,7 +351,20 @@ def test_trace(self):
'initial_cwd': self.initial_cwd,
},
}
results, simplified = self._execute(self.get_child_command(True))

def test_trace_wrong_path(self):
# Deliberately start the trace from the wrong path. Starts it from the
# directory 'data' so 'data/data/trace_inputs/child1.py' is not accessible,
# so child2.py process is not started.
results = self._execute(self.get_child_command(False))
expected = self._gen_dict_wrong_path()
actual = results.flatten()
self.assertTrue(actual['root'].pop('pid'))
self.assertEquals(expected, actual)

def test_trace(self):
expected = self._gen_dict_full_gyp()
results = self._execute(self.get_child_command(True))
actual = results.flatten()
self.assertTrue(actual['root'].pop('pid'))
self.assertTrue(actual['root']['children'][0].pop('pid'))
Expand All @@ -313,10 +374,10 @@ def test_trace(self):
u'trace_inputs.py',
u'trace_inputs_smoke_test.py',
]
simplified = self.trace_inputs.extract_directories(ROOT_DIR, results.files)
self.assertEquals(files, [f.path for f in simplified])



if __name__ == '__main__':
VERBOSE = '-v' in sys.argv
logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
Expand Down
3 changes: 2 additions & 1 deletion tools/isolate/trace_test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ def trace_test_case(
continue
duration = time.time() - start
try:
results, simplified = trace_inputs.load_trace(logname, root_dir, api)
results = trace_inputs.load_trace(logname, root_dir, api)
break
except trace_inputs.TracingFailure, e:
print >> sys.stderr, '\nTracing failed for: %s' % ' '.join(cmd)
print >> sys.stderr, str(e)
simplified = trace_inputs.extract_directories(root_dir, results.files)
if simplified:
variables = isolate_common.generate_dict(simplified, cwd_dir, product_dir)
else:
Expand Down

0 comments on commit e47aee0

Please sign in to comment.