[Lldb-commits] [lldb] r116881 - in /lldb/trunk/test: lldbtest.py settings/TestSettings.py

Johnny Chen johnny.chen at apple.com
Tue Oct 19 16:40:14 PDT 2010


Author: johnny
Date: Tue Oct 19 18:40:13 2010
New Revision: 116881

URL: http://llvm.org/viewvc/llvm-project?rev=116881&view=rev
Log:
Restoring the original setting should be done more robustly by adding a hook function
to be run during tearDown() to effect the restore action instead of executing it inline
during the test method, because the test may already fail and bailout before the inline
restore action.

Fix test_set_output_path() and pass_run_args_and_env_vars() to use this mechanism.

Modified:
    lldb/trunk/test/lldbtest.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=116881&r1=116880&r2=116881&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Tue Oct 19 18:40:13 2010
@@ -424,6 +424,10 @@
         self.__errored__ = False
         self.__failed__ = False
 
+        # See addTearDownHook(self, hook) which allows the client to add a hook
+        # function to be run during tearDown() time.
+        self.hooks = []
+
     def markError(self):
         """Callback invoked when we (the test case instance) errored."""
         self.__errored__ = True
@@ -465,10 +469,25 @@
         self.dict = dictionary
         self.doTearDownCleanup = True
 
+    def addTearDownHook(self, hook):
+        """
+        Add a function to be run during tearDown() time.
+
+        Hooks are executed in a first come first serve manner.
+        """
+        self.hooks.append(hook)
+
     def tearDown(self):
         #import traceback
         #traceback.print_stack()
 
+        # Check and run any hook functions.
+        for hook in self.hooks:
+            #print "Executing hook:", hook
+            hook()
+
+        self.runCmd("settings show")
+
         # Terminate the current process being debugged, if any.
         if self.runStarted:
             self.runCmd("process kill", PROCESS_KILLED, check=False)
@@ -478,6 +497,7 @@
             del self.process
 
         del self.dbg
+        del self.hooks
 
         # Perform registered teardown cleanup.
         if doCleanup and self.doTearDownCleanup:

Modified: lldb/trunk/test/settings/TestSettings.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/settings/TestSettings.py?rev=116881&r1=116880&r2=116881&view=diff
==============================================================================
--- lldb/trunk/test/settings/TestSettings.py (original)
+++ lldb/trunk/test/settings/TestSettings.py Tue Oct 19 18:40:13 2010
@@ -89,6 +89,11 @@
         # Set the run-args and the env-vars.
         self.runCmd('settings set target.process.run-args A B C')
         self.runCmd('settings set target.process.env-vars ["MY_ENV_VAR"]=YES')
+        # And add hooks to restore the settings during tearDown().
+        self.addTearDownHook(
+            lambda: self.runCmd("settings set -r target.process.run-args"))
+        self.addTearDownHook(
+            lambda: self.runCmd("settings set -r target.process.env-vars"))
 
         self.runCmd("run", RUN_SUCCEEDED)
 
@@ -114,15 +119,17 @@
 
         # Set the output-path and verify it is set.
         self.runCmd("settings set target.process.output-path 'stdout.txt'")
+        # And add a hook to restore original setting of target.process.output-path
+        # later on during tearDown().
+        self.addTearDownHook(
+            lambda: self.runCmd("settings set -r target.process.output-path"))
+
         self.expect("settings show target.process.output-path",
                     SETTING_MSG("target.process.output-path"),
             startstr = "target.process.output-path (string) = 'stdout.txt'")
 
         self.runCmd("run", RUN_SUCCEEDED)
 
-        # Restore the original setting now that the program has been run.
-        self.runCmd("settings set -r target.process.output-path")
-
         # The 'stdout.txt' file should now exist.
         self.assertTrue(os.path.isfile("stdout.txt"),
                         "'stdout.txt' exists due to target.process.output-path.")





More information about the lldb-commits mailing list