Skip to content

Commit

Permalink
Add a simple test suite and a "make check" target
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Clements committed Sep 28, 2016
1 parent edd65fd commit 0950be8
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ install:
clean:
$(MAKE) -C elf clean
$(MAKE) -C dwarf clean

check:
cd test && ./test.sh
11 changes: 11 additions & 0 deletions test/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
int fib(int x)
{
if (x <= 1)
return x;
return fib(x - 1) + fib(x - 2);
}

int main(int argc, char **argv)
{
return fib(10);
}
5 changes: 5 additions & 0 deletions test/golden-gcc-4.9.2/NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Built with

$ gcc -o golden-gcc-4.9.2/example -g -fdebug-prefix-map=$PWD=x example.c

where gcc is version 4.9.2 from Debian.
Binary file added test/golden-gcc-4.9.2/example
Binary file not shown.
10 changes: 10 additions & 0 deletions test/golden-gcc-4.9.2/lines
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- <0>
x/example.c 2 0x4004b6
x/example.c 3 0x4004c2
x/example.c 4 0x4004c8
x/example.c 5 0x4004cd
x/example.c 6 0x4004eb
x/example.c 9 0x4004f2
x/example.c 10 0x400501
x/example.c 11 0x40050b

72 changes: 72 additions & 0 deletions test/golden-gcc-4.9.2/sections
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] null 0000000000000000 00000000
0000000000000000 0000000000000000 (shf)0x0 undef 0 0
[ 1] .interp progbits 0000000000400200 00000200
000000000000001c 0000000000000000 alloc undef 0 1
[ 2] .note.ABI-tag note 000000000040021c 0000021c
0000000000000020 0000000000000000 alloc undef 0 4
[ 3] .note.gnu.build-id note 000000000040023c 0000023c
0000000000000024 0000000000000000 alloc undef 0 4
[ 4] .gnu.hash (sht)0x6ffffff6 0000000000400260 00000260
000000000000001c 0000000000000000 alloc 5 0 8
[ 5] .dynsym dynsym 0000000000400280 00000280
0000000000000048 0000000000000018 alloc 6 1 8
[ 6] .dynstr strtab 00000000004002c8 000002c8
0000000000000038 0000000000000000 alloc undef 0 1
[ 7] .gnu.version (sht)0x6fffffff 0000000000400300 00000300
0000000000000006 0000000000000002 alloc 5 0 2
[ 8] .gnu.version_r (sht)0x6ffffffe 0000000000400308 00000308
0000000000000020 0000000000000000 alloc 6 1 8
[ 9] .rela.dyn rela 0000000000400328 00000328
0000000000000018 0000000000000018 alloc 5 0 8
[10] .rela.plt rela 0000000000400340 00000340
0000000000000030 0000000000000018 alloc|(shf)0x40 5 12 8
[11] .init progbits 0000000000400370 00000370
000000000000001a 0000000000000000 alloc|execinstr undef 0 4
[12] .plt progbits 0000000000400390 00000390
0000000000000030 0000000000000010 alloc|execinstr undef 0 16
[13] .text progbits 00000000004003c0 000003c0
00000000000001c2 0000000000000000 alloc|execinstr undef 0 16
[14] .fini progbits 0000000000400584 00000584
0000000000000009 0000000000000000 alloc|execinstr undef 0 4
[15] .rodata progbits 0000000000400590 00000590
0000000000000004 0000000000000004 alloc|(shf)0x10 undef 0 4
[16] .eh_frame_hdr progbits 0000000000400594 00000594
000000000000003c 0000000000000000 alloc undef 0 4
[17] .eh_frame progbits 00000000004005d0 000005d0
0000000000000114 0000000000000000 alloc undef 0 8
[18] .init_array (sht)0xe 00000000006006e8 000006e8
0000000000000008 0000000000000000 write|alloc undef 0 8
[19] .fini_array (sht)0xf 00000000006006f0 000006f0
0000000000000008 0000000000000000 write|alloc undef 0 8
[20] .jcr progbits 00000000006006f8 000006f8
0000000000000008 0000000000000000 write|alloc undef 0 8
[21] .dynamic dynamic 0000000000600700 00000700
00000000000001d0 0000000000000010 write|alloc 6 0 8
[22] .got progbits 00000000006008d0 000008d0
0000000000000008 0000000000000008 write|alloc undef 0 8
[23] .got.plt progbits 00000000006008d8 000008d8
0000000000000028 0000000000000008 write|alloc undef 0 8
[24] .data progbits 0000000000600900 00000900
0000000000000010 0000000000000000 write|alloc undef 0 8
[25] .bss nobits 0000000000600910 00000910
0000000000000008 0000000000000000 write|alloc undef 0 1
[26] .comment progbits 0000000000000000 00000910
0000000000000039 0000000000000001 (shf)0x30 undef 0 1
[27] .debug_aranges progbits 0000000000000000 00000949
0000000000000030 0000000000000000 (shf)0x0 undef 0 1
[28] .debug_info progbits 0000000000000000 00000979
00000000000000b2 0000000000000000 (shf)0x0 undef 0 1
[29] .debug_abbrev progbits 0000000000000000 00000a2b
0000000000000089 0000000000000000 (shf)0x0 undef 0 1
[30] .debug_line progbits 0000000000000000 00000ab4
0000000000000043 0000000000000000 (shf)0x0 undef 0 1
[31] .debug_str progbits 0000000000000000 00000af7
000000000000007d 0000000000000001 (shf)0x30 undef 0 1
[32] .shstrtab strtab 0000000000000000 00000b74
0000000000000148 0000000000000000 (shf)0x0 undef 0 1
[33] .symtab symtab 0000000000000000 00000cc0
0000000000000690 0000000000000018 (shf)0x0 34 50 8
[34] .strtab strtab 0000000000000000 00001350
000000000000022b 0000000000000000 (shf)0x0 undef 0 1
18 changes: 18 additions & 0 deletions test/golden-gcc-4.9.2/segments
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
phdr 0x0000000000000040 0x0000000000400040 0x0000000000400040
0x00000000000001c0 0x00000000000001c0 x|r 8
interp 0x0000000000000200 0x0000000000400200 0x0000000000400200
0x000000000000001c 0x000000000000001c r 1
load 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x00000000000006e4 0x00000000000006e4 x|r 200000
load 0x00000000000006e8 0x00000000006006e8 0x00000000006006e8
0x0000000000000228 0x0000000000000230 w|r 200000
dynamic 0x0000000000000700 0x0000000000600700 0x0000000000600700
0x00000000000001d0 0x00000000000001d0 w|r 8
note 0x000000000000021c 0x000000000040021c 0x000000000040021c
0x0000000000000044 0x0000000000000044 r 4
(pt)0x6474e550 0x0000000000000594 0x0000000000400594 0x0000000000400594
0x000000000000003c 0x000000000000003c r 4
(pt)0x6474e551 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 w|r 10
77 changes: 77 additions & 0 deletions test/golden-gcc-4.9.2/syms
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Symbol table '.dynsym':
Num: Value Size Type Binding Index Name
0: 0000000000000000 0 notype local undef
1: 0000000000000000 0 func global undef __libc_start_main
2: 0000000000000000 0 notype weak undef __gmon_start__
Symbol table '.symtab':
Num: Value Size Type Binding Index Name
0: 0000000000000000 0 notype local undef
1: 0000000000400200 0 section local 1
2: 000000000040021c 0 section local 2
3: 000000000040023c 0 section local 3
4: 0000000000400260 0 section local 4
5: 0000000000400280 0 section local 5
6: 00000000004002c8 0 section local 6
7: 0000000000400300 0 section local 7
8: 0000000000400308 0 section local 8
9: 0000000000400328 0 section local 9
10: 0000000000400340 0 section local 10
11: 0000000000400370 0 section local 11
12: 0000000000400390 0 section local 12
13: 00000000004003c0 0 section local 13
14: 0000000000400584 0 section local 14
15: 0000000000400590 0 section local 15
16: 0000000000400594 0 section local 16
17: 00000000004005d0 0 section local 17
18: 00000000006006e8 0 section local 18
19: 00000000006006f0 0 section local 19
20: 00000000006006f8 0 section local 20
21: 0000000000600700 0 section local 21
22: 00000000006008d0 0 section local 22
23: 00000000006008d8 0 section local 23
24: 0000000000600900 0 section local 24
25: 0000000000600910 0 section local 25
26: 0000000000000000 0 section local 26
27: 0000000000000000 0 section local 27
28: 0000000000000000 0 section local 28
29: 0000000000000000 0 section local 29
30: 0000000000000000 0 section local 30
31: 0000000000000000 0 section local 31
32: 0000000000000000 0 file local abs crtstuff.c
33: 00000000006006f8 0 object local 20 __JCR_LIST__
34: 00000000004003f0 0 func local 13 deregister_tm_clones
35: 0000000000400430 0 func local 13 register_tm_clones
36: 0000000000400470 0 func local 13 __do_global_dtors_aux
37: 0000000000600910 1 object local 25 completed.6661
38: 00000000006006f0 0 object local 19 __do_global_dtors_aux_fini_array_entry
39: 0000000000400490 0 func local 13 frame_dummy
40: 00000000006006e8 0 object local 18 __frame_dummy_init_array_entry
41: 0000000000000000 0 file local abs example.c
42: 0000000000000000 0 file local abs crtstuff.c
43: 00000000004006e0 0 object local 17 __FRAME_END__
44: 00000000006006f8 0 object local 20 __JCR_END__
45: 0000000000000000 0 file local abs
46: 00000000006006f0 0 notype local 18 __init_array_end
47: 0000000000600700 0 object local 21 _DYNAMIC
48: 00000000006006e8 0 notype local 18 __init_array_start
49: 00000000006008d8 0 object local 23 _GLOBAL_OFFSET_TABLE_
50: 0000000000400580 2 func global 13 __libc_csu_fini
51: 0000000000000000 0 notype weak undef _ITM_deregisterTMCloneTable
52: 0000000000600900 0 notype weak 24 data_start
53: 0000000000600910 0 notype global 24 _edata
54: 0000000000400584 0 func global 14 _fini
55: 0000000000000000 0 func global undef __libc_start_main@@GLIBC_2.2.5
56: 0000000000600900 0 notype global 24 __data_start
57: 0000000000000000 0 notype weak undef __gmon_start__
58: 0000000000600908 0 object global 24 __dso_handle
59: 0000000000400590 4 object global 15 _IO_stdin_used
60: 0000000000400510 101 func global 13 __libc_csu_init
61: 0000000000600918 0 notype global 25 _end
62: 00000000004003c0 0 func global 13 _start
63: 0000000000600910 0 notype global 25 __bss_start
64: 00000000004004f2 27 func global 13 main
65: 00000000004004b6 60 func global 13 fib
66: 0000000000000000 0 notype weak undef _Jv_RegisterClasses
67: 0000000000600910 0 object global 24 __TMC_END__
68: 0000000000000000 0 notype weak undef _ITM_registerTMCloneTable
69: 0000000000400370 0 func global 11 _init
65 changes: 65 additions & 0 deletions test/golden-gcc-4.9.2/tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
--- <0>
<b> DW_TAG_compile_unit
DW_AT_producer GNU C 4.9.2 -mtune=generic -march=x86-64 -g -fdebug-prefix-map=/home/amthrax/r/libelfin/test=x
DW_AT_language 0x1
DW_AT_name example.c
DW_AT_comp_dir x
DW_AT_low_pc 0x4004b6
DW_AT_high_pc 0x57
DW_AT_stmt_list <line 0x0>
<2b> DW_TAG_subprogram
DW_AT_external true
DW_AT_name fib
DW_AT_decl_file 0x1
DW_AT_decl_line 0x1
DW_AT_prototyped true
DW_AT_type <0x59>
DW_AT_low_pc 0x4004b6
DW_AT_high_pc 0x3c
DW_AT_frame_base <exprloc>
(DW_AT)0x2116 true
DW_AT_sibling <0x59>
<4c> DW_TAG_formal_parameter
DW_AT_name x
DW_AT_decl_file 0x1
DW_AT_decl_line 0x1
DW_AT_type <0x59>
DW_AT_location <exprloc>
<59> DW_TAG_base_type
DW_AT_byte_size 0x4
DW_AT_encoding 0x5
DW_AT_name int
<60> DW_TAG_subprogram
DW_AT_external true
DW_AT_name main
DW_AT_decl_file 0x1
DW_AT_decl_line 0x8
DW_AT_prototyped true
DW_AT_type <0x59>
DW_AT_low_pc 0x4004f2
DW_AT_high_pc 0x1b
DW_AT_frame_base <exprloc>
(DW_AT)0x2116 true
DW_AT_sibling <0x9e>
<81> DW_TAG_formal_parameter
DW_AT_name argc
DW_AT_decl_file 0x1
DW_AT_decl_line 0x8
DW_AT_type <0x59>
DW_AT_location <exprloc>
<8f> DW_TAG_formal_parameter
DW_AT_name argv
DW_AT_decl_file 0x1
DW_AT_decl_line 0x8
DW_AT_type <0x9e>
DW_AT_location <exprloc>
<9e> DW_TAG_pointer_type
DW_AT_byte_size 0x8
DW_AT_type <0xa4>
<a4> DW_TAG_pointer_type
DW_AT_byte_size 0x8
DW_AT_type <0xaa>
<aa> DW_TAG_base_type
DW_AT_byte_size 0x1
DW_AT_encoding 0x6
DW_AT_name char
69 changes: 69 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

