mysql-test-run.sh 52.4 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>
paul@ice.snake.net's avatar
Typo.  
paul@ice.snake.net committed
4
# Slightly updated by Monty
5
# Cleaned up again by Matt
6
# Fixed by Sergei
7
# List of failed cases (--force) backported from 4.1 by Joerg
8
# :-)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
9 10 11 12 13

#++
# Access Definitions
#--
DB=test
monty@mysql.com's avatar
monty@mysql.com committed
14
DBPASSWD=""
15
VERBOSE=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
16
USE_MANAGER=0
17 18
MY_TZ=GMT-3
TZ=$MY_TZ; export TZ # for UNIX_TIMESTAMP tests to work
19
LOCAL_SOCKET=@MYSQL_UNIX_ADDR@
20
MYSQL_TCP_PORT=@MYSQL_TCP_PORT@
bk@work.mysql.com's avatar
bk@work.mysql.com committed
21

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

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

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

44 45 46 47
# Standard functions

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


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

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

105 106 107 108 109
# For the future

wait_for_pid()
{
  pid=$1
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
110
  #$WAIT_PID pid $SLEEP_TIME_FOR_DELETE
111 112
}

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

115 116
SED=sed

117 118
BASENAME=`which basename`
if test $? != 0; then exit 1; fi
119
DIFF=`which diff | $SED q`
120
if test $? != 0; then exit 1; fi
121 122
CAT=cat
CUT=cut
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
123
HEAD=head
124 125 126 127
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
128
GREP=grep
129
if test $? != 0; then exit 1; fi
130 131
PRINTF=printf
RM=rm
132
if test $? != 0; then exit 1; fi
133
TR=tr
134 135
XARGS=`which xargs`
if test $? != 0; then exit 1; fi
136
SORT=sort
137 138 139 140 141

# Are we using a source or a binary distribution?

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
157 158 159
#++
# Misc. Definitions
#--
160

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

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
167
#BASEDIR is always one above mysql-test directory
bk@work.mysql.com's avatar
bk@work.mysql.com committed
168 169 170 171
CWD=`pwd`
cd ..
BASEDIR=`pwd`
cd $CWD
172
MYSQL_TEST_DIR=$BASEDIR/mysql-test
173
export MYSQL_TEST_DIR
174
STD_DATA=$MYSQL_TEST_DIR/std_data
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
175
hostname=`hostname`		# Installed in the mysql privilege table
176

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

201 202 203 204 205 206 207
#
# Allow anyone in the group to see the generated database files
#
UMASK=0660
UMASK_DIR=0770
export UMASK UMASK_DIR

sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
208
MASTER_RUNNING=0
209
MASTER1_RUNNING=0
210
MASTER_MYPORT=9306
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
211
SLAVE_RUNNING=0
212
SLAVE_MYPORT=9308 # leave room for 2 masters for cluster tests
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
213
MYSQL_MANAGER_PORT=9305 # needs to be out of the way of slaves
214
NDBCLUSTER_PORT=9350
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
215 216 217
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
218
NO_SLAVE=0
219
USER_TEST=
kent@mysql.com's avatar
kent@mysql.com committed
220
FAILED_CASES=
221

222
EXTRA_MASTER_OPT=""
223
EXTRA_MYSQL_TEST_OPT=""
224
EXTRA_MYSQLDUMP_OPT=""
225
EXTRA_MYSQLSHOW_OPT=""
226
EXTRA_MYSQLBINLOG_OPT=""
227
USE_RUNNING_SERVER=0
228
USE_NDBCLUSTER=@USE_NDBCLUSTER@
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
229
USE_RUNNING_NDBCLUSTER=""
230 231
USE_PURIFY=""
PURIFY_LOGS=""
232 233
DO_GCOV=""
DO_GDB=""
234
MANUAL_GDB=""
235
DO_DDD=""
236
DO_CLIENT_GDB=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
237
SLEEP_TIME_AFTER_RESTART=1
238
SLEEP_TIME_FOR_DELETE=10
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
239
SLEEP_TIME_FOR_FIRST_MASTER=400		# Enough time to create innodb tables
240
SLEEP_TIME_FOR_SECOND_MASTER=400
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
241
SLEEP_TIME_FOR_FIRST_SLAVE=400
242
SLEEP_TIME_FOR_SECOND_SLAVE=300
243
CHARACTER_SET=latin1
244
DBUSER=""
245 246
START_WAIT_TIMEOUT=10
STOP_WAIT_TIMEOUT=10
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
247
MYSQL_TEST_SSL_OPTS=""
kent@mysql.com's avatar
kent@mysql.com committed
248
USE_TIMER=""
kent@mysql.com's avatar
kent@mysql.com committed
249
USE_EMBEDDED_SERVER=""
250
TEST_MODE=""
251

252
NDB_MGM_EXTRA_OPTS=
253 254 255
NDB_MGMD_EXTRA_OPTS=
NDBD_EXTRA_OPTS=

256 257
while test $# -gt 0; do
  case "$1" in
258 259 260
    --embedded-server)
      USE_EMBEDDED_SERVER=1
      USE_MANAGER=0 NO_SLAVE=1
kent@mysql.com's avatar
kent@mysql.com committed
261
      USE_RUNNING_SERVER=0
262 263 264 265
      TEST_MODE="$TEST_MODE embedded" ;;
    --purify)
      USE_PURIFY=1
      USE_MANAGER=0
kent@mysql.com's avatar
kent@mysql.com committed
266
      USE_RUNNING_SERVER=0
267
      TEST_MODE="$TEST_MODE purify" ;;
268 269
    --user=*) DBUSER=`$ECHO "$1" | $SED -e "s;--user=;;"` ;;
    --force)  FORCE=1 ;;
kent@mysql.com's avatar
kent@mysql.com committed
270
    --timer)  USE_TIMER=1 ;;
271
    --verbose-manager)  MANAGER_QUIET_OPT="" ;;
272 273 274 275 276
    --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=;;"` ;;
277 278
    --local)   USE_RUNNING_SERVER=0 ;;
    --extern)  USE_RUNNING_SERVER=1 ;;
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
279
    --with-ndbcluster)
280
      USE_NDBCLUSTER="--ndbcluster" ;;
281
    --ndb-connectstring=*)
282
      USE_NDBCLUSTER="--ndbcluster" ;
283
      USE_RUNNING_NDBCLUSTER=`$ECHO "$1" | $SED -e "s;--ndb-connectstring=;;"` ;;
284 285
    --ndb_mgm-extra-opts=*)
      NDB_MGM_EXTRA_OPTS=`$ECHO "$1" | $SED -e "s;--ndb_mgm-extra-opts=;;"` ;;
286 287 288 289
    --ndb_mgmd-extra-opts=*)
      NDB_MGMD_EXTRA_OPTS=`$ECHO "$1" | $SED -e "s;--ndb_mgmd-extra-opts=;;"` ;;
    --ndbd-extra-opts=*)
      NDBD_EXTRA_OPTS=`$ECHO "$1" | $SED -e "s;--ndbd-extra-opts=;;"` ;;
290
    --tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;;
291 292 293 294 295
    --local-master)
      MASTER_MYPORT=3306;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --host=127.0.0.1 \
      --port=$MYSQL_MYPORT"
      LOCAL_MASTER=1 ;;
296 297
    --master_port=*) MASTER_MYPORT=`$ECHO "$1" | $SED -e "s;--master_port=;;"` ;;
    --slave_port=*) SLAVE_MYPORT=`$ECHO "$1" | $SED -e "s;--slave_port=;;"` ;;
298
    --manager-port=*) MYSQL_MANAGER_PORT=`$ECHO "$1" | $SED -e "s;--manager_port=;;"` ;;
299
    --ndbcluster_port=*) NDBCLUSTER_PORT=`$ECHO "$1" | $SED -e "s;--ndbcluster_port=;;"` ;;
300 301
    --with-openssl)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
302 303 304
     --ssl-ca=$BASEDIR/SSL/cacert.pem \
     --ssl-cert=$BASEDIR/SSL/server-cert.pem \
     --ssl-key=$BASEDIR/SSL/server-key.pem"
305
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
tonu@x153.internalnet's avatar
tonu@x153.internalnet committed
306 307
     --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
308 309 310 311
     --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
312
    --no-manager | --skip-manager) USE_MANAGER=0 ;;
313 314
    --manager)
     USE_MANAGER=1
