[Lldb-commits] [lldb] r234885 - Simplify some lldb-mi tests by using the Base.addTearDownHook()

Ilia K ki.stfu at gmail.com
Tue Apr 14 06:48:49 PDT 2015


Author: ki.stfu
Date: Tue Apr 14 08:48:49 2015
New Revision: 234885

URL: http://llvm.org/viewvc/llvm-project?rev=234885&view=rev
Log:
Simplify some lldb-mi tests by using the Base.addTearDownHook()


Modified:
    lldb/trunk/test/tools/lldb-mi/signal/TestMiSignal.py
    lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py

Modified: lldb/trunk/test/tools/lldb-mi/signal/TestMiSignal.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/signal/TestMiSignal.py?rev=234885&r1=234884&r2=234885&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/signal/TestMiSignal.py (original)
+++ lldb/trunk/test/tools/lldb-mi/signal/TestMiSignal.py Tue Apr 14 08:48:49 2015
@@ -88,12 +88,13 @@ class MiSignalTestCase(lldbmi_testcase.M
         import lldbgdbserverutils
         debugserver_exe = lldbgdbserverutils.get_debugserver_exe()
         if not debugserver_exe:
-            raise Exception("debugserver not found")
+            self.skipTest("debugserver exe not found")
         hostname = "localhost"
         import random
         port = 12000 + random.randint(0,3999) # the same as GdbRemoteTestCaseBase.get_next_port
         import pexpect
         debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port))
+        self.addTearDownHook(lambda: debugserver_child.terminate(force = True))
 
         self.spawnLldbMi(args = None)
 
