1# Run all tests
2
3PROGDIR=`dirname $0`
4PROGDIR=`cd $PROGDIR && pwd`
5
6# Assume that we are under tests/
7# and that the samples will be under samples/ and platforms/android-N/samples/
8#
9ROOTDIR=`dirname $PROGDIR`
10#
11# Sanity checks:
12#
13if [ -z "$NDK" ] ; then
14    echo "ERROR: Please define NDK in your environment to point to the root of your NDK install."
15    exit 1
16fi
17
18if [ ! -d "$NDK" ] ; then
19    echo "ERROR: Your NDK variable does not point to a directory: $NDK"
20    exit 2
21fi
22
23if [ ! -f "$NDK/ndk-build" -o ! -f "$NDK/build/core/ndk-common.sh" ] ; then
24    echo "ERROR: Your NDK variable does not point to a valid NDK directory: $NDK"
25    exit 3
26fi
27
28if [ ! -d "$NDK/platforms" -o ! -d "$NDK/samples" ] ; then
29    echo "ERROR: Your NDK directory does not have 'platforms' or 'samples' directories."
30    echo "Please run $NDK/build/tools/build-platforms.sh first !"
31    exit 3
32fi
33
34#
35# Parse options
36#
37JOBS=
38while [ -n "$1" ]; do
39    opt="$1"
40    optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
41    case "$opt" in
42        --help|-h|-\?)
43            OPTION_HELP=yes
44            ;;
45        --verbose)
46            VERBOSE=yes
47            ;;
48        -j*)
49            JOBS="$opt"
50            shift
51            ;;
52        --jobs=*)
53            JOBS="-j$optarg"
54            ;;
55        -*) # unknown options
56            echo "ERROR: Unknown option '$opt', use --help for list of valid ones."
57            exit 1
58        ;;
59        *)  # Simply record parameter
60            if [ -z "$PARAMETERS" ] ; then
61                PARAMETERS="$opt"
62            else
63                PARAMETERS="$PARAMETERS $opt"
64            fi
65            ;;
66    esac
67    shift
68done
69
70if [ "$OPTION_HELP" = "yes" ] ; then
71    echo "Usage: $PROGNAME [options]"
72    echo ""
73    echo "Run all NDK automated tests at once."
74    echo ""
75    echo "Valid options:"
76    echo ""
77    echo "    --help|-h|-?      Print this help"
78    echo "    --verbose         Enable verbose mode"
79    echo "    -j<N> --jobs=<N>  Launch parallel builds"
80    echo ""
81    exit 0
82fi
83
84#
85# Create log file
86#
87MYLOG=/tmp/ndk-tests.log
88mkdir -p `dirname $MYLOG`
89rm -f $MYLOG
90echo "NDK automated tests log file" > $MYLOG
91
92if [ "$VERBOSE" = "yes" ] ; then
93run ()
94{
95    $NDK/ndk-build -B $JOBS 2>&1
96}
97else
98run ()
99{
100    $NDK/ndk-build -B $JOBS >> $MYLOG 2>&1
101}
102fi
103
104# Find sample directories
105SAMPLE_DIRS=`cd $ROOTDIR && ls -d samples/*`
106SAMPLE_DIRS="$SAMPLE_DIRS "`cd $ROOTDIR && ls -d platforms/android-*/samples/*`
107
108#
109# Rebuild all samples first
110# $1: sample name
111#
112build_sample ()
113{
114    echo "Building NDK sample: `basename $1`"
115    SAMPLEDIR=$ROOTDIR/$1
116    cd $SAMPLEDIR
117    run $NDK/ndk-build -B $JOBS
118    if [ $? != 0 ] ; then
119        echo "!!! BUILD FAILURE [$1]!!! See $MYLOG for details or use --verbose option!"
120        exit 1
121    fi
122}
123
124for DIR in $SAMPLE_DIRS; do
125    build_sample $DIR
126done
127