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

#++
# Access Definitions
#--
DB=test
13
DBPASSWD=
14
VERBOSE=""
unknown's avatar
unknown committed
15
USE_MANAGER=0
unknown's avatar
unknown committed
16
TZ=GMT-3; export TZ # for UNIX_TIMESTAMP tests to work
unknown's avatar
unknown committed
17

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

unknown's avatar
unknown committed
22
PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin
23

24 25 26 27
# Standard functions

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


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

BASENAME=`which basename | head -1`
unknown's avatar
unknown committed
49
DIFF=`which diff | head -1`
50 51
CAT=cat
CUT=cut
unknown's avatar
unknown committed
52
HEAD=head
53 54 55 56 57 58 59 60 61 62
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`
unknown's avatar
unknown committed
63
SED=sed
64 65 66 67 68

# Are we using a source or a binary distribution?

testdir=@testdir@
if [ -d bin/mysqld ] && [ -d mysql-test ] ; then
69 70
 cd mysql-test
else
71 72
 if [ -d $testdir/mysql-test ] ; then
   cd $testdir
73
 fi
74 75 76 77 78 79 80
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."
unknown's avatar
unknown committed
81
  exit 1
82
fi
83

unknown's avatar
unknown committed
84 85 86
#++
# Misc. Definitions
#--
87

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

94
#BASEDIR is always one above mysql-test directory 
unknown's avatar
unknown committed
95 96 97 98
CWD=`pwd`
cd ..
BASEDIR=`pwd`
cd $CWD
99
MYSQL_TEST_DIR=$BASEDIR/mysql-test
100
export MYSQL_TEST_DIR
101
STD_DATA=$MYSQL_TEST_DIR/std_data
unknown's avatar
unknown committed
102
hostname=`hostname`		# Installed in the mysql privilege table
unknown's avatar
unknown committed
103 104

MANAGER_QUIET_OPT="-q"    
105
TESTDIR="$MYSQL_TEST_DIR/t"
unknown's avatar
unknown committed
106
TESTSUFFIX=test
107
TOT_SKIP=0
unknown's avatar
unknown committed
108 109 110
TOT_PASS=0
TOT_FAIL=0
TOT_TEST=0
111 112 113
USERT=0
SYST=0
REALT=0
unknown's avatar
unknown committed
114
MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp
unknown's avatar
unknown committed
115
SLAVE_LOAD_TMPDIR=../../var/tmp #needs to be same length to test logging
unknown's avatar
unknown committed
116
RES_SPACE="      "
unknown's avatar
unknown committed
117 118
MYSQLD_SRC_DIRS="strings mysys include extra regex isam merge myisam \
 myisammrg heap sql"
119 120 121
#
# Set LD_LIBRARY_PATH if we are using shared libraries
#
unknown's avatar
unknown committed
122
LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$LD_LIBRARY_PATH"
123
export LD_LIBRARY_PATH
124

unknown's avatar
fixed  
unknown committed
125
MASTER_RUNNING=0
126
MASTER_MYPORT=9306
unknown's avatar
fixed  
unknown committed
127
SLAVE_RUNNING=0
128
SLAVE_MYPORT=9307
129
MYSQL_MANAGER_PORT=9305 # needs to be out of the way of slaves
unknown's avatar
unknown committed
130 131 132
MYSQL_MANAGER_PW_FILE=$MYSQL_TEST_DIR/var/tmp/manager.pwd
MYSQL_MANAGER_LOG=$MYSQL_TEST_DIR/var/log/manager.log
MYSQL_MANAGER_USER=root
133
NO_SLAVE=0
134

135
EXTRA_MASTER_OPT=""
136 137 138 139 140
EXTRA_MYSQL_TEST_OPT=""
USE_RUNNING_SERVER=1
DO_GCOV=""
DO_GDB=""
DO_DDD=""
141
DO_CLIENT_GDB=""
142
SLEEP_TIME=2
unknown's avatar
unknown committed
143
CHARACTER_SET=latin1
144
DBUSER=""
unknown's avatar
unknown committed
145 146
START_WAIT_TIMEOUT=3
STOP_WAIT_TIMEOUT=3
147 148 149

while test $# -gt 0; do
  case "$1" in
150 151
    --user=*) DBUSER=`$ECHO "$1" | $SED -e "s;--user=;;"` ;;
    --force)  FORCE=1 ;;
unknown's avatar
unknown committed
152
    --verbose-manager)  MANAGER_QUIET_OPT="" ;;
153 154
    --local)   USE_RUNNING_SERVER="" ;;
    --tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;;
155 156 157 158 159
    --local-master)
      MASTER_MYPORT=3306;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --host=127.0.0.1 \
      --port=$MYSQL_MYPORT"
      LOCAL_MASTER=1 ;;
160 161
    --master_port=*) MASTER_MYPORT=`$ECHO "$1" | $SED -e "s;--master_port=;;"` ;;
    --slave_port=*) SLAVE_MYPORT=`$ECHO "$1" | $SED -e "s;--slave_port=;;"` ;;
unknown's avatar
unknown committed
162
    --manager-port=*) MYSQL_MANAGER_PORT=`$ECHO "$1" | $SED -e "s;--manager_port=;;"` ;;
unknown's avatar
unknown committed
163 164
    --with-openssl)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
unknown's avatar
unknown committed
165 166 167
     --ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/server-cert.pem \
     --ssl-key=$BASEDIR/SSL/server-key.pem"
unknown's avatar
unknown committed
168
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
unknown's avatar
unknown committed
169 170 171
     --ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/server-cert.pem \
     --ssl-key=$BASEDIR/SSL/server-key.pem" ;;
unknown's avatar
unknown committed
172
    --no-manager | --skip-manager) USE_MANAGER=0 ;;
173 174 175 176
    --manager)
     USE_MANAGER=1
     USE_RUNNING_SERVER=
     ;;
177 178 179
    --start-and-exit)
     START_AND_EXIT=1
     ;; 
180 181 182 183 184 185
    --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" ;;
186
    --skip-rpl) NO_SLAVE=1 ;;
unknown's avatar
unknown committed
187
    --skip-test=*) SKIP_TEST=`$ECHO "$1" | $SED -e "s;--skip-test=;;"`;;
188
    --do-test=*) DO_TEST=`$ECHO "$1" | $SED -e "s;--do-test=;;"`;;
unknown's avatar
unknown committed
189 190 191
    --wait-timeout=*)
     START_WAIT_TIMEOUT=`$ECHO "$1" | $SED -e "s;--wait-timeout=;;"`
     STOP_WAIT_TIMEOUT=$START_WAIT_TIMEOUT;;
192 193 194
    --record)
      RECORD=1;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
unknown's avatar
unknown committed
195 196 197 198
    --bench)
      DO_BENCH=1
      NO_SLAVE=1
      ;;  
199 200
    --big*)			# Actually --big-test
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
unknown's avatar
unknown committed
201 202
    --compress)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
203 204 205 206
    --sleep=*)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1"
      SLEEP_TIME=`$ECHO "$1" | $SED -e "s;--sleep=;;"`
      ;;
207
    --mysqld=*)
unknown's avatar
unknown committed
208
       TMP=`$ECHO "$1" | $SED -e "s;--mysqld=;;"`
unknown's avatar
unknown committed
209
       EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $TMP"
210
       EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $TMP"
211
       ;;
212 213 214 215 216 217 218
    --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
      ;;
unknown's avatar
unknown committed
219 220 221
    --gprof )
      DO_GPROF=1
      ;;  
222
    --gdb )
unknown's avatar
unknown committed
223 224
      START_WAIT_TIMEOUT=300
      STOP_WAIT_TIMEOUT=300
225
      if [ x$BINARY_DIST = x1 ] ; then
226
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --gdb option"
227 228
      fi
      DO_GDB=1
229
      USE_RUNNING_SERVER=""
230
      ;;
231 232 233 234 235 236
    --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
      ;;
237 238
    --ddd )
      if [ x$BINARY_DIST = x1 ] ; then
239
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --ddd option"
240 241
      fi
      DO_DDD=1
242
      USE_RUNNING_SERVER=""
243
      ;;
244 245 246 247
    --skip-*)
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $1"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $1"
      ;;
unknown's avatar
unknown committed
248 249 250
    --strace-client )
      STRACE_CLIENT=1
      ;;        
251
    --debug)
252
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
253
       --debug=d:t:i:O,$MYSQL_TEST_DIR/var/log/master.trace"
254
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
255
       --debug=d:t:i:O,$MYSQL_TEST_DIR/var/log/slave.trace"
256
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --debug"
257 258 259 260 261 262 263
      ;;
    -- )  shift; break ;;
    --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
    * ) break ;;
  esac
  shift
done
unknown's avatar
fixed  
unknown committed
264

unknown's avatar
unknown committed
265 266 267
#++
# mysqld Environment Parameters
#--
268

unknown's avatar
unknown committed
269
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
270 271
MANAGER_PID_FILE="$MYRUN_DIR/manager.pid"

272
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
unknown's avatar
unknown committed
273
MASTER_MYSOCK="$MYSQL_TMP_DIR/master.sock"
unknown's avatar
unknown committed
274
MASTER_MYPID="$MYRUN_DIR/mysqld.pid"
275 276 277 278
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"
unknown's avatar
unknown committed
279
SLAVE_MYSOCK="$MYSQL_TMP_DIR/slave.sock"
unknown's avatar
unknown committed
280
SLAVE_MYPID="$MYRUN_DIR/mysqld-slave.pid"
281 282 283
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/mysqld-slave.log"
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/mysqld-slave.err"

284 285
SMALL_SERVER="-O key_buffer_size=1M -O sort_buffer=256K -O max_heap_table_size=1M"

unknown's avatar
unknown committed
286 287 288
export MASTER_MYPORT
export SLAVE_MYPORT

289 290 291 292 293
if [ x$SOURCE_DIST = x1 ] ; then
 MY_BASEDIR=$MYSQL_TEST_DIR
else
 MY_BASEDIR=$BASEDIR
fi  
unknown's avatar
unknown committed
294

unknown's avatar
unknown committed
295 296 297 298 299 300 301 302 303
# 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

304 305
[ -z "$COLUMNS" ] && COLUMNS=80
E=`$EXPR $COLUMNS - 8`
306
DASH72=`$ECHO '------------------------------------------------------------------------'|$CUT -c 1-$E`
307

308 309 310 311
# 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"
312
 if [ -f "$BASEDIR/client/.libs/lt-mysqltest" ] ; then
313
   MYSQL_TEST="$BASEDIR/client/.libs/lt-mysqltest"
unknown's avatar
unknown committed
314 315
 elif [ -f "$BASEDIR/client/.libs/mysqltest" ] ; then
   MYSQL_TEST="$BASEDIR/client/.libs/mysqltest"
316 317 318
 else
   MYSQL_TEST="$BASEDIR/client/mysqltest"
 fi
unknown's avatar
unknown committed
319 320 321 322
 if [ -n "$STRACE_CLIENT" ]; then
  MYSQL_TEST="strace -o $MYSQL_TEST_DIR/var/log/mysqltest.strace $MYSQL_TEST"
 fi
 
323
 MYSQLADMIN="$BASEDIR/client/mysqladmin"
unknown's avatar
unknown committed
324 325 326
 MYSQL_MANAGER_CLIENT="$BASEDIR/client/mysqlmanagerc"
 MYSQL_MANAGER="$BASEDIR/tools/mysqlmanager"
 MYSQL_MANAGER_PWGEN="$BASEDIR/client/mysqlmanager-pwgen"
unknown's avatar
unknown committed
327
 MYSQL="$BASEDIR/client/mysql"
328
 LANGUAGE="$BASEDIR/sql/share/english/"
329
 CHARSETSDIR="$BASEDIR/sql/share/charsets"
330 331 332 333 334
 INSTALL_DB="./install_test_db"
else
 MYSQLD="$BASEDIR/bin/mysqld"
 MYSQL_TEST="$BASEDIR/bin/mysqltest"
 MYSQLADMIN="$BASEDIR/bin/mysqladmin"
unknown's avatar
unknown committed
335 336 337
 MYSQL_MANAGER="$BASEDIR/bin/mysqlmanager"
 MYSQL_MANAGER_CLIENT="$BASEDIR/bin/mysqlmanagerc"
 MYSQL_MANAGER_PWGEN="$BASEDIR/bin/mysqlmanager-pwgen"
unknown's avatar
unknown committed
338
 MYSQL="$BASEDIR/bin/mysql"
unknown's avatar
unknown committed
339
 INSTALL_DB="./install_test_db -bin"
340 341 342
 if test -d "$BASEDIR/share/mysql/english" 
 then
   LANGUAGE="$BASEDIR/share/mysql/english/"
343
   CHARSETSDIR="$BASEDIR/share/mysql/charsets"
344 345
 else
   LANGUAGE="$BASEDIR/share/english/"
346
   CHARSETSDIR="$BASEDIR/share/charsets"
347
  fi
348 349
fi

350 351 352 353 354 355
# If we should run all tests cases, we will use a local server for that

if [ -z "$1" ]
then
   USE_RUNNING_SERVER=""
fi
356 357 358
if [ -n "$USE_RUNNING_SERVER" ]
then
   MASTER_MYSOCK="/tmp/mysql.sock"
359
   DBUSER=${DBUSER:-test}
360
else
361
   DBUSER=${DBUSER:-root}		# We want to do FLUSH xxx commands
362
fi
363 364 365 366 367 368 369 370

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

371

372 373 374
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
 --user=$DBUSER --password=$DBPASSWD --silent -v \
 --tmpdir=$MYSQL_TMP_DIR"
375 376 377
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
378 379 380
GDB_MASTER_INIT=$MYSQL_TMP_DIR/gdbinit.master
GDB_SLAVE_INIT=$MYSQL_TMP_DIR/gdbinit.slave
GCOV_MSG=$MYSQL_TMP_DIR/mysqld-gcov.out
unknown's avatar
unknown committed
381 382 383 384
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
385
TIMEFILE="$MYSQL_TEST_DIR/var/log/mysqltest-time"
386
SLAVE_MYSQLD=$MYSQLD #this can be changed later if we are doing gcov
unknown's avatar
unknown committed
387
XTERM=`which xterm`
388

unknown's avatar
unknown committed
389 390 391
#++
# Function Definitions
#--
unknown's avatar
unknown committed
392
wait_for_server_start ()
unknown's avatar
unknown committed
393
{
unknown's avatar
unknown committed
394
   $MYSQLADMIN --no-defaults -u $DBUSER --silent -O connect_timeout=10 -w2 --host=$hostname --port=$1  ping >/dev/null 2>&1
unknown's avatar
unknown committed
395
}
unknown's avatar
unknown committed
396

unknown's avatar
unknown committed
397 398
prompt_user ()
{
399
 $ECHO $1
400
 read unused
unknown's avatar
unknown committed
401 402
}

unknown's avatar
unknown committed
403
# We can't use diff -u or diff -a as these are not portable
404

unknown's avatar
unknown committed
405 406 407 408
show_failed_diff ()
{
  reject_file=r/$1.reject
  result_file=r/$1.result
409 410 411 412 413 414 415
  eval_file=r/$1.eval
  
  if [ -f $eval_file ]
  then
    result_file=$eval_file
  fi
    
unknown's avatar
unknown committed
416 417 418 419
  if [ -x "$DIFF" ] && [ -f $reject_file ]
  then
    echo "Below are the diffs between actual and expected results:"
    echo "-------------------------------------------------------"
unknown's avatar
unknown committed
420
    $DIFF -c $result_file $reject_file
unknown's avatar
unknown committed
421
    echo "-------------------------------------------------------"
422 423 424
    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."
unknown's avatar
unknown committed
425 426
  fi  
}
unknown's avatar
unknown committed
427

428 429 430 431 432 433
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
unknown's avatar
unknown committed
434
  $XTERM -title "Client" -e gdb -x $GDB_CLIENT_INIT $MYSQL_TEST_BIN
435 436
}

unknown's avatar
unknown committed
437
error () {
unknown's avatar
unknown committed
438
    $ECHO  "Error:  $1"
unknown's avatar
unknown committed
439 440 441
    exit 1
}

442
error_is () {
unknown's avatar
unknown committed
443
    $CAT < $TIMEFILE | $SED -e 's/.* At line \(.*\)\: \(.*\)/   \>\> Error at line \1: \2<\</' | $HEAD -1
444 445
}

unknown's avatar
unknown committed
446
prefix_to_8() {
447
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
unknown's avatar
unknown committed
448 449
}

unknown's avatar
unknown committed
450
pass_inc () {
unknown's avatar
unknown committed
451
    TOT_PASS=`$EXPR $TOT_PASS + 1`
unknown's avatar
unknown committed
452 453 454
}

fail_inc () {
unknown's avatar
unknown committed
455
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
unknown's avatar
unknown committed
456 457
}

458 459 460 461
skip_inc () {
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
}

unknown's avatar
unknown committed
462
total_inc () {
unknown's avatar
unknown committed
463
    TOT_TEST=`$EXPR $TOT_TEST + 1`
unknown's avatar
unknown committed
464 465 466
}

report_stats () {
467
    if [ $TOT_FAIL = 0 ]; then
unknown's avatar
unknown committed
468
	$ECHO "All $TOT_TEST tests were successful."
unknown's avatar
unknown committed
469
    else
unknown's avatar
unknown committed
470 471 472 473 474 475
	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`       
