[Lldb-commits] [lldb] r124510 - in /lldb/trunk/test/logging: ./ Makefile TestLogging.py main.cpp

Caroline Tice ctice at apple.com
Fri Jan 28 16:19:53 PST 2011


Author: ctice
Date: Fri Jan 28 18:19:53 2011
New Revision: 124510

URL: http://llvm.org/viewvc/llvm-project?rev=124510&view=rev
Log:
Add a test case to check logging of command processing.
Currently this test case works fine run by itself, but fails when
run in the entire test suite; Johnny requested that I check it in
so that he can look at it.


Added:
    lldb/trunk/test/logging/
    lldb/trunk/test/logging/Makefile
    lldb/trunk/test/logging/TestLogging.py
    lldb/trunk/test/logging/main.cpp

Added: lldb/trunk/test/logging/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/logging/Makefile?rev=124510&view=auto
==============================================================================
--- lldb/trunk/test/logging/Makefile (added)
+++ lldb/trunk/test/logging/Makefile Fri Jan 28 18:19:53 2011
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/test/logging/TestLogging.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/logging/TestLogging.py?rev=124510&view=auto
==============================================================================
--- lldb/trunk/test/logging/TestLogging.py (added)
+++ lldb/trunk/test/logging/TestLogging.py Fri Jan 28 18:19:53 2011
@@ -0,0 +1,93 @@
+"""
+Test lldb logging.
+"""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class LogTestCase(TestBase):
+
+    mydir = "logging"
+
+    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
+    def test_with_dsym (self):
+        self.buildDsym ()
+        self.command_log_tests ()
+
+    def test_with_dwarf (self):
+        self.buildDwarf ()
+        self.command_log_tests ()
+
+    def command_log_tests (self):
+        exe = os.path.join (os.getcwd(), "a.out")
+        self.expect("file " + exe,
+                    patterns = [ "Current executable set to .*a.out" ])
+
+        log_file = os.path.join (os.getcwd(), "lldb-commands-log.txt")
+
+        if (os.path.exists (log_file)):
+            os.remove (log_file)
+
+        self.runCmd ("log enable lldb commands -f " + log_file)
+        
+        self.runCmd ("commands alias bp breakpoint")
+                     
+        self.runCmd ("bp set -n main")
+
+        self.runCmd ("bp l")
+
+        expected_log_lines = [
+            "com.apple.main-thread Processing command: commands alias bp breakpoint\n",
+            "com.apple.main-thread HandleCommand, cmd_obj : 'commands alias'\n",
+            "com.apple.main-thread HandleCommand, revised_command_line: 'commands alias bp breakpoint'\n",
+            "com.apple.main-thread HandleCommand, wants_raw_input:'True'\n",
+            "com.apple.main-thread HandleCommand, command line after removing command name(s): 'bp breakpoint'\n",
+            "\n",
+            "com.apple.main-thread Processing command: bp set -n main\n",
+            "com.apple.main-thread HandleCommand, cmd_obj : 'breakpoint set'\n",
+            "com.apple.main-thread HandleCommand, revised_command_line: 'breakpoint set -n main'\n",
+            "com.apple.main-thread HandleCommand, wants_raw_input:'False'\n",
+            "com.apple.main-thread HandleCommand, command line after removing command name(s): '-n main'\n",
+            "\n",
+            "com.apple.main-thread Processing command: bp l\n",
+            "com.apple.main-thread HandleCommand, cmd_obj : 'breakpoint list'\n",
+            "com.apple.main-thread HandleCommand, revised_command_line: 'breakpoint l'\n",
+            "com.apple.main-thread HandleCommand, wants_raw_input:'False'\n",
+            "com.apple.main-thread HandleCommand, command line after removing command name(s): ''\n",
+            "\n"
+            ]
+
+        self.assertTrue (os.path.isfile (log_file))
+
+        idx = 0
+        end = len (expected_log_lines)
+        f = open (log_file)
+        log_lines = f.readlines()
+        f.close ()
+        os.remove (log_file)
+
+        err_msg = ""
+        success = True
+
+        if len (log_lines) != len (expected_log_lines):
+            success = False
+            err_msg = "Wrong number of lines in log file; expected: " + repr (len (expected_log_lines)) + " found: " + repr(len (log_lines))
+        else:
+            for line1, line2 in zip (log_lines, expected_log_lines):
+                if line1 != line2:
+                    success = False
+                    err_msg = "Expected '" + line2 + "'; Found '" + line1 + "'"
+                    break
+
+        if not success:
+            self.fail (err_msg)
+
+
+if __name__ == '__main__':
+    import atexit
+    lldb.SBDebugger.Initialize()
+    atexit.register(lambda: lldb.SBDebugger.Terminate())
+    unittest2.main()
+

Added: lldb/trunk/test/logging/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/logging/main.cpp?rev=124510&view=auto
==============================================================================
--- lldb/trunk/test/logging/main.cpp (added)
+++ lldb/trunk/test/logging/main.cpp Fri Jan 28 18:19:53 2011
@@ -0,0 +1,62 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <cstdlib>
+#include <string>
+#include <fstream>
+#include <iostream>
+
+int
+product (int x, int y)
+{
+    int result = x * y;
+    return result;
+}
+
+int
+sum (int a, int b)
+{
+    int result = a + b;
+    return result;
+}
+
+int
+strange_max (int m, int n)
+{
+    if (m > n)
+        return m;
+    else if (n > m)
+        return n;
+    else
+        return 0;
+}
+
+int
+foo (int i, int j)
+{
+    if (strange_max (i, j) == i)
+        return product (i, j);
+    else if (strange_max  (i, j) == j)
+        return sum (i, j);
+    else
+        return product (sum (i, i), sum (j, j));
+}
+
+int
+main(int argc, char const *argv[])
+{
+
+    int array[3];
+
+    array[0] = foo (1238, 78392);
+    array[1] = foo (379265, 23674);
+    array[2] = foo (872934, 234);
+
+    return 0;
+}





More information about the lldb-commits mailing list