summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/test/array_types/TestArrayTypes.py2
-rw-r--r--lldb/test/bitfields/TestBitfields.py2
-rw-r--r--lldb/test/hello_world/Makefile5
-rw-r--r--lldb/test/hello_world/TestHelloWorld.py86
-rw-r--r--lldb/test/hello_world/main.c6
-rw-r--r--lldb/test/lldbtest.py43
6 files changed, 132 insertions, 12 deletions
diff --git a/lldb/test/array_types/TestArrayTypes.py b/lldb/test/array_types/TestArrayTypes.py
index 64e634e3cb6..0671f0afd7f 100644
--- a/lldb/test/array_types/TestArrayTypes.py
+++ b/lldb/test/array_types/TestArrayTypes.py
@@ -68,7 +68,7 @@ class TestArrayTypes(TestBase):
# The stop reason of the thread should be breakpoint.
thread = target.GetProcess().GetThreadAtIndex(0)
- self.assertTrue(thread.GetStopReason() == Enum("Breakpoint"),
+ self.assertTrue(thread.GetStopReason() == StopReasonEnum("Breakpoint"),
STOPPED_DUE_TO_BREAKPOINT)
# The breakpoint should have a hit count of 1.
diff --git a/lldb/test/bitfields/TestBitfields.py b/lldb/test/bitfields/TestBitfields.py
index 8a583aa47fb..886f5e8f1b3 100644
--- a/lldb/test/bitfields/TestBitfields.py
+++ b/lldb/test/bitfields/TestBitfields.py
@@ -69,7 +69,7 @@ class TestBitfields(TestBase):
# The stop reason of the thread should be breakpoint.
thread = target.GetProcess().GetThreadAtIndex(0)
- self.assertTrue(thread.GetStopReason() == Enum("Breakpoint"),
+ self.assertTrue(thread.GetStopReason() == StopReasonEnum("Breakpoint"),
STOPPED_DUE_TO_BREAKPOINT)
# The breakpoint should have a hit count of 1.
diff --git a/lldb/test/hello_world/Makefile b/lldb/test/hello_world/Makefile
new file mode 100644
index 00000000000..d6cd0db0506
--- /dev/null
+++ b/lldb/test/hello_world/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/test/hello_world/TestHelloWorld.py b/lldb/test/hello_world/TestHelloWorld.py
new file mode 100644
index 00000000000..294beadb65e
--- /dev/null
+++ b/lldb/test/hello_world/TestHelloWorld.py
@@ -0,0 +1,86 @@
+"""Test Python APIs for target, breakpoint, and process."""
+
+import os, time
+import unittest2
+import lldb
+from lldbtest import *
+
+class TestHelloWorld(TestBase):
+
+ mydir = "hello_world"
+
+ @unittest2.expectedFailure
+ def test_hellp_world_python(self):
+ """Create target, breakpoint, launch a process, and then kill it."""
+
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+
+ breakpoint = target.BreakpointCreateByLocation("main.c", 4)
+
+ # The default state after breakpoint creation should be enabled.
+ self.assertTrue(breakpoint.IsEnabled(),
+ "Breakpoint should be enabled after creation")
+
+ breakpoint.SetEnabled(False)
+ self.assertTrue(not breakpoint.IsEnabled(),
+ "Breakpoint.SetEnabled(False) works")
+
+ breakpoint.SetEnabled(True)
+ self.assertTrue(breakpoint.IsEnabled(),
+ "Breakpoint.SetEnabled(True) works")
+
+ # rdar://problem/8364687
+ # SBTarget.LaunchProcess() issue (or is there some race condition)?
+
+ # The following approach of launching a process looks untidy and only
+ # works sometimes.
+ process = target.LaunchProcess([''], [''], os.ctermid(), False)
+
+ SR = process.GetThreadAtIndex(0).GetStopReason()
+ count = 0
+ while SR == StopReasonEnum("Invalid") or SR == StopReasonEnum("Signal"):
+ print >> sys.stderr, "StopReason =", StopReasonString(SR)
+
+ time.sleep(1.0)
+ print >> sys.stderr, "Continuing the process:", process
+ process.Continue()
+
+ count = count + 1
+ if count == 10:
+ print >> sys.stderr, "Reached 10 iterations, giving up..."
+ break
+
+ SR = process.GetThreadAtIndex(0).GetStopReason()
+
+ # End of section of launching a process.
+
+ # On the other hand, the following two lines of code are more reliable.
+ #self.runCmd("run")
+ #process = target.GetProcess()
+
+ self.runCmd("thread backtrace")
+ self.runCmd("breakpoint list")
+ self.runCmd("thread list")
+
+ # The stop reason of the thread should be breakpoint.
+ thread = process.GetThreadAtIndex(0)
+
+ print >> sys.stderr, "StopReason =", StopReasonString(thread.GetStopReason())
+ self.assertTrue(thread.GetStopReason() == StopReasonEnum("Breakpoint"),
+ STOPPED_DUE_TO_BREAKPOINT)
+
+ # The breakpoint should have a hit count of 1.
+ self.assertTrue(breakpoint.GetHitCount() == 1, BREAKPOINT_HIT_ONCE)
+
+ # Now kill the process, and we are done.
+ rc = process.Kill()
+ self.assertTrue(rc.Success())
+
+
+if __name__ == '__main__':
+ import atexit
+ lldb.SBDebugger.Initialize()
+ atexit.register(lambda: lldb.SBDebugger.Terminate())
+ unittest2.main()
diff --git a/lldb/test/hello_world/main.c b/lldb/test/hello_world/main.c
new file mode 100644
index 00000000000..277aa54a4ee
--- /dev/null
+++ b/lldb/test/hello_world/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char const *argv[]) {
+ printf("Hello world.\n");
+ return 0;
+}
diff --git a/lldb/test/lldbtest.py b/lldb/test/lldbtest.py
index 0eb650399a7..851b2de6794 100644
--- a/lldb/test/lldbtest.py
+++ b/lldb/test/lldbtest.py
@@ -149,29 +149,52 @@ def CMD_MSG(command):
return "Command '%s' returns successfully" % (command)
#
-# Returns the enum from the input string stopReason.
+# Returns the enum from the input string.
#
-def Enum(stopReason):
- if stopReason == "Invalid":
+def StopReasonEnum(string):
+ if string == "Invalid":
return 0
- elif stopReason == "None":
+ elif string == "None":
return 1
- elif stopReason == "Trace":
+ elif string == "Trace":
return 2
- elif stopReason == "Breakpoint":
+ elif string == "Breakpoint":
return 3
- elif stopReason == "Watchpoint":
+ elif string == "Watchpoint":
return 4
- elif stopReason == "Signal":
+ elif string == "Signal":
return 5
- elif stopReason == "Exception":
+ elif string == "Exception":
return 6
- elif stopReason == "PlanComplete":
+ elif string == "PlanComplete":
return 7
else:
raise Exception("Unknown stopReason string")
#
+# Returns the stopReason string given an enum.
+#
+def StopReasonString(enum):
+ if enum == 0:
+ return "Invalid"
+ elif enum == 1:
+ return "None"
+ elif enum == 2:
+ return "Trace"
+ elif enum == 3:
+ return "Breakpoint"
+ elif enum == 4:
+ return "Watchpoint"
+ elif enum == 5:
+ return "Signal"
+ elif enum == 6:
+ return "Exception"
+ elif enum == 7:
+ return "PlanComplete"
+ else:
+ raise Exception("Unknown stopReason enum")
+
+#
# Returns an env variable array from the os.environ map object.
#
def EnvArray():
OpenPOWER on IntegriCloud