1*7304104dSAndroid Build Coastguard Worker#! /bin/sh 2*7304104dSAndroid Build Coastguard Worker# Copyright (C) 2005, 2006, 2013 Red Hat, Inc. 3*7304104dSAndroid Build Coastguard Worker# This file is part of elfutils. 4*7304104dSAndroid Build Coastguard Worker# 5*7304104dSAndroid Build Coastguard Worker# This file is free software; you can redistribute it and/or modify 6*7304104dSAndroid Build Coastguard Worker# it under the terms of the GNU General Public License as published by 7*7304104dSAndroid Build Coastguard Worker# the Free Software Foundation; either version 3 of the License, or 8*7304104dSAndroid Build Coastguard Worker# (at your option) any later version. 9*7304104dSAndroid Build Coastguard Worker# 10*7304104dSAndroid Build Coastguard Worker# elfutils is distributed in the hope that it will be useful, but 11*7304104dSAndroid Build Coastguard Worker# WITHOUT ANY WARRANTY; without even the implied warranty of 12*7304104dSAndroid Build Coastguard Worker# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*7304104dSAndroid Build Coastguard Worker# GNU General Public License for more details. 14*7304104dSAndroid Build Coastguard Worker# 15*7304104dSAndroid Build Coastguard Worker# You should have received a copy of the GNU General Public License 16*7304104dSAndroid Build Coastguard Worker# along with this program. If not, see <http://www.gnu.org/licenses/>. 17*7304104dSAndroid Build Coastguard Worker 18*7304104dSAndroid Build Coastguard Worker 19*7304104dSAndroid Build Coastguard Worker. $srcdir/test-subr.sh 20*7304104dSAndroid Build Coastguard Worker 21*7304104dSAndroid Build Coastguard Worker# This tests all the miscellaneous components of backend support 22*7304104dSAndroid Build Coastguard Worker# against whatever this build is running on. A platform will fail 23*7304104dSAndroid Build Coastguard Worker# this test if it is missing parts of the backend implementation. 24*7304104dSAndroid Build Coastguard Worker# 25*7304104dSAndroid Build Coastguard Worker# As new backend code is added to satisfy the test, be sure to update 26*7304104dSAndroid Build Coastguard Worker# the fixed test cases (run-allregs.sh et al) to test that backend 27*7304104dSAndroid Build Coastguard Worker# in all builds. 28*7304104dSAndroid Build Coastguard Worker 29*7304104dSAndroid Build Coastguard Workertempfiles native.c native 30*7304104dSAndroid Build Coastguard Workerprintf '#include <unistd.h>\nint main (void) { while (1) pause (); }\n' \ 31*7304104dSAndroid Build Coastguard Worker > native.c 32*7304104dSAndroid Build Coastguard Worker 33*7304104dSAndroid Build Coastguard Workernative=0 34*7304104dSAndroid Build Coastguard Workerkill_native() 35*7304104dSAndroid Build Coastguard Worker{ 36*7304104dSAndroid Build Coastguard Worker test $native -eq 0 || { 37*7304104dSAndroid Build Coastguard Worker kill -9 $native 2> /dev/null || : 38*7304104dSAndroid Build Coastguard Worker wait $native 2> /dev/null || : 39*7304104dSAndroid Build Coastguard Worker } 40*7304104dSAndroid Build Coastguard Worker native=0 41*7304104dSAndroid Build Coastguard Worker} 42*7304104dSAndroid Build Coastguard Worker 43*7304104dSAndroid Build Coastguard Workernative_cleanup() 44*7304104dSAndroid Build Coastguard Worker{ 45*7304104dSAndroid Build Coastguard Worker kill_native 46*7304104dSAndroid Build Coastguard Worker test_cleanup 47*7304104dSAndroid Build Coastguard Worker} 48*7304104dSAndroid Build Coastguard Worker 49*7304104dSAndroid Build Coastguard Workernative_exit() 50*7304104dSAndroid Build Coastguard Worker{ 51*7304104dSAndroid Build Coastguard Worker native_cleanup 52*7304104dSAndroid Build Coastguard Worker exit_cleanup 53*7304104dSAndroid Build Coastguard Worker} 54*7304104dSAndroid Build Coastguard Worker 55*7304104dSAndroid Build Coastguard Workertrap native_cleanup 1 2 15 56*7304104dSAndroid Build Coastguard Workertrap native_exit 0 57*7304104dSAndroid Build Coastguard Worker 58*7304104dSAndroid Build Coastguard Workerfor cc in "$HOSTCC" "$HOST_CC" cc gcc "$CC"; do 59*7304104dSAndroid Build Coastguard Worker test "x$cc" != x || continue 60*7304104dSAndroid Build Coastguard Worker $cc -o native -g native.c && 61*7304104dSAndroid Build Coastguard Worker # Some shell versions don't do this right without the braces. 62*7304104dSAndroid Build Coastguard Worker { ./native & native=$! ; } && 63*7304104dSAndroid Build Coastguard Worker sleep 1 && kill -0 $native && 64*7304104dSAndroid Build Coastguard Worker break || 65*7304104dSAndroid Build Coastguard Worker native=0 66*7304104dSAndroid Build Coastguard Workerdone 67*7304104dSAndroid Build Coastguard Worker 68*7304104dSAndroid Build Coastguard Workernative_test() 69*7304104dSAndroid Build Coastguard Worker{ 70*7304104dSAndroid Build Coastguard Worker # Try the build against itself, i.e. $config_host. 71*7304104dSAndroid Build Coastguard Worker echo "Try the build against itself: $@ -e $1" 72*7304104dSAndroid Build Coastguard Worker testrun "$@" -e $1 73*7304104dSAndroid Build Coastguard Worker 74*7304104dSAndroid Build Coastguard Worker # Try the build against a presumed native process, running this sh. 75*7304104dSAndroid Build Coastguard Worker # For tests requiring debug information, this may not test anything. 76*7304104dSAndroid Build Coastguard Worker echo "Try the build against a presumed native process: $@ -p $$" 77*7304104dSAndroid Build Coastguard Worker testrun "$@" -p $$ 78*7304104dSAndroid Build Coastguard Worker 79*7304104dSAndroid Build Coastguard Worker # Try the build against the trivial native program we just built with -g. 80*7304104dSAndroid Build Coastguard Worker echo "Try the build against the trivial native program: $@ -p $native" 81*7304104dSAndroid Build Coastguard Worker test $native -eq 0 || testrun "$@" -p $native 82*7304104dSAndroid Build Coastguard Worker} 83*7304104dSAndroid Build Coastguard Worker 84*7304104dSAndroid Build Coastguard Workernative_test ${abs_builddir}/allregs 85*7304104dSAndroid Build Coastguard Workernative_test ${abs_builddir}/funcretval 86*7304104dSAndroid Build Coastguard Worker 87*7304104dSAndroid Build Coastguard Worker# We do this explicitly rather than letting the trap 0 cover it, 88*7304104dSAndroid Build Coastguard Worker# because as of version 3.1 bash prints the "Killed" report for 89*7304104dSAndroid Build Coastguard Worker# $native when we do the kill inside the exit handler. 90*7304104dSAndroid Build Coastguard Workernative_cleanup 91*7304104dSAndroid Build Coastguard Worker 92*7304104dSAndroid Build Coastguard Workerexit 0 93