[Lldb-commits] [lldb] r112276 - in /lldb/trunk/test: array_types/TestArrayTypes.py bitfields/TestBitfields.py hello_world/ hello_world/Makefile hello_world/TestHelloWorld.py hello_world/main.c lldbtest.py
Johnny Chen
johnny.chen at apple.com
Fri Aug 27 11:08:58 PDT 2010
Author: johnny
Date: Fri Aug 27 13:08:58 2010
New Revision: 112276
URL: http://llvm.org/viewvc/llvm-project?rev=112276&view=rev
Log:
Added TestHelloWorld.py which exercises the Python APIs for target, breakpoint,
and process. Added comment within the file about issues of using LaunchProcess
of SBTarget to launch a process (rdar://problem/8364687).
Added:
lldb/trunk/test/hello_world/
lldb/trunk/test/hello_world/Makefile
lldb/trunk/test/hello_world/TestHelloWorld.py
lldb/trunk/test/hello_world/main.c
Modified:
lldb/trunk/test/array_types/TestArrayTypes.py
lldb/trunk/test/bitfields/TestBitfields.py
lldb/trunk/test/lldbtest.py
Modified: lldb/trunk/test/array_types/TestArrayTypes.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=112276&r1=112275&r2=112276&view=diff
==============================================================================
--- lldb/trunk/test/array_types/TestArrayTypes.py (original)
+++ lldb/trunk/test/array_types/TestArrayTypes.py Fri Aug 27 13:08:58 2010
@@ -68,7 +68,7 @@
# 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.
Modified: lldb/trunk/test/bitfields/TestBitfields.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/bitfields/TestBitfields.py?rev=112276&r1=112275&r2=112276&view=diff
==============================================================================
--- lldb/trunk/test/bitfields/TestBitfields.py (original)
+++ lldb/trunk/test/bitfields/TestBitfields.py Fri Aug 27 13:08:58 2010
@@ -69,7 +69,7 @@
# 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.
Added: lldb/trunk/test/hello_world/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/hello_world/Makefile?rev=112276&view=auto
==============================================================================
--- lldb/trunk/test/hello_world/Makefile (added)
+++ lldb/trunk/test/hello_world/Makefile Fri Aug 27 13:08:58 2010
@@ -0,0 +1,5 @@
+LEVEL = ../make
+
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/test/hello_world/TestHelloWorld.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/hello_world/TestHelloWorld.py?rev=112276&view=auto
==============================================================================
--- lldb/trunk/test/hello_world/TestHelloWorld.py (added)
+++ lldb/trunk/test/hello_world/TestHelloWorld.py Fri Aug 27 13:08:58 2010
@@ -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()
Added: lldb/trunk/test/hello_world/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/hello_world/main.c?rev=112276&view=auto
==============================================================================
--- lldb/trunk/test/hello_world/main.c (added)
+++ lldb/trunk/test/hello_world/main.c Fri Aug 27 13:08:58 2010
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char const *argv[]) {
+ printf("Hello world.\n");
+ return 0;
+}
Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=112276&r1=112275&r2=112276&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Fri Aug 27 13:08:58 2010
@@ -149,29 +149,52 @@
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():
More information about the lldb-commits
mailing list