summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2017-03-01 20:25:48 +0000
committerJim Ingham <jingham@apple.com>2017-03-01 20:25:48 +0000
commit96b2530f52caa732af43b26e6d467dd15df9ffdf (patch)
treef062a8f7f0d07648cd1843d39bbb99b656b6795f /lldb/packages/Python/lldbsuite/test
parent0a4703b5ece8df0ed794d351a919aec490b539bb (diff)
downloadbcm5719-llvm-96b2530f52caa732af43b26e6d467dd15df9ffdf.tar.gz
bcm5719-llvm-96b2530f52caa732af43b26e6d467dd15df9ffdf.zip
Add a sample_test directory with simple starter
test cases for standard and "inline" tests. llvm-svn: 296669
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/README-TestSuite7
-rw-r--r--lldb/packages/Python/lldbsuite/test/sample_test/Makefile6
-rw-r--r--lldb/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py6
-rw-r--r--lldb/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py71
-rw-r--r--lldb/packages/Python/lldbsuite/test/sample_test/main.c13
5 files changed, 103 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/README-TestSuite b/lldb/packages/Python/lldbsuite/test/README-TestSuite
index 70e4c91b889..92649fc9963 100644
--- a/lldb/packages/Python/lldbsuite/test/README-TestSuite
+++ b/lldb/packages/Python/lldbsuite/test/README-TestSuite
@@ -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
diff --git a/lldb/packages/Python/lldbsuite/test/sample_test/Makefile b/lldb/packages/Python/lldbsuite/test/sample_test/Makefile
new file mode 100644
index 00000000000..0e5a537bbec
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/sample_test/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+CFLAGS_EXTRAS += -std=c99
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py b/lldb/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py
new file mode 100644
index 00000000000..2a37ecdab34
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/sample_test/TestSampleInlineTest.py
@@ -0,0 +1,6 @@
+from __future__ import absolute_import
+
+from lldbsuite.test import lldbinline
+
+lldbinline.MakeInlineTest(
+ __file__, globals(), None)
diff --git a/lldb/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py b/lldb/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py
new file mode 100644
index 00000000000..16f48022d9a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/sample_test/TestSampleTest.py
@@ -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")
+
diff --git a/lldb/packages/Python/lldbsuite/test/sample_test/main.c b/lldb/packages/Python/lldbsuite/test/sample_test/main.c
new file mode 100644
index 00000000000..0164d7155b0
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/sample_test/main.c
@@ -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;
+}
OpenPOWER on IntegriCloud