mysql-test-run.sh 42 KB
Newer Older
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
Typo.  
unknown committed
4
# Slightly 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
unknown's avatar
unknown committed
13
DBPASSWD=""
14
VERBOSE=""
unknown's avatar
unknown committed
15
USE_MANAGER=0
16 17
MY_TZ=GMT-3
TZ=$MY_TZ; export TZ # for UNIX_TIMESTAMP tests to work
18
LOCAL_SOCKET=@MYSQL_UNIX_ADDR@
19
MYSQL_TCP_PORT=@MYSQL_TCP_PORT@
unknown's avatar
unknown committed
20

21
# For query_cache test
unknown's avatar
unknown committed
22
case `uname` in
23 24 25
    SCO_SV | UnixWare | OpenUNIX )
        # do nothing (Causes strange behavior)
        ;;
unknown's avatar
unknown committed
26 27 28
    QNX)
        # do nothing (avoid error message)
        ;;
29 30 31 32
    * )
        ulimit -n 1024
        ;;
esac
33

34 35 36 37
#++
# Program Definitions
#--

unknown's avatar
unknown committed
38 39
LC_COLLATE=C
export LC_COLLATE
40
PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11:$PATH
41
MASTER_40_ARGS="--rpl-recovery-rank=1 --init-rpl-role=master"
42

43 44 45 46
# Standard functions

which ()
{
47
  IFS="${IFS=   }"; save_ifs="$IFS"; IFS=':'
48 49
  for file
  do
50
    for dir in $PATH
51
    do
unknown's avatar
unknown committed
52
      if test -f $dir/$file
53 54 55 56 57
      then
        echo "$dir/$file"
        continue 2
      fi
    done
58
    echo "Fatal error: Cannot find program $file in $PATH" 1>&2
59 60
    exit 1
  done
61
  IFS="$save_ifs"
62
  exit 0
63 64 65
}


unknown's avatar
unknown committed
66 67
sleep_until_file_deleted ()
{
68 69
  pid=$1;
  file=$2
unknown's avatar
unknown committed
70
  loop=$SLEEP_TIME_FOR_DELETE
unknown's avatar
unknown committed
71 72
  while (test $loop -gt 0)
  do
unknown's avatar
unknown committed
73
    if [ ! -r $file ]
unknown's avatar
unknown committed
74
    then
75 76 77 78
      if test $pid != "0"
      then
        wait_for_pid $pid
      fi
unknown's avatar
unknown committed
79 80
      return
    fi
unknown's avatar
unknown committed
81
    sleep 1
unknown's avatar
unknown committed
82 83 84 85
    loop=`expr $loop - 1`
  done
}

86
sleep_until_file_created ()
unknown's avatar
unknown committed
87 88
{
  file=$1
unknown's avatar
unknown committed
89 90
  loop=$2
  org_time=$2
unknown's avatar
unknown committed
91 92
  while (test $loop -gt 0)
  do
unknown's avatar
unknown committed
93
    if [ -r $file ]
unknown's avatar
unknown committed
94
    then
95
      return 0
unknown's avatar
unknown committed
96
    fi
unknown's avatar
unknown committed
97
    sleep 1
unknown's avatar
unknown committed
98 99
    loop=`expr $loop - 1`
  done
unknown's avatar
unknown committed
100
  echo "ERROR: $file was not created in $org_time seconds;  Aborting"
unknown's avatar
unknown committed
101 102 103
  exit 1;
}

104 105 106 107 108
# For the future

wait_for_pid()
{
  pid=$1
unknown's avatar
unknown committed
109
  #$WAIT_PID pid $SLEEP_TIME_FOR_DELETE
110 111
}

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

unknown's avatar
unknown committed
114 115
SED=sed

116 117
BASENAME=`which basename`
if test $? != 0; then exit 1; fi
unknown's avatar
unknown committed
118
DIFF=`which diff | $SED q`
119
if test $? != 0; then exit 1; fi
120 121
CAT=cat
CUT=cut
unknown's avatar
unknown committed
122
HEAD=head
123 124 125 126
TAIL=tail
ECHO=echo # use internal echo if possible
EXPR=expr # use internal if possible
FIND=find
unknown's avatar
unknown committed
127
GREP=grep
128
if test $? != 0; then exit 1; fi
129 130
PRINTF=printf
RM=rm
131
if test $? != 0; then exit 1; fi
132
TR=tr
133 134
XARGS=`which xargs`
if test $? != 0; then exit 1; fi
135
SORT=sort
136 137 138 139 140

# Are we using a source or a binary distribution?

testdir=@testdir@
if [ -d bin/mysqld ] && [ -d mysql-test ] ; then
141 142
 cd mysql-test
else
143 144
 if [ -d $testdir/mysql-test ] ; then
   cd $testdir
145
 fi
146 147 148 149 150 151 152
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
153
  exit 1
154
fi
155

unknown's avatar
unknown committed
156 157 158
#++
# Misc. Definitions
#--
159

160 161 162 163 164
if [ -d ../sql ] ; then
   SOURCE_DIST=1
else
   BINARY_DIST=1
fi
165

unknown's avatar
unknown committed
166
#BASEDIR is always one above mysql-test directory
unknown's avatar
unknown committed
167 168 169 170
CWD=`pwd`
cd ..
BASEDIR=`pwd`
cd $CWD
171
MYSQL_TEST_DIR=$BASEDIR/mysql-test
172
export MYSQL_TEST_DIR
173
STD_DATA=$MYSQL_TEST_DIR/std_data
unknown's avatar
unknown committed
174
hostname=`hostname`		# Installed in the mysql privilege table
unknown's avatar
unknown committed
175

unknown's avatar
unknown committed
176
MANAGER_QUIET_OPT="-q"
177
TESTDIR="$MYSQL_TEST_DIR/t"
unknown's avatar
unknown committed
178
TESTSUFFIX=test
179
TOT_SKIP=0
unknown's avatar
unknown committed
180 181 182
TOT_PASS=0
TOT_FAIL=0
TOT_TEST=0
183 184 185
USERT=0
SYST=0
REALT=0
186
FAST_START=""
unknown's avatar
unknown committed
187
MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp
unknown's avatar
unknown committed
188
SLAVE_LOAD_TMPDIR=../../var/tmp #needs to be same length to test logging
unknown's avatar
unknown committed
189
RES_SPACE="      "
unknown's avatar
unknown committed
190 191
MYSQLD_SRC_DIRS="strings mysys include extra regex isam merge myisam \
 myisammrg heap sql"
192
MY_LOG_DIR="$MYSQL_TEST_DIR/var/log" 
193 194 195
#
# Set LD_LIBRARY_PATH if we are using shared libraries
#
unknown's avatar
unknown committed
196
LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$LD_LIBRARY_PATH"
unknown's avatar
unknown committed
197 198
DYLD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$DYLD_LIBRARY_PATH"
export LD_LIBRARY_PATH DYLD_LIBRARY_PATH
199

unknown's avatar
fixed  
unknown committed
200
MASTER_RUNNING=0
201
MASTER_MYPORT=9306
unknown's avatar
fixed  
unknown committed
202
SLAVE_RUNNING=0
203
SLAVE_MYPORT=9307
unknown's avatar
unknown committed
204
MYSQL_MANAGER_PORT=9305 # needs to be out of the way of slaves
205
NDBCLUSTER_PORT=9350
unknown's avatar
unknown committed
206 207 208
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
209
NO_SLAVE=0
unknown's avatar
unknown committed
210
USER_TEST=
211

