Skip to content

Commit

Permalink
[dotest] Clean up test folder clean-up
Browse files Browse the repository at this point in the history
Summary:
This patch implements a unified way of cleaning the build folder of each
test. This is done by completely removing the build folder before each
test, in the respective setUp() method. Previously, we were using a
combination of several methods, each with it's own drawbacks:
- nuking the entire build tree before running dotest: the issue here is
  that this did not take place if you ran dotest manually
- running "make clean" before the main "make" target: this relied on the
  clean command being correctly implemented. This was usually true, but
  not always.
- for files which were not produced by make, each python file was
  responsible for ensuring their deleting, using a variety of methods.

With this approach, the previous methods become redundant. I remove the
first two, since they are centralized. For the other various bits of
clean-up code in python files, I indend to delete it when I come
across it.

Reviewers: aprantl

Subscribers: emaste, ki.stfu, mgorny, eraman, lldb-commits

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

llvm-svn: 327703
  • Loading branch information
labath committed Mar 16, 2018
1 parent eacfefd commit 63047d0
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 73 deletions.
Expand Up @@ -64,7 +64,6 @@ def test_symlink_paths_unset(self):
self.line)

def create_src_symlink(self):
self.makeBuildDir()
pwd_symlink = self.getBuildArtifact('pwd_symlink')
if os.path.exists(pwd_symlink):
os.unlink(pwd_symlink)
Expand All @@ -73,7 +72,7 @@ def create_src_symlink(self):
return pwd_symlink

def doBuild(self, pwd_symlink):
self.build(None, None, {'PWD': pwd_symlink}, True)
self.build(None, None, {'PWD': pwd_symlink})

exe = self.getBuildArtifact(_EXE_NAME)
self.runCmd('file ' + exe, CURRENT_EXECUTABLE_SET)
Expand Up @@ -30,7 +30,6 @@ def setUp(self):
@expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr26139")
def test_command_script_immediate_output_console(self):
"""Test that LLDB correctly allows scripted commands to set immediate output to the console."""
self.makeBuildDir()
self.launch(timeout=10)

script = os.path.join(self.getSourceDir(), 'custom_command.py')
Expand All @@ -53,7 +52,6 @@ def test_command_script_immediate_output_console(self):
@expectedFailureAll(oslist=["freebsd"], bugnumber="llvm.org/pr26139")
def test_command_script_immediate_output_file(self):
"""Test that LLDB correctly allows scripted commands to set immediate output to a file."""
self.makeBuildDir()
self.launch(timeout=10)

test_files = {self.getBuildArtifact('read.txt'): 'r',
Expand Down
Expand Up @@ -41,7 +41,6 @@ def test_skipping_exec (self):
self.do_test(True)

def do_test(self, skip_exec):
self.makeBuildDir()
exe = self.getBuildArtifact("a.out")
if self.getArchitecture() == 'x86_64':
source = self.getSourcePath("main.cpp")
Expand Down
Expand Up @@ -22,7 +22,7 @@ def test_target_symbols_add(self):
"""Test that 'target symbols add' can load the symbols
even if gnu.build-id and gnu_debuglink are not present in the module.
Similar to test_add_dsym_mid_execution test for macos."""
self.build(clean=True)
self.build()
exe = self.getBuildArtifact("stripped.out")

self.target = self.dbg.CreateTarget(exe)
Expand Down
Expand Up @@ -17,7 +17,7 @@ class TestTargetSymbolsSepDebugSymlink(TestBase):
@skipIf(hostoslist=["windows"])
@skipIfRemote # llvm.org/pr36237
def test_target_symbols_sepdebug_symlink_case(self):
self.build(clean=True)
self.build()
exe = self.getBuildArtifact("dirsymlink/stripped.symlink")

lldbutil.run_to_name_breakpoint(self, "main", exe_name = exe)
1 change: 0 additions & 1 deletion lldb/packages/Python/lldbsuite/test/lldbinline.py
Expand Up @@ -97,7 +97,6 @@ def getRerunArgs(self):
return "-N dsym " + self.mydir

def BuildMakefile(self):
self.makeBuildDir()
makefilePath = self.getBuildArtifact("Makefile")
if os.path.exists(makefilePath):
return
Expand Down
56 changes: 23 additions & 33 deletions lldb/packages/Python/lldbsuite/test/lldbtest.py
Expand Up @@ -44,6 +44,7 @@
import io
import os.path
import re
import shutil
import signal
from subprocess import *
import sys
Expand Down Expand Up @@ -697,17 +698,18 @@ def getBuildDirBasename(self):

def getBuildDir(self):
"""Return the full path to the current test."""
variant = self.getDebugInfo()
if variant is None:
variant = 'default'
return os.path.join(os.environ["LLDB_BUILD"], self.mydir,
self.getBuildDirBasename())


def makeBuildDir(self):
"""Create the test-specific working directory."""
"""Create the test-specific working directory, deleting any previous
contents."""
# See also dotest.py which sets up ${LLDB_BUILD}.
lldbutil.mkdir_p(self.getBuildDir())
bdir = self.getBuildDir()
if os.path.isdir(bdir):
shutil.rmtree(bdir)
lldbutil.mkdir_p(bdir)

def getBuildArtifact(self, name="a.out"):
"""Return absolute path to an artifact in the test's build directory."""
Expand Down Expand Up @@ -1490,26 +1492,23 @@ def buildDefault(
self,
architecture=None,
compiler=None,
dictionary=None,
clean=True):
dictionary=None):
"""Platform specific way to build the default binaries."""
testdir = self.mydir
testname = self.getBuildDirBasename()
if self.getDebugInfo():
raise Exception("buildDefault tests must set NO_DEBUG_INFO_TESTCASE")
module = builder_module()
self.makeBuildDir()
dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
if not module.buildDefault(self, architecture, compiler,
dictionary, clean, testdir, testname):
dictionary, testdir, testname):
raise Exception("Don't know how to build default binary")

