mysql-test-run.sh 48.9 KB
Newer Older
1
#!/bin/sh
2 3
# mysql-test-run - originally written by Matt Wagner <matt@mysql.com>
# modified by Sasha Pachev <sasha@mysql.com>
unknown's avatar
Typo.  
unknown committed
4
# Slightly updated by Monty
5
# Cleaned up again by Matt
unknown's avatar
unknown committed
6
# Fixed by Sergei
7
# List of failed cases (--force) backported from 4.1 by Joerg
unknown's avatar
unknown committed
8
# :-)
unknown's avatar
unknown committed
9 10 11 12 13

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

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

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

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

44 45 46 47
# Standard functions

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


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

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

105 106 107 108 109
# For the future

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

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

unknown's avatar
unknown committed
115 116
SED=sed

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

# Are we using a source or a binary distribution?

testdir=@testdir@
if [ -d bin/mysqld ] && [ -d mysql-test ] ; then
142 143
 cd mysql-test
else
144 145
 if [ -d $testdir/mysql-test ] ; then
   cd $testdir
146
 fi
147 148 149 150 151 152 153
fi

if [ ! -f ./mysql-test-run ] ; then
  $ECHO "Can't find the location for the mysql-test-run script"

  $ECHO "Go to to the mysql-test directory and execute the script as follows:"
  $ECHO "./mysql-test-run."
unknown's avatar
unknown committed
154
  exit 1
155
fi
156

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

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

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

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

unknown's avatar
fixed  
unknown committed
201
MASTER_RUNNING=0
unknown's avatar
unknown committed
202
MASTER1_RUNNING=0
203
MASTER_MYPORT=9306
unknown's avatar
unknown committed
204
MASTER_MYPORT1=9307
unknown's avatar
fixed  
unknown committed
205
SLAVE_RUNNING=0
unknown's avatar
unknown committed
206
SLAVE_MYPORT=9308 # leave room for 2 masters for cluster tests
unknown's avatar
unknown committed
207
MYSQL_MANAGER_PORT=9305 # needs to be out of the way of slaves
208
NDBCLUSTER_PORT=9350
unknown's avatar
unknown committed
209 210 211
MYSQL_MANAGER_PW_FILE=$MYSQL_TEST_DIR/var/tmp/manager.pwd
MYSQL_MANAGER_LOG=$MYSQL_TEST_DIR/var/log/manager.log
MYSQL_MANAGER_USER=root
212
NO_SLAVE=0
unknown's avatar
unknown committed
213
USER_TEST=
unknown's avatar
unknown committed
214
FAILED_CASES=
215

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

244
NDB_MGM_EXTRA_OPTS=
245 246 247
NDB_MGMD_EXTRA_OPTS=
NDBD_EXTRA_OPTS=

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

unknown's avatar
unknown committed
450 451 452
#++
# mysqld Environment Parameters
#--
453

unknown's avatar
unknown committed
454
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
455 456
MANAGER_PID_FILE="$MYRUN_DIR/manager.pid"

457
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
unknown's avatar
unknown committed
458
MASTER_MYSOCK="$MYSQL_TMP_DIR/master.sock"
unknown's avatar
unknown committed
459
MASTER_MYSOCK1=$MYSQL_MYSOCK"1"
unknown's avatar
unknown committed
460 461 462
MASTER_MYPID="$MYRUN_DIR/master.pid"
MASTER_MYLOG="$MYSQL_TEST_DIR/var/log/master.log"
MASTER_MYERR="$MYSQL_TEST_DIR/var/log/master.err"
463 464

SLAVE_MYDDIR="$MYSQL_TEST_DIR/var/slave-data"
unknown's avatar
unknown committed
465
SLAVE_MYSOCK="$MYSQL_TMP_DIR/slave.sock"
unknown's avatar
unknown committed
466 467 468
SLAVE_MYPID="$MYRUN_DIR/slave.pid"
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/slave.log"
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/slave.err"
469

470
CURRENT_TEST="$MYSQL_TEST_DIR/var/log/current_test"
471
SMALL_SERVER="--key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M"
472

unknown's avatar
unknown committed
473
export MASTER_MYPORT MASTER_MYPORT1 SLAVE_MYPORT MYSQL_TCP_PORT MASTER_MYSOCK MASTER_MYSOCK1
unknown's avatar
unknown committed
474

475
NDBCLUSTER_BASE_PORT=`expr $NDBCLUSTER_PORT + 2`
476
NDBCLUSTER_OPTS="--port=$NDBCLUSTER_PORT --port-base=$NDBCLUSTER_BASE_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"
477

478 479 480 481
if [ x$SOURCE_DIST = x1 ] ; then
 MY_BASEDIR=$MYSQL_TEST_DIR
else
 MY_BASEDIR=$BASEDIR
unknown's avatar
unknown committed
482
fi
unknown's avatar
unknown committed
483

unknown's avatar
unknown committed
484 485 486 487 488 489 490 491
# 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
492
[ -d $MYSQL_TEST_DIR/var/log ] || mkdir $MYSQL_TEST_DIR/var/log
unknown's avatar
unknown committed
493

494
if test ${COLUMNS:-0} -lt 80 ; then COLUMNS=80 ; fi
495
E=`$EXPR $COLUMNS - 8`
unknown's avatar
unknown committed
496
DASH72=`$ECHO '-------------------------------------------------------'|$CUT -c 1-$E`
497

498 499 500
# on source dist, we pick up freshly build executables
# on binary, use what is installed
if [ x$SOURCE_DIST = x1 ] ; then
unknown's avatar
unknown committed
501 502 503 504 505 506 507
 if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
   if [ -f "$BASEDIR/libmysqld/examples/mysqltest" ] ; then
     MYSQL_TEST="$VALGRIND $BASEDIR/libmysqld/examples/mysqltest"
   else
     echo "Fatal error: Cannot find embedded server 'mysqltest'" 1>&2
     exit 1
   fi
unknown's avatar
unknown committed
508
   TESTS_BINDIR="$BASEDIR/libmysqld/examples"
509
 else
unknown's avatar
unknown committed
510 511 512 513 514 515 516 517
   MYSQLD="$VALGRIND $BASEDIR/sql/mysqld"
   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
unknown's avatar
unknown committed
518
   TESTS_BINDIR="$BASEDIR/tests"
519
 fi
520
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
unknown's avatar
unknown committed
521
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
522
 else
unknown's avatar
unknown committed
523
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
524
 fi
unknown's avatar
unknown committed
525
 if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then
unknown's avatar
unknown committed
526
   MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog"
unknown's avatar
unknown committed
527
 else
unknown's avatar
unknown committed
528
   MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog"
unknown's avatar
unknown committed
529
 fi
unknown's avatar
unknown committed
530 531 532
 if [ -n "$STRACE_CLIENT" ]; then
  MYSQL_TEST="strace -o $MYSQL_TEST_DIR/var/log/mysqltest.strace $MYSQL_TEST"
 fi
unknown's avatar
unknown committed
533

unknown's avatar
unknown committed
534 535
 CLIENT_BINDIR="$BASEDIR/client"
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
unknown's avatar
unknown committed
536
 WAIT_PID="$BASEDIR/extra/mysql_waitpid"
unknown's avatar
unknown committed
537
 MYSQL_MANAGER_CLIENT="$CLIENT_BINDIR/mysqlmanagerc"
unknown's avatar
unknown committed
538
 MYSQL_MANAGER="$BASEDIR/tools/mysqlmanager"
unknown's avatar
unknown committed
539 540
 MYSQL_MANAGER_PWGEN="$CLIENT_BINDIR/mysqlmanager-pwgen"
 MYSQL="$CLIENT_BINDIR/mysql"
541
 LANGUAGE="$BASEDIR/sql/share/english/"
542
 CHARSETSDIR="$BASEDIR/sql/share/charsets"
543
 INSTALL_DB="./install_test_db"
