diff options
| author | Johnny Chen <johnny.chen@apple.com> | 2011-04-26 23:54:25 +0000 |
|---|---|---|
| committer | Johnny Chen <johnny.chen@apple.com> | 2011-04-26 23:54:25 +0000 |
| commit | c5f121e3c0ff2e2cf33160329756cf60803a3550 (patch) | |
| tree | 83a20f0716a7b379f743598bda765d63a74024d9 /lldb/test/python_api | |
| parent | bcb23a180b5eaa865baaf2a266330c6cc688c8db (diff) | |
| download | bcm5719-llvm-c5f121e3c0ff2e2cf33160329756cf60803a3550.tar.gz bcm5719-llvm-c5f121e3c0ff2e2cf33160329756cf60803a3550.zip | |
Add a test case for lldbutil.lldb_iter() which returns an iterator object
for lldb objects which can contain other lldb objects. Examples are:
SBTarget contains SBModule, SBModule contains SBSymbols, SBProcess contains
SBThread, SBThread contains SBFrame, etc.
llvm-svn: 130258
Diffstat (limited to 'lldb/test/python_api')
| -rw-r--r-- | lldb/test/python_api/lldbutil/TestLLDBIterator.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lldb/test/python_api/lldbutil/TestLLDBIterator.py b/lldb/test/python_api/lldbutil/TestLLDBIterator.py new file mode 100644 index 00000000000..5337ffaf5ab --- /dev/null +++ b/lldb/test/python_api/lldbutil/TestLLDBIterator.py @@ -0,0 +1,64 @@ +""" +Test lldbutil.lldb_iter() which returns an iterator object for lldb's aggregate +data structures. +""" + +import os, time +import re +import unittest2 +import lldb +from lldbtest import * + +class LLDBIteratorTestCase(TestBase): + + mydir = "python_api/lldbutil" + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.line = line_number('main.cpp', '// Set break point at this line.') + + def test_lldb_iter(self): + """Test lldb_iter works correctly.""" + self.buildDefault() + self.lldb_iter_test() + + def lldb_iter_test(self): + exe = os.path.join(os.getcwd(), "a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target.IsValid(), VALID_TARGET) + + breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line) + self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + rc = lldb.SBError() + self.process = target.Launch (self.dbg.GetListener(), None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc) + + if not rc.Success() or not self.process.IsValid(): + self.fail("SBTarget.LaunchProcess() failed") + + from lldbutil import lldb_iter, get_description + yours = [] + for i in range(target.GetNumModules()): + yours.append(target.GetModuleAtIndex(i)) + mine = [] + for m in lldb_iter(target, 'GetNumModules', 'GetModuleAtIndex'): + mine.append(m) + + self.assertTrue(len(yours) == len(mine)) + for i in range(len(yours)): + if self.TraceOn(): + print "yours[%d]='%s'" % (i, get_description(yours[i])) + print "mine[%d]='%s'" % (i, get_description(mine[i])) + self.assertTrue(yours[i].GetUUIDString() == mine[i].GetUUIDString(), + "UUID of yours[%d] and mine[%d] matches" % (i, i)) + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() |

