103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#! /bin/sh
203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# Copyright (C) 2005, 2006, 2013 Red Hat, Inc.
303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# This file is part of elfutils.
403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#
503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# This file is free software; you can redistribute it and/or modify
603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# it under the terms of the GNU General Public License as published by
703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# the Free Software Foundation; either version 3 of the License, or
803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# (at your option) any later version.
903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#
1003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# elfutils is distributed in the hope that it will be useful, but
1103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# WITHOUT ANY WARRANTY; without even the implied warranty of
1203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# GNU General Public License for more details.
1403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#
1503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# You should have received a copy of the GNU General Public License
1603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
1903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes. $srcdir/test-subr.sh
2003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# This tests all the miscellaneous components of backend support
2203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# against whatever this build is running on.  A platform will fail
2303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# this test if it is missing parts of the backend implementation.
2403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes#
2503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# As new backend code is added to satisfy the test, be sure to update
2603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# the fixed test cases (run-allregs.sh et al) to test that backend
2703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# in all builds.
2803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
2903333823c75a1c1887e923828113a1b0fd12020cElliott Hughestempfiles native.c native
3003333823c75a1c1887e923828113a1b0fd12020cElliott Hughesecho 'main () { while (1) pause (); }' > native.c
3103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
3203333823c75a1c1887e923828113a1b0fd12020cElliott Hughesnative=0
3303333823c75a1c1887e923828113a1b0fd12020cElliott Hugheskill_native()
3403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes{
3503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  test $native -eq 0 || {
3603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    kill -9 $native 2> /dev/null || :
3703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes    wait $native 2> /dev/null || :
3803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  }
3903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  native=0
4003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes}
4103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
4203333823c75a1c1887e923828113a1b0fd12020cElliott Hughesnative_cleanup()
4303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes{
4403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  kill_native
4503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  test_cleanup
4603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes}
4703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
4803333823c75a1c1887e923828113a1b0fd12020cElliott Hughesnative_exit()
4903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes{
5003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  native_cleanup
5103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  exit_cleanup
5203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes}
5303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
5403333823c75a1c1887e923828113a1b0fd12020cElliott Hughestrap native_cleanup 1 2 15
5503333823c75a1c1887e923828113a1b0fd12020cElliott Hughestrap native_exit 0
5603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
5703333823c75a1c1887e923828113a1b0fd12020cElliott Hughesfor cc in "$HOSTCC" "$HOST_CC" cc gcc "$CC"; do
5803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  test "x$cc" != x || continue
5903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  $cc -o native -g native.c > /dev/null 2>&1 &&
6003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  # Some shell versions don't do this right without the braces.
6103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  { ./native > /dev/null 2>&1 & native=$! ; } &&
6203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  sleep 1 && kill -0 $native 2> /dev/null &&
6303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  break ||
6403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  native=0
6503333823c75a1c1887e923828113a1b0fd12020cElliott Hughesdone
6603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
6703333823c75a1c1887e923828113a1b0fd12020cElliott Hughesnative_test()
6803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes{
6903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  # Try the build against itself, i.e. $config_host.
7003333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  testrun "$@" -e $1 > /dev/null
7103333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
7203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  # Try the build against a presumed native process, running this sh.
7303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  # For tests requiring debug information, this may not test anything.
7403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  testrun "$@" -p $$ > /dev/null
7503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
7603333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  # Try the build against the trivial native program we just built with -g.
7703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes  test $native -eq 0 || testrun "$@" -p $native > /dev/null
7803333823c75a1c1887e923828113a1b0fd12020cElliott Hughes}
7903333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
8003333823c75a1c1887e923828113a1b0fd12020cElliott Hughesnative_test ${abs_builddir}/allregs
8103333823c75a1c1887e923828113a1b0fd12020cElliott Hughesnative_test ${abs_builddir}/funcretval
8203333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
8303333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# We do this explicitly rather than letting the trap 0 cover it,
8403333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# because as of version 3.1 bash prints the "Killed" report for
8503333823c75a1c1887e923828113a1b0fd12020cElliott Hughes# $native when we do the kill inside the exit handler.
8603333823c75a1c1887e923828113a1b0fd12020cElliott Hughesnative_cleanup
8703333823c75a1c1887e923828113a1b0fd12020cElliott Hughes
8803333823c75a1c1887e923828113a1b0fd12020cElliott Hughesexit 0
89