544
 MYSQL_FIX_SYSTEM_TABLES="$BASEDIR/scripts/mysql_fix_privilege_tables"
545
 NDB_TOOLS_DIR="$BASEDIR/ndb/tools"
546
 NDB_MGM="$BASEDIR/ndb/src/mgmclient/ndb_mgm"
547
else
548 549
 if test -x "$BASEDIR/libexec/mysqld"
 then
unknown's avatar
unknown committed
550
   MYSQLD="$VALGRIND $BASEDIR/libexec/mysqld"
551
 else
unknown's avatar
unknown committed
552
   MYSQLD="$VALGRIND $BASEDIR/bin/mysqld"
553
 fi
unknown's avatar
unknown committed
554
 CLIENT_BINDIR="$BASEDIR/bin"
555 556 557 558 559 560
 if test -d "$BASEDIR/tests"
 then
   TESTS_BINDIR="$BASEDIR/tests"
 else
   TESTS_BINDIR="$BASEDIR/bin"
 fi
unknown's avatar
unknown committed
561 562 563 564 565 566 567 568 569
 MYSQL_TEST="$CLIENT_BINDIR/mysqltest"
 MYSQL_DUMP="$CLIENT_BINDIR/mysqldump"
 MYSQL_BINLOG="$CLIENT_BINDIR/mysqlbinlog"
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
 WAIT_PID="$CLIENT_BINDIR/mysql_waitpid"
 MYSQL_MANAGER="$CLIENT_BINDIR/mysqlmanager"
 MYSQL_MANAGER_CLIENT="$CLIENT_BINDIR/mysqlmanagerc"
 MYSQL_MANAGER_PWGEN="$CLIENT_BINDIR/mysqlmanager-pwgen"
 MYSQL="$CLIENT_BINDIR/mysql"
570
 INSTALL_DB="./install_test_db --bin"
unknown's avatar
unknown committed
571
 MYSQL_FIX_SYSTEM_TABLES="$CLIENT_BINDIR/mysql_fix_privilege_tables"
572
 NDB_TOOLS_DIR="$CLIENT_BINDIR"
573
 NDB_MGM="$CLIENT_BINDIR/ndb_mgm"
unknown's avatar
unknown committed
574
 if test -d "$BASEDIR/share/mysql/english"
575 576
 then
   LANGUAGE="$BASEDIR/share/mysql/english/"
577
   CHARSETSDIR="$BASEDIR/share/mysql/charsets"
578 579
 else
   LANGUAGE="$BASEDIR/share/english/"
580
   CHARSETSDIR="$BASEDIR/share/charsets"
581
  fi
582 583
fi

584 585 586 587 588 589 590 591 592 593
if [ -z "$MASTER_MYSQLD" ]
then
MASTER_MYSQLD=$MYSQLD
fi

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

594 595 596 597 598 599
# If we should run all tests cases, we will use a local server for that

if [ -z "$1" ]
then
   USE_RUNNING_SERVER=""
fi
600 601
if [ -n "$USE_RUNNING_SERVER" ]
then
602
   MASTER_MYSOCK=$LOCAL_SOCKET;
603
   DBUSER=${DBUSER:-test}
604
else
605
   DBUSER=${DBUSER:-root}		# We want to do FLUSH xxx commands
606
fi
607 608 609

if [ -w / ]
then
unknown's avatar
unknown committed
610 611 612
  # 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"
613 614
fi

615

616 617 618 619
MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR $EXTRA_MYSQLBINLOG_OPT"
MYSQL_FIX_SYSTEM_TABLES="$MYSQL_FIX_SYSTEM_TABLES --no-defaults --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD --basedir=$BASEDIR --bindir=$CLIENT_BINDIR --verbose"
MYSQL="$MYSQL --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD"
620 621
export MYSQL MYSQL_DUMP MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES
export CLIENT_BINDIR TESTS_BINDIR CHARSETSDIR
622
export NDB_TOOLS_DIR
623
export NDB_MGM
624

625
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
626
 --user=$DBUSER --password=$DBPASSWD --silent -v --skip-safemalloc \
unknown's avatar
unknown committed
627
 --tmpdir=$MYSQL_TMP_DIR --port=$MASTER_MYPORT $MYSQL_TEST_SSL_OPTS"
unknown's avatar
unknown committed
628 629 630
if [ x$USE_TIMER = x1 ] ; then
  MYSQL_TEST_ARGS="$MYSQL_TEST_ARGS --timer-file=$MY_LOG_DIR/timer"
fi
631 632 633
MYSQL_TEST_BIN=$MYSQL_TEST
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
634 635 636
GDB_MASTER_INIT=$MYSQL_TMP_DIR/gdbinit.master
GDB_SLAVE_INIT=$MYSQL_TMP_DIR/gdbinit.slave
GCOV_MSG=$MYSQL_TMP_DIR/mysqld-gcov.out
unknown's avatar
unknown committed
637 638 639 640
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
641
TIMEFILE="$MYSQL_TEST_DIR/var/log/mysqltest-time"
642 643 644
if [ -n "$DO_CLIENT_GDB" -o -n "$DO_GDB" ] ; then
  XTERM=`which xterm`
fi
645

unknown's avatar
unknown committed
646 647
export MYSQL MYSQL_DUMP MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES CLIENT_BINDIR MASTER_MYSOCK

unknown's avatar
unknown committed
648 649 650 651
#++
# Function Definitions
#--

unknown's avatar
unknown committed
652 653
prompt_user ()
{
654
 $ECHO $1
655
 read unused
unknown's avatar
unknown committed
656 657
}

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

unknown's avatar
unknown committed
660 661 662 663
show_failed_diff ()
{
  reject_file=r/$1.reject
  result_file=r/$1.result
664
  eval_file=r/$1.eval
unknown's avatar
unknown committed
665

unknown's avatar
unknown committed
666 667 668 669 670 671 672
  # If we have an special externsion for result files we use it if we are recording
  # or a result file with that extension exists.
  if [ -n "$RESULT_EXT" -a \( x$RECORD = x1 -o -f "$result_file$RESULT_EXT" \) ]
  then
    result_file="$result_file$RESULT_EXT"
  fi

673 674 675 676
  if [ -f $eval_file ]
  then
    result_file=$eval_file
  fi
unknown's avatar
unknown committed
677

unknown's avatar
unknown committed
678 679 680 681
  if [ -x "$DIFF" ] && [ -f $reject_file ]
  then
    echo "Below are the diffs between actual and expected results:"
    echo "-------------------------------------------------------"
unknown's avatar
unknown committed
682
    $DIFF -c $result_file $reject_file
unknown's avatar
unknown committed
683
    echo "-------------------------------------------------------"
684
    echo "Please follow the instructions outlined at"
685
    echo "http://www.mysql.com/doc/en/Reporting_mysqltest_bugs.html"
686
    echo "to find the reason to this problem and how to report this."
687
    echo ""
unknown's avatar
unknown committed
688
  fi
unknown's avatar
unknown committed
689
}
unknown's avatar
unknown committed
690

691 692 693 694 695 696
do_gdb_test ()
{
  mysql_test_args="$MYSQL_TEST_ARGS $1"
  $ECHO "set args $mysql_test_args < $2" > $GDB_CLIENT_INIT
  echo "Set breakpoints ( if needed) and type 'run' in gdb window"
  #this xterm should not be backgrounded
unknown's avatar
unknown committed
697
  $XTERM -title "Client" -e gdb -x $GDB_CLIENT_INIT $MYSQL_TEST_BIN
698 699
}

unknown's avatar
unknown committed
700
error () {
unknown's avatar
unknown committed
701
    $ECHO  "Error:  $1"
unknown's avatar
unknown committed
702 703 704
    exit 1
}

705
error_is () {
706 707
    $ECHO "Errors are (from $TIMEFILE) :"
    $CAT < $TIMEFILE
708
    $ECHO "(the last lines may be the most important ones)"
709 710
}