476
	$ECHO  "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% successful."
477 478 479 480 481
	$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"
unknown's avatar
unknown committed
482 483
    fi
}
484

unknown's avatar
unknown committed
485
mysql_install_db () {
486
    $ECHO "Removing Stale Files"
487 488
    $RM -rf $MASTER_MYDDIR $SLAVE_MYDDIR $SLAVE_MYLOG $MASTER_MYLOG \
     $SLAVE_MYERR $MASTER_MYERR
489
    $ECHO "Installing Master Databases"
490 491 492 493 494
    $INSTALL_DB
    if [ $? != 0 ]; then
	error "Could not install master test DBs"
	exit 1
    fi
495
    $ECHO "Installing Slave Databases"
496
    $INSTALL_DB -slave
497
    if [ $? != 0 ]; then
498
	error "Could not install slave test DBs"
499
	exit 1
unknown's avatar
unknown committed
500
    fi
501 502 503
    
    for slave_num in 1 2 ;
    do
504
     rm -rf var/slave$slave_num-data/
505 506 507 508
     mkdir -p var/slave$slave_num-data/mysql
     mkdir -p var/slave$slave_num-data/test
     cp var/slave-data/mysql/* var/slave$slave_num-data/mysql
    done
509 510
    # Give mysqld some time to die.
    sleep $SLEEP_TIME
unknown's avatar
unknown committed
511 512 513
    return 0
}

unknown's avatar
unknown committed
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
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
}

532
gcov_prepare () {
unknown's avatar
unknown committed
533 534
    $FIND $BASEDIR -name \*.gcov \
    -or -name \*.da | $XARGS $RM
unknown's avatar
unknown committed
535 536 537
}

gcov_collect () {
unknown's avatar
unknown committed
538
    $ECHO "Collecting source coverage info..."
unknown's avatar
unknown committed
539 540
    [ -f $GCOV_MSG ] && $RM $GCOV_MSG
    [ -f $GCOV_ERR ] && $RM $GCOV_ERR
unknown's avatar
unknown committed
541 542 543
    for d in $MYSQLD_SRC_DIRS; do
	cd $BASEDIR/$d
	for f in *.h *.cc *.c; do
unknown's avatar
unknown committed
544
	    $GCOV $f 2>>$GCOV_ERR  >>$GCOV_MSG
unknown's avatar
unknown committed
545
	done
546
	cd $MYSQL_TEST_DIR
unknown's avatar
unknown committed
547 548
    done

unknown's avatar
unknown committed
549
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
unknown's avatar
unknown committed
550 551
}

unknown's avatar
unknown committed
552 553 554 555 556 557 558 559 560 561
abort_if_failed()
{
 if [ ! $? = 0 ] ; then
  echo $1
  exit 1
 fi 
}

start_manager()
{
unknown's avatar
unknown committed
562
 if [ $USE_MANAGER = 0 ] ; then
563
  echo "Manager disabled, skipping manager start."
564 565
  return
 fi
unknown's avatar
unknown committed
566
 $ECHO "Starting MySQL Manager"
567 568 569 570 571 572 573 574 575 576
 if [ -f "$MANAGER_PID_FILE" ] ; then
    kill `cat $MANAGER_PID_FILE`
    sleep 1
    if [ -f "$MANAGER_PID_FILE" ] ; then
     kill -9 `cat $MANAGER_PID_FILE`
     sleep 1
    fi
 fi

 rm -f $MANAGER_PID_FILE
unknown's avatar
unknown committed
577 578
 MYSQL_MANAGER_PW=`$MYSQL_MANAGER_PWGEN -u $MYSQL_MANAGER_USER \
 -o $MYSQL_MANAGER_PW_FILE`
unknown's avatar
unknown committed
579
 $MYSQL_MANAGER --log=$MYSQL_MANAGER_LOG --port=$MYSQL_MANAGER_PORT \
580
  --password-file=$MYSQL_MANAGER_PW_FILE --pid-file=$MANAGER_PID_FILE
unknown's avatar
unknown committed
581
  abort_if_failed "Could not start MySQL manager"
582 583
  mysqltest_manager_args="--manager-host=localhost \
  --manager-user=$MYSQL_MANAGER_USER \
584 585 586 587 588
  --manager-password=$MYSQL_MANAGER_PW \
  --manager-port=$MYSQL_MANAGER_PORT \
  --manager-wait-timeout=$START_WAIT_TIMEOUT"
  MYSQL_TEST="$MYSQL_TEST $mysqltest_manager_args"
  MYSQL_TEST_ARGS="$MYSQL_TEST_ARGS $mysqltest_manager_args"
589 590 591 592
  while [ ! -f $MANAGER_PID_FILE ] ; do
   sleep 1
  done
  echo "Manager started"
unknown's avatar
unknown committed
593 594
}

unknown's avatar
unknown committed
595 596
stop_manager()
{
unknown's avatar
unknown committed
597
 if [ $USE_MANAGER = 0 ] ; then
598 599
  return
 fi
unknown's avatar
unknown committed
600 601 602 603
 $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT -u$MYSQL_MANAGER_USER \
  -p$MYSQL_MANAGER_PW -P $MYSQL_MANAGER_PORT <<EOF
shutdown
EOF
604 605
 echo "Manager terminated"

unknown's avatar
unknown committed
606 607 608
}

manager_launch()
unknown's avatar
unknown committed
609
{
unknown's avatar
unknown committed
610 611
  ident=$1
  shift
unknown's avatar
unknown committed
612
  if [ $USE_MANAGER = 0 ] ; then
613 614 615 616
   $@  >$CUR_MYERR 2>&1  &
   sleep 2 #hack 
   return
  fi
unknown's avatar
unknown committed
617
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
unknown's avatar
unknown committed
618
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
unknown's avatar
unknown committed
619 620 621 622 623
def_exec $ident $@
set_exec_stdout $ident $CUR_MYERR
set_exec_stderr $ident $CUR_MYERR
set_exec_con $ident root localhost $CUR_MYSOCK
start_exec $ident $START_WAIT_TIMEOUT
unknown's avatar
unknown committed
624 625 626
EOF
 abort_if_failed "Could not execute manager command"
}
unknown's avatar
unknown committed
627

unknown's avatar
unknown committed
628 629 630 631
manager_term()
{
  ident=$1
  shift
unknown's avatar
unknown committed
632
  if [ $USE_MANAGER = 0 ] ; then
633
   $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock -O \
634
   connect_timeout=5 -O shutdown_timeout=20 shutdown >/dev/null 2>&1
635 636
   return
  fi
unknown's avatar
unknown committed
637 638
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
639
stop_exec $ident $STOP_WAIT_TIMEOUT
unknown's avatar
unknown committed
640 641 642 643 644
EOF
 abort_if_failed "Could not execute manager command"
}


unknown's avatar
unknown committed
645 646
start_master()
{
647 648 649
    if [ x$MASTER_RUNNING = x1 ] || [ x$LOCAL_MASTER = x1 ] ; then
      return
    fi
650 651 652 653
    # Remove old berkeley db log files that can confuse the server
    $RM -f $MASTER_MYDDIR/log.*
    # Remove stale binary logs
    $RM -f $MYSQL_TEST_DIR/var/log/master-bin.*
654 655 656 657 658
    #run master initialization shell script if one exists
    if [ -f "$master_init_script" ] ;
    then
        /bin/sh $master_init_script
    fi
unknown's avatar
unknown committed
659
    cd $BASEDIR # for gcov
660
    #start master
unknown's avatar
unknown committed
661 662
    if [ -z "$DO_BENCH" ]
    then
663
      master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin \
664
    	    --server-id=1 --rpl-recovery-rank=1 \
665
            --basedir=$MY_BASEDIR --init-rpl-role=master \
666
	    --port=$MASTER_MYPORT \
667
	    --exit-info=256 \
unknown's avatar
unknown committed
668
	    --core \
669 670 671
            --datadir=$MASTER_MYDDIR \
	    --pid-file=$MASTER_MYPID \
	    --socket=$MASTER_MYSOCK \
672 673 674
            --log=$MASTER_MYLOG \
	    --character-sets-dir=$CHARSETSDIR \
	    --default-character-set=$CHARACTER_SET \
675
	    --tmpdir=$MYSQL_TMP_DIR \
676
	    --language=$LANGUAGE \
unknown's avatar
unknown committed
677
            --innodb_data_file_path=ibdata1:50M \
678 679
	     $SMALL_SERVER \
	     $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT"
unknown's avatar
unknown committed
680
    else
681
      master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin \
682
	    --server-id=1 --rpl-recovery-rank=1 \
683
            --basedir=$MY_BASEDIR --init-rpl-role=master \
unknown's avatar
unknown committed
684 685 686 687
	    --port=$MASTER_MYPORT \
            --datadir=$MASTER_MYDDIR \
	    --pid-file=$MASTER_MYPID \
	    --socket=$MASTER_MYSOCK \
688 689
	    --character-sets-dir=$CHARSETSDIR \
            --default-character-set=$CHARACTER_SET \
unknown's avatar
unknown committed
690 691
	    --core \
	    --tmpdir=$MYSQL_TMP_DIR \
692
	    --language=$LANGUAGE \
unknown's avatar
unknown committed
693
            --innodb_data_file_path=ibdata1:50M \
unknown's avatar
unknown committed
694 695
	     $SMALL_SERVER \
	     $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT"
unknown's avatar
unknown committed
696 697 698 699 700
    fi
    
    CUR_MYERR=$MASTER_MYERR
    CUR_MYSOCK=$MASTER_MYSOCK
    
unknown's avatar
unknown committed
701 702 703
    if [ x$DO_DDD = x1 ]
    then
      $ECHO "set args $master_args" > $GDB_MASTER_INIT
unknown's avatar
unknown committed
704 705
      manager_launch master ddd -display $DISPLAY --debugger \
      "gdb -x $GDB_MASTER_INIT" $MYSQLD 
unknown's avatar
unknown committed
706
    elif [ x$DO_GDB = x1 ]
unknown's avatar
unknown committed
707
    then
unknown's avatar
unknown committed
708
      ( echo set args $master_args;
709
        if [ $USE_MANAGER = 0 ] ; then
unknown's avatar
unknown committed
710
	 cat <<EOF
unknown's avatar
unknown committed
711 712
b mysql_parse
commands 1
713
disa 1
unknown's avatar
unknown committed
714
end
unknown's avatar
unknown committed
715 716 717
r
EOF
      fi )  > $GDB_MASTER_INIT     
718 719
      manager_launch master $XTERM -display $DISPLAY \
      -title "Master" -e gdb -x $GDB_MASTER_INIT $MYSQLD 
unknown's avatar
unknown committed
720
    else	    
unknown's avatar
unknown committed
721
      manager_launch master $MYSQLD $master_args  
unknown's avatar
unknown committed
722 723 724 725 726 727
    fi  
  MASTER_RUNNING=1
}

start_slave()
{
unknown's avatar
unknown committed
728
    [ x$SKIP_SLAVE = x1 ] && return
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
    eval "this_slave_running=\$SLAVE$1_RUNNING"
    [ x$this_slave_running = 1 ] && return
    #when testing fail-safe replication, we will have more than one slave
    #in this case, we start secondary slaves with an argument
    slave_ident="slave$1"
    if [ -n "$1" ] ;
    then
     slave_server_id=`$EXPR 2 + $1`
     slave_rpl_rank=$slave_server_id
     slave_port=`expr $SLAVE_MYPORT + $1`
     slave_log="$SLAVE_MYLOG.$1"
     slave_err="$SLAVE_MYERR.$1"
     slave_datadir="var/$slave_ident-data/"
     slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
     slave_sock="$SLAVE_MYSOCK-$1"
    else
     slave_server_id=2
     slave_rpl_rank=2
     slave_port=$SLAVE_MYPORT 
     slave_log=$SLAVE_MYLOG
     slave_err=$SLAVE_MYERR
     slave_datadir=$SLAVE_MYDDIR
     slave_pid=$SLAVE_MYPID
     slave_sock="$SLAVE_MYSOCK"
   fi 
754
    # Remove stale binary logs
755
    $RM -f $MYSQL_TEST_DIR/var/log/$slave_ident-bin.*
756
    
757 758 759 760 761 762
    #run slave initialization shell script if one exists
    if [ -f "$slave_init_script" ] ;
    then
	  /bin/sh $slave_init_script
    fi
    
763
    if [ -z "$SLAVE_MASTER_INFO" ] ; then
unknown's avatar
fixed  
unknown committed
764
      master_info="--master-user=root \
unknown's avatar
unknown committed
765
	    --master-connect-retry=1 \
766
	    --master-host=127.0.0.1 \
unknown's avatar
unknown committed
767
	    --master-password= \
768
	    --master-port=$MASTER_MYPORT \
769
	    --server-id=$slave_server_id --rpl-recovery-rank=$slave_rpl_rank"
unknown's avatar
fixed  
unknown committed
770 771 772 773
   else
     master_info=$SLAVE_MASTER_INFO
   fi	    
    
774
    $RM -f $slave_datadir/log.*	
unknown's avatar
fixed  
unknown committed
775 776
    slave_args="--no-defaults $master_info \
    	    --exit-info=256 \
777
	    --log-bin=$MYSQL_TEST_DIR/var/log/$slave_ident-bin \
778
	    --log-slave-updates \
779
            --log=$slave_log \
780
            --basedir=$MY_BASEDIR \
781 782 783 784
            --datadir=$slave_datadir \
	    --pid-file=$slave_pid \
	    --port=$slave_port \
	    --socket=$slave_sock \
785 786
	    --character-sets-dir=$CHARSETSDIR \
	    --default-character-set=$CHARACTER_SET \
787
	    --core --init-rpl-role=slave \
788
	    --tmpdir=$MYSQL_TMP_DIR \
789
            --language=$LANGUAGE \
790
	    --skip-innodb --skip-slave-start \
unknown's avatar
unknown committed
791
	    --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
792
	    --report-host=127.0.0.1 --report-user=root \
793
	    --report-port=$slave_port \
794
	    --master-retry-count=5 \
795 796
	     $SMALL_SERVER \
             $EXTRA_SLAVE_OPT $EXTRA_SLAVE_MYSQLD_OPT"
797 798
    CUR_MYERR=$slave_err
    CUR_MYSOCK=$slave_sock
unknown's avatar
unknown committed
799
  
unknown's avatar
unknown committed
800 801 802
    if [ x$DO_DDD = x1 ]
    then
      $ECHO "set args $master_args" > $GDB_SLAVE_INIT
803
      manager_launch $slave_ident ddd -display $DISPLAY --debugger \
unknown's avatar
unknown committed
804
       "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD 
unknown's avatar
unknown committed
805
    elif [ x$DO_GDB = x1 ]
unknown's avatar
unknown committed
806
    then
807
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
unknown's avatar
unknown committed
808 809
      manager_launch $slave_ident $XTERM -display $DISPLAY -title "Slave" -e \
      gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD 
unknown's avatar
unknown committed
810
    else
811
      manager_launch $slave_ident $SLAVE_MYSQLD $slave_args
unknown's avatar
unknown committed
812
    fi
813
    eval "SLAVE$1_RUNNING=1"
unknown's avatar
unknown committed
814 815 816
}

mysql_start () {
817
    $ECHO "Starting MySQL daemon"
unknown's avatar
unknown committed
818 819
    start_master
    start_slave
820
    cd $MYSQL_TEST_DIR
unknown's avatar
unknown committed
821 822 823
    return 1
}

unknown's avatar
unknown committed
824 825
stop_slave ()
{
826 827 828
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ -n "$1" ] ;
unknown's avatar
unknown committed
829
  then
830 831 832 833 834 835 836 837
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
  else
   slave_pid=$SLAVE_MYPID
  fi 
  if [ x$this_slave_running = x1 ]
  then
    manager_term $slave_ident
    if [ $? != 0 ] && [ -f $slave_pid ]
838
    then # try harder!
839
     $ECHO "slave not cooperating with mysqladmin, will try manual kill"
840
     kill `$CAT $slave_pid`
841
     sleep $SLEEP_TIME
unknown's avatar
unknown committed
842
     if [ -f $SLAVE_MYPID ] ; then
unknown's avatar
unknown committed
843
       $ECHO "slave refused to die. Sending SIGKILL"
844 845
       kill -9 `$CAT $slave_pid`
       $RM -f $slave_pid
unknown's avatar
unknown committed
846
     else
847
      $ECHO "slave responded to SIGTERM " 
unknown's avatar
unknown committed
848 849
     fi
    fi
850
    eval "SLAVE$1_RUNNING=0"
unknown's avatar
unknown committed
851 852
  fi  
}
unknown's avatar
unknown committed
853

unknown's avatar
unknown committed
854 855 856 857
stop_master ()
{
  if [ x$MASTER_RUNNING = x1 ]
  then
unknown's avatar
unknown committed
858
    manager_term master
859 860
    if [ $? != 0 ] && [ -f $MASTER_MYPID ]
    then # try harder!
861
     $ECHO "master not cooperating with mysqladmin, will try manual kill"
862
     kill `$CAT $MASTER_MYPID`
863
     sleep $SLEEP_TIME
unknown's avatar
unknown committed
864
     if [ -f $MASTER_MYPID ] ; then
unknown's avatar
unknown committed
865
       $ECHO "master refused to die. Sending SIGKILL"
866
       kill -9 `$CAT $MASTER_MYPID`
867
       $RM -f $MASTER_MYPID
unknown's avatar
unknown committed
868
     else
869
      $ECHO "master responded to SIGTERM " 
unknown's avatar
unknown committed
870 871
     fi
    fi
unknown's avatar
unknown committed
872 873 874
    MASTER_RUNNING=0
  fi
}
unknown's avatar
unknown committed
875

unknown's avatar
unknown committed
876 877
mysql_stop ()
{
878 879
 $ECHO  "Ending Tests"
 $ECHO  "Shutting-down MySQL daemon"
880
 $ECHO  ""
unknown's avatar
unknown committed
881
 stop_master
unknown's avatar
unknown committed
882
 $ECHO "Master shutdown finished"
unknown's avatar
unknown committed
883
 stop_slave
884 885
 stop_slave 1
 stop_slave 2
unknown's avatar
unknown committed
886 887
 $ECHO "Slave shutdown finished"
 
unknown's avatar
unknown committed
888
 return 1
unknown's avatar
unknown committed
889 890 891 892 893 894 895 896 897 898 899
}

mysql_restart () {

    mysql_stop
    mysql_start

    return 1
}

mysql_loadstd () {
900
    
unknown's avatar
unknown committed
901
    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test  
unknown's avatar
unknown committed
902 903 904
    return 1
}

unknown's avatar
unknown committed
905 906 907
run_testcase ()
{
 tf=$1
unknown's avatar
unknown committed
908
 tname=`$BASENAME $tf .test`
unknown's avatar
unknown committed
909 910
 master_opt_file=$TESTDIR/$tname-master.opt
 slave_opt_file=$TESTDIR/$tname-slave.opt
911 912
 master_init_script=$TESTDIR/$tname-master.sh
 slave_init_script=$TESTDIR/$tname-slave.sh
unknown's avatar
fixed  
unknown committed
913
 slave_master_info_file=$TESTDIR/$tname-slave-master-info.opt
unknown's avatar
unknown committed
914
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`
unknown's avatar
unknown committed
915
 if [ $USE_MANAGER = 1 ] ; then
916 917 918
  many_slaves=`$EXPR \( $tname : rpl_failsafe \) != 0`
 fi 
 
919
 if [ -n "$SKIP_TEST" ] ; then 
unknown's avatar
unknown committed
920
   SKIP_THIS_TEST=`$EXPR \( $tname : "$SKIP_TEST" \) != 0`
unknown's avatar
unknown committed
921 922 923 924 925
   if [ x$SKIP_THIS_TEST = x1 ] ;
   then
    return;
   fi
  fi
926

927 928 929 930 931 932 933 934 935
 if [ -n "$DO_TEST" ] ; then 
   DO_THIS_TEST=`$EXPR \( $tname : "$DO_TEST" \) != 0`
   if [ x$DO_THIS_TEST = x0 ] ;
   then
    return;
   fi
  fi


936 937 938 939 940 941
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ;
 then
   USERT="    ...."
   SYST="    ...."
   REALT="    ...."
   timestr="$USERT $SYST $REALT"
942 943
   pname=`$ECHO "$tname                        "|$CUT -c 1-24`
   RES="$pname  $timestr"
944
   skip_inc
945 946 947 948
   $ECHO "$RES$RES_SPACE [ skipped ]"
   return
 fi

949
 if [ -z "$USE_RUNNING_SERVER" ] ;
unknown's avatar
unknown committed
950
 then
951 952 953 954 955 956 957 958 959 960 961 962 963 964
   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
unknown's avatar
fixed  
unknown committed
965
 
966 967 968 969 970 971 972 973 974 975 976
   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
unknown's avatar
fixed  
unknown committed
977

978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
   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
993 994 995 996
   if [ x$many_slaves = x1 ]; then
    start_slave 1
    start_slave 2
   fi
unknown's avatar
fixed  
unknown committed
997
 fi
998
 cd $MYSQL_TEST_DIR
unknown's avatar
unknown committed
999
   
unknown's avatar
unknown committed
1000
 if [ -f $tf ] ; then
unknown's avatar
unknown committed
1001
    $RM -f r/$tname.*reject
1002
    mysql_test_args="-R r/$tname.result $EXTRA_MYSQL_TEST_OPT"
1003 1004
    if [ -z "$DO_CLIENT_GDB" ] ; then
      mytime=`$TIME -p $MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`
1005
    else
1006
      do_gdb_test "$mysql_test_args" "$tf"
1007 1008
    fi
     
unknown's avatar
unknown committed
1009 1010
    res=$?

unknown's avatar
unknown committed
1011
    if [ $res = 0 ]; then
1012
	mytime=`$CAT $TIMEFILE | $TAIL -3 | $TR '\n' ':'`
1013

1014
	USERT=`$ECHO $mytime | $CUT -d : -f 2 | $CUT -d ' ' -f 2`
unknown's avatar
unknown committed
1015
        USERT=`prefix_to_8 $USERT`
1016
	SYST=`$ECHO $mytime | $CUT -d : -f 3 | $CUT -d ' ' -f 2`
unknown's avatar
unknown committed
1017
        SYST=`prefix_to_8 $SYST`
1018
	REALT=`$ECHO $mytime | $CUT -d : -f 1 | $CUT -d ' ' -f 2`
unknown's avatar
unknown committed
1019
        REALT=`prefix_to_8 $REALT`
1020
    else
unknown's avatar
unknown committed
1021 1022 1023
	USERT="    ...."
	SYST="    ...."
	REALT="    ...."
1024 1025
    fi

1026
    timestr="$USERT $SYST $REALT"
1027 1028
    pname=`$ECHO "$tname                        "|$CUT -c 1-24`
    RES="$pname  $timestr"
1029 1030 1031 1032 1033 1034
    
    if [ x$many_slaves = x1 ] ; then
     stop_slave 1
     stop_slave 2
    fi
    
unknown's avatar
unknown committed
1035
    if [ $res = 0 ]; then
1036 1037
      total_inc
      pass_inc
1038
      $ECHO "$RES$RES_SPACE [ pass ]"
1039
    else
1040
      # why the following ``if'' ? That is why res==1 is special ?
1041 1042 1043 1044
      if [ $res = 2 ]; then
        skip_inc
	$ECHO "$RES$RES_SPACE [ skipped ]"
      else
1045
	total_inc
unknown's avatar
unknown committed
1046
        fail_inc
1047
	$ECHO "$RES$RES_SPACE [ fail ]"
1048 1049
        $ECHO
	error_is
unknown's avatar
unknown committed
1050
	show_failed_diff $tname
unknown's avatar
unknown committed
1051
	$ECHO
1052
	if [ x$FORCE != x1 ] ; then
1053 1054
	 $ECHO "Aborting. To continue, re-run with '--force'."
	 $ECHO
unknown's avatar
unknown committed
1055 1056 1057
         if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	 then
	   mysql_stop
unknown's avatar
unknown committed
1058
	   stop_manager
unknown's avatar
unknown committed
1059
   	 fi
1060 1061 1062
	 exit 1
	fi
	 
unknown's avatar
unknown committed
1063 1064 1065 1066
        if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	then
	  mysql_restart
	fi
1067
	$ECHO "Resuming Tests"
1068
	$ECHO ""
1069
      fi
unknown's avatar
unknown committed
1070
    fi
1071
  fi
unknown's avatar
unknown committed
1072 1073 1074
}


unknown's avatar
unknown committed
1075 1076 1077 1078
######################################################################
# Main script starts here
######################################################################

unknown's avatar
unknown committed
1079 1080 1081
[ "$DO_GCOV" -a ! -x "$GCOV" ] && error "No gcov found"

[ "$DO_GCOV" ] && gcov_prepare 
unknown's avatar
unknown committed
1082
[ "$DO_GPROF" ] && gprof_prepare 
unknown's avatar
unknown committed
1083

unknown's avatar
unknown committed
1084
# Ensure that no old mysqld test servers are running
1085 1086
if [ -z "$USE_RUNNING_SERVER" ]
then
1087 1088
  $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
  $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
1089 1090
  $ECHO "Installing Test Databases"
  mysql_install_db
unknown's avatar
unknown committed
1091
  start_manager
unknown's avatar
unknown committed
1092 1093
#do not automagically start deamons if we are in gdb or running only one test
#case
1094 1095 1096 1097 1098 1099
  if [ -z "$DO_GDB" ] && [ -z "$DO_DDD" ]
  then
    mysql_start
  fi
  $ECHO  "Loading Standard Test Databases"
  mysql_loadstd
unknown's avatar
unknown committed
1100 1101
fi

1102 1103 1104 1105
if [ "x$START_AND_EXIT" = "x1" ] ; then
 echo "Servers started, exiting"
 exit
fi
unknown's avatar
unknown committed
1106

1107
$ECHO  "Starting Tests"
unknown's avatar
unknown committed
1108

unknown's avatar
unknown committed
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
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
unknown's avatar
unknown committed
1127
 stop_manager
unknown's avatar
unknown committed
1128 1129 1130
 exit
fi

unknown's avatar
unknown committed
1131
$ECHO
unknown's avatar
unknown committed
1132
$ECHO " TEST                         USER   SYSTEM  ELAPSED        RESULT"
unknown's avatar
unknown committed
1133 1134
$ECHO $DASH72

unknown's avatar
unknown committed
1135
if [ -z "$1" ] ;
unknown's avatar
unknown committed
1136
then
1137
 if [ x$RECORD = x1 ]; then
1138
  $ECHO "Will not run in record mode without a specific test case."
1139 1140 1141 1142 1143
 else
  for tf in $TESTDIR/*.$TESTSUFFIX
  do
    run_testcase $tf
  done
1144
  $RM -f $TIMEFILE	# Remove for full test
1145
 fi
1146
else 
unknown's avatar
unknown committed
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
  while [ ! -z "$1" ]; do
    tname=`$BASENAME $1 .test`
    tf=$TESTDIR/$tname.$TESTSUFFIX
    if [ -f $tf ] ; then
      run_testcase $tf
    else
      $ECHO "Test case $tf does not exist."
    fi
    shift
  done
unknown's avatar
unknown committed
1157
fi
unknown's avatar
unknown committed
1158

unknown's avatar
unknown committed
1159 1160
$ECHO $DASH72
$ECHO
1161

1162
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
unknown's avatar
unknown committed
1163 1164 1165
then
    mysql_stop
fi
unknown's avatar
unknown committed
1166

unknown's avatar
unknown committed
1167
stop_manager
unknown's avatar
unknown committed
1168
report_stats
unknown's avatar
unknown committed
1169
$ECHO
unknown's avatar
unknown committed
1170

unknown's avatar
unknown committed
1171
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
unknown's avatar
unknown committed
1172
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
unknown's avatar
unknown committed
1173

unknown's avatar
unknown committed
1174
exit 0