315
     USE_RUNNING_SERVER=0
316
     ;;
317 318
    --start-and-exit)
     START_AND_EXIT=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
319
     ;;
320
    --socket=*) LOCAL_SOCKET=`$ECHO "$1" | $SED -e "s;--socket=;;"` ;;
321
    --skip-rpl) NO_SLAVE=1 ;;
322
    --skip-test=*) SKIP_TEST=`$ECHO "$1" | $SED -e "s;--skip-test=;;"`;;
323
    --do-test=*) DO_TEST=`$ECHO "$1" | $SED -e "s;--do-test=;;"`;;
324
    --start-from=* ) START_FROM=`$ECHO "$1" | $SED -e "s;--start-from=;;"` ;;
325 326 327 328
    --warnings | --log-warnings)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --log-warnings"
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --log-warnings"
     ;;
329 330 331
    --wait-timeout=*)
     START_WAIT_TIMEOUT=`$ECHO "$1" | $SED -e "s;--wait-timeout=;;"`
     STOP_WAIT_TIMEOUT=$START_WAIT_TIMEOUT;;
332 333 334
    --record)
      RECORD=1;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
335 336 337 338 339
    --small-bench)
      DO_SMALL_BENCH=1
      DO_BENCH=1
      NO_SLAVE=1
      ;;
340 341 342
    --bench)
      DO_BENCH=1
      NO_SLAVE=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
343
      ;;
344 345
    --big*)			# Actually --big-test
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
346 347
    --compress)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
348 349
    --sleep=*)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1"
350
      SLEEP_TIME_AFTER_RESTART=`$ECHO "$1" | $SED -e "s;--sleep=;;"`
351
      ;;
352
    --ps-protocol)
353
      TEST_MODE="$TEST_MODE ps-protocol" EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
354 355 356
    --user-test=*)
      USER_TEST=`$ECHO "$1" | $SED -e "s;--user-test=;;"`
      ;;
357
    --mysqld=*)
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
358
       TMP=`$ECHO "$1" | $SED -e "s;--mysqld=;;"`
359
       EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $TMP"
360
       EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $TMP"
361
       ;;
362 363 364 365 366 367
    --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
368
      GCOV=`which gcov`
369
      ;;
370 371
    --gprof )
      DO_GPROF=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
372
      ;;
373
    --gdb )
374 375
      START_WAIT_TIMEOUT=300
      STOP_WAIT_TIMEOUT=300
376
      if [ x$BINARY_DIST = x1 ] ; then
377
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --gdb option"
378 379
      fi
      DO_GDB=1
380 381
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
382 383
      # This needs to be checked properly
      # USE_MANAGER=1
384
      USE_RUNNING_SERVER=0
385
      ;;
386 387 388 389 390
    --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
391 392
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
393
      ;;
394 395 396
    --manual-gdb )
      DO_GDB=1
      MANUAL_GDB=1
397
      USE_RUNNING_SERVER=0
398 399
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
400
      ;;
401 402
    --ddd )
      if [ x$BINARY_DIST = x1 ] ; then
403
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --ddd option"
404 405
      fi
      DO_DDD=1
406
      USE_RUNNING_SERVER=0
407 408
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
409
      ;;
410
    --valgrind | --valgrind-all)
guilhem@mysql.com's avatar
guilhem@mysql.com committed
411 412 413
      VALGRIND=`which valgrind` # this will print an error if not found
      # Give good warning to the user and stop
      if [ -z "$VALGRIND" ] ; then
414
        $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://valgrind.kde.org ."
guilhem@mysql.com's avatar
guilhem@mysql.com committed
415 416
        exit 1
      fi
417 418
      # >=2.1.2 requires the --tool option, some versions write to stdout, some to stderr
      valgrind --help 2>&1 | grep "\-\-tool" > /dev/null && VALGRIND="$VALGRIND --tool=memcheck"
419
      VALGRIND="$VALGRIND --alignment=8 --leak-check=yes --num-callers=16 --suppressions=$CWD/valgrind.supp"
420 421
      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
422
      SLEEP_TIME_AFTER_RESTART=10
423
      SLEEP_TIME_FOR_DELETE=60
424
      USE_RUNNING_SERVER=0
425 426 427 428
      if test "$1" = "--valgrind-all"
      then
        VALGRIND="$VALGRIND -v --show-reachable=yes"
      fi
429 430 431 432 433
      ;;
    --valgrind-options=*)
      TMP=`$ECHO "$1" | $SED -e "s;--valgrind-options=;;"`
      VALGRIND="$VALGRIND $TMP"
      ;;
434
    --skip-ndbcluster | --skip-ndb)
435
      USE_NDBCLUSTER=""
436 437
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-ndbcluster"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-ndbcluster"
438
      ;;
439 440 441 442
    --skip-*)
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $1"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $1"
      ;;
443 444
    --strace-client )
      STRACE_CLIENT=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
445
      ;;
446
    --debug)
447
      EXTRA_MASTER_MYSQLD_TRACE=" \
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
448
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/master.trace"
449
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
450
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/slave.trace"
451 452
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqltest.trace"
453 454
      EXTRA_MYSQLDUMP_OPT="$EXTRA_MYSQLDUMP_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqldump.trace"
455 456
      EXTRA_MYSQLSHOW_OPT="$EXTRA_MYSQLSHOW_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlshow.trace"
457 458
      EXTRA_MYSQLBINLOG_OPT="$EXTRA_MYSQLBINLOG_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlbinlog.trace"
459
      EXTRA_MYSQL_CLIENT_TEST_OPT="--debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysql_client_test.trace"
460
      ;;
461 462 463
    --fast)
      FAST_START=1
      ;;
464 465 466
    --use-old-data)
      USE_OLD_DATA=1;
      ;;
467 468 469 470 471 472
    -- )  shift; break ;;
    --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
    * ) break ;;
  esac
  shift
done
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
473

474 475 476 477 478 479 480
if [ -z "$TEST_MODE" ] ; then
  TEST_MODE="default"
else
  # Remove the leading space if any
  TEST_MODE=`echo $TEST_MODE | sed 's/^ *//'`
fi

bk@work.mysql.com's avatar
bk@work.mysql.com committed
481 482 483
#++
# mysqld Environment Parameters
#--
484

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
485
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
486 487
MANAGER_PID_FILE="$MYRUN_DIR/manager.pid"

488
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
489
MASTER_MYSOCK="$MYSQL_TMP_DIR/master.sock"
490
MASTER_MYSOCK1=$MYSQL_MYSOCK"1"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
491 492 493
MASTER_MYPID="$MYRUN_DIR/master.pid"
MASTER_MYLOG="$MYSQL_TEST_DIR/var/log/master.log"
MASTER_MYERR="$MYSQL_TEST_DIR/var/log/master.err"
494 495

SLAVE_MYDDIR="$MYSQL_TEST_DIR/var/slave-data"
496
SLAVE_MYSOCK="$MYSQL_TMP_DIR/slave.sock"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
497 498 499
SLAVE_MYPID="$MYRUN_DIR/slave.pid"
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/slave.log"
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/slave.err"
500

501
CURRENT_TEST="$MYSQL_TEST_DIR/var/log/current_test"
502
SMALL_SERVER="--key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M"
503

504
export MASTER_MYPORT SLAVE_MYPORT MYSQL_TCP_PORT MASTER_MYSOCK MASTER_MYSOCK1
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
505

506
NDBCLUSTER_OPTS="--port=$NDBCLUSTER_PORT --data-dir=$MYSQL_TEST_DIR/var --ndb_mgm-extra-opts=$NDB_MGM_EXTRA_OPTS --ndb_mgmd-extra-opts=$NDB_MGMD_EXTRA_OPTS --ndbd-extra-opts=$NDBD_EXTRA_OPTS"
507
NDB_BACKUP_DIR=$MYSQL_TEST_DIR/var/ndbcluster-$NDBCLUSTER_PORT
508
NDB_TOOLS_OUTPUT=$MYSQL_TEST_DIR/var/log/ndb_tools.log
509

510 511 512 513
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
514
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
515

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
516 517 518 519 520 521 522 523
# 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
524
[ -d $MYSQL_TEST_DIR/var/log ] || mkdir $MYSQL_TEST_DIR/var/log
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
525

