[Lldb-commits] [lldb] r219979 - Add a test for the -b (batch mode) option to the lldb driver.

Jim Ingham jingham at apple.com
Thu Oct 16 16:02:14 PDT 2014


Author: jingham
Date: Thu Oct 16 18:02:14 2014
New Revision: 219979

URL: http://llvm.org/viewvc/llvm-project?rev=219979&view=rev
Log:
Add a test for the -b (batch mode) option to the lldb driver.

Added:
    lldb/trunk/test/driver/
    lldb/trunk/test/driver/batch_mode/
    lldb/trunk/test/driver/batch_mode/Makefile
    lldb/trunk/test/driver/batch_mode/TestBatchMode.py
    lldb/trunk/test/driver/batch_mode/main.c
Modified:
    lldb/trunk/test/lldbtest.py

Added: lldb/trunk/test/driver/batch_mode/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/driver/batch_mode/Makefile?rev=219979&view=auto
==============================================================================
--- lldb/trunk/test/driver/batch_mode/Makefile (added)
+++ lldb/trunk/test/driver/batch_mode/Makefile Thu Oct 16 18:02:14 2014
@@ -0,0 +1,28 @@
+CC ?= clang
+ifeq "$(ARCH)" ""
+	ARCH = x86_64
+endif
+
+ifeq "$(OS)" ""
+	OS = $(shell uname -s)
+endif
+
+CFLAGS ?= -g -O0
+CWD := $(shell pwd)
+
+LIB_PREFIX := lib
+
+ifeq "$(OS)" "Darwin"
+	CFLAGS += -arch $(ARCH)
+endif
+
+all: a.out
+
+a.out: main.o
+	$(CC) $(CFLAGS) -o a.out main.o
+
+main.o: main.c
+	$(CC) $(CFLAGS) -c main.c
+
+clean:
+	rm -rf $(wildcard *.o *~ *.dylib *.so a.out *.dSYM)

Added: lldb/trunk/test/driver/batch_mode/TestBatchMode.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/driver/batch_mode/TestBatchMode.py?rev=219979&view=auto
==============================================================================
--- lldb/trunk/test/driver/batch_mode/TestBatchMode.py (added)
+++ lldb/trunk/test/driver/batch_mode/TestBatchMode.py Thu Oct 16 18:02:14 2014
@@ -0,0 +1,99 @@
+"""
+Test that the lldb driver's batch mode works correctly.
+"""
+
+import os, time
+import unittest2
+import lldb
+import pexpect
+from lldbtest import *
+
+class DriverBatchModeTest (TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    @unittest2.expectedFailure("<rdar://problem/18684124>, lldb doesn't reliably print the prompt when run under pexpect")
+    @dsym_test
+    def test_driver_batch_mode_with_dsym(self):
+        """Test that the lldb driver's batch mode works correctly."""
+        self.buildDsym()
+        self.setTearDownCleanup()
+        self.batch_mode ()
+
+    @unittest2.expectedFailure("<rdar://problem/18684124>, lldb doesn't reliably print the prompt when run under pexpect")
+    @dwarf_test
+    def test_driver_batch_mode_with_dwarf(self):
+        """Test that the lldb driver's batch mode works correctly."""
+        self.buildDwarf()
+        self.setTearDownCleanup()
+        self.batch_mode()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+        # Our simple source filename.
+        self.source = 'main.c'
+
+    def expect_string (self, string):
+        """This expects for "string", with timeout & EOF being test fails."""
+        try:
+            self.child.expect_exact(string)
+        except pexpect.EOF:
+            self.fail ("Got EOF waiting for '%s'"%(string))
+        except pexpect.TIMEOUT:
+            self.fail ("Timed out waiting for '%s'"%(string))
+
+
+    def batch_mode (self):
+        exe = os.path.join(os.getcwd(), "a.out")
+        prompt = "(lldb) "
+
+        # First time through, pass CRASH so the process will crash and stop in batch mode.
+        run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
+        self.child = pexpect.spawn('%s %s %s %s -- CRASH' % (self.lldbHere, self.lldbOption, run_commands, exe))
+        child = self.child
+        # Turn on logging for what the child sends back.
+        if self.TraceOn():
+            child.logfile_read = sys.stdout
+
+        # We should see the "run":
+        self.expect_string ("run")
+        # We should have hit the breakpoint & continued:
+        self.expect_string ("continue")
+        # The App should have crashed:
+        self.expect_string("About to crash")
+        # Then we should have a live prompt:
+        self.expect_string (prompt)
+        self.child.sendline("frame variable touch_me_not")
+        self.expect_string ('(char *) touch_me_not')
+        
+        self.deletePexpectChild()
+
+        # Now do it again, and see make sure if we don't crash, we quit:
+        run_commands = ' -b -o "break set -n main" -o "run" -o "continue" '
+        self.child = pexpect.spawn('%s %s %s %s -- NOCRASH' % (self.lldbHere, self.lldbOption, run_commands, exe))
+        child = self.child
+        # Turn on logging for what the child sends back.
+        if self.TraceOn():
+            child.logfile_read = sys.stdout
+
+        # We should see the "run":
+        self.expect_string ("run")
+        # We should have hit the breakpoint & continued:
+        self.expect_string ("continue")
+        # The App should have not have crashed:
+        self.expect_string("Got there on time and it did not crash.")
+        # Then we should have a live prompt:
+        self.expect_string ("exited")
+        index = self.child.expect([pexpect.EOF, pexpect.TIMEOUT])
+        self.assertTrue(index == 0, "lldb didn't close on successful batch completion.")
+
+        
+       
+
+        
+        
+
+
+

Added: lldb/trunk/test/driver/batch_mode/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/driver/batch_mode/main.c?rev=219979&view=auto
==============================================================================
--- lldb/trunk/test/driver/batch_mode/main.c (added)
+++ lldb/trunk/test/driver/batch_mode/main.c Thu Oct 16 18:02:14 2014
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <string.h>
+
+int 
+main (int argc, char **argv)
+{
+    if (argc >= 2 && strcmp (argv[1], "CRASH") == 0)
+    {
+      char *touch_me_not = (char *) 0;
+      printf ("About to crash.\n");
+      touch_me_not[0] = 'a';
+    }
+    printf ("Got there on time and it did not crash.\n");
+    return 0;
+}

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=219979&r1=219978&r2=219979&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Thu Oct 16 18:02:14 2014
@@ -997,11 +997,7 @@ class Base(unittest2.TestCase):
                 print >> sbuf, "Adding tearDown hook:", getsource_if_available(hook)
             self.hooks.append(hook)
 
-    def tearDown(self):
-        """Fixture for unittest test case teardown."""
-        #import traceback
-        #traceback.print_stack()
-
+    def deletePexpectChild(self):
         # This is for the case of directly spawning 'lldb' and interacting with it
         # using pexpect.
         if self.child and self.child.isalive():
@@ -1022,6 +1018,14 @@ class Base(unittest2.TestCase):
             # Give it one final blow to make sure the child is terminated.
             self.child.close()
 
+
+    def tearDown(self):
+        """Fixture for unittest test case teardown."""
+        #import traceback
+        #traceback.print_stack()
+
+        self.deletePexpectChild()
+
         # Check and run any hook functions.
         for hook in reversed(self.hooks):
             with recording(self, traceAlways) as sbuf:





More information about the lldb-commits mailing list