Redo the new arm reloc test as a proper unit test, aligned with other tests
authorEli Bendersky <eliben@gmail.com>
Wed, 5 Sep 2018 12:29:44 +0000 (05:29 -0700)
committerEli Bendersky <eliben@gmail.com>
Wed, 5 Sep 2018 12:29:44 +0000 (05:29 -0700)
test/run_arm_reloc_call_test.py [deleted file]
test_arm_call_reloc.py [new file with mode: 0755]

diff --git a/test/run_arm_reloc_call_test.py b/test/run_arm_reloc_call_test.py
deleted file mode 100755 (executable)
index 261949d..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python
-#-------------------------------------------------------------------------------
-# test/run_arm_reloc_call_test.py
-#
-# Test 'R_ARM_CALL' relocation type support.
-# Compare the '.text' section data of ELF file that relocated by elftools
-# and ELF file that relocated by linker.
-#
-# Dmitry Koltunov (koltunov@ispras.ru)
-#-------------------------------------------------------------------------------
-from os.path import (
-    join,
-    dirname
-)
-from sys import (
-    exit
-)
-
-from elftools.common.py3compat import (
-    BytesIO
-)
-from elftools.elf.elffile import (
-    ELFFile
-)
-from elftools.elf.relocation import (
-    RelocationHandler
-)
-
-
-def do_relocation(rel_elf):
-    data = rel_elf.get_section_by_name('.text').data()
-    rh = RelocationHandler(rel_elf)
-
-    stream = BytesIO()
-    stream.write(data)
-
-    rel = rel_elf.get_section_by_name('.rel.text')
-    rh.apply_section_relocations(stream, rel)
-
-    stream.seek(0)
-    data = stream.readlines()
-
-    return data
-
-
-def main():
-    test_dir = join(dirname(__file__) or '.', 'testfiles_for_unittests')
-    with open(join(test_dir, 'reloc_simple_arm_llvm.o'), 'rb') as rel_f, \
-            open(join(test_dir, 'simple_arm_llvm.elf'), 'rb') as f:
-        rel_elf = ELFFile(rel_f)
-        elf = ELFFile(f)
-
-        # Comparison of '.text' section data
-        if do_relocation(rel_elf).pop() != elf.get_section_by_name('.text').data():
-            print 'FAIL'
-            return 1
-        print 'OK'
-        return 0
-
-
-if __name__ == '__main__':
-    exit(main())
diff --git a/test_arm_call_reloc.py b/test_arm_call_reloc.py
new file mode 100755 (executable)
index 0000000..685cd71
--- /dev/null
@@ -0,0 +1,45 @@
+#-------------------------------------------------------------------------------
+# elftools tests
+#
+# Test 'R_ARM_CALL' relocation type support.
+# Compare the '.text' section data of ELF file that was relocated by elftools
+# with an ELF file that was relocated by linker.
+#
+# Dmitry Koltunov (koltunov@ispras.ru)
+# This code is in the public domain
+#-------------------------------------------------------------------------------
+import os
+import sys
+
+from elftools.common.py3compat import BytesIO
+from elftools.elf.elffile import ELFFile
+from elftools.elf.relocation import RelocationHandler
+
+
+def do_relocation(rel_elf):
+    data = rel_elf.get_section_by_name('.text').data()
+    rh = RelocationHandler(rel_elf)
+
+    stream = BytesIO()
+    stream.write(data)
+
+    rel = rel_elf.get_section_by_name('.rel.text')
+    rh.apply_section_relocations(stream, rel)
+
+    stream.seek(0)
+    data = stream.readlines()
+
+    return data
+
+
+class TestARMRElocation(unittest.TestCase):
+    def test_reloc(self):
+        test_dir = os.path.joinjoin('test', 'testfiles_for_unittests')
+        with open(join(test_dir, 'reloc_simple_arm_llvm.o'), 'rb') as rel_f, \
+                open(join(test_dir, 'simple_arm_llvm.elf'), 'rb') as f:
+            rel_elf = ELFFile(rel_f)
+            elf = ELFFile(f)
+
+            # Comparison of '.text' section data
+            self.assertEquals(do_relocation(rel_elf).pop(),
+                              elf.get_section_by_name('.text').data())