526
if test ${COLUMNS:-0} -lt 80 ; then COLUMNS=80 ; fi
527
E=`$EXPR $COLUMNS - 8`
kent@mysql.com's avatar
kent@mysql.com committed
528
DASH72=`$ECHO '-------------------------------------------------------'|$CUT -c 1-$E`
529

530 531 532
# on source dist, we pick up freshly build executables
# on binary, use what is installed
if [ x$SOURCE_DIST = x1 ] ; then
kent@mysql.com's avatar
kent@mysql.com committed
533
 if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
534 535
   if [ -f "$BASEDIR/libmysqld/examples/mysqltest_embedded" ] ; then
     MYSQL_TEST="$VALGRIND $BASEDIR/libmysqld/examples/mysqltest_embedded"
kent@mysql.com's avatar
kent@mysql.com committed
536
   else
537
     echo "Fatal error: Cannot find embedded server 'mysqltest_embedded'" 1>&2
kent@mysql.com's avatar
kent@mysql.com committed
538 539
     exit 1
   fi
540
   MYSQL_CLIENT_TEST="$BASEDIR/libmysqld/examples/mysql_client_test_embedded"
541
 else
542 543 544 545
   MYSQLD="$BASEDIR/sql/mysqld"
   if [ -n "$VALGRIND" ] ; then
     MYSQLD="$VALGRIND $MYSQLD"
   fi
kent@mysql.com's avatar
kent@mysql.com committed
546 547 548 549 550 551 552
   if [ -f "$BASEDIR/client/.libs/lt-mysqltest" ] ; then
     MYSQL_TEST="$BASEDIR/client/.libs/lt-mysqltest"
   elif [ -f "$BASEDIR/client/.libs/mysqltest" ] ; then
     MYSQL_TEST="$BASEDIR/client/.libs/mysqltest"
   else
     MYSQL_TEST="$BASEDIR/client/mysqltest"
   fi
553
   MYSQL_CLIENT_TEST="$BASEDIR/tests/mysql_client_test"
554
 fi
555
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
556
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
557
 else
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
558
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
559
 fi
560 561 562 563 564
 if [ -f "$BASEDIR/client/.libs/mysqlshow" ] ; then
   MYSQL_SHOW="$BASEDIR/client/.libs/mysqlshow"
 else
   MYSQL_SHOW="$BASEDIR/client/mysqlshow"
 fi
565
 if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
566
   MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog"
567
 else
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
568
   MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog"
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
569
 fi
570 571 572
 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
573

monty@mysql.com's avatar
monty@mysql.com committed
574 575
 CLIENT_BINDIR="$BASEDIR/client"
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
576
 WAIT_PID="$BASEDIR/extra/mysql_waitpid"
577 578 579
 MYSQL_MANAGER_CLIENT="$CLIENT_BINDIR/mysqltestmanagerc"
 MYSQL_MANAGER="$BASEDIR/tools/mysqltestmanager"
 MYSQL_MANAGER_PWGEN="$CLIENT_BINDIR/mysqltestmanager-pwgen"
monty@mysql.com's avatar
monty@mysql.com committed
580
 MYSQL="$CLIENT_BINDIR/mysql"
581
 LANGUAGE="$BASEDIR/sql/share/english/"
582
 CHARSETSDIR="$BASEDIR/sql/share/charsets"
583
 INSTALL_DB="./install_test_db"
584
 MYSQL_FIX_SYSTEM_TABLES="$BASEDIR/scripts/mysql_fix_privilege_tables"
585
 NDB_TOOLS_DIR="$BASEDIR/ndb/tools"
586
 NDB_MGM="$BASEDIR/ndb/src/mgmclient/ndb_mgm"
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611

 if [ -n "$USE_PURIFY" ] ; then
   PSUP="$MYSQL_TEST_DIR/purify.suppress"
   echo "suppress UMR rw_read_held; mi_open; ha_myisam::open64; handler::ha_open; openfrm" >  $PSUP
   echo "suppress UMR my_end; main" >> $PSUP
   echo "suppress UMR _doprnt; fprintf; my_end; main" >> $PSUP
   PURIFYOPTIONS="-windows=no -log-file=%v.purifylog -append-logfile -add-suppression-files=$PSUP"
   if [ -f "${MYSQL_TEST}-purify" ] ; then
     MYSQL_TEST="${MYSQL_TEST}-purify"
     PLOG="$MYSQL_TEST.purifylog"
     if [ -f $PLOG ]; then
       mv $PLOG $PLOG.$$
     fi
     PURIFY_LOGS="$PLOG"
   fi
   if [ -f "${MYSQLD}-purify" ] ; then
     MYSQLD="${MYSQLD}-purify"
     PLOG="$MYSQLD.purifylog"
     if [ -f $PLOG ]; then
       mv $PLOG $PLOG.$$
     fi
     PURIFY_LOGS="$PURIFY_LOGS $PLOG"
   fi
 fi

612
else
613 614 615 616 617 618 619 620

 # We have a binary installation. Note that this can be both from
 # unpacking a MySQL AB binary distribution (created using
 # "scripts/make_binary_distribution", and from a "make install".
 # Unfortunately the structure differs a bit, for a "make install"
 # currently all binaries are in "bin", for a MySQL AB packaging
 # some are in "tests".

621 622
 if test -x "$BASEDIR/libexec/mysqld"
 then
623
   MYSQLD="$VALGRIND $BASEDIR/libexec/mysqld"
624
 else
625
   MYSQLD="$VALGRIND $BASEDIR/bin/mysqld"
626
 fi
monty@mysql.com's avatar
monty@mysql.com committed
627
 CLIENT_BINDIR="$BASEDIR/bin"
628 629 630 631 632 633
 if test -d "$BASEDIR/tests"
 then
   TESTS_BINDIR="$BASEDIR/tests"
 else
   TESTS_BINDIR="$BASEDIR/bin"
 fi
monty@mysql.com's avatar
monty@mysql.com committed
634 635
 MYSQL_TEST="$CLIENT_BINDIR/mysqltest"
 MYSQL_DUMP="$CLIENT_BINDIR/mysqldump"
636
 MYSQL_SHOW="$CLIENT_BINDIR/mysqlshow"
monty@mysql.com's avatar
monty@mysql.com committed
637 638 639
 MYSQL_BINLOG="$CLIENT_BINDIR/mysqlbinlog"
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
 WAIT_PID="$CLIENT_BINDIR/mysql_waitpid"
640 641 642
 MYSQL_MANAGER="$CLIENT_BINDIR/mysqltestmanager"
 MYSQL_MANAGER_CLIENT="$CLIENT_BINDIR/mysqltestmanagerc"
 MYSQL_MANAGER_PWGEN="$CLIENT_BINDIR/mysqltestmanager-pwgen"
monty@mysql.com's avatar
monty@mysql.com committed
643
 MYSQL="$CLIENT_BINDIR/mysql"
644
 INSTALL_DB="./install_test_db --bin"
monty@mysql.com's avatar
monty@mysql.com committed
645
 MYSQL_FIX_SYSTEM_TABLES="$CLIENT_BINDIR/mysql_fix_privilege_tables"
646
 NDB_TOOLS_DIR="$CLIENT_BINDIR"
647
 NDB_MGM="$CLIENT_BINDIR/ndb_mgm"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
648
 if test -d "$BASEDIR/share/mysql/english"
649 650
 then
   LANGUAGE="$BASEDIR/share/mysql/english/"
651
   CHARSETSDIR="$BASEDIR/share/mysql/charsets"
652 653
 else
   LANGUAGE="$BASEDIR/share/english/"
654
   CHARSETSDIR="$BASEDIR/share/charsets"
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
 fi
 if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
   if [ -f "$CLIENT_BINDIR/mysqltest_embedded" ] ; then
     MYSQL_TEST="$VALGRIND $CLIENT_BINDIR/mysqltest_embedded"
   else
     echo "Fatal error: Cannot find embedded server 'mysqltest_embedded'" 1>&2
     exit 1
   fi
   if [ -d "$BASEDIR/tests/mysql_client_test_embedded" ] ; then
     MYSQL_CLIENT_TEST="$TESTS_BINDIR/mysql_client_test_embedded"
   else
     MYSQL_CLIENT_TEST="$CLIENT_BINDIR/mysql_client_test_embedded"
   fi
 else
   MYSQL_TEST="$CLIENT_BINDIR/mysqltest"
   MYSQL_CLIENT_TEST="$CLIENT_BINDIR/mysql_client_test"
 fi