die() {
echo "$@"
exit 1
}

(cd ../examples && make --quiet) || die "failed to build examples"

dumps="sections segments lines syms tree"
binaries=example
compilers=gcc-4.9.2

if [[ $1 == --make-golden ]]; then
MODE=make-golden
fi

output=$(mktemp --tmpdir libelfin.XXXXXXXXXX)
trap "rm -f $output $output.out" EXIT

FAILED=0
for dump in $dumps; do
for binary in $binaries; do
for compiler in $compilers; do
if [[ $MODE == make-golden ]]; then
../examples/dump-$dump golden-$compiler/$binary > golden-$compiler/$dump || \
die "failed to create golden output"
continue
fi

PASS=1

# Save stdout and stderr and redirect output to temporary file.
exec 3>&1 4>&2 1>$output 2>&1

# Run the test.
../examples/dump-$dump golden-$compiler/$binary >& $output.out
STATUS=$?
if [[ $STATUS != 0 ]]; then
PASS=0
echo "failed: exit status $STATUS"
fi
if ! diff -u golden-$compiler/$dump $output.out; then
PASS=0
fi

# Restore FDs.
exec 1>&3 2>&4 3>&- 4>&-

# Report results.
if [[ $PASS == 0 ]]; then
FAILED=$((FAILED + 1))
echo -n "FAIL "
else
echo -n "PASS "
fi
echo dump-$dump golden-$compiler/$binary

if [[ $PASS == 0 ]]; then
sed 's/^/\t/' $output
fi
done
done
done

if [[ $FAILED != 0 ]]; then
echo "$FAILED test(s) failed"
exit 1
fi

0 comments on commit 0950be8

Please sign in to comment.