mysql-test-run.sh 38 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=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
15
USE_MANAGER=0
16 17
MY_TZ=GMT-3
TZ=$MY_TZ; export TZ # for UNIX_TIMESTAMP tests to work
bk@work.mysql.com's avatar
bk@work.mysql.com committed
18

19 20 21
# For query_cache test
ulimit -n 1024

22 23 24 25
#++
# Program Definitions
#--

26 27
LC_COLLATE=C
export LC_COLLATE
28
PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11:$PATH
29
MASTER_40_ARGS="--rpl-recovery-rank=1 --init-rpl-role=master"
30

31 32 33 34
# Standard functions

which ()
{
35
  IFS="${IFS=   }"; save_ifs="$IFS"; IFS=':'
36 37
  for file
  do
38
    for dir in $PATH
39
    do
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
40
      if test -f $dir/$file
41 42 43 44 45
      then
        echo "$dir/$file"
        continue 2
      fi
    done
46
    echo "Fatal error: Cannot find program $file in $PATH" 1>&2
47 48
    exit 1
  done
49
  IFS="$save_ifs"
50
  exit 0
51 52 53
}


monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
54 55
sleep_until_file_deleted ()
{
56 57
  pid=$1;
  file=$2
58
  loop=$SLEEP_TIME_FOR_DELETE
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
59 60
  while (test $loop -gt 0)
  do
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
61
    if [ ! -r $file ]
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
62
    then
63 64 65 66
      if test $pid != "0"
      then
        wait_for_pid $pid
      fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
67 68
      return
    fi
69
    sleep 1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
70 71 72 73
    loop=`expr $loop - 1`
  done
}

74
sleep_until_file_created ()
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
75 76
{
  file=$1
77 78
  loop=$2
  org_time=$2
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
79 80
  while (test $loop -gt 0)
  do
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
81
    if [ -r $file ]
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
82
    then
83
      return 0
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
84
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
85
    sleep 1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
86 87
    loop=`expr $loop - 1`
  done
88
  echo "ERROR: $file was not created in $org_time seconds;  Aborting"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
89 90 91
  exit 1;
}

92 93 94 95 96
# For the future

wait_for_pid()
{
  pid=$1
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
97
  #$WAIT_PID pid $SLEEP_TIME_FOR_DELETE
98 99
}

100 101
# No paths below as we can't be sure where the program is!

102 103
SED=sed

104 105
BASENAME=`which basename`
if test $? != 0; then exit 1; fi
106
DIFF=`which diff | $SED q`
107
if test $? != 0; then exit 1; fi
108 109
CAT=cat
CUT=cut
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
110
HEAD=head
111 112 113 114
TAIL=tail
ECHO=echo # use internal echo if possible
EXPR=expr # use internal if possible
FIND=find
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
115
GREP=grep
116
if test $? != 0; then exit 1; fi
117 118
PRINTF=printf
RM=rm
119
if test $? != 0; then exit 1; fi
120
TR=tr
121 122
XARGS=`which xargs`
if test $? != 0; then exit 1; fi
123
SORT=sort
124 125 126 127 128

# Are we using a source or a binary distribution?

testdir=@testdir@
if [ -d bin/mysqld ] && [ -d mysql-test ] ; then
129 130
 cd mysql-test
else
131 132
 if [ -d $testdir/mysql-test ] ; then
   cd $testdir
133
 fi
134 135 136 137 138 139 140
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
141
  exit 1
142
fi
143

bk@work.mysql.com's avatar
bk@work.mysql.com committed
144 145 146
#++
# Misc. Definitions
#--
147

148 149 150 151 152
if [ -d ../sql ] ; then
   SOURCE_DIST=1
else
   BINARY_DIST=1
fi
153

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
154
#BASEDIR is always one above mysql-test directory
bk@work.mysql.com's avatar
bk@work.mysql.com committed
155 156 157 158
CWD=`pwd`
cd ..
BASEDIR=`pwd`
cd $CWD
159
MYSQL_TEST_DIR=$BASEDIR/mysql-test
160
export MYSQL_TEST_DIR
161
STD_DATA=$MYSQL_TEST_DIR/std_data
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
162
hostname=`hostname`		# Installed in the mysql privilege table
163

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
164
MANAGER_QUIET_OPT="-q"
165
TESTDIR="$MYSQL_TEST_DIR/t"
166
TESTSUFFIX=test
167
TOT_SKIP=0
bk@work.mysql.com's avatar
bk@work.mysql.com committed
168 169 170
TOT_PASS=0
TOT_FAIL=0
TOT_TEST=0
171 172 173
USERT=0
SYST=0
REALT=0
174
FAST_START=""
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
175
MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
176
SLAVE_LOAD_TMPDIR=../../var/tmp #needs to be same length to test logging
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
177
RES_SPACE="      "
178 179
MYSQLD_SRC_DIRS="strings mysys include extra regex isam merge myisam \
 myisammrg heap sql"
180
MY_LOG_DIR="$MYSQL_TEST_DIR/var/log" 
181 182 183
#
# Set LD_LIBRARY_PATH if we are using shared libraries
#
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
184
LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$LD_LIBRARY_PATH"
185
export LD_LIBRARY_PATH
186

sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
187
MASTER_RUNNING=0
188
MASTER_MYPORT=9306
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
189
SLAVE_RUNNING=0
190
SLAVE_MYPORT=9307
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
191 192 193 194
MYSQL_MANAGER_PORT=9305 # needs to be out of the way of slaves
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
195
NO_SLAVE=0
196
USER_TEST=
197

198
EXTRA_MASTER_OPT=""
199 200 201 202
EXTRA_MYSQL_TEST_OPT=""
USE_RUNNING_SERVER=1
DO_GCOV=""
DO_GDB=""
203
MANUAL_GDB=""
204
DO_DDD=""
205
DO_CLIENT_GDB=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
206
SLEEP_TIME_AFTER_RESTART=1
207
SLEEP_TIME_FOR_DELETE=10
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
208
SLEEP_TIME_FOR_FIRST_MASTER=400		# Enough time to create innodb tables
209
SLEEP_TIME_FOR_SECOND_MASTER=30
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
210
SLEEP_TIME_FOR_FIRST_SLAVE=400
211
SLEEP_TIME_FOR_SECOND_SLAVE=30
212
CHARACTER_SET=latin1
213
DBUSER=""
214 215
START_WAIT_TIMEOUT=10
STOP_WAIT_TIMEOUT=10
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
216
MYSQL_TEST_SSL_OPTS=""
217 218 219

