mysql-test-run-shell.sh 67.3 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 14
#echo "##################################################";
#echo "This script is deprecated and will soon be removed";
#echo "Use mysql-test-run.pl instead";
#echo "##################################################";
#echo
15

bk@work.mysql.com's avatar
bk@work.mysql.com committed
16 17 18 19
#++
# Access Definitions
#--
DB=test
monty@mysql.com's avatar
monty@mysql.com committed
20
DBPASSWD=""
21
VERBOSE=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
22
USE_MANAGER=0
23 24
MY_TZ=GMT-3
TZ=$MY_TZ; export TZ # for UNIX_TIMESTAMP tests to work
25
LOCAL_SOCKET=@MYSQL_UNIX_ADDR@
26 27 28 29 30 31 32 33 34 35

if [ -z "$MYSQL_TCP_PORT" ]; then
  MYSQL_TCP_PORT=@MYSQL_TCP_PORT@
  if [ @MYSQL_TCP_PORT_DEFAULT@ -eq 0 ]; then
    ESP=`getent services mysql/tcp`
    if [ $? -eq 0 ]; then
      MYSQL_TCP_PORT=`echo "$ESP"|sed -e's-^[a-z]*[ ]*\([0-9]*\)/[a-z]*$-\1-g'`
    fi
  fi
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
36

37 38
umask 022

39
# For query_cache test
monty@mysql.com's avatar
monty@mysql.com committed
40
case `uname` in
41 42 43
    SCO_SV | UnixWare | OpenUNIX )
        # do nothing (Causes strange behavior)
        ;;
monty@mysql.com's avatar
monty@mysql.com committed
44 45 46
    QNX)
        # do nothing (avoid error message)
        ;;
47 48 49 50
    * )
        ulimit -n 1024
        ;;
esac
51

52 53 54 55
#++
# Program Definitions
#--

56 57
LC_COLLATE=C
export LC_COLLATE
58
PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11:$PATH
59
MASTER_40_ARGS="--rpl-recovery-rank=1 --init-rpl-role=master"
60

61 62 63 64
# Standard functions

which ()
{
65
  IFS="${IFS=   }"; save_ifs="$IFS"; IFS=':'
66 67
  for file
  do
68
    for dir in $PATH
69
    do
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
70
      if test -f $dir/$file
71 72 73 74 75
      then
        echo "$dir/$file"
        continue 2
      fi
    done
76
    echo "Fatal error: Cannot find program $file in $PATH" 1>&2
77 78
    exit 1
  done
79
  IFS="$save_ifs"
80
  exit 0
81 82 83
}


monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
84 85
sleep_until_file_deleted ()
{
86 87
  pid=$1;
  file=$2
88
  loop=$SLEEP_TIME_FOR_DELETE
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
89 90
  while (test $loop -gt 0)
  do
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
91
    if [ ! -r $file ]
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
92
    then
93 94 95 96
      if test $pid != "0"
      then
        wait_for_pid $pid
      fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
97 98
      return
    fi
99
    sleep 1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
100 101 102 103
    loop=`expr $loop - 1`
  done
}

104
sleep_until_file_created ()
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
105 106
{
  file=$1
107 108
  loop=$2
  org_time=$2
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
109 110
  while (test $loop -gt 0)
  do
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
111
    if [ -r $file ]
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
112
    then
113
      return 0
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
114
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
115
    sleep 1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
116 117
    loop=`expr $loop - 1`
  done
118
  echo "ERROR: $file was not created in $org_time seconds;  Aborting"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
119 120 121
  exit 1;
}

122 123 124 125 126
# For the future

wait_for_pid()
{
  pid=$1
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
127
  #$WAIT_PID pid $SLEEP_TIME_FOR_DELETE
128 129
}

130 131 132 133 134 135 136 137 138 139 140
# Check that valgrind is installed
find_valgrind()
{
  FIND_VALGRIND=`which valgrind` # this will print an error if not found
  # Give good warning to the user and stop
  if [ -z "$FIND_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://valgrind.kde.org ."
    exit 1
  fi
  # >=2.1.2 requires the --tool option, some versions write to stdout, some to stderr
  valgrind --help 2>&1 | grep "\-\-tool" > /dev/null && FIND_VALGRIND="$FIND_VALGRIND --tool=memcheck"
141
  FIND_VALGRIND="$FIND_VALGRIND --alignment=8 --leak-check=yes --num-callers=16 --suppressions=$MYSQL_TEST_DIR/valgrind.supp"
142 143
}

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

146 147
SED=sed

148 149
BASENAME=`which basename`
if test $? != 0; then exit 1; fi
150
DIFF=`which diff | $SED q`
151
if test $? != 0; then exit 1; fi
152 153
CAT=cat
CUT=cut
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
154
HEAD=head
155 156 157 158
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
159
GREP=grep
160
if test $? != 0; then exit 1; fi
161 162
PRINTF=printf
RM=rm
163
if test $? != 0; then exit 1; fi
164
TR=tr
165 166
XARGS=`which xargs`
if test $? != 0; then exit 1; fi
167
SORT=sort
168 169 170 171 172

# Are we using a source or a binary distribution?

testdir=@testdir@
if [ -d bin/mysqld ] && [ -d mysql-test ] ; then
173 174
 cd mysql-test
else
175 176
 if [ -d $testdir/mysql-test ] ; then
   cd $testdir
177
 fi
178 179 180 181 182 183 184
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
185
  exit 1
186
fi
187

bk@work.mysql.com's avatar
bk@work.mysql.com committed
188 189 190
#++
# Misc. Definitions
#--
191

192 193 194 195 196
# BASEDIR is always above mysql-test directory ...
MYSQL_TEST_DIR=`pwd`
cd ..

if [ -d ./sql ] ; then
197 198 199
   SOURCE_DIST=1
else
   BINARY_DIST=1
200

201 202 203 204 205
  # ... one level for tar.gz, two levels for a RPM installation
  if [ ! -f ./bin/mysql_upgrade ] ; then
     # Has to be RPM installation
    cd ..
  fi
206
fi
207
BASEDIR=`pwd`
208 209

cd $MYSQL_TEST_DIR
kent@mysql.com's avatar
kent@mysql.com committed
210
MYSQL_TEST_WINDIR=$MYSQL_TEST_DIR
211 212
MYSQLTEST_VARDIR=$MYSQL_TEST_DIR/var
export MYSQL_TEST_DIR MYSQL_TEST_WINDIR MYSQLTEST_VARDIR
213
STD_DATA=$MYSQL_TEST_DIR/std_data
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
214
hostname=`hostname`		# Installed in the mysql privilege table
215

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
216
MANAGER_QUIET_OPT="-q"
217
TESTDIR="$MYSQL_TEST_DIR/t"
218
TESTSUFFIX=test
219
TOT_SKIP=0
bk@work.mysql.com's avatar
bk@work.mysql.com committed
220 221 222
TOT_PASS=0
TOT_FAIL=0
TOT_TEST=0
223
GOT_WARNINGS=0
224 225 226
USERT=0
SYST=0
REALT=0
227
FAST_START=""
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
228
MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp
229
export MYSQL_TMP_DIR
230 231 232 233 234 235 236 237

# Use a relative path for where the slave will find the dumps
# generated by "LOAD DATA" on the master. The path is relative
# since it must have fixed length to test logging
# i.e otherwise the output from "SHOW MASTER STATUS" will vary
# with the strlen() of MYSQL_TEST_DIR
SLAVE_LOAD_TMPDIR=../tmp

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
238
RES_SPACE="      "
239
MYSQLD_SRC_DIRS="strings mysys include extra regex myisam \
240
 myisammrg heap sql"
241
MY_LOG_DIR="$MYSQL_TEST_DIR/var/log" 
242 243 244
#
# Set LD_LIBRARY_PATH if we are using shared libraries
#
monty@mysql.com's avatar
monty@mysql.com committed
245 246
LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/libmysql_r/.libs:$BASEDIR/zlib/.libs:$LD_LIBRARY_PATH"
DYLD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/libmysql_r/.libs:$BASEDIR/zlib/.libs:$DYLD_LIBRARY_PATH"
247
export LD_LIBRARY_PATH DYLD_LIBRARY_PATH
248

249 250 251 252 253 254 255
#
# 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
256
MASTER_RUNNING=0
257
MASTER1_RUNNING=0
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
258
MASTER_MYHOST=127.0.0.1
259
MASTER_MYPORT=9306
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
260
SLAVE_RUNNING=0
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
261
SLAVE_MYHOST=127.0.0.1
262
SLAVE_MYPORT=9308 # leave room for 2 masters for cluster tests
263
MYSQL_MANAGER_LOG=$MYSQL_TEST_DIR/var/log/manager.log
264
NDBCLUSTER_PORT=9350
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
265
NDBCLUSTER_PORT_SLAVE=9358
kent@mysql.com's avatar
kent@mysql.com committed
266 267 268 269 270 271

#
# To make it easier for different devs to work on the same host,
# an environment variable can be used to control all ports. A small
# number is to be used, 0 - 16 or similar.
#
kent@mysql.com's avatar
kent@mysql.com committed
272 273 274 275 276
# Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
# versions of this script, else a 4.0 test run might conflict with a
# 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
# all port numbers might not be used in this version of the script.
#
kent@mysql.com's avatar
kent@mysql.com committed
277
if [ -n "$MTR_BUILD_THREAD" ] ; then
kent@mysql.com's avatar
kent@mysql.com committed
278
  MASTER_MYPORT=`expr $MTR_BUILD_THREAD '*' 10 + 10000`
279
  SLAVE_MYPORT=`expr $MASTER_MYPORT + 3`
kent@mysql.com's avatar
kent@mysql.com committed
280
  NDBCLUSTER_PORT=`expr $MASTER_MYPORT + 6`
kent@mysql.com's avatar
kent@mysql.com committed
281
  NDBCLUSTER_PORT_SLAVE=`expr $MASTER_MYPORT + 7`
kent@mysql.com's avatar
kent@mysql.com committed
282

283 284 285 286 287
  echo "Using MTR_BUILD_THREAD      = $MTR_BUILD_THREAD"
  echo "Using MASTER_MYPORT         = $MASTER_MYPORT"
  echo "Using SLAVE_MYPORT          = $SLAVE_MYPORT"
  echo "Using NDBCLUSTER_PORT       = $NDBCLUSTER_PORT"
  echo "Using NDBCLUSTER_PORT_SLAVE = $NDBCLUSTER_PORT_SLAVE"
kent@mysql.com's avatar
kent@mysql.com committed
288 289
fi

290
NO_SLAVE=0
291
USER_TEST=
kent@mysql.com's avatar
kent@mysql.com committed
292
FAILED_CASES=
293

294
EXTRA_MASTER_OPT=""
295
EXTRA_MYSQL_TEST_OPT=""
296
EXTRA_MYSQLCHECK_OPT=""
297
EXTRA_MYSQLDUMP_OPT=""
298
EXTRA_MYSQLSLAP_OPT=""
299
EXTRA_MYSQLSHOW_OPT=""
300
EXTRA_MYSQLBINLOG_OPT=""
301
USE_RUNNING_SERVER=0
302
USE_NDBCLUSTER=@USE_NDBCLUSTER@
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
303
USE_NDBCLUSTER_SLAVE=@USE_NDBCLUSTER@
304
USE_NDBCLUSTER_ALL=0
305
USE_NDBCLUSTER_ONLY=0
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
306
USE_RUNNING_NDBCLUSTER=""
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
307 308
USE_RUNNING_NDBCLUSTER_SLAVE=""
NDB_EXTRA_TEST=0
309
NDB_VERBOSE=0
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
310
NDBCLUSTER_EXTRA_OPTS=""
311 312
USE_PURIFY=""
PURIFY_LOGS=""
313 314
DO_GCOV=""
DO_GDB=""
315
MANUAL_GDB=""
316
DO_DDD=""
317
DO_CLIENT_GDB=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
318
SLEEP_TIME_AFTER_RESTART=1
319
SLEEP_TIME_FOR_DELETE=10
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
320
SLEEP_TIME_FOR_FIRST_MASTER=400		# Enough time to create innodb tables
321
SLEEP_TIME_FOR_SECOND_MASTER=400
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
322
SLEEP_TIME_FOR_FIRST_SLAVE=400
323
SLEEP_TIME_FOR_SECOND_SLAVE=300
324
CHARACTER_SET=latin1
325
DBUSER=""
326 327
START_WAIT_TIMEOUT=10
STOP_WAIT_TIMEOUT=10
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
328
MYSQL_TEST_SSL_OPTS=""
kent@mysql.com's avatar
kent@mysql.com committed
329
USE_TIMER=""
kent@mysql.com's avatar
kent@mysql.com committed
330
USE_EMBEDDED_SERVER=""
331
TEST_MODE=""
332

333
NDB_MGM_EXTRA_OPTS=
334 335
NDB_MGMD_EXTRA_OPTS=
NDBD_EXTRA_OPTS=
336
MASTER_MYSQLDBINLOG=1
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
337
SLAVE_MYSQLDBINLOG=1
338

ranger@regul.home.lan's avatar
ranger@regul.home.lan committed
339
DO_STRESS=""
340 341 342
STRESS_SUITE="main"
STRESS_MODE="random"
STRESS_THREADS=5
343
STRESS_TEST_COUNT=""
344 345 346 347 348 349
STRESS_LOOP_COUNT=""
STRESS_TEST_DURATION=""
STRESS_INIT_FILE=""
STRESS_TEST_FILE=""
STRESS_TEST=""

350 351
$ECHO "Logging: $0 $*"   # To ensure we see all arguments in the output, for the test analysis tool

352 353
while test $# -gt 0; do
  case "$1" in
354 355 356
    --embedded-server)
      USE_EMBEDDED_SERVER=1
      USE_MANAGER=0 NO_SLAVE=1
