Add configurable option to choose at compile time which i2c backend to use.
[bertos.git] / bertos / run_tests.sh
1 #!/bin/bash
2 #
3 # Copyright 2005 Develer S.r.l. (http://www.develer.com/)
4 # Copyright 2008 Bernie Innocenti <bernie@codewiz.org>
5 #
6 # Version: $Id$
7 # Author:  Bernie Innocenti <bernie@codewiz.org>
8 #
9
10 # Testsuite output level:
11 #  0 - quiet
12 #  1 - progress output
13 #  2 - build warnings
14 #  3 - execution output
15 #  4 - build commands
16 VERBOSE=${VERBOSE:-1}
17
18 CC=gcc
19 #FIXME: -Ibertos/emul should not be needed
20 CFLAGS="-W -Wall -Wextra -Ibertos -Ibertos/emul -std=gnu99 -fno-builtin -D_DEBUG -DARCH=(ARCH_EMUL|ARCH_UNITTEST)"
21
22 CXX=g++
23 CXXFLAGS="$CFLAGS"
24
25 TESTS=${TESTS:-`find . \
26         \( -name .svn -prune -o -name .git -prune -o -name .hg  -prune \) \
27         -o -name "*_test.c*" -print` }
28
29 TESTOUT="testout"
30
31 buildout='/dev/null'
32 runout='/dev/null'
33 [ "$VERBOSE" -ge 2 ] && buildout='/dev/stdout'
34 [ "$VERBOSE" -ge 3 ] && runout='/dev/stdout'
35
36 # Needed to get build/exec result code rather than tee's
37 set -o pipefail
38
39 rm -rf "${TESTOUT}.old"
40 mv -f "${TESTOUT}" "$TESTOUT.old"
41 mkdir -p "$TESTOUT"
42
43 for src in $TESTS; do
44         name="`basename $src | sed -e 's/\.cpp$//' -e 's/\.c$//'`"
45         exe="./$TESTOUT/$name"
46
47         case "$src" in
48         *.cpp) BUILDCMD="$CXX $CXXFLAGS $src -o $exe" ;;
49         *.c)   BUILDCMD="$CC  $CXXFLAGS $src -o $exe" ;;
50         esac
51
52         [ $VERBOSE -gt 0 ] && echo "Building $name..."
53         [ $VERBOSE -gt 4 ] && echo " $BUILDCMD"
54         if $BUILDCMD 2>&1 | tee >$buildout $TESTOUT/$name.build; then
55                 [ $VERBOSE -gt 0 ] && echo "Running $name..."
56                 if ! $exe 2>&1 | tee >$runout $TESTOUT/$name.out; then
57                         echo "FAILED [RUN]: $name"
58                 fi
59         else
60                 echo "FAILED [BUILD]: $name"
61         fi
62 done
63