while test $# -gt 0; do
  case "$1" in
220 221
    --user=*) DBUSER=`$ECHO "$1" | $SED -e "s;--user=;;"` ;;
    --force)  FORCE=1 ;;
222
    --verbose-manager)  MANAGER_QUIET_OPT="" ;;
223 224 225 226 227
    --old-master) MASTER_40_ARGS="";;
    --master-binary=*)
      MASTER_MYSQLD=`$ECHO "$1" | $SED -e "s;--master-binary=;;"` ;;
    --slave-binary=*)
      SLAVE_MYSQLD=`$ECHO "$1" | $SED -e "s;--slave-binary=;;"` ;;
228
    --local)   USE_RUNNING_SERVER="" ;;
229
    --extern)   USE_RUNNING_SERVER="1" ;;
230
    --tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;;
231 232 233 234 235
    --local-master)
      MASTER_MYPORT=3306;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --host=127.0.0.1 \
      --port=$MYSQL_MYPORT"
      LOCAL_MASTER=1 ;;
236 237
    --master_port=*) MASTER_MYPORT=`$ECHO "$1" | $SED -e "s;--master_port=;;"` ;;
    --slave_port=*) SLAVE_MYPORT=`$ECHO "$1" | $SED -e "s;--slave_port=;;"` ;;
238
    --manager-port=*) MYSQL_MANAGER_PORT=`$ECHO "$1" | $SED -e "s;--manager_port=;;"` ;;
239 240
    --with-openssl)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
241 242 243
     --ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/server-cert.pem \
     --ssl-key=$BASEDIR/SSL/server-key.pem"
244
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
245 246
     --ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/server-cert.pem \
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
247 248 249 250
     --ssl-key=$BASEDIR/SSL/server-key.pem"
     MYSQL_TEST_SSL_OPTS="--ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/client-cert.pem \
     --ssl-key=$BASEDIR/SSL/client-key.pem" ;;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
251
    --no-manager | --skip-manager) USE_MANAGER=0 ;;
252 253 254 255
    --manager)
     USE_MANAGER=1
     USE_RUNNING_SERVER=
     ;;
256 257
    --start-and-exit)
     START_AND_EXIT=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
258
     ;;
259
    --skip-rpl) NO_SLAVE=1 ;;
260
    --skip-test=*) SKIP_TEST=`$ECHO "$1" | $SED -e "s;--skip-test=;;"`;;
261
    --do-test=*) DO_TEST=`$ECHO "$1" | $SED -e "s;--do-test=;;"`;;
262 263 264 265
    --warnings | --log-warnings)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --log-warnings"
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --log-warnings"
     ;;
266 267 268
    --wait-timeout=*)
     START_WAIT_TIMEOUT=`$ECHO "$1" | $SED -e "s;--wait-timeout=;;"`
     STOP_WAIT_TIMEOUT=$START_WAIT_TIMEOUT;;
269 270 271
    --record)
      RECORD=1;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
272 273 274
    --bench)
      DO_BENCH=1
      NO_SLAVE=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
275
      ;;
276 277
    --big*)			# Actually --big-test
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
278 279
    --compress)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
280 281
    --sleep=*)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1"
282
      SLEEP_TIME_AFTER_RESTART=`$ECHO "$1" | $SED -e "s;--sleep=;;"`
283
      ;;
284 285 286
    --user-test=*)
      USER_TEST=`$ECHO "$1" | $SED -e "s;--user-test=;;"`
      ;;
287
    --mysqld=*)
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
288
       TMP=`$ECHO "$1" | $SED -e "s;--mysqld=;;"`
289
       EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $TMP"
290
       EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $TMP"
291
       ;;
292 293 294 295 296 297
    --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
298
      GCOV=`which gcov`
299
      ;;
300 301
    --gprof )
      DO_GPROF=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
302
      ;;
303
    --gdb )
304 305
      START_WAIT_TIMEOUT=300
      STOP_WAIT_TIMEOUT=300
306
      if [ x$BINARY_DIST = x1 ] ; then
307
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --gdb option"
308 309
      fi
      DO_GDB=1
310 311
      # This needs to be checked properly
      # USE_MANAGER=1
312
      USE_RUNNING_SERVER=""
313
      ;;
314 315 316 317 318
    --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
319 320
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
321
      ;;
322 323 324 325
    --manual-gdb )
      DO_GDB=1
      MANUAL_GDB=1
      USE_RUNNING_SERVER=""
326 327
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
328
      ;;
329 330
    --ddd )
      if [ x$BINARY_DIST = x1 ] ; then
331
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --ddd option"
332 333
      fi
      DO_DDD=1
334
      USE_RUNNING_SERVER=""
335 336
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
337
      ;;
338
    --valgrind)
guilhem@mysql.com's avatar
guilhem@mysql.com committed
339 340 341 342 343 344 345
      VALGRIND=`which valgrind` # this will print an error if not found
      # Give good warning to the user and stop
      if [ -z "$VALGRIND" ] ; then
        $ECHO "You need to have the 'valgrind' program in your PATH to run mysql-test-run with option --valgrind. Valgrind's home page is http://developer.kde.org/~sewardj ."
        exit 1
      fi
      VALGRIND="$VALGRIND --alignment=8 --leak-check=yes --num-callers=16"
346 347
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc --skip-bdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-safemalloc --skip-bdb"
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
348
      SLEEP_TIME_AFTER_RESTART=10
349
      SLEEP_TIME_FOR_DELETE=120
350
      USE_RUNNING_SERVER=""
351 352 353 354 355
      ;;
    --valgrind-options=*)
      TMP=`$ECHO "$1" | $SED -e "s;--valgrind-options=;;"`
      VALGRIND="$VALGRIND $TMP"
      ;;