212
EXTRA_MASTER_OPT=""
213
EXTRA_MYSQL_TEST_OPT=""
214 215
EXTRA_MYSQLDUMP_OPT=""
EXTRA_MYSQLBINLOG_OPT=""
216
USE_RUNNING_SERVER=""
unknown's avatar
unknown committed
217 218
USE_NDBCLUSTER=""
USE_RUNNING_NDBCLUSTER=""
219 220
DO_GCOV=""
DO_GDB=""
unknown's avatar
unknown committed
221
MANUAL_GDB=""
222
DO_DDD=""
223
DO_CLIENT_GDB=""
unknown's avatar
unknown committed
224
SLEEP_TIME_AFTER_RESTART=1
unknown's avatar
unknown committed
225
SLEEP_TIME_FOR_DELETE=10
unknown's avatar
unknown committed
226
SLEEP_TIME_FOR_FIRST_MASTER=400		# Enough time to create innodb tables
unknown's avatar
unknown committed
227
SLEEP_TIME_FOR_SECOND_MASTER=30
unknown's avatar
unknown committed
228
SLEEP_TIME_FOR_FIRST_SLAVE=400
unknown's avatar
unknown committed
229
SLEEP_TIME_FOR_SECOND_SLAVE=30
unknown's avatar
unknown committed
230
CHARACTER_SET=latin1
231
DBUSER=""
232 233
START_WAIT_TIMEOUT=10
STOP_WAIT_TIMEOUT=10
unknown's avatar
unknown committed
234
MYSQL_TEST_SSL_OPTS=""
235 236 237

while test $# -gt 0; do
  case "$1" in
238 239
    --user=*) DBUSER=`$ECHO "$1" | $SED -e "s;--user=;;"` ;;
    --force)  FORCE=1 ;;
unknown's avatar
unknown committed
240
    --verbose-manager)  MANAGER_QUIET_OPT="" ;;
241 242 243 244 245
    --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=;;"` ;;
246
    --local)   USE_RUNNING_SERVER="" ;;
247
    --extern)  USE_RUNNING_SERVER="1" ;;
unknown's avatar
unknown committed
248
    --with-ndbcluster)
249
      USE_NDBCLUSTER="--ndbcluster" ;;
unknown's avatar
unknown committed
250
    --ndbconnectstring=*)
251
      USE_NDBCLUSTER="--ndbcluster" ;
unknown's avatar
unknown committed
252
      USE_RUNNING_NDBCLUSTER=`$ECHO "$1" | $SED -e "s;--ndbconnectstring=;;"` ;;
253
    --tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;;
254 255 256 257 258
    --local-master)
      MASTER_MYPORT=3306;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --host=127.0.0.1 \
      --port=$MYSQL_MYPORT"
      LOCAL_MASTER=1 ;;
259 260
    --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
261
    --manager-port=*) MYSQL_MANAGER_PORT=`$ECHO "$1" | $SED -e "s;--manager_port=;;"` ;;
262
    --ndbcluster_port=*) NDBCLUSTER_PORT=`$ECHO "$1" | $SED -e "s;--ndbcluster_port=;;"` ;;
unknown's avatar
unknown committed
263 264
    --with-openssl)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
unknown's avatar
unknown committed
265 266 267
     --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
268
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
unknown's avatar
unknown committed
269 270
     --ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/server-cert.pem \
unknown's avatar
unknown committed
271 272 273 274
     --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" ;;
unknown's avatar
unknown committed
275
    --no-manager | --skip-manager) USE_MANAGER=0 ;;
276 277 278 279
    --manager)
     USE_MANAGER=1
     USE_RUNNING_SERVER=
     ;;
280 281
    --start-and-exit)
     START_AND_EXIT=1
unknown's avatar
unknown committed
282
     ;;
283
    --socket=*) LOCAL_SOCKET=`$ECHO "$1" | $SED -e "s;--socket=;;"` ;;
284
    --skip-rpl) NO_SLAVE=1 ;;
unknown's avatar
unknown committed
285
    --skip-test=*) SKIP_TEST=`$ECHO "$1" | $SED -e "s;--skip-test=;;"`;;
286
    --do-test=*) DO_TEST=`$ECHO "$1" | $SED -e "s;--do-test=;;"`;;
287
    --start-from=* ) START_FROM=`$ECHO "$1" | $SED -e "s;--start-from=;;"` ;;
288 289 290 291
    --warnings | --log-warnings)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --log-warnings"
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --log-warnings"
     ;;
unknown's avatar
unknown committed
292 293 294
    --wait-timeout=*)
     START_WAIT_TIMEOUT=`$ECHO "$1" | $SED -e "s;--wait-timeout=;;"`
     STOP_WAIT_TIMEOUT=$START_WAIT_TIMEOUT;;
295 296 297
    --record)
      RECORD=1;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
unknown's avatar
unknown committed
298 299 300
    --bench)
      DO_BENCH=1
      NO_SLAVE=1
unknown's avatar
unknown committed
301
      ;;
302 303
    --big*)			# Actually --big-test
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
unknown's avatar
unknown committed
304 305
    --compress)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
306 307
    --sleep=*)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1"
unknown's avatar
unknown committed
308
      SLEEP_TIME_AFTER_RESTART=`$ECHO "$1" | $SED -e "s;--sleep=;;"`
309
      ;;
unknown's avatar
unknown committed
310 311 312
    --user-test=*)
      USER_TEST=`$ECHO "$1" | $SED -e "s;--user-test=;;"`
      ;;
313
    --mysqld=*)
unknown's avatar
unknown committed
314
       TMP=`$ECHO "$1" | $SED -e "s;--mysqld=;;"`
unknown's avatar
unknown committed
315
       EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $TMP"
316
       EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $TMP"
317
       ;;
318 319 320 321 322 323
    --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
324
      GCOV=`which gcov`
325
      ;;
unknown's avatar
unknown committed
326 327
    --gprof )
      DO_GPROF=1
unknown's avatar
unknown committed
328
      ;;
329
    --gdb )
unknown's avatar
unknown committed
330 331
      START_WAIT_TIMEOUT=300
      STOP_WAIT_TIMEOUT=300
332
      if [ x$BINARY_DIST = x1 ] ; then
333
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --gdb option"
334 335
      fi
      DO_GDB=1
336 337
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
unknown's avatar
unknown committed
338 339
      # This needs to be checked properly
      # USE_MANAGER=1
340
      USE_RUNNING_SERVER=""
341
      ;;
342 343 344 345 346
    --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
347 348
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
349
      ;;
unknown's avatar
unknown committed
350 351 352 353
    --manual-gdb )
      DO_GDB=1
      MANUAL_GDB=1
      USE_RUNNING_SERVER=""
354 355
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
unknown's avatar
unknown committed
356
      ;;
357 358
    --ddd )
      if [ x$BINARY_DIST = x1 ] ; then
359
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --ddd option"
360 361
      fi
      DO_DDD=1
362
      USE_RUNNING_SERVER=""
363 364
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
365
      ;;
366
    --valgrind | --valgrind-all)
unknown's avatar
unknown committed
367 368 369 370 371 372
      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
unknown's avatar
unknown committed
373
      VALGRIND="$VALGRIND --tool=memcheck --alignment=8 --leak-check=yes --num-callers=16"
374 375
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc --skip-bdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-safemalloc --skip-bdb"
unknown's avatar
unknown committed
376
      SLEEP_TIME_AFTER_RESTART=10
377
      SLEEP_TIME_FOR_DELETE=60
378
      USE_RUNNING_SERVER=""
379 380 381 382
      if test "$1" = "--valgrind-all"
      then
        VALGRIND="$VALGRIND -v --show-reachable=yes"
      fi