unknown's avatar
unknown committed
711
prefix_to_8() {
712
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
unknown's avatar
unknown committed
713 714
}

unknown's avatar
unknown committed
715
pass_inc () {
unknown's avatar
unknown committed
716
    TOT_PASS=`$EXPR $TOT_PASS + 1`
unknown's avatar
unknown committed
717 718 719
}

fail_inc () {
unknown's avatar
unknown committed
720
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
unknown's avatar
unknown committed
721 722
}

723 724 725 726
skip_inc () {
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
}

unknown's avatar
unknown committed
727
total_inc () {
unknown's avatar
unknown committed
728
    TOT_TEST=`$EXPR $TOT_TEST + 1`
unknown's avatar
unknown committed
729 730
}

731 732 733 734 735 736

skip_test() {
   USERT="    ...."
   SYST="    ...."
   REALT="    ...."
   pname=`$ECHO "$1                        "|$CUT -c 1-24`
737
   RES="$pname"
738 739 740 741
   skip_inc
   $ECHO "$RES$RES_SPACE [ skipped ]"
}

unknown's avatar
unknown committed
742
report_stats () {
743
    if [ $TOT_FAIL = 0 ]; then
unknown's avatar
unknown committed
744
	$ECHO "All $TOT_TEST tests were successful."
unknown's avatar
unknown committed
745
    else
unknown's avatar
unknown committed
746 747 748 749 750 751
	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`
752
	$ECHO  "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% successful."
753
	$ECHO ""
754
        $ECHO "The log files in $MY_LOG_DIR may give you some hint"
755 756
	$ECHO "of what when wrong."
	$ECHO "If you want to report this error, please read first the documentation at"
757
        $ECHO "http://www.mysql.com/doc/en/MySQL_test_suite.html"
unknown's avatar
unknown committed
758
    fi
unknown's avatar
unknown committed
759

unknown's avatar
unknown committed
760 761 762
    if test -z "$USE_RUNNING_SERVER"
    then

unknown's avatar
unknown committed
763 764 765 766
    # 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
767
    $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' \
768 769 770
        $MY_LOG_DIR/*.err \
        | $SED -e 's!Warning:  Table:.* on rename!!g' \
        > $MY_LOG_DIR/warnings.tmp
unknown's avatar
unknown committed
771 772 773 774 775

    found_error=0
    # Find errors
    for i in "^Warning:" "^Error:" "^==.* at 0x"
    do
unknown's avatar
unknown committed
776
      if $GREP "$i" $MY_LOG_DIR/warnings.tmp >> $MY_LOG_DIR/warnings
unknown's avatar
unknown committed
777 778 779 780 781 782 783 784 785 786
      then
        found_error=1
      fi
    done
    $RM -f $MY_LOG_DIR/warnings.tmp
    if [ $found_error = "1" ]
    then
      echo "WARNING: Got errors/warnings while running tests. Please examine"
      echo "$MY_LOG_DIR/warnings for details."
    fi
unknown's avatar
unknown committed
787
    fi
unknown's avatar
unknown committed
788
}
789

unknown's avatar
unknown committed
790
mysql_install_db () {
791
    $ECHO "Removing Stale Files"
792 793 794 795 796
    if [ -z "$USE_OLD_DATA" ]; then
      $RM -rf $MASTER_MYDDIR $MASTER_MYDDIR"1"
      $ECHO "Installing Master Databases"
      $INSTALL_DB
      if [ $? != 0 ]; then
797
	error "Could not install master test DBs"
798 799
        exit 1
      fi
800
    fi
unknown's avatar
unknown committed
801 802 803 804 805 806 807 808 809
    if [ ! -z "$USE_NDBCLUSTER" ]
    then
      $ECHO "Installing Master Databases 1"
      $INSTALL_DB -1
      if [ $? != 0 ]; then
	error "Could not install master test DBs 1"
	exit 1
      fi
    fi
810
    $ECHO "Installing Slave Databases"
811
    $RM -rf $SLAVE_MYDDIR $MY_LOG_DIR/* 
812
    $INSTALL_DB -slave
813
    if [ $? != 0 ]; then
814
	error "Could not install slave test DBs"
815
	exit 1
unknown's avatar
unknown committed
816
    fi
unknown's avatar
unknown committed
817

818 819
    for slave_num in 1 2 ;
    do
820
      $RM -rf var/slave$slave_num-data
821 822 823
      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
824
    done
unknown's avatar
unknown committed
825 826 827
    return 0
}

unknown's avatar
unknown committed
828 829
gprof_prepare ()
{
unknown's avatar
unknown committed
830 831
 $RM -rf $GPROF_DIR
 mkdir -p $GPROF_DIR
unknown's avatar
unknown committed
832 833 834 835 836
}

gprof_collect ()
{
 if [ -f $MASTER_MYDDIR/gmon.out ]; then
837
   gprof $MASTER_MYSQLD $MASTER_MYDDIR/gmon.out > $GPROF_MASTER
unknown's avatar
unknown committed
838 839 840
   echo "Master execution profile has been saved in $GPROF_MASTER"
 fi
 if [ -f $SLAVE_MYDDIR/gmon.out ]; then
841
   gprof $SLAVE_MYSQLD $SLAVE_MYDDIR/gmon.out > $GPROF_SLAVE
unknown's avatar
unknown committed
842 843 844 845
   echo "Slave execution profile has been saved in $GPROF_SLAVE"
 fi
}

846
gcov_prepare () {
unknown's avatar
unknown committed
847 848
    $FIND $BASEDIR -name \*.gcov \
    -or -name \*.da | $XARGS $RM
unknown's avatar
unknown committed
849 850 851
}

gcov_collect () {
unknown's avatar
unknown committed
852
    $ECHO "Collecting source coverage info..."
unknown's avatar
unknown committed
853 854
    [ -f $GCOV_MSG ] && $RM $GCOV_MSG
    [ -f $GCOV_ERR ] && $RM $GCOV_ERR
unknown's avatar
unknown committed
855 856 857
    for d in $MYSQLD_SRC_DIRS; do
	cd $BASEDIR/$d
	for f in *.h *.cc *.c; do
unknown's avatar
unknown committed
858
	    $GCOV $f 2>>$GCOV_ERR  >>$GCOV_MSG
unknown's avatar
unknown committed
859
	done
860
	cd $MYSQL_TEST_DIR
unknown's avatar
unknown committed
861 862
    done

unknown's avatar
unknown committed
863
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
unknown's avatar
unknown committed
864 865
}

unknown's avatar
unknown committed
866 867 868 869 870
abort_if_failed()
{
 if [ ! $? = 0 ] ; then
  echo $1
  exit 1
unknown's avatar
unknown committed
871
 fi
unknown's avatar
unknown committed
872 873 874 875
}

start_manager()
{
unknown's avatar
unknown committed
876
 if [ $USE_MANAGER = 0 ] ; then
877 878
   echo "Manager disabled, skipping manager start."
   $RM -f $MYSQL_MANAGER_LOG
879 880
  return
 fi
unknown's avatar
unknown committed
881
 $ECHO "Starting MySQL Manager"
882 883 884 885 886 887 888 889 890
 if [ -f "$MANAGER_PID_FILE" ] ; then
    kill `cat $MANAGER_PID_FILE`
    sleep 1
    if [ -f "$MANAGER_PID_FILE" ] ; then
     kill -9 `cat $MANAGER_PID_FILE`
     sleep 1
    fi
 fi

unknown's avatar
unknown committed
891
 $RM -f $MANAGER_PID_FILE
unknown's avatar
unknown committed
892 893
 MYSQL_MANAGER_PW=`$MYSQL_MANAGER_PWGEN -u $MYSQL_MANAGER_USER \
 -o $MYSQL_MANAGER_PW_FILE`
unknown's avatar
unknown committed
894
 $MYSQL_MANAGER --log=$MYSQL_MANAGER_LOG --port=$MYSQL_MANAGER_PORT \
895
  --password-file=$MYSQL_MANAGER_PW_FILE --pid-file=$MANAGER_PID_FILE
unknown's avatar
unknown committed
896
  abort_if_failed "Could not start MySQL manager"
897 898
  mysqltest_manager_args="--manager-host=localhost \
  --manager-user=$MYSQL_MANAGER_USER \
899 900 901 902 903
  --manager-password=$MYSQL_MANAGER_PW \
  --manager-port=$MYSQL_MANAGER_PORT \
  --manager-wait-timeout=$START_WAIT_TIMEOUT"
  MYSQL_TEST="$MYSQL_TEST $mysqltest_manager_args"
  MYSQL_TEST_ARGS="$MYSQL_TEST_ARGS $mysqltest_manager_args"
904 905 906 907
  while [ ! -f $MANAGER_PID_FILE ] ; do
   sleep 1
  done
  echo "Manager started"
unknown's avatar
unknown committed
908 909
}

unknown's avatar
unknown committed
910 911
stop_manager()
{
unknown's avatar
unknown committed
912
 if [ $USE_MANAGER = 0 ] ; then
913 914
  return
 fi
unknown's avatar
unknown committed
915 916 917 918
 $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT -u$MYSQL_MANAGER_USER \
  -p$MYSQL_MANAGER_PW -P $MYSQL_MANAGER_PORT <<EOF
shutdown
EOF
919 920
 echo "Manager terminated"

unknown's avatar
unknown committed
921 922 923
}

manager_launch()
unknown's avatar
unknown committed
924
{
unknown's avatar
unknown committed
925 926
  ident=$1
  shift
unknown's avatar
unknown committed
927
  if [ $USE_MANAGER = 0 ] ; then
unknown's avatar
unknown committed
928
    echo $@ | /bin/sh  >> $CUR_MYERR 2>&1  &
unknown's avatar
unknown committed
929 930
    sleep 2 #hack
    return
931
  fi
unknown's avatar
unknown committed
932
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
unknown's avatar
unknown committed
933
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
934
def_exec $ident "$@"
unknown's avatar
unknown committed
935 936 937 938
set_exec_stdout $ident $CUR_MYERR
set_exec_stderr $ident $CUR_MYERR
set_exec_con $ident root localhost $CUR_MYSOCK
start_exec $ident $START_WAIT_TIMEOUT
unknown's avatar
unknown committed
939
EOF
unknown's avatar
unknown committed
940
  abort_if_failed "Could not execute manager command"
unknown's avatar
unknown committed
941
}
unknown's avatar
unknown committed
942

unknown's avatar
unknown committed
943 944
manager_term()
{
945 946
  pid=$1
  ident=$2
unknown's avatar
unknown committed
947
  if [ $USE_MANAGER = 0 ] ; then
unknown's avatar
unknown committed
948
    # Shutdown time must be high as slave may be in reconnect
unknown's avatar
unknown committed
949
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock$3 --connect_timeout=5 --shutdown_timeout=70 shutdown >> $MYSQL_MANAGER_LOG 2>&1
950 951
    res=$?
    # Some systems require an extra connect
unknown's avatar
unknown committed
952
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock$3 --connect_timeout=1 ping >> $MYSQL_MANAGER_LOG 2>&1
953 954 955 956 957
    if test $res = 0
    then
      wait_for_pid $pid
    fi
    return $res
958
  fi
unknown's avatar
unknown committed
959 960
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
961
stop_exec $ident $STOP_WAIT_TIMEOUT
unknown's avatar
unknown committed
962 963 964 965
EOF
 abort_if_failed "Could not execute manager command"
}

966 967 968 969 970 971 972 973 974
start_ndbcluster()
{
  if [ ! -z "$USE_NDBCLUSTER" ]
  then
  if [ -z "$USE_RUNNING_NDBCLUSTER" ]
  then
    echo "Starting ndbcluster"
    if [ "$DO_BENCH" = 1 ]
    then
975
      NDBCLUSTER_EXTRA_OPTS=""
976
    else
977
      NDBCLUSTER_EXTRA_OPTS="--small"
978
    fi
unknown's avatar
unknown committed
979 980 981 982 983 984 985
    NDB_STARTED=1
    ./ndb/ndbcluster $NDBCLUSTER_OPTS $NDBCLUSTER_EXTRA_OPTS --initial || NDB_STARTED=0
    if [ x$NDB_STARTED != x1 ] ; then
      if [ x$FORCE != x1 ] ; then
        exit 1
      fi
    fi
986
    NDB_CONNECTSTRING="host=localhost:$NDBCLUSTER_PORT"
987
  else
988 989
    NDB_CONNECTSTRING="$USE_RUNNING_NDBCLUSTER"
    echo "Using ndbcluster at $NDB_CONNECTSTRING"
990
  fi
991 992
  USE_NDBCLUSTER="$USE_NDBCLUSTER --ndb-connectstring=\"$NDB_CONNECTSTRING\""
  export NDB_CONNECTSTRING
993 994 995 996 997 998 999 1000 1001 1002
  fi
}

stop_ndbcluster()
{
 if [ ! -z "$USE_NDBCLUSTER" ]
 then
 if [ -z "$USE_RUNNING_NDBCLUSTER" ]
 then
   # Kill any running ndbcluster stuff
1003
   ./ndb/ndbcluster $NDBCLUSTER_OPTS --stop
1004 1005 1006 1007
 fi
 fi
}

unknown's avatar
unknown committed
1008 1009
# The embedded server needs the cleanup so we do some of the start work
# but stop before actually running mysqld or anything.
unknown's avatar
unknown committed
1010

unknown's avatar
unknown committed
1011 1012
start_master()
{
unknown's avatar
unknown committed
1013 1014
  eval "this_master_running=\$MASTER$1_RUNNING"
  if [ x$this_master_running = x1 ] || [ x$LOCAL_MASTER = x1 ] ; then
unknown's avatar
unknown committed
1015 1016
    return
  fi
unknown's avatar
unknown committed
1017 1018 1019
  # 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
unknown's avatar
unknown committed
1020
    $RM -f $MYSQL_TEST_DIR/var/log/master-bin$1.*
unknown's avatar
unknown committed
1021 1022
  fi

1023
  # Remove old master.info and relay-log.info files
unknown's avatar
unknown committed
1024
  $RM -f $MYSQL_TEST_DIR/var/master-data$1/master.info $MYSQL_TEST_DIR/var/master-data$1/relay-log.info
unknown's avatar
unknown committed
1025 1026 1027 1028 1029 1030 1031 1032

  #run master initialization shell script if one exists

  if [ -f "$master_init_script" ] ;
  then
      /bin/sh $master_init_script
  fi
  cd $BASEDIR # for gcov
unknown's avatar
unknown committed
1033 1034 1035
  if [ -n "$1" ] ; then
   id=`$EXPR $1 + 101`;
   this_master_myport=`$EXPR $MASTER_MYPORT + $1`
1036
   NOT_FIRST_MASTER_EXTRA_OPTS="--skip-innodb"
unknown's avatar
unknown committed
1037 1038 1039
  else
   id=1;
   this_master_myport=$MASTER_MYPORT
1040
   NOT_FIRST_MASTER_EXTRA_OPTS=""
unknown's avatar
unknown committed
1041
  fi
unknown's avatar
unknown committed
1042 1043
  if [ -z "$DO_BENCH" ]
  then
unknown's avatar
unknown committed
1044 1045
    master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin$1 \
  	    --server-id=$id  \
1046
          --basedir=$MY_BASEDIR \
unknown's avatar
unknown committed
1047
          --port=$this_master_myport \
unknown's avatar
unknown committed
1048
          --local-infile \
unknown's avatar
unknown committed
1049 1050
          --exit-info=256 \
          --core \
unknown's avatar
unknown committed
1051
          $USE_NDBCLUSTER \
unknown's avatar
unknown committed
1052 1053 1054 1055
          --datadir=$MASTER_MYDDIR$1 \
          --pid-file=$MASTER_MYPID$1 \
          --socket=$MASTER_MYSOCK$1 \
          --log=$MASTER_MYLOG$1 \
unknown's avatar
unknown committed
1056 1057 1058 1059 1060
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
          --innodb_data_file_path=ibdata1:50M \
1061
	  --open-files-limit=1024 \
1062
	   $MASTER_40_ARGS \
unknown's avatar
unknown committed
1063
           $SMALL_SERVER \
1064 1065
           $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT \
           $NOT_FIRST_MASTER_EXTRA_OPTS"
unknown's avatar
unknown committed
1066
  else
unknown's avatar
unknown committed
1067 1068
    master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin$1 \
          --server-id=$id --rpl-recovery-rank=1 \
unknown's avatar
unknown committed
1069
          --basedir=$MY_BASEDIR --init-rpl-role=master \
unknown's avatar
unknown committed
1070
          --port=$this_master_myport \
unknown's avatar
unknown committed
1071
          --local-infile \
unknown's avatar
unknown committed
1072 1073 1074
          --datadir=$MASTER_MYDDIR$1 \
          --pid-file=$MASTER_MYPID$1 \
          --socket=$MASTER_MYSOCK$1 \
unknown's avatar
unknown committed
1075 1076 1077
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core \
unknown's avatar
unknown committed
1078
          $USE_NDBCLUSTER \
unknown's avatar
unknown committed
1079 1080 1081
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
          --innodb_data_file_path=ibdata1:50M \
1082
	   $MASTER_40_ARGS \
unknown's avatar
unknown committed
1083
           $SMALL_SERVER \
1084 1085
           $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT \
           $NOT_FIRST_MASTER_EXTRA_OPTS"
unknown's avatar
unknown committed
1086 1087 1088 1089 1090
  fi

  CUR_MYERR=$MASTER_MYERR
  CUR_MYSOCK=$MASTER_MYSOCK

unknown's avatar
unknown committed
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
  # 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

unknown's avatar
unknown committed
1103 1104 1105 1106
  if [ x$DO_DDD = x1 ]
  then
    $ECHO "set args $master_args" > $GDB_MASTER_INIT
    manager_launch master ddd -display $DISPLAY --debugger \
1107
    "gdb -x $GDB_MASTER_INIT" $MASTER_MYSQLD
unknown's avatar
unknown committed
1108 1109
  elif [ x$DO_GDB = x1 ]
  then
unknown's avatar
unknown committed
1110 1111 1112 1113
    if [ x$MANUAL_GDB = x1 ]
    then
      $ECHO "set args $master_args" > $GDB_MASTER_INIT
      $ECHO "To start gdb for the master , type in another window:"
1114
      $ECHO "cd $CWD ; gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD"
unknown's avatar
unknown committed
1115 1116 1117 1118
      wait_for_master=1500
    else
      ( $ECHO set args $master_args;
      if [ $USE_MANAGER = 0 ] ; then
unknown's avatar
unknown committed
1119
    cat <<EOF
unknown's avatar
unknown committed
1120 1121
b mysql_parse
commands 1
1122
disa 1
unknown's avatar
unknown committed
1123
end
unknown's avatar
unknown committed
1124 1125
r
EOF
unknown's avatar
unknown committed
1126 1127
      fi )  > $GDB_MASTER_INIT
      manager_launch master $XTERM -display $DISPLAY \
1128
      -title "Master" -e gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD
unknown's avatar
unknown committed
1129
    fi
unknown's avatar
unknown committed
1130
  else
1131
    manager_launch master $MASTER_MYSQLD $master_args
unknown's avatar
unknown committed
1132
  fi
unknown's avatar
unknown committed
1133
  sleep_until_file_created $MASTER_MYPID$1 $wait_for_master
unknown's avatar
unknown committed
1134
  wait_for_master=$SLEEP_TIME_FOR_SECOND_MASTER
unknown's avatar
unknown committed
1135
  eval "MASTER$1_RUNNING=1"
unknown's avatar
unknown committed
1136 1137 1138 1139
}

start_slave()
{
unknown's avatar
unknown committed
1140 1141 1142
  [ x$SKIP_SLAVE = x1 ] && return
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  [ x$this_slave_running = 1 ] && return
unknown's avatar
unknown committed
1143 1144
  # When testing fail-safe replication, we will have more than one slave
  # in this case, we start secondary slaves with an argument
unknown's avatar
unknown committed
1145 1146 1147 1148 1149 1150 1151 1152
  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"
1153
   slave_datadir="$SLAVE_MYDDIR/../$slave_ident-data/"
unknown's avatar
unknown committed
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
   slave_sock="$SLAVE_MYSOCK-$1"
  else
   slave_server_id=2
   slave_rpl_rank=2
   slave_port=$SLAVE_MYPORT
   slave_log=$SLAVE_MYLOG
   slave_err=$SLAVE_MYERR
   slave_datadir=$SLAVE_MYDDIR
   slave_pid=$SLAVE_MYPID
   slave_sock="$SLAVE_MYSOCK"
 fi
unknown's avatar
unknown committed
1166
  # Remove stale binary logs and old master.info files
unknown's avatar
unknown committed
1167 1168 1169 1170 1171 1172
  # except for too tests which need them
  if [ "$tname" != "rpl_crash_binlog_ib_1b" ] && [ "$tname" != "rpl_crash_binlog_ib_2b" ] && [ "$tname" != "rpl_crash_binlog_ib_3b" ]
  then
    $RM -f $MYSQL_TEST_DIR/var/log/$slave_ident-*bin.*
    $RM -f $slave_datadir/master.info $slave_datadir/relay-log.info
  fi
unknown's avatar
unknown committed
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183

  #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 \
1184
          --master-password="" \
unknown's avatar
unknown committed
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
          --master-port=$MASTER_MYPORT \
          --server-id=$slave_server_id --rpl-recovery-rank=$slave_rpl_rank"
 else
   master_info=$SLAVE_MASTER_INFO
 fi

  $RM -f $slave_datadir/log.*
  slave_args="--no-defaults $master_info \
  	    --exit-info=256 \
          --log-bin=$MYSQL_TEST_DIR/var/log/$slave_ident-bin \
1195
          --relay-log=$MYSQL_TEST_DIR/var/log/$slave_ident-relay-bin \
unknown's avatar
unknown committed
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
          --log-slave-updates \
          --log=$slave_log \
          --basedir=$MY_BASEDIR \
          --datadir=$slave_datadir \
          --pid-file=$slave_pid \
          --port=$slave_port \
          --socket=$slave_sock \
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core --init-rpl-role=slave \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
unknown's avatar
unknown committed
1208
          --skip-innodb --skip-ndbcluster --skip-slave-start \
unknown's avatar
unknown committed
1209 1210 1211
          --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
          --report-host=127.0.0.1 --report-user=root \
          --report-port=$slave_port \
1212
          --master-retry-count=10 \
unknown's avatar
unknown committed
1213
          -O slave_net_timeout=10 \
unknown's avatar
unknown committed
1214 1215 1216 1217 1218 1219 1220
           $SMALL_SERVER \
           $EXTRA_SLAVE_OPT $EXTRA_SLAVE_MYSQLD_OPT"
  CUR_MYERR=$slave_err
  CUR_MYSOCK=$slave_sock

  if [ x$DO_DDD = x1 ]
  then
1221
    $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
unknown's avatar
unknown committed
1222 1223 1224 1225
    manager_launch $slave_ident ddd -display $DISPLAY --debugger \
     "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD
  elif [ x$DO_GDB = x1 ]
  then
unknown's avatar
unknown committed
1226 1227
    if [ x$MANUAL_GDB = x1 ]
    then
unknown's avatar
unknown committed
1228
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
unknown's avatar
unknown committed
1229
      echo "To start gdb for the slave, type in another window:"
1230
      echo "cd $CWD ; gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD"
unknown's avatar
unknown committed
1231 1232
      wait_for_slave=1500
    else
unknown's avatar
unknown committed
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242
      ( $ECHO set args $slave_args;
      if [ $USE_MANAGER = 0 ] ; then
    cat <<EOF
b mysql_parse
commands 1
disa 1
end
r
EOF
      fi )  > $GDB_SLAVE_INIT
unknown's avatar
unknown committed
1243 1244 1245
      manager_launch $slave_ident $XTERM -display $DISPLAY -title "Slave" -e \
      gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD
    fi
unknown's avatar
unknown committed
1246 1247 1248 1249
  else
    manager_launch $slave_ident $SLAVE_MYSQLD $slave_args
  fi
  eval "SLAVE$1_RUNNING=1"
1250
  sleep_until_file_created $slave_pid $wait_for_slave
unknown's avatar
unknown committed
1251
  wait_for_slave=$SLEEP_TIME_FOR_SECOND_SLAVE
unknown's avatar
unknown committed
1252 1253
}

unknown's avatar
unknown committed
1254 1255
mysql_start ()
{
unknown's avatar
unknown committed
1256
# We should not start the daemon here as we don't know the arguments
unknown's avatar
unknown committed
1257
# for the test.  Better to let the test start the daemon
unknown's avatar
unknown committed
1258 1259 1260 1261

#  $ECHO "Starting MySQL daemon"
#  start_master
#  start_slave
unknown's avatar
unknown committed
1262
  cd $MYSQL_TEST_DIR
1263
  start_ndbcluster
unknown's avatar
unknown committed
1264
  return 1
unknown's avatar
unknown committed
1265 1266
}

unknown's avatar
unknown committed
1267 1268
stop_slave ()
{
1269 1270 1271
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ -n "$1" ] ;
unknown's avatar
unknown committed
1272
  then
1273 1274 1275
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
  else
   slave_pid=$SLAVE_MYPID
unknown's avatar
unknown committed
1276
  fi
1277 1278
  if [ x$this_slave_running = x1 ]
  then
1279 1280
    pid=`$CAT $slave_pid`
    manager_term $pid $slave_ident
1281
    if [ $? != 0 ] && [ -f $slave_pid ]
1282
    then # try harder!
1283
      $ECHO "slave not cooperating with mysqladmin, will try manual kill"
1284 1285
      kill $pid
      sleep_until_file_deleted $pid $slave_pid
1286 1287 1288 1289 1290 1291 1292 1293 1294
      if [ -f $slave_pid ] ; then
        $ECHO "slave refused to die. Sending SIGKILL"
        kill -9 `$CAT $slave_pid`
        $RM -f $slave_pid
      else
        $ECHO "slave responded to SIGTERM "
      fi
    else
      sleep $SLEEP_TIME_AFTER_RESTART
unknown's avatar
unknown committed
1295
    fi
1296
    eval "SLAVE$1_RUNNING=0"
unknown's avatar
unknown committed
1297
  fi
unknown's avatar
unknown committed
1298
}
unknown's avatar
unknown committed
1299

1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
stop_slave_threads ()
{
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ x$this_slave_running = x1 ]
  then
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$slave_ident.sock stop-slave > /dev/null 2>&1
  fi
}

unknown's avatar
unknown committed
1310 1311
stop_master ()
{
unknown's avatar
unknown committed
1312 1313
  eval "this_master_running=\$MASTER$1_RUNNING"
  if [ x$this_master_running = x1 ]
unknown's avatar
unknown committed
1314
  then
unknown's avatar
unknown committed
1315 1316 1317
    # 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
unknown's avatar
Merge  
unknown committed
1318
      pid=`$CAT $MASTER_MYPID$1`
unknown's avatar
unknown committed
1319
      manager_term $pid master $1
unknown's avatar
Merge  
unknown committed
1320
      if [ $? != 0 ] && [ -f $MASTER_MYPID$1 ]
unknown's avatar
unknown committed
1321 1322 1323
      then # try harder!
	$ECHO "master not cooperating with mysqladmin, will try manual kill"
	kill $pid
unknown's avatar
Merge  
unknown committed
1324 1325
	sleep_until_file_deleted $pid $MASTER_MYPID$1
	if [ -f $MASTER_MYPID$1 ] ; then
unknown's avatar
unknown committed
1326
	  $ECHO "master refused to die. Sending SIGKILL"
unknown's avatar
Merge  
unknown committed
1327 1328
	  kill -9 `$CAT $MASTER_MYPID$1`
	  $RM -f $MASTER_MYPID$1
unknown's avatar
unknown committed
1329 1330 1331
	else
	  $ECHO "master responded to SIGTERM "
	fi
1332
      else
unknown's avatar
unknown committed
1333
	sleep $SLEEP_TIME_AFTER_RESTART
1334
      fi
unknown's avatar
unknown committed
1335
    fi
unknown's avatar
unknown committed
1336
    eval "MASTER$1_RUNNING=0"
unknown's avatar
unknown committed
1337 1338
  fi
}
unknown's avatar
unknown committed
1339

unknown's avatar
unknown committed
1340 1341
mysql_stop ()
{
1342 1343 1344 1345 1346 1347
  if [ "$MASTER_RUNNING" = 1 ]
  then
    $ECHO  "Ending Tests"
    $ECHO  "Shutting-down MySQL daemon"
    $ECHO  ""
    stop_master
unknown's avatar
unknown committed
1348
    stop_master 1
1349 1350 1351 1352 1353
    $ECHO "Master shutdown finished"
    stop_slave
    stop_slave 1
    stop_slave 2
    $ECHO "Slave shutdown finished"
unknown's avatar
unknown committed
1354
    stop_ndbcluster
1355 1356
  fi
  return 1
unknown's avatar
unknown committed
1357 1358
}

unknown's avatar
unknown committed
1359 1360 1361 1362 1363
mysql_restart ()
{
  mysql_stop
  mysql_start
  return 1
unknown's avatar
unknown committed
1364 1365 1366
}

mysql_loadstd () {
unknown's avatar
unknown committed
1367 1368

    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test
unknown's avatar
unknown committed
1369 1370 1371
    return 1
}

unknown's avatar
unknown committed
1372 1373 1374
run_testcase ()
{
 tf=$1
unknown's avatar
unknown committed
1375
 tname=`$BASENAME $tf .test`
unknown's avatar
unknown committed
1376 1377
 master_opt_file=$TESTDIR/$tname-master.opt
 slave_opt_file=$TESTDIR/$tname-slave.opt
1378 1379
 master_init_script=$TESTDIR/$tname-master.sh
 slave_init_script=$TESTDIR/$tname-slave.sh
1380
 slave_master_info_file=$TESTDIR/$tname.slave-mi
unknown's avatar
unknown committed
1381 1382
 tsrcdir=$TESTDIR/$tname-src
 result_file="r/$tname.result"
1383
 echo $tname > $CURRENT_TEST
1384
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0 \& \( $tname : federated \) = 0`
unknown's avatar
unknown committed
1385 1386 1387
 if [ -n "$RESULT_EXT" -a \( x$RECORD = x1 -o -f "$result_file$RESULT_EXT" \) ] ; then
   result_file="$result_file$RESULT_EXT"
 fi
1388
 if [ "$USE_MANAGER" = 1 ] ; then
unknown's avatar
unknown committed
1389
  many_slaves=`$EXPR \( \( $tname : rpl_failsafe \) != 0 \) \| \( \( $tname : rpl_chain_temp_table \) != 0 \)`
1390 1391 1392 1393
 fi
 if $EXPR "$tname" '<' "$START_FROM" > /dev/null ; then
   #skip_test $tname
   return
unknown's avatar
unknown committed
1394 1395
 fi

1396 1397 1398 1399
 if [ "$SKIP_TEST" ] ; then
   if $EXPR \( "$tname" : "$SKIP_TEST" \) > /dev/null ; then
     skip_test $tname
     return
unknown's avatar
unknown committed
1400
   fi
1401
 fi
1402

1403 1404
 if [ "$DO_TEST" ] ; then
   if $EXPR \( "$tname" : "$DO_TEST" \) > /dev/null ; then
unknown's avatar
unknown committed
1405
     : #empty command to keep some shells happy
1406 1407 1408
   else
     #skip_test $tname
     return
1409
   fi
1410
 fi
1411

1412 1413
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ; then
   skip_test $tname
1414 1415 1416
   return
 fi

unknown's avatar
unknown committed
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
 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 \
1429
        "alter_table" \
unknown's avatar
unknown committed
1430 1431
	"bdb-deadlock" \
	"connect" \
1432 1433
        "ctype_latin1_de" \
        "ctype_ucs" \
unknown's avatar
unknown committed
1434 1435 1436 1437 1438
	"flush_block_commit" \
	"grant2" \
	"grant_cache" \
	"grant" \
	"init_connect" \
1439 1440
	"init_file" \
        "innodb" \
unknown's avatar
unknown committed
1441 1442 1443 1444 1445 1446 1447
	"innodb-deadlock" \
	"innodb-lock" \
	"mix_innodb_myisam_binlog" \
	"mysqlbinlog2" \
	"mysqlbinlog" \
	"mysqldump" \
	"mysql_protocols" \
1448
        "packet" \
unknown's avatar
unknown committed
1449 1450 1451 1452
	"ps_1general" \
	"rename" \
	"show_check" \
        "system_mysql_db_fix" \
1453
        "timezone2" \
unknown's avatar
unknown committed
1454 1455 1456 1457 1458 1459 1460 1461 1462
	"user_var" \
	"variables"
   do
     if [ "$tname" = "$t" ] ; then
       skip_test $tname
       return
     fi
   done
 fi
1463

1464
 if [ -z "$USE_RUNNING_SERVER" ] ;
unknown's avatar
unknown committed
1465
 then
1466 1467
   if [ -f $master_opt_file ] ;
   then
unknown's avatar
unknown committed
1468
     EXTRA_MASTER_OPT=`$CAT $master_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1469 1470 1471 1472 1473 1474 1475
     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=" "
	 ;;
1476 1477
       --result-file=*)
         result_file=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--result-file=;;"`
unknown's avatar
unknown committed
1478 1479 1480 1481
         result_file="r/$result_file.result"
         if [ -n "$RESULT_EXT" -a \( x$RECORD = x1 -o -f "$result_file$RESULT_EXT" \) ] ; then
	   result_file="$result_file$RESULT_EXT"
	 fi
1482 1483 1484
	 # Note that this must be set to space, not "" for test-reset to work
	 EXTRA_MASTER_OPT=" "
         ;;
1485
     esac
1486
     stop_master
unknown's avatar
unknown committed
1487
     stop_master 1
unknown's avatar
unknown committed
1488
     echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1489
     start_master
unknown's avatar
unknown committed
1490
     if [ -n "$USE_NDBCLUSTER" -a -z "$DO_BENCH" ] ; then
unknown's avatar
unknown committed
1491 1492
       start_master 1
     fi
1493
     TZ=$MY_TZ; export TZ
1494
   else
unknown's avatar
unknown committed
1495 1496 1497 1498 1499
     # If we had extra master opts to the previous run
     # or there is no master running (FIXME strange.....)
     # or there is a master init script
     if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] || \
	[ -f $master_init_script ]