kent@mysql.com's avatar
kent@mysql.com committed
357
      USE_RUNNING_SERVER=0
358 359
      USE_NDBCLUSTER=""
      USE_NDBCLUSTER_SLAVE=""
360 361 362 363
      TEST_MODE="$TEST_MODE embedded" ;;
    --purify)
      USE_PURIFY=1
      USE_MANAGER=0
kent@mysql.com's avatar
kent@mysql.com committed
364
      USE_RUNNING_SERVER=0
365
      TEST_MODE="$TEST_MODE purify" ;;
366 367
    --user=*) DBUSER=`$ECHO "$1" | $SED -e "s;--user=;;"` ;;
    --force)  FORCE=1 ;;
kent@mysql.com's avatar
kent@mysql.com committed
368
    --timer)  USE_TIMER=1 ;;
369 370 371 372 373
    --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=;;"` ;;
374 375
    --local)   USE_RUNNING_SERVER=0 ;;
    --extern)  USE_RUNNING_SERVER=1 ;;
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
376
    --with-ndbcluster)
377
      USE_NDBCLUSTER="--ndbcluster" ;;
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
378 379
    --with-ndbcluster-slave)
      USE_NDBCLUSTER_SLAVE="--ndbcluster" ;;
380 381 382 383
    --with-ndbcluster-all)
      USE_NDBCLUSTER="--ndbcluster"
      USE_NDBCLUSTER_SLAVE="--ndbcluster"
      USE_NDBCLUSTER_ALL=1 ;;
384 385 386 387
    --with-ndbcluster-only)
      USE_NDBCLUSTER="--ndbcluster"
      USE_NDBCLUSTER_SLAVE="--ndbcluster"
      USE_NDBCLUSTER_ONLY=1 ;;
388
    --ndb-connectstring=*)
389
      USE_NDBCLUSTER="--ndbcluster" ;
390
      USE_RUNNING_NDBCLUSTER=`$ECHO "$1" | $SED -e "s;--ndb-connectstring=;;"` ;;
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
391 392 393 394 395 396 397
    --ndb-connectstring-slave=*)
      USE_NDBCLUSTER_SLAVE="--ndbcluster" ;
      USE_RUNNING_NDBCLUSTER_SLAVE=`$ECHO "$1" | $SED -e "s;--ndb-connectstring-slave=;;"` ;;
    --ndb-extra-test)
      NDBCLUSTER_EXTRA_OPTS=" "
      NDB_EXTRA_TEST=1 ;
      ;;
398 399
    --ndb-verbose)
      NDB_VERBOSE=2 ;;
400 401
    --ndb_mgm-extra-opts=*)
      NDB_MGM_EXTRA_OPTS=`$ECHO "$1" | $SED -e "s;--ndb_mgm-extra-opts=;;"` ;;
402 403 404 405
    --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=;;"` ;;
406
    --tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;;
407 408 409 410 411
    --local-master)
      MASTER_MYPORT=3306;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --host=127.0.0.1 \
      --port=$MYSQL_MYPORT"
      LOCAL_MASTER=1 ;;
412 413
    --master_port=*) MASTER_MYPORT=`$ECHO "$1" | $SED -e "s;--master_port=;;"` ;;
    --slave_port=*) SLAVE_MYPORT=`$ECHO "$1" | $SED -e "s;--slave_port=;;"` ;;
414
    --ndbcluster_port=*) NDBCLUSTER_PORT=`$ECHO "$1" | $SED -e "s;--ndbcluster_port=;;"` ;;
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
415 416
    --ndbcluster-port=*) NDBCLUSTER_PORT=`$ECHO "$1" | $SED -e "s;--ndbcluster-port=;;"` ;;
    --ndbcluster-port-slave=*) NDBCLUSTER_PORT_SLAVE=`$ECHO "$1" | $SED -e "s;--ndbcluster-port-slave=;;"` ;;
417 418
    --with-openssl)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
419 420 421
     --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem \
     --ssl-cert=$MYSQL_TEST_DIR/std_data/server-cert.pem \
     --ssl-key=$MYSQL_TEST_DIR/std_data/server-key.pem"
422
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
423 424 425
     --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem \
     --ssl-cert=$MYSQL_TEST_DIR/std_data/server-cert.pem \
     --ssl-key=$MYSQL_TEST_DIR/std_data/server-key.pem"
kent@mysql.com's avatar
kent@mysql.com committed
426
     MYSQL_TEST_SSL_OPTS="--ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem \
427 428
     --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem \
     --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem" ;;
429 430
    --start-and-exit)
     START_AND_EXIT=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
431
     ;;
432
    --socket=*) LOCAL_SOCKET=`$ECHO "$1" | $SED -e "s;--socket=;;"` ;;
433
    --skip-rpl) NO_SLAVE=1 ;;
434
    --skip-test=*) SKIP_TEST=`$ECHO "$1" | $SED -e "s;--skip-test=;;"`;;
435
    --do-test=*) DO_TEST=`$ECHO "$1" | $SED -e "s;--do-test=;;"`;;
436
    --start-from=* ) START_FROM=`$ECHO "$1" | $SED -e "s;--start-from=;;"` ;;
437 438 439 440
    --warnings | --log-warnings)
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --log-warnings"
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --log-warnings"
     ;;
441 442 443
    --wait-timeout=*)
     START_WAIT_TIMEOUT=`$ECHO "$1" | $SED -e "s;--wait-timeout=;;"`
     STOP_WAIT_TIMEOUT=$START_WAIT_TIMEOUT;;
444 445 446
    --record)
      RECORD=1;
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
447 448 449 450 451
    --small-bench)
      DO_SMALL_BENCH=1
      DO_BENCH=1
      NO_SLAVE=1
      ;;
452 453 454
    --bench)
      DO_BENCH=1
      NO_SLAVE=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
455
      ;;
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
    --stress)
      DO_STRESS=1
      NO_SLAVE=1
      SKIP_SLAVE=1
      ;;
    --stress-suite=*)
      STRESS_SUITE=`$ECHO "$1" | $SED -e "s;--stress-suite=;;"`
      ;;
    --stress-threads=*)
      STRESS_THREADS=`$ECHO "$1" | $SED -e "s;--stress-threads=;;"`
      ;;
    --stress-test-file=*)
      STRESS_TEST_FILE=`$ECHO "$1" | $SED -e "s;--stress-test-file=;;"`
      ;;
    --stress-init-file=*)
      STRESS_INIT_FILE=`$ECHO "$1" | $SED -e "s;--stress-init-file=;;"`
      ;; 
    --stress-mode=*)
      STRESS_MODE=`$ECHO "$1" | $SED -e "s;--stress-mode=;;"`
      ;;
    --stress-loop-count=*)
      STRESS_LOOP_COUNT=`$ECHO "$1" | $SED -e "s;--stress-loop-count=;;"`
      ;;
    --stress-test-count=*)
      STRESS_TEST_COUNT=`$ECHO "$1" | $SED -e "s;--stress-test-count=;;"`
      ;;      
    --stress-test-duration=*)
      STRESS_TEST_DURATION=`$ECHO "$1" | $SED -e "s;--stress-test-duration=;;"`
      ;;
485 486
    --big*)			# Actually --big-test
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
487 488
    --compress)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
489 490
    --sleep=*)
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1"
491
      SLEEP_TIME_AFTER_RESTART=`$ECHO "$1" | $SED -e "s;--sleep=;;"`
492
      ;;
493
    --ps-protocol)
494
      TEST_MODE="$TEST_MODE ps-protocol" EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
495 496 497
    --user-test=*)
      USER_TEST=`$ECHO "$1" | $SED -e "s;--user-test=;;"`
      ;;
498
    --mysqld=*)
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
499
       TMP=`$ECHO "$1" | $SED -e "s;--mysqld=;;"`
500
       EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $TMP"
501
       EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $TMP"
502
       ;;
503 504 505 506 507 508
    --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
509
      GCOV=`which gcov`
510
      ;;
511 512
    --gprof )
      DO_GPROF=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
513
      ;;
514
    --gdb )
515 516
      START_WAIT_TIMEOUT=300
      STOP_WAIT_TIMEOUT=300
517
      if [ x$BINARY_DIST = x1 ] ; then
518
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --gdb option"
519 520
      fi
      DO_GDB=1
521 522
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
523 524
      # This needs to be checked properly
      # USE_MANAGER=1
525
      USE_RUNNING_SERVER=0
526
      ;;
527 528 529 530 531
    --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
532 533
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
534
      ;;
535 536 537
    --manual-gdb )
      DO_GDB=1
      MANUAL_GDB=1
538
      USE_RUNNING_SERVER=0
539 540
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
541
      ;;
542 543
    --ddd )
      if [ x$BINARY_DIST = x1 ] ; then
