Skip to content

Commit 6ecdbc8

Browse files
committedOct 15, 2015
Factor the execution of the test method into a separate function to ensure that any exceptions that are thrown go out of scope and no longer hold references to SB objects that need to be freed before teardown.
Differential Revision: http://reviews.llvm.org/D13788 llvm-svn: 250467
1 parent c7cc6ec commit 6ecdbc8

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed
 

‎lldb/source/Target/Target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ Target::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp)
12761276
void
12771277
Target::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp)
12781278
{
1279-
// A module is being added to this target for the first time
1279+
// A module is being removed from this target.
12801280
if (m_valid)
12811281
{
12821282
ModuleList my_module_list;

‎lldb/test/lldbtest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"""
3333

3434
import abc
35+
import gc
3536
import glob
3637
import os, sys, traceback
3738
import os.path
@@ -2544,6 +2545,11 @@ def tearDown(self):
25442545
#import traceback
25452546
#traceback.print_stack()
25462547

2548+
# Ensure all the references to SB objects have gone away so that we can
2549+
# be sure that all test-specific resources have been freed before we
2550+
# attempt to delete the targets.
2551+
gc.collect()
2552+
25472553
# Delete the target(s) from the debugger as a general cleanup step.
25482554
# This includes terminating the process for each target, if any.
25492555
# We'd like to reuse the debugger for our next test without incurring

‎lldb/test/unittest2/case.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -353,32 +353,7 @@ def run(self, result=None):
353353
except Exception:
354354
result.addError(self, sys.exc_info())
355355
else:
356-
try:
357-
testMethod()
358-
except self.failureException:
359-
result.addFailure(self, sys.exc_info())
360-
except _ExpectedFailure, e:
361-
addExpectedFailure = getattr(result, 'addExpectedFailure', None)
362-
if addExpectedFailure is not None:
363-
addExpectedFailure(self, e.exc_info, e.bugnumber)
364-
else:
365-
warnings.warn("Use of a TestResult without an addExpectedFailure method is deprecated",
366-
DeprecationWarning)
367-
result.addSuccess(self)
368-
except _UnexpectedSuccess, x:
369-
addUnexpectedSuccess = getattr(result, 'addUnexpectedSuccess', None)
370-
if addUnexpectedSuccess is not None:
371-
addUnexpectedSuccess(self, x.bugnumber)
372-
else:
373-
warnings.warn("Use of a TestResult without an addUnexpectedSuccess method is deprecated",
374-
DeprecationWarning)
375-
result.addFailure(self, sys.exc_info())
376-
except SkipTest, e:
377-
self._addSkip(result, str(e))
378-
except Exception:
379-
result.addError(self, sys.exc_info())
380-
else:
381-
success = True
356+
success = self.runMethod(testMethod, result)
382357

383358
try:
384359
self.tearDown()
@@ -399,6 +374,42 @@ def run(self, result=None):
399374
if stopTestRun is not None:
400375
stopTestRun()
401376

377+
def runMethod(self, testMethod, result):
378+
"""Runs the test method and catches any exception that might be thrown.
379+
380+
This is factored out of TestCase.run() to ensure that any exception
381+
thrown during the test goes out of scope before tearDown. Otherwise, an
382+
exception could hold references to Python objects that are bound to
383+
SB objects and prevent them from being deleted in time.
384+
"""
385+
try:
386+
testMethod()
387+
except self.failureException:
388+
result.addFailure(self, sys.exc_info())
389+
except _ExpectedFailure, e:
390+
addExpectedFailure = getattr(result, 'addExpectedFailure', None)
391+
if addExpectedFailure is not None:
392+
addExpectedFailure(self, e.exc_info, e.bugnumber)
393+
else:
394+
warnings.warn("Use of a TestResult without an addExpectedFailure method is deprecated",
395+
DeprecationWarning)
396+
result.addSuccess(self)
397+
except _UnexpectedSuccess, x:
398+
addUnexpectedSuccess = getattr(result, 'addUnexpectedSuccess', None)
399+
if addUnexpectedSuccess is not None:
400+
addUnexpectedSuccess(self, x.bugnumber)
401+
else:
402+
warnings.warn("Use of a TestResult without an addUnexpectedSuccess method is deprecated",
403+
DeprecationWarning)
404+
result.addFailure(self, sys.exc_info())
405+
except SkipTest, e:
406+
self._addSkip(result, str(e))
407+
except Exception:
408+
result.addError(self, sys.exc_info())
409+
else:
410+
return True
411+
return False
412+
402413
def doCleanups(self):
403414
"""Execute all cleanup functions. Normally called for you after
404415
tearDown."""

0 commit comments

Comments
 (0)
Please sign in to comment.