1500 1501 1502
     then
       EXTRA_MASTER_OPT=""
       stop_master
unknown's avatar
unknown committed
1503
       stop_master 1
unknown's avatar
unknown committed
1504
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1505
       start_master
unknown's avatar
unknown committed
1506
       if [ -n "$USE_NDBCLUSTER"  -a -z "$DO_BENCH" ] ; then
unknown's avatar
unknown committed
1507 1508
         start_master 1
       fi
unknown's avatar
unknown committed
1509 1510
     else
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
unknown's avatar
unknown committed
1511
     fi
1512
   fi
unknown's avatar
unknown committed
1513

unknown's avatar
unknown committed
1514 1515 1516 1517
   # 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 ] ;
1518
     then
unknown's avatar
unknown committed
1519
       EXTRA_SLAVE_OPT=`$CAT $slave_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
unknown's avatar
unknown committed
1520
       do_slave_restart=1
unknown's avatar
unknown committed
1521 1522 1523 1524 1525 1526
     else
      if [ ! -z "$EXTRA_SLAVE_OPT" ] || [ x$SLAVE_RUNNING != x1 ] ;
      then
	EXTRA_SLAVE_OPT=""
	do_slave_restart=1
      fi
unknown's avatar
unknown committed
1527
     fi
1528

unknown's avatar
unknown committed
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550
     if [ -f $slave_master_info_file ] ; then
       SLAVE_MASTER_INFO=`$CAT $slave_master_info_file`
       do_slave_restart=1
     else
       if [ ! -z "$SLAVE_MASTER_INFO" ] || [ x$SLAVE_RUNNING != x1 ] ;
       then
	 SLAVE_MASTER_INFO=""
	 do_slave_restart=1
       fi
     fi

     if [ x$do_slave_restart = x1 ] ; then
       stop_slave
       echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
       start_slave
     else
       echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
     fi
     if [ x$many_slaves = x1 ]; then
      start_slave 1
      start_slave 2
     fi
1551
   fi
unknown's avatar
fixed  
unknown committed
1552
 fi
1553 1554 1555 1556 1557 1558

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

1559
 cd $MYSQL_TEST_DIR
unknown's avatar
unknown committed
1560

unknown's avatar
unknown committed
1561
 if [ -f $tf ] ; then
unknown's avatar
unknown committed
1562
    $RM -f r/$tname.*reject
unknown's avatar
unknown committed
1563
    mysql_test_args="-R $result_file $EXTRA_MYSQL_TEST_OPT"
1564
    if [ -z "$DO_CLIENT_GDB" ] ; then
1565
      `$MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`;
1566
    else
1567
      do_gdb_test "$mysql_test_args" "$tf"
1568
    fi
unknown's avatar
unknown committed
1569

unknown's avatar
unknown committed
1570 1571
    res=$?

1572
    pname=`$ECHO "$tname                        "|$CUT -c 1-24`
1573
    RES="$pname"
unknown's avatar
unknown committed
1574

1575 1576 1577 1578
    if [ x$many_slaves = x1 ] ; then
     stop_slave 1
     stop_slave 2
    fi
unknown's avatar
unknown committed
1579

unknown's avatar
unknown committed
1580
    if [ $res = 0 ]; then
1581 1582
      total_inc
      pass_inc
unknown's avatar
unknown committed
1583
      TIMER=""
unknown's avatar
unknown committed
1584
      if [ x$USE_TIMER = x1 -a -f "$MY_LOG_DIR/timer" ]; then
unknown's avatar
unknown committed
1585 1586 1587 1588
	TIMER=`cat $MY_LOG_DIR/timer`
	TIMER=`$PRINTF "%13s" $TIMER`
      fi
      $ECHO "$RES$RES_SPACE [ pass ]   $TIMER"
1589
    else
1590
      # why the following ``if'' ? That is why res==1 is special ?
1591 1592 1593 1594
      if [ $res = 2 ]; then
        skip_inc
	$ECHO "$RES$RES_SPACE [ skipped ]"
      else
1595 1596 1597
        if [ $res -gt 2 ]; then
          $ECHO "mysqltest returned unexpected code $res, it has probably crashed" >> $TIMEFILE
        fi
1598
	total_inc
unknown's avatar
unknown committed
1599
        fail_inc
1600
	$ECHO "$RES$RES_SPACE [ fail ]"
1601 1602
        $ECHO
	error_is
unknown's avatar
unknown committed
1603
	show_failed_diff $tname
unknown's avatar
unknown committed
1604
	$ECHO
1605
	if [ x$FORCE != x1 ] ; then
unknown's avatar
unknown committed
1606
	 $ECHO "Aborting: $tname failed in $TEST_MODE mode. To continue, re-run with '--force'."
1607
	 $ECHO
unknown's avatar
unknown committed
1608 1609
         if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && \
	    [ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
unknown's avatar
unknown committed
1610 1611
	 then
	   mysql_stop
unknown's avatar
unknown committed
1612
	   stop_manager
unknown's avatar
unknown committed
1613
   	 fi
1614 1615
	 exit 1
	fi
unknown's avatar
unknown committed
1616
	FAILED_CASES="$FAILED_CASES $tname"
unknown's avatar
unknown committed
1617 1618
        if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && \
	   [ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
unknown's avatar
unknown committed
1619 1620 1621
	then
	  mysql_restart
	fi
1622
      fi
unknown's avatar
unknown committed
1623
    fi
1624
  fi
unknown's avatar
unknown committed
1625 1626
}

unknown's avatar
unknown committed
1627 1628 1629 1630
######################################################################
# Main script starts here
######################################################################

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

unknown's avatar
unknown committed
1633 1634
[ "$DO_GCOV" ] && gcov_prepare
[ "$DO_GPROF" ] && gprof_prepare
unknown's avatar
unknown committed
1635

1636 1637
if [ -z "$USE_RUNNING_SERVER" ]
then
1638 1639 1640 1641
  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
1642
    $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK1 -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
1643 1644
    $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
1645
    $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT1 -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
1646 1647 1648
    $MYSQLADMIN --no-defaults --host=$hostname --port=$SLAVE_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --host=$hostname --port=`expr $SLAVE_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    sleep_until_file_deleted 0 $MASTER_MYPID
