603fb7c70d3a3812b73b9f843afe0818da903b97
[platform/upstream/elfutils.git] / tests / run-strip-reloc.sh
1 #! /bin/sh
2 # Copyright (C) 2011 Red Hat, Inc.
3 # This file is part of elfutils.
4 #
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # elfutils is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 . $srcdir/test-subr.sh
19
20 testfiles hello_i386.ko hello_x86_64.ko hello_ppc64.ko hello_s390.ko
21
22 status=0
23 runtest() {
24   infile=$1
25   is_ET_REL=$2
26   outfile1=out.stripped1
27   debugfile1=out.debug1
28   outfile2=out.stripped2
29   debugfile2=out.debug2
30
31   testrun ../src/strip -o $outfile1 -f $debugfile1 $infile ||
32   { echo "*** failure strip $infile"; status=1; }
33
34   testrun ../src/strip --reloc-debug-sections -o $outfile2 \
35         -f $debugfile2 $infile ||
36   { echo "*** failure strip --reloc-debug-sections $infile"; status=1; }
37
38   # shouldn't make any difference for stripped files.
39   testrun ../src/readelf -a $outfile1 > readelf.out ||
40   { echo "*** failure readelf -a outfile1 $infile"; status=1; }
41
42   testrun_compare ../src/readelf -a $outfile2 < readelf.out ||
43   { echo "*** failure compare stripped files $infile"; status=1; }
44
45   # debug files however should be smaller, when ET_REL.
46   SIZE1=$(stat -c%s $debugfile1)
47   SIZE2=$(stat -c%s $debugfile2)
48   test \( \( $is_ET_REL -eq 1 \) -a \( $SIZE1 -gt $SIZE2 \) \) \
49         -o \( \( $is_ET_REL -eq 0 \) -a \( $SIZE1 -eq $SIZE2 \) \) ||
50   { echo "*** failure --reloc-debug-sections not smaller $infile"; status=1; }
51
52   # Strip of DWARF section lines, offset will not match.
53   # Everything else should match.
54   testrun ../src/readelf -w $debugfile1 \
55         | grep -v ^DWARF\ section > readelf.out1 ||
56   { echo "*** failure readelf -w debugfile1 $infile"; status=1; }
57
58   testrun ../src/readelf -w $debugfile2 \
59         | grep -v ^DWARF\ section > readelf.out2 ||
60   { echo "*** failure readelf -w debugfile2 $infile"; status=1; }
61
62   testrun_compare cat readelf.out1 < readelf.out2 ||
63   { echo "*** failure readelf -w compare $infile"; status=1; }
64
65   rm -f $outfile1 $debugfile1 $outfile2 $debugfile2 readelf.out*
66 }
67
68 # Most simple hello world kernel module for various architectures.
69 # ::::::::::::::
70 # Makefile
71 # ::::::::::::::
72 # obj-m := hello.o
73 # hello-y := init.o exit.o
74
75 # all:
76 #       make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
77 # ::::::::::::::
78 # init.c
79 # ::::::::::::::
80 # #include <linux/kernel.h>
81 # #include <linux/module.h>
82
83 # int init_module(void)
84 # {
85 #   printk(KERN_INFO "Hello, world!\n");
86 #   return 0;
87 # }
88 # ::::::::::::::
89 # exit.c
90 # ::::::::::::::
91 # #include <linux/kernel.h>
92 # #include <linux/module.h>
93
94 # void cleanup_module()
95 # {
96 #   printk(KERN_INFO "Goodbye, World!\n");
97 # }
98 runtest hello_i386.ko 1
99 runtest hello_x86_64.ko 1
100 runtest hello_ppc64.ko 1
101 runtest hello_s390.ko 1
102
103 # self test, shouldn't impact non-ET_REL files at all.
104 runtest ../src/strip 0
105 runtest ../src/strip.o 1
106
107 exit $status