Blame tests/run-large-elf-file.sh

Packit 032894
#! /bin/bash
Packit 032894
# Copyright (C) 2019 Red Hat, Inc.
Packit 032894
# This file is part of elfutils.
Packit 032894
#
Packit 032894
# This file is free software; you can redistribute it and/or modify
Packit 032894
# it under the terms of the GNU General Public License as published by
Packit 032894
# the Free Software Foundation; either version 3 of the License, or
Packit 032894
# (at your option) any later version.
Packit 032894
#
Packit 032894
# elfutils is distributed in the hope that it will be useful, but
Packit 032894
# WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 032894
# GNU General Public License for more details.
Packit 032894
#
Packit 032894
# You should have received a copy of the GNU General Public License
Packit 032894
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 032894
Packit 032894
. $srcdir/test-subr.sh
Packit 032894
Packit 032894
# Only run on 64bit systems, 32bit systems don't support > 4GB
Packit 032894
# ELF files.
Packit 032894
long_bit=$(getconf LONG_BIT)
Packit 032894
echo "long_bit: $long_bit"
Packit 032894
if test $long_bit -ne 64; then
Packit 032894
  echo "Only 64bit systems can create > 4GB ELF files"
Packit 032894
  exit 77
Packit 032894
fi
Packit 032894
Packit 032894
# These tests need lots of disk space since they test files > 4GB.
Packit 032894
# Skip if there just isn't enough (2.5 * 4 = 10GB).
Packit 032894
space_available=$[$(stat -f --format="%a*%S" .)/(1024 * 1024 * 1024)]
Packit 032894
echo "space_available: $space_available"
Packit 032894
if test $space_available -lt 10; then
Packit 032894
  echo "Not enough disk space, need at least 10GB available"
Packit 032894
  exit 77
Packit 032894
fi
Packit 032894
Packit 032894
# Make sure the files fit into memory, assume 6GB needed (2.5 * 2 + 1 extra).
Packit 032894
# Running under valgrind might need even more.
Packit 032894
mem_needed=6
Packit 032894
if [ "x$VALGRIND_CMD" != "x" ]; then
Packit 032894
  mem_needed=$[${mem_needed} + 2]
Packit 032894
fi
Packit 032894
echo "mem_needed: $mem_needed"
Packit 032894
mem_available=$(free -g 2>/dev/null | grep ^Mem: | awk -F ' +' '{print $7}')
Packit 032894
echo "mem_available: $mem_available"
Packit 032894
if test -z "$mem_available" || test $mem_available -lt $mem_needed; then
Packit 032894
  echo "Need at least ${mem_needed}GB free available memory"
Packit 032894
  exit 77
Packit 032894
fi
Packit 032894
Packit 032894
# Make sure the disk is reasonably fast, should be able to write 100MB/s
Packit 032894
fast_disk=1
Packit 032894
timeout -s9 10s dd conv=fsync if=/dev/zero of=tempfile bs=1M count=1K \
Packit 032894
  || fast_disk=0; rm tempfile
Packit 032894
if test $fast_disk -eq 0; then
Packit 032894
  echo "File system not fast enough, need at least 100MB/s"
Packit 032894
  exit 77
Packit 032894
fi
Packit 032894
Packit 032894
# NOTE: test file will be mangled and removed!
Packit 032894
test_file ()
Packit 032894
{
Packit 032894
  in_file="$1"
Packit 032894
  readelf_out="${in_file}.readelf.out"
Packit 032894
  out_file_strip="${in_file}.strip"
Packit 032894
  out_file_debug="${in_file}.debug"
Packit 032894
Packit 032894
  testfiles ${in_file}
Packit 032894
  tempfiles ${readelf_out} ${out_file_mmap} ${out_file_strip} ${out_file_debug}
Packit 032894
Packit 032894
  # Add two 2GB sections to the file.
Packit 032894
  echo "addsections 2 ${in_file} 2147483648"
Packit 032894
  testrun ${abs_builddir}/addsections 2 ${in_file} 2147483648
Packit 032894
  testrun ${abs_top_builddir}/src/readelf -S ${in_file} > ${readelf_out}
Packit 032894
  nr=$(grep '.extra' ${readelf_out} | wc -l)
Packit 032894
  if test ${nr} != 2; then
Packit 032894
    # Show what went wrong
Packit 032894
    cat ${readelf_out}
Packit 032894
    exit 1
Packit 032894
  fi
Packit 032894
Packit 032894
  echo "strip -o ${out_file_strip} -f ${out_file_debug} ${in_file}"
Packit 032894
  testrun ${abs_top_builddir}/src/strip -o ${out_file_strip} \
Packit 032894
                                        -f ${out_file_debug} ${in_file}
Packit 032894
Packit 032894
  echo "elflint --gnu ${out_file_strip}"
Packit 032894
  testrun ${abs_top_builddir}/src/elflint --gnu ${out_file_strip}
Packit 032894
Packit 032894
  echo "elflint --gnu -d ${out_file_debug}"
Packit 032894
  testrun ${abs_top_builddir}/src/elflint --gnu -d ${out_file_debug}
Packit 032894
Packit 032894
  # Now test unstrip recombining those files.
Packit 032894
  echo "unstrip ${out_file_strip} ${out_file_debug}"
Packit 032894
  testrun ${abs_top_builddir}/src/unstrip ${out_file_strip} ${out_file_debug}
Packit 032894
Packit 032894
  echo "elfcmp ${out_file} ${out_file_strip}"
Packit 032894
  testrun ${abs_top_builddir}/src/elfcmp ${in_file} ${out_file_debug}
Packit 032894
Packit 032894
  # Remove the temp files immediately, they are big...
Packit 032894
  rm -f ${in_file} ${out_file_strip} ${out_file_debug}
Packit 032894
}
Packit 032894
Packit 032894
# A collection of random testfiles to test 64bit, little/big endian
Packit 032894
# and non-ET_REL (with phdrs)/ET_REL (without phdrs).
Packit 032894
# Don't test 32bit, they cannot go beyond 4GB.
Packit 032894
Packit 032894
# 64bit, little endian, rel
Packit 032894
test_file testfile38
Packit 032894
Packit 032894
# 64bit, big endian, non-rel
Packit 032894
test_file testfile27
Packit 032894
Packit 032894
exit 0