• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
24libName="libffi-host"
25execFile="/tmp/run-test-$$"
26outFile="/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
32prog="$0"
33while [ -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
42done
43origDir=`pwd`
44progDir=`dirname "${prog}"`
45cd "${progDir}"
46progDir=`pwd`
47prog="${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
54while 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
63done
64
65sourceDir=`pwd`
66
67
68# Find the library, collect the list of test files, and set other variables.
69
70if get_build_var x >/dev/null 2>&1; then
71    : # Already have build system defs.
72else
73    # Pull in envsetup.sh.
74    . build/envsetup.sh
75fi
76
77CC=`get_build_var CC`
78HOST_OS=`get_build_var HOST_OS`
79HOST_ARCH=`get_build_var HOST_ARCH`
80
81# All this is to make the libFile be an absolute path.
82libFile=`find out/host/${HOST_OS}-${HOST_ARCH} -name "${libName}.a" | head -1`
83libDir=`dirname ${libFile}`
84libDir=`cd "$libDir"; pwd`
85libFile="${libDir}/${libName}.a"
86
87if [ "x$libFile" = "x" ]; then
88    echo "could not find ${libName}" 1>&2
89    exit 1
90fi
91
92cd "${progDir}"
93testFiles=`/bin/ls libffi.call/*.c`
94
95echo "$libDir"
96ls "$libDir"
97
98# Iterate over all the files, compiling and running each.
99
100for 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
116done
117
118rm -f "$execFile" "$outFile"
119