356 357 358
    --valgrind-all)
      VALGRIND="$VALGRIND -v --show-reachable=yes"
      ;;
359 360 361 362
    --skip-*)
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $1"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $1"
      ;;
363 364
    --strace-client )
      STRACE_CLIENT=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
365
      ;;
366
    --debug)
367
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
368
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/master.trace"
369
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
370
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/slave.trace"
371 372
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqltest.trace"
373
      ;;
374 375 376
    --fast)
      FAST_START=1
      ;;
377 378 379 380 381 382
    -- )  shift; break ;;
    --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
    * ) break ;;
  esac
  shift
done
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
383

bk@work.mysql.com's avatar
bk@work.mysql.com committed
384 385 386
#++
# mysqld Environment Parameters
#--
387

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
388
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
389 390
MANAGER_PID_FILE="$MYRUN_DIR/manager.pid"

391
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
392
MASTER_MYSOCK="$MYSQL_TMP_DIR/master.sock"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
393 394 395
MASTER_MYPID="$MYRUN_DIR/master.pid"
MASTER_MYLOG="$MYSQL_TEST_DIR/var/log/master.log"
MASTER_MYERR="$MYSQL_TEST_DIR/var/log/master.err"
396 397

SLAVE_MYDDIR="$MYSQL_TEST_DIR/var/slave-data"
398
SLAVE_MYSOCK="$MYSQL_TMP_DIR/slave.sock"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
399 400 401
SLAVE_MYPID="$MYRUN_DIR/slave.pid"
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/slave.log"
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/slave.err"
402

403
CURRENT_TEST="$MYSQL_TEST_DIR/var/log/current_test"
404 405
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
406 407 408
export MASTER_MYPORT
export SLAVE_MYPORT

409 410 411 412
if [ x$SOURCE_DIST = x1 ] ; then
 MY_BASEDIR=$MYSQL_TEST_DIR
else
 MY_BASEDIR=$BASEDIR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
413
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
414

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
415 416 417 418 419 420 421 422
# 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
423
[ -d $MYSQL_TEST_DIR/var/log ] || mkdir $MYSQL_TEST_DIR/var/log
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
424

425
if test ${COLUMNS:-0} -lt 80 ; then COLUMNS=80 ; fi
426
E=`$EXPR $COLUMNS - 8`
427
DASH72=`$ECHO '------------------------------------------'|$CUT -c 1-$E`
428

429 430 431
# on source dist, we pick up freshly build executables
# on binary, use what is installed
if [ x$SOURCE_DIST = x1 ] ; then
432
 MYSQLD="$VALGRIND $BASEDIR/sql/mysqld"
433
 if [ -f "$BASEDIR/client/.libs/lt-mysqltest" ] ; then
434
   MYSQL_TEST="$BASEDIR/client/.libs/lt-mysqltest"
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
435 436
 elif [ -f "$BASEDIR/client/.libs/mysqltest" ] ; then
   MYSQL_TEST="$BASEDIR/client/.libs/mysqltest"
437 438 439
 else
   MYSQL_TEST="$BASEDIR/client/mysqltest"
 fi
440
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
441
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
442
 else
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
443
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
444
 fi
445
 if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
446
   MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog"
447
 else
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
448
   MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog"
449
 fi
450 451 452
 if [ -n "$STRACE_CLIENT" ]; then
  MYSQL_TEST="strace -o $MYSQL_TEST_DIR/var/log/mysqltest.strace $MYSQL_TEST"
 fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
453

454
 MYSQLADMIN="$BASEDIR/client/mysqladmin"
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
455
 WAIT_PID="$BASEDIR/extra/mysql_waitpid"
456 457 458
 MYSQL_MANAGER_CLIENT="$BASEDIR/client/mysqlmanagerc"
 MYSQL_MANAGER="$BASEDIR/tools/mysqlmanager"
 MYSQL_MANAGER_PWGEN="$BASEDIR/client/mysqlmanager-pwgen"
459
 MYSQL="$BASEDIR/client/mysql"
460
 LANGUAGE="$BASEDIR/sql/share/english/"
461
 CHARSETSDIR="$BASEDIR/sql/share/charsets"
462 463
 INSTALL_DB="./install_test_db"
else
464 465
 if test -x "$BASEDIR/libexec/mysqld"
 then
466
   MYSQLD="$VALGRIND $BASEDIR/libexec/mysqld"
467
 else
468
   MYSQLD="$VALGRIND $BASEDIR/bin/mysqld"
469
 fi
470
 MYSQL_TEST="$BASEDIR/bin/mysqltest"
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
471 472
 MYSQL_DUMP="$BASEDIR/bin/mysqldump"
 MYSQL_BINLOG="$BASEDIR/bin/mysqlbinlog"
473
 MYSQLADMIN="$BASEDIR/bin/mysqladmin"
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
474
 WAIT_PID="$BASEDIR/bin/mysql_waitpid"
475 476 477
 MYSQL_MANAGER="$BASEDIR/bin/mysqlmanager"
 MYSQL_MANAGER_CLIENT="$BASEDIR/bin/mysqlmanagerc"
 MYSQL_MANAGER_PWGEN="$BASEDIR/bin/mysqlmanager-pwgen"
478
 MYSQL="$BASEDIR/bin/mysql"
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
479
 INSTALL_DB="./install_test_db -bin"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
480
 if test -d "$BASEDIR/share/mysql/english"
481 482
 then
   LANGUAGE="$BASEDIR/share/mysql/english/"
483
   CHARSETSDIR="$BASEDIR/share/mysql/charsets"
484 485
 else
   LANGUAGE="$BASEDIR/share/english/"
486
   CHARSETSDIR="$BASEDIR/share/charsets"
487
  fi
488 489
fi

monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
490 491
MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK"
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR"
492
export MYSQL_DUMP
493
export MYSQL_BINLOG
494

495 496 497 498 499 500 501 502 503 504
if [ -z "$MASTER_MYSQLD" ]
then
MASTER_MYSQLD=$MYSQLD
fi