unknown's avatar
unknown committed
383 384 385 386 387
      ;;
    --valgrind-options=*)
      TMP=`$ECHO "$1" | $SED -e "s;--valgrind-options=;;"`
      VALGRIND="$VALGRIND $TMP"
      ;;
388 389 390 391
    --skip-*)
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $1"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $1"
      ;;
unknown's avatar
unknown committed
392 393
    --strace-client )
      STRACE_CLIENT=1
unknown's avatar
unknown committed
394
      ;;
395
    --debug)
396
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
unknown's avatar
unknown committed
397
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/master.trace"
398
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
unknown's avatar
unknown committed
399
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/slave.trace"
400 401
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqltest.trace"
402 403 404 405
      EXTRA_MYSQLDUMP_OPT="$EXTRA_MYSQLDUMP_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqldump.trace"
      EXTRA_MYSQLBINLOG_OPT="$EXTRA_MYSQLBINLOG_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlbinlog.trace"
406
      ;;
407 408 409
    --fast)
      FAST_START=1
      ;;
410 411 412 413 414 415
    -- )  shift; break ;;
    --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
    * ) break ;;
  esac
  shift
done
unknown's avatar
fixed  
unknown committed
416

unknown's avatar
unknown committed
417 418 419
#++
# mysqld Environment Parameters
#--
420

unknown's avatar
unknown committed
421
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
422 423
MANAGER_PID_FILE="$MYRUN_DIR/manager.pid"

424
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
unknown's avatar
unknown committed
425
MASTER_MYSOCK="$MYSQL_TMP_DIR/master.sock"
unknown's avatar
unknown committed
426 427 428
MASTER_MYPID="$MYRUN_DIR/master.pid"
MASTER_MYLOG="$MYSQL_TEST_DIR/var/log/master.log"
MASTER_MYERR="$MYSQL_TEST_DIR/var/log/master.err"
429 430

SLAVE_MYDDIR="$MYSQL_TEST_DIR/var/slave-data"
unknown's avatar
unknown committed
431
SLAVE_MYSOCK="$MYSQL_TMP_DIR/slave.sock"
unknown's avatar
unknown committed
432 433 434
SLAVE_MYPID="$MYRUN_DIR/slave.pid"
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/slave.log"
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/slave.err"
435

436
CURRENT_TEST="$MYSQL_TEST_DIR/var/log/current_test"
437
SMALL_SERVER="--key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M"
438

439
export MASTER_MYPORT SLAVE_MYPORT MYSQL_TCP_PORT
unknown's avatar
unknown committed
440

441 442 443 444
if [ x$SOURCE_DIST = x1 ] ; then
 MY_BASEDIR=$MYSQL_TEST_DIR
else
 MY_BASEDIR=$BASEDIR
unknown's avatar
unknown committed
445
fi
unknown's avatar
unknown committed
446

unknown's avatar
unknown committed
447 448 449 450 451 452 453 454
# 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
455
[ -d $MYSQL_TEST_DIR/var/log ] || mkdir $MYSQL_TEST_DIR/var/log
unknown's avatar
unknown committed
456

457
if test ${COLUMNS:-0} -lt 80 ; then COLUMNS=80 ; fi
458
E=`$EXPR $COLUMNS - 8`
459
DASH72=`$ECHO '------------------------------------------'|$CUT -c 1-$E`
460

461 462 463
# on source dist, we pick up freshly build executables
# on binary, use what is installed
if [ x$SOURCE_DIST = x1 ] ; then
unknown's avatar
unknown committed
464
 MYSQLD="$VALGRIND $BASEDIR/sql/mysqld"
465
 if [ -f "$BASEDIR/client/.libs/lt-mysqltest" ] ; then
466
   MYSQL_TEST="$BASEDIR/client/.libs/lt-mysqltest"
unknown's avatar
unknown committed
467 468
 elif [ -f "$BASEDIR/client/.libs/mysqltest" ] ; then
   MYSQL_TEST="$BASEDIR/client/.libs/mysqltest"
469 470 471
 else
   MYSQL_TEST="$BASEDIR/client/mysqltest"
 fi
472
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
unknown's avatar
unknown committed
473
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
474
 else
unknown's avatar
unknown committed
475
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
476
 fi
unknown's avatar
unknown committed
477
 if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then
unknown's avatar
unknown committed
478
   MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog"
unknown's avatar
unknown committed
479
 else
unknown's avatar
unknown committed
480
   MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog"
unknown's avatar
unknown committed
481
 fi
unknown's avatar
unknown committed
482 483 484
 if [ -n "$STRACE_CLIENT" ]; then
  MYSQL_TEST="strace -o $MYSQL_TEST_DIR/var/log/mysqltest.strace $MYSQL_TEST"
 fi
unknown's avatar
unknown committed
485

unknown's avatar
unknown committed
486 487
 CLIENT_BINDIR="$BASEDIR/client"
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
unknown's avatar
unknown committed
488
 WAIT_PID="$BASEDIR/extra/mysql_waitpid"
unknown's avatar
unknown committed
489
 MYSQL_MANAGER_CLIENT="$CLIENT_BINDIR/mysqlmanagerc"
unknown's avatar
unknown committed
490
 MYSQL_MANAGER="$BASEDIR/tools/mysqlmanager"
unknown's avatar
unknown committed
491 492
 MYSQL_MANAGER_PWGEN="$CLIENT_BINDIR/mysqlmanager-pwgen"
 MYSQL="$CLIENT_BINDIR/mysql"
493
 LANGUAGE="$BASEDIR/sql/share/english/"
494
 CHARSETSDIR="$BASEDIR/sql/share/charsets"
495
 INSTALL_DB="./install_test_db"
496
 MYSQL_FIX_SYSTEM_TABLES="$BASEDIR/scripts/mysql_fix_privilege_tables"
497
else
498 499
 if test -x "$BASEDIR/libexec/mysqld"
 then
unknown's avatar
unknown committed
500
   MYSQLD="$VALGRIND $BASEDIR/libexec/mysqld"
501
 else
unknown's avatar
unknown committed
502
   MYSQLD="$VALGRIND $BASEDIR/bin/mysqld"
503
 fi
unknown's avatar
unknown committed
504 505 506 507 508 509 510 511 512 513
 CLIENT_BINDIR="$BASEDIR/bin"
 MYSQL_TEST="$CLIENT_BINDIR/mysqltest"
 MYSQL_DUMP="$CLIENT_BINDIR/mysqldump"
 MYSQL_BINLOG="$CLIENT_BINDIR/mysqlbinlog"
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
 WAIT_PID="$CLIENT_BINDIR/mysql_waitpid"
 MYSQL_MANAGER="$CLIENT_BINDIR/mysqlmanager"
 MYSQL_MANAGER_CLIENT="$CLIENT_BINDIR/mysqlmanagerc"
 MYSQL_MANAGER_PWGEN="$CLIENT_BINDIR/mysqlmanager-pwgen"
 MYSQL="$CLIENT_BINDIR/mysql"
514
 INSTALL_DB="./install_test_db --bin"
unknown's avatar
unknown committed
515
 MYSQL_FIX_SYSTEM_TABLES="$CLIENT_BINDIR/mysql_fix_privilege_tables"
unknown's avatar
unknown committed
516
 if test -d "$BASEDIR/share/mysql/english"
517 518
 then
   LANGUAGE="$BASEDIR/share/mysql/english/"
519
   CHARSETSDIR="$BASEDIR/share/mysql/charsets"
520 521
 else
   LANGUAGE="$BASEDIR/share/english/"
