Adrian Prantl 5ec76fe720 Compile the LLDB tests out-of-tree.
This patch is the result of a discussion on lldb-dev, see
http://lists.llvm.org/pipermail/lldb-dev/2018-January/013111.html for
background.

For each test (should be eventually: each test configuration) a
separate build directory is created and we execute

  make VPATH=$srcdir/path/to/test -C $builddir/path/to/test -f $srcdir/path/to/test/Makefile -I $srcdir/path/to/test

In order to make this work all LLDB tests need to be updated to find
the executable in the test build directory, since CWD still points at
the test's source directory, which is a requirement for unittest2.

Although we have done extensive testing, I'm expecting that this first
attempt will break a few bots. Please DO NOT HESITATE TO REVERT this
patch in order to get the bots green again. We will likely have to
iterate on this some more.

Differential Revision: https://reviews.llvm.org/D42281

llvm-svn: 323803
2018-01-30 18:29:16 +00:00

67 lines
2.5 KiB
Python

"""
Make sure we can find the binary inside an app bundle.
"""
from __future__ import print_function
import os
import time
import re
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import lldbsuite.test.lldbplatformutil as lldbplatformutil
from lldbsuite.test.lldbtest import *
@decorators.skipUnlessDarwin
class FindAppInMacOSAppBundle(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def test_find_app_in_bundle(self):
"""There can be many tests in a test case - describe this test here."""
self.build()
self.main_source_file = lldb.SBFileSpec("main.c")
self.find_app_in_bundle_test()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
def find_app_in_bundle_test(self):
"""This reads in the .app, makes sure we get the right binary and can run it."""
# This function starts a process, "a.out" by default, sets a source
# breakpoint, runs to it, and returns the thread, process & target.
# It optionally takes an SBLaunchOption argument if you want to pass
# arguments or environment variables.
exe = self.getBuildArtifact("TestApp.app")
error = lldb.SBError()
target = self.dbg.CreateTarget(exe, None, None, False, error)
self.assertTrue(error.Success(), "Could not create target: %s"%(error.GetCString()))
self.assertTrue(target.IsValid(), "Target: TestApp.app is not valid.")
exe_module_spec = target.GetExecutable()
self.assertTrue(exe_module_spec.GetFilename(), "TestApp")
bkpt = target.BreakpointCreateBySourceRegex("Set a breakpoint here", self.main_source_file)
self.assertTrue(bkpt.GetNumLocations() == 1, "Couldn't set a breakpoint in the main app")
if lldbplatformutil.getPlatform() == "macosx":
launch_info = lldb.SBLaunchInfo(None)
launch_info.SetWorkingDirectory(self.get_process_working_directory())
error = lldb.SBError()
process = target.Launch(launch_info, error)
self.assertTrue(process.IsValid(), "Could not create a valid process for TestApp: %s"%(error.GetCString()))
# Frame #0 should be at our breakpoint.
threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
self.assertTrue(len(threads) == 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))