def buildDsym(
self,
architecture=None,
compiler=None,
dictionary=None,
clean=True):
dictionary=None):
"""Platform specific way to build binaries with dsym info."""
testdir = self.mydir
testname = self.getBuildDirBasename()
Expand All @@ -1519,15 +1518,14 @@ def buildDsym(
module = builder_module()
dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
if not module.buildDsym(self, architecture, compiler,
dictionary, clean, testdir, testname):
dictionary, testdir, testname):
raise Exception("Don't know how to build binary with dsym")

def buildDwarf(
self,
architecture=None,
compiler=None,
dictionary=None,
clean=True):
dictionary=None):
"""Platform specific way to build binaries with dwarf maps."""
testdir = self.mydir
testname = self.getBuildDirBasename()
Expand All @@ -1537,15 +1535,14 @@ def buildDwarf(
module = builder_module()
dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
if not module.buildDwarf(self, architecture, compiler,
dictionary, clean, testdir, testname):
dictionary, testdir, testname):
raise Exception("Don't know how to build binary with dwarf")

def buildDwo(
self,
architecture=None,
compiler=None,
dictionary=None,
clean=True):
dictionary=None):
"""Platform specific way to build binaries with dwarf maps."""
testdir = self.mydir
testname = self.getBuildDirBasename()
Expand All @@ -1555,15 +1552,14 @@ def buildDwo(
module = builder_module()
dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
if not module.buildDwo(self, architecture, compiler,
dictionary, clean, testdir, testname):
dictionary, testdir, testname):
raise Exception("Don't know how to build binary with dwo")

def buildGModules(
self,
architecture=None,
compiler=None,
dictionary=None,
clean=True):
dictionary=None):
"""Platform specific way to build binaries with gmodules info."""
testdir = self.mydir
testname = self.getBuildDirBasename()
Expand All @@ -1573,7 +1569,7 @@ def buildGModules(
module = builder_module()
dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
if not module.buildGModules(self, architecture, compiler,
dictionary, clean, testdir, testname):
dictionary, testdir, testname):
raise Exception("Don't know how to build binary with gmodules")

def buildGo(self):
Expand Down Expand Up @@ -1869,7 +1865,6 @@ class TestBase(Base):
timeWaitNextLaunch = 1.0

def generateSource(self, source):
self.makeBuildDir()
template = source + '.template'
temp = os.path.join(self.getSourceDir(), template)
with open(temp, 'r') as f:
Expand Down Expand Up @@ -2297,26 +2292,21 @@ def build(
self,
architecture=None,
compiler=None,
dictionary=None,
clean=True):
dictionary=None):
"""Platform specific way to build the default binaries."""
module = builder_module()
self.makeBuildDir()

dictionary = lldbplatformutil.finalize_build_dictionary(dictionary)
if self.getDebugInfo() is None:
return self.buildDefault(architecture, compiler, dictionary,
clean)
return self.buildDefault(architecture, compiler, dictionary)
elif self.getDebugInfo() == "dsym":
return self.buildDsym(architecture, compiler, dictionary, clean)
return self.buildDsym(architecture, compiler, dictionary)
elif self.getDebugInfo() == "dwarf":
return self.buildDwarf(architecture, compiler, dictionary, clean)
return self.buildDwarf(architecture, compiler, dictionary)
elif self.getDebugInfo() == "dwo":
return self.buildDwo(architecture, compiler, dictionary,
clean)
return self.buildDwo(architecture, compiler, dictionary)
elif self.getDebugInfo() == "gmodules":
return self.buildGModules(architecture, compiler, dictionary,
clean)
return self.buildGModules(architecture, compiler, dictionary)
else:
self.fail("Can't build for debug info: %s" % self.getDebugInfo())

Expand Down
Expand Up @@ -25,7 +25,7 @@ def setUp(self):
@no_debug_info_test # Prevent the genaration of the dwarf version of this test
def test_add_dsym_mid_execution(self):
"""Test that add-dsym mid-execution loads the symbols at the right place for a slid binary."""
self.buildDefault(clean=True, dictionary={'MAKE_DSYM':'YES'})
self.buildDefault(dictionary={'MAKE_DSYM':'YES'})
exe = self.getBuildArtifact("a.out")

