[Lldb-commits] [lldb] r114058 - in /lldb/trunk/test: lldbtest.py persistent_variables/Makefile persistent_variables/TestPersistentVariables.py persistent_variables/main.c plugins/darwin.py settings/TestSettings.py
Johnny Chen
johnny.chen at apple.com
Wed Sep 15 18:53:04 PDT 2010
Author: johnny
Date: Wed Sep 15 20:53:04 2010
New Revision: 114058
URL: http://llvm.org/viewvc/llvm-project?rev=114058&view=rev
Log:
Provided a mechanism for the test class to cleanup after itself once it's done.
This will remove the confusion experienced when previous test runs left some
files (both intermediate or by-product as a result of the test).
lldbtest.TestBase defines a classmethod tearDownClass(cls) which invokes the
platform-specific cleanup() function as defined by the plugin; after that, it
invokes a subclass-specific function classCleanup(cls) if defined; and, finally,
it restores the old working directory.
An example of classCleanup(cls) is in settings/TestSettings.py:
@classmethod
def classCleanup(cls):
system(["/bin/sh", "-c", "rm output.txt"])
where it deletes the by-product "output.txt" as a result of running a.out.
Added:
lldb/trunk/test/persistent_variables/Makefile
lldb/trunk/test/persistent_variables/main.c
Modified:
lldb/trunk/test/lldbtest.py
lldb/trunk/test/persistent_variables/TestPersistentVariables.py
lldb/trunk/test/plugins/darwin.py
lldb/trunk/test/settings/TestSettings.py
Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=114058&r1=114057&r2=114058&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Wed Sep 15 20:53:04 2010
@@ -271,20 +271,47 @@
# Can be overridden by the LLDB_TIME_WAIT environment variable.
timeWait = 1.0;
- def setUp(self):
- #import traceback
- #traceback.print_stack()
+ # Keep track of the old current working directory.
+ oldcwd = None
+ @classmethod
+ def setUpClass(cls):
# Fail fast if 'mydir' attribute is not overridden.
- if not self.mydir or len(self.mydir) == 0:
+ if not cls.mydir or len(cls.mydir) == 0:
raise Exception("Subclasses must override the 'mydir' attribute.")
# Save old working directory.
- self.oldcwd = os.getcwd()
+ cls.oldcwd = os.getcwd()
# Change current working directory if ${LLDB_TEST} is defined.
# See also dotest.py which sets up ${LLDB_TEST}.
if ("LLDB_TEST" in os.environ):
- os.chdir(os.path.join(os.environ["LLDB_TEST"], self.mydir));
+ if traceAlways:
+ print "Change dir to:", os.path.join(os.environ["LLDB_TEST"], cls.mydir)
+ os.chdir(os.path.join(os.environ["LLDB_TEST"], cls.mydir))
+
+ @classmethod
+ def tearDownClass(cls):
+ """Do class-wide cleanup."""
+
+ # First, let's do the platform-specific cleanup.
+ module = __import__(sys.platform)
+ if not module.cleanup():
+ raise Exception("Don't know how to do cleanup")
+
+ # Subclass might have specific cleanup function defined.
+ if getattr(cls, "classCleanup", None):
+ if traceAlways:
+ print "Call class-specific cleanup function for class:", cls
+ cls.classCleanup()
+
+ # Restore old working directory.
+ if traceAlways:
+ print "Restore dir to:", cls.oldcwd
+ os.chdir(cls.oldcwd)
+
+ def setUp(self):
+ #import traceback
+ #traceback.print_stack()
if "LLDB_MAX_LAUNCH_COUNT" in os.environ:
self.maxLaunchCount = int(os.environ["LLDB_MAX_LAUNCH_COUNT"])
@@ -330,9 +357,6 @@
del self.dbg
- # Restore old working directory.
- os.chdir(self.oldcwd)
-
def runCmd(self, cmd, msg=None, check=True, trace=False, setCookie=True):
"""
Ask the command interpreter to handle the command and then check its
Added: lldb/trunk/test/persistent_variables/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/persistent_variables/Makefile?rev=114058&view=auto
==============================================================================
--- lldb/trunk/test/persistent_variables/Makefile (added)
+++ lldb/trunk/test/persistent_variables/Makefile Wed Sep 15 20:53:04 2010
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
Modified: lldb/trunk/test/persistent_variables/TestPersistentVariables.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/persistent_variables/TestPersistentVariables.py?rev=114058&r1=114057&r2=114058&view=diff
==============================================================================
--- lldb/trunk/test/persistent_variables/TestPersistentVariables.py (original)
+++ lldb/trunk/test/persistent_variables/TestPersistentVariables.py Wed Sep 15 20:53:04 2010
@@ -13,7 +13,9 @@
def test_persistent_variables(self):
"""Test that lldb persistent variables works correctly."""
- self.runCmd("file ../array_types/a.out", CURRENT_EXECUTABLE_SET)
+ self.buildDefault()
+
+ self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
self.runCmd("breakpoint set --name main")
Added: lldb/trunk/test/persistent_variables/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/persistent_variables/main.c?rev=114058&view=auto
==============================================================================
--- lldb/trunk/test/persistent_variables/main.c (added)
+++ lldb/trunk/test/persistent_variables/main.c Wed Sep 15 20:53:04 2010
@@ -0,0 +1,13 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main (int argc, char const *argv[])
+{
+ return 0;
+}
Modified: lldb/trunk/test/plugins/darwin.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/plugins/darwin.py?rev=114058&r1=114057&r2=114058&view=diff
==============================================================================
--- lldb/trunk/test/plugins/darwin.py (original)
+++ lldb/trunk/test/plugins/darwin.py Wed Sep 15 20:53:04 2010
@@ -50,3 +50,11 @@
# True signifies that we can handle building dsym.
return True
+
+def cleanup():
+ """Do class-wide cleanup after the test."""
+ if os.path.isfile("Makefile"):
+ lldbtest.system(["/bin/sh", "-c", "make clean"])
+
+ # True signifies that we can handle building dsym.
+ return True
Modified: lldb/trunk/test/settings/TestSettings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/TestSettings.py?rev=114058&r1=114057&r2=114058&view=diff
==============================================================================
--- lldb/trunk/test/settings/TestSettings.py (original)
+++ lldb/trunk/test/settings/TestSettings.py Wed Sep 15 20:53:04 2010
@@ -11,6 +11,10 @@
mydir = "settings"
+ @classmethod
+ def classCleanup(cls):
+ system(["/bin/sh", "-c", "rm output.txt"])
+
def test_set_prompt(self):
"""Test that 'set prompt' actually changes the prompt."""
@@ -62,7 +66,7 @@
self.runCmd("run", RUN_SUCCEEDED)
# Read the output file produced by running the program.
- output = open('/tmp/output.txt', 'r').read()
+ output = open('output.txt', 'r').read()
self.assertTrue(output.startswith("argv[1] matches") and
output.find("argv[2] matches") > 0 and
More information about the lldb-commits
mailing list