summaryrefslogtreecommitdiffstats
path: root/lldb/test/functionalities
diff options
context:
space:
mode:
authorAndrew MacPherson <andrew.macp@gmail.com>2014-04-02 06:57:45 +0000
committerAndrew MacPherson <andrew.macp@gmail.com>2014-04-02 06:57:45 +0000
commit82aae0d835a33e56ae8881eff301dade55a022c2 (patch)
treea612a4ebfc3fa9f4e46753d5ab5f6b7168867a84 /lldb/test/functionalities
parentb461b1c78566d63aeb0736ae377b6c8117740d49 (diff)
downloadbcm5719-llvm-82aae0d835a33e56ae8881eff301dade55a022c2.tar.gz
bcm5719-llvm-82aae0d835a33e56ae8881eff301dade55a022c2.zip
Use getpgid() with waitpid() in case the process pgid is not equal to its pid, as is the case with a forked subprocess. Also a couple of fixes for unit test failures from Todd Fiala.
llvm-svn: 205405
Diffstat (limited to 'lldb/test/functionalities')
-rw-r--r--lldb/test/functionalities/attach_resume/Makefile8
-rw-r--r--lldb/test/functionalities/attach_resume/TestAttachResume.py95
-rw-r--r--lldb/test/functionalities/attach_resume/main.c32
3 files changed, 135 insertions, 0 deletions
diff --git a/lldb/test/functionalities/attach_resume/Makefile b/lldb/test/functionalities/attach_resume/Makefile
new file mode 100644
index 00000000000..0375c31ff26
--- /dev/null
+++ b/lldb/test/functionalities/attach_resume/Makefile
@@ -0,0 +1,8 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+LD_EXTRAS := -lpthread
+
+EXE := AttachResume
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/functionalities/attach_resume/TestAttachResume.py b/lldb/test/functionalities/attach_resume/TestAttachResume.py
new file mode 100644
index 00000000000..b79633ddb2b
--- /dev/null
+++ b/lldb/test/functionalities/attach_resume/TestAttachResume.py
@@ -0,0 +1,95 @@
+"""
+Test process attach/resume.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+
+exe_name = "AttachResume" # Must match Makefile
+
+class AttachResumeTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @dwarf_test
+ def test_attach_continue_interrupt_detach(self):
+ """Test attach/continue/interrupt/detach"""
+ self.buildDwarf()
+ self.process_attach_continue_interrupt_detach()
+
+ def process_attach_continue_interrupt_detach(self):
+ """Test attach/continue/interrupt/detach"""
+
+ exe = os.path.join(os.getcwd(), exe_name)
+
+ popen = self.spawnSubprocess(exe)
+ self.addTearDownHook(self.cleanupSubprocesses)
+
+ self.runCmd("process attach -p " + str(popen.pid))
+
+ self._state = 0
+ def process_events():
+ event = lldb.SBEvent()
+ while self.dbg.GetListener().GetNextEvent(event):
+ self._state = lldb.SBProcess.GetStateFromEvent(event)
+
+ # using process.GetState() does not work: llvm.org/pr16172
+ def wait_for_state(s, timeout=5):
+ t = 0
+ period = 0.1
+ while self._state != s:
+ process_events()
+ time.sleep(period)
+ t += period
+ if t > timeout:
+ return False
+ return True
+
+ self.setAsync(True)
+
+ self.runCmd("c")
+ self.assertTrue(wait_for_state(lldb.eStateRunning),
+ 'Process not running after continue')
+
+ self.runCmd("process interrupt")
+ self.assertTrue(wait_for_state(lldb.eStateStopped),
+ 'Process not stopped after interrupt')
+
+ # be sure to continue/interrupt/continue (r204504)
+ self.runCmd("c")
+ self.assertTrue(wait_for_state(lldb.eStateRunning),
+ 'Process not running after continue')
+
+ self.runCmd("process interrupt")
+ self.assertTrue(wait_for_state(lldb.eStateStopped),
+ 'Process not stopped after interrupt')
+
+ # check that this breakpoint is auto-cleared on detach (r204752)
+ self.runCmd("br set -f main.c -l 12")
+
+ self.runCmd("c")
+ self.assertTrue(wait_for_state(lldb.eStateRunning),
+ 'Process not running after continue')
+
+ self.assertTrue(wait_for_state(lldb.eStateStopped),
+ 'Process not stopped after breakpoint')
+ self.expect('br list', 'Breakpoint not hit',
+ patterns = ['hit count = 1'])
+
+ self.runCmd("c")
+ self.assertTrue(wait_for_state(lldb.eStateRunning),
+ 'Process not running after continue')
+
+ # make sure to detach while in running state (r204759)
+ self.runCmd("detach")
+ self.assertTrue(wait_for_state(lldb.eStateDetached),
+ 'Process not detached after detach')
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/functionalities/attach_resume/main.c b/lldb/test/functionalities/attach_resume/main.c
new file mode 100644
index 00000000000..564e71be2ae
--- /dev/null
+++ b/lldb/test/functionalities/attach_resume/main.c
@@ -0,0 +1,32 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <pthread.h>
+
+void *start(void *data)
+{
+ int i;
+ size_t idx = (size_t)data;
+ for (i=0; i<30; i++)
+ {
+ if ( idx == 0 )
+ usleep(1);
+ sleep(1);
+ }
+ return 0;
+}
+
+int main(int argc, char const *argv[])
+{
+ static const size_t nthreads = 16;
+ pthread_attr_t attr;
+ pthread_t threads[nthreads];
+ size_t i;
+
+ pthread_attr_init(&attr);
+ for (i=0; i<nthreads; i++)
+ pthread_create(&threads[i], &attr, &start, (void *)i);
+
+ for (i=0; i<nthreads; i++)
+ pthread_join(threads[i], 0);
+}
OpenPOWER on IntegriCloud