Commit e3a4b348 authored by Ximin Luo's avatar Ximin Luo

Add test for rlib files, helping also to test ArFile, LlvmBitCodeFile and RustObjectFile

parent 28dbe48e
......@@ -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
......
# -*- coding: utf-8 -*-
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2015 Jérémy Bobbio <lunar@debian.org>
# Copyright © 2016 Ximin Luo <infinity0@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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffoscope is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import os.path
import shutil
import pytest
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
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.rlib')
TEST_FILE2_PATH = os.path.join(os.path.dirname(__file__), '../data/test2.rlib')
@pytest.fixture
def rlib1():
return specialize(FilesystemFile(TEST_FILE1_PATH))
@pytest.fixture
def rlib2():
return specialize(FilesystemFile(TEST_FILE2_PATH))
def test_identification(rlib1):
assert isinstance(rlib1, ArFile)
def test_no_differences(rlib1):
difference = rlib1.compare(rlib1)
assert difference is None
@pytest.fixture
def differences(rlib1, rlib2):
return rlib1.compare(rlib2).details
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_item1_rust_metadata_bin(differences):
assert differences[1].source1 == 'rust.metadata.bin'
assert differences[1].source2 == 'rust.metadata.bin'
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_compare_non_existing(monkeypatch, rlib1):
monkeypatch.setattr(Config.general, 'new_file', True)
difference = rlib1.compare(NonExistingFile('/nonexisting', rlib1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
@@ -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
@@ -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:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment