diff options
| author | Jordan Rupprecht <rupprecht@google.com> | 2020-02-11 10:01:16 -0800 |
|---|---|---|
| committer | Jordan Rupprecht <rupprecht@google.com> | 2020-02-11 10:03:53 -0800 |
| commit | 99451b4453688a94c6014cac233d371ab4cc342d (patch) | |
| tree | 5f388465c19360723e2311c105c8f66e944c8d68 /lldb/test/API/python_api/module_section/TestModuleAndSection.py | |
| parent | 29bc5dd19407c4d7cad1c059dea26ee216ddc7ca (diff) | |
[lldb][test] Remove symlink for API tests.
Summary: Moves lldbsuite tests to lldb/test/API.
This is a largely mechanical change, moved with the following steps:
```
rm lldb/test/API/testcases
mkdir -p lldb/test/API/{test_runner/test,tools/lldb-{server,vscode}}
mv lldb/packages/Python/lldbsuite/test/test_runner/test lldb/test/API/test_runner
for d in $(find lldb/packages/Python/lldbsuite/test/* -maxdepth 0 -type d | egrep -v "make|plugins|test_runner|tools"); do mv $d lldb/test/API; done
for d in $(find lldb/packages/Python/lldbsuite/test/tools/lldb-vscode -maxdepth 1 -mindepth 1 | grep -v ".py"); do mv $d lldb/test/API/tools/lldb-vscode; done
for d in $(find lldb/packages/Python/lldbsuite/test/tools/lldb-server -maxdepth 1 -mindepth 1 | egrep -v "gdbremote_testcase.py|lldbgdbserverutils.py|socket_packet_pump.py"); do mv $d lldb/test/API/tools/lldb-server; done
```
lldb/packages/Python/lldbsuite/__init__.py and lldb/test/API/lit.cfg.py were also updated with the new directory structure.
Reviewers: labath, JDevlieghere
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D71151
Diffstat (limited to 'lldb/test/API/python_api/module_section/TestModuleAndSection.py')
| -rw-r--r-- | lldb/test/API/python_api/module_section/TestModuleAndSection.py | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/module_section/TestModuleAndSection.py b/lldb/test/API/python_api/module_section/TestModuleAndSection.py new file mode 100644 index 000000000000..95d457697e7c --- /dev/null +++ b/lldb/test/API/python_api/module_section/TestModuleAndSection.py @@ -0,0 +1,167 @@ +""" +Test some SBModule and SBSection APIs. +""" + +from __future__ import print_function + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +from lldbsuite.test.lldbutil import symbol_type_to_str + + +class ModuleAndSectionAPIsTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + # Py3 asserts due to a bug in SWIG. A fix for this was upstreamed into + # SWIG 3.0.8. + @skipIf(py_version=['>=', (3, 0)], swig_version=['<', (3, 0, 8)]) + @add_test_categories(['pyapi']) + def test_module_and_section(self): + """Test module and section APIs.""" + self.build() + exe = self.getBuildArtifact("a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + self.assertTrue(target.GetNumModules() > 0) + + # Hide stdout if not running with '-t' option. + if not self.TraceOn(): + self.HideStdout() + + print("Number of modules for the target: %d" % target.GetNumModules()) + for module in target.module_iter(): + print(module) + + # Get the executable module at index 0. + exe_module = target.GetModuleAtIndex(0) + + print("Exe module: %s" % str(exe_module)) + print("Number of sections: %d" % exe_module.GetNumSections()) + print("Number of symbols: %d" % len(exe_module)) + INDENT = ' ' * 4 + INDENT2 = INDENT * 2 + for sec in exe_module.section_iter(): + print(sec) + print( + INDENT + + "Number of subsections: %d" % + sec.GetNumSubSections()) + if sec.GetNumSubSections() == 0: + for sym in exe_module.symbol_in_section_iter(sec): + print(INDENT + str(sym)) + print( + INDENT + + "symbol type: %s" % + symbol_type_to_str( + sym.GetType())) + else: + for subsec in sec: + print(INDENT + str(subsec)) + # Now print the symbols belonging to the subsection.... + for sym in exe_module.symbol_in_section_iter(subsec): + print(INDENT2 + str(sym)) + print( + INDENT2 + + "symbol type: %s" % + symbol_type_to_str( + sym.GetType())) + + @add_test_categories(['pyapi']) + def test_module_and_section_boundary_condition(self): + """Test module and section APIs by passing None when it expects a Python string.""" + self.build() + exe = self.getBuildArtifact("a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + self.assertTrue(target.GetNumModules() > 0) + + # Hide stdout if not running with '-t' option. + if not self.TraceOn(): + self.HideStdout() + + print("Number of modules for the target: %d" % target.GetNumModules()) + for module in target.module_iter(): + print(module) + + # Get the executable module at index 0. + exe_module = target.GetModuleAtIndex(0) + + print("Exe module: %s" % str(exe_module)) + print("Number of sections: %d" % exe_module.GetNumSections()) + + # Boundary condition testings. Should not crash lldb! + exe_module.FindFirstType(None) + exe_module.FindTypes(None) + exe_module.FindGlobalVariables(target, None, 1) + exe_module.FindFunctions(None, 0) + exe_module.FindSection(None) + + # Get the section at index 1. + if exe_module.GetNumSections() > 1: + sec1 = exe_module.GetSectionAtIndex(1) + print(sec1) + else: + sec1 = None + + if sec1: + sec1.FindSubSection(None) + + @add_test_categories(['pyapi']) + def test_module_compile_unit_iter(self): + """Test module's compile unit iterator APIs.""" + self.build() + exe = self.getBuildArtifact("a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + self.assertTrue(target.GetNumModules() > 0) + + # Hide stdout if not running with '-t' option. + if not self.TraceOn(): + self.HideStdout() + + print("Number of modules for the target: %d" % target.GetNumModules()) + for module in target.module_iter(): + print(module) + + # Get the executable module at index 0. + exe_module = target.GetModuleAtIndex(0) + + print("Exe module: %s" % str(exe_module)) + print("Number of compile units: %d" % exe_module.GetNumCompileUnits()) + INDENT = ' ' * 4 + INDENT2 = INDENT * 2 + for cu in exe_module.compile_unit_iter(): + print(cu) + + @add_test_categories(['pyapi']) + def test_find_compile_units(self): + """Exercise SBModule.FindCompileUnits() API.""" + d = {'EXE': 'b.out'} + self.build(dictionary=d) + self.setTearDownCleanup(dictionary=d) + self.find_compile_units(self.getBuildArtifact('b.out')) + + def find_compile_units(self, exe): + """Exercise SBModule.FindCompileUnits() API.""" + source_name_list = ["main.cpp", "b.cpp", "c.cpp"] + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + num_modules = target.GetNumModules() + for i in range(num_modules): + module = target.GetModuleAtIndex(i) + for source_name in source_name_list: + list = module.FindCompileUnits(lldb.SBFileSpec(source_name, False)) + for sc in list: + self.assertTrue( + sc.GetCompileUnit().GetFileSpec().GetFilename() == + source_name) |
