mysql-test-run.sh 23.7 KB
Newer Older
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1
#! /bin/sh
2 3
# mysql-test-run - originally written by Matt Wagner <matt@mysql.com>
# modified by Sasha Pachev <sasha@mysql.com>
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
4
# Sligtly updated by Monty
5
# Cleaned up again by Matt
6 7
# Fixed by Sergei
# :-)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
8 9 10 11 12

#++
# Access Definitions
#--
DB=test
13
DBPASSWD=
14
VERBOSE=""
15
TZ=GMT-3; export TZ # for UNIX_TIMESTAMP tests to work
bk@work.mysql.com's avatar
bk@work.mysql.com committed
16

17 18 19 20
#++
# Program Definitions
#--

21
PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin
22

23 24 25 26
# Standard functions

which ()
{
27
  IFS="${IFS=   }"; save_ifs="$IFS"; IFS=':'
28 29
  for file
  do
30
    for dir in $PATH
31 32 33 34 35 36 37 38 39 40
    do
      if test -f $dir/$file
      then
        echo "$dir/$file"
        continue 2
      fi
    done
    echo "which: no $file in ($PATH)"
    exit 1
  done
41
  IFS="$save_ifs"
42 43 44
}


45 46 47
# No paths below as we can't be sure where the program is!

BASENAME=`which basename | head -1`
48
DIFF=`which diff | head -1`
49 50 51 52 53 54 55 56 57 58 59 60
CAT=cat
CUT=cut
TAIL=tail
ECHO=echo # use internal echo if possible
EXPR=expr # use internal if possible
FIND=find
GCOV=`which gcov | head -1`
PRINTF=printf
RM=rm
TIME=time
TR=tr
XARGS=`which xargs | head -1`
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
61
SED=sed
62 63 64 65 66

# Are we using a source or a binary distribution?

testdir=@testdir@
if [ -d bin/mysqld ] && [ -d mysql-test ] ; then
67 68
 cd mysql-test
else
69 70
 if [ -d $testdir/mysql-test ] ; then
   cd $testdir
71
 fi
72 73 74 75 76 77 78
fi

if [ ! -f ./mysql-test-run ] ; then
  $ECHO "Can't find the location for the mysql-test-run script"

  $ECHO "Go to to the mysql-test directory and execute the script as follows:"
  $ECHO "./mysql-test-run."
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
79
  exit 1
80
fi
81

bk@work.mysql.com's avatar
bk@work.mysql.com committed
82 83 84
#++
# Misc. Definitions
#--
85

86 87 88 89 90
if [ -d ../sql ] ; then
   SOURCE_DIST=1
else
   BINARY_DIST=1
fi
91

92
#BASEDIR is always one above mysql-test directory 
bk@work.mysql.com's avatar
bk@work.mysql.com committed
93 94 95 96
CWD=`pwd`
cd ..
BASEDIR=`pwd`
cd $CWD
97
MYSQL_TEST_DIR=$BASEDIR/mysql-test
98
export MYSQL_TEST_DIR
99
STD_DATA=$MYSQL_TEST_DIR/std_data
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
100
hostname=`hostname`		# Installed in the mysql privilege table
101
  
102
TESTDIR="$MYSQL_TEST_DIR/t"
103
TESTSUFFIX=test
104
TOT_SKIP=0
bk@work.mysql.com's avatar
bk@work.mysql.com committed
105 106 107
TOT_PASS=0
TOT_FAIL=0
TOT_TEST=0
108 109 110
USERT=0
SYST=0
REALT=0
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
111
MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
112
SLAVE_LOAD_TMPDIR=../../var/tmp #needs to be same length to test logging
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
113
RES_SPACE="      "
114 115
MYSQLD_SRC_DIRS="strings mysys include extra regex isam merge myisam \
 myisammrg heap sql"
116

sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
117
MASTER_RUNNING=0
118
MASTER_MYPORT=9306
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
119
SLAVE_RUNNING=0
120
SLAVE_MYPORT=9307
121
NO_SLAVE=0
122

123
EXTRA_MASTER_OPT=""
124 125 126 127 128
EXTRA_MYSQL_TEST_OPT=""
USE_RUNNING_SERVER=1
DO_GCOV=""
DO_GDB=""
DO_DDD=""
129
DO_CLIENT_GDB=""
130
SLEEP_TIME=2
131
CHARACTER_SET=latin1_de
132
DBUSER=""
133 134 135

while test $# -gt 0; do
  case "$1" in