544
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --ddd option"
545 546
      fi
      DO_DDD=1
547
      USE_RUNNING_SERVER=0
548 549
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
550
      ;;
551
    --valgrind | --valgrind-all)
552 553
      find_valgrind;
      VALGRIND=$FIND_VALGRIND
554 555
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-safemalloc"
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
556
      SLEEP_TIME_AFTER_RESTART=10
557
      SLEEP_TIME_FOR_DELETE=60
558
      USE_RUNNING_SERVER=0
559 560 561 562
      if test "$1" = "--valgrind-all"
      then
        VALGRIND="$VALGRIND -v --show-reachable=yes"
      fi
563 564 565 566 567
      ;;
    --valgrind-options=*)
      TMP=`$ECHO "$1" | $SED -e "s;--valgrind-options=;;"`
      VALGRIND="$VALGRIND $TMP"
      ;;
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
568 569 570 571
    --skip-ndbcluster-slave | --skip-ndb-slave)
      USE_NDBCLUSTER_SLAVE=""
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-ndbcluster"
      ;;
572 573 574 575 576 577 578
    --valgrind-mysqltest | --valgrind-mysqltest-all)
      find_valgrind;
      VALGRIND_MYSQLTEST=$FIND_VALGRIND
      if test "$1" = "--valgrind-mysqltest-all"
      then
        VALGRIND_MYSQLTEST="$VALGRIND_MYSQLTEST -v --show-reachable=yes"
      fi
579
      ;;
580
    --skip-ndbcluster | --skip-ndb)
581
      USE_NDBCLUSTER=""
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
582
      USE_NDBCLUSTER_SLAVE=""
583 584
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-ndbcluster"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-ndbcluster"
585
      ;;
586
    --skip-master-binlog) MASTER_MYSQLDBINLOG=0 ;;
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
587
    --skip-slave-binlog) SLAVE_MYSQLDBINLOG=0 ;;
588 589 590 591
    --skip-*)
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $1"
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $1"
      ;;
592 593
    --strace-client )
      STRACE_CLIENT=1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
594
      ;;
595
    --debug)
596
      EXTRA_MASTER_MYSQLD_TRACE=" \
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
597
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/master.trace"
598
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
599
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/slave.trace"
600 601
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqltest.trace"
602 603
      EXTRA_MYSQLCHECK_OPT="$EXTRA_MYSQLCHECK_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlcheck.trace"
604 605
      EXTRA_MYSQLDUMP_OPT="$EXTRA_MYSQLDUMP_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqldump.trace"
606 607
      EXTRA_MYSQLSLAP_OPT="$EXTRA_MYSQLSLAP_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlslap.trace"
608 609
      EXTRA_MYSQLSHOW_OPT="$EXTRA_MYSQLSHOW_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlshow.trace"
610 611
      EXTRA_MYSQLBINLOG_OPT="$EXTRA_MYSQLBINLOG_OPT \
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlbinlog.trace"
612
      EXTRA_MYSQL_CLIENT_TEST_OPT="--debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysql_client_test.trace"
613
      ;;
614 615 616
    --fast)
      FAST_START=1
      ;;
617
    --use-old-data)
618 619
      USE_OLD_DATA=1
      ;;
620 621 622 623 624 625
    --comment=*)
      TMP=`$ECHO "$1" | $SED -e "s;--comment=;;"`
      echo
      echo '############################################'
      echo "# $TMP"
      echo '############################################'
626
      ;;
627 628 629 630 631 632
    -- )  shift; break ;;
    --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
    * ) break ;;
  esac
  shift
done
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
633

634 635 636 637 638 639 640
if [ -z "$TEST_MODE" ] ; then
  TEST_MODE="default"
else
  # Remove the leading space if any
  TEST_MODE=`echo $TEST_MODE | sed 's/^ *//'`
fi

641 642 643 644 645
#
# Skip tests that doesn't work with shell version
#
SKIP_TEST="$SKIP_TEST bootstrap"

bk@work.mysql.com's avatar
bk@work.mysql.com committed
646 647 648
#++
# mysqld Environment Parameters
#--
649

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
650
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
651

652
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
653
MASTER_MYSOCK="$MYSQL_TMP_DIR/master.sock"
654
MASTER_MYSOCK1=$MYSQL_MYSOCK"1"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
655 656 657
MASTER_MYPID="$MYRUN_DIR/master.pid"
MASTER_MYLOG="$MYSQL_TEST_DIR/var/log/master.log"
MASTER_MYERR="$MYSQL_TEST_DIR/var/log/master.err"
658 659

SLAVE_MYDDIR="$MYSQL_TEST_DIR/var/slave-data"
660
SLAVE_MYSOCK="$MYSQL_TMP_DIR/slave.sock"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
661 662 663
SLAVE_MYPID="$MYRUN_DIR/slave.pid"
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/slave.log"
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/slave.err"
664

665
CURRENT_TEST="$MYSQL_TEST_DIR/var/log/current_test"
666
SMALL_SERVER="--key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M"
667

tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
668
export MASTER_MYHOST MASTER_MYPORT SLAVE_MYHOST SLAVE_MYPORT MYSQL_TCP_PORT MASTER_MYSOCK MASTER_MYSOCK1
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
669

670
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"
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
671 672
NDBCLUSTER_OPTS_SLAVE="--port=$NDBCLUSTER_PORT_SLAVE --data-dir=$MYSQL_TEST_DIR/var"
if [ -n "$USE_NDBCLUSTER_SLAVE" ] ; then
673
  USE_NDBCLUSTER_SLAVE="$USE_NDBCLUSTER_SLAVE --ndb-connectstring=localhost:$NDBCLUSTER_PORT_SLAVE --ndb-extra-logging"
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
674
fi
675
NDB_BACKUP_DIR=$MYSQL_TEST_DIR/var/ndbcluster-$NDBCLUSTER_PORT
676
NDB_TOOLS_OUTPUT=$MYSQL_TEST_DIR/var/log/ndb_tools.log
677

678 679 680 681
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
682
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
683

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
684 685 686 687 688 689 690 691
# 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
692
[ -d $MYSQL_TEST_DIR/var/log ] || mkdir $MYSQL_TEST_DIR/var/log
693 694 695

# Use 'test', not '[' as the shell builtin might not have '-L
if test ! -L "$MYSQL_TEST_DIR/var/std_data_ln" ; then
696 697 698
  ln -s $MYSQL_TEST_DIR/std_data/ $MYSQL_TEST_DIR/var/std_data_ln
fi

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

703 704 705
# 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
706
 if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
707
   if [ -f "$BASEDIR/libmysqld/examples/mysqltest_embedded" ] ; then
708
     MYSQL_TEST="$BASEDIR/libmysqld/examples/mysqltest_embedded"
kent@mysql.com's avatar
kent@mysql.com committed
709
   else
710
     echo "Fatal error: Cannot find embedded server 'mysqltest_embedded'" 1>&2
kent@mysql.com's avatar
kent@mysql.com committed
711 712
     exit 1
   fi
713
   MYSQL_CLIENT_TEST="$BASEDIR/libmysqld/examples/mysql_client_test_embedded"
714
 else
715 716 717 718
   MYSQLD="$BASEDIR/sql/mysqld"
   if [ -n "$VALGRIND" ] ; then
     MYSQLD="$VALGRIND $MYSQLD"
   fi
kent@mysql.com's avatar
kent@mysql.com committed
719 720 721 722 723 724 725
   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
726
   MYSQL_CLIENT_TEST="$BASEDIR/tests/mysql_client_test"
727
 fi
728 729 730 731 732
 if [ -f "$BASEDIR/client/.libs/mysqlcheck" ] ; then
   MYSQL_CHECK="$BASEDIR/client/.libs/mysqlcheck"
 else
   MYSQL_CHECK="$BASEDIR/client/mysqlcheck"
 fi
733
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
734
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
735
 else
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
736
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
737
 fi
738 739 740 741 742
 if [ -f "$BASEDIR/client/.libs/mysqlslap" ] ; then
   MYSQL_SLAP="$BASEDIR/client/.libs/mysqlslap"
 else
   MYSQL_SLAP="$BASEDIR/client/mysqlslap"
 fi
patg@krsna.patg.net's avatar
patg@krsna.patg.net committed
743 744 745 746 747
 if [ -f "$BASEDIR/client/.libs/mysqlimport" ] ; then
   MYSQL_IMPORT="$BASEDIR/client/.libs/mysqlimport"
 else
   MYSQL_IMPORT="$BASEDIR/client/mysqlimport"
 fi
748 749 750 751 752
 if [ -f "$BASEDIR/client/.libs/mysqlshow" ] ; then
   MYSQL_SHOW="$BASEDIR/client/.libs/mysqlshow"
 else
   MYSQL_SHOW="$BASEDIR/client/mysqlshow"
 fi
753
 if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
754
   MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog"
755
 else
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
756
   MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog"
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
757
 fi
758 759 760
 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
761

monty@mysql.com's avatar
monty@mysql.com committed
762 763
 CLIENT_BINDIR="$BASEDIR/client"
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
764
 WAIT_PID="$BASEDIR/extra/mysql_waitpid"
765
 MYSQL_MY_PRINT_DEFAULTS="$BASEDIR/extra/my_print_defaults"
monty@mysql.com's avatar
monty@mysql.com committed
766
 MYSQL="$CLIENT_BINDIR/mysql"
767
 LANGUAGE="$BASEDIR/sql/share/english/"
768
 CHARSETSDIR="$BASEDIR/sql/share/charsets"
769
 INSTALL_DB="./install_test_db"
770
 MYSQL_FIX_SYSTEM_TABLES="$BASEDIR/scripts/mysql_fix_privilege_tables"
771 772
 NDB_TOOLS_DIR="$BASEDIR/storage/ndb/tools"
 NDB_MGM="$BASEDIR/storage/ndb/src/mgmclient/ndb_mgm"
773 774

 if [ -n "$USE_PURIFY" ] ; then
775
   PSUP="$MYSQL_TEST_DIR/suppress.purify"
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
   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

795
else
796 797 798 799 800 801 802 803

 # 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".

804 805
 if test -x "$BASEDIR/libexec/mysqld"
 then
806
   MYSQLD="$VALGRIND $BASEDIR/libexec/mysqld"
807 808
 elif test -x "$BASEDIR/bin/mysqld"
 then
809
   MYSQLD="$VALGRIND $BASEDIR/bin/mysqld"
810 811 812 813 814 815
 elif test -x "$BASEDIR/sbin/mysqld"
 then
   MYSQLD="$VALGRIND $BASEDIR/sbin/mysqld"
 else
   $ECHO "Fatal error: Cannot find program mysqld in $BASEDIR/{libexec,bin,sbin}" 1>&2
   exit 1
816
 fi
monty@mysql.com's avatar
monty@mysql.com committed
817
 CLIENT_BINDIR="$BASEDIR/bin"
818 819 820 821 822 823
 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
824
 MYSQL_TEST="$CLIENT_BINDIR/mysqltest"
825
 MYSQL_CHECK="$CLIENT_BINDIR/mysqlcheck"
826
 MYSQL_SLAP="$CLIENT_BINDIR/mysqlslap"
827
 MYSQL_SHOW="$CLIENT_BINDIR/mysqlshow"
