diff options
Diffstat (limited to 'bindings/python/llvm/tests')
-rw-r--r-- | bindings/python/llvm/tests/test_core.py | 42 | ||||
-rw-r--r-- | bindings/python/llvm/tests/test_disassembler.py | 4 | ||||
-rw-r--r-- | bindings/python/llvm/tests/test_object.py | 2 |
3 files changed, 29 insertions, 19 deletions
diff --git a/bindings/python/llvm/tests/test_core.py b/bindings/python/llvm/tests/test_core.py index 63f84c828bc8..da7b635ec999 100644 --- a/bindings/python/llvm/tests/test_core.py +++ b/bindings/python/llvm/tests/test_core.py @@ -1,20 +1,30 @@ from .base import TestBase -from ..core import OpCode from ..core import MemoryBuffer from ..core import PassRegistry from ..core import Context from ..core import Module +from ..core import Enums +from ..core import OpCode from ..bit_reader import parse_bitcode class TestCore(TestBase): - def test_opcode(self): - self.assertTrue(hasattr(OpCode, 'Ret')) - self.assertTrue(isinstance(OpCode.Ret, OpCode)) - self.assertEqual(OpCode.Ret.value, 1) - - op = OpCode.from_value(1) - self.assertTrue(isinstance(op, OpCode)) - self.assertEqual(op, OpCode.Ret) + def test_enumerations(self): + for enum_cls, enum_spec in Enums: + for enum_name, enum_value in enum_spec: + # First make sure that enum_cls has the name of the enum as an + # attribute. People will access these values as + # EnumCls.EnumName. + self.assertTrue(hasattr(enum_cls, enum_name)) + v_attr = getattr(enum_cls, enum_name) + self.assertTrue(isinstance(v_attr, enum_cls)) + + # Then make sure that the value returned for this attribute is + # correct in both ways. + self.assertEqual(v_attr.value, enum_value) + + e = enum_cls.from_value(enum_value) + self.assertTrue(isinstance(e, enum_cls)) + self.assertEqual(e, v_attr) def test_memory_buffer_create_from_file(self): source = self.get_test_file() @@ -61,7 +71,7 @@ class TestCore(TestBase): target = "thumbv7-apple-ios5.0.0" m.target = target m.print_module_to_file("test2.ll") - + def test_module_function_iteration(self): m = parse_bitcode(MemoryBuffer(filename=self.get_test_bc())) i = 0 @@ -81,19 +91,19 @@ class TestCore(TestBase): def test_function_basicblock_iteration(self): m = parse_bitcode(MemoryBuffer(filename=self.get_test_bc())) i = 0 - + bb_list = ['b1', 'b2', 'end'] - + f = m.first while f.name != "f6": f = f.next - + # Forward for bb in f: self.assertEqual(bb.name, bb_list[i]) bb.dump() i += 1 - + # Backwards for bb in reversed(f): i -= 1 @@ -103,12 +113,12 @@ class TestCore(TestBase): def test_basicblock_instruction_iteration(self): m = parse_bitcode(MemoryBuffer(filename=self.get_test_bc())) i = 0 - + inst_list = [('arg1', OpCode.ExtractValue), ('arg2', OpCode.ExtractValue), ('', OpCode.Call), ('', OpCode.Ret)] - + bb = m.first.first # Forward diff --git a/bindings/python/llvm/tests/test_disassembler.py b/bindings/python/llvm/tests/test_disassembler.py index e960dc0ba9ca..37a04e4fc7e7 100644 --- a/bindings/python/llvm/tests/test_disassembler.py +++ b/bindings/python/llvm/tests/test_disassembler.py @@ -16,9 +16,9 @@ class TestDisassembler(TestBase): self.assertEqual(count, 3) self.assertEqual(s, '\tjcxz\t-127') - def test_nonexistant_triple(self): + def test_nonexistent_triple(self): with self.assertRaisesRegexp(Exception, "Could not obtain disassembler for triple"): - Disassembler("nonexistant-triple-raises") + Disassembler("nonexistent-triple-raises") def test_get_instructions(self): sequence = '\x67\xe3\x81\x01\xc7' # jcxz -127; addl %eax, %edi diff --git a/bindings/python/llvm/tests/test_object.py b/bindings/python/llvm/tests/test_object.py index 7ff981b6a2f7..3f92d8155b61 100644 --- a/bindings/python/llvm/tests/test_object.py +++ b/bindings/python/llvm/tests/test_object.py @@ -23,6 +23,7 @@ class TestObjectFile(TestBase): assert isinstance(section.size, long) assert isinstance(section.contents, str) assert isinstance(section.address, long) + assert len(section.contents) == section.size self.assertGreater(count, 0) @@ -39,7 +40,6 @@ class TestObjectFile(TestBase): 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) |