add packaging
[platform/upstream/db4.git] / test_micro / test_micro
1 #! /bin/sh
2 #
3 # $Id$
4 LIBS=${LIBS:-"-lpthread"}
5 WINBUILDDIR="Win32/Release"
6
7 CYGWIN=0
8 HOSTOS="`uname -o 2>/dev/null||uname -s 2>/dev/null`"
9 if test `echo "$HOSTOS"|grep -i cygwin|wc -l` -gt 0;then
10         CYGWIN=1
11 fi
12
13 # build_test_micro_posix
14 #       Build test_micro on a POSIX system.
15 build_test_micro_posix()
16 {
17         # See if there's a test_micro binary already.
18         test $clean -eq 0 && test -x test_micro && return 0
19
20         echo 'Compiling test_micro on posix system...'
21         rm -f test_micro
22         CC=${CC:-gcc}
23         if [ "$CC" = "gcc" ]; then
24                 CC="$CC -O3 -Wall"
25         else
26                 CC="$CC -O"
27         fi
28         $CC -I. -I../dbinc -I../dbinc_auto -I.. -I$h/source \
29             $SRC -o test_micro ./libdb.a $LIBS || return 1
30 }
31
32 # build_test_micro_windows
33 #       Build test_micro on a Windows system.
34 build_test_micro_windows()
35 {
36         # See if there's a test_micro binary already.
37         test $clean -eq 0 && test -x test_micro && return 0
38
39         echo 'Compiling test_micro on windows ...'
40         rm -f test_micro
41
42         cl /nologo /o test_micro /DDB_WIN32 /G6 /Ox /MD\
43           -I./  -I../ -I$h/source/ -I../dbinc -I../dbinc_auto $SRC $WINSRC\
44             ./$WINBUILDDIR/libdb*.lib ./Release/libdb*.lib ws2_32.lib advapi32.lib 
45 }
46
47 # run --
48 #       $1: args
49 run()
50 {
51         # You can set the MAJOR and MINOR environment variables to limit
52         # the BDB releases on which the tests are run.
53         echo Versions db-${MAJOR:-[3-9]}.${MINOR:-*}.*
54         for i in db-${MAJOR:-[3-9]}.${MINOR:-*}.*; do
55
56                 major=`echo $i|sed "s/db-//g"|cut -d . -f 1`
57                 minor=`echo $i|sed "s/db-//g"|cut -d . -f 2`
58                 if test $major -gt "4";then
59                         WINBUILDDIR="Win32/Release"
60                 elif test $major -lt "4";then
61                         WINBUILDDIR="Release"
62                 elif test "X$minor" = "X" -o "$minor" -lt "8";then
63                         WINBUILDDIR="Release"
64                 else
65                         WINBUILDDIR="Win32/Release"
66                 fi
67
68                 if [ -f $i/$variant/libdb.a ] ; then
69                         (cd $i/$variant/ &&
70                             build_test_micro_posix || exit 1)
71                 elif [ -f $i/build_windows/${WINBUILDDIR}/libdb??.lib ] ; then
72                         (cd $i/build_windows &&
73                             build_test_micro_windows || exit 1)
74                  fi
75
76                 echo "$i run begins: `date`"
77                 echo "test_micro $1..."
78                 if [ -f $i/$variant/libdb.a ] ; then
79                         (cd $i/$variant/ && ./test_micro $1 || exit 1)
80                         if [ -f $t/gmon.out ] ; then
81                                 mv $t/gmon.out $i/$variant
82                                 gprof $i/$variant/.libs/lt-test_micro $i/$variant/gmon.out > $i/$variant/gprof.out
83                         fi
84                 elif [ -f $i/build_windows/${WINBUILDDIR}/libdb??.lib  ] ; then
85                         (cd $i/build_windows/ && ./test_micro $1 || exit 1)
86                 fi
87                 echo "$i run ends: `date`"
88         done
89 }
90
91 # Get a path to this shellscript.
92 t=`dirname $0`
93 h=`(cd $t && pwd)`
94 if [ "$CYGWIN" = "1" ];then
95         h="`cygpath -m -a \"$h\"`"
96 fi
97 # We may need to re-compile, create a list of our sources.
98 SRC="$h/source/b_curalloc.c $h/source/b_curwalk.c $h/source/b_del.c
99 $h/source/b_get.c $h/source/b_inmem.c $h/source/b_load.c $h/source/b_latch.c
100 $h/source/b_open.c $h/source/b_put.c $h/source/b_recover.c
101 $h/source/b_txn.c $h/source/b_txn_write.c $h/source/b_uname.c
102 $h/source/b_util.c $h/source/b_workload.c $h/source/test_micro.c
103 $h/../common/util_arg.c"
104
105 WINSRC="$h/../clib/getopt.c"
106
107 # Process arguments.
108 clean=0                                 # Rebuild test_micro
109 workload=0                              # Run workload tests
110 start_test=0                            # Start test
111 end_test=0                              # End test
112 variant=build_unix
113 while :
114         do case "$1" in
115         -c)                             # Rebuild test_micro.
116                 clean=1
117                 shift;;
118         -w)                             # Run workload tests
119                 workload=1
120                 shift;;
121         [1-9]*-[0-9]*)                  # Range: -3, 3-, 3-10
122                 start_test=`echo $1|sed 's/-.*//'`
123                 start_test=${start_test:=1}
124                 end_test=`echo $1|sed 's/.*-//'`
125                 end_test=${end_test:=0}
126                 shift;;
127         [1-9]*)                         # Specific test
128                 start_test="$1"
129                 end_test="$1"
130                 shift;;
131         -v)     variant=$2      # get code here, rather than from build_unix
132                 shift; shift;;
133         *)
134                 break;;
135         esac
136 done
137 test "$#" -ne 0 && {
138         echo 'usage: test_micro [-cw] [# | #- | -# | #-#]' >& 2
139         exit 1
140 }
141
142 if test $start_test != 0; then
143         cmd="$cmd -s $start_test"
144 fi
145 if test $end_test != 0; then
146         cmd="$cmd -e $end_test"
147 fi
148
149 # Create the run directory, and initialize test_micro's arguments.
150 t=RUN.`hostname | sed 's/\..*//'`
151 [ -d $t ] || mkdir $t
152 if [ "$CYGWIN" = "1" ];then
153         cmd="$cmd -d `(cd $t && cygpath -m -a \"$PWD\")`"
154 else
155         cmd="$cmd -d `(cd $t && pwd)`"
156 fi
157 # Set input file.
158 if test "$workload" -eq 1; then
159         cmd="$cmd -i $h/configs/run.workload"
160 else
161         cmd="$cmd -i $h/configs/run.std"
162 fi
163
164 # Flush any I/O, just to get as a clean a timing as we can, ignore errors,
165 # sync is privleged on some systems.
166 (sync && sleep 1 2>&1) > /dev/null
167
168 run "$cmd"
169
170 exit 0