labath created this revision.
labath added reviewers: zturner, clayborg.
labath added a subscriber: lldb-commits.

The test (among other things) attempts to verify that detaching works while the 
inferior is
running. However, this was racy since the inferior could end up stopping again 
before we got a
chance to detach from it (the test could be made to fail reliably by inserting 
a sleep just after
the last "continue" command). The reason for the stop was that we had a 
breakpoint set in a place
that can be hit by multiple threads, and we stop because another thread hit a 
breakpoint.

I fix this by moving the breakpoint to a place that is reachable from only one 
thread. I also
make sure that the same thread cannot hit the breakpoint if we are exceptionaly 
slow by flipping
a flag which makes the breakpoint unreachable (I cannot just disable or delete 
the breakpoint as
the test makes it a point to try detaching while breakpoints are still set).

http://reviews.llvm.org/D12527

Files:
  test/functionalities/attach_resume/TestAttachResume.py
  test/functionalities/attach_resume/main.cpp

Index: test/functionalities/attach_resume/main.cpp
===================================================================
--- test/functionalities/attach_resume/main.cpp
+++ test/functionalities/attach_resume/main.cpp
@@ -8,15 +8,17 @@
 #include <sys/prctl.h>
 #endif
 
+volatile bool debugger_flag = true; // The debugger will flip this to false
+
 void *start(void *data)
 {
     int i;
     size_t idx = (size_t)data;
     for (i=0; i<30; i++)
     {
-        if ( idx == 0 )
-            std::this_thread::sleep_for(std::chrono::microseconds(1));
-        std::this_thread::sleep_for(std::chrono::seconds(1)); // Set 
breakpoint here
+        if ( idx == 0 && debugger_flag)
+            std::this_thread::sleep_for(std::chrono::microseconds(1)); // Set 
breakpoint here
+        std::this_thread::sleep_for(std::chrono::seconds(1));
     }
     return 0;
 }
Index: test/functionalities/attach_resume/TestAttachResume.py
===================================================================
--- test/functionalities/attach_resume/TestAttachResume.py
+++ test/functionalities/attach_resume/TestAttachResume.py
@@ -14,16 +14,14 @@
 
     mydir = TestBase.compute_mydir(__file__)
 
-    @expectedFlakeyLinux('llvm.org/pr19310')
     @expectedFailureFreeBSD('llvm.org/pr19310')
     @skipIfRemote
     @dwarf_test
     def test_attach_continue_interrupt_detach(self):
         """Test attach/continue/interrupt/detach"""
         self.buildDwarf()
         self.process_attach_continue_interrupt_detach()
 
-    @expectedFlakeyLinux('llvm.org/pr19478') # intermittent ~2/14 runs
     @skipIfRemote
     def process_attach_continue_interrupt_detach(self):
         """Test attach/continue/interrupt/detach"""
@@ -81,12 +79,11 @@
 
         self.assertTrue(wait_for_state(lldb.eStateStopped),
             'Process not stopped after breakpoint')
-        # This test runs a bunch of threads in the same little function with 
this
-        # breakpoint.  We want to make sure the breakpoint got hit at least 
once,
-        # but more than one thread may hit it at a time.  So we really only 
care
-        # that is isn't 0 times, not how many times it is.
         self.expect('br list', 'Breakpoint not hit',
-            patterns = ['hit count = [1-9]'])
+            substrs = ['hit count = 1'])
+
+        # Make sure the breakpoint is not hit again.
+        self.expect("expr debugger_flag = false", substrs=[" = false"]);
 
         self.runCmd("c")
         self.assertTrue(wait_for_state(lldb.eStateRunning),


Index: test/functionalities/attach_resume/main.cpp
===================================================================
--- test/functionalities/attach_resume/main.cpp
+++ test/functionalities/attach_resume/main.cpp
@@ -8,15 +8,17 @@
 #include <sys/prctl.h>
 #endif
 
+volatile bool debugger_flag = true; // The debugger will flip this to false
+
 void *start(void *data)
 {
     int i;
     size_t idx = (size_t)data;
     for (i=0; i<30; i++)
     {
-        if ( idx == 0 )
-            std::this_thread::sleep_for(std::chrono::microseconds(1));
-        std::this_thread::sleep_for(std::chrono::seconds(1)); // Set breakpoint here
+        if ( idx == 0 && debugger_flag)
+            std::this_thread::sleep_for(std::chrono::microseconds(1)); // Set breakpoint here
+        std::this_thread::sleep_for(std::chrono::seconds(1));
     }
     return 0;
 }
Index: test/functionalities/attach_resume/TestAttachResume.py
===================================================================
--- test/functionalities/attach_resume/TestAttachResume.py
+++ test/functionalities/attach_resume/TestAttachResume.py
@@ -14,16 +14,14 @@
 
     mydir = TestBase.compute_mydir(__file__)
 
-    @expectedFlakeyLinux('llvm.org/pr19310')
     @expectedFailureFreeBSD('llvm.org/pr19310')
     @skipIfRemote
     @dwarf_test
     def test_attach_continue_interrupt_detach(self):
         """Test attach/continue/interrupt/detach"""
         self.buildDwarf()
         self.process_attach_continue_interrupt_detach()
 
-    @expectedFlakeyLinux('llvm.org/pr19478') # intermittent ~2/14 runs
     @skipIfRemote
     def process_attach_continue_interrupt_detach(self):
         """Test attach/continue/interrupt/detach"""
@@ -81,12 +79,11 @@
 
         self.assertTrue(wait_for_state(lldb.eStateStopped),
             'Process not stopped after breakpoint')
-        # This test runs a bunch of threads in the same little function with this
-        # breakpoint.  We want to make sure the breakpoint got hit at least once,
-        # but more than one thread may hit it at a time.  So we really only care
-        # that is isn't 0 times, not how many times it is.
         self.expect('br list', 'Breakpoint not hit',
-            patterns = ['hit count = [1-9]'])
+            substrs = ['hit count = 1'])
+
+        # Make sure the breakpoint is not hit again.
+        self.expect("expr debugger_flag = false", substrs=[" = false"]);
 
         self.runCmd("c")
         self.assertTrue(wait_for_state(lldb.eStateRunning),
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to