teak-llvm/lldb/packages/Python/lldbsuite/test/tools/lldb-mi/lldbmi_testcase.py
Pavel Labath 63047d05c0 [dotest] Clean up test folder clean-up
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
2018-03-16 12:04:46 +00:00

60 lines
1.6 KiB
Python

"""
Base class for lldb-mi test cases.
"""
from __future__ import print_function
from lldbsuite.test.lldbtest import *
class MiTestCaseBase(Base):
mydir = None
myexe = None
mylog = None
NO_DEBUG_INFO_TESTCASE = True
@classmethod
def classCleanup(cls):
if cls.myexe:
TestBase.RemoveTempFile(cls.myexe)
if cls.mylog:
TestBase.RemoveTempFile(cls.mylog)
def setUp(self):
if not self.mydir:
raise("mydir is empty")
Base.setUp(self)
self.buildDefault()
self.child_prompt = "(gdb)"
self.myexe = self.getBuildArtifact("a.out")
def tearDown(self):
if self.TraceOn():
print("\n\nContents of %s:" % self.mylog)
try:
print(open(self.mylog, "r").read())
except IOError:
pass
Base.tearDown(self)
def spawnLldbMi(self, args=None):
import pexpect
self.child = pexpect.spawn("%s --interpreter %s" % (
self.lldbMiExec, args if args else ""), cwd=self.getBuildDir())
self.child.setecho(True)
self.mylog = self.getBuildArtifact("child.log")
self.child.logfile_read = open(self.mylog, "w")
# wait until lldb-mi has started up and is ready to go
self.expect(self.child_prompt, exactly=True)
def runCmd(self, cmd):
self.child.sendline(cmd)
def expect(self, pattern, exactly=False, *args, **kwargs):
if exactly:
return self.child.expect_exact(pattern, *args, **kwargs)
return self.child.expect(pattern, *args, **kwargs)