136 137
    --user=*) DBUSER=`$ECHO "$1" | $SED -e "s;--user=;;"` ;;
    --force)  FORCE=1 ;;
138 139 140 141
    --local)   USE_RUNNING_SERVER="" ;;
    --tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;;
    --master_port=*) MASTER_MYPORT=`$ECHO "$1" | $SED -e "s;--master_port=;;"` ;;
    --slave_port=*) SLAVE_MYPORT=`$ECHO "$1" | $SED -e "s;--slave_port=;;"` ;;
142 143
    --with-openssl)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
144 145 146
     --ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/server-cert.pem \
     --ssl-key=$BASEDIR/SSL/server-key.pem"
147
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
148 149 150
     --ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/server-cert.pem \
     --ssl-key=$BASEDIR/SSL/server-key.pem" ;;
151 152 153 154 155 156
    --skip-innobase)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-innobase"
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-innobase" ;;
    --skip-bdb)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-bdb"
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-bdb" ;;
157
    --skip-rpl) NO_SLAVE=1 ;;
158
    --skip-test=*) SKIP_TEST=`$ECHO "$1" | $SED -e "s;--skip-test=;;"`;;
159
    --do-test=*) DO_TEST=`$ECHO "$1" | $SED -e "s;--do-test=;;"`;;
160 161 162
    --record)
      RECORD=1;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
163 164 165 166
    --bench)
      DO_BENCH=1
      NO_SLAVE=1
      ;;  
167 168
    --big*)			# Actually --big-test
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
169 170 171 172
    --sleep=*)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1"
      SLEEP_TIME=`$ECHO "$1" | $SED -e "s;--sleep=;;"`
      ;;
173
    --mysqld=*)
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
174
       TMP=`$ECHO "$1" | $SED -e "s;--mysqld=;;"`
175
       EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $TMP"
176
       EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $TMP"
177
       ;;
178 179 180 181 182 183 184
    --gcov )
      if [ x$BINARY_DIST = x1 ] ; then
	$ECHO "Cannot do coverage test without the source - please use source dist"
	exit 1
      fi
      DO_GCOV=1
      ;;
185 186 187
    --gprof )
      DO_GPROF=1
      ;;  
188 189
    --gdb )
      if [ x$BINARY_DIST = x1 ] ; then
190
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --gdb option"
191 192
      fi
      DO_GDB=1
193
      USE_RUNNING_SERVER=""
194
      ;;
195 196 197 198 199 200
    --client-gdb )
      if [ x$BINARY_DIST = x1 ] ; then
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --client-gdb option"
      fi
      DO_CLIENT_GDB=1
      ;;
201 202
    --ddd )
      if [ x$BINARY_DIST = x1 ] ; then
203
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --ddd option"
204 205
      fi
      DO_DDD=1
206
      USE_RUNNING_SERVER=""
207
      ;;
208 209 210 211
    --skip-*)
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $1"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $1"
      ;;
212
    --debug)
213
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
214
       --debug=d:t:O,$MYSQL_TEST_DIR/var/log/master.trace"
215
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
216
       --debug=d:t:O,$MYSQL_TEST_DIR/var/log/slave.trace"
217
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --debug"
218 219 220 221 222 223 224
      ;;
    -- )  shift; break ;;
    --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
    * ) break ;;
  esac
  shift
done
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
225

bk@work.mysql.com's avatar
bk@work.mysql.com committed
226 227 228
#++
# mysqld Environment Parameters
#--
229

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
230
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
231
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
232
MASTER_MYSOCK="$MYSQL_TMP_DIR/mysql-master.sock"
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
233
MASTER_MYPID="$MYRUN_DIR/mysqld.pid"
234 235 236 237
MASTER_MYLOG="$MYSQL_TEST_DIR/var/log/mysqld.log"
MASTER_MYERR="$MYSQL_TEST_DIR/var/log/mysqld.err"

SLAVE_MYDDIR="$MYSQL_TEST_DIR/var/slave-data"
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
238 239
SLAVE_MYSOCK="$MYSQL_TMP_DIR/mysql-slave.sock"
SLAVE_MYPID="$MYRUN_DIR/mysqld-slave.pid"
240 241 242
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/mysqld-slave.log"
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/mysqld-slave.err"

243 244
SMALL_SERVER="-O key_buffer_size=1M -O sort_buffer=256K -O max_heap_table_size=1M"

sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
245 246 247
export MASTER_MYPORT
export SLAVE_MYPORT

248 249 250 251 252
if [ x$SOURCE_DIST = x1 ] ; then
 MY_BASEDIR=$MYSQL_TEST_DIR