patg@krsna.patg.net's avatar
patg@krsna.patg.net committed
828
 MYSQL_IMPORT="$CLIENT_BINDIR/mysqlimport"
monty@mysql.com's avatar
monty@mysql.com committed
829 830 831
 MYSQL_BINLOG="$CLIENT_BINDIR/mysqlbinlog"
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
 WAIT_PID="$CLIENT_BINDIR/mysql_waitpid"
832
 MYSQL_MY_PRINT_DEFAULTS="$CLIENT_BINDIR/my_print_defaults"
monty@mysql.com's avatar
monty@mysql.com committed
833
 MYSQL="$CLIENT_BINDIR/mysql"
834
 INSTALL_DB="./install_test_db --bin"
monty@mysql.com's avatar
monty@mysql.com committed
835
 MYSQL_FIX_SYSTEM_TABLES="$CLIENT_BINDIR/mysql_fix_privilege_tables"
836
 NDB_TOOLS_DIR="$CLIENT_BINDIR"
837
 NDB_MGM="$CLIENT_BINDIR/ndb_mgm"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
838
 if test -d "$BASEDIR/share/mysql/english"
839 840
 then
   LANGUAGE="$BASEDIR/share/mysql/english/"
841
   CHARSETSDIR="$BASEDIR/share/mysql/charsets"
842 843
 else
   LANGUAGE="$BASEDIR/share/english/"
844
   CHARSETSDIR="$BASEDIR/share/charsets"
845 846 847
 fi
 if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
   if [ -f "$CLIENT_BINDIR/mysqltest_embedded" ] ; then
848
     MYSQL_TEST="$CLIENT_BINDIR/mysqltest_embedded"
849 850 851 852 853 854 855 856 857 858
   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
859
   MYSQL_TEST="$CLIENT_BINDIR/mysqltest"
860 861
   MYSQL_CLIENT_TEST="$CLIENT_BINDIR/mysql_client_test"
 fi
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
862 863 864 865 866 867 868
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
 elif  [ -f "$BASEDIR/client/mysqldump" ] ; then
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
 else
   MYSQL_DUMP="$BASEDIR/bin/mysqldump"
 fi
869 870
fi

871 872 873 874 875 876 877 878 879 880
if [ -z "$MASTER_MYSQLD" ]
then
MASTER_MYSQLD=$MYSQLD
fi

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

881 882
# If we should run all tests cases, we will use a local server for that

ranger@regul.home.lan's avatar
ranger@regul.home.lan committed
883
if [ -z "$1" -a -z "$DO_STRESS" ]
884
then
885
   USE_RUNNING_SERVER=0
886
fi
887
if [ $USE_RUNNING_SERVER -eq 1 ]
888
then
889
   MASTER_MYSOCK=$LOCAL_SOCKET;
890
   DBUSER=${DBUSER:-test}
891
else
892
   DBUSER=${DBUSER:-root}		# We want to do FLUSH xxx commands
893
fi
894 895 896

if [ -w / ]
then
monty@mysql.com's avatar
monty@mysql.com committed
897 898 899
  # 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"
900 901
fi

902
MYSQL_CLIENT_TEST="$MYSQL_CLIENT_TEST --no-defaults --testcase --user=root --socket=$MASTER_MYSOCK --port=$MYSQL_TCP_PORT --silent $EXTRA_MYSQL_CLIENT_TEST_OPT"
903 904 905 906 907 908
# Need to pass additional arguments to MYSQL_CLIENT_TEST for embedded server
# -A marks each argument for passing to the function which initializes the
# embedded library
if [ "x$USE_EMBEDDED_SERVER" = "x1" ]; then
  MYSQL_CLIENT_TEST="$MYSQL_CLIENT_TEST -A --language=$LANGUAGE -A --datadir=$SLAVE_MYDDIR -A --character-sets-dir=$CHARSETSDIR"
fi
msvensson@neptunus.(none)[msvensson]'s avatar
patch  
msvensson@neptunus.(none)[msvensson] committed
909 910 911
# Save path and name of mysqldump
MYSQL_DUMP_DIR="$MYSQL_DUMP"
export MYSQL_DUMP_DIR
912 913
MYSQL_CHECK="$MYSQL_CHECK --no-defaults --debug-info -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLCHECK_OPT"
MYSQL_DUMP="$MYSQL_DUMP --no-defaults --debug-info -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
914
MYSQL_SLAP="$MYSQL_SLAP -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLSLAP_OPT"
915
MYSQL_DUMP_SLAVE="$MYSQL_DUMP_DIR --no-defaults -uroot --socket=$SLAVE_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
916
MYSQL_SHOW="$MYSQL_SHOW --no-defaults --debug-info -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLSHOW_OPT"
917 918
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --debug-info --local-load=$MYSQL_TMP_DIR  --character-sets-dir=$CHARSETSDIR $EXTRA_MYSQLBINLOG_OPT"
MYSQL_IMPORT="$MYSQL_IMPORT --no-defaults --debug-info -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
919
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"
920
MYSQL="$MYSQL --no-defaults --debug-info --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD"
921
export MYSQL MYSQL_CHECK MYSQL_DUMP MYSQL_DUMP_SLAVE MYSQL_SHOW MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES MYSQL_IMPORT
922
export CLIENT_BINDIR MYSQL_CLIENT_TEST CHARSETSDIR MYSQL_MY_PRINT_DEFAULTS
923
export MYSQL_SLAP
924
export NDB_TOOLS_DIR
925
export NDB_MGM
926
export NDB_BACKUP_DIR
927
export NDB_TOOLS_OUTPUT
928
export PURIFYOPTIONS
929 930
NDB_STATUS_OK=1
export NDB_STATUS_OK
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
931 932 933
NDB_SLAVE_STATUS_OK=1
export NDB_SLAVE_STATUS_OK
export NDB_EXTRA_TEST NDBCLUSTER_PORT NDBCLUSTER_PORT_SLAVE
934

935
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
936
 --user=$DBUSER --password=$DBPASSWD --silent -v --skip-safemalloc \
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
937
 --tmpdir=$MYSQL_TMP_DIR --port=$MASTER_MYPORT $MYSQL_TEST_SSL_OPTS"
kent@mysql.com's avatar
kent@mysql.com committed
938 939 940
if [ x$USE_TIMER = x1 ] ; then
  MYSQL_TEST_ARGS="$MYSQL_TEST_ARGS --timer-file=$MY_LOG_DIR/timer"
fi
941 942
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
943 944

# Export MYSQL_TEST variable for use from .test files
945
export MYSQL_TEST
946

947
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
948 949 950
GDB_MASTER_INIT=$MYSQL_TMP_DIR/gdbinit.master
GDB_SLAVE_INIT=$MYSQL_TMP_DIR/gdbinit.slave
GCOV_MSG=$MYSQL_TMP_DIR/mysqld-gcov.out
951 952 953 954
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
955
TIMEFILE="$MYSQL_TEST_DIR/var/log/mysqltest-time"
956
MYSQLTEST_LOG="$MYSQL_TEST_DIR/var/log/mysqltest.log"
957 958 959
if [ -n "$DO_CLIENT_GDB" -o -n "$DO_GDB" ] ; then
  XTERM=`which xterm`
fi
960

961
export MYSQL MYSQL_CHECK MYSQL_DUMP MYSQL_SHOW MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES CLIENT_BINDIR MASTER_MYSOCK
monty@mysql.com's avatar
monty@mysql.com committed
962

bk@work.mysql.com's avatar
bk@work.mysql.com committed
963 964 965 966
#++
# Function Definitions
#--

967 968
prompt_user ()
{
969
 $ECHO $1
970
 read unused
971 972
}

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

