Merge two at91sam7 project.
[bertos.git] / test / 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 -O0 -g3 -ggdb -Ibertos -Ibertos/emul -std=gnu99 -fno-builtin -D_DEBUG -DARCH=(ARCH_EMUL|ARCH_UNITTEST) -DCPU_FREQ=(12288000UL)"
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 SRC_LIST="bertos/algo/ramp.c bertos/drv/kdebug.c bertos/drv/timer.c bertos/fs/battfs.c bertos/kern/coop.c bertos/kern/idle.c bertos/kern/kfile.c bertos/kern/monitor.c bertos/kern/proc.c bertos/kern/signal.c bertos/kern/sem.c bertos/mware/event.c bertos/mware/formatwr.c bertos/mware/hex.c bertos/mware/sprintf.c bertos/os/hptime.c bertos/emul/switch_ctx_emul.S"
31
32 buildout='/dev/null'
33 runout='/dev/null'
34 [ "$VERBOSE" -ge 2 ] && buildout='/dev/stdout'
35 [ "$VERBOSE" -ge 3 ] && runout='/dev/stdout'
36
37 # Needed to get build/exec result code rather than tee's
38 set -o pipefail
39
40 rm -rf "${TESTOUT}.old"
41 mv -f "${TESTOUT}" "$TESTOUT.old"
42 mkdir -p "$TESTOUT"
43
44 for src in $TESTS; do
45         name="`basename $src | sed -e 's/\.cpp$//' -e 's/\.c$//'`"
46         testdir="./$TESTOUT/$name"
47         cfgdir="$testdir/cfg"
48         mkdir -p "$cfgdir"
49         exe="$testdir/$name"
50
51         PREPARECMD="test/parsetest.py $src"
52         BUILDCMD="$CC -I$testdir $CFLAGS $src $SRC_LIST -o $exe"
53         export testdir name cfgdir
54
55         [ $VERBOSE -gt 0 ] && echo "Preparing $name..."
56         [ $VERBOSE -gt 4 ] && echo " $PREPARECMD"
57         if $PREPARECMD 2>&1 | tee >$buildout $testdir/$name.prep; then
58                 [ $VERBOSE -gt 0 ] && echo "Building $name..."
59                 [ $VERBOSE -gt 4 ] && echo " $BUILDCMD"
60                 if $BUILDCMD 2>&1 | tee >$buildout $testdir/$name.build; then
61                         [ $VERBOSE -gt 0 ] && echo "Running $name..."
62                         if ! $exe 2>&1 | tee >$runout $testdir/$name.out; then
63                                 echo "FAILED [RUN]: $name"
64                         fi
65                 else
66                         echo "FAILED [BUILD]: $name"
67                 fi
68         else
69                 echo "FAILED [PREPARING]: $name"
70         fi
71 done
72