else
 MY_BASEDIR=$BASEDIR
fi  
bk@work.mysql.com's avatar
bk@work.mysql.com committed
253

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
254 255 256 257 258 259 260 261 262
# Create the directories

# This should be fixed to be not be dependent on the contence of MYSQL_TMP_DIR
# or MYRUN_DIR
# (mkdir -p is not portable)
[ -d $MYSQL_TEST_DIR/var ] || mkdir $MYSQL_TEST_DIR/var
[ -d $MYSQL_TEST_DIR/var/tmp ] || mkdir $MYSQL_TEST_DIR/var/tmp
[ -d $MYSQL_TEST_DIR/var/run ] || mkdir $MYSQL_TEST_DIR/var/run

263 264
[ -z "$COLUMNS" ] && COLUMNS=80
E=`$EXPR $COLUMNS - 8`
265
#DASH72=`$EXPR substr '------------------------------------------------------------------------' 1 $E`
266
DASH72=`$ECHO '------------------------------------------------------------------------'|$CUT -c 1-$E`
267

268 269 270 271
# on source dist, we pick up freshly build executables
# on binary, use what is installed
if [ x$SOURCE_DIST = x1 ] ; then
 MYSQLD="$BASEDIR/sql/mysqld"
272 273 274 275 276 277
 if [ -e "$BASEDIR/client/.libs/mysqltest" ] ; then
   [ -e "$BASEDIR/client/.libs/lt-mysqltest" ] || $BASEDIR/client/mysqltest -V
   MYSQL_TEST="$BASEDIR/client/.libs/lt-mysqltest"
 else
   MYSQL_TEST="$BASEDIR/client/mysqltest"
 fi
278
 MYSQLADMIN="$BASEDIR/client/mysqladmin"
279
 MYSQL="$BASEDIR/client/mysql"
280
 LANGUAGE="$BASEDIR/sql/share/english/"
281
 CHARSETSDIR="$BASEDIR/sql/share/charsets"
282 283 284 285 286
 INSTALL_DB="./install_test_db"
else
 MYSQLD="$BASEDIR/bin/mysqld"
 MYSQL_TEST="$BASEDIR/bin/mysqltest"
 MYSQLADMIN="$BASEDIR/bin/mysqladmin"
287
 MYSQL="$BASEDIR/bin/mysql"
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
288
 INSTALL_DB="./install_test_db -bin"
289 290 291
 if test -d "$BASEDIR/share/mysql/english" 
 then
   LANGUAGE="$BASEDIR/share/mysql/english/"
292
   CHARSETSDIR="$BASEDIR/share/mysql/charsets"
293 294
 else
   LANGUAGE="$BASEDIR/share/english/"
295
   CHARSETSDIR="$BASEDIR/share/charsets"
296
  fi
297 298
fi

299 300 301 302 303 304
# If we should run all tests cases, we will use a local server for that

if [ -z "$1" ]
then
   USE_RUNNING_SERVER=""
fi
305 306 307
if [ -n "$USE_RUNNING_SERVER" ]
then
   MASTER_MYSOCK="/tmp/mysql.sock"
308
   DBUSER=${DBUSER:-test}
309
else
310
   DBUSER=${DBUSER:-root}		# We want to do FLUSH xxx commands
311
fi
312 313 314 315 316 317 318 319

if [ -w / ]
then
    # We are running as root;  We need to add the --root argument
    EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --user=root"
    EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --user=root"
fi

320

321 322 323 324
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB --user=$DBUSER --password=$DBPASSWD --silent -v --tmpdir=$MYSQL_TMP_DIR"
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
325 326 327
GDB_MASTER_INIT=$MYSQL_TMP_DIR/gdbinit.master
GDB_SLAVE_INIT=$MYSQL_TMP_DIR/gdbinit.slave
GCOV_MSG=$MYSQL_TMP_DIR/mysqld-gcov.out
328 329 330 331
GCOV_ERR=$MYSQL_TMP_DIR/mysqld-gcov.err
GPROF_DIR=$MYSQL_TMP_DIR/gprof
GPROF_MASTER=$GPROF_DIR/master.gprof
GPROF_SLAVE=$GPROF_DIR/slave.gprof
332 333 334
TIMEFILE="$MYSQL_TMP_DIR/mysqltest-time"
SLAVE_MYSQLD=$MYSQLD #this can be changed later if we are doing gcov