self.target = self.dbg.CreateTarget(exe)
Expand Down
15 changes: 0 additions & 15 deletions lldb/packages/Python/lldbsuite/test/plugins/builder_base.py
Expand Up @@ -140,13 +140,10 @@ def buildDefault(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None,
testname=None):
"""Build the binaries the default way."""
commands = []
if clean:
commands.append(getMake(testdir, testname) + ["clean", getCmdLine(dictionary)])
commands.append(getMake(testdir, testname) + ["all", getArchSpec(architecture),
getCCSpec(compiler), getCmdLine(dictionary)])

Expand All @@ -161,14 +158,10 @@ def buildDwarf(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None,
testname=None):
"""Build the binaries with dwarf debug info."""
commands = []
if clean:
commands.append(getMake(testdir, testname) +
["clean", getCmdLine(dictionary)])
commands.append(getMake(testdir, testname) +
["MAKE_DSYM=NO", getArchSpec(architecture),
getCCSpec(compiler), getCmdLine(dictionary)])
Expand All @@ -183,14 +176,10 @@ def buildDwo(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None,
testname=None):
"""Build the binaries with dwarf debug info."""
commands = []
if clean:
commands.append(getMake(testdir, testname) +
["clean", getCmdLine(dictionary)])
commands.append(getMake(testdir, testname) +
["MAKE_DSYM=NO", "MAKE_DWO=YES",
getArchSpec(architecture),
Expand All @@ -207,14 +196,10 @@ def buildGModules(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None,
testname=None):
"""Build the binaries with dwarf debug info."""
commands = []
if clean:
commands.append(getMake(testdir, testname) +
["clean", getCmdLine(dictionary)])
commands.append(getMake(testdir, testname) +
["MAKE_DSYM=NO",
"MAKE_GMODULES=YES",
Expand Down
4 changes: 0 additions & 4 deletions lldb/packages/Python/lldbsuite/test/plugins/builder_darwin.py
Expand Up @@ -10,14 +10,10 @@ def buildDsym(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None,
testname=None):
"""Build the binaries with dsym debug info."""
commands = []
if clean:
commands.append(getMake(testdir, testname) +
["clean", getCmdLine(dictionary)])
commands.append(getMake(testdir, testname) +
["MAKE_DSYM=YES",
getArchSpec(architecture),
Expand Down
Expand Up @@ -6,6 +6,5 @@ def buildDsym(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None):
return False
Expand Up @@ -6,6 +6,5 @@ def buildDsym(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None):
return False
Expand Up @@ -6,6 +6,5 @@ def buildDsym(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None):
return False
Expand Up @@ -6,6 +6,5 @@ def buildDsym(
architecture=None,
compiler=None,
dictionary=None,
clean=True,
testdir=None):
return False
Expand Up @@ -27,7 +27,6 @@ def setUp(self):
raise("mydir is empty")

Base.setUp(self)
self.makeBuildDir()
self.buildDefault()
self.child_prompt = "(gdb)"
self.myexe = self.getBuildArtifact("a.out")
Expand Down
Expand Up @@ -28,14 +28,14 @@ def test_add_dsym_command_with_error(self):

# Call the program generator to produce main.cpp, version 1.
self.generate_main_cpp(version=1)
self.buildDefault(clean=True, dictionary={'MAKE_DSYM':'YES'})
self.buildDefault(dictionary={'MAKE_DSYM':'YES'})

# Insert some delay and then call the program generator to produce
# main.cpp, version 2.
time.sleep(5)
self.generate_main_cpp(version=101)
# Now call make again, but this time don't generate the dSYM.
self.buildDefault(clean=False, dictionary={'MAKE_DSYM':'NO'})
self.buildDefault(dictionary={'MAKE_DSYM':'NO'})

self.exe_name = 'a.out'
self.do_add_dsym_with_error(self.exe_name)
Expand All @@ -46,7 +46,7 @@ def test_add_dsym_command_with_success(self):

# Call the program generator to produce main.cpp, version 1.
self.generate_main_cpp(version=1)
self.buildDefault(clean=True, dictionary={'MAKE_DSYM':'YES'})
self.buildDefault(dictionary={'MAKE_DSYM':'YES'})

self.exe_name = 'a.out'
self.do_add_dsym_with_success(self.exe_name)
Expand All @@ -57,7 +57,7 @@ def test_add_dsym_with_dSYM_bundle(self):

# Call the program generator to produce main.cpp, version 1.
self.generate_main_cpp(version=1)
self.buildDefault(clean=True, dictionary={'MAKE_DSYM':'YES'})
self.buildDefault(dictionary={'MAKE_DSYM':'YES'})

self.exe_name = 'a.out'
self.do_add_dsym_with_dSYM_bundle(self.exe_name)
Expand All @@ -72,7 +72,6 @@ def generate_main_cpp(self, version=0):
'%ADD_EXTRA_CODE%',
'printf("This is version %d\\n");' %
version)
self.makeBuildDir()
src = os.path.join(self.getBuildDir(), self.source)
with open(src, 'w') as f:
f.write(new_content)
Expand Down

0 comments on commit 63047d0

Please sign in to comment.