Commit a31130f6 authored by Tatyana Krasnukha's avatar Tatyana Krasnukha
Browse files

[lldb][testsuite] Create a SBDebugger instance for each test

Some tests set settings and don't clean them up, this leads to side effects in other tests.
The patch removes a global debugger instance with a per-test debugger to avoid such effects.

From what I see, lldb.DBG was needed to determine the platform before a test is run,
lldb.selected_platform is used for this purpose now. Though, this required adding a new function
to the SBPlatform interface.

Differential Revision: https://reviews.llvm.org/D74903
parent b10deb94
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@ public:

    ~SBPlatform();

    static SBPlatform GetHostPlatform();

    bool
    IsValid () const;

+2 −0
Original line number Diff line number Diff line
@@ -97,6 +97,8 @@ public:

  ~SBPlatform();

  static SBPlatform GetHostPlatform();

  explicit operator bool() const;

  bool IsValid() const;
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ def _decorateTest(mode,
        skip_for_debug_info = _match_decorator_property(
            debug_info, self.getDebugInfo())
        skip_for_triple = _match_decorator_property(
            triple, lldb.DBG.GetSelectedPlatform().GetTriple())
            triple, lldb.selected_platform.GetTriple())
        skip_for_remote = _match_decorator_property(
            remote, lldb.remote_platform is not None)

+7 −23
Original line number Diff line number Diff line
@@ -774,16 +774,6 @@ def visit(prefix, dir, names):
            raise


def setSetting(setting, value):
    import lldb
    ci = lldb.DBG.GetCommandInterpreter()
    res = lldb.SBCommandReturnObject()
    cmd = 'setting set %s %s'%(setting, value)
    print(cmd)
    ci.HandleCommand(cmd, res, False)
    if not res.Succeeded():
        raise Exception('failed to run "%s"'%cmd)

# ======================================== #
#                                          #
# Execution of the test driver starts here #
@@ -809,6 +799,8 @@ def checkDsymForUUIDIsNotOn():


def exitTestSuite(exitCode=None):
    # lldb.py does SBDebugger.Initialize().
    # Call SBDebugger.Terminate() on exit.
    import lldb
    lldb.SBDebugger.Terminate()
    if exitCode:
@@ -931,7 +923,7 @@ def checkWatchpointSupport():
def checkDebugInfoSupport():
    import lldb

    platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2]
    platform = lldb.selected_platform.GetTriple().split('-')[2]
    compiler = configuration.compiler
    skipped = []
    for cat in test_categories.debug_info_categories:
@@ -961,17 +953,13 @@ def run_suite():

    setupSysPath()


    # For the time being, let's bracket the test runner within the
    # lldb.SBDebugger.Initialize()/Terminate() pair.
    import lldb
    # Use host platform by default.
    lldb.selected_platform = lldb.SBPlatform.GetHostPlatform()

    # Now we can also import lldbutil
    from lldbsuite.test import lldbutil

    # Create a singleton SBDebugger in the lldb namespace.
    lldb.DBG = lldb.SBDebugger.Create()

    if configuration.lldb_platform_name:
        print("Setting up remote platform '%s'" %
              (configuration.lldb_platform_name))
@@ -1020,7 +1008,7 @@ def run_suite():
        if not lldb.remote_platform.SetWorkingDirectory(
                configuration.lldb_platform_working_dir):
            raise Exception("failed to set working directory '%s'" % configuration.lldb_platform_working_dir)
        lldb.DBG.SetSelectedPlatform(lldb.remote_platform)
        lldb.selected_platform = lldb.remote_platform
    else:
        lldb.remote_platform = None
        configuration.lldb_platform_working_dir = None
@@ -1031,7 +1019,7 @@ def run_suite():
    build_dir = configuration.test_build_dir
    lldbutil.mkdir_p(build_dir)

    target_platform = lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2]
    target_platform = lldb.selected_platform.GetTriple().split('-')[2]

    checkLibcxxSupport()
    checkLibstdcxxSupport()
@@ -1059,10 +1047,6 @@ def run_suite():
    # Now that we have loaded all the test cases, run the whole test suite.
    #

    # Set any user-overridden settings.
    for key, value in configuration.settings:
        setSetting(key, value)

    # Install the control-c handler.
    unittest2.signals.installHandler()

+2 −2
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ def _run_adb_command(cmd, device_id):

def target_is_android():
    if not hasattr(target_is_android, 'result'):
        triple = lldb.DBG.GetSelectedPlatform().GetTriple()
        triple = lldb.selected_platform.GetTriple()
        match = re.match(".*-.*-.*-android", triple)
        target_is_android.result = match is not None
    return target_is_android.result
@@ -129,7 +129,7 @@ def getDarwinOSTriples():

def getPlatform():
    """Returns the target platform which the tests are running on."""
    triple = lldb.DBG.GetSelectedPlatform().GetTriple()
    triple = lldb.selected_platform.GetTriple()
    if triple is None:
      # It might be an unconnected remote platform.
      return ''
Loading