1649
    sleep_until_file_deleted 0 $MASTER_MYPID"1"
1650 1651
    sleep_until_file_deleted 0 $SLAVE_MYPID
  else
1652
    rm $MASTER_MYPID $MASTER_MYPID"1" $SLAVE_MYPID
1653
  fi
unknown's avatar
unknown committed
1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666

  # Kill any running managers
  if [ -f "$MANAGER_PID_FILE" ]
  then
    kill `cat $MANAGER_PID_FILE`
    sleep 1
    if [ -f "$MANAGER_PID_FILE" ]
    then
      kill -9 `cat $MANAGER_PID_FILE`
      sleep 1
    fi
  fi

unknown's avatar
unknown committed
1667
  stop_ndbcluster
unknown's avatar
unknown committed
1668

unknown's avatar
unknown committed
1669
  # Remove files that can cause problems
1670
  $RM -rf $MYSQL_TEST_DIR/var/ndbcluster
unknown's avatar
unknown committed
1671 1672
  $RM -f $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*

1673 1674
  # Remove old berkeley db log files that can confuse the server
  $RM -f $MASTER_MYDDIR/log.*
unknown's avatar
unknown committed
1675
  $RM -f $MASTER_MYDDIR"1"/log.*
1676

unknown's avatar
unknown committed
1677 1678
  wait_for_master=$SLEEP_TIME_FOR_FIRST_MASTER
  wait_for_slave=$SLEEP_TIME_FOR_FIRST_SLAVE