672 673
fi

674 675 676 677 678 679 680 681 682 683
if [ -z "$MASTER_MYSQLD" ]
then
MASTER_MYSQLD=$MYSQLD
fi

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

684 685 686 687
# If we should run all tests cases, we will use a local server for that

if [ -z "$1" ]
then
688
   USE_RUNNING_SERVER=0
689
fi
690
if [ $USE_RUNNING_SERVER -eq 1 ]
691
then
692
   MASTER_MYSOCK=$LOCAL_SOCKET;
693
   DBUSER=${DBUSER:-test}
694
else
695
   DBUSER=${DBUSER:-root}		# We want to do FLUSH xxx commands
696
fi
697 698 699

if [ -w / ]
then
monty@mysql.com's avatar
monty@mysql.com committed
700 701 702
  # 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"
703 704
fi

705
MYSQL_CLIENT_TEST="$MYSQL_CLIENT_TEST --no-defaults --testcase --user=root --socket=$MASTER_MYSOCK --port=$MYSQL_TCP_PORT --silent $EXTRA_MYSQL_CLIENT_TEST_OPT"
706
MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
707
MYSQL_SHOW="$MYSQL_SHOW -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLSHOW_OPT"
708
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR  --character-sets-dir=$CHARSETSDIR $EXTRA_MYSQLBINLOG_OPT"
709 710
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"
MYSQL="$MYSQL --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD"
711
export MYSQL MYSQL_DUMP MYSQL_SHOW MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES
712
export CLIENT_BINDIR MYSQL_CLIENT_TEST CHARSETSDIR
713
export NDB_TOOLS_DIR
714
export NDB_MGM
715
export NDB_BACKUP_DIR
716
export NDB_TOOLS_OUTPUT
717
export PURIFYOPTIONS
718 719
NDB_STATUS_OK=1
export NDB_STATUS_OK
720

721
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
722
 --user=$DBUSER --password=$DBPASSWD --silent -v --skip-safemalloc \
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
723
 --tmpdir=$MYSQL_TMP_DIR --port=$MASTER_MYPORT $MYSQL_TEST_SSL_OPTS"
kent@mysql.com's avatar
kent@mysql.com committed
724 725 726
if [ x$USE_TIMER = x1 ] ; then
  MYSQL_TEST_ARGS="$MYSQL_TEST_ARGS --timer-file=$MY_LOG_DIR/timer"
fi
727 728 729
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
730 731 732
GDB_MASTER_INIT=$MYSQL_TMP_DIR/gdbinit.master
GDB_SLAVE_INIT=$MYSQL_TMP_DIR/gdbinit.slave
GCOV_MSG=$MYSQL_TMP_DIR/mysqld-gcov.out
733 734 735 736
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
737
TIMEFILE="$MYSQL_TEST_DIR/var/log/mysqltest-time"
738 739 740
if [ -n "$DO_CLIENT_GDB" -o -n "$DO_GDB" ] ; then
  XTERM=`which xterm`
fi
741

742
export MYSQL MYSQL_DUMP MYSQL_SHOW MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES CLIENT_BINDIR MASTER_MYSOCK
monty@mysql.com's avatar
monty@mysql.com committed
743

bk@work.mysql.com's avatar
bk@work.mysql.com committed
744 745 746 747
#++
# Function Definitions
#--

748 749
prompt_user ()
{
750
 $ECHO $1
751
 read unused
752 753
}

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

