[Lldb-commits] [lldb] r289155 - Clean up the new TestInterruptThreadNames test a bit.

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 8 15:34:57 PST 2016


Author: jmolenda
Date: Thu Dec  8 17:34:56 2016
New Revision: 289155

URL: http://llvm.org/viewvc/llvm-project?rev=289155&view=rev
Log:
Clean up the new TestInterruptThreadNames test a bit.

Modified:
    lldb/trunk/packages/Python/lldbsuite/test/macosx/thread-names/TestInterruptThreadNames.py

Modified: lldb/trunk/packages/Python/lldbsuite/test/macosx/thread-names/TestInterruptThreadNames.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/macosx/thread-names/TestInterruptThreadNames.py?rev=289155&r1=289154&r2=289155&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/macosx/thread-names/TestInterruptThreadNames.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/macosx/thread-names/TestInterruptThreadNames.py Thu Dec  8 17:34:56 2016
@@ -40,19 +40,7 @@ class TestInterruptThreadNames(TestBase)
         self.assertTrue(rc != 0, "Unable to add listener to process")
         self.assertTrue(self.wait_for_running(process, listener), "Check that process is up and running")
 
-
-        inferior_set_up = lldb.SBValue()
-        retry = 5
-        while retry > 0:
-            time.sleep(1)
-            process.SendAsyncInterrupt()
-            self.assertTrue(self.wait_for_stop(process, listener), "Check that process is paused")
-            inferior_set_up = target.CreateValueFromExpression("threads_up_and_running", "threads_up_and_running")
-            if inferior_set_up.IsValid() and inferior_set_up.GetValueAsSigned() == 1:
-                retry = 0
-            else:
-                process.Continue()
-            retry = retry - 1
+        inferior_set_up = self.wait_until_program_setup_complete(process, listener)
 
         self.assertTrue(inferior_set_up.IsValid() and inferior_set_up.GetValueAsSigned() == 1, "Check that the program was able to create its threads within the allotted time")
 
@@ -70,12 +58,32 @@ class TestInterruptThreadNames(TestBase)
             if t.GetName() == "third thread":
                 third_thread = t
 
-        self.assertTrue(
-            main_thread.IsValid() and second_thread.IsValid() and third_thread.IsValid(),
-            "Got all three expected threads")
+        self.check_expected_threads_present(main_thread, second_thread, third_thread)
 
         process.Kill()
 
+
+    # The process will set a global variable 'threads_up_and_running' to 1 when 
+    # it has has completed its setup.  Sleep for one second, pause the program,
+    # check to see if the global has that value, and continue if it does not.
+    def wait_until_program_setup_complete(self, process, listener):
+        inferior_set_up = lldb.SBValue()
+        retry = 5
+        while retry > 0:
+            time.sleep(1)
+            process.SendAsyncInterrupt()
+            self.assertTrue(self.wait_for_stop(process, listener), "Check that process is paused")
+            inferior_set_up = process.GetTarget().CreateValueFromExpression("threads_up_and_running", "threads_up_and_running")
+            if inferior_set_up.IsValid() and inferior_set_up.GetValueAsSigned() == 1:
+                retry = 0
+            else:
+                process.Continue()
+            retry = retry - 1
+        return inferior_set_up
+
+    # Listen to the process events until we get an event saying that the process is
+    # running.  Retry up to five times in case we get other events that are not
+    # what we're looking for.
     def wait_for_running(self, process, listener):
         retry_count = 5
         if process.GetState() == lldb.eStateRunning:
@@ -91,13 +99,9 @@ class TestInterruptThreadNames(TestBase)
 
         return False
 
-    def check_number_of_threads(self, process):
-        self.assertTrue(
-            process.GetNumThreads() == 3,
-            "Check that the process has three threads when sitting at the stopper() breakpoint")
-
-
-
+    # Listen to the process events until we get an event saying the process is
+    # stopped.  Retry up to five times in case we get other events that we are 
+    # not looking for.
     def wait_for_stop(self, process, listener):
         retry_count = 5
         if process.GetState() == lldb.eStateStopped or process.GetState() == lldb.eStateCrashed or process.GetState() == lldb.eStateDetached or process.GetState() == lldb.eStateExited:
@@ -109,8 +113,20 @@ class TestInterruptThreadNames(TestBase)
             if event.GetType() == lldb.SBProcess.eBroadcastBitStateChanged:
                 if process.GetState() == lldb.eStateStopped or process.GetState() == lldb.eStateCrashed or process.GetState() == lldb.eStateDetached or process.GetState() == lldb.eStateExited:
                     return True
+                if process.GetState() == lldb.eStateCrashed or process.GetState() == lldb.eStateDetached or process.GetState() == lldb.eStateExited:
+                    return False
             retry_count = retry_count - 1
 
         return False
 
 
+
+    def check_number_of_threads(self, process):
+        self.assertTrue(
+            process.GetNumThreads() == 3,
+            "Check that the process has three threads when sitting at the stopper() breakpoint")
+
+    def check_expected_threads_present(self, main_thread, second_thread, third_thread):
+        self.assertTrue(
+            main_thread.IsValid() and second_thread.IsValid() and third_thread.IsValid(),
+            "Got all three expected threads")




More information about the lldb-commits mailing list