1679 1680
  $ECHO "Installing Test Databases"
  mysql_install_db
unknown's avatar
unknown committed
1681

unknown's avatar
unknown committed
1682
  start_manager
unknown's avatar
unknown committed
1683

unknown's avatar
unknown committed
1684
# Do not automagically start daemons if we are in gdb or running only one test
unknown's avatar
unknown committed
1685
# case
1686 1687 1688 1689 1690 1691
  if [ -z "$DO_GDB" ] && [ -z "$DO_DDD" ]
  then
    mysql_start
  fi
  $ECHO  "Loading Standard Test Databases"
  mysql_loadstd
unknown's avatar
unknown committed
1692 1693 1694
fi


1695
$ECHO  "Starting Tests"
unknown's avatar
unknown committed
1696

1697 1698 1699
#
# This can probably be deleted
#
unknown's avatar
unknown committed
1700 1701
if [ "$DO_BENCH" = 1 ]
then
1702 1703
  start_master

1704 1705 1706 1707 1708
  if [ "$DO_SMALL_BENCH" = 1 ]
  then
    EXTRA_BENCH_ARGS="--small-test --small-tables"
  fi

1709 1710
  if [ ! -z "$USE_NDBCLUSTER" ]
  then
1711
    EXTRA_BENCH_ARGS="--create-options=TYPE=ndb $EXTRA_BENCH_ARGS"
