Home | History | Annotate | Download | only in testsuite
      1 #!/bin/bash
      2 #
      3 # Copyright 2009 The Android Open Source Project
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http://www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 
     17 #
     18 # Script to run all the tests, which only works for host builds. This
     19 # uses some heuristics to navigate the source tree and built output,
     20 # and it won't be too surprising if this breaks with some change in
     21 # the build system.
     22 #
     23 
     24 libName="libffi-host"
     25 execFile="/tmp/run-test-$$"
     26 outFile="/tmp/out-test-$$.txt"
     27 
     28 
     29 # Set up prog to be the path of this script, including following symlinks,
     30 # and set up progdir to be the fully-qualified pathname of its directory.
     31 
     32 prog="$0"
     33 while [ -h "${prog}" ]; do
     34     newProg=`/bin/ls -ld "${prog}"`
     35     newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
     36     if expr "x${newProg}" : 'x/' >/dev/null; then
     37         prog="${newProg}"
     38     else
     39         progdir=`dirname "${prog}"`
     40         prog="${progdir}/${newProg}"
     41     fi
     42 done
     43 origDir=`pwd`
     44 progDir=`dirname "${prog}"`
     45 cd "${progDir}"
     46 progDir=`pwd`
     47 prog="${progDir}"/`basename "${prog}"`
     48 
     49 
     50 # Find the base directory of the source tree (which is expected to be
     51 # the first directory found up the tree that contains both an out and
     52 # a build directory).
     53 
     54 while true; do
     55     if [ -d out -a -d build ]; then
     56         break;
     57     fi
     58     cd ..
     59     if [ "x`pwd`" = "x/" ]; then
     60         echo "could not find top of source tree" 1>&2
     61         exit 1
     62     fi
     63 done
     64 
     65 sourceDir=`pwd`
     66 
     67 
     68 # Find the library, collect the list of test files, and set other variables.
     69 
     70 if get_build_var x >/dev/null 2>&1; then
     71     : # Already have build system defs.
     72 else
     73     # Pull in envsetup.sh.
     74     . build/envsetup.sh
     75 fi
     76 
     77 CC=`get_build_var CC`
     78 HOST_OS=`get_build_var HOST_OS`
     79 HOST_ARCH=`get_build_var HOST_ARCH`
     80 
     81 # All this is to make the libFile be an absolute path.
     82 libFile=`find out/host/${HOST_OS}-${HOST_ARCH} -name "${libName}.a" | head -1`
     83 libDir=`dirname ${libFile}`
     84 libDir=`cd "$libDir"; pwd`
     85 libFile="${libDir}/${libName}.a"
     86 
     87 if [ "x$libFile" = "x" ]; then
     88     echo "could not find ${libName}" 1>&2
     89     exit 1
     90 fi
     91 
     92 cd "${progDir}"
     93 testFiles=`/bin/ls libffi.call/*.c`
     94 
     95 echo "$libDir"
     96 ls "$libDir"
     97 
     98 # Iterate over all the files, compiling and running each.
     99 
    100 for file in $testFiles; do
    101     echo "${file}..."
    102     rm -f "$execFile" "$outFile"
    103     "$CC" -g -I"../${HOST_OS}-${HOST_ARCH}" -o "$execFile" "$file" "$libFile"
    104     #    -L"$libDir" -l"$libName"
    105     if [ "$?" != "0" ]; then
    106         echo "compilation failure" 1>&2
    107     else
    108         "$execFile" > "$outFile"
    109         if [ "$?" = "0" ]; then
    110             echo "${file}: OK"
    111         else
    112             echo "${file}: FAIL"
    113             cat "$outFile"
    114         fi
    115     fi
    116 done
    117 
    118 rm -f "$execFile" "$outFile"
    119