From 54206f3ffc21a8ed8f2969617531eae2311450d0 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Tue, 9 Feb 2016 22:46:14 +0000 Subject: [PATCH] Added tests for object file tools. (".o") --- golden-files/input/Mcrt1.o | Bin 0 -> 404 bytes .../results/objdump_disassemble-Mcrt1_o | 5 ++ golden-files/results/objdump_headers-Mcrt1_o | 23 +++++++++ golden-files/results/readelf-Mcrt1_o | 44 ++++++++++++++++++ tools.py | 8 ++-- tools_test.py | 6 +++ 6 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 golden-files/input/Mcrt1.o create mode 100644 golden-files/results/objdump_disassemble-Mcrt1_o create mode 100644 golden-files/results/objdump_headers-Mcrt1_o create mode 100644 golden-files/results/readelf-Mcrt1_o diff --git a/golden-files/input/Mcrt1.o b/golden-files/input/Mcrt1.o new file mode 100644 index 0000000000000000000000000000000000000000..2de812234c4f3269de36e22921a2ae4dc4927cc1 GIT binary patch literal 404 zcmb<-^>JflWMqH=Mh0dE1doBC1}b3!rZpJY8Q2(nlZ#3W_3{~#v?Yoe^olczONvSo zlNj_$QY%Ur^imQ_5*hT8ih)vj`6a1(?tY=V#U+W!*$jH=d8P3wsY#{jIhlFcFdGTe z+(0EDH?cvLLfnGT2Xn6=R2?$`b>cvI4j?9^P6lco)HnuQ_Ud3!#{<)ZBnNUQ%ubNB N0}xw-7*GK72LRh*8+`x( literal 0 HcmV?d00001 diff --git a/golden-files/results/objdump_disassemble-Mcrt1_o b/golden-files/results/objdump_disassemble-Mcrt1_o new file mode 100644 index 0000000..2968436 --- /dev/null +++ b/golden-files/results/objdump_disassemble-Mcrt1_o @@ -0,0 +1,5 @@ + +./input/Mcrt1.o: file format elf32-i386 + +objdump: ./input/Mcrt1.o: not a dynamic object +objdump: ./input/Mcrt1.o: Invalid operation \ No newline at end of file diff --git a/golden-files/results/objdump_headers-Mcrt1_o b/golden-files/results/objdump_headers-Mcrt1_o new file mode 100644 index 0000000..8c1185b --- /dev/null +++ b/golden-files/results/objdump_headers-Mcrt1_o @@ -0,0 +1,23 @@ + +./input/Mcrt1.o: file format elf32-i386 +./input/Mcrt1.o +architecture: i386, flags 0x00000000: + +start address 0x00000000 + +Sections: +Idx Name Size VMA LMA File off Algn + 0 .text 00000000 00000000 00000000 00000034 2**0 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 1 .data 00000000 00000000 00000000 00000034 2**0 + CONTENTS, ALLOC, LOAD, DATA + 2 .bss 00000000 00000000 00000000 00000034 2**0 + ALLOC + 3 .note.GNU-stack 00000000 00000000 00000000 00000034 2**0 + CONTENTS, READONLY + 4 .gnu_debuglink 0000000c 00000000 00000000 00000034 2**0 + CONTENTS, READONLY +SYMBOL TABLE: +no symbols + + \ No newline at end of file diff --git a/golden-files/results/readelf-Mcrt1_o b/golden-files/results/readelf-Mcrt1_o new file mode 100644 index 0000000..d9c97e6 --- /dev/null +++ b/golden-files/results/readelf-Mcrt1_o @@ -0,0 +1,44 @@ +ELF Header: + Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, little endian + Version: 1 (current) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL (Relocatable file) + Machine: Intel 80386 + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 (bytes into file) + Start of section headers: 124 (bytes into file) + Flags: 0x0 + Size of this header: 52 (bytes) + Size of program headers: 0 (bytes) + Number of program headers: 0 + Size of section headers: 40 (bytes) + Number of section headers: 7 + Section header string table index: 6 + +Section Headers: + [Nr] Name Type Addr Off Size ES Flg Lk Inf Al + [ 0] NULL 00000000 000000 000000 00 0 0 0 + [ 1] .text PROGBITS 00000000 000034 000000 00 AX 0 0 1 + [ 2] .data PROGBITS 00000000 000034 000000 00 WA 0 0 1 + [ 3] .bss NOBITS 00000000 000034 000000 00 WA 0 0 1 + [ 4] .note.GNU-stack PROGBITS 00000000 000034 000000 00 0 0 1 + [ 5] .gnu_debuglink PROGBITS 00000000 000034 00000c 00 0 0 1 + [ 6] .shstrtab STRTAB 00000000 000040 00003b 00 0 0 1 +Key to Flags: + W (write), A (alloc), X (execute), M (merge), S (strings) + I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) + O (extra OS processing required) o (OS specific), p (processor specific) + +There are no section groups in this file. + +There are no program headers in this file. + +There are no relocations in this file. + +The decoding of unwind sections for machine type Intel 80386 is not currently supported. + +No version information found in this file. \ No newline at end of file diff --git a/tools.py b/tools.py index 8a2eac5..1e084e3 100644 --- a/tools.py +++ b/tools.py @@ -459,11 +459,9 @@ objdump_headers.dependencies = {"binutils"} def objdump_disassemble(path): - stdout, *rest = _do_command( - ["objdump", "--disassemble", "--reloc", "--dynamic-reloc", path]) - import pygments.lexers.asm - lexer = pygments.lexers.asm.ObjdumpLexer() - return Status.ok, fill3.Text(list(pygments.lex(stdout, lexer))) + return _run_command( + ["objdump", "--disassemble", "--reloc", "--dynamic-reloc", path], + Status.normal) objdump_disassemble.dependencies = {"binutils"} diff --git a/tools_test.py b/tools_test.py index f5b3b83..ed5daf3 100755 --- a/tools_test.py +++ b/tools_test.py @@ -140,6 +140,12 @@ class ToolsTestCase(unittest.TestCase): self._sub_tests([(tools.splint, "hello.c", tools.Status.ok), (tools.splint, "hello.h", tools.Status.ok)]) + def test_object_file_tools(self): + self._sub_tests([ + (tools.objdump_headers, "Mcrt1.o", tools.Status.normal), + (tools.objdump_disassemble, "Mcrt1.o", tools.Status.problem), + (tools.readelf, "Mcrt1.o", tools.Status.normal)]) + def test_unzip(self): self._sub_tests([ (tools.unzip, "hi.zip", tools.Status.normal)])