522
   CHARSETSDIR="$BASEDIR/share/charsets"
523
  fi
524 525
fi

526
MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
527
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR $EXTRA_MYSQLBINLOG_OPT"
unknown's avatar
unknown committed
528
MYSQL_FIX_SYSTEM_TABLES="$MYSQL_FIX_SYSTEM_TABLES --no-defaults --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD --basedir=$BASEDIR --bindir=$CLIENT_BINDIR --verbose"
unknown's avatar
unknown committed
529 530
MYSQL="$MYSQL --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD"
export MYSQL MYSQL_DUMP MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES CLIENT_BINDIR
531

532

533 534 535 536 537 538 539 540 541 542
if [ -z "$MASTER_MYSQLD" ]
then
MASTER_MYSQLD=$MYSQLD
fi

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

543 544 545 546 547 548
# If we should run all tests cases, we will use a local server for that

if [ -z "$1" ]
then
   USE_RUNNING_SERVER=""
fi
549 550
if [ -n "$USE_RUNNING_SERVER" ]
then
551
   MASTER_MYSOCK=$LOCAL_SOCKET;
552
   DBUSER=${DBUSER:-test}
553
else
554
   DBUSER=${DBUSER:-root}		# We want to do FLUSH xxx commands
555
fi
556 557 558

if [ -w / ]
then
unknown's avatar
unknown committed
559 560 561
  # 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"
562 563
fi

564

565
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
566
 --user=$DBUSER --password=$DBPASSWD --silent -v --skip-safemalloc \
unknown's avatar
unknown committed
567
 --tmpdir=$MYSQL_TMP_DIR --port=$MASTER_MYPORT $MYSQL_TEST_SSL_OPTS"
568 569 570
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
571 572 573
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
574 575 576 577
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
578
TIMEFILE="$MYSQL_TEST_DIR/var/log/mysqltest-time"
579 580 581
if [ -n "$DO_CLIENT_GDB" -o -n "$DO_GDB" ] ; then
  XTERM=`which xterm`
fi
582

unknown's avatar
unknown committed
583 584 585 586
#++
# Function Definitions
#--

unknown's avatar
unknown committed
587 588
prompt_user ()
{
589
 $ECHO $1
590
 read unused
unknown's avatar
unknown committed
591 592
}

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

unknown's avatar
unknown committed
595 596 597 598
show_failed_diff ()
{
  reject_file=r/$1.reject
  result_file=r/$1.result
599
  eval_file=r/$1.eval
unknown's avatar
unknown committed
600

601 602 603 604
  if [ -f $eval_file ]
  then
    result_file=$eval_file
  fi
unknown's avatar
unknown committed
605

unknown's avatar
unknown committed
606 607 608 609
  if [ -x "$DIFF" ] && [ -f $reject_file ]
  then
    echo "Below are the diffs between actual and expected results:"
    echo "-------------------------------------------------------"
unknown's avatar
unknown committed
610
    $DIFF -c $result_file $reject_file
unknown's avatar
unknown committed
611
    echo "-------------------------------------------------------"
612
    echo "Please follow the instructions outlined at"
613
    echo "http://www.mysql.com/doc/en/Reporting_mysqltest_bugs.html"
614
    echo "to find the reason to this problem and how to report this."
615
    echo ""
unknown's avatar
unknown committed
616
  fi
unknown's avatar
unknown committed
617
}
unknown's avatar
unknown committed
618

619 620 621 622 623 624
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
625
  $XTERM -title "Client" -e gdb -x $GDB_CLIENT_INIT $MYSQL_TEST_BIN
626 627
}

unknown's avatar
unknown committed
628
error () {
unknown's avatar
unknown committed
629
    $ECHO  "Error:  $1"
unknown's avatar
unknown committed
630 631 632
    exit 1
}

633
error_is () {
634 635
    $ECHO "Errors are (from $TIMEFILE) :"
    $CAT < $TIMEFILE
636
    $ECHO "(the last lines may be the most important ones)"
637 638
}

unknown's avatar
unknown committed
639
prefix_to_8() {
640
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
unknown's avatar
unknown committed
641 642
}

unknown's avatar
unknown committed
643
pass_inc () {
unknown's avatar
unknown committed
644
    TOT_PASS=`$EXPR $TOT_PASS + 1`
unknown's avatar
unknown committed
645 646 647
}

fail_inc () {
unknown's avatar
unknown committed
648
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
unknown's avatar
unknown committed
649 650
}

651 652 653 654
skip_inc () {
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
}

unknown's avatar
unknown committed
655
total_inc () {
unknown's avatar
unknown committed
656
    TOT_TEST=`$EXPR $TOT_TEST + 1`
unknown's avatar
unknown committed
657 658
}

659 660 661 662 663 664

skip_test() {
   USERT="    ...."
   SYST="    ...."
   REALT="    ...."
   pname=`$ECHO "$1                        "|$CUT -c 1-24`
665
   RES="$pname"
666 667 668 669
   skip_inc
   $ECHO "$RES$RES_SPACE [ skipped ]"
}