975 976 977 978
show_failed_diff ()
{
  reject_file=r/$1.reject
  result_file=r/$1.result
979
  eval_file=r/$1.eval
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
980

981 982 983 984
  if [ -f $eval_file ]
  then
    result_file=$eval_file
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
985

986 987 988 989
  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
990
    $DIFF -c $result_file $reject_file
991
    echo "-------------------------------------------------------"
992
    echo "Please follow the instructions outlined at"
cmiller@zippy.cornsilk.net's avatar
cmiller@zippy.cornsilk.net committed
993
    echo "http://forge.mysql.com/wiki/MySQL_Internals_Porting#Debugging_a_MySQL_Server"
994
    echo "to find the reason to this problem and how to report this."
995
    echo ""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
996
  fi
997
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
998

999 1000 1001 1002 1003 1004
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
1005
  $XTERM -title "Client" -e gdb -x $GDB_CLIENT_INIT $MYSQL_TEST_BIN
1006 1007
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1008
error () {
1009
    $ECHO  "Error:  $1"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1010 1011 1012
    exit 1
}

1013
error_is () {
1014 1015
    $ECHO "Errors are (from $TIMEFILE) :"
    $CAT < $TIMEFILE
1016
    $ECHO "(the last lines may be the most important ones)"
1017 1018
}

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1019
prefix_to_8() {
1020
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1021 1022
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1023
pass_inc () {
1024
    TOT_PASS=`$EXPR $TOT_PASS + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1025 1026 1027
}

fail_inc () {
1028
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1029 1030
}

1031 1032 1033 1034
skip_inc () {
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1035
total_inc () {
1036
    TOT_TEST=`$EXPR $TOT_TEST + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1037 1038
}

1039 1040 1041 1042 1043 1044

skip_test() {
   USERT="    ...."
   SYST="    ...."
   REALT="    ...."
   pname=`$ECHO "$1                        "|$CUT -c 1-24`
1045
   RES="$pname"
1046 1047 1048 1049
   skip_inc
   $ECHO "$RES$RES_SPACE [ skipped ]"
}

1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060

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
1061

1062 1063 1064
report_current_test () {
   tname=$1
   echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1065 1066 1067 1068
   eval "master1_running=\$MASTER1_RUNNING"
   if [ x$master1_running = x1 ] ; then
     echo "CURRENT_TEST: $tname" >> $MASTER_MYERR"1"
   fi
1069 1070 1071 1072 1073 1074 1075 1076
   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
1077

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1078
report_stats () {
1079
    if [ $TOT_FAIL = 0 ]; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1080
	$ECHO "All $TOT_TEST tests were successful."
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1081
    else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1082 1083 1084 1085 1086 1087
	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`
1088
	$ECHO  "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% were successful."
1089
	$ECHO ""
1090
        $ECHO "The log files in $MY_LOG_DIR may give you some hint"
1091
	$ECHO "of what went wrong."
1092
	$ECHO "If you want to report this error, please read first the documentation at"
1093
        $ECHO "http://dev.mysql.com/doc/mysql/en/mysql-test-suite.html"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1094
    fi
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1095

1096
    if [ $USE_RUNNING_SERVER -eq 0 ]
1097 1098
    then

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1099 1100 1101 1102
    # 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
1103
    $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' -e 's|InnoDB: Warning: we did not need to do crash recovery||g' \
1104 1105 1106
        $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
1107 1108

    # Find errors
1109
    for i in "^Warning:" "^Error:" "^==.* at 0x" "InnoDB: Warning" "missing DBUG_RETURN" "mysqld: Warning" "Attempting backtrace" "Assertion .* failed"
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1110
    do
1111
      if $GREP "$i" $MY_LOG_DIR/warnings.tmp >> $MY_LOG_DIR/warnings
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1112
      then
1113
        GOT_WARNINGS=1
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1114 1115 1116
      fi
    done
    $RM -f $MY_LOG_DIR/warnings.tmp
1117
    if [ $GOT_WARNINGS = "1" ]
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1118 1119 1120 1121
    then
      echo "WARNING: Got errors/warnings while running tests. Please examine"
      echo "$MY_LOG_DIR/warnings for details."
    fi
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133

    fi # USE_RUNNING_SERVER

    # Check valgrind errors from mysqltest
    if [ ! -z "$VALGRIND_MYSQLTEST" ]
    then
      if $GREP "ERROR SUMMARY" $MYSQLTEST_LOG | $GREP -v "0 errors" > /dev/null
      then
	  $ECHO "Valgrind detected errors!"
	  $GREP "ERROR SUMMARY" $MYSQLTEST_LOG | $GREP -v "0 errors"
	  $ECHO "See $MYSQLTEST_LOG"
      fi
1134
    fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1135
}
1136

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1137
mysql_install_db () {
1138
    $ECHO "Removing Stale Files"
1139 1140 1141 1142 1143
    if [ -z "$USE_OLD_DATA" ]; then
      $RM -rf $MASTER_MYDDIR $MASTER_MYDDIR"1"
      $ECHO "Installing Master Databases"
      $INSTALL_DB
      if [ $? != 0 ]; then
1144
	error "Could not install master test DBs"
1145 1146
        exit 1
      fi
1147
    fi
1148 1149 1150
    if [ ! -z "$USE_NDBCLUSTER" ]
    then
      $ECHO "Installing Master Databases 1"
1151 1152 1153 1154
#     $INSTALL_DB -1
      $RM -rf var/master-data1
      mkdir var/master-data1
      cp -r var/master-data/* var/master-data1
1155 1156 1157 1158 1159
      if [ $? != 0 ]; then
	error "Could not install master test DBs 1"
	exit 1
      fi
    fi
1160
    $ECHO "Installing Slave Databases"
1161
    $RM -rf $SLAVE_MYDDIR $MY_LOG_DIR/* 
1162 1163 1164
#    $INSTALL_DB -slave
    mkdir var/slave-data
    cp -r var/master-data/* var/slave-data
1165
    if [ $? != 0 ]; then
1166
	error "Could not install slave test DBs"
1167
	exit 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1168
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1169

1170 1171
    for slave_num in 1 2 ;
    do
1172
      $RM -rf var/slave$slave_num-data
1173 1174 1175
      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
1176
    done
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1177 1178 1179
    return 0
}

1180 1181
gprof_prepare ()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1182 1183
 $RM -rf $GPROF_DIR
 mkdir -p $GPROF_DIR
1184 1185 1186 1187 1188
}

gprof_collect ()
{
 if [ -f $MASTER_MYDDIR/gmon.out ]; then
1189
   gprof $MASTER_MYSQLD $MASTER_MYDDIR/gmon.out > $GPROF_MASTER
1190 1191 1192
   echo "Master execution profile has been saved in $GPROF_MASTER"
 fi
 if [ -f $SLAVE_MYDDIR/gmon.out ]; then
1193
   gprof $SLAVE_MYSQLD $SLAVE_MYDDIR/gmon.out > $GPROF_SLAVE
1194 1195 1196 1197
   echo "Slave execution profile has been saved in $GPROF_SLAVE"
 fi
}

1198
gcov_prepare () {
1199 1200
    $FIND $BASEDIR -name \*.gcov \
    -or -name \*.da | $XARGS $RM
1201 1202 1203
}

gcov_collect () {
1204
    $ECHO "Collecting source coverage info..."
1205 1206
    [ -f $GCOV_MSG ] && $RM $GCOV_MSG
    [ -f $GCOV_ERR ] && $RM $GCOV_ERR
1207 1208 1209
    for d in $MYSQLD_SRC_DIRS; do
	cd $BASEDIR/$d
	for f in *.h *.cc *.c; do
1210
	    $GCOV $f 2>>$GCOV_ERR  >>$GCOV_MSG
1211
	done
1212
	cd $MYSQL_TEST_DIR
1213 1214
    done

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1215
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
1216 1217
}

1218 1219 1220 1221 1222
abort_if_failed()
{
 if [ ! $? = 0 ] ; then
  echo $1
  exit 1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1223
 fi
1224 1225
}

1226
launch_in_background()
1227
{
1228
  shift
1229 1230
  echo $@ | /bin/sh  >> $CUR_MYERR 2>&1  &
  sleep 2 #hack
1231
  return
1232 1233
}

1234
shutdown_mysqld()
1235
{
1236 1237
  pid=$1
  ident=$2
1238 1239 1240 1241 1242 1243 1244 1245
  # Shutdown time must be high as slave may be in reconnect
  $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock$3 --connect_timeout=5 --shutdown_timeout=70 shutdown >> $MYSQL_MANAGER_LOG 2>&1
  res=$?
  # Some systems require an extra connect
  $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock$3 --connect_timeout=1 ping >> $MYSQL_MANAGER_LOG 2>&1
  if test $res = 0
  then
    wait_for_pid $pid
1246
  fi
1247
  return $res
1248 1249
}

1250 1251
start_ndbcluster()
{
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1252 1253 1254 1255 1256 1257 1258
  if [ ! -n "$USE_NDBCLUSTER" ] ;
  then
    USING_NDBCLUSTER=0
    USE_NDBCLUSTER_OPT=
  fi
  
  if [ x$USING_NDBCLUSTER = x1 -a -z "$USE_NDBCLUSTER_OPT" ]
1259
  then
joreland@mysql.com's avatar
merge  
joreland@mysql.com committed
1260
  rm -f $NDB_TOOLS_OUTPUT
1261 1262
  if [ -z "$USE_RUNNING_NDBCLUSTER" ]
  then
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1263
    if [ "$DO_BENCH" != 1 -a -z "$NDBCLUSTER_EXTRA_OPTS" ]
1264
    then
1265
      NDBCLUSTER_EXTRA_OPTS="--small"
1266
    fi
1267
    OPTS="$NDBCLUSTER_OPTS $NDBCLUSTER_EXTRA_OPTS --character-sets-dir=$CHARSETSDIR --verbose=$NDB_VERBOSE --initial --relative-config-data-dir --core"
1268 1269 1270
    if [ "x$NDB_VERBOSE" != "x0" ] ; then
      echo "Starting master ndbcluster " $OPTS
    fi
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1271
    ./ndb/ndbcluster $OPTS || NDB_STATUS_OK=0
1272
    if [ x$NDB_STATUS_OK != x1 ] ; then
1273 1274 1275
      if [ x$FORCE != x1 ] ; then
        exit 1
      fi
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1276 1277
      USING_NDBCLUSTER=0
      USE_NDBCLUSTER_OPT=
1278
      return
1279
    fi
1280

1281
    NDB_CONNECTSTRING="host=localhost:$NDBCLUSTER_PORT"
1282
  else
1283 1284
    NDB_CONNECTSTRING="$USE_RUNNING_NDBCLUSTER"
    echo "Using ndbcluster at $NDB_CONNECTSTRING"
1285
  fi
1286
  USE_NDBCLUSTER_OPT="$USE_NDBCLUSTER --ndb-connectstring=\"$NDB_CONNECTSTRING\" --ndb-extra-logging"
1287
  export NDB_CONNECTSTRING
1288 1289 1290
  fi
}

tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1291 1292
rm_ndbcluster_tables()
{
1293 1294
  $RM -f $1/mysql/apply_status*
  $RM -f $1/mysql/schema*
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1295 1296
}

1297 1298
stop_ndbcluster()
{
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1299
 if [ -n "$USE_NDBCLUSTER_OPT" ]
1300
 then
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1301
 USE_NDBCLUSTER_OPT=
1302 1303 1304
 if [ -z "$USE_RUNNING_NDBCLUSTER" ]
 then
   # Kill any running ndbcluster stuff
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1305
   $ECHO "Stopping master cluster"
1306
   ./ndb/ndbcluster $NDBCLUSTER_OPTS --stop
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1307 1308 1309
   # remove ndb table the hard way as not to upset later tests
   rm_ndbcluster_tables $MASTER_MYDDIR
   rm_ndbcluster_tables $MASTER_MYDDIR"1"
1310 1311 1312 1313
 fi
 fi
}

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

1317 1318
start_master()
{
1319 1320
  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
1321 1322
    return
  fi
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1323 1324 1325
  # 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
1326
    $RM -f $MYSQL_TEST_DIR/var/log/master-bin$1.*
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1327 1328
  fi

1329
  # Remove old master.info and relay-log.info files
1330
  $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
1331 1332 1333 1334 1335 1336 1337 1338

  #run master initialization shell script if one exists

  if [ -f "$master_init_script" ] ;
  then
      /bin/sh $master_init_script
  fi
  cd $BASEDIR # for gcov
1339 1340 1341
  if [ -n "$1" ] ; then
   id=`$EXPR $1 + 101`;
   this_master_myport=`$EXPR $MASTER_MYPORT + $1`
1342
   NOT_FIRST_MASTER_EXTRA_OPTS="--skip-innodb"
1343 1344
   eval "MASTER_MYPORT$1=$this_master_myport"
   export MASTER_MYPORT$1
1345 1346 1347
  else
   id=1;
   this_master_myport=$MASTER_MYPORT
1348
   NOT_FIRST_MASTER_EXTRA_OPTS=""
1349
  fi
1350 1351
  if [ -n "$EXTRA_MASTER_MYSQLD_TRACE" ] 
  then
1352
      CURR_MASTER_MYSQLD_TRACE="$EXTRA_MASTER_MYSQLD_TRACE$1"
1353
  fi
1354 1355
  if [ x$MASTER_MYSQLDBINLOG = x1 ]
  then
1356
    MASTER_MYSQLD_BINLOG_OPT="--log-bin=$MYSQL_TEST_DIR/var/log/master-bin$1"
1357
  fi
1358
  if [ -z "$DO_BENCH" -a -z "$DO_STRESS"  ]
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1359
  then
1360
    master_args="--no-defaults \
1361
  	    --server-id=$id  \
1362
          --basedir=$MY_BASEDIR \
1363
          --port=$this_master_myport \
1364
          --port-open-timeout=380 \
1365
          --local-infile \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1366 1367
          --exit-info=256 \
          --core \
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1368
          $USE_NDBCLUSTER_OPT \
1369 1370 1371 1372
          --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
1373 1374 1375 1376
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
1377
          --innodb_data_file_path=ibdata1:128M:autoextend \
1378
	  --open-files-limit=1024 \
1379
          --log-bin-trust-function-creators \
1380
	   $MASTER_40_ARGS \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1381
           $SMALL_SERVER \
1382
           $MASTER_MYSQLD_BINLOG_OPT \
1383
           $EXTRA_MASTER_MYSQLD_OPT $EXTRA_MASTER_OPT \
1384
           $NOT_FIRST_MASTER_EXTRA_OPTS $CURR_MASTER_MYSQLD_TRACE"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1385
  else
1386
    master_args="--no-defaults \
1387
          --server-id=$id --rpl-recovery-rank=1 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1388
          --basedir=$MY_BASEDIR --init-rpl-role=master \
1389
          --port=$this_master_myport \
1390
          --port-open-timeout=380 \
1391
          --local-infile \
1392 1393 1394
          --datadir=$MASTER_MYDDIR$1 \
          --pid-file=$MASTER_MYPID$1 \
          --socket=$MASTER_MYSOCK$1 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1395 1396 1397
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core \
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1398
          $USE_NDBCLUSTER_OPT \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1399 1400
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
1401
          --innodb_data_file_path=ibdata1:128M:autoextend \
1402
          --log-bin-trust-function-creators \
1403
	   $MASTER_40_ARGS \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1404
           $SMALL_SERVER \
1405
           $MASTER_MYSQLD_BINLOG_OPT \
1406
           $EXTRA_MASTER_MYSQLD_OPT $EXTRA_MASTER_OPT \
1407
           $NOT_FIRST_MASTER_EXTRA_OPTS"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1408 1409
  fi

1410 1411
  CUR_MYERR=$MASTER_MYERR$1
  CUR_MYSOCK=$MASTER_MYSOCK$1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1412

kent@mysql.com's avatar
kent@mysql.com committed
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
  # 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
1425 1426
  if [ x$DO_DDD = x1 ]
  then
1427
    $ECHO "set args $master_args" > $GDB_MASTER_INIT$1
1428
    launch_in_background master ddd -display $DISPLAY --debugger \
1429
    "gdb -x $GDB_MASTER_INIT$1" $MASTER_MYSQLD
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1430 1431
  elif [ x$DO_GDB = x1 ]
  then
1432 1433
    if [ x$MANUAL_GDB = x1 ]
    then
1434
      $ECHO "set args $master_args" > $GDB_MASTER_INIT$1
1435
      $ECHO "To start gdb for the master , type in another window:"
1436
      $ECHO "cd $MYSQL_TEST_DIR ; gdb -x $GDB_MASTER_INIT$1 $MASTER_MYSQLD"
1437 1438 1439 1440
      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
1441
    cat <<EOF
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1442 1443
b mysql_parse
commands 1
1444
disa 1
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
1445
end
1446 1447
r
EOF
1448
      fi )  > $GDB_MASTER_INIT$1
1449
      launch_in_background master $XTERM -display $DISPLAY \
1450
      -title "Master" -e gdb -x $GDB_MASTER_INIT$1 $MASTER_MYSQLD
1451
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1452
  else
1453
    launch_in_background master $MASTER_MYSQLD $master_args
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1454
  fi
1455
  sleep_until_file_created $MASTER_MYPID$1 $wait_for_master
1456
  wait_for_master=$SLEEP_TIME_FOR_SECOND_MASTER
1457
  eval "MASTER$1_RUNNING=1"
1458 1459 1460 1461
}

start_slave()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1462 1463 1464
  [ x$SKIP_SLAVE = x1 ] && return
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  [ x$this_slave_running = 1 ] && return
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1465

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1466 1467
  # 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
1468 1469 1470 1471 1472 1473 1474 1475
  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"
1476
   slave_datadir="$SLAVE_MYDDIR/../$slave_ident-data/"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
   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
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499

  #
  if [ x$USING_NDBCLUSTER = x1 -a -n "$USE_NDBCLUSTER_SLAVE" ] ; then
    if [ $slave_server_id -eq 2 ] ; then
      savedir=`pwd`
      cd $MYSQL_TEST_DIR
      if [ "$DO_BENCH" != 1 -a -z "$NDBCLUSTER_EXTRA_OPTS" ]
       then
         NDBCLUSTER_EXTRA_OPTS="--small"
      fi

1500
      OPTS="$NDBCLUSTER_OPTS_SLAVE --initial $NDBCLUSTER_EXTRA_OPTS --ndbd-nodes=1 --verbose=$NDB_VERBOSE --relative-config-data-dir --core"
1501 1502 1503
      if [ "x$NDB_VERBOSE" != "x0" ] ; then
        echo "Starting slave ndbcluster " $OPTS
      fi
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520
      ./ndb/ndbcluster $OPTS \
                      || NDB_SLAVE_STATUS_OK=0
      #                > /dev/null 2>&1 || NDB_SLAVE_STATUS_OK=0
      cd $savedir
      if [ x$NDB_SLAVE_STATUS_OK != x1 ] ; then
        if [ x$FORCE != x1 ] ; then
          exit 1
        fi
        USE_NDBCLUSTER_SLAVE_OPT=
        USE_NDBCLUSTER_SLAVE=
      fi
      USE_NDBCLUSTER_SLAVE_OPT=$USE_NDBCLUSTER_SLAVE
    fi
  else
    USE_NDBCLUSTER_SLAVE_OPT=
  fi

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1521
  # Remove stale binary logs and old master.info files
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1522 1523 1524 1525 1526 1527
  # 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
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538

  #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 \
1539
          --master-password="" \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1540 1541 1542 1543 1544 1545
          --master-port=$MASTER_MYPORT \
          --server-id=$slave_server_id --rpl-recovery-rank=$slave_rpl_rank"
 else
   master_info=$SLAVE_MASTER_INFO
 fi

tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1546 1547
  if [ x$SLAVE_MYSQLDBINLOG = x1 ]
  then
1548
    SLAVE_MYSQLD_BINLOG_OPT="--log-bin=$MYSQL_TEST_DIR/var/log/$slave_ident-bin --log-slave-updates"
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1549 1550
  fi

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1551 1552 1553
  $RM -f $slave_datadir/log.*
  slave_args="--no-defaults $master_info \
  	    --exit-info=256 \
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1554
          $SLAVE_MYSQLDBINLOG_OPT \
1555
          --relay-log=$MYSQL_TEST_DIR/var/log/$slave_ident-relay-bin \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1556 1557 1558 1559 1560
          --log=$slave_log \
          --basedir=$MY_BASEDIR \
          --datadir=$slave_datadir \
          --pid-file=$slave_pid \
          --port=$slave_port \
1561
          --port-open-timeout=380 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1562 1563 1564 1565 1566 1567
          --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
1568
          --skip-innodb --skip-ndbcluster --skip-slave-start \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1569 1570 1571
          --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
          --report-host=127.0.0.1 --report-user=root \
          --report-port=$slave_port \
1572
          --master-retry-count=10 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1573
          -O slave_net_timeout=10 \
1574
          --log-bin-trust-function-creators \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1575
           $SMALL_SERVER \
1576
           $SLAVE_MYSQLD_BINLOG_OPT \
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1577 1578
           $EXTRA_SLAVE_MYSQLD_OPT $EXTRA_SLAVE_OPT \
           $USE_NDBCLUSTER_SLAVE_OPT"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1579 1580 1581 1582 1583
  CUR_MYERR=$slave_err
  CUR_MYSOCK=$slave_sock

  if [ x$DO_DDD = x1 ]
  then
1584
    $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
1585
    launch_in_background $slave_ident ddd -display $DISPLAY --debugger \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1586 1587 1588
     "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD
  elif [ x$DO_GDB = x1 ]
  then
1589 1590
    if [ x$MANUAL_GDB = x1 ]
    then
1591
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
1592
      echo "To start gdb for the slave, type in another window:"
1593
      echo "cd $MYSQL_TEST_DIR ; gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD"
1594 1595
      wait_for_slave=1500
    else
1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
      ( $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
1606
      launch_in_background $slave_ident $XTERM -display $DISPLAY -title "Slave" -e \
1607 1608
      gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1609
  else
1610
    launch_in_background $slave_ident $SLAVE_MYSQLD $slave_args
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1611 1612
  fi
  eval "SLAVE$1_RUNNING=1"
1613
  sleep_until_file_created $slave_pid $wait_for_slave
1614
  wait_for_slave=$SLEEP_TIME_FOR_SECOND_SLAVE
1615 1616
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1617 1618
mysql_start ()
{
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1619
# 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
1620
# for the test.  Better to let the test start the daemon
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1621 1622 1623 1624

#  $ECHO "Starting MySQL daemon"
#  start_master
#  start_slave
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1625 1626
  cd $MYSQL_TEST_DIR
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1627 1628
}

1629 1630
stop_slave ()
{
1631 1632 1633
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ -n "$1" ] ;
1634
  then
1635 1636 1637
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
  else
   slave_pid=$SLAVE_MYPID
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1638
  fi
1639 1640
  if [ x$this_slave_running = x1 ]
  then
1641
    pid=`$CAT $slave_pid`
1642
    shutdown_mysqld $pid $slave_ident
1643
    if [ $? != 0 ] && [ -f $slave_pid ]
1644
    then # try harder!
1645
      $ECHO "slave not cooperating with mysqladmin, will try manual kill"
1646 1647
      kill $pid
      sleep_until_file_deleted $pid $slave_pid
1648 1649 1650 1651 1652 1653 1654 1655 1656
      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
1657
    fi
1658
    eval "SLAVE$1_RUNNING=0"
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1659 1660 1661 1662 1663 1664 1665 1666
    if [ -n "$USE_NDBCLUSTER_SLAVE_OPT" ] ; then
      savedir=`pwd`
      cd $MYSQL_TEST_DIR
        $ECHO "Stopping slave cluster"
      ./ndb/ndbcluster $NDBCLUSTER_OPTS_SLAVE --stop
      rm_ndbcluster_tables $SLAVE_MYDDIR
      cd $savedir
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1667
  fi
1668
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1669

1670 1671 1672 1673 1674 1675 1676 1677 1678 1679
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
}

1680 1681
stop_master ()
{
1682 1683
  eval "this_master_running=\$MASTER$1_RUNNING"
  if [ x$this_master_running = x1 ]
1684
  then
kent@mysql.com's avatar
kent@mysql.com committed
1685 1686 1687
    # 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
1688
      pid=`$CAT $MASTER_MYPID$1`
1689
      shutdown_mysqld $pid master $1
tomas@poseidon.ndb.mysql.com's avatar
Merge  
tomas@poseidon.ndb.mysql.com committed
1690
      if [ $? != 0 ] && [ -f $MASTER_MYPID$1 ]
kent@mysql.com's avatar
kent@mysql.com committed
1691 1692 1693
      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
1694 1695
	sleep_until_file_deleted $pid $MASTER_MYPID$1
	if [ -f $MASTER_MYPID$1 ] ; then
kent@mysql.com's avatar
kent@mysql.com committed
1696
	  $ECHO "master refused to die. Sending SIGKILL"
tomas@poseidon.ndb.mysql.com's avatar
Merge  
tomas@poseidon.ndb.mysql.com committed
1697 1698
	  kill -9 `$CAT $MASTER_MYPID$1`
	  $RM -f $MASTER_MYPID$1
kent@mysql.com's avatar
kent@mysql.com committed
1699 1700 1701
	else
	  $ECHO "master responded to SIGTERM "
	fi
1702
      else
kent@mysql.com's avatar
kent@mysql.com committed
1703
	sleep $SLEEP_TIME_AFTER_RESTART
1704
      fi
1705
    fi
1706
    eval "MASTER$1_RUNNING=0"
1707 1708
  fi
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1709

1710 1711
mysql_stop ()
{
1712 1713 1714 1715 1716 1717
  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
1718
    stop_master 1
1719 1720 1721 1722 1723
    $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
1724
    stop_ndbcluster
1725 1726
  fi
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1727 1728
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1729 1730 1731 1732 1733
mysql_restart ()
{
  mysql_stop
  mysql_start
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1734 1735 1736
}

mysql_loadstd () {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1737 1738

    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1739 1740 1741
    return 1
}

1742 1743 1744
run_testcase ()
{
 tf=$1
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1745
 tname=`$BASENAME $tf .test`
1746 1747
 master_opt_file=$TESTDIR/$tname-master.opt
 slave_opt_file=$TESTDIR/$tname-slave.opt
1748 1749
 master_init_script=$TESTDIR/$tname-master.sh
 slave_init_script=$TESTDIR/$tname-slave.sh
1750
 slave_master_info_file=$TESTDIR/$tname.slave-mi
kent@mysql.com's avatar
kent@mysql.com committed
1751 1752
 tsrcdir=$TESTDIR/$tname-src
 result_file="r/$tname.result"
1753
 echo $tname > $CURRENT_TEST
1754
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0 \& \( $tname : federated \) = 0`
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1755
 NDBCLUSTER_TEST=`$EXPR \( $tname : '.*ndb.*' \) != 0`
1756 1757 1758
 if [ "x$USE_NDBCLUSTER_ALL" = "x1" ] ; then
   NDBCLUSTER_TEST=1
 fi
1759 1760 1761 1762
 if [ "x$USE_NDBCLUSTER_ONLY" = "x1" -a "x$NDBCLUSTER_TEST" != "x1" ] ; then
   skip_test $tname
   return
 fi
1763
 if [ "$USE_MANAGER" = 1 ] ; then
guilhem@mysql.com's avatar
guilhem@mysql.com committed
1764
  many_slaves=`$EXPR \( \( $tname : rpl_failsafe \) != 0 \) \| \( \( $tname : rpl_chain_temp_table \) != 0 \)`
1765 1766 1767 1768
 fi
 if $EXPR "$tname" '<' "$START_FROM" > /dev/null ; then
   #skip_test $tname
   return
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1769 1770
 fi

1771 1772 1773 1774
 if [ "$SKIP_TEST" ] ; then
   if $EXPR \( "$tname" : "$SKIP_TEST" \) > /dev/null ; then
     skip_test $tname
     return
1775
   fi
1776
 fi
1777

1778 1779
 if [ "$DO_TEST" ] ; then
   if $EXPR \( "$tname" : "$DO_TEST" \) > /dev/null ; then
1780
     : #empty command to keep some shells happy
1781 1782 1783
   else
     #skip_test $tname
     return
1784
   fi
1785
 fi
1786

1787 1788
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ; then
   skip_test $tname
1789 1790 1791
   return
 fi

kent@mysql.com's avatar
kent@mysql.com committed
1792 1793 1794 1795 1796 1797
# 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
1798 1799 1800 1801 1802 1803 1804 1805
 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
1806 1807
 fi

kent@mysql.com's avatar
kent@mysql.com committed
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819
 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 \
1820 1821
       "init_connect" \
       "init_file"
kent@mysql.com's avatar
kent@mysql.com committed
1822 1823 1824 1825 1826 1827 1828
   do
     if [ "$tname" = "$t" ] ; then
       skip_test $tname
       return
     fi
   done
 fi
1829

1830
 if [ $USE_RUNNING_SERVER -eq 0 ] ;
1831
 then
1832 1833
   if [ -f $master_opt_file ] ;
   then
1834
     EXTRA_MASTER_OPT=`$CAT $master_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1835 1836 1837 1838 1839 1840 1841
     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=" "
	 ;;
1842 1843
       --result-file=*)
         result_file=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--result-file=;;"`
kent@mysql.com's avatar
kent@mysql.com committed
1844
         result_file="r/$result_file.result"
1845
         # Note that this must be set to space, not "" for test-reset to work
1846 1847
	 EXTRA_MASTER_OPT=" "
         ;;
1848 1849 1850 1851
       --force-restart)
         # Note that this must be set to space, not "" for test-reset to work
	 EXTRA_MASTER_OPT=" "
	 ;;
1852
     esac
1853
     stop_master
1854
     stop_master 1
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1855 1856 1857 1858 1859 1860 1861

     # only stop the cluster if this test will not use cluster
     if [ x$NDBCLUSTER_TEST != x1 ] ;
     then
       stop_ndbcluster
     fi

1862
     report_current_test $tname
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1863 1864 1865
     USING_NDBCLUSTER=$NDBCLUSTER_TEST
     # start_ndbcluster knows if cluster is already started
     start_ndbcluster
1866
     start_master
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1867
     if [ x$USING_NDBCLUSTER = x1 -a -z "$DO_BENCH" -a -z "$DO_STRESS" ] ; then
1868
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR"1"
1869 1870
       start_master 1
     fi
1871
     TZ=$MY_TZ; export TZ
1872
   else
kent@mysql.com's avatar
kent@mysql.com committed
1873 1874 1875 1876
     # 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 ] || \
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1877 1878
	[ -f $master_init_script ] || \
        [ -n "$USE_NDBCLUSTER" -a x$NDBCLUSTER_TEST != x$USING_NDBCLUSTER ]
1879 1880 1881
     then
       EXTRA_MASTER_OPT=""
       stop_master
1882
       stop_master 1
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1883 1884 1885 1886 1887 1888 1889

       # only stop the cluster if this test will not use cluster
       if [ x$NDBCLUSTER_TEST != x1 ] ;
       then
         stop_ndbcluster
       fi

1890
       report_current_test $tname
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1891 1892 1893
       USING_NDBCLUSTER=$NDBCLUSTER_TEST
       # start_ndbcluster knows if cluster is already started
       start_ndbcluster
1894
       start_master
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1895
       if [ x$USING_NDBCLUSTER = x1  -a -z "$DO_BENCH" -a -z "$DO_STRESS" ] ; then
1896
         echo "CURRENT_TEST: $tname" >> $MASTER_MYERR"1"
1897 1898
         start_master 1
       fi
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1899
     else
1900
       report_current_test $tname
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1901
     fi
1902
   fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1903

kent@mysql.com's avatar
kent@mysql.com committed
1904 1905 1906 1907
   # 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 ] ;
1908
     then
kent@mysql.com's avatar
kent@mysql.com committed
1909
       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
1910
       do_slave_restart=1
kent@mysql.com's avatar
kent@mysql.com committed
1911 1912 1913 1914 1915 1916
     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
1917
     fi
1918

kent@mysql.com's avatar
kent@mysql.com committed
1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929
     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

tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941
     USING_NDBCLUSTER=$NDBCLUSTER_TEST
     if [ -n "$USE_NDBCLUSTER_SLAVE_OPT" ] ; then
       if [ x$USING_NDBCLUSTER != x1 ] ; then
         do_slave_restart=1
       fi
     else
       if [ x$USING_NDBCLUSTER = x1 ] ; then
         do_slave_restart=1
       fi
     fi


kent@mysql.com's avatar
kent@mysql.com committed
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
     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
1953
   fi
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
1954
 fi
1955 1956 1957 1958 1959 1960

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

1961
 cd $MYSQL_TEST_DIR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1962

1963
 if [ -f $tf ] ; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1964
    $RM -f r/$tname.*reject
kent@mysql.com's avatar
kent@mysql.com committed
1965
    mysql_test_args="-R $result_file $EXTRA_MYSQL_TEST_OPT"
1966
    if [ -z "$DO_CLIENT_GDB" ] ; then
1967
      `$VALGRIND_MYSQLTEST $MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`;
1968
    else
1969
      do_gdb_test "$mysql_test_args" "$tf"
1970
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1971

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1972 1973
    res=$?

1974 1975 1976 1977
    # Save the testcase log to mysqltest log file
    echo "CURRENT_TEST: $tname" >> $MYSQLTEST_LOG
    cat $TIMEFILE >> $MYSQLTEST_LOG

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

1981 1982 1983 1984
    if [ x$many_slaves = x1 ] ; then
     stop_slave 1
     stop_slave 2
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1985

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1986
    if [ $res = 0 ]; then
1987 1988
      total_inc
      pass_inc
kent@mysql.com's avatar
kent@mysql.com committed
1989
      TIMER=""
kent@mysql.com's avatar
kent@mysql.com committed
1990
      if [ x$USE_TIMER = x1 -a -f "$MY_LOG_DIR/timer" ]; then
kent@mysql.com's avatar
kent@mysql.com committed
1991 1992 1993 1994
	TIMER=`cat $MY_LOG_DIR/timer`
	TIMER=`$PRINTF "%13s" $TIMER`
      fi
      $ECHO "$RES$RES_SPACE [ pass ]   $TIMER"
1995
    else
1996
      # why the following ``if'' ? That is why res==1 is special ?
1997
      if [ $res = 62 ]; then
1998 1999 2000
        skip_inc
	$ECHO "$RES$RES_SPACE [ skipped ]"
      else
2001
        if [ $res -ne 1 ]; then
2002 2003
          $ECHO "mysqltest returned unexpected code $res, it has probably crashed" >> $TIMEFILE
        fi
2004
	total_inc
2005
        fail_inc
2006
	$ECHO "$RES$RES_SPACE [ fail ]"
2007 2008
        $ECHO
	error_is
kent@mysql.com's avatar
kent@mysql.com committed
2009
	show_failed_diff $tname
2010
	$ECHO
2011
	if [ x$FORCE != x1 ] ; then
2012
	 $ECHO "Aborting: $tname failed in $TEST_MODE mode. To continue, re-run with '--force'."
2013
	 $ECHO
2014
         if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && \
kent@mysql.com's avatar
kent@mysql.com committed
2015
	    [ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2016 2017 2018
	 then
	   mysql_stop
   	 fi
2019 2020
	 exit 1
	fi
kent@mysql.com's avatar
kent@mysql.com committed
2021
	FAILED_CASES="$FAILED_CASES $tname"
2022
        if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && \
kent@mysql.com's avatar
kent@mysql.com committed
2023
	   [ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2024 2025 2026
	then
	  mysql_restart
	fi
2027
      fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2028
    fi
2029
  fi
2030 2031
}

2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064
run_stress_test()
{

  STRESS_BASEDIR="$MYSQL_TEST_DIR/var/stress"

  #Clean-up old stress test basedir
  if [ -d $STRESS_BASEDIR ] ; then 
    $RM -rf $STRESS_BASEDIR
  fi
  #Create stress test basedir 
  mkdir $STRESS_BASEDIR

  if [ "$STRESS_SUITE" != "main" -a "$STRESS_SUITE" != "default" ] ; then
    STRESS_SUITE_DIR="$MYSQL_TEST_DIR/suite/$STRESS_SUITE"
  else
    STRESS_SUITE_DIR="$MYSQL_TEST_DIR"
  fi

  if [ -d "$STRESS_SUITE_DIR" ] ; then 
    STRESS_SUITE_T_DIR="$STRESS_SUITE_DIR/t"
    STRESS_SUITE_R_DIR="$STRESS_SUITE_DIR/r"
    #FIXME: check that dirs above are exist
  else
    echo "Directory $STRESS_SUITE_DIR with test suite doesn't exists. Abort stress testing"
    exit 1
  fi
  
  if [ -n "$STRESS_TEST" ] ; then 
    STRESS_TEST_FILE="$STRESS_BASEDIR/stress_tests.txt"
    echo $STRESS_TEST > $STRESS_TEST_FILE
  elif [ -n "$STRESS_TEST_FILE" ] ; then    
    STRESS_TEST_FILE="$STRESS_SUITE_DIR/$STRESS_TEST_FILE"
    if [ ! -f  "$STRESS_TEST_FILE" ] ; then 
ranger@regul.home.lan's avatar
ranger@regul.home.lan committed
2065 2066
      echo "Specified file $STRESS_TEST_FILE with list of tests does not exist"
      echo "Please ensure that file exists and has proper permissions"
2067 2068 2069 2070 2071
      exit 1
    fi
  else 
    STRESS_TEST_FILE="$STRESS_SUITE_DIR/stress_tests.txt"
    if [ ! -f  "$STRESS_TEST_FILE" ] ; then 
ranger@regul.home.lan's avatar
ranger@regul.home.lan committed
2072 2073 2074
      echo "Default file $STRESS_TEST_FILE with list of tests does not exist."
      echo "Please use --stress-test-file option to specify custom one or you can" 
      echo "just specify name of test for testing as last argument in command line"
2075 2076 2077 2078 2079 2080 2081
      exit 1
    fi
  fi

  if [ -n "$STRESS_INIT_FILE" ] ; then 
    STRESS_INIT_FILE="$STRESS_SUITE_DIR/$STRESS_INIT_FILE"
    if [ ! -f  "$STRESS_INIT_FILE" ] ; then 
ranger@regul.home.lan's avatar
ranger@regul.home.lan committed
2082 2083
      echo "Specified file $STRESS_INIT_FILE with list of tests doesn't exist."
      echo "Please ensure that file exists and has proper permissions"
2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094
      exit 1
    fi
  else
    STRESS_INIT_FILE="$STRESS_SUITE_DIR/stress_init.txt"
    #Check for default init file
    if [ ! -f "$STRESS_INIT_FILE" ] ; then 
      STRESS_INIT_FILE=""
    fi
  fi

  if [ "$STRESS_MODE" != "random" -a "$STRESS_MODE" != "seq" ] ; then
ranger@regul.home.lan's avatar
ranger@regul.home.lan committed
2095 2096
    echo "You specified wrong mode '$STRESS_MODE' for stress test."
    echo "Correct values are 'random' or 'seq'"
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108
    exit 1
  fi
 
  STRESS_TEST_ARGS="--server-socket=$MASTER_MYSOCK \
                    --server-user=$DBUSER \
                    --server-database=$DB \
                    --stress-suite-basedir=$MYSQL_TEST_DIR \
                    --suite=$STRESS_SUITE \
                    --stress-tests-file=$STRESS_TEST_FILE \
                    --stress-basedir=$STRESS_BASEDIR \
                    --server-logs-dir=$STRESS_BASEDIR \
                    --stress-mode=$STRESS_MODE \
2109
                    --mysqltest=$CLIENT_BINDIR/mysqltest \
2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
                    --threads=$STRESS_THREADS \
                    --verbose \
                    --cleanup \
                    --log-error-details \
                    --abort-on-error" 
  
  if [ -n "$STRESS_INIT_FILE" ] ; then 
    STRESS_TEST_ARGS="$STRESS_TEST_ARGS --stress-init-file=$STRESS_INIT_FILE"
  fi

2120 2121 2122 2123 2124 2125 2126 2127
  if [ -z "$STRESS_LOOP_COUNT" -a -z  "$STRESS_TEST_COUNT" -a 
       -z "$STRESS_TEST_DURATION" ] ; then 

    #Limit stress testing with 20 loops in case when any limit parameter
    #was specified
    STRESS_TEST_COUNT=20
  fi

2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158
  if [ -n "$STRESS_LOOP_COUNT" ] ; then 
    STRESS_TEST_ARGS="$STRESS_TEST_ARGS --loop-count=$STRESS_LOOP_COUNT"
  fi

  if [ -n "$STRESS_TEST_COUNT" ] ; then 
    STRESS_TEST_ARGS="$STRESS_TEST_ARGS --test-count=$STRESS_TEST_COUNT"
  fi

  if [ -n "$STRESS_TEST_DURATION" ] ; then 
    STRESS_TEST_ARGS="$STRESS_TEST_ARGS --test-duration=$STRESS_TEST_DURATION"
  fi  

  echo "Stress test related variables:"
  echo "TESTS                - $1"
  echo "STRESS               - $DO_STRESS"
  echo "STRESS_SUITE         - $STRESS_SUITE"
  echo "STRESS_TEST_FILE     - $STRESS_TEST_FILE"
  echo "STRESS_INIT_FILE     - $STRESS_INIT_FILE"
  echo "STRESS_THREADS       - $STRESS_THREADS"
  echo "STRESS_MODE          - $STRESS_MODE"
  echo "STRESS_TEST_COUNT    - $STRESS_TEST_COUNT"
  echo "STRESS_LOOP_COUNT    - $STRESS_LOOP_COUNT"  
  echo "STRESS_TEST_DURATION - $STRESS_TEST_DURATION"

  #echo "$STRESS_TEST_ARGS";
  #Run stress test 
  $MYSQL_TEST_DIR/mysql-stress-test.pl $STRESS_TEST_ARGS


}

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
2159 2160 2161 2162
######################################################################
# Main script starts here
######################################################################

2163 2164
[ "$DO_GCOV" -a ! -x "$GCOV" ] && error "No gcov found"

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2165 2166
[ "$DO_GCOV" ] && gcov_prepare
[ "$DO_GPROF" ] && gprof_prepare
2167

2168
if [ $USE_RUNNING_SERVER -eq 0 ]
2169
then
2170 2171 2172 2173
  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
2174
    $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK1 -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2175
    $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2176
    $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT --protocol=tcp -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2177
    $MYSQLADMIN --no-defaults --host=$hostname --protocol=tcp --port=`expr $MASTER_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2178 2179
    $MYSQLADMIN --no-defaults --host=$hostname --protocol=tcp --port=$SLAVE_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --host=$hostname --protocol=tcp --port=`expr $SLAVE_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2180
    sleep_until_file_deleted 0 $MASTER_MYPID
2181
    sleep_until_file_deleted 0 $MASTER_MYPID"1"
2182 2183
    sleep_until_file_deleted 0 $SLAVE_MYPID
  else
2184
    rm $MASTER_MYPID $MASTER_MYPID"1" $SLAVE_MYPID
2185
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2186

tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
2187 2188
  # just to force stopping anything from previous runs
  USE_NDBCLUSTER_OPT=$USE_NDBCLUSTER
2189
  stop_ndbcluster
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
2190

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2191
  # Remove files that can cause problems
2192
  $RM -rf $MYSQL_TEST_DIR/var/ndbcluster
2193
  $RM -rf $MYSQL_TEST_DIR/var/tmp/snapshot*
2194
  $RM -rf $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2195

2196 2197
  # Remove old berkeley db log files that can confuse the server
  $RM -f $MASTER_MYDDIR/log.*
2198
  $RM -f $MASTER_MYDDIR"1"/log.*
2199

2200 2201 2202
  # Remove old log and reject files
  $RM -f r/*.reject r/*.progress r/*.log r/*.warnings

2203 2204
  wait_for_master=$SLEEP_TIME_FOR_FIRST_MASTER
  wait_for_slave=$SLEEP_TIME_FOR_FIRST_SLAVE
2205 2206
  $ECHO "Installing Test Databases"
  mysql_install_db
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
2207

2208 2209
  if [ -n "$1" -a `expr "X$*" : '.*ndb'` -eq 0 ]
  then
tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
2210 2211
    USING_NDBCLUSTER=0
    USE_NDBCLUSTER_OPT=
2212 2213
  fi

kostja@bodhi.local's avatar
kostja@bodhi.local committed
2214
  mysql_start
2215 2216
  $ECHO  "Loading Standard Test Databases"
  mysql_loadstd
2217 2218
fi

2219
$ECHO  "Starting Tests"
2220

2221 2222 2223
# Some test cases need USE_RUNNING_SERVER
export USE_RUNNING_SERVER

2224 2225 2226
#
# This can probably be deleted
#
2227 2228
if [ "$DO_BENCH" = 1 ]
then
2229 2230
  start_master

2231 2232 2233 2234 2235
  if [ "$DO_SMALL_BENCH" = 1 ]
  then
    EXTRA_BENCH_ARGS="--small-test --small-tables"
  fi

tomas@poseidon.ndb.mysql.com's avatar
tomas@poseidon.ndb.mysql.com committed
2236
  if [ x$USING_NDBCLUSTER = x1 ]
2237
  then
2238
    EXTRA_BENCH_ARGS="--create-options=TYPE=ndb $EXTRA_BENCH_ARGS"
2239 2240
  fi 

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2241 2242 2243 2244
  BENCHDIR=$BASEDIR/sql-bench/
  savedir=`pwd`
  cd $BENCHDIR
  if [ -z "$1" ]
2245
  then
2246
    ./run-all-tests --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS --log
2247
  else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2248 2249
    if [ -x "./$1" ]
    then
2250
       ./$1 --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2251 2252 2253
    else
      echo "benchmark $1 not found"
    fi
2254
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2255 2256 2257
  cd $savedir
  mysql_stop
  exit
2258 2259
fi

2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284
#
# Stress testing
#
if [ "$DO_STRESS" = 1 ] 
then

  if [ -n "$1" ] ; then
    STRESS_TEST="$1";
  fi                      
 
  if [ $USE_RUNNING_SERVER -eq 0 ] ; then 
    start_master
  fi
 
  run_stress_test

  if [ $USE_RUNNING_SERVER -eq 0 ] ; then
    mysql_stop
  fi
  
  exit

fi


2285
$ECHO
kent@mysql.com's avatar
kent@mysql.com committed
2286
if [ x$USE_TIMER = x1 ] ; then
kent@mysql.com's avatar
kent@mysql.com committed
2287
$ECHO "TEST                            RESULT        TIME (ms)"
kent@mysql.com's avatar
kent@mysql.com committed
2288 2289 2290
else
$ECHO "TEST                            RESULT"
fi
2291 2292
$ECHO $DASH72

2293
if [ -z "$1" ] ;
2294
then
2295 2296 2297
  if [ x$RECORD = x1 ]; then
    $ECHO "Will not run in record mode without a specific test case."
  else
2298 2299 2300 2301
    for tf in $TESTDIR/*.$TESTSUFFIX
    do
      run_testcase $tf
    done
2302 2303
    $RM -f $TIMEFILE	# Remove for full test
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
2304
else
2305 2306 2307 2308 2309 2310 2311 2312 2313 2314
  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
2315
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2316

2317 2318
$ECHO $DASH72
$ECHO
2319

2320
if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && [ -z "$DO_DDD" ]
2321 2322 2323
then
    mysql_stop
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2324
report_stats
2325
$ECHO
bk@work.mysql.com's avatar
bk@work.mysql.com committed
2326

2327
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
2328
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
2329

kent@mysql.com's avatar
kent@mysql.com committed
2330
if [ $TOT_FAIL -ne 0 ]; then
2331
  $ECHO "mysql-test-run in $TEST_MODE mode: *** Failing the test(s):$FAILED_CASES"
kent@mysql.com's avatar
kent@mysql.com committed
2332 2333 2334
  $ECHO
  exit 1
fi
2335 2336 2337 2338
if [ $GOT_WARNINGS -ne 0 ]; then
  exit 1
fi
exit 0