1712 1713
  fi 

unknown's avatar
unknown committed
1714 1715 1716 1717
  BENCHDIR=$BASEDIR/sql-bench/
  savedir=`pwd`
  cd $BENCHDIR
  if [ -z "$1" ]
unknown's avatar
unknown committed
1718
  then
1719
    ./run-all-tests --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS --log
unknown's avatar
unknown committed
1720
  else
unknown's avatar
unknown committed
1721 1722
    if [ -x "./$1" ]
    then
1723
       ./$1 --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS
unknown's avatar
unknown committed
1724 1725 1726
    else
      echo "benchmark $1 not found"
    fi
unknown's avatar
unknown committed
1727
  fi
unknown's avatar
unknown committed
1728 1729 1730 1731
  cd $savedir
  mysql_stop
  stop_manager
  exit
unknown's avatar
unknown committed
1732 1733
fi

unknown's avatar
unknown committed
1734
$ECHO
unknown's avatar
unknown committed
1735
if [ x$USE_TIMER = x1 ] ; then
unknown's avatar
unknown committed
1736
$ECHO "TEST                            RESULT        TIME (ms)"
unknown's avatar
unknown committed
1737 1738 1739
else
$ECHO "TEST                            RESULT"
fi
unknown's avatar
unknown committed
1740 1741
$ECHO $DASH72