@@ -105,21 +106,16 @@ class MiSignalTestCase(lldbmi_testcase.M
         self.runCmd("-interpreter-exec command \"process connect connect://%s:%d\"" % (hostname, port))
         self.expect("\^done")
 
-        try:
-            # Run with stop-at-entry flag
-            self.runCmd("-interpreter-exec command \"process launch -s\"")
-            self.expect("\^done")
-
-            # Test that *stopped is printed
-            self.expect("\*stopped,reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\",.*thread-id=\"1\",stopped-threads=\"all\"")
-
-            # Exit
-            self.runCmd("-gdb-exit")
-            self.expect("\^exit")
-
-        finally:
-            # Clean up
-            debugserver_child.terminate(force = True)
+        # Run with stop-at-entry flag
+        self.runCmd("-interpreter-exec command \"process launch -s\"")
+        self.expect("\^done")
+
+        # Test that *stopped is printed
+        self.expect("\*stopped,reason=\"signal-received\",signal-name=\"SIGINT\",signal-meaning=\"Interrupt\",.*thread-id=\"1\",stopped-threads=\"all\"")
+
+        # Exit
+        self.runCmd("-gdb-exit")
+        self.expect("\^exit")
 
     @lldbmi_test
     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
@@ -164,12 +160,13 @@ class MiSignalTestCase(lldbmi_testcase.M
         import lldbgdbserverutils
         debugserver_exe = lldbgdbserverutils.get_debugserver_exe()
         if not debugserver_exe:
-            raise Exception("debugserver not found")
+            self.skipTest("debugserver exe not found")
         hostname = "localhost"
         import random
         port = 12000 + random.randint(0,3999) # the same as GdbRemoteTestCaseBase.get_next_port
         import pexpect
         debugserver_child = pexpect.spawn("%s %s:%d" % (debugserver_exe, hostname, port))
+        self.addTearDownHook(lambda: debugserver_child.terminate(force = True))
 
         self.spawnLldbMi(args = None)
 
@@ -181,31 +178,26 @@ class MiSignalTestCase(lldbmi_testcase.M
         self.runCmd("-interpreter-exec command \"process connect connect://%s:%d\"" % (hostname, port))
         self.expect("\^done")
 
-        try:
-            # Run to main
-            self.runCmd("-break-insert -f main")
-            self.expect("\^done,bkpt={number=\"1\"")
-            #FIXME -exec-run doesn't work
-            self.runCmd("-interpreter-exec command \"process launch\"") #FIXME: self.runCmd("-exec-run")
-            self.expect("\^done")                                       #FIXME: self.expect("\^running")
-            self.expect("\*stopped,reason=\"breakpoint-hit\"")
-
-            # Set do_segfault=1 and run (to cause a segfault error)
-            self.runCmd("-data-evaluate-expression \"do_segfault=1\"")
-            self.expect("\^done,value=\"1\"")
-            self.runCmd("-exec-continue")
-            self.expect("\^running")
-
-            # Test that *stopped is printed
-            self.expect("\*stopped,reason=\"exception-received\",exception=\"EXC_BAD_ACCESS \(code=1, address=0x0\)\",thread-id=\"1\",stopped-threads=\"all\"")
-
-            # Exit
-            self.runCmd("-gdb-exit")
-            self.expect("\^exit")
-
-        finally:
-            # Clean up
-            debugserver_child.terminate(force = True)
+        # Run to main
+        self.runCmd("-break-insert -f main")
+        self.expect("\^done,bkpt={number=\"1\"")
+        #FIXME -exec-run doesn't work
+        self.runCmd("-interpreter-exec command \"process launch\"") #FIXME: self.runCmd("-exec-run")
+        self.expect("\^done")                                       #FIXME: self.expect("\^running")
+        self.expect("\*stopped,reason=\"breakpoint-hit\"")
+
+        # Set do_segfault=1 and run (to cause a segfault error)
+        self.runCmd("-data-evaluate-expression \"do_segfault=1\"")
+        self.expect("\^done,value=\"1\"")
+        self.runCmd("-exec-continue")
+        self.expect("\^running")
+
+        # Test that *stopped is printed
+        self.expect("\*stopped,reason=\"exception-received\",exception=\"EXC_BAD_ACCESS \(code=1, address=0x0\)\",thread-id=\"1\",stopped-threads=\"all\"")
+
+        # Exit
+        self.runCmd("-gdb-exit")
+        self.expect("\^exit")
 
 if __name__ == '__main__':
     unittest2.main()

Modified: lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py?rev=234885&r1=234884&r2=234885&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py (original)
+++ lldb/trunk/test/tools/lldb-mi/syntax/TestMiSyntax.py Tue Apr 14 08:48:49 2015
@@ -44,25 +44,19 @@ class MiSyntaxTestCase(lldbmi_testcase.M
 
         # Create alias for myexe
         complicated_myexe = "C--mpl-x file's`s @#$%^&*()_+-={}[]| name"
-        if os.path.exists(complicated_myexe):
-            os.unlink(complicated_myexe)
         os.symlink(self.myexe, complicated_myexe)
+        self.addTearDownHook(lambda: os.unlink(complicated_myexe))
 
-        try:
-            # Try to load executable with complicated filename
-            self.runCmd("-file-exec-and-symbols \"%s\"" % complicated_myexe)
-            self.expect("\^done")
+        # Try to load executable with complicated filename
+        self.runCmd("-file-exec-and-symbols \"%s\"" % complicated_myexe)
+        self.expect("\^done")
 
-            # Check that it was loaded correctly
-            self.runCmd("-break-insert -f main")
-            self.expect("\^done,bkpt={number=\"1\"")
-            self.runCmd("-exec-run")
-            self.expect("\^running")
-            self.expect("\*stopped,reason=\"breakpoint-hit\"")
-
-        finally:
-            # Clean up
-            os.unlink(complicated_myexe)
+        # Check that it was loaded correctly
+        self.runCmd("-break-insert -f main")
+        self.expect("\^done,bkpt={number=\"1\"")
+        self.runCmd("-exec-run")
+        self.expect("\^running")
+        self.expect("\*stopped,reason=\"breakpoint-hit\"")
 
     @lldbmi_test
     @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")





More information about the lldb-commits mailing list