summaryrefslogtreecommitdiff
path: root/bindings/python/llvm/tests/test_object.py
diff options
context:
space:
mode:
authorGregory Szorc <gregory.szorc@gmail.com>2012-03-10 04:41:24 +0000
committerGregory Szorc <gregory.szorc@gmail.com>2012-03-10 04:41:24 +0000
commit61e22cd85cd4c84fff391da67018c92bf21a8e19 (patch)
tree9f3f6b06d25b5735247ea51b665ed16a858cab3b /bindings/python/llvm/tests/test_object.py
parent51cf8661637c114e4b4f178bd2677a6bb246be0d (diff)
downloadllvm-61e22cd85cd4c84fff391da67018c92bf21a8e19.tar.gz
llvm-61e22cd85cd4c84fff391da67018c92bf21a8e19.tar.bz2
llvm-61e22cd85cd4c84fff391da67018c92bf21a8e19.tar.xz
[llvm.py] Implement interface to object files
It is now possible to load object files and scan over sections, symbols, and relocations! Includes test code with partial coverage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152482 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/llvm/tests/test_object.py')
-rw-r--r--bindings/python/llvm/tests/test_object.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/bindings/python/llvm/tests/test_object.py b/bindings/python/llvm/tests/test_object.py
new file mode 100644
index 0000000000..7ff981b6a2
--- /dev/null
+++ b/bindings/python/llvm/tests/test_object.py
@@ -0,0 +1,67 @@
+from .base import TestBase
+from ..object import ObjectFile
+from ..object import Relocation
+from ..object import Section
+from ..object import Symbol
+
+class TestObjectFile(TestBase):
+ def get_object_file(self):
+ source = self.get_test_binary()
+ return ObjectFile(filename=source)
+
+ def test_create_from_file(self):
+ self.get_object_file()
+
+ def test_get_sections(self):
+ o = self.get_object_file()
+
+ count = 0
+ for section in o.get_sections():
+ count += 1
+ assert isinstance(section, Section)
+ assert isinstance(section.name, str)
+ assert isinstance(section.size, long)
+ assert isinstance(section.contents, str)
+ assert isinstance(section.address, long)
+
+ self.assertGreater(count, 0)
+
+ for section in o.get_sections():
+ section.cache()
+
+ def test_get_symbols(self):
+ o = self.get_object_file()
+
+ count = 0
+ for symbol in o.get_symbols():
+ count += 1
+ assert isinstance(symbol, Symbol)
+ assert isinstance(symbol.name, str)
+ assert isinstance(symbol.address, long)
+ assert isinstance(symbol.size, long)
+ assert isinstance(symbol.file_offset, long)
+
+ self.assertGreater(count, 0)
+
+ for symbol in o.get_symbols():
+ symbol.cache()
+
+ def test_symbol_section_accessor(self):
+ o = self.get_object_file()
+
+ for symbol in o.get_symbols():
+ section = symbol.section
+ assert isinstance(section, Section)
+
+ break
+
+ def test_get_relocations(self):
+ o = self.get_object_file()
+ for section in o.get_sections():
+ for relocation in section.get_relocations():
+ assert isinstance(relocation, Relocation)
+ assert isinstance(relocation.address, long)
+ assert isinstance(relocation.offset, long)
+ assert isinstance(relocation.type_number, long)
+ assert isinstance(relocation.type_name, str)
+ assert isinstance(relocation.value_string, str)