if [ -z "$SLAVE_MYSQLD" ]
then
SLAVE_MYSQLD=$MYSQLD
fi

505 506 507 508 509 510
# If we should run all tests cases, we will use a local server for that

if [ -z "$1" ]
then
   USE_RUNNING_SERVER=""
fi
511 512 513
if [ -n "$USE_RUNNING_SERVER" ]
then
   MASTER_MYSOCK="/tmp/mysql.sock"
514
   DBUSER=${DBUSER:-test}
515
else
516
   DBUSER=${DBUSER:-root}		# We want to do FLUSH xxx commands
517
fi
518 519 520 521 522 523 524 525

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

526

527
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
528
 --user=$DBUSER --password=$DBPASSWD --silent -v --skip-safemalloc \
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
529
 --tmpdir=$MYSQL_TMP_DIR --port=$MASTER_MYPORT $MYSQL_TEST_SSL_OPTS"
530 531 532
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
533 534 535
GDB_MASTER_INIT=$MYSQL_TMP_DIR/gdbinit.master
GDB_SLAVE_INIT=$MYSQL_TMP_DIR/gdbinit.slave
GCOV_MSG=$MYSQL_TMP_DIR/mysqld-gcov.out
536 537 538 539
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
540
TIMEFILE="$MYSQL_TEST_DIR/var/log/mysqltest-time"
541 542 543
if [ -n "$DO_CLIENT_GDB" -o -n "$DO_GDB" ] ; then
  XTERM=`which xterm`
fi
544

bk@work.mysql.com's avatar
bk@work.mysql.com committed
545 546 547 548
#++
# Function Definitions
#--

