[Lldb-commits] [lldb] r296669 - Add a sample_test directory with simple starter

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 1 12:25:49 PST 2017


Author: jingham
Date: Wed Mar  1 14:25:48 2017
New Revision: 296669

URL: http://llvm.org/viewvc/llvm-project?rev=296669&view=rev
Log:
Add a sample_test directory with simple starter
test cases for standard and "inline" tests.

Added:
    lldb/trunk/packages/Python/lldbsuite/test/sample_test/
    lldb/trunk/packages/Python/lldbsuite/test/sample_test/Makefile
    lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py
    lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py
    lldb/trunk/packages/Python/lldbsuite/test/sample_test/main.c
Modified:
    lldb/trunk/packages/Python/lldbsuite/test/README-TestSuite

Modified: lldb/trunk/packages/Python/lldbsuite/test/README-TestSuite
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/README-TestSuite?rev=296669&r1=296668&r2=296669&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/README-TestSuite (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/README-TestSuite Wed Mar  1 14:25:48 2017
@@ -54,6 +54,10 @@ o subdirectories of 'test'
   C/C++/ObjC source files; they were created to house the Python test case which
   does not involve lldb reading in an executable file at all.
 
+  The sample_test directory contains examples of both a full and an "inline" 
+  testcase that run a process to a breakpoint and check a local variable.  These
+  are convenient starting points for adding new tests.
+
 o make directory
 
   Contains Makefile.rules, which can be utilized by test cases to write Makefile
@@ -158,6 +162,9 @@ o Writing test cases:
  from the command in the command return object, and all the part where you are driving the 
  debugger to the point you want to test will be more robust.
 
+ The sample_test directory contains a standard and an "inline" test that are good starting
+ points for writing a new test.
+
 o Attaching in test cases:
 
  If you need to attach to inferiors in your tests, you must make sure the inferior calls

Added: lldb/trunk/packages/Python/lldbsuite/test/sample_test/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/sample_test/Makefile?rev=296669&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/sample_test/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/sample_test/Makefile Wed Mar  1 14:25:48 2017
@@ -0,0 +1,6 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+CFLAGS_EXTRAS += -std=c99
+
+include $(LEVEL)/Makefile.rules

Added: lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py?rev=296669&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py Wed Mar  1 14:25:48 2017
@@ -0,0 +1,6 @@
+from __future__ import absolute_import
+
+from lldbsuite.test import lldbinline
+
+lldbinline.MakeInlineTest(
+    __file__, globals(), None)

Added: lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py?rev=296669&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py Wed Mar  1 14:25:48 2017
@@ -0,0 +1,71 @@
+"""
+Sample test that runs a process to a source regexp breakpoint.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import re
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class SampleTestTestCase(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    NO_DEBUG_INFO_TESTCASE = True
+
+    def test_sample(self):
+        """A sample test example that drives a debug session to a breakpoint."""
+        self.build()
+        self.sample_test()
+
+    def setUp(self):
+        # Call super's setUp().
+        TestBase.setUp(self)
+
+    def sample_test(self):
+        """A sample test example that drives a debug session to a breakpoint."""
+        exe = os.path.join(os.getcwd(), "a.out")
+
+        # Create a target by the debugger.
+        target = self.dbg.CreateTarget(exe)
+        self.assertTrue(target, VALID_TARGET)
+
+        # Now create a breakpoint in main.c at the source matching
+        # "Set a breakpoint here"
+        breakpoint = target.BreakpointCreateBySourceRegex(
+            "Set a breakpoint here", lldb.SBFileSpec("main.c"))
+        self.assertTrue(breakpoint and
+                        breakpoint.GetNumLocations() >= 1,
+                        VALID_BREAKPOINT)
+
+        error = lldb.SBError()
+        # This is the launch info.  If you want to launch with arguments or
+        # environment variables, add them using SetArguments or
+        # SetEnvironmentEntries
+
+        launch_info = lldb.SBLaunchInfo(None)
+        process = target.Launch(launch_info, error)
+        self.assertTrue(process, PROCESS_IS_VALID)
+
+        # Did we hit our breakpoint?
+        from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint
+        threads = get_threads_stopped_at_breakpoint(process, breakpoint)
+        self.assertTrue(
+            len(threads) == 1,
+            "There should be a thread stopped at our breakpoint")
+
+        # The hit count for the breakpoint should be 1.
+        self.assertTrue(breakpoint.GetHitCount() == 1)
+
+        frame = threads[0].GetFrameAtIndex(0)
+        test_var = frame.FindVariable("test_var")
+        self.assertTrue(test_var.GetError().Success(), "Failed to fetch test_var")
+        test_value = test_var.GetValueAsUnsigned()
+        self.assertEqual(test_value, 10, "Got the right value for test_var")
+

Added: lldb/trunk/packages/Python/lldbsuite/test/sample_test/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/sample_test/main.c?rev=296669&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/sample_test/main.c (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/sample_test/main.c Wed Mar  1 14:25:48 2017
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+int
+main()
+{
+  int test_var = 10;
+  printf ("Set a breakpoint here: %d.\n", test_var);
+  //% test_var = self.frame().FindVariable("test_var")
+  //% test_value = test_var.GetValueAsUnsigned()
+  //% self.assertTrue(test_var.GetError().Success(), "Failed to fetch test_var")
+  //% self.assertEqual(test_value, 10, "Failed to get the right value for test_var")
+  return 0;
+}




More information about the lldb-commits mailing list