Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 1 | #! /bin/sh |
Petr Machata | 98c8a73 | 2013-11-26 03:10:31 +0100 | [diff] [blame] | 2 | # Copyright (C) 2011, 2013 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 3 | # This file is part of elfutils. |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 4 | # |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 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. |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 9 | # |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 10 | # elfutils is distributed in the hope that it will be useful, but |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 14 | # |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 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/>. |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 17 | |
| 18 | . $srcdir/test-subr.sh |
| 19 | |
Petr Machata | 98c8a73 | 2013-11-26 03:10:31 +0100 | [diff] [blame] | 20 | testfiles hello_i386.ko hello_x86_64.ko hello_ppc64.ko hello_s390.ko \ |
| 21 | hello_aarch64.ko |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 22 | |
Mark Wielaard | a609831 | 2013-04-26 21:21:56 +0200 | [diff] [blame] | 23 | tempfiles readelf.out readelf.out1 readelf.out2 |
| 24 | tempfiles out.stripped1 out.debug1 out.stripped2 out.debug2 |
| 25 | |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 26 | status=0 |
| 27 | runtest() { |
| 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 Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 35 | testrun ${abs_top_builddir}/src/strip -o $outfile1 -f $debugfile1 $infile || |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 36 | { echo "*** failure strip $infile"; status=1; } |
| 37 | |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 38 | testrun ${abs_top_builddir}/src/strip --reloc-debug-sections -o $outfile2 \ |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 39 | -f $debugfile2 $infile || |
| 40 | { echo "*** failure strip --reloc-debug-sections $infile"; status=1; } |
| 41 | |
| 42 | # shouldn't make any difference for stripped files. |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 43 | testrun ${abs_top_builddir}/src/readelf -a $outfile1 > readelf.out || |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 44 | { echo "*** failure readelf -a outfile1 $infile"; status=1; } |
| 45 | |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 46 | testrun_compare ${abs_top_builddir}/src/readelf -a $outfile2 < readelf.out || |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 47 | { 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 Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 58 | testrun ${abs_top_builddir}/src/readelf -w $debugfile1 \ |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 59 | | grep -v ^DWARF\ section > readelf.out1 || |
| 60 | { echo "*** failure readelf -w debugfile1 $infile"; status=1; } |
| 61 | |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 62 | testrun ${abs_top_builddir}/src/readelf -w $debugfile2 \ |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 63 | | 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 Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 68 | } |
| 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 | # } |
| 100 | runtest hello_i386.ko 1 |
| 101 | runtest hello_x86_64.ko 1 |
| 102 | runtest hello_ppc64.ko 1 |
Mark Wielaard | 20a217d | 2011-05-24 14:30:40 +0200 | [diff] [blame] | 103 | runtest hello_s390.ko 1 |
Petr Machata | 98c8a73 | 2013-11-26 03:10:31 +0100 | [diff] [blame] | 104 | runtest hello_aarch64.ko 1 |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 105 | |
| 106 | # self test, shouldn't impact non-ET_REL files at all. |
Mark Wielaard | 86be792 | 2013-04-26 23:44:25 +0200 | [diff] [blame] | 107 | runtest ${abs_top_builddir}/src/strip 0 |
| 108 | runtest ${abs_top_builddir}/src/strip.o 1 |
Mark Wielaard | 1662bc3 | 2011-05-16 11:33:11 +0200 | [diff] [blame] | 109 | |
| 110 | exit $status |