blob: a3245fd8823633040625d680e7801042f0ac4cb6 [file] [log] [blame]
Mark Wielaard1662bc32011-05-16 11:33:11 +02001#! /bin/sh
Petr Machata98c8a732013-11-26 03:10:31 +01002# Copyright (C) 2011, 2013 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003# This file is part of elfutils.
Mark Wielaard1662bc32011-05-16 11:33:11 +02004#
Mark Wielaardde2ed972012-06-05 17:15:16 +02005# 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.
Mark Wielaard1662bc32011-05-16 11:33:11 +02009#
Mark Wielaardde2ed972012-06-05 17:15:16 +020010# elfutils is distributed in the hope that it will be useful, but
Mark Wielaard1662bc32011-05-16 11:33:11 +020011# WITHOUT ANY WARRANTY; without even the implied warranty of
Mark Wielaardde2ed972012-06-05 17:15:16 +020012# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
Mark Wielaard1662bc32011-05-16 11:33:11 +020014#
Mark Wielaardde2ed972012-06-05 17:15:16 +020015# 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/>.
Mark Wielaard1662bc32011-05-16 11:33:11 +020017
18. $srcdir/test-subr.sh
19
Petr Machata98c8a732013-11-26 03:10:31 +010020testfiles hello_i386.ko hello_x86_64.ko hello_ppc64.ko hello_s390.ko \
21 hello_aarch64.ko
Mark Wielaard1662bc32011-05-16 11:33:11 +020022
Mark Wielaarda6098312013-04-26 21:21:56 +020023tempfiles readelf.out readelf.out1 readelf.out2
24tempfiles out.stripped1 out.debug1 out.stripped2 out.debug2
25
Mark Wielaard1662bc32011-05-16 11:33:11 +020026status=0
27runtest() {
28 infile=$1
29 is_ET_REL=$2
30 outfile1=out.stripped1
31 debugfile1=out.debug1
32 outfile2=out.stripped2
33 debugfile2=out.debug2
34
Mark Wielaard86be7922013-04-26 23:44:25 +020035 testrun ${abs_top_builddir}/src/strip -o $outfile1 -f $debugfile1 $infile ||
Mark Wielaard1662bc32011-05-16 11:33:11 +020036 { echo "*** failure strip $infile"; status=1; }
37
Mark Wielaard86be7922013-04-26 23:44:25 +020038 testrun ${abs_top_builddir}/src/strip --reloc-debug-sections -o $outfile2 \
Mark Wielaard1662bc32011-05-16 11:33:11 +020039 -f $debugfile2 $infile ||
40 { echo "*** failure strip --reloc-debug-sections $infile"; status=1; }
41
42 # shouldn't make any difference for stripped files.
Mark Wielaard86be7922013-04-26 23:44:25 +020043 testrun ${abs_top_builddir}/src/readelf -a $outfile1 > readelf.out ||
Mark Wielaard1662bc32011-05-16 11:33:11 +020044 { echo "*** failure readelf -a outfile1 $infile"; status=1; }
45
Mark Wielaard86be7922013-04-26 23:44:25 +020046 testrun_compare ${abs_top_builddir}/src/readelf -a $outfile2 < readelf.out ||
Mark Wielaard1662bc32011-05-16 11:33:11 +020047 { echo "*** failure compare stripped files $infile"; status=1; }
48
49 # debug files however should be smaller, when ET_REL.
50 SIZE1=$(stat -c%s $debugfile1)
51 SIZE2=$(stat -c%s $debugfile2)
52 test \( \( $is_ET_REL -eq 1 \) -a \( $SIZE1 -gt $SIZE2 \) \) \
53 -o \( \( $is_ET_REL -eq 0 \) -a \( $SIZE1 -eq $SIZE2 \) \) ||
54 { echo "*** failure --reloc-debug-sections not smaller $infile"; status=1; }
55
56 # Strip of DWARF section lines, offset will not match.
57 # Everything else should match.
Mark Wielaard86be7922013-04-26 23:44:25 +020058 testrun ${abs_top_builddir}/src/readelf -w $debugfile1 \
Mark Wielaard1662bc32011-05-16 11:33:11 +020059 | grep -v ^DWARF\ section > readelf.out1 ||
60 { echo "*** failure readelf -w debugfile1 $infile"; status=1; }
61
Mark Wielaard86be7922013-04-26 23:44:25 +020062 testrun ${abs_top_builddir}/src/readelf -w $debugfile2 \
Mark Wielaard1662bc32011-05-16 11:33:11 +020063 | grep -v ^DWARF\ section > readelf.out2 ||
64 { echo "*** failure readelf -w debugfile2 $infile"; status=1; }
65
66 testrun_compare cat readelf.out1 < readelf.out2 ||
67 { echo "*** failure readelf -w compare $infile"; status=1; }
Mark Wielaard1662bc32011-05-16 11:33:11 +020068}
69
70# Most simple hello world kernel module for various architectures.
71# ::::::::::::::
72# Makefile
73# ::::::::::::::
74# obj-m := hello.o
75# hello-y := init.o exit.o
76#
77# all:
78# make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
79# ::::::::::::::
80# init.c
81# ::::::::::::::
82# #include <linux/kernel.h>
83# #include <linux/module.h>
84#
85# int init_module(void)
86# {
87# printk(KERN_INFO "Hello, world!\n");
88# return 0;
89# }
90# ::::::::::::::
91# exit.c
92# ::::::::::::::
93# #include <linux/kernel.h>
94# #include <linux/module.h>
95#
96# void cleanup_module()
97# {
98# printk(KERN_INFO "Goodbye, World!\n");
99# }
100runtest hello_i386.ko 1
101runtest hello_x86_64.ko 1
102runtest hello_ppc64.ko 1
Mark Wielaard20a217d2011-05-24 14:30:40 +0200103runtest hello_s390.ko 1
Petr Machata98c8a732013-11-26 03:10:31 +0100104runtest hello_aarch64.ko 1
Mark Wielaard1662bc32011-05-16 11:33:11 +0200105
106# self test, shouldn't impact non-ET_REL files at all.
Mark Wielaard86be7922013-04-26 23:44:25 +0200107runtest ${abs_top_builddir}/src/strip 0
108runtest ${abs_top_builddir}/src/strip.o 1
Mark Wielaard1662bc32011-05-16 11:33:11 +0200109
110exit $status