unknown's avatar
unknown committed
1742
if [ -z "$1" ] ;
unknown's avatar
unknown committed
1743
then
1744 1745 1746
  if [ x$RECORD = x1 ]; then
    $ECHO "Will not run in record mode without a specific test case."
  else
1747 1748 1749 1750
    for tf in $TESTDIR/*.$TESTSUFFIX
    do
      run_testcase $tf
    done
1751 1752
    $RM -f $TIMEFILE	# Remove for full test
  fi
unknown's avatar
unknown committed
1753
else
unknown's avatar
unknown committed
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
  while [ ! -z "$1" ]; do
    tname=`$BASENAME $1 .test`
    tf=$TESTDIR/$tname.$TESTSUFFIX
    if [ -f $tf ] ; then
      run_testcase $tf
    else
      $ECHO "Test case $tf does not exist."
    fi
    shift
  done
unknown's avatar
unknown committed
1764
fi
unknown's avatar
unknown committed
1765

unknown's avatar
unknown committed
1766 1767
$ECHO $DASH72
$ECHO
1768

1769
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
unknown's avatar
unknown committed
1770 1771 1772
then
    mysql_stop
fi
unknown's avatar
unknown committed
1773
stop_manager
unknown's avatar
unknown committed
1774
report_stats
unknown's avatar
unknown committed
1775
$ECHO
unknown's avatar
unknown committed
1776

unknown's avatar
unknown committed
1777
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
unknown's avatar
unknown committed
1778
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
unknown's avatar
unknown committed
1779

unknown's avatar
unknown committed
1780
if [ $TOT_FAIL -ne 0 ]; then
unknown's avatar
unknown committed
1781
  $ECHO "mysql-test-run in $TEST_MODE mode: *** Failing the test(s):$FAILED_CASES"
unknown's avatar
unknown committed
1782 1783 1784 1785 1786
  $ECHO
  exit 1
else
  exit 0
fi