[Git][reproducible-builds/diffoscope][master] 3 commits: Simplify parsing of optional "command_args" argument to Difference.from_command_exc.

Chris Lamb gitlab at salsa.debian.org
Thu Aug 15 23:46:51 UTC 2019



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
cc9a7301 by Chris Lamb at 2019-08-15T23:30:13Z
Simplify parsing of optional "command_args" argument to Difference.from_command_exc.

- - - - -
d3c7ac8e by Chris Lamb at 2019-08-15T23:42:29Z
Add support to Difference.from_command_exc and friends to ignore specific returncodes from the called program and treat them as "no" difference.

- - - - -
962eb040 by Chris Lamb at 2019-08-15T23:45:42Z
Don't fallback to a (useless) raw hexdump when, for example, readelf(1) reports an minor issue in a section in an ELF binary. For example, when the "frames" section is of the "NOBITS" type its contents are apparently "unreliable" and thus readelf(1) returns 1). (Closes: reproducible-builds/diffoscope#58, Debian:#931962)

- - - - -


6 changed files:

- diffoscope/comparators/elf.py
- diffoscope/difference.py
- tests/comparators/test_elf.py
- + tests/data/ignore_readelf_errors_expected_diff
- + tests/data/test1.debug
- + tests/data/test2.debug


Changes:

=====================================
diffoscope/comparators/elf.py
=====================================
@@ -263,7 +263,7 @@ READELF_COMMANDS = (
 
 def _compare_elf_data(path1, path2):
     return [
-        Difference.from_command(x, path1, path2)
+        Difference.from_command(x, path1, path2, ignore_returncodes={1})
         for x in list(READELF_COMMANDS) + READELF_DEBUG_DUMP_COMMANDS
     ]
 


=====================================
diffoscope/difference.py
=====================================
@@ -19,6 +19,7 @@
 
 import heapq
 import logging
+import subprocess
 
 from . import feeders
 from .exc import RequiredToolNotFound
@@ -256,10 +257,8 @@ class Difference(object):
 
     @staticmethod
     def from_command_exc(klass, path1, path2, *args, **kwargs):
-        command_args = []
-        if 'command_args' in kwargs:
-            command_args = kwargs['command_args']
-            del kwargs['command_args']
+        command_args = kwargs.pop('command_args', [])
+        ignore_returncodes = kwargs.pop('ignore_returncodes', ())
 
         def command_and_feeder(path):
             command = None
@@ -283,9 +282,15 @@ class Difference(object):
             source_cmd = command1 or command2
             kwargs['source'] = source_cmd.shell_cmdline()
 
-        difference = Difference.from_feeder(
-            feeder1, feeder2, path1, path2, *args, **kwargs
-        )
+        try:
+            difference = Difference.from_feeder(
+                feeder1, feeder2, path1, path2, *args, **kwargs
+            )
+        except subprocess.CalledProcessError as exc:
+            if exc.returncode in ignore_returncodes:
+                return None, False
+            assert False, exc.__dict__
+
         if not difference:
             return None, False
 


=====================================
tests/comparators/test_elf.py
=====================================
@@ -41,6 +41,8 @@ from ..utils.tools import (
 obj1 = load_fixture('test1.o')
 obj2 = load_fixture('test2.o')
 bug_903446 = load_fixture('bug_903446.a')
+ignore_readelf_errors1 = load_fixture('test1.debug')
+ignore_readelf_errors2 = load_fixture('test2.debug')
 
 
 def readelf_version():
@@ -203,3 +205,28 @@ def test_bug_903446(bug_903446):
 
     # Not a real StaticLibFile
     assert isinstance(bug_903446, FilesystemFile)
+
+
+def test_ignore_readelf_errors1_identify(ignore_readelf_errors1):
+    assert isinstance(ignore_readelf_errors1, ElfFile)
+
+
+def test_ignore_readelf_errors1_identify(ignore_readelf_errors2):
+    assert isinstance(ignore_readelf_errors2, ElfFile)
+
+
+ at pytest.fixture
+def ignore_readelf_errors_differences(
+    ignore_readelf_errors1, ignore_readelf_errors2
+):
+    return ignore_readelf_errors1.compare(ignore_readelf_errors2).details
+
+
+ at skip_unless_tools_exist('readelf')
+ at skip_if_tool_version_is('readelf', readelf_version, '2.29')
+ at skip_if_binutils_does_not_support_x86()
+def test_ignore_readelf_errors(ignore_readelf_errors_differences):
+    with open('tests/data/ignore_readelf_errors_expected_diff', 'w') as f:
+        f.write(ignore_readelf_errors_differences[0].unified_diff)
+    expected_diff = get_data('ignore_readelf_errors_expected_diff')
+    assert ignore_readelf_errors_differences[0].unified_diff == expected_diff


=====================================
tests/data/ignore_readelf_errors_expected_diff
=====================================
@@ -0,0 +1,25 @@
+@@ -23,19 +23,19 @@
+   [18] .dynamic          NOBITS          0000000000003de0 000dd0 000200 10  WA  4   0  8
+   [19] .got              NOBITS          0000000000003fe0 000dd0 000020 08  WA  0   0  8
+   [20] .got.plt          NOBITS          0000000000004000 000dd0 000020 08  WA  0   0  8
+   [21] .data             NOBITS          0000000000004020 000dd0 000008 00  WA  0   0  8
+   [22] .bss              NOBITS          0000000000004028 000dd0 000008 00  WA  0   0  1
+   [23] .comment          PROGBITS        0000000000000000 00025c 00001d 01  MS  0   0  1
+   [24] .debug_aranges    PROGBITS        0000000000000000 000279 00005a 00   C  0   0  1
+-  [25] .debug_info       PROGBITS        0000000000000000 0002d3 000330 00   C  0   0  1
+-  [26] .debug_abbrev     PROGBITS        0000000000000000 000603 0000da 00   C  0   0  1
+-  [27] .debug_line       PROGBITS        0000000000000000 0006dd 000176 00   C  0   0  1
+-  [28] .debug_str        PROGBITS        0000000000000000 000853 0002c3 01 MSC  0   0  1
+-  [29] .debug_ranges     PROGBITS        0000000000000000 000b16 00004e 00   C  0   0  1
++  [25] .debug_info       PROGBITS        0000000000000000 0002d3 00032e 00   C  0   0  1
++  [26] .debug_abbrev     PROGBITS        0000000000000000 000601 0000da 00   C  0   0  1
++  [27] .debug_line       PROGBITS        0000000000000000 0006db 000176 00   C  0   0  1
++  [28] .debug_str        PROGBITS        0000000000000000 000851 0002c4 01 MSC  0   0  1
++  [29] .debug_ranges     PROGBITS        0000000000000000 000b15 00004e 00   C  0   0  1
+   [30] .symtab           SYMTAB          0000000000000000 000b68 000690 18     31  49  8
+   [31] .strtab           STRTAB          0000000000000000 0011f8 0002ca 00      0   0  1
+   [32] .shstrtab         STRTAB          0000000000000000 0014c2 000137 00      0   0  1
+ Key to Flags:
+   W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
+   L (link order), O (extra OS processing required), G (group), T (TLS),
+   C (compressed), x (unknown), o (OS specific), E (exclude),


=====================================
tests/data/test1.debug
=====================================
Binary files /dev/null and b/tests/data/test1.debug differ


=====================================
tests/data/test2.debug
=====================================
Binary files /dev/null and b/tests/data/test2.debug differ



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/5261096d1d10a765d4d7a93c718fc6ee0a49208b...962eb0408f1df38b6f4d2d75dbce1f1e9b246ea1

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/5261096d1d10a765d4d7a93c718fc6ee0a49208b...962eb0408f1df38b6f4d2d75dbce1f1e9b246ea1
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20190815/81b31502/attachment.html>


More information about the rb-commits mailing list