549 550
prompt_user ()
{
551
 $ECHO $1
552
 read unused
553 554
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
555
# We can't use diff -u or diff -a as these are not portable
556

557 558 559 560
show_failed_diff ()
{
  reject_file=r/$1.reject
  result_file=r/$1.result
561
  eval_file=r/$1.eval
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
562

563 564 565 566
  if [ -f $eval_file ]
  then
    result_file=$eval_file
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
567

568 569 570 571
  if [ -x "$DIFF" ] && [ -f $reject_file ]
  then
    echo "Below are the diffs between actual and expected results:"
    echo "-------------------------------------------------------"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
572
    $DIFF -c $result_file $reject_file
573
    echo "-------------------------------------------------------"
574 575 576
    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."
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
577
  fi
578
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
579

580 581 582 583 584 585
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
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
586
  $XTERM -title "Client" -e gdb -x $GDB_CLIENT_INIT $MYSQL_TEST_BIN
587 588
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
589
error () {
590
    $ECHO  "Error:  $1"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
591 592 593
    exit 1
}

594
error_is () {
595 596 597
    $ECHO "Errors are (from $TIMEFILE) :"
    $CAT < $TIMEFILE
    $ECHO "(the last line(s) may be the ones that caused the die() in mysqltest)"
598 599
}

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
600
prefix_to_8() {
601
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
602 603
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
604
pass_inc () {
605
    TOT_PASS=`$EXPR $TOT_PASS + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
606 607 608
}

fail_inc () {
609
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
610 611
}

612 613 614 615
skip_inc () {
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
616
total_inc () {
617
    TOT_TEST=`$EXPR $TOT_TEST + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
618 619
}

620 621 622 623 624 625

skip_test() {
   USERT="    ...."
   SYST="    ...."
   REALT="    ...."
   pname=`$ECHO "$1                        "|$CUT -c 1-24`
626
   RES="$pname"
627 628 629 630
   skip_inc
   $ECHO "$RES$RES_SPACE [ skipped ]"
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
631
report_stats () {
632
    if [ $TOT_FAIL = 0 ]; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
633
	$ECHO "All $TOT_TEST tests were successful."
bk@work.mysql.com's avatar
bk@work.mysql.com committed
634
    else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
635 636 637 638 639 640
	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`
641
	$ECHO  "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% successful."
642
	$ECHO ""
643
        $ECHO "The log files in $MY_LOG_DIR may give you some hint"
644 645 646
	$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
647
    fi
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
648

649 650 651
    if test -z "$USE_RUNNING_SERVER"
    then

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
    # Report if there was any fatal warnings/errors in the log files
    #
    $RM -f $MY_LOG_DIR/warnings $MY_LOG_DIR/warnings.tmp
    # Remove some non fatal warnings from the log files
    $SED -e 's!Warning:  Table:.* on delete!!g' \
         $MY_LOG_DIR/*.err > $MY_LOG_DIR/warnings.tmp

    found_error=0
    # Find errors
    for i in "^Warning:" "^Error:" "^==.* at 0x"
    do
      if `$GREP "$i" $MY_LOG_DIR/warnings.tmp >> $MY_LOG_DIR/warnings`
      then
        found_error=1
      fi
    done
    $RM -f $MY_LOG_DIR/warnings.tmp
    if [ $found_error = "1" ]
    then
      echo "WARNING: Got errors/warnings while running tests. Please examine"
      echo "$MY_LOG_DIR/warnings for details."
    fi
674
    fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
675
}
676

bk@work.mysql.com's avatar
bk@work.mysql.com committed
677
mysql_install_db () {
678
    $ECHO "Removing Stale Files"
679
    $RM -rf $MASTER_MYDDIR $SLAVE_MYDDIR $MY_LOG_DIR/* 
680
    $ECHO "Installing Master Databases"
681 682 683 684 685
    $INSTALL_DB
    if [ $? != 0 ]; then
	error "Could not install master test DBs"
	exit 1
    fi
686
    $ECHO "Installing Slave Databases"
687
    $INSTALL_DB -slave
688
    if [ $? != 0 ]; then
689
	error "Could not install slave test DBs"
690
	exit 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
691
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
692

693 694
    for slave_num in 1 2 ;
    do
695
      $RM -rf var/slave$slave_num-data
696 697 698
      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
699
    done
bk@work.mysql.com's avatar
bk@work.mysql.com committed
700 701 702
    return 0
}

703 704
gprof_prepare ()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
705 706
 $RM -rf $GPROF_DIR
 mkdir -p $GPROF_DIR
707 708 709 710 711
}

gprof_collect ()
{
 if [ -f $MASTER_MYDDIR/gmon.out ]; then
712
   gprof $MASTER_MYSQLD $MASTER_MYDDIR/gmon.out > $GPROF_MASTER
713 714 715
   echo "Master execution profile has been saved in $GPROF_MASTER"
 fi
 if [ -f $SLAVE_MYDDIR/gmon.out ]; then
716
   gprof $SLAVE_MYSQLD $SLAVE_MYDDIR/gmon.out > $GPROF_SLAVE
717 718 719 720
   echo "Slave execution profile has been saved in $GPROF_SLAVE"
 fi
}

721
gcov_prepare () {
722 723
    $FIND $BASEDIR -name \*.gcov \
    -or -name \*.da | $XARGS $RM
724 725 726
}

gcov_collect () {
727
    $ECHO "Collecting source coverage info..."
728 729
    [ -f $GCOV_MSG ] && $RM $GCOV_MSG
    [ -f $GCOV_ERR ] && $RM $GCOV_ERR
730 731 732
    for d in $MYSQLD_SRC_DIRS; do
	cd $BASEDIR/$d
	for f in *.h *.cc *.c; do
733
	    $GCOV $f 2>>$GCOV_ERR  >>$GCOV_MSG
734
	done
735
	cd $MYSQL_TEST_DIR
736 737
    done

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
738
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
739 740
}

741 742 743 744 745
abort_if_failed()
{
 if [ ! $? = 0 ] ; then
  echo $1
  exit 1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
746
 fi
747 748 749 750
}

start_manager()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
751
 if [ $USE_MANAGER = 0 ] ; then
752 753
   echo "Manager disabled, skipping manager start."
   $RM -f $MYSQL_MANAGER_LOG
754 755
  return
 fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
756
 $ECHO "Starting MySQL Manager"
757 758 759 760 761 762 763 764 765
 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

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
766
 $RM -f $MANAGER_PID_FILE
767 768
 MYSQL_MANAGER_PW=`$MYSQL_MANAGER_PWGEN -u $MYSQL_MANAGER_USER \
 -o $MYSQL_MANAGER_PW_FILE`
769
 $MYSQL_MANAGER --log=$MYSQL_MANAGER_LOG --port=$MYSQL_MANAGER_PORT \
770
  --password-file=$MYSQL_MANAGER_PW_FILE --pid-file=$MANAGER_PID_FILE
771
  abort_if_failed "Could not start MySQL manager"
772 773
  mysqltest_manager_args="--manager-host=localhost \
  --manager-user=$MYSQL_MANAGER_USER \
774 775 776 777 778
  --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"
779 780 781 782
  while [ ! -f $MANAGER_PID_FILE ] ; do
   sleep 1
  done
  echo "Manager started"
783 784
}

785 786
stop_manager()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
787
 if [ $USE_MANAGER = 0 ] ; then
788 789
  return
 fi
790 791 792 793
 $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT -u$MYSQL_MANAGER_USER \
  -p$MYSQL_MANAGER_PW -P $MYSQL_MANAGER_PORT <<EOF
shutdown
EOF
794 795
 echo "Manager terminated"

796 797 798
}

manager_launch()
799
{
800 801
  ident=$1
  shift
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
802
  if [ $USE_MANAGER = 0 ] ; then
803
    $@  >> $CUR_MYERR 2>&1  &
804 805
    sleep 2 #hack
    return
806
  fi
807
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
808
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
809 810 811 812 813
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
814
EOF
815
  abort_if_failed "Could not execute manager command"
816
}
817

818 819
manager_term()
{
820 821
  pid=$1
  ident=$2
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
822
  if [ $USE_MANAGER = 0 ] ; then
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
823 824
    # Shutdown time must be high as slave may be in reconnect
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock --connect_timeout=5 --shutdown_timeout=70 shutdown >> $MYSQL_MANAGER_LOG 2>&1
825 826 827 828 829 830 831 832
    res=$?
    # Some systems require an extra connect
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock --connect_timeout=1 ping >> $MYSQL_MANAGER_LOG 2>&1
    if test $res = 0
    then
      wait_for_pid $pid
    fi
    return $res
833
  fi
834 835
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
836
stop_exec $ident $STOP_WAIT_TIMEOUT
837 838 839 840 841
EOF
 abort_if_failed "Could not execute manager command"
}


842 843
start_master()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
844 845 846 847 848 849 850
  if [ x$MASTER_RUNNING = x1 ] || [ x$LOCAL_MASTER = x1 ] ; then
    return
  fi
  # 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.*
851 852
  # Remove old master.info and relay-log.info files
  $RM -f $MYSQL_TEST_DIR/var/master-data/master.info $MYSQL_TEST_DIR/var/master-data/relay-log.info
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
853 854 855 856 857 858 859 860 861 862 863

  #run master initialization shell script if one exists

  if [ -f "$master_init_script" ] ;
  then
      /bin/sh $master_init_script
  fi
  cd $BASEDIR # for gcov
  if [ -z "$DO_BENCH" ]
  then
    master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin \
864 865
  	    --server-id=1  \
          --basedir=$MY_BASEDIR \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
866
          --port=$MASTER_MYPORT \
867
          --local-infile \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
868 869 870 871 872 873 874 875 876 877 878
          --exit-info=256 \
          --core \
          --datadir=$MASTER_MYDDIR \
          --pid-file=$MASTER_MYPID \
          --socket=$MASTER_MYSOCK \
          --log=$MASTER_MYLOG \
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
          --innodb_data_file_path=ibdata1:50M \
879
	  --open-files-limit=1024 \
880
	   $MASTER_40_ARGS \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
881 882 883 884 885 886 887
           $SMALL_SERVER \
           $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT"
  else
    master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin \
          --server-id=1 --rpl-recovery-rank=1 \
          --basedir=$MY_BASEDIR --init-rpl-role=master \
          --port=$MASTER_MYPORT \
888
          --local-infile \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
889 890 891 892 893 894 895 896 897
          --datadir=$MASTER_MYDDIR \
          --pid-file=$MASTER_MYPID \
          --socket=$MASTER_MYSOCK \
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
          --innodb_data_file_path=ibdata1:50M \
898
	   $MASTER_40_ARGS \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
899 900 901 902 903 904 905 906 907 908 909
           $SMALL_SERVER \
           $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT"
  fi

  CUR_MYERR=$MASTER_MYERR
  CUR_MYSOCK=$MASTER_MYSOCK

  if [ x$DO_DDD = x1 ]
  then
    $ECHO "set args $master_args" > $GDB_MASTER_INIT
    manager_launch master ddd -display $DISPLAY --debugger \
910
    "gdb -x $GDB_MASTER_INIT" $MASTER_MYSQLD
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
911 912
  elif [ x$DO_GDB = x1 ]
  then
913 914 915 916
    if [ x$MANUAL_GDB = x1 ]
    then
      $ECHO "set args $master_args" > $GDB_MASTER_INIT
      $ECHO "To start gdb for the master , type in another window:"
917
      $ECHO "cd $CWD ; gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD"
918 919 920 921
      wait_for_master=1500
    else
      ( $ECHO set args $master_args;
      if [ $USE_MANAGER = 0 ] ; then
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
922
    cat <<EOF
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
923 924
b mysql_parse
commands 1
925
disa 1
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
926
end
927 928
r
EOF
929 930
      fi )  > $GDB_MASTER_INIT
      manager_launch master $XTERM -display $DISPLAY \
931
      -title "Master" -e gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD
932
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
933
  else
934
    manager_launch master $MASTER_MYSQLD $master_args
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
935
  fi
936
  sleep_until_file_created $MASTER_MYPID $wait_for_master
937
  wait_for_master=$SLEEP_TIME_FOR_SECOND_MASTER
938 939 940 941 942
  MASTER_RUNNING=1
}

start_slave()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
943 944 945
  [ x$SKIP_SLAVE = x1 ] && return
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  [ x$this_slave_running = 1 ] && return
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
946 947
  # When testing fail-safe replication, we will have more than one slave
  # in this case, we start secondary slaves with an argument
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
948 949 950 951 952 953 954 955
  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"
956
   slave_datadir="$SLAVE_MYDDIR/../$slave_ident-data/"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
957 958 959 960 961 962 963 964 965 966 967 968
   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
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
969 970
  # Remove stale binary logs and old master.info files
  $RM -f $MYSQL_TEST_DIR/var/log/$slave_ident-*bin.*
971
  $RM -f $slave_datadir/master.info $slave_datadir/relay-log.info
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
972 973 974 975 976 977 978 979 980 981 982

  #run slave initialization shell script if one exists
  if [ -f "$slave_init_script" ] ;
  then
        /bin/sh $slave_init_script
  fi

  if [ -z "$SLAVE_MASTER_INFO" ] ; then
    master_info="--master-user=root \
          --master-connect-retry=1 \
          --master-host=127.0.0.1 \
983
          --master-password="" \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
984 985 986 987 988 989 990 991 992 993
          --master-port=$MASTER_MYPORT \
          --server-id=$slave_server_id --rpl-recovery-rank=$slave_rpl_rank"
 else
   master_info=$SLAVE_MASTER_INFO
 fi

  $RM -f $slave_datadir/log.*
  slave_args="--no-defaults $master_info \
  	    --exit-info=256 \
          --log-bin=$MYSQL_TEST_DIR/var/log/$slave_ident-bin \
994
          --relay-log=$MYSQL_TEST_DIR/var/log/$slave_ident-relay-bin \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
          --log-slave-updates \
          --log=$slave_log \
          --basedir=$MY_BASEDIR \
          --datadir=$slave_datadir \
          --pid-file=$slave_pid \
          --port=$slave_port \
          --socket=$slave_sock \
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core --init-rpl-role=slave \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
          --skip-innodb --skip-slave-start \
          --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
          --report-host=127.0.0.1 --report-user=root \
          --report-port=$slave_port \
1011
          --master-retry-count=10 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1012
          -O slave_net_timeout=10 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024
           $SMALL_SERVER \
           $EXTRA_SLAVE_OPT $EXTRA_SLAVE_MYSQLD_OPT"
  CUR_MYERR=$slave_err
  CUR_MYSOCK=$slave_sock

  if [ x$DO_DDD = x1 ]
  then
    $ECHO "set args $master_args" > $GDB_SLAVE_INIT
    manager_launch $slave_ident ddd -display $DISPLAY --debugger \
     "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD
  elif [ x$DO_GDB = x1 ]
  then
1025 1026
    if [ x$MANUAL_GDB = x1 ]
    then
1027
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
1028
      echo "To start gdb for the slave, type in another window:"
1029
      echo "cd $CWD ; gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD"
1030 1031
      wait_for_slave=1500
    else
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
      ( $ECHO set args $slave_args;
      if [ $USE_MANAGER = 0 ] ; then
    cat <<EOF
b mysql_parse
commands 1
disa 1
end
r
EOF
      fi )  > $GDB_SLAVE_INIT
1042 1043 1044
      manager_launch $slave_ident $XTERM -display $DISPLAY -title "Slave" -e \
      gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1045 1046 1047 1048
  else
    manager_launch $slave_ident $SLAVE_MYSQLD $slave_args
  fi
  eval "SLAVE$1_RUNNING=1"
1049
  sleep_until_file_created $slave_pid $wait_for_slave
1050
  wait_for_slave=$SLEEP_TIME_FOR_SECOND_SLAVE
1051 1052
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1053 1054
mysql_start ()
{
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1055
# We should not start the daemon here as we don't know the arguments
paul@ice.snake.net's avatar
paul@ice.snake.net committed
1056
# for the test.  Better to let the test start the daemon
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1057 1058 1059 1060

#  $ECHO "Starting MySQL daemon"
#  start_master
#  start_slave
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1061 1062
  cd $MYSQL_TEST_DIR
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1063 1064
}

1065 1066
stop_slave ()
{
1067 1068 1069
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ -n "$1" ] ;
1070
  then
1071 1072 1073
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
  else
   slave_pid=$SLAVE_MYPID
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1074
  fi
1075 1076
  if [ x$this_slave_running = x1 ]
  then
1077 1078
    pid=`$CAT $slave_pid`
    manager_term $pid $slave_ident
1079
    if [ $? != 0 ] && [ -f $slave_pid ]
1080
    then # try harder!
1081
      $ECHO "slave not cooperating with mysqladmin, will try manual kill"
1082 1083
      kill $pid
      sleep_until_file_deleted $pid $slave_pid
1084 1085 1086 1087 1088 1089 1090 1091 1092
      if [ -f $slave_pid ] ; then
        $ECHO "slave refused to die. Sending SIGKILL"
        kill -9 `$CAT $slave_pid`
        $RM -f $slave_pid
      else
        $ECHO "slave responded to SIGTERM "
      fi
    else
      sleep $SLEEP_TIME_AFTER_RESTART
1093
    fi
1094
    eval "SLAVE$1_RUNNING=0"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1095
  fi
1096
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1097

1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
stop_slave_threads ()
{
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ x$this_slave_running = x1 ]
  then
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$slave_ident.sock stop-slave > /dev/null 2>&1
  fi
}

1108 1109 1110 1111
stop_master ()
{
  if [ x$MASTER_RUNNING = x1 ]
  then
1112 1113
    pid=`$CAT $MASTER_MYPID`
    manager_term $pid master
1114 1115
    if [ $? != 0 ] && [ -f $MASTER_MYPID ]
    then # try harder!
1116
      $ECHO "master not cooperating with mysqladmin, will try manual kill"
1117 1118
      kill $pid
      sleep_until_file_deleted $pid $MASTER_MYPID
1119 1120 1121 1122 1123 1124 1125 1126 1127
      if [ -f $MASTER_MYPID ] ; then
        $ECHO "master refused to die. Sending SIGKILL"
        kill -9 `$CAT $MASTER_MYPID`
        $RM -f $MASTER_MYPID
      else
        $ECHO "master responded to SIGTERM "
      fi
    else
      sleep $SLEEP_TIME_AFTER_RESTART
1128
    fi
1129 1130 1131
    MASTER_RUNNING=0
  fi
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1132

1133 1134
mysql_stop ()
{
1135 1136
 $ECHO  "Ending Tests"
 $ECHO  "Shutting-down MySQL daemon"
1137
 $ECHO  ""
1138
 stop_master
1139
 $ECHO "Master shutdown finished"
1140
 stop_slave
1141 1142
 stop_slave 1
 stop_slave 2
1143
 $ECHO "Slave shutdown finished"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1144

1145
 return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1146 1147
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1148 1149 1150 1151 1152
mysql_restart ()
{
  mysql_stop
  mysql_start
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1153 1154 1155
}

mysql_loadstd () {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1156 1157

    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1158 1159 1160
    return 1
}

1161 1162 1163
run_testcase ()
{
 tf=$1
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1164
 tname=`$BASENAME $tf .test`
1165 1166
 master_opt_file=$TESTDIR/$tname-master.opt
 slave_opt_file=$TESTDIR/$tname-slave.opt
1167 1168
 master_init_script=$TESTDIR/$tname-master.sh
 slave_init_script=$TESTDIR/$tname-slave.sh
1169
 slave_master_info_file=$TESTDIR/$tname.slave-mi
1170
 echo $tname > $CURRENT_TEST
1171
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1172
 if [ $USE_MANAGER = 1 ] ; then
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1173
  many_slaves=`$EXPR \( \( $tname : rpl_failsafe \) != 0 \) \| \( \( $tname : rpl_chain_temp_table \) != 0 \)`
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1174 1175 1176
 fi

 if [ -n "$SKIP_TEST" ] ; then
1177
   SKIP_THIS_TEST=`$EXPR \( $tname : "$SKIP_TEST" \) != 0`
1178 1179
   if [ x$SKIP_THIS_TEST = x1 ] ;
   then
1180 1181
     skip_test $tname;
     return;
1182 1183
   fi
  fi
1184

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1185
 if [ -n "$DO_TEST" ] ; then
1186 1187 1188
   DO_THIS_TEST=`$EXPR \( $tname : "$DO_TEST" \) != 0`
   if [ x$DO_THIS_TEST = x0 ] ;
   then
1189 1190
     skip_test $tname;
     return;
1191 1192 1193 1194
   fi
  fi


1195 1196
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ;
 then
1197
   skip_test $tname;
1198 1199 1200
   return
 fi

1201 1202 1203 1204 1205 1206
 # Stop all slave threads, so that we don't have useless reconnection attempts
 # and error messages in case the slave and master servers restart.
 stop_slave_threads
 stop_slave_threads 1
 stop_slave_threads 2

1207
 if [ -z "$USE_RUNNING_SERVER" ] ;
1208
 then
1209 1210
   if [ -f $master_opt_file ] ;
   then
1211
     EXTRA_MASTER_OPT=`$CAT $master_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1212 1213 1214 1215 1216 1217 1218 1219
     case "$EXTRA_MASTER_OPT" in
       --timezone=*)
	 TZ=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--timezone=;;"`
	 export TZ
	 # Note that this must be set to space, not "" for test-reset to work
	 EXTRA_MASTER_OPT=" "
	 ;;
     esac
1220
     stop_master
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1221
     echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1222
     start_master
1223
     TZ=$MY_TZ; export TZ
1224
   else
1225
     if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] || [ -f $master_init_script ]
1226 1227 1228
     then
       EXTRA_MASTER_OPT=""
       stop_master
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1229
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1230
       start_master
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1231 1232
     else
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1233
     fi
1234
   fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1235

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1236
   do_slave_restart=0
1237 1238
   if [ -f $slave_opt_file ] ;
   then
1239
     EXTRA_SLAVE_OPT=`$CAT $slave_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1240 1241 1242 1243 1244
     do_slave_restart=1
   else
    if [ ! -z "$EXTRA_SLAVE_OPT" ] || [ x$SLAVE_RUNNING != x1 ] ;
    then
      EXTRA_SLAVE_OPT=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1245 1246
      do_slave_restart=1
    fi
1247
   fi
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
1248

1249 1250 1251 1252 1253 1254 1255
   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=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1256 1257
       do_slave_restart=1
     fi
1258 1259 1260 1261
   fi

   if [ x$do_slave_restart = x1 ] ; then
     stop_slave
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1262
     echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
1263
     start_slave
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1264 1265
   else
     echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
1266
   fi
1267 1268 1269 1270
   if [ x$many_slaves = x1 ]; then
    start_slave 1
    start_slave 2
   fi
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
1271
 fi
1272
 cd $MYSQL_TEST_DIR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1273

1274
 if [ -f $tf ] ; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1275
    $RM -f r/$tname.*reject
1276
    mysql_test_args="-R r/$tname.result $EXTRA_MYSQL_TEST_OPT"
1277
    if [ -z "$DO_CLIENT_GDB" ] ; then
1278
      `$MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`;
1279
    else
1280
      do_gdb_test "$mysql_test_args" "$tf"
1281
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1282

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1283 1284
    res=$?

1285
    pname=`$ECHO "$tname                        "|$CUT -c 1-24`
1286
    RES="$pname"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1287

1288 1289 1290 1291
    if [ x$many_slaves = x1 ] ; then
     stop_slave 1
     stop_slave 2
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1292

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1293
    if [ $res = 0 ]; then
1294 1295
      total_inc
      pass_inc
1296
      $ECHO "$RES$RES_SPACE [ pass ]"
1297
    else
1298
      # why the following ``if'' ? That is why res==1 is special ?
1299 1300 1301 1302
      if [ $res = 2 ]; then
        skip_inc
	$ECHO "$RES$RES_SPACE [ skipped ]"
      else
1303
	total_inc
1304
        fail_inc
1305
	$ECHO "$RES$RES_SPACE [ fail ]"
1306 1307
        $ECHO
	error_is
1308
	show_failed_diff $tname
1309
	$ECHO
1310
	if [ x$FORCE != x1 ] ; then
1311 1312
	 $ECHO "Aborting. To continue, re-run with '--force'."
	 $ECHO
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1313 1314 1315
         if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	 then
	   mysql_stop
1316
	   stop_manager
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1317
   	 fi
1318 1319
	 exit 1
	fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1320

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1321 1322 1323 1324
        if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	then
	  mysql_restart
	fi
1325
	$ECHO "Resuming Tests"
1326
	$ECHO ""
1327
      fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1328
    fi
1329
  fi
1330 1331
}

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1332 1333 1334 1335
######################################################################
# Main script starts here
######################################################################

1336 1337
[ "$DO_GCOV" -a ! -x "$GCOV" ] && error "No gcov found"

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1338 1339
[ "$DO_GCOV" ] && gcov_prepare
[ "$DO_GPROF" ] && gprof_prepare
1340

1341 1342
if [ -z "$USE_RUNNING_SERVER" ]
then
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
  if [ -z "$FAST_START" ]
  then
    # Ensure that no old mysqld test servers are running
    $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
    $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --host=$hostname --port=$SLAVE_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --host=$hostname --port=`expr $SLAVE_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    sleep_until_file_deleted 0 $MASTER_MYPID
    sleep_until_file_deleted 0 $SLAVE_MYPID
  else
    rm $MASTER_MYPID $SLAVE_MYPID
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371

  # Kill any running managers
  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

  # Remove files that can cause problems
  $RM -f $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*

1372 1373
  wait_for_master=$SLEEP_TIME_FOR_FIRST_MASTER
  wait_for_slave=$SLEEP_TIME_FOR_FIRST_SLAVE
1374 1375
  $ECHO "Installing Test Databases"
  mysql_install_db
1376
  start_manager
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1377

paul@ice.snake.net's avatar
paul@ice.snake.net committed
1378
# Do not automagically start daemons if we are in gdb or running only one test
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1379
# case
1380 1381 1382 1383 1384 1385
  if [ -z "$DO_GDB" ] && [ -z "$DO_DDD" ]
  then
    mysql_start
  fi
  $ECHO  "Loading Standard Test Databases"
  mysql_loadstd
1386 1387
fi

1388 1389 1390 1391
if [ "x$START_AND_EXIT" = "x1" ] ; then
 echo "Servers started, exiting"
 exit
fi
1392

1393
$ECHO  "Starting Tests"
1394

1395 1396 1397
#
# This can probably be deleted
#
1398 1399
if [ "$DO_BENCH" = 1 ]
then
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1400 1401 1402 1403
  BENCHDIR=$BASEDIR/sql-bench/
  savedir=`pwd`
  cd $BENCHDIR
  if [ -z "$1" ]
1404
  then
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1405
    ./run-all-tests --socket=$MASTER_MYSOCK --user=root
1406
  else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1407 1408 1409 1410 1411 1412
    if [ -x "./$1" ]
    then
       ./$1 --socket=$MASTER_MYSOCK --user=root
    else
      echo "benchmark $1 not found"
    fi
1413
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1414 1415 1416 1417
  cd $savedir
  mysql_stop
  stop_manager
  exit
1418 1419
fi

1420
$ECHO
1421
$ECHO " TEST                           RESULT"
1422 1423
$ECHO $DASH72

1424
if [ -z "$1" ] ;
1425
then
1426
 if [ x$RECORD = x1 ]; then
1427
  $ECHO "Will not run in record mode without a specific test case."
1428
 else
1429
  for tf in `ls -1 $TESTDIR/*.$TESTSUFFIX | $SORT`
1430 1431 1432
  do
    run_testcase $tf
  done
1433
  $RM -f $TIMEFILE	# Remove for full test
1434
 fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1435
else
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445
  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
1446
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1447

1448 1449
$ECHO $DASH72
$ECHO
1450

1451
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
1452 1453 1454
then
    mysql_stop
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1455

1456
stop_manager
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1457
report_stats
1458
$ECHO
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1459

1460
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
1461
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
1462

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