[diffoscope] 03/05: Add test for rlib files, helping also to test ArFile, LlvmBitCodeFile and RustObjectFile
Ximin Luo
infinity0 at debian.org
Sat Aug 13 03:05:03 CEST 2016
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository diffoscope.
commit e3a4b348a9862cc66e30c4c7b23a30479dfe495c
Author: Ximin Luo <infinity0 at debian.org>
Date: Sat Aug 13 02:35:37 2016 +0200
Add test for rlib files, helping also to test ArFile, LlvmBitCodeFile and RustObjectFile
---
diffoscope/comparators/llvm.py | 5 +-
tests/comparators/{test_gzip.py => test_rlib.py} | 64 ++++++++++-------------
tests/data/rlib_elf_expected_diff | 17 ++++++
tests/data/rlib_llvm_dis_expected_diff | 36 +++++++++++++
tests/data/test1.rlib | Bin 0 -> 9734 bytes
tests/data/test2.rlib | Bin 0 -> 9734 bytes
6 files changed, 86 insertions(+), 36 deletions(-)
diff --git a/diffoscope/comparators/llvm.py b/diffoscope/comparators/llvm.py
index a740bf8..a78019b 100644
--- a/diffoscope/comparators/llvm.py
+++ b/diffoscope/comparators/llvm.py
@@ -32,7 +32,10 @@ class LlvmBcAnalyzer(Command):
class LlvmBcDisassembler(Command):
@tool_required('llvm-dis')
def cmdline(self):
- return ['llvm-dis', '-o', '-', self.path]
+ # execute llvm-dis from the same directory as the file, so it doesn't
+ # embed the whole path, including our tempdir, into the output.
+ # this makes it easier to generate reproducible diffs for our tests.
+ return ['find', self.path, '-execdir', 'llvm-dis', '-o', '-', '{}', ';']
class LlvmBitCodeFile(File):
@staticmethod
diff --git a/tests/comparators/test_gzip.py b/tests/comparators/test_rlib.py
similarity index 53%
copy from tests/comparators/test_gzip.py
copy to tests/comparators/test_rlib.py
index 038398f..5ef7032 100644
--- a/tests/comparators/test_gzip.py
+++ b/tests/comparators/test_rlib.py
@@ -3,6 +3,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
+# Copyright © 2016 Ximin Luo <infinity0 at debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -22,58 +23,51 @@ import shutil
import pytest
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from diffoscope.comparators.gzip import GzipFile
+from diffoscope.comparators.ar import ArFile
+from diffoscope.comparators.llvm import LlvmBitCodeFile
+from diffoscope.comparators.rust import RustObjectFile
from diffoscope.config import Config
-TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.gz')
-TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.gz')
+TEST_FILE1_PATH = os.path.join(os.path.dirname(__file__), '../data/test1.rlib')
+TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.rlib')
@pytest.fixture
-def gzip1():
+def rlib1():
return specialize(FilesystemFile(TEST_FILE1_PATH))
@pytest.fixture
-def gzip2():
+def rlib2():
return specialize(FilesystemFile(TEST_FILE2_PATH))
-def test_identification(gzip1):
- assert isinstance(gzip1, GzipFile)
+def test_identification(rlib1):
+ assert isinstance(rlib1, ArFile)
-def test_no_differences(gzip1):
- difference = gzip1.compare(gzip1)
+def test_no_differences(rlib1):
+ difference = rlib1.compare(rlib1)
assert difference is None
@pytest.fixture
-def differences(gzip1, gzip2):
- return gzip1.compare(gzip2).details
+def differences(rlib1, rlib2):
+ return rlib1.compare(rlib2).details
-def test_metadata(differences):
- assert differences[0].source1 == 'metadata'
- assert differences[0].source2 == 'metadata'
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/gzip_metadata_expected_diff')).read()
- assert differences[0].unified_diff == expected_diff
+def test_item0_elf(differences):
+ assert differences[0].source1 == 'alloc_system-d16b8f0e.0.o'
+ assert differences[0].source2 == 'alloc_system-d16b8f0e.0.o'
+ expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/rlib_elf_expected_diff')).read()
+ assert differences[0].details[0].unified_diff == expected_diff
-def test_content_source(differences):
- assert differences[1].source1 == 'test1'
- assert differences[1].source2 == 'test2'
+def test_item1_rust_metadata_bin(differences):
+ assert differences[1].source1 == 'rust.metadata.bin'
+ assert differences[1].source2 == 'rust.metadata.bin'
-def test_content_source_without_extension(tmpdir):
- path1 = str(tmpdir.join('test1'))
- path2 = str(tmpdir.join('test2'))
- shutil.copy(TEST_FILE1_PATH, path1)
- shutil.copy(TEST_FILE2_PATH, path2)
- gzip1 = specialize(FilesystemFile(path1))
- gzip2 = specialize(FilesystemFile(path2))
- difference = gzip1.compare(gzip2).details
- assert difference[1].source1 == 'test1-content'
- assert difference[1].source2 == 'test2-content'
+def test_item2_deflate_llvm_bitcode(differences):
+ assert differences[2].source1 == 'alloc_system-d16b8f0e.0.bytecode.deflate'
+ assert differences[2].source2 == 'alloc_system-d16b8f0e.0.bytecode.deflate'
+ expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/rlib_llvm_dis_expected_diff')).read()
+ assert differences[2].details[0].details[1].unified_diff == expected_diff
-def test_content_diff(differences):
- expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/text_ascii_expected_diff')).read()
- assert differences[1].unified_diff == expected_diff
-
-def test_compare_non_existing(monkeypatch, gzip1):
+def test_compare_non_existing(monkeypatch, rlib1):
monkeypatch.setattr(Config.general, 'new_file', True)
- difference = gzip1.compare(NonExistingFile('/nonexisting', gzip1))
+ difference = rlib1.compare(NonExistingFile('/nonexisting', rlib1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
diff --git a/tests/data/rlib_elf_expected_diff b/tests/data/rlib_elf_expected_diff
new file mode 100644
index 0000000..282cb63
--- /dev/null
+++ b/tests/data/rlib_elf_expected_diff
@@ -0,0 +1,17 @@
+@@ -6,15 +6,15 @@
+ 0000000000000000 <__rust_reallocate>:
+ __rust_reallocate():
+ 0: 41 57 push %r15
+ 2: 41 56 push %r14
+ 4: 41 54 push %r12
+ 6: 53 push %rbx
+ 7: 50 push %rax
+- 8: 48 89 d3 mov %rdx,%rbx
++ 8: 48 89 d1 mov %rdx,%rcx
+ b: 49 89 f7 mov %rsi,%r15
+ e: 49 89 fe mov %rdi,%r14
+ 11: 48 83 f9 10 cmp $0x10,%rcx
+ 15: 77 16 ja 2d <__rust_reallocate+0x2d>
+ 17: 4c 89 f7 mov %r14,%rdi
+ 1a: 48 89 de mov %rbx,%rsi
+ 1d: 48 83 c4 08 add $0x8,%rsp
diff --git a/tests/data/rlib_llvm_dis_expected_diff b/tests/data/rlib_llvm_dis_expected_diff
new file mode 100644
index 0000000..f649c2d
--- /dev/null
+++ b/tests/data/rlib_llvm_dis_expected_diff
@@ -0,0 +1,36 @@
+@@ -41,32 +41,32 @@
+ entry-block:
+ %out.i.i = alloca i8*, align 8
+ %4 = icmp ult i64 %3, 17
+ br i1 %4, label %then-block-195-.i, label %_ZN12alloc_system3imp8allocate17h8ba7625cc4a820e8E.exit.i
+
+ then-block-195-.i: ; preds = %entry-block
+ %5 = tail call i8* @realloc(i8* %0, i64 %2) #3
+- br label %_ZN12alloc_system3imp10reallocate17h4a0811c9ec086854E.exit
++ br label %_ZN12alloc_system3imp10reallocate1l44a0811c9ec086854E.exit
+
+ _ZN12alloc_system3imp8allocate17h8ba7625cc4a820e8E.exit.i: ; preds = %entry-block
+ %6 = bitcast i8** %out.i.i to i8*
+ call void @llvm.lifetime.start(i64 8, i8* %6) #3
+ store i8* null, i8** %out.i.i, align 8
+ %7 = call i32 @posix_memalign(i8** nonnull %out.i.i, i64 %3, i64 %2) #3
+ %8 = icmp eq i32 %7, 0
+ %9 = load i8*, i8** %out.i.i, align 8
+ %sret_slot.0.i.i = select i1 %8, i8* %9, i8* null
+ call void @llvm.lifetime.end(i64 8, i8* %6) #3
+ %10 = icmp ule i64 %2, %1
+ %11 = select i1 %10, i64 %2, i64 %1
+ call void @llvm.memmove.p0i8.p0i8.i64(i8* %sret_slot.0.i.i, i8* %0, i64 %11, i32 1, i1 false) #3
+ call void @free(i8* %0) #3
+- br label %_ZN12alloc_system3imp10reallocate17h4a0811c9ec086854E.exit
++ br label %_ZN12alloc_system3imp10reallocate1l44a0811c9ec086854E.exit
+
+-_ZN12alloc_system3imp10reallocate17h4a0811c9ec086854E.exit: ; preds = %_ZN12alloc_system3imp8allocate17h8ba7625cc4a820e8E.exit.i, %then-block-195-.i
++_ZN12alloc_system3imp10reallocate1l44a0811c9ec086854E.exit: ; preds = %_ZN12alloc_system3imp8allocate17h8ba7625cc4a820e8E.exit.i, %then-block-195-.i
+ %sret_slot.0.i = phi i8* [ %5, %then-block-195-.i ], [ %sret_slot.0.i.i, %_ZN12alloc_system3imp8allocate17h8ba7625cc4a820e8E.exit.i ]
+ ret i8* %sret_slot.0.i
+ }
+
+ ; Function Attrs: nounwind readnone uwtable
+ define i64 @__rust_reallocate_inplace(i8* nocapture readnone, i64, i64, i64) unnamed_addr #1 {
+ entry-block:
diff --git a/tests/data/test1.rlib b/tests/data/test1.rlib
new file mode 100644
index 0000000..0520f6e
Binary files /dev/null and b/tests/data/test1.rlib differ
diff --git a/tests/data/test2.rlib b/tests/data/test2.rlib
new file mode 100644
index 0000000..149358c
Binary files /dev/null and b/tests/data/test2.rlib differ
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list