[diffoscope] 02/04: Skip tests if binutils can't handle the object file format. Based on a patch by Mattia Rizzolo (Closes: #851588)

Chris Lamb chris at chris-lamb.co.uk
Tue Jan 17 01:13:38 CET 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 9641b9dfbb1646517a0b000164e4f24dc418c9fb
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Jan 17 10:46:46 2017 +1100

    Skip tests if binutils can't handle the object file format. Based on a patch by Mattia Rizzolo (Closes: #851588)
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 tests/comparators/test_elf.py    |  7 ++++++-
 tests/comparators/test_rlib.py   |  5 ++++-
 tests/comparators/utils/tools.py | 18 ++++++++++++++++++
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/tests/comparators/test_elf.py b/tests/comparators/test_elf.py
index 64c41ba..e31200e 100644
--- a/tests/comparators/test_elf.py
+++ b/tests/comparators/test_elf.py
@@ -29,7 +29,8 @@ from diffoscope.comparators.missing_file import MissingFile
 from diffoscope.comparators.utils.specialize import specialize
 
 from utils.data import data, load_fixture
-from utils.tools import skip_unless_tools_exist
+from utils.tools import skip_unless_tools_exist, \
+    skip_if_binutils_does_not_support_x86
 
 
 try:
@@ -53,6 +54,7 @@ def obj_differences(obj1, obj2):
     return obj1.compare(obj2).details
 
 @skip_unless_tools_exist('readelf')
+ at skip_if_binutils_does_not_support_x86()
 def test_obj_compare_non_existing(monkeypatch, obj1):
     monkeypatch.setattr(Config(), 'new_file', True)
     difference = obj1.compare(MissingFile('/nonexisting', obj1))
@@ -60,6 +62,7 @@ def test_obj_compare_non_existing(monkeypatch, obj1):
     assert len(difference.details) > 0
 
 @skip_unless_tools_exist('readelf')
+ at skip_if_binutils_does_not_support_x86()
 def test_diff(obj_differences):
     assert len(obj_differences) == 1
     expected_diff = open(data('elf_obj_expected_diff')).read()
@@ -88,6 +91,7 @@ def lib_differences(lib1, lib2):
     return lib1.compare(lib2).details
 
 @skip_unless_tools_exist('readelf', 'objdump')
+ at skip_if_binutils_does_not_support_x86()
 def test_lib_differences(lib_differences):
     assert len(lib_differences) == 2
     assert lib_differences[0].source1 == 'file list'
@@ -98,6 +102,7 @@ def test_lib_differences(lib_differences):
     assert lib_differences[1].unified_diff == expected_objdump_diff
 
 @skip_unless_tools_exist('readelf', 'objdump')
+ at skip_if_binutils_does_not_support_x86()
 def test_lib_compare_non_existing(monkeypatch, lib1):
     monkeypatch.setattr(Config(), 'new_file', True)
     difference = lib1.compare(MissingFile('/nonexisting', lib1))
diff --git a/tests/comparators/test_rlib.py b/tests/comparators/test_rlib.py
index bc89337..ab7a090 100644
--- a/tests/comparators/test_rlib.py
+++ b/tests/comparators/test_rlib.py
@@ -25,7 +25,8 @@ from diffoscope.comparators.ar import ArFile
 
 from utils import diff_ignore_line_numbers
 from utils.data import data, load_fixture
-from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
+from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least, \
+    skip_if_binutils_does_not_support_x86
 from utils.nonexisting import assert_non_existing
 
 
@@ -52,6 +53,7 @@ def test_num_items(differences):
     assert len(differences) == 4
 
 @skip_unless_tools_exist('nm')
+ at skip_if_binutils_does_not_support_x86()
 def test_item0_armap(differences):
     assert differences[0].source1 == 'nm -s {}'
     assert differences[0].source2 == 'nm -s {}'
@@ -59,6 +61,7 @@ def test_item0_armap(differences):
     assert differences[0].unified_diff == expected_diff
 
 @skip_unless_tools_exist('nm')
+ at skip_if_binutils_does_not_support_x86()
 def test_item1_elf(differences):
     assert differences[1].source1 == 'alloc_system-d16b8f0e.0.o'
     assert differences[1].source2 == 'alloc_system-d16b8f0e.0.o'
diff --git a/tests/comparators/utils/tools.py b/tests/comparators/utils/tools.py
index 4bed1d3..d949aa1 100644
--- a/tests/comparators/utils/tools.py
+++ b/tests/comparators/utils/tools.py
@@ -19,10 +19,13 @@
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
 import pytest
+import functools
+import subprocess
 
 from distutils.spawn import find_executable
 from distutils.version import LooseVersion
 
+
 def tools_missing(*required):
     return not required or any(find_executable(x) is None for x in required)
 
@@ -41,3 +44,18 @@ def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
         vcls(str(actual_ver)) < vcls(str(min_ver)),
         reason="requires {} >= {} ({} detected)".format(tool, min_ver, actual_ver)
     )
+
+def skip_if_binutils_does_not_support_x86():
+    if tools_missing('objdump'):
+        return skip_unless_tools_exist('objdump')
+
+    return pytest.mark.skipif(
+       'elf64-x86-64' not in get_supported_elf_formats(),
+        reason="requires a binutils capable of reading x86-64 binaries"
+    )
+
+ at functools.lru_cache()
+def get_supported_elf_formats():
+    return set(subprocess.check_output(
+        ('objdump', '--info'),
+    ).decode('utf-8').splitlines())

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list