756 757 758 759
show_failed_diff ()
{
  reject_file=r/$1.reject
  result_file=r/$1.result
760
  eval_file=r/$1.eval
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
761

762 763 764 765
  if [ -f $eval_file ]
  then
    result_file=$eval_file
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
766

767 768 769 770
  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
771
    $DIFF -c $result_file $reject_file
772
    echo "-------------------------------------------------------"
773
    echo "Please follow the instructions outlined at"
774
    echo "http://www.mysql.com/doc/en/Reporting_mysqltest_bugs.html"
775
    echo "to find the reason to this problem and how to report this."
776
    echo ""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
777
  fi
778
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
779

780 781 782 783 784 785
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
786
  $XTERM -title "Client" -e gdb -x $GDB_CLIENT_INIT $MYSQL_TEST_BIN
787 788
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
789
error () {
790
    $ECHO  "Error:  $1"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
791 792 793
    exit 1
}

794
error_is () {
795 796
    $ECHO "Errors are (from $TIMEFILE) :"
    $CAT < $TIMEFILE
797
    $ECHO "(the last lines may be the most important ones)"
798 799
}

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
800
prefix_to_8() {
801
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
802 803
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
804
pass_inc () {
805
    TOT_PASS=`$EXPR $TOT_PASS + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
806 807 808
}

fail_inc () {
809
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
810 811
}

812 813 814 815
skip_inc () {
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
816
total_inc () {
817
    TOT_TEST=`$EXPR $TOT_TEST + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
818 819
}

820 821 822 823 824 825

skip_test() {
   USERT="    ...."
   SYST="    ...."
   REALT="    ...."
   pname=`$ECHO "$1                        "|$CUT -c 1-24`
826
   RES="$pname"
827 828 829 830
   skip_inc
   $ECHO "$RES$RES_SPACE [ skipped ]"
}

831 832 833 834 835 836 837 838 839 840 841

disable_test() {
   USERT="    ...."
   SYST="    ...."
   REALT="    ...."
   pname=`$ECHO "$1                        "|$CUT -c 1-24`
   RES="$pname"
   skip_inc
   $ECHO "$RES$RES_SPACE [ disabled ]  $2"
}

kent@mysql.com's avatar
Merge  
kent@mysql.com committed
842

843 844 845 846 847 848 849 850 851 852 853
report_current_test () {
   tname=$1
   echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
   if [ -n "$PURIFY_LOGS" ] ; then
     for log in $PURIFY_LOGS
     do
       echo "CURRENT_TEST: $tname" >> $log
     done
   fi
}

kent@mysql.com's avatar
Merge  
kent@mysql.com committed
854

bk@work.mysql.com's avatar
bk@work.mysql.com committed
855
report_stats () {
856
    if [ $TOT_FAIL = 0 ]; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
857
	$ECHO "All $TOT_TEST tests were successful."
bk@work.mysql.com's avatar
bk@work.mysql.com committed
858
    else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
859 860 861 862 863 864
	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`
865
	$ECHO  "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% were successful."
866
	$ECHO ""
867
        $ECHO "The log files in $MY_LOG_DIR may give you some hint"
868 869
	$ECHO "of what when wrong."
	$ECHO "If you want to report this error, please read first the documentation at"
870
        $ECHO "http://www.mysql.com/doc/en/MySQL_test_suite.html"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
871
    fi
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
872

873
    if [ $USE_RUNNING_SERVER -eq 0 ]
874 875
    then

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
876 877 878 879
    # 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
880
    $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' \
881 882 883
        $MY_LOG_DIR/*.err \
        | $SED -e 's!Warning:  Table:.* on rename!!g' \
        > $MY_LOG_DIR/warnings.tmp
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
884 885 886 887 888

    found_error=0
    # Find errors
    for i in "^Warning:" "^Error:" "^==.* at 0x"
    do
889
      if $GREP "$i" $MY_LOG_DIR/warnings.tmp >> $MY_LOG_DIR/warnings
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
890 891 892 893 894 895 896 897 898 899
      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
900
    fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
901
}
902

bk@work.mysql.com's avatar
bk@work.mysql.com committed
903
mysql_install_db () {
904
    $ECHO "Removing Stale Files"
905 906 907 908 909
    if [ -z "$USE_OLD_DATA" ]; then
      $RM -rf $MASTER_MYDDIR $MASTER_MYDDIR"1"
      $ECHO "Installing Master Databases"
      $INSTALL_DB
      if [ $? != 0 ]; then
910
	error "Could not install master test DBs"
911 912
        exit 1
      fi
913
    fi
914 915 916 917 918 919 920 921 922
    if [ ! -z "$USE_NDBCLUSTER" ]
    then
      $ECHO "Installing Master Databases 1"
      $INSTALL_DB -1
      if [ $? != 0 ]; then
	error "Could not install master test DBs 1"
	exit 1
      fi
    fi
923
    $ECHO "Installing Slave Databases"
924
    $RM -rf $SLAVE_MYDDIR $MY_LOG_DIR/* 
925
    $INSTALL_DB -slave
926
    if [ $? != 0 ]; then
927
	error "Could not install slave test DBs"
928
	exit 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
929
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
930

931 932
    for slave_num in 1 2 ;
    do
933
      $RM -rf var/slave$slave_num-data
934 935 936
      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
937
    done
bk@work.mysql.com's avatar
bk@work.mysql.com committed
938 939 940
    return 0
}

941 942
gprof_prepare ()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
943 944
 $RM -rf $GPROF_DIR
 mkdir -p $GPROF_DIR
945 946 947 948 949
}

gprof_collect ()
{
 if [ -f $MASTER_MYDDIR/gmon.out ]; then
950
   gprof $MASTER_MYSQLD $MASTER_MYDDIR/gmon.out > $GPROF_MASTER
951 952 953
   echo "Master execution profile has been saved in $GPROF_MASTER"
 fi
 if [ -f $SLAVE_MYDDIR/gmon.out ]; then
954
   gprof $SLAVE_MYSQLD $SLAVE_MYDDIR/gmon.out > $GPROF_SLAVE
955 956 957 958
   echo "Slave execution profile has been saved in $GPROF_SLAVE"
 fi
}

959
gcov_prepare () {
960 961
    $FIND $BASEDIR -name \*.gcov \
    -or -name \*.da | $XARGS $RM
962 963 964
}

gcov_collect () {
965
    $ECHO "Collecting source coverage info..."
966 967
    [ -f $GCOV_MSG ] && $RM $GCOV_MSG
    [ -f $GCOV_ERR ] && $RM $GCOV_ERR
968 969 970
    for d in $MYSQLD_SRC_DIRS; do
	cd $BASEDIR/$d
	for f in *.h *.cc *.c; do
971
	    $GCOV $f 2>>$GCOV_ERR  >>$GCOV_MSG
972
	done
973
	cd $MYSQL_TEST_DIR
974 975
    done

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
976
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
977 978
}

979 980 981 982 983
abort_if_failed()
{
 if [ ! $? = 0 ] ; then
  echo $1
  exit 1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
984
 fi
985 986 987 988
}

start_manager()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
989
 if [ $USE_MANAGER = 0 ] ; then
990 991
   echo "Manager disabled, skipping manager start."
   $RM -f $MYSQL_MANAGER_LOG
992 993
  return
 fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
994
 $ECHO "Starting MySQL Manager"
995 996 997 998 999 1000 1001 1002 1003
 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
1004
 $RM -f $MANAGER_PID_FILE
1005 1006
 MYSQL_MANAGER_PW=`$MYSQL_MANAGER_PWGEN -u $MYSQL_MANAGER_USER \
 -o $MYSQL_MANAGER_PW_FILE`
1007
 $MYSQL_MANAGER --log=$MYSQL_MANAGER_LOG --port=$MYSQL_MANAGER_PORT \
1008
  --password-file=$MYSQL_MANAGER_PW_FILE --pid-file=$MANAGER_PID_FILE
1009
  abort_if_failed "Could not start MySQL manager"
1010 1011
  mysqltest_manager_args="--manager-host=localhost \
  --manager-user=$MYSQL_MANAGER_USER \
1012 1013 1014 1015 1016
  --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"
1017 1018 1019 1020
  while [ ! -f $MANAGER_PID_FILE ] ; do
   sleep 1
  done
  echo "Manager started"
1021 1022
}

1023 1024
stop_manager()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1025
 if [ $USE_MANAGER = 0 ] ; then
1026 1027
  return
 fi
1028 1029 1030 1031
 $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT -u$MYSQL_MANAGER_USER \
  -p$MYSQL_MANAGER_PW -P $MYSQL_MANAGER_PORT <<EOF
shutdown
EOF
1032 1033
 echo "Manager terminated"

1034 1035 1036
}

manager_launch()
1037
{
1038 1039
  ident=$1
  shift
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1040
  if [ $USE_MANAGER = 0 ] ; then
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
1041
    echo $@ | /bin/sh  >> $CUR_MYERR 2>&1  &
1042 1043
    sleep 2 #hack
    return
1044
  fi
1045
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
1046
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
1047
def_exec $ident "$@"
1048 1049 1050 1051
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
1052
EOF
1053
  abort_if_failed "Could not execute manager command"
1054
}
1055

1056 1057
manager_term()
{
1058 1059
  pid=$1
  ident=$2
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1060
  if [ $USE_MANAGER = 0 ] ; then
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1061
    # Shutdown time must be high as slave may be in reconnect
1062
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock$3 --connect_timeout=5 --shutdown_timeout=70 shutdown >> $MYSQL_MANAGER_LOG 2>&1
1063 1064
    res=$?
    # Some systems require an extra connect
1065
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock$3 --connect_timeout=1 ping >> $MYSQL_MANAGER_LOG 2>&1
1066 1067 1068 1069 1070
    if test $res = 0
    then
      wait_for_pid $pid
    fi
    return $res
1071
  fi
1072 1073
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
1074
stop_exec $ident $STOP_WAIT_TIMEOUT
1075 1076 1077 1078
EOF
 abort_if_failed "Could not execute manager command"
}

1079 1080 1081 1082
start_ndbcluster()
{
  if [ ! -z "$USE_NDBCLUSTER" ]
  then
joreland@mysql.com's avatar
merge  
joreland@mysql.com committed
1083
  rm -f $NDB_TOOLS_OUTPUT
1084 1085 1086 1087 1088
  if [ -z "$USE_RUNNING_NDBCLUSTER" ]
  then
    echo "Starting ndbcluster"
    if [ "$DO_BENCH" = 1 ]
    then
1089
      NDBCLUSTER_EXTRA_OPTS=""
1090
    else
1091
      NDBCLUSTER_EXTRA_OPTS="--small"
1092
    fi
1093 1094
    ./ndb/ndbcluster $NDBCLUSTER_OPTS $NDBCLUSTER_EXTRA_OPTS --initial || NDB_STATUS_OK=0
    if [ x$NDB_STATUS_OK != x1 ] ; then
1095 1096 1097
      if [ x$FORCE != x1 ] ; then
        exit 1
      fi
1098 1099
      USE_NDBCLUSTER=
      return
1100
    fi
1101

1102
    NDB_CONNECTSTRING="host=localhost:$NDBCLUSTER_PORT"
1103
  else
1104 1105
    NDB_CONNECTSTRING="$USE_RUNNING_NDBCLUSTER"
    echo "Using ndbcluster at $NDB_CONNECTSTRING"
1106
  fi
1107 1108
  USE_NDBCLUSTER="$USE_NDBCLUSTER --ndb-connectstring=\"$NDB_CONNECTSTRING\""
  export NDB_CONNECTSTRING
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
  fi
}

stop_ndbcluster()
{
 if [ ! -z "$USE_NDBCLUSTER" ]
 then
 if [ -z "$USE_RUNNING_NDBCLUSTER" ]
 then
   # Kill any running ndbcluster stuff
1119
   ./ndb/ndbcluster $NDBCLUSTER_OPTS --stop
1120 1121 1122 1123
 fi
 fi
}

kent@mysql.com's avatar
kent@mysql.com committed
1124 1125
# The embedded server needs the cleanup so we do some of the start work
# but stop before actually running mysqld or anything.
1126

1127 1128
start_master()
{
1129 1130
  eval "this_master_running=\$MASTER$1_RUNNING"
  if [ x$this_master_running = x1 ] || [ x$LOCAL_MASTER = x1 ] ; then
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1131 1132
    return
  fi
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1133 1134 1135
  # 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
1136
    $RM -f $MYSQL_TEST_DIR/var/log/master-bin$1.*
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1137 1138
  fi

1139
  # Remove old master.info and relay-log.info files
1140
  $RM -f $MYSQL_TEST_DIR/var/master-data$1/master.info $MYSQL_TEST_DIR/var/master-data$1/relay-log.info
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1141 1142 1143 1144 1145 1146 1147 1148

  #run master initialization shell script if one exists

  if [ -f "$master_init_script" ] ;
  then
      /bin/sh $master_init_script
  fi
  cd $BASEDIR # for gcov
1149 1150 1151
  if [ -n "$1" ] ; then
   id=`$EXPR $1 + 101`;
   this_master_myport=`$EXPR $MASTER_MYPORT + $1`
1152
   NOT_FIRST_MASTER_EXTRA_OPTS="--skip-innodb"
1153 1154
   eval "MASTER_MYPORT$1=$this_master_myport"
   export MASTER_MYPORT$1
1155 1156 1157
  else
   id=1;
   this_master_myport=$MASTER_MYPORT
1158
   NOT_FIRST_MASTER_EXTRA_OPTS=""
1159
  fi
1160 1161
  if [ -n "$EXTRA_MASTER_MYSQLD_TRACE" ] 
  then
1162
      CURR_MASTER_MYSQLD_TRACE="$EXTRA_MASTER_MYSQLD_TRACE$1"
1163
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1164 1165
  if [ -z "$DO_BENCH" ]
  then
1166 1167
    master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin$1 \
  	    --server-id=$id  \
1168
          --basedir=$MY_BASEDIR \
1169
          --port=$this_master_myport \
1170
          --local-infile \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1171 1172
          --exit-info=256 \
          --core \
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1173
          $USE_NDBCLUSTER \
1174 1175 1176 1177
          --datadir=$MASTER_MYDDIR$1 \
          --pid-file=$MASTER_MYPID$1 \
          --socket=$MASTER_MYSOCK$1 \
          --log=$MASTER_MYLOG$1 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1178 1179 1180 1181
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
1182
          --innodb_data_file_path=ibdata1:128M:autoextend \
1183
	  --open-files-limit=1024 \
1184
	   $MASTER_40_ARGS \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1185
           $SMALL_SERVER \
1186
           $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT \
1187
           $NOT_FIRST_MASTER_EXTRA_OPTS $CURR_MASTER_MYSQLD_TRACE"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1188
  else
1189 1190
    master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin$1 \
          --server-id=$id --rpl-recovery-rank=1 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1191
          --basedir=$MY_BASEDIR --init-rpl-role=master \
1192
          --port=$this_master_myport \
1193
          --local-infile \
1194 1195 1196
          --datadir=$MASTER_MYDDIR$1 \
          --pid-file=$MASTER_MYPID$1 \
          --socket=$MASTER_MYSOCK$1 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1197 1198 1199
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core \
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1200
          $USE_NDBCLUSTER \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1201 1202
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
1203
          --innodb_data_file_path=ibdata1:128M:autoextend \
1204
	   $MASTER_40_ARGS \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1205
           $SMALL_SERVER \
1206 1207
           $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT \
           $NOT_FIRST_MASTER_EXTRA_OPTS"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1208 1209 1210 1211 1212
  fi

  CUR_MYERR=$MASTER_MYERR
  CUR_MYSOCK=$MASTER_MYSOCK

kent@mysql.com's avatar
kent@mysql.com committed
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224
  # For embedded server we collect the server flags and return
  if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
    # Add a -A to each argument to pass it to embedded server
    EMBEDDED_SERVER_OPTS=""
    for opt in $master_args
    do
      EMBEDDED_SERVER_OPTS="$EMBEDDED_SERVER_OPTS -A $opt"
    done
    EXTRA_MYSQL_TEST_OPT="$EMBEDDED_SERVER_OPTS"
    return
  fi

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1225 1226 1227 1228
  if [ x$DO_DDD = x1 ]
  then
    $ECHO "set args $master_args" > $GDB_MASTER_INIT
    manager_launch master ddd -display $DISPLAY --debugger \
1229
    "gdb -x $GDB_MASTER_INIT" $MASTER_MYSQLD
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1230 1231
  elif [ x$DO_GDB = x1 ]
  then
1232 1233 1234 1235
    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:"
1236
      $ECHO "cd $CWD ; gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD"
1237 1238 1239 1240
      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
1241
    cat <<EOF
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1242 1243
b mysql_parse
commands 1
1244
disa 1
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1245
end
1246 1247
r
EOF
1248 1249
      fi )  > $GDB_MASTER_INIT
      manager_launch master $XTERM -display $DISPLAY \
1250
      -title "Master" -e gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD
1251
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1252
  else
1253
    manager_launch master $MASTER_MYSQLD $master_args
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1254
  fi
1255
  sleep_until_file_created $MASTER_MYPID$1 $wait_for_master
1256
  wait_for_master=$SLEEP_TIME_FOR_SECOND_MASTER
1257
  eval "MASTER$1_RUNNING=1"
1258 1259 1260 1261
}

start_slave()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1262 1263 1264
  [ 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
1265 1266
  # 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
1267 1268 1269 1270 1271 1272 1273 1274
  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"
1275
   slave_datadir="$SLAVE_MYDDIR/../$slave_ident-data/"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
   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
1288
  # Remove stale binary logs and old master.info files
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1289 1290 1291 1292 1293 1294
  # 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
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305

  #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 \
1306
          --master-password="" \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316
          --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 \
1317
          --relay-log=$MYSQL_TEST_DIR/var/log/$slave_ident-relay-bin \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
          --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 \
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1330
          --skip-innodb --skip-ndbcluster --skip-slave-start \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1331 1332 1333
          --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
          --report-host=127.0.0.1 --report-user=root \
          --report-port=$slave_port \
1334
          --master-retry-count=10 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1335
          -O slave_net_timeout=10 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1336 1337 1338 1339 1340 1341 1342
           $SMALL_SERVER \
           $EXTRA_SLAVE_OPT $EXTRA_SLAVE_MYSQLD_OPT"
  CUR_MYERR=$slave_err
  CUR_MYSOCK=$slave_sock

  if [ x$DO_DDD = x1 ]
  then
1343
    $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1344 1345 1346 1347
    manager_launch $slave_ident ddd -display $DISPLAY --debugger \
     "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD
  elif [ x$DO_GDB = x1 ]
  then
1348 1349
    if [ x$MANUAL_GDB = x1 ]
    then
1350
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
1351
      echo "To start gdb for the slave, type in another window:"
1352
      echo "cd $CWD ; gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD"
1353 1354
      wait_for_slave=1500
    else
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
      ( $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
1365 1366 1367
      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
1368 1369 1370 1371
  else
    manager_launch $slave_ident $SLAVE_MYSQLD $slave_args
  fi
  eval "SLAVE$1_RUNNING=1"
1372
  sleep_until_file_created $slave_pid $wait_for_slave
1373
  wait_for_slave=$SLEEP_TIME_FOR_SECOND_SLAVE
1374 1375
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1376 1377
mysql_start ()
{
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1378
# 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
1379
# for the test.  Better to let the test start the daemon
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1380 1381 1382 1383

#  $ECHO "Starting MySQL daemon"
#  start_master
#  start_slave
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1384
  cd $MYSQL_TEST_DIR
1385
  start_ndbcluster
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1386
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1387 1388
}

1389 1390
stop_slave ()
{
1391 1392 1393
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ -n "$1" ] ;
1394
  then
1395 1396 1397
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
  else
   slave_pid=$SLAVE_MYPID
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1398
  fi
1399 1400
  if [ x$this_slave_running = x1 ]
  then
1401 1402
    pid=`$CAT $slave_pid`
    manager_term $pid $slave_ident
1403
    if [ $? != 0 ] && [ -f $slave_pid ]
1404
    then # try harder!
1405
      $ECHO "slave not cooperating with mysqladmin, will try manual kill"
1406 1407
      kill $pid
      sleep_until_file_deleted $pid $slave_pid
1408 1409 1410 1411 1412 1413 1414 1415 1416
      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
1417
    fi
1418
    eval "SLAVE$1_RUNNING=0"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1419
  fi
1420
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1421

1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
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
}

1432 1433
stop_master ()
{
1434 1435
  eval "this_master_running=\$MASTER$1_RUNNING"
  if [ x$this_master_running = x1 ]
1436
  then
kent@mysql.com's avatar
kent@mysql.com committed
1437 1438 1439
    # For embedded server we don't stop anyting but mark that
    # MASTER_RUNNING=0 to get cleanup when calling start_master().
    if [ x$USE_EMBEDDED_SERVER != x1 ] ; then
tomas@poseidon.ndb.mysql.com's avatar
Merge  
tomas@poseidon.ndb.mysql.com committed
1440
      pid=`$CAT $MASTER_MYPID$1`
1441
      manager_term $pid master $1
tomas@poseidon.ndb.mysql.com's avatar
Merge  
tomas@poseidon.ndb.mysql.com committed
1442
      if [ $? != 0 ] && [ -f $MASTER_MYPID$1 ]
kent@mysql.com's avatar
kent@mysql.com committed
1443 1444 1445
      then # try harder!
	$ECHO "master not cooperating with mysqladmin, will try manual kill"
	kill $pid
tomas@poseidon.ndb.mysql.com's avatar
Merge  
tomas@poseidon.ndb.mysql.com committed
1446 1447
	sleep_until_file_deleted $pid $MASTER_MYPID$1
	if [ -f $MASTER_MYPID$1 ] ; then
kent@mysql.com's avatar
kent@mysql.com committed
1448
	  $ECHO "master refused to die. Sending SIGKILL"
tomas@poseidon.ndb.mysql.com's avatar
Merge  
tomas@poseidon.ndb.mysql.com committed
1449 1450
	  kill -9 `$CAT $MASTER_MYPID$1`
	  $RM -f $MASTER_MYPID$1
kent@mysql.com's avatar
kent@mysql.com committed
1451 1452 1453
	else
	  $ECHO "master responded to SIGTERM "
	fi
1454
      else
kent@mysql.com's avatar
kent@mysql.com committed
1455
	sleep $SLEEP_TIME_AFTER_RESTART
1456
      fi
1457
    fi
1458
    eval "MASTER$1_RUNNING=0"
1459 1460
  fi
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1461

1462 1463
mysql_stop ()
{
1464 1465 1466 1467 1468 1469
  if [ "$MASTER_RUNNING" = 1 ]
  then
    $ECHO  "Ending Tests"
    $ECHO  "Shutting-down MySQL daemon"
    $ECHO  ""
    stop_master
monty@mysql.com's avatar
monty@mysql.com committed
1470
    stop_master 1
1471 1472 1473 1474 1475
    $ECHO "Master shutdown finished"
    stop_slave
    stop_slave 1
    stop_slave 2
    $ECHO "Slave shutdown finished"
monty@mysql.com's avatar
monty@mysql.com committed
1476
    stop_ndbcluster
1477 1478
  fi
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1479 1480
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1481 1482 1483 1484 1485
mysql_restart ()
{
  mysql_stop
  mysql_start
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1486 1487 1488
}

mysql_loadstd () {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1489 1490

    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1491 1492 1493
    return 1
}

1494 1495 1496
run_testcase ()
{
 tf=$1
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1497
 tname=`$BASENAME $tf .test`
1498 1499
 master_opt_file=$TESTDIR/$tname-master.opt
 slave_opt_file=$TESTDIR/$tname-slave.opt
1500 1501
 master_init_script=$TESTDIR/$tname-master.sh
 slave_init_script=$TESTDIR/$tname-slave.sh
1502
 slave_master_info_file=$TESTDIR/$tname.slave-mi
kent@mysql.com's avatar
kent@mysql.com committed
1503 1504
 tsrcdir=$TESTDIR/$tname-src
 result_file="r/$tname.result"
1505
 echo $tname > $CURRENT_TEST
1506
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0 \& \( $tname : federated \) = 0`
1507
 if [ "$USE_MANAGER" = 1 ] ; then
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1508
  many_slaves=`$EXPR \( \( $tname : rpl_failsafe \) != 0 \) \| \( \( $tname : rpl_chain_temp_table \) != 0 \)`
1509 1510 1511 1512
 fi
 if $EXPR "$tname" '<' "$START_FROM" > /dev/null ; then
   #skip_test $tname
   return
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1513 1514
 fi

1515 1516 1517 1518
 if [ "$SKIP_TEST" ] ; then
   if $EXPR \( "$tname" : "$SKIP_TEST" \) > /dev/null ; then
     skip_test $tname
     return
1519
   fi
1520
 fi
1521

1522 1523
 if [ "$DO_TEST" ] ; then
   if $EXPR \( "$tname" : "$DO_TEST" \) > /dev/null ; then
1524
     : #empty command to keep some shells happy
1525 1526 1527
   else
     #skip_test $tname
     return
1528
   fi
1529
 fi
1530

1531 1532
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ; then
   skip_test $tname
1533 1534 1535
   return
 fi

kent@mysql.com's avatar
kent@mysql.com committed
1536 1537 1538 1539 1540 1541
# if [ -f "$TESTDIR/$tname.disabled" ]
# then
#   comment=`$CAT $TESTDIR/$tname.disabled`;
#   disable_test $tname "$comment"
#   return
# fi
kent@mysql.com's avatar
kent@mysql.com committed
1542 1543 1544 1545 1546 1547 1548 1549
 if [ -f "$TESTDIR/disabled.def" ] ; then
   comment=`$GREP "^$tname *: *" $TESTDIR/disabled.def`;
   if [ -n "$comment" ]
   then
     comment=`echo $comment | sed 's/^[^:]*: *//'`
     disable_test $tname "$comment"
     return
   fi
kent@mysql.com's avatar
kent@mysql.com committed
1550 1551
 fi

kent@mysql.com's avatar
kent@mysql.com committed
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
 if [ "x$USE_EMBEDDED_SERVER" != "x1" ] ; then
   # 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
 fi

 # FIXME temporary solution, we will get a new C version of this
 # script soon anyway so it is not worth it spending the time
 if [ "x$USE_EMBEDDED_SERVER" = "x1" -a -z "$DO_TEST" ] ; then
   for t in \
1564 1565
       "init_connect" \
       "init_file"
kent@mysql.com's avatar
kent@mysql.com committed
1566 1567 1568 1569 1570 1571 1572
   do
     if [ "$tname" = "$t" ] ; then
       skip_test $tname
       return
     fi
   done
 fi
1573

1574
 if [ $USE_RUNNING_SERVER -eq 0 ] ;
1575
 then
1576 1577
   if [ -f $master_opt_file ] ;
   then
1578
     EXTRA_MASTER_OPT=`$CAT $master_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1579 1580 1581 1582 1583 1584 1585
     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=" "
	 ;;
1586 1587
       --result-file=*)
         result_file=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--result-file=;;"`
kent@mysql.com's avatar
kent@mysql.com committed
1588
         result_file="r/$result_file.result"
1589 1590
         # Note that this must be set to space, not "" for test-reset to
# work
1591 1592
	 EXTRA_MASTER_OPT=" "
         ;;
1593
     esac
1594
     stop_master
1595
     stop_master 1
1596
     report_current_test $tname
1597
     start_master
1598
     if [ -n "$USE_NDBCLUSTER" -a -z "$DO_BENCH" ] ; then
1599 1600
       start_master 1
     fi
1601
     TZ=$MY_TZ; export TZ
1602
   else
kent@mysql.com's avatar
kent@mysql.com committed
1603 1604 1605 1606 1607
     # If we had extra master opts to the previous run
     # or there is no master running (FIXME strange.....)
     # or there is a master init script
     if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] || \
	[ -f $master_init_script ]
1608 1609 1610
     then
       EXTRA_MASTER_OPT=""
       stop_master
1611
       stop_master 1
1612
       report_current_test $tname
1613
       start_master
1614
       if [ -n "$USE_NDBCLUSTER"  -a -z "$DO_BENCH" ] ; then
1615 1616
         start_master 1
       fi
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1617
     else
1618
       report_current_test $tname
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1619
     fi
1620
   fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1621

kent@mysql.com's avatar
kent@mysql.com committed
1622 1623 1624 1625
   # We never start a slave if embedded server is used
   if [ "x$USE_EMBEDDED_SERVER" != "x1" ] ; then
     do_slave_restart=0
     if [ -f $slave_opt_file ] ;
1626
     then
kent@mysql.com's avatar
kent@mysql.com committed
1627
       EXTRA_SLAVE_OPT=`$CAT $slave_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1628
       do_slave_restart=1
kent@mysql.com's avatar
kent@mysql.com committed
1629 1630 1631 1632 1633 1634
     else
      if [ ! -z "$EXTRA_SLAVE_OPT" ] || [ x$SLAVE_RUNNING != x1 ] ;
      then
	EXTRA_SLAVE_OPT=""
	do_slave_restart=1
      fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1635
     fi
1636

kent@mysql.com's avatar
kent@mysql.com committed
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
     if [ -f $slave_master_info_file ] ; then
       SLAVE_MASTER_INFO=`$CAT $slave_master_info_file`
       do_slave_restart=1
     else
       if [ ! -z "$SLAVE_MASTER_INFO" ] || [ x$SLAVE_RUNNING != x1 ] ;
       then
	 SLAVE_MASTER_INFO=""
	 do_slave_restart=1
       fi
     fi

     if [ x$do_slave_restart = x1 ] ; then
       stop_slave
       echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
       start_slave
     else
       echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
     fi
     if [ x$many_slaves = x1 ]; then
      start_slave 1
      start_slave 2
     fi
1659
   fi
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
1660
 fi
1661 1662 1663 1664 1665 1666

 if [ "x$START_AND_EXIT" = "x1" ] ; then
  echo "Servers started, exiting"
  exit
 fi

1667
 cd $MYSQL_TEST_DIR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1668

1669
 if [ -f $tf ] ; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1670
    $RM -f r/$tname.*reject
kent@mysql.com's avatar
kent@mysql.com committed
1671
    mysql_test_args="-R $result_file $EXTRA_MYSQL_TEST_OPT"
1672
    if [ -z "$DO_CLIENT_GDB" ] ; then
1673
      `$MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`;
1674
    else
1675
      do_gdb_test "$mysql_test_args" "$tf"
1676
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1677

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1678 1679
    res=$?

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

1683 1684 1685 1686
    if [ x$many_slaves = x1 ] ; then
     stop_slave 1
     stop_slave 2
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1687

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1688
    if [ $res = 0 ]; then
1689 1690
      total_inc
      pass_inc
kent@mysql.com's avatar
kent@mysql.com committed
1691
      TIMER=""
kent@mysql.com's avatar
kent@mysql.com committed
1692
      if [ x$USE_TIMER = x1 -a -f "$MY_LOG_DIR/timer" ]; then
kent@mysql.com's avatar
kent@mysql.com committed
1693 1694 1695 1696
	TIMER=`cat $MY_LOG_DIR/timer`
	TIMER=`$PRINTF "%13s" $TIMER`
      fi
      $ECHO "$RES$RES_SPACE [ pass ]   $TIMER"
1697
    else
1698
      # why the following ``if'' ? That is why res==1 is special ?
1699 1700 1701 1702
      if [ $res = 2 ]; then
        skip_inc
	$ECHO "$RES$RES_SPACE [ skipped ]"
      else
1703 1704 1705
        if [ $res -gt 2 ]; then
          $ECHO "mysqltest returned unexpected code $res, it has probably crashed" >> $TIMEFILE
        fi
1706
	total_inc
1707
        fail_inc
1708
	$ECHO "$RES$RES_SPACE [ fail ]"
1709 1710
        $ECHO
	error_is
kent@mysql.com's avatar
kent@mysql.com committed
1711
	show_failed_diff $tname
1712
	$ECHO
1713
	if [ x$FORCE != x1 ] ; then
1714
	 $ECHO "Aborting: $tname failed in $TEST_MODE mode. To continue, re-run with '--force'."
1715
	 $ECHO
1716
         if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && \
kent@mysql.com's avatar
kent@mysql.com committed
1717
	    [ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1718 1719
	 then
	   mysql_stop
1720
	   stop_manager
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1721
   	 fi
1722 1723
	 exit 1
	fi
kent@mysql.com's avatar
kent@mysql.com committed
1724
	FAILED_CASES="$FAILED_CASES $tname"
1725
        if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && \
kent@mysql.com's avatar
kent@mysql.com committed
1726
	   [ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1727 1728 1729
	then
	  mysql_restart
	fi
1730
      fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1731
    fi
1732
  fi
1733 1734
}

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1735 1736 1737 1738
######################################################################
# Main script starts here
######################################################################

1739 1740
[ "$DO_GCOV" -a ! -x "$GCOV" ] && error "No gcov found"

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1741 1742
[ "$DO_GCOV" ] && gcov_prepare
[ "$DO_GPROF" ] && gprof_prepare
1743

1744
if [ $USE_RUNNING_SERVER -eq 0 ]
1745
then
1746 1747 1748 1749
  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
1750
    $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK1 -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
1751 1752
    $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
1753
    $MYSQLADMIN --no-defaults --host=$hostname --port=`expr $MASTER_MYPORT+1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
1754 1755 1756
    $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
1757
    sleep_until_file_deleted 0 $MASTER_MYPID"1"
1758 1759
    sleep_until_file_deleted 0 $SLAVE_MYPID
  else
1760
    rm $MASTER_MYPID $MASTER_MYPID"1" $SLAVE_MYPID
1761
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774

  # 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

1775
  stop_ndbcluster
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1776

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1777
  # Remove files that can cause problems
1778
  $RM -rf $MYSQL_TEST_DIR/var/ndbcluster
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1779 1780
  $RM -f $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*

1781 1782
  # Remove old berkeley db log files that can confuse the server
  $RM -f $MASTER_MYDDIR/log.*
1783
  $RM -f $MASTER_MYDDIR"1"/log.*
1784

1785 1786
  wait_for_master=$SLEEP_TIME_FOR_FIRST_MASTER
  wait_for_slave=$SLEEP_TIME_FOR_FIRST_SLAVE
1787 1788
  $ECHO "Installing Test Databases"
  mysql_install_db
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1789

1790
  start_manager
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1791

paul@ice.snake.net's avatar
paul@ice.snake.net committed
1792
# 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
1793
# case
1794 1795 1796 1797 1798 1799
  if [ -z "$DO_GDB" ] && [ -z "$DO_DDD" ]
  then
    mysql_start
  fi
  $ECHO  "Loading Standard Test Databases"
  mysql_loadstd
1800 1801
fi

1802
$ECHO  "Starting Tests"
1803

1804 1805 1806
# Some test cases need USE_RUNNING_SERVER
export USE_RUNNING_SERVER

1807 1808 1809
#
# This can probably be deleted
#
1810 1811
if [ "$DO_BENCH" = 1 ]
then
1812 1813
  start_master

1814 1815 1816 1817 1818
  if [ "$DO_SMALL_BENCH" = 1 ]
  then
    EXTRA_BENCH_ARGS="--small-test --small-tables"
  fi

1819 1820
  if [ ! -z "$USE_NDBCLUSTER" ]
  then
1821
    EXTRA_BENCH_ARGS="--create-options=TYPE=ndb $EXTRA_BENCH_ARGS"
1822 1823
  fi 

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1824 1825 1826 1827
  BENCHDIR=$BASEDIR/sql-bench/
  savedir=`pwd`
  cd $BENCHDIR
  if [ -z "$1" ]
1828
  then
1829
    ./run-all-tests --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS --log
1830
  else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1831 1832
    if [ -x "./$1" ]
    then
1833
       ./$1 --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1834 1835 1836
    else
      echo "benchmark $1 not found"
    fi
1837
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1838 1839 1840 1841
  cd $savedir
  mysql_stop
  stop_manager
  exit
1842 1843
fi

1844
$ECHO
kent@mysql.com's avatar
kent@mysql.com committed
1845
if [ x$USE_TIMER = x1 ] ; then
kent@mysql.com's avatar
kent@mysql.com committed
1846
$ECHO "TEST                            RESULT        TIME (ms)"
kent@mysql.com's avatar
kent@mysql.com committed
1847 1848 1849
else
$ECHO "TEST                            RESULT"
fi
1850 1851
$ECHO $DASH72

1852
if [ -z "$1" ] ;
1853
then
1854 1855 1856
  if [ x$RECORD = x1 ]; then
    $ECHO "Will not run in record mode without a specific test case."
  else
1857 1858 1859 1860
    for tf in $TESTDIR/*.$TESTSUFFIX
    do
      run_testcase $tf
    done
1861 1862
    $RM -f $TIMEFILE	# Remove for full test
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1863
else
1864 1865 1866 1867 1868 1869 1870 1871 1872 1873
  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
1874
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1875

1876 1877
$ECHO $DASH72
$ECHO
1878

1879
if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && [ -z "$DO_DDD" ]
1880 1881 1882
then
    mysql_stop
fi
1883
stop_manager
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1884
report_stats
1885
$ECHO
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1886

1887
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
1888
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
1889

kent@mysql.com's avatar
kent@mysql.com committed
1890
if [ $TOT_FAIL -ne 0 ]; then
1891
  $ECHO "mysql-test-run in $TEST_MODE mode: *** Failing the test(s):$FAILED_CASES"
kent@mysql.com's avatar
kent@mysql.com committed
1892 1893 1894 1895 1896
  $ECHO
  exit 1
else
  exit 0
fi