bk@work.mysql.com's avatar
bk@work.mysql.com committed
335 336 337
#++
# Function Definitions
#--
338
wait_for_server_start ()
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
339
{
monty@tik.mysql.fi's avatar
monty@tik.mysql.fi committed
340
   $MYSQLADMIN --no-defaults -u $DBUSER --silent -O connect_timeout=10 -w2 --host=$hostname --port=$1  ping >/dev/null 2>&1
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
341
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
342

343 344
prompt_user ()
{
345
 $ECHO $1
346
 read unused
347 348
}

349 350
# We can't use diff -u as this isn't portable

351 352 353 354
show_failed_diff ()
{
  reject_file=r/$1.reject
  result_file=r/$1.result
355 356 357 358 359 360 361
  eval_file=r/$1.eval
  
  if [ -f $eval_file ]
  then
    result_file=$eval_file
  fi
    
362 363 364 365
  if [ -x "$DIFF" ] && [ -f $reject_file ]
  then
    echo "Below are the diffs between actual and expected results:"
    echo "-------------------------------------------------------"
366
    $DIFF -c -a $result_file $reject_file
367
    echo "-------------------------------------------------------"
368 369 370
    echo "Please follow the instructions outlined at"
    echo "http://www.mysql.com/doc/R/e/Reporting_mysqltest_bugs.html"
    echo "to find the reason to this problem and how to report this."
371 372
  fi  
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
373

374 375 376 377 378 379 380 381 382
do_gdb_test ()
{
  mysql_test_args="$MYSQL_TEST_ARGS $1"
  $ECHO "set args $mysql_test_args < $2" > $GDB_CLIENT_INIT
  echo "Set breakpoints ( if needed) and type 'run' in gdb window"
  #this xterm should not be backgrounded
  xterm -title "Client" -e gdb -x $GDB_CLIENT_INIT $MYSQL_TEST_BIN
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
383
error () {
384
    $ECHO  "Error:  $1"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
385 386 387
    exit 1
}

388
error_is () {
389
    $TR "\n" " " < $TIMEFILE | $SED -e 's/.* At line \(.*\)\: \(.*\)Command .*$/   \>\> Error at line \1: \2<\</'
390 391
}

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
392
prefix_to_8() {
393
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
394 395
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
396
pass_inc () {
397
    TOT_PASS=`$EXPR $TOT_PASS + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
398 399 400
}

fail_inc () {
401
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
402 403
}

404 405 406 407
skip_inc () {
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
408
total_inc () {
409
    TOT_TEST=`$EXPR $TOT_TEST + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
410 411 412
}

report_stats () {
413
    if [ $TOT_FAIL = 0 ]; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
414
	$ECHO "All $TOT_TEST tests were successful."
bk@work.mysql.com's avatar
bk@work.mysql.com committed
415
    else
416 417 418 419 420 421
	xten=`$EXPR $TOT_PASS \* 10000`   
	raw=`$EXPR $xten / $TOT_TEST`     
	raw=`$PRINTF %.4d $raw`           
	whole=`$PRINTF %.2s $raw`         
	xwhole=`$EXPR $whole \* 100`      
	deci=`$EXPR $raw - $xwhole`       
422
	$ECHO  "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% successful."
423 424 425 426 427
	$ECHO ""
        $ECHO "The log files in $MYSQL_TEST_DIR/var/log may give you some hint"
	$ECHO "of what when wrong."
	$ECHO "If you want to report this error, please read first the documentation at"
        $ECHO "http://www.mysql.com/doc/M/y/MySQL_test_suite.html"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
428 429
    fi
}
430

bk@work.mysql.com's avatar
bk@work.mysql.com committed
431
mysql_install_db () {
432
    $ECHO "Removing Stale Files"
433 434
    $RM -rf $MASTER_MYDDIR $SLAVE_MYDDIR $SLAVE_MYLOG $MASTER_MYLOG \
     $SLAVE_MYERR $MASTER_MYERR
435
    $ECHO "Installing Master Databases"
436 437 438 439 440
    $INSTALL_DB
    if [ $? != 0 ]; then
	error "Could not install master test DBs"
	exit 1
    fi
441
    $ECHO "Installing Slave Databases"
442
    $INSTALL_DB -slave
443
    if [ $? != 0 ]; then
444
	error "Could not install slave test DBs"
445
	exit 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
446
    fi
447 448
    # Give mysqld some time to die.
    sleep $SLEEP_TIME
bk@work.mysql.com's avatar
bk@work.mysql.com committed
449 450 451
    return 0
}

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
gprof_prepare ()
{
 rm -rf $GPROF_DIR
 mkdir -p $GPROF_DIR 
}

gprof_collect ()
{
 if [ -f $MASTER_MYDDIR/gmon.out ]; then
   gprof $MYSQLD $MASTER_MYDDIR/gmon.out > $GPROF_MASTER
   echo "Master execution profile has been saved in $GPROF_MASTER"
 fi
 if [ -f $SLAVE_MYDDIR/gmon.out ]; then
   gprof $MYSQLD $SLAVE_MYDDIR/gmon.out > $GPROF_SLAVE
   echo "Slave execution profile has been saved in $GPROF_SLAVE"
 fi
}

470
gcov_prepare () {
471 472
    $FIND $BASEDIR -name \*.gcov \
    -or -name \*.da | $XARGS $RM
473 474 475
}

gcov_collect () {
476
    $ECHO "Collecting source coverage info..."
477 478
    [ -f $GCOV_MSG ] && $RM $GCOV_MSG
    [ -f $GCOV_ERR ] && $RM $GCOV_ERR
479 480 481
    for d in $MYSQLD_SRC_DIRS; do
	cd $BASEDIR/$d
	for f in *.h *.cc *.c; do
482
	    $GCOV $f 2>>$GCOV_ERR  >>$GCOV_MSG
483
	done
484
	cd $MYSQL_TEST_DIR
485 486
    done

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
487
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
488 489
}

490

491 492
start_master()
{
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
493
    [ x$MASTER_RUNNING = 1 ] && return
494 495 496 497 498
    #run master initialization shell script if one exists
    if [ -f "$master_init_script" ] ;
    then
        /bin/sh $master_init_script
    fi
499
    cd $BASEDIR # for gcov
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
500 501
    # Remove old berkeley db log files that can confuse the server
    $RM -f $MASTER_MYDDIR/log.*	
502
    #start master
503 504 505
    if [ -z "$DO_BENCH" ]
    then
      master_args="--no-defaults --log-bin=master-bin \
506
    	    --server-id=1 \
507
            --basedir=$MY_BASEDIR \
508
	    --port=$MASTER_MYPORT \
509
	    --exit-info=256 \
510 511 512
            --datadir=$MASTER_MYDDIR \
	    --pid-file=$MASTER_MYPID \
	    --socket=$MASTER_MYSOCK \
513 514 515
            --log=$MASTER_MYLOG \
	    --character-sets-dir=$CHARSETSDIR \
	    --default-character-set=$CHARACTER_SET \
516
	    --tmpdir=$MYSQL_TMP_DIR \
517
	    --language=$LANGUAGE \
518
            --innodb_data_file_path=ibdata1:50M \
519 520
	     $SMALL_SERVER \
	     $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT"
521 522 523 524 525 526 527
    else
      master_args="--no-defaults --log-bin=master-bin --server-id=1 \
            --basedir=$MY_BASEDIR \
	    --port=$MASTER_MYPORT \
            --datadir=$MASTER_MYDDIR \
	    --pid-file=$MASTER_MYPID \
	    --socket=$MASTER_MYSOCK \
528 529
	    --character-sets-dir=$CHARSETSDIR \
            --default-character-set=$CHARACTER_SET \
530 531
	    --core \
	    --tmpdir=$MYSQL_TMP_DIR \
532
	    --language=$LANGUAGE \
533
            --innodb_data_file_path=ibdata1:50M \
534 535 536
	     $SMALL_SERVER \
	     $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT"
    fi	     
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
537 538 539 540 541 542
    if [ x$DO_DDD = x1 ]
    then
      $ECHO "set args $master_args" > $GDB_MASTER_INIT
      ddd --debugger "gdb -x $GDB_MASTER_INIT" $MYSQLD &
      prompt_user "Hit enter to continue after you've started the master"
    elif [ x$DO_GDB = x1 ]
543
    then
544
      $ECHO "set args $master_args" > $GDB_MASTER_INIT
545 546 547 548 549
      xterm -title "Master" -e gdb -x $GDB_MASTER_INIT $MYSQLD &
      prompt_user "Hit enter to continue after you've started the master"
    else	    
      $MYSQLD $master_args  >> $MASTER_MYERR 2>&1 &
    fi  
550
  wait_for_server_start $MASTER_MYPORT
551 552 553 554 555
  MASTER_RUNNING=1
}

start_slave()
{
556
    [ x$SKIP_SLAVE = x1 ] && return
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
557
    [ x$SLAVE_RUNNING = 1 ] && return
558 559 560 561 562 563 564
    
    #run slave initialization shell script if one exists
    if [ -f "$slave_init_script" ] ;
    then
	  /bin/sh $slave_init_script
    fi
    
565
    if [ -z "$SLAVE_MASTER_INFO" ] ; then
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
566
      master_info="--master-user=root \
567
	    --master-connect-retry=1 \
568
	    --master-host=127.0.0.1 \
569
	    --master-password= \
570
	    --master-port=$MASTER_MYPORT \
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
571 572 573 574 575
	    --server-id=2"
   else
     master_info=$SLAVE_MASTER_INFO
   fi	    
    
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
576
    $RM -f $SLAVE_MYDDIR/log.*	
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
577 578
    slave_args="--no-defaults $master_info \
    	    --exit-info=256 \
579
	    --log-bin=slave-bin --log-slave-updates \
580
            --basedir=$MY_BASEDIR \
581 582 583 584
            --datadir=$SLAVE_MYDDIR \
	    --pid-file=$SLAVE_MYPID \
	    --port=$SLAVE_MYPORT \
	    --socket=$SLAVE_MYSOCK \
585 586 587
            --log=$SLAVE_MYLOG \
	    --character-sets-dir=$CHARSETSDIR \
	    --default-character-set=$CHARACTER_SET \
588
	    --core \
589
	    --tmpdir=$MYSQL_TMP_DIR \
590
            --language=$LANGUAGE \
591
	    --skip-innodb --skip-slave-start \
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
592
	    --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
593 594
	    --report-host=127.0.0.1 --report-user=root \
	    --report-port=$SLAVE_MYPORT \
595 596
	     $SMALL_SERVER \
             $EXTRA_SLAVE_OPT $EXTRA_SLAVE_MYSQLD_OPT"
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
597 598 599
    if [ x$DO_DDD = x1 ]
    then
      $ECHO "set args $master_args" > $GDB_SLAVE_INIT
600
      ddd --debugger "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD &
601
      prompt_user "Hit enter to continue after you've started the slave"
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
602
    elif [ x$DO_GDB = x1 ]
603
    then
604
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
605
      xterm -title "Slave" -e gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD &
606
      prompt_user "Hit enter to continue after you've started the slave"
607 608
    else
      $SLAVE_MYSQLD $slave_args  >> $SLAVE_MYERR 2>&1 &
609
    fi
610
    wait_for_server_start $SLAVE_MYPORT
611 612 613 614
    SLAVE_RUNNING=1
}

mysql_start () {
615
    $ECHO "Starting MySQL daemon"
616 617
    start_master
    start_slave
618
    cd $MYSQL_TEST_DIR
bk@work.mysql.com's avatar
bk@work.mysql.com committed
619 620 621
    return 1
}

622 623 624 625
stop_slave ()
{
  if [ x$SLAVE_RUNNING = x1 ]
  then
626
    $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O shutdown_timeout=10 shutdown
627 628
    if [ $? != 0 ] && [ -f $SLAVE_MYPID ]
    then # try harder!
629
     $ECHO "slave not cooperating with mysqladmin, will try manual kill"
630
     kill `$CAT $SLAVE_MYPID`
631
     sleep $SLEEP_TIME
632
     if [ -f $SLAVE_MYPID ] ; then
633
       $ECHO "slave refused to die. Sending SIGKILL"
634
       kill -9 `$CAT $SLAVE_MYPID`
635
       $RM -f $SLAVE_MYPID
636
     else
637
      $ECHO "slave responded to SIGTERM " 
638 639
     fi
    fi
640 641 642
    SLAVE_RUNNING=0
  fi  
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
643

644 645 646 647
stop_master ()
{
  if [ x$MASTER_RUNNING = x1 ]
  then
648
    $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK -u root -O shutdown_timeout=10 shutdown
649 650
    if [ $? != 0 ] && [ -f $MASTER_MYPID ]
    then # try harder!
651
     $ECHO "master not cooperating with mysqladmin, will try manual kill"
652
     kill `$CAT $MASTER_MYPID`
653
     sleep $SLEEP_TIME
654
     if [ -f $MASTER_MYPID ] ; then
655
       $ECHO "master refused to die. Sending SIGKILL"
656
       kill -9 `$CAT $MASTER_MYPID`
657
       $RM -f $MASTER_MYPID
658
     else
659
      $ECHO "master responded to SIGTERM " 
660 661
     fi
    fi
662 663 664
    MASTER_RUNNING=0
  fi
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
665

666 667
mysql_stop ()
{
668 669
 $ECHO  "Ending Tests"
 $ECHO  "Shutting-down MySQL daemon"
670
 $ECHO  ""
671
 stop_master
672
 $ECHO "Master shutdown finished"
673
 stop_slave
674 675
 $ECHO "Slave shutdown finished"
 
676
 return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
677 678 679 680 681 682 683 684 685 686 687
}

mysql_restart () {

    mysql_stop
    mysql_start

    return 1
}

mysql_loadstd () {
688
    
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
689
    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test  
bk@work.mysql.com's avatar
bk@work.mysql.com committed
690 691 692
    return 1
}

693 694 695
run_testcase ()
{
 tf=$1
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
696
 tname=`$BASENAME $tf .test`
697 698
 master_opt_file=$TESTDIR/$tname-master.opt
 slave_opt_file=$TESTDIR/$tname-slave.opt
699 700
 master_init_script=$TESTDIR/$tname-master.sh
 slave_init_script=$TESTDIR/$tname-slave.sh
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
701
 slave_master_info_file=$TESTDIR/$tname-slave-master-info.opt
702
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`
703
 if [ -n "$SKIP_TEST" ] ; then 
704
   SKIP_THIS_TEST=`$EXPR \( $tname : "$SKIP_TEST" \) != 0`
705 706 707 708 709
   if [ x$SKIP_THIS_TEST = x1 ] ;
   then
    return;
   fi
  fi
710

711 712 713 714 715 716 717 718 719
 if [ -n "$DO_TEST" ] ; then 
   DO_THIS_TEST=`$EXPR \( $tname : "$DO_TEST" \) != 0`
   if [ x$DO_THIS_TEST = x0 ] ;
   then
    return;
   fi
  fi


720 721 722 723 724 725
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ;
 then
   USERT="    ...."
   SYST="    ...."
   REALT="    ...."
   timestr="$USERT $SYST $REALT"
726 727
   pname=`$ECHO "$tname                        "|$CUT -c 1-24`
   RES="$pname  $timestr"
728
   skip_inc
729 730 731 732
   $ECHO "$RES$RES_SPACE [ skipped ]"
   return
 fi

733
 if [ -z "$USE_RUNNING_SERVER" ] ;
734
 then
735 736 737 738 739 740 741 742 743 744 745 746 747 748
   if [ -f $master_opt_file ] ;
   then
     EXTRA_MASTER_OPT=`$CAT $master_opt_file`
     stop_master
     start_master
   else
     if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] ;
     then
       EXTRA_MASTER_OPT=""
       stop_master
       start_master
     fi  
   fi
   do_slave_restart=0
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
749
 
750 751 752 753 754 755 756 757 758 759 760
   if [ -f $slave_opt_file ] ;
   then
     EXTRA_SLAVE_OPT=`$CAT $slave_opt_file`
     do_slave_restart=1
   else
    if [ ! -z "$EXTRA_SLAVE_OPT" ] || [ x$SLAVE_RUNNING != x1 ] ;
    then
      EXTRA_SLAVE_OPT=""
      do_slave_restart=1    
    fi  
   fi
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
761

762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
   if [ -f $slave_master_info_file ] ; then
     SLAVE_MASTER_INFO=`$CAT $slave_master_info_file`
     do_slave_restart=1
   else
     if [ ! -z "$SLAVE_MASTER_INFO" ] || [ x$SLAVE_RUNNING != x1 ] ;
     then
       SLAVE_MASTER_INFO=""
       do_slave_restart=1    
     fi  
   fi

   if [ x$do_slave_restart = x1 ] ; then
     stop_slave
     start_slave
   fi
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
777
 fi
778
 cd $MYSQL_TEST_DIR
779
  
780
 if [ -f $tf ] ; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
781
    $RM -f r/$tname.*reject
782
    mysql_test_args="-R r/$tname.result $EXTRA_MYSQL_TEST_OPT"
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
783
     if [ -z "$DO_CLIENT_GDB" ] ; then
784 785 786 787 788
     mytime=`$TIME -p $MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`
    else
     do_gdb_test "$mysql_test_args" "$tf"
    fi
     
bk@work.mysql.com's avatar
bk@work.mysql.com committed
789 790
    res=$?

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
791
    if [ $res = 0 ]; then
792
	mytime=`$CAT $TIMEFILE | $TAIL -3 | $TR '\n' ':'`
793

794
	USERT=`$ECHO $mytime | $CUT -d : -f 2 | $CUT -d ' ' -f 2`
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
795
        USERT=`prefix_to_8 $USERT`
796
	SYST=`$ECHO $mytime | $CUT -d : -f 3 | $CUT -d ' ' -f 2`
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
797
        SYST=`prefix_to_8 $SYST`
798
	REALT=`$ECHO $mytime | $CUT -d : -f 1 | $CUT -d ' ' -f 2`
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
799
        REALT=`prefix_to_8 $REALT`
800
    else
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
801 802 803
	USERT="    ...."
	SYST="    ...."
	REALT="    ...."
804 805
    fi

806
    timestr="$USERT $SYST $REALT"
807 808
    pname=`$ECHO "$tname                        "|$CUT -c 1-24`
    RES="$pname  $timestr"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
809

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
810
    if [ $res = 0 ]; then
811 812
      total_inc
      pass_inc
813
      $ECHO "$RES$RES_SPACE [ pass ]"
814
    else
815
      # why the following ``if'' ? That is why res==1 is special ?
816 817 818 819
      if [ $res = 2 ]; then
        skip_inc
	$ECHO "$RES$RES_SPACE [ skipped ]"
      else
820
	total_inc
821
        fail_inc
822
	$ECHO "$RES$RES_SPACE [ fail ]"
823 824
        $ECHO
	error_is
825
	show_failed_diff $tname
826
	$ECHO
827
	if [ x$FORCE != x1 ] ; then
828 829
	 $ECHO "Aborting. To continue, re-run with '--force'."
	 $ECHO
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
830 831 832 833
         if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	 then
	   mysql_stop
   	 fi
834 835 836
	 exit 1
	fi
	 
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
837 838 839 840
        if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	then
	  mysql_restart
	fi
841
	$ECHO "Resuming Tests"
842
	$ECHO ""
843
      fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
844
    fi
845
  fi
846 847 848
}


monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
849 850 851 852
######################################################################
# Main script starts here
######################################################################

853 854 855
[ "$DO_GCOV" -a ! -x "$GCOV" ] && error "No gcov found"

[ "$DO_GCOV" ] && gcov_prepare 
856
[ "$DO_GPROF" ] && gprof_prepare 
857

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
858
# Ensure that no old mysqld test servers are running
859 860 861 862 863 864
if [ -z "$USE_RUNNING_SERVER" ]
then
  $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK -u root -O connect_timeout=5 shutdown > /dev/null 2>&1
  $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 shutdown > /dev/null 2>&1
  $ECHO "Installing Test Databases"
  mysql_install_db
865

866 867
#do not automagically start deamons if we are in gdb or running only one test
#case
868 869 870 871 872 873
  if [ -z "$DO_GDB" ] && [ -z "$DO_DDD" ]
  then
    mysql_start
  fi
  $ECHO  "Loading Standard Test Databases"
  mysql_loadstd
874 875 876
fi


877
$ECHO  "Starting Tests"
878

879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
if [ "$DO_BENCH" = 1 ]
then
 BENCHDIR=$BASEDIR/sql-bench/
 savedir=`pwd`
 cd $BENCHDIR
 if [ -z "$1" ]
 then
  ./run-all-tests --socket=$MASTER_MYSOCK --user=root
 else
 if [ -x "./$1" ]
  then
   ./$1 --socket=$MASTER_MYSOCK --user=root
  else
   echo "benchmark $1 not found" 
  fi
 fi  
 cd $savedir
 mysql_stop
 exit
fi


901
$ECHO
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
902
$ECHO " TEST                         USER   SYSTEM  ELAPSED        RESULT"
903 904
$ECHO $DASH72

905
if [ -z "$1" ] ;
906
then
907
 if [ x$RECORD = x1 ]; then
908
  $ECHO "Will not run in record mode without a specific test case."
909 910 911 912 913
 else
  for tf in $TESTDIR/*.$TESTSUFFIX
  do
    run_testcase $tf
  done
914
  $RM -f $TIMEFILE	# Remove for full test
915
 fi
916 917
else 
tname=`$BASENAME $1 .test`
918
 tf=$TESTDIR/$tname.$TESTSUFFIX
919 920 921
 if [ -f $tf ] ; then
  run_testcase $tf
 else
922
   $ECHO "Test case $tf does not exist."
923
 fi
924
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
925

926 927
$ECHO $DASH72
$ECHO
928

929
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
930 931 932
then
    mysql_stop
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
933 934

report_stats
935
$ECHO
bk@work.mysql.com's avatar
bk@work.mysql.com committed
936

937
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
938
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
939

bk@work.mysql.com's avatar
bk@work.mysql.com committed
940
exit 0