[Lldb-commits] [lldb] r180977 - Adding test for non-API process attach

Andrew Kaylor andrew.kaylor at intel.com
Thu May 2 17:10:28 PDT 2013


Author: akaylor
Date: Thu May  2 19:10:27 2013
New Revision: 180977

URL: http://llvm.org/viewvc/llvm-project?rev=180977&view=rev
Log:
Adding test for non-API process attach

Added:
    lldb/trunk/test/functionalities/process_attach/
    lldb/trunk/test/functionalities/process_attach/Makefile
    lldb/trunk/test/functionalities/process_attach/TestProcessAttach.py
    lldb/trunk/test/functionalities/process_attach/main.c

Added: lldb/trunk/test/functionalities/process_attach/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/process_attach/Makefile?rev=180977&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/process_attach/Makefile (added)
+++ lldb/trunk/test/functionalities/process_attach/Makefile Thu May  2 19:10:27 2013
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/functionalities/process_attach/TestProcessAttach.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/process_attach/TestProcessAttach.py?rev=180977&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/process_attach/TestProcessAttach.py (added)
+++ lldb/trunk/test/functionalities/process_attach/TestProcessAttach.py Thu May  2 19:10:27 2013
@@ -0,0 +1,87 @@
+"""
+Test process attach.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+import lldbutil
+
+class ProcessAttachTestCase(TestBase):
+
+    mydir = os.path.join("functionalities", "process_attach")
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @dsym_test
+    def test_attach_to_process_by_id_with_dsym(self):
+        """Test attach by process id"""
+        self.buildDsym()
+        self.process_attach_by_id()
+
+    @expectedFailureLinux # lldb is unable to attach to process by id
+    @dwarf_test
+    def test_attach_to_process_by_id_with_dwarf(self):
+        """Test attach by process id"""
+        self.buildDwarf()
+        self.process_attach_by_id()
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @dsym_test
+    def test_attach_to_process_by_name_with_dsym(self):
+        """Test attach by process name"""
+        self.buildDsym()
+        self.process_attach_by_name()
+
+    @expectedFailureLinux # due to bugzilla 14541 -- lldb is unable to attach to process by name
+    @dwarf_test
+    def test_attach_to_process_by_name_with_dwarf(self):
+        """Test attach by process name"""
+        self.buildDwarf()
+        self.process_attach_by_name()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+
+    def process_attach_by_id(self):
+        """Test attach by process id"""
+
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        #target = self.dbg.CreateTarget(exe)
+
+        # Spawn a new process
+        popen = self.spawnSubprocess(exe)
+        self.addTearDownHook(self.cleanupSubprocesses)
+
+        self.runCmd("process attach -p " + str(popen.pid))
+
+        target = self.dbg.GetSelectedTarget()
+
+        process = target.GetProcess()
+        self.assertTrue(process, PROCESS_IS_VALID)
+
+
+    def process_attach_by_name(self):
+        """Test attach by process name"""
+
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        # Spawn a new process
+        popen = self.spawnSubprocess(exe)
+        self.addTearDownHook(self.cleanupSubprocesses)
+
+        target = self.dbg.GetSelectedTarget()
+
+        self.runCmd("process attach -n a.out")
+
+        proces = target.GetProcess()
+        self.assertTrue(process, PROCESS_IS_VALID)
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()

Added: lldb/trunk/test/functionalities/process_attach/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/process_attach/main.c?rev=180977&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/process_attach/main.c (added)
+++ lldb/trunk/test/functionalities/process_attach/main.c Thu May  2 19:10:27 2013
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <unistd.h>
+
+int main(int argc, char const *argv[]) {
+    // Waiting to be attached by the debugger.
+    int temp = 0;
+    while (temp < 30) // Waiting to be attached...
+    {
+        sleep(1);
+        temp++;
+    }
+
+    printf("Exiting now\n");
+}





More information about the lldb-commits mailing list