unknown's avatar
unknown committed
670
report_stats () {
671
    if [ $TOT_FAIL = 0 ]; then
unknown's avatar
unknown committed
672
	$ECHO "All $TOT_TEST tests were successful."
unknown's avatar
unknown committed
673
    else
unknown's avatar
unknown committed
674 675 676 677 678 679
	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`
680
	$ECHO  "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% successful."
681
	$ECHO ""
682
        $ECHO "The log files in $MY_LOG_DIR may give you some hint"
683 684
	$ECHO "of what when wrong."
	$ECHO "If you want to report this error, please read first the documentation at"
685
        $ECHO "http://www.mysql.com/doc/en/MySQL_test_suite.html"
unknown's avatar
unknown committed
686
    fi
unknown's avatar
unknown committed
687

unknown's avatar
unknown committed
688 689 690
    if test -z "$USE_RUNNING_SERVER"
    then

unknown's avatar
unknown committed
691 692 693 694
    # 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
695
    $SED -e 's!Warning:  Table:.* on delete!!g' -e 's!Warning: Setting lower_case_table_names=2!!g' -e 's!Warning: One can only use the --user.*root!!g' \
696 697 698
        $MY_LOG_DIR/*.err \
        | $SED -e 's!Warning:  Table:.* on rename!!g' \
        > $MY_LOG_DIR/warnings.tmp
unknown's avatar
unknown committed
699 700 701 702 703

    found_error=0
    # Find errors
    for i in "^Warning:" "^Error:" "^==.* at 0x"
    do
unknown's avatar
unknown committed
704
      if $GREP "$i" $MY_LOG_DIR/warnings.tmp >> $MY_LOG_DIR/warnings
unknown's avatar
unknown committed
705 706 707 708 709 710 711 712 713 714
      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
unknown's avatar
unknown committed
715
    fi
unknown's avatar
unknown committed
716
}
717

unknown's avatar
unknown committed
718
mysql_install_db () {
719
    $ECHO "Removing Stale Files"
720
    $RM -rf $MASTER_MYDDIR $SLAVE_MYDDIR $MY_LOG_DIR/* 
721
    $ECHO "Installing Master Databases"
722 723 724 725 726
    $INSTALL_DB
    if [ $? != 0 ]; then
	error "Could not install master test DBs"
	exit 1
    fi
727
    $ECHO "Installing Slave Databases"
728
    $INSTALL_DB -slave
729
    if [ $? != 0 ]; then
730
	error "Could not install slave test DBs"
731
	exit 1
unknown's avatar
unknown committed
732
    fi
unknown's avatar
unknown committed
733

734 735
    for slave_num in 1 2 ;
    do
736
      $RM -rf var/slave$slave_num-data
737 738 739
      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
740
    done
unknown's avatar
unknown committed
741 742 743
    return 0
}

unknown's avatar
unknown committed
744 745
gprof_prepare ()
{
unknown's avatar
unknown committed
746 747
 $RM -rf $GPROF_DIR
 mkdir -p $GPROF_DIR
unknown's avatar
unknown committed
748 749 750 751 752
}

gprof_collect ()
{
 if [ -f $MASTER_MYDDIR/gmon.out ]; then
753
   gprof $MASTER_MYSQLD $MASTER_MYDDIR/gmon.out > $GPROF_MASTER
unknown's avatar
unknown committed
754 755 756
   echo "Master execution profile has been saved in $GPROF_MASTER"
 fi
 if [ -f $SLAVE_MYDDIR/gmon.out ]; then
757
   gprof $SLAVE_MYSQLD $SLAVE_MYDDIR/gmon.out > $GPROF_SLAVE
unknown's avatar
unknown committed
758 759 760 761
   echo "Slave execution profile has been saved in $GPROF_SLAVE"
 fi
}

762
gcov_prepare () {
unknown's avatar
unknown committed
763 764
    $FIND $BASEDIR -name \*.gcov \
    -or -name \*.da | $XARGS $RM
unknown's avatar
unknown committed
765 766 767
}

gcov_collect () {
unknown's avatar
unknown committed
768
    $ECHO "Collecting source coverage info..."
unknown's avatar
unknown committed
769 770
    [ -f $GCOV_MSG ] && $RM $GCOV_MSG
    [ -f $GCOV_ERR ] && $RM $GCOV_ERR
unknown's avatar
unknown committed
771 772 773
    for d in $MYSQLD_SRC_DIRS; do
	cd $BASEDIR/$d
	for f in *.h *.cc *.c; do
unknown's avatar
unknown committed
774
	    $GCOV $f 2>>$GCOV_ERR  >>$GCOV_MSG
unknown's avatar
unknown committed
775
	done
776
	cd $MYSQL_TEST_DIR
unknown's avatar
unknown committed
777 778
    done

unknown's avatar
unknown committed
779
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
unknown's avatar
unknown committed
780 781
}

unknown's avatar
unknown committed
782 783 784 785 786
abort_if_failed()
{
 if [ ! $? = 0 ] ; then
  echo $1
  exit 1
unknown's avatar
unknown committed
787
 fi
unknown's avatar
unknown committed
788 789 790 791
}

start_manager()
{
unknown's avatar
unknown committed
792
 if [ $USE_MANAGER = 0 ] ; then
793 794
   echo "Manager disabled, skipping manager start."
   $RM -f $MYSQL_MANAGER_LOG
795 796
  return
 fi
unknown's avatar
unknown committed
797
 $ECHO "Starting MySQL Manager"
798 799 800 801 802 803 804 805 806
 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

unknown's avatar
unknown committed
807
 $RM -f $MANAGER_PID_FILE
unknown's avatar
unknown committed
808 809
 MYSQL_MANAGER_PW=`$MYSQL_MANAGER_PWGEN -u $MYSQL_MANAGER_USER \
 -o $MYSQL_MANAGER_PW_FILE`
unknown's avatar
unknown committed
810
 $MYSQL_MANAGER --log=$MYSQL_MANAGER_LOG --port=$MYSQL_MANAGER_PORT \
811
  --password-file=$MYSQL_MANAGER_PW_FILE --pid-file=$MANAGER_PID_FILE
unknown's avatar
unknown committed
812
  abort_if_failed "Could not start MySQL manager"
813 814
  mysqltest_manager_args="--manager-host=localhost \
  --manager-user=$MYSQL_MANAGER_USER \
815 816 817 818 819
  --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"
820 821 822 823
  while [ ! -f $MANAGER_PID_FILE ] ; do
   sleep 1
  done
  echo "Manager started"
unknown's avatar
unknown committed
824 825
}

unknown's avatar
unknown committed
826 827
stop_manager()
{
unknown's avatar
unknown committed
828
 if [ $USE_MANAGER = 0 ] ; then
829 830
  return
 fi
unknown's avatar
unknown committed
831 832 833 834
 $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT -u$MYSQL_MANAGER_USER \
  -p$MYSQL_MANAGER_PW -P $MYSQL_MANAGER_PORT <<EOF
shutdown
EOF
835 836
 echo "Manager terminated"

unknown's avatar
unknown committed
837 838 839
}

manager_launch()
unknown's avatar
unknown committed
840
{
unknown's avatar
unknown committed
841 842
  ident=$1
  shift
unknown's avatar
unknown committed
843
  if [ $USE_MANAGER = 0 ] ; then
unknown's avatar
unknown committed
844
    echo $@ | /bin/sh  >> $CUR_MYERR 2>&1  &
unknown's avatar
unknown committed
845 846
    sleep 2 #hack
    return
847
  fi
unknown's avatar
unknown committed
848
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
unknown's avatar
unknown committed
849
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
850
def_exec $ident "$@"
unknown's avatar
unknown committed
851 852 853 854
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
855
EOF
unknown's avatar
unknown committed
856
  abort_if_failed "Could not execute manager command"
unknown's avatar
unknown committed
857
}
unknown's avatar
unknown committed
858

unknown's avatar
unknown committed
859 860
manager_term()
{
861 862
  pid=$1
  ident=$2
unknown's avatar
unknown committed
863
  if [ $USE_MANAGER = 0 ] ; then
unknown's avatar
unknown committed
864 865
    # 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
866 867 868 869 870 871 872 873
    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
874
  fi
unknown's avatar
unknown committed
875 876
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
877
stop_exec $ident $STOP_WAIT_TIMEOUT
unknown's avatar
unknown committed
878 879 880 881 882
EOF
 abort_if_failed "Could not execute manager command"
}


unknown's avatar
unknown committed
883 884
start_master()
{
unknown's avatar
unknown committed
885 886 887
  if [ x$MASTER_RUNNING = x1 ] || [ x$LOCAL_MASTER = x1 ] ; then
    return
  fi
unknown's avatar
unknown committed
888 889 890 891 892 893
  # Remove stale binary logs except for 2 tests which need them
  if [ "$tname" != "rpl_crash_binlog_ib_1b" ] && [ "$tname" != "rpl_crash_binlog_ib_2b" ] && [ "$tname" != "rpl_crash_binlog_ib_3b" ] 
  then
    $RM -f $MYSQL_TEST_DIR/var/log/master-bin.*
  fi

894 895
  # 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
unknown's avatar
unknown committed
896 897 898 899 900 901 902 903 904 905 906

  #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 \
907 908
  	    --server-id=1  \
          --basedir=$MY_BASEDIR \
unknown's avatar
unknown committed
909
          --port=$MASTER_MYPORT \
unknown's avatar
unknown committed
910
          --local-infile \
unknown's avatar
unknown committed
911 912
          --exit-info=256 \
          --core \
unknown's avatar
unknown committed
913
          $USE_NDBCLUSTER \
unknown's avatar
unknown committed
914 915 916 917 918 919 920 921 922
          --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 \
923
	  --open-files-limit=1024 \
924
	   $MASTER_40_ARGS \
unknown's avatar
unknown committed
925 926 927 928 929 930 931
           $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 \
unknown's avatar
unknown committed
932
          --local-infile \
unknown's avatar
unknown committed
933 934 935 936 937 938
          --datadir=$MASTER_MYDDIR \
          --pid-file=$MASTER_MYPID \
          --socket=$MASTER_MYSOCK \
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core \
unknown's avatar
unknown committed
939
          $USE_NDBCLUSTER \
unknown's avatar
unknown committed
940 941 942
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
          --innodb_data_file_path=ibdata1:50M \
943
	   $MASTER_40_ARGS \
unknown's avatar
unknown committed
944 945 946 947 948 949 950 951 952 953 954
           $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 \
955
    "gdb -x $GDB_MASTER_INIT" $MASTER_MYSQLD
unknown's avatar
unknown committed
956 957
  elif [ x$DO_GDB = x1 ]
  then
unknown's avatar
unknown committed
958 959 960 961
    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:"
962
      $ECHO "cd $CWD ; gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD"
unknown's avatar
unknown committed
963 964 965 966
      wait_for_master=1500
    else
      ( $ECHO set args $master_args;
      if [ $USE_MANAGER = 0 ] ; then
unknown's avatar
unknown committed
967
    cat <<EOF
unknown's avatar
unknown committed
968 969
b mysql_parse
commands 1
970
disa 1
unknown's avatar
unknown committed
971
end
unknown's avatar
unknown committed
972 973
r
EOF
unknown's avatar
unknown committed
974 975
      fi )  > $GDB_MASTER_INIT
      manager_launch master $XTERM -display $DISPLAY \
976
      -title "Master" -e gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD
unknown's avatar
unknown committed
977
    fi
unknown's avatar
unknown committed
978
  else
979
    manager_launch master $MASTER_MYSQLD $master_args
unknown's avatar
unknown committed
980
  fi
981
  sleep_until_file_created $MASTER_MYPID $wait_for_master
unknown's avatar
unknown committed
982
  wait_for_master=$SLEEP_TIME_FOR_SECOND_MASTER
unknown's avatar
unknown committed
983 984 985 986 987
  MASTER_RUNNING=1
}

start_slave()
{
unknown's avatar
unknown committed
988 989 990
  [ x$SKIP_SLAVE = x1 ] && return
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  [ x$this_slave_running = 1 ] && return
unknown's avatar
unknown committed
991 992
  # When testing fail-safe replication, we will have more than one slave
  # in this case, we start secondary slaves with an argument
unknown's avatar
unknown committed
993 994 995 996 997 998 999 1000
  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"
1001
   slave_datadir="$SLAVE_MYDDIR/../$slave_ident-data/"
unknown's avatar
unknown committed
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
   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
unknown's avatar
unknown committed
1014
  # Remove stale binary logs and old master.info files
unknown's avatar
unknown committed
1015 1016 1017 1018 1019 1020
  # except for too tests which need them
  if [ "$tname" != "rpl_crash_binlog_ib_1b" ] && [ "$tname" != "rpl_crash_binlog_ib_2b" ] && [ "$tname" != "rpl_crash_binlog_ib_3b" ]
  then
    $RM -f $MYSQL_TEST_DIR/var/log/$slave_ident-*bin.*
    $RM -f $slave_datadir/master.info $slave_datadir/relay-log.info
  fi
unknown's avatar
unknown committed
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031

  #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 \
1032
          --master-password="" \
unknown's avatar
unknown committed
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
          --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 \
1043
          --relay-log=$MYSQL_TEST_DIR/var/log/$slave_ident-relay-bin \
unknown's avatar
unknown committed
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
          --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 \
unknown's avatar
unknown committed
1056
          --skip-innodb --skip-ndbcluster --skip-slave-start \
unknown's avatar
unknown committed
1057 1058 1059
          --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
          --report-host=127.0.0.1 --report-user=root \
          --report-port=$slave_port \
1060
          --master-retry-count=10 \
unknown's avatar
unknown committed
1061
          -O slave_net_timeout=10 \
unknown's avatar
unknown committed
1062 1063 1064 1065 1066 1067 1068
           $SMALL_SERVER \
           $EXTRA_SLAVE_OPT $EXTRA_SLAVE_MYSQLD_OPT"
  CUR_MYERR=$slave_err
  CUR_MYSOCK=$slave_sock

  if [ x$DO_DDD = x1 ]
  then
1069
    $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
unknown's avatar
unknown committed
1070 1071 1072 1073
    manager_launch $slave_ident ddd -display $DISPLAY --debugger \
     "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD
  elif [ x$DO_GDB = x1 ]
  then
unknown's avatar
unknown committed
1074 1075
    if [ x$MANUAL_GDB = x1 ]
    then
unknown's avatar
unknown committed
1076
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
unknown's avatar
unknown committed
1077
      echo "To start gdb for the slave, type in another window:"
1078
      echo "cd $CWD ; gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD"
unknown's avatar
unknown committed
1079 1080
      wait_for_slave=1500
    else
unknown's avatar
unknown committed
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
      ( $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
unknown's avatar
unknown committed
1091 1092 1093
      manager_launch $slave_ident $XTERM -display $DISPLAY -title "Slave" -e \
      gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD
    fi
unknown's avatar
unknown committed
1094 1095 1096 1097
  else
    manager_launch $slave_ident $SLAVE_MYSQLD $slave_args
  fi
  eval "SLAVE$1_RUNNING=1"
1098
  sleep_until_file_created $slave_pid $wait_for_slave
unknown's avatar
unknown committed
1099
  wait_for_slave=$SLEEP_TIME_FOR_SECOND_SLAVE
unknown's avatar
unknown committed
1100 1101
}

unknown's avatar
unknown committed
1102 1103
mysql_start ()
{
unknown's avatar
unknown committed
1104
# We should not start the daemon here as we don't know the arguments
unknown's avatar
unknown committed
1105
# for the test.  Better to let the test start the daemon
unknown's avatar
unknown committed
1106 1107 1108 1109

#  $ECHO "Starting MySQL daemon"
#  start_master
#  start_slave
unknown's avatar
unknown committed
1110 1111
  cd $MYSQL_TEST_DIR
  return 1
unknown's avatar
unknown committed
1112 1113
}

unknown's avatar
unknown committed
1114 1115
stop_slave ()
{
1116 1117 1118
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ -n "$1" ] ;
unknown's avatar
unknown committed
1119
  then
1120 1121 1122
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
  else
   slave_pid=$SLAVE_MYPID
unknown's avatar
unknown committed
1123
  fi
1124 1125
  if [ x$this_slave_running = x1 ]
  then
1126 1127
    pid=`$CAT $slave_pid`
    manager_term $pid $slave_ident
1128
    if [ $? != 0 ] && [ -f $slave_pid ]
1129
    then # try harder!
1130
      $ECHO "slave not cooperating with mysqladmin, will try manual kill"
1131 1132
      kill $pid
      sleep_until_file_deleted $pid $slave_pid
1133 1134 1135 1136 1137 1138 1139 1140 1141
      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
unknown's avatar
unknown committed
1142
    fi
1143
    eval "SLAVE$1_RUNNING=0"
unknown's avatar
unknown committed
1144
  fi
unknown's avatar
unknown committed
1145
}
unknown's avatar
unknown committed
1146

1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
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
}

unknown's avatar
unknown committed
1157 1158 1159 1160
stop_master ()
{
  if [ x$MASTER_RUNNING = x1 ]
  then
1161 1162
    pid=`$CAT $MASTER_MYPID`
    manager_term $pid master
1163 1164
    if [ $? != 0 ] && [ -f $MASTER_MYPID ]
    then # try harder!
1165
      $ECHO "master not cooperating with mysqladmin, will try manual kill"
1166 1167
      kill $pid
      sleep_until_file_deleted $pid $MASTER_MYPID
1168 1169 1170 1171 1172 1173 1174 1175 1176
      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
unknown's avatar
unknown committed
1177
    fi
unknown's avatar
unknown committed
1178 1179 1180
    MASTER_RUNNING=0
  fi
}
unknown's avatar
unknown committed
1181

unknown's avatar
unknown committed
1182 1183
mysql_stop ()
{
1184 1185
 $ECHO  "Ending Tests"
 $ECHO  "Shutting-down MySQL daemon"
1186
 $ECHO  ""
unknown's avatar
unknown committed
1187
 stop_master
unknown's avatar
unknown committed
1188
 $ECHO "Master shutdown finished"
unknown's avatar
unknown committed
1189
 stop_slave
1190 1191
 stop_slave 1
 stop_slave 2
unknown's avatar
unknown committed
1192
 $ECHO "Slave shutdown finished"
unknown's avatar
unknown committed
1193

unknown's avatar
unknown committed
1194
 return 1
unknown's avatar
unknown committed
1195 1196
}

unknown's avatar
unknown committed
1197 1198 1199 1200 1201
mysql_restart ()
{
  mysql_stop
  mysql_start
  return 1
unknown's avatar
unknown committed
1202 1203 1204
}

mysql_loadstd () {
unknown's avatar
unknown committed
1205 1206

    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test
unknown's avatar
unknown committed
1207 1208 1209
    return 1
}

unknown's avatar
unknown committed
1210 1211 1212
run_testcase ()
{
 tf=$1
unknown's avatar
unknown committed
1213
 tname=`$BASENAME $tf .test`
unknown's avatar
unknown committed
1214 1215
 master_opt_file=$TESTDIR/$tname-master.opt
 slave_opt_file=$TESTDIR/$tname-slave.opt
1216 1217
 master_init_script=$TESTDIR/$tname-master.sh
 slave_init_script=$TESTDIR/$tname-slave.sh
1218
 slave_master_info_file=$TESTDIR/$tname.slave-mi
1219
 result_file=$tname
1220
 echo $tname > $CURRENT_TEST
unknown's avatar
unknown committed
1221
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`
1222
 if [ "$USE_MANAGER" = 1 ] ; then
1223 1224 1225 1226 1227
   many_slaves=`$EXPR \( \( $tname : rpl_failsafe \) != 0 \) \| \( \( $tname : rpl_chain_temp_table \) != 0 \)`
 fi
 if $EXPR "$tname" '<' "$START_FROM" > /dev/null ; then
   #skip_test $tname
   return
unknown's avatar
unknown committed
1228 1229
 fi

1230 1231 1232 1233
 if [ "$SKIP_TEST" ] ; then
   if $EXPR \( "$tname" : "$SKIP_TEST" \) > /dev/null ; then
     skip_test $tname
     return
unknown's avatar
unknown committed
1234
   fi
1235
 fi
1236

1237 1238
 if [ "$DO_TEST" ] ; then
   if $EXPR \( "$tname" : "$DO_TEST" \) > /dev/null ; then
unknown's avatar
unknown committed
1239
     : #empty command to keep some shells happy
1240 1241 1242
   else
     #skip_test $tname
     return
1243
   fi
1244
 fi
1245

1246 1247
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ; then
   skip_test $tname
1248 1249 1250
   return
 fi

1251 1252 1253 1254 1255 1256
 # 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

1257
 if [ -z "$USE_RUNNING_SERVER" ] ;
unknown's avatar
unknown committed
1258
 then
1259 1260
   if [ -f $master_opt_file ] ;
   then
unknown's avatar
unknown committed
1261
     EXTRA_MASTER_OPT=`$CAT $master_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1262 1263 1264 1265 1266 1267 1268
     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=" "
	 ;;
1269 1270 1271 1272 1273
       --result-file=*)
         result_file=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--result-file=;;"`
	 # Note that this must be set to space, not "" for test-reset to work
	 EXTRA_MASTER_OPT=" "
         ;;
1274
     esac
1275
     stop_master
unknown's avatar
unknown committed
1276
     echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1277
     start_master
1278
     TZ=$MY_TZ; export TZ
1279
   else
1280
     if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] || [ -f $master_init_script ]
1281 1282 1283
     then
       EXTRA_MASTER_OPT=""
       stop_master
unknown's avatar
unknown committed
1284
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1285
       start_master
unknown's avatar
unknown committed
1286 1287
     else
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
unknown's avatar
unknown committed
1288
     fi
1289
   fi
unknown's avatar
unknown committed
1290

unknown's avatar
unknown committed
1291
   do_slave_restart=0
1292 1293
   if [ -f $slave_opt_file ] ;
   then
unknown's avatar
unknown committed
1294
     EXTRA_SLAVE_OPT=`$CAT $slave_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1295 1296 1297 1298 1299
     do_slave_restart=1
   else
    if [ ! -z "$EXTRA_SLAVE_OPT" ] || [ x$SLAVE_RUNNING != x1 ] ;
    then
      EXTRA_SLAVE_OPT=""
unknown's avatar
unknown committed
1300 1301
      do_slave_restart=1
    fi
1302
   fi
unknown's avatar
fixed  
unknown committed
1303

1304 1305 1306 1307 1308 1309 1310
   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=""
unknown's avatar
unknown committed
1311 1312
       do_slave_restart=1
     fi
1313 1314 1315 1316
   fi

   if [ x$do_slave_restart = x1 ] ; then
     stop_slave
unknown's avatar
unknown committed
1317
     echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
1318
     start_slave
unknown's avatar
unknown committed
1319 1320
   else
     echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
1321
   fi
1322 1323 1324 1325
   if [ x$many_slaves = x1 ]; then
    start_slave 1
    start_slave 2
   fi
unknown's avatar
fixed  
unknown committed
1326
 fi
1327
 cd $MYSQL_TEST_DIR
unknown's avatar
unknown committed
1328

unknown's avatar
unknown committed
1329
 if [ -f $tf ] ; then
unknown's avatar
unknown committed
1330
    $RM -f r/$tname.*reject
1331
    mysql_test_args="-R r/$result_file.result $EXTRA_MYSQL_TEST_OPT"
1332
    if [ -z "$DO_CLIENT_GDB" ] ; then
1333
      `$MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`;
1334
    else
1335
      do_gdb_test "$mysql_test_args" "$tf"
1336
    fi
unknown's avatar
unknown committed
1337

unknown's avatar
unknown committed
1338 1339
    res=$?

1340
    pname=`$ECHO "$tname                        "|$CUT -c 1-24`
1341
    RES="$pname"
unknown's avatar
unknown committed
1342

1343 1344 1345 1346
    if [ x$many_slaves = x1 ] ; then
     stop_slave 1
     stop_slave 2
    fi
unknown's avatar
unknown committed
1347

unknown's avatar
unknown committed
1348
    if [ $res = 0 ]; then
1349 1350
      total_inc
      pass_inc
1351
      $ECHO "$RES$RES_SPACE [ pass ]"
1352
    else
1353
      # why the following ``if'' ? That is why res==1 is special ?
1354 1355 1356 1357
      if [ $res = 2 ]; then
        skip_inc
	$ECHO "$RES$RES_SPACE [ skipped ]"
      else
1358 1359 1360
        if [ $res -gt 2 ]; then
          $ECHO "mysqltest returned unexpected code $res, it has probably crashed" >> $TIMEFILE
        fi
1361
	total_inc
unknown's avatar
unknown committed
1362
        fail_inc
1363
	$ECHO "$RES$RES_SPACE [ fail ]"
1364 1365
        $ECHO
	error_is
1366
	show_failed_diff $result_file
unknown's avatar
unknown committed
1367
	$ECHO
1368
	if [ x$FORCE != x1 ] ; then
1369
	 $ECHO "Aborting: $tname failed. To continue, re-run with '--force'."
1370
	 $ECHO
unknown's avatar
unknown committed
1371 1372 1373
         if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	 then
	   mysql_stop
unknown's avatar
unknown committed
1374
	   stop_manager
unknown's avatar
unknown committed
1375
   	 fi
1376 1377
	 exit 1
	fi
unknown's avatar
unknown committed
1378

unknown's avatar
unknown committed
1379 1380 1381 1382
        if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	then
	  mysql_restart
	fi
1383
	$ECHO "Resuming Tests"
1384
	$ECHO ""
1385
      fi
unknown's avatar
unknown committed
1386
    fi
1387
  fi
unknown's avatar
unknown committed
1388 1389
}

unknown's avatar
unknown committed
1390 1391 1392 1393
######################################################################
# Main script starts here
######################################################################

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

unknown's avatar
unknown committed
1396 1397
[ "$DO_GCOV" ] && gcov_prepare
[ "$DO_GPROF" ] && gprof_prepare
unknown's avatar
unknown committed
1398

1399 1400
if [ -z "$USE_RUNNING_SERVER" ]
then
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
  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
unknown's avatar
unknown committed
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426

  # 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

unknown's avatar
unknown committed
1427 1428 1429 1430 1431
  if [ ! -z "$USE_NDBCLUSTER" ]
  then
  if [ -z "$USE_RUNNING_NDBCLUSTER" ]
  then
    # Kill any running ndbcluster stuff
unknown's avatar
unknown committed
1432
    ./ndb/ndbcluster --data-dir=$MYSQL_TEST_DIR/var --port-base=$NDBCLUSTER_PORT --stop
unknown's avatar
unknown committed
1433 1434 1435
  fi
  fi

unknown's avatar
unknown committed
1436
  # Remove files that can cause problems
1437
  $RM -rf $MYSQL_TEST_DIR/var/ndbcluster
unknown's avatar
unknown committed
1438 1439
  $RM -f $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*

1440 1441 1442
  # Remove old berkeley db log files that can confuse the server
  $RM -f $MASTER_MYDDIR/log.*

unknown's avatar
unknown committed
1443 1444
  wait_for_master=$SLEEP_TIME_FOR_FIRST_MASTER
  wait_for_slave=$SLEEP_TIME_FOR_FIRST_SLAVE
1445 1446
  $ECHO "Installing Test Databases"
  mysql_install_db
unknown's avatar
unknown committed
1447 1448 1449 1450 1451 1452

  if [ ! -z "$USE_NDBCLUSTER" ]
  then
  if [ -z "$USE_RUNNING_NDBCLUSTER" ]
  then
    echo "Starting ndbcluster"
1453
    ./ndb/ndbcluster --port-base=$NDBCLUSTER_PORT --small --diskless --initial --data-dir=$MYSQL_TEST_DIR/var || exit 1
1454
    USE_NDBCLUSTER="--ndb-connectstring=\"host=localhost:$NDBCLUSTER_PORT\""
unknown's avatar
unknown committed
1455
  else
1456 1457
    USE_NDBCLUSTER="--ndb-connectstring=\"$USE_RUNNING_NDBCLUSTER\""
    echo "Using ndbcluster at $USE_NDBCLUSTER"
unknown's avatar
unknown committed
1458 1459 1460
  fi
  fi

unknown's avatar
unknown committed
1461
  start_manager
unknown's avatar
unknown committed
1462

unknown's avatar
unknown committed
1463
# Do not automagically start daemons if we are in gdb or running only one test
unknown's avatar
unknown committed
1464
# case
1465 1466 1467 1468 1469 1470
  if [ -z "$DO_GDB" ] && [ -z "$DO_DDD" ]
  then
    mysql_start
  fi
  $ECHO  "Loading Standard Test Databases"
  mysql_loadstd
unknown's avatar
unknown committed
1471 1472
fi

1473 1474 1475 1476
if [ "x$START_AND_EXIT" = "x1" ] ; then
 echo "Servers started, exiting"
 exit
fi
unknown's avatar
unknown committed
1477

1478
$ECHO  "Starting Tests"
unknown's avatar
unknown committed
1479

1480 1481 1482
#
# This can probably be deleted
#
unknown's avatar
unknown committed
1483 1484
if [ "$DO_BENCH" = 1 ]
then
1485 1486 1487 1488 1489 1490 1491
  start_master

  if [ ! -z "$USE_NDBCLUSTER" ]
  then
    EXTRA_BENCH_ARGS="--create-options=TYPE=ndb"
  fi 

unknown's avatar
unknown committed
1492 1493 1494 1495
  BENCHDIR=$BASEDIR/sql-bench/
  savedir=`pwd`
  cd $BENCHDIR
  if [ -z "$1" ]
unknown's avatar
unknown committed
1496
  then
1497
    ./run-all-tests --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS
unknown's avatar
unknown committed
1498
  else
unknown's avatar
unknown committed
1499 1500
    if [ -x "./$1" ]
    then
1501
       ./$1 --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS
unknown's avatar
unknown committed
1502 1503 1504
    else
      echo "benchmark $1 not found"
    fi
unknown's avatar
unknown committed
1505
  fi
unknown's avatar
unknown committed
1506 1507 1508 1509
  cd $savedir
  mysql_stop
  stop_manager
  exit
unknown's avatar
unknown committed
1510 1511
fi

unknown's avatar
unknown committed
1512
$ECHO
1513
$ECHO " TEST                           RESULT"
unknown's avatar
unknown committed
1514 1515
$ECHO $DASH72

unknown's avatar
unknown committed
1516
if [ -z "$1" ] ;
unknown's avatar
unknown committed
1517
then
1518 1519 1520
  if [ x$RECORD = x1 ]; then
    $ECHO "Will not run in record mode without a specific test case."
  else
1521 1522 1523 1524
    for tf in $TESTDIR/*.$TESTSUFFIX
    do
      run_testcase $tf
    done
1525 1526
    $RM -f $TIMEFILE	# Remove for full test
  fi
unknown's avatar
unknown committed
1527
else
unknown's avatar
unknown committed
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
  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
1538
fi
unknown's avatar
unknown committed
1539

unknown's avatar
unknown committed
1540 1541
$ECHO $DASH72
$ECHO
1542

1543
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
unknown's avatar
unknown committed
1544 1545 1546
then
    mysql_stop
fi
unknown's avatar
unknown committed
1547

unknown's avatar
unknown committed
1548 1549 1550 1551 1552
if [ ! -z "$USE_NDBCLUSTER" ]
then
if [ -z "$USE_RUNNING_NDBCLUSTER" ]
then
  # Kill any running ndbcluster stuff
unknown's avatar
unknown committed
1553
  ./ndb/ndbcluster --data-dir=$MYSQL_TEST_DIR/var --port-base=$NDBCLUSTER_PORT --stop
unknown's avatar
unknown committed
1554 1555 1556
fi
fi

unknown's avatar
unknown committed
1557
stop_manager
unknown's avatar
unknown committed
1558
report_stats
unknown's avatar
unknown committed
1559
$ECHO
unknown's avatar
unknown committed
1560

unknown's avatar
unknown committed
1561
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
unknown's avatar
unknown committed
1562
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
unknown's avatar
unknown committed
1563

unknown's avatar
unknown committed
1564
exit 0