Blame tests/run-native-test.sh

Packit 032894
#! /bin/sh
Packit 032894
# Copyright (C) 2005, 2006, 2013 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
Packit 032894
. $srcdir/test-subr.sh
Packit 032894
Packit 032894
# This tests all the miscellaneous components of backend support
Packit 032894
# against whatever this build is running on.  A platform will fail
Packit 032894
# this test if it is missing parts of the backend implementation.
Packit 032894
#
Packit 032894
# As new backend code is added to satisfy the test, be sure to update
Packit 032894
# the fixed test cases (run-allregs.sh et al) to test that backend
Packit 032894
# in all builds.
Packit 032894
Packit 032894
tempfiles native.c native
Packit 032894
echo 'main () { while (1) pause (); }' > native.c
Packit 032894
Packit 032894
native=0
Packit 032894
kill_native()
Packit 032894
{
Packit 032894
  test $native -eq 0 || {
Packit 032894
    kill -9 $native 2> /dev/null || :
Packit 032894
    wait $native 2> /dev/null || :
Packit 032894
  }
Packit 032894
  native=0
Packit 032894
}
Packit 032894
Packit 032894
native_cleanup()
Packit 032894
{
Packit 032894
  kill_native
Packit 032894
  test_cleanup
Packit 032894
}
Packit 032894
Packit 032894
native_exit()
Packit 032894
{
Packit 032894
  native_cleanup
Packit 032894
  exit_cleanup
Packit 032894
}
Packit 032894
Packit 032894
trap native_cleanup 1 2 15
Packit 032894
trap native_exit 0
Packit 032894
Packit 032894
for cc in "$HOSTCC" "$HOST_CC" cc gcc "$CC"; do
Packit 032894
  test "x$cc" != x || continue
Packit 032894
  $cc -o native -g native.c > /dev/null 2>&1 &&
Packit 032894
  # Some shell versions don't do this right without the braces.
Packit 032894
  { ./native > /dev/null 2>&1 & native=$! ; } &&
Packit 032894
  sleep 1 && kill -0 $native 2> /dev/null &&
Packit 032894
  break ||
Packit 032894
  native=0
Packit 032894
done
Packit 032894
Packit 032894
native_test()
Packit 032894
{
Packit 032894
  # Try the build against itself, i.e. $config_host.
Packit 032894
  testrun "$@" -e $1 > /dev/null
Packit 032894
Packit 032894
  # Try the build against a presumed native process, running this sh.
Packit 032894
  # For tests requiring debug information, this may not test anything.
Packit 032894
  testrun "$@" -p $$ > /dev/null
Packit 032894
Packit 032894
  # Try the build against the trivial native program we just built with -g.
Packit 032894
  test $native -eq 0 || testrun "$@" -p $native > /dev/null
Packit 032894
}
Packit 032894
Packit 032894
native_test ${abs_builddir}/allregs
Packit 032894
native_test ${abs_builddir}/funcretval
Packit 032894
Packit 032894
# We do this explicitly rather than letting the trap 0 cover it,
Packit 032894
# because as of version 3.1 bash prints the "Killed" report for
Packit 032894
# $native when we do the kill inside the exit handler.
Packit 032894
native_cleanup
Packit 032894
Packit 032894
exit 0