mysql-test-run.sh 41.2 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 7
# Fixed by Sergei
# :-)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
8 9 10 11 12

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

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

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

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

43 44 45 46
# Standard functions

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


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

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

104 105 106 107 108
# For the future

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

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

114 115
SED=sed

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

# Are we using a source or a binary distribution?

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

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

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

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

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

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

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

sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
200
MASTER_RUNNING=0
201
MASTER_MYPORT=9306
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
202
SLAVE_RUNNING=0
203
SLAVE_MYPORT=9307
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
204 205 206 207
MYSQL_MANAGER_PORT=9305 # needs to be out of the way of slaves
MYSQL_MANAGER_PW_FILE=$MYSQL_TEST_DIR/var/tmp/manager.pwd
MYSQL_MANAGER_LOG=$MYSQL_TEST_DIR/var/log/manager.log
MYSQL_MANAGER_USER=root
208
NO_SLAVE=0
209
USER_TEST=
210

211
EXTRA_MASTER_OPT=""
212
EXTRA_MYSQL_TEST_OPT=""
213 214
EXTRA_MYSQLDUMP_OPT=""
EXTRA_MYSQLBINLOG_OPT=""
215
USE_RUNNING_SERVER=""
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
216 217
USE_NDBCLUSTER=""
USE_RUNNING_NDBCLUSTER=""
218 219
DO_GCOV=""
DO_GDB=""
220
MANUAL_GDB=""
221
DO_DDD=""
222
DO_CLIENT_GDB=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
223
SLEEP_TIME_AFTER_RESTART=1
224
SLEEP_TIME_FOR_DELETE=10
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
225
SLEEP_TIME_FOR_FIRST_MASTER=400		# Enough time to create innodb tables
226
SLEEP_TIME_FOR_SECOND_MASTER=30
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
227
SLEEP_TIME_FOR_FIRST_SLAVE=400
228
SLEEP_TIME_FOR_SECOND_SLAVE=30
229
CHARACTER_SET=latin1
230
DBUSER=""
231 232
START_WAIT_TIMEOUT=10
STOP_WAIT_TIMEOUT=10
gluh@gluh.mysql.r18.ru's avatar
gluh@gluh.mysql.r18.ru committed
233
MYSQL_TEST_SSL_OPTS=""
234 235 236

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
415 416 417
#++
# mysqld Environment Parameters
#--
418

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
419
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
420 421
MANAGER_PID_FILE="$MYRUN_DIR/manager.pid"

422
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
423
MASTER_MYSOCK="$MYSQL_TMP_DIR/master.sock"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
424 425 426
MASTER_MYPID="$MYRUN_DIR/master.pid"
MASTER_MYLOG="$MYSQL_TEST_DIR/var/log/master.log"
MASTER_MYERR="$MYSQL_TEST_DIR/var/log/master.err"
427 428

SLAVE_MYDDIR="$MYSQL_TEST_DIR/var/slave-data"
429
SLAVE_MYSOCK="$MYSQL_TMP_DIR/slave.sock"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
430 431 432
SLAVE_MYPID="$MYRUN_DIR/slave.pid"
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/slave.log"
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/slave.err"
433

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

monty@mysql.com's avatar
monty@mysql.com committed
437
export MASTER_MYPORT SLAVE_MYPORT
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
438

439 440 441 442
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
443
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
444

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
445 446 447 448 449 450 451 452
# 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
453
[ -d $MYSQL_TEST_DIR/var/log ] || mkdir $MYSQL_TEST_DIR/var/log
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
454

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

459 460 461
# on source dist, we pick up freshly build executables
# on binary, use what is installed
if [ x$SOURCE_DIST = x1 ] ; then
462
 MYSQLD="$VALGRIND $BASEDIR/sql/mysqld"
463
 if [ -f "$BASEDIR/client/.libs/lt-mysqltest" ] ; then
464
   MYSQL_TEST="$BASEDIR/client/.libs/lt-mysqltest"
monty@bitch.mysql.fi's avatar
monty@bitch.mysql.fi committed
465 466
 elif [ -f "$BASEDIR/client/.libs/mysqltest" ] ; then
   MYSQL_TEST="$BASEDIR/client/.libs/mysqltest"
467 468 469
 else
   MYSQL_TEST="$BASEDIR/client/mysqltest"
 fi
470
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
471
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
472
 else
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
473
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
474
 fi
475
 if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
476
   MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog"
477
 else
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
478
   MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog"
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
479
 fi
480 481 482
 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
483

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

524
MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
525
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR $EXTRA_MYSQLBINLOG_OPT"
526
MYSQL_FIX_SYSTEM_TABLES="$MYSQL_FIX_SYSTEM_TABLES --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD --basedir=$BASEDIR --bindir=$CLIENT_BINDIR --verbose=1"
monty@mysql.com's avatar
monty@mysql.com committed
527 528
MYSQL="$MYSQL --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD"
export MYSQL MYSQL_DUMP MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES CLIENT_BINDIR
529

530

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

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

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

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

if [ -w / ]
then
monty@mysql.com's avatar
monty@mysql.com committed
557 558 559
  # 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"
560 561
fi

562

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
581 582 583 584
#++
# Function Definitions
#--

585 586
prompt_user ()
{
587
 $ECHO $1
588
 read unused
589 590
}

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

593 594 595 596
show_failed_diff ()
{
  reject_file=r/$1.reject
  result_file=r/$1.result
597
  eval_file=r/$1.eval
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
598

599 600 601 602
  if [ -f $eval_file ]
  then
    result_file=$eval_file
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
603

604 605 606 607
  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
608
    $DIFF -c $result_file $reject_file
609
    echo "-------------------------------------------------------"
610
    echo "Please follow the instructions outlined at"
611
    echo "http://www.mysql.com/doc/en/Reporting_mysqltest_bugs.html"
612
    echo "to find the reason to this problem and how to report this."
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
613
  fi
614
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
615

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

bk@work.mysql.com's avatar
bk@work.mysql.com committed
625
error () {
626
    $ECHO  "Error:  $1"
bk@work.mysql.com's avatar
bk@work.mysql.com committed
627 628 629
    exit 1
}

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

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
636
prefix_to_8() {
637
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
638 639
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
640
pass_inc () {
641
    TOT_PASS=`$EXPR $TOT_PASS + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
642 643 644
}

fail_inc () {
645
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
646 647
}

648 649 650 651
skip_inc () {
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
}

bk@work.mysql.com's avatar
bk@work.mysql.com committed
652
total_inc () {
653
    TOT_TEST=`$EXPR $TOT_TEST + 1`
bk@work.mysql.com's avatar
bk@work.mysql.com committed
654 655
}

656 657 658 659 660 661

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

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

685 686 687
    if test -z "$USE_RUNNING_SERVER"
    then

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
688 689 690 691 692
    # Report if there was any fatal warnings/errors in the log files
    #
    $RM -f $MY_LOG_DIR/warnings $MY_LOG_DIR/warnings.tmp
    # Remove some non fatal warnings from the log files
    $SED -e 's!Warning:  Table:.* on delete!!g' \
693 694 695
        $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
696 697 698 699 700

    found_error=0
    # Find errors
    for i in "^Warning:" "^Error:" "^==.* at 0x"
    do
701
      if $GREP "$i" $MY_LOG_DIR/warnings.tmp >> $MY_LOG_DIR/warnings
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
702 703 704 705 706 707 708 709 710 711
      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
712
    fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
713
}
714

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

731 732
    for slave_num in 1 2 ;
    do
733
      $RM -rf var/slave$slave_num-data
734 735 736
      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
737
    done
bk@work.mysql.com's avatar
bk@work.mysql.com committed
738 739 740
    return 0
}

741 742
gprof_prepare ()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
743 744
 $RM -rf $GPROF_DIR
 mkdir -p $GPROF_DIR
745 746 747 748 749
}

gprof_collect ()
{
 if [ -f $MASTER_MYDDIR/gmon.out ]; then
750
   gprof $MASTER_MYSQLD $MASTER_MYDDIR/gmon.out > $GPROF_MASTER
751 752 753
   echo "Master execution profile has been saved in $GPROF_MASTER"
 fi
 if [ -f $SLAVE_MYDDIR/gmon.out ]; then
754
   gprof $SLAVE_MYSQLD $SLAVE_MYDDIR/gmon.out > $GPROF_SLAVE
755 756 757 758
   echo "Slave execution profile has been saved in $GPROF_SLAVE"
 fi
}

759
gcov_prepare () {
760 761
    $FIND $BASEDIR -name \*.gcov \
    -or -name \*.da | $XARGS $RM
762 763 764
}

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

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
776
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
777 778
}

779 780 781 782 783
abort_if_failed()
{
 if [ ! $? = 0 ] ; then
  echo $1
  exit 1
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
784
 fi
785 786 787 788
}

start_manager()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
789
 if [ $USE_MANAGER = 0 ] ; then
790 791
   echo "Manager disabled, skipping manager start."
   $RM -f $MYSQL_MANAGER_LOG
792 793
  return
 fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
794
 $ECHO "Starting MySQL Manager"
795 796 797 798 799 800 801 802 803
 if [ -f "$MANAGER_PID_FILE" ] ; then
    kill `cat $MANAGER_PID_FILE`
    sleep 1
    if [ -f "$MANAGER_PID_FILE" ] ; then
     kill -9 `cat $MANAGER_PID_FILE`
     sleep 1
    fi
 fi

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

823 824
stop_manager()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
825
 if [ $USE_MANAGER = 0 ] ; then
826 827
  return
 fi
828 829 830 831
 $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT -u$MYSQL_MANAGER_USER \
  -p$MYSQL_MANAGER_PW -P $MYSQL_MANAGER_PORT <<EOF
shutdown
EOF
832 833
 echo "Manager terminated"

834 835 836
}

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

856 857
manager_term()
{
858 859
  pid=$1
  ident=$2
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
860
  if [ $USE_MANAGER = 0 ] ; then
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
861 862
    # Shutdown time must be high as slave may be in reconnect
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock --connect_timeout=5 --shutdown_timeout=70 shutdown >> $MYSQL_MANAGER_LOG 2>&1
863 864 865 866 867 868 869 870
    res=$?
    # Some systems require an extra connect
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock --connect_timeout=1 ping >> $MYSQL_MANAGER_LOG 2>&1
    if test $res = 0
    then
      wait_for_pid $pid
    fi
    return $res
871
  fi
872 873
  $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
   --password=$MYSQL_MANAGER_PW  --port=$MYSQL_MANAGER_PORT <<EOF
874
stop_exec $ident $STOP_WAIT_TIMEOUT
875 876 877 878 879
EOF
 abort_if_failed "Could not execute manager command"
}


880 881
start_master()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
882 883 884 885 886
  if [ x$MASTER_RUNNING = x1 ] || [ x$LOCAL_MASTER = x1 ] ; then
    return
  fi
  # Remove stale binary logs
  $RM -f $MYSQL_TEST_DIR/var/log/master-bin.*
887 888
  # Remove old master.info and relay-log.info files
  $RM -f $MYSQL_TEST_DIR/var/master-data/master.info $MYSQL_TEST_DIR/var/master-data/relay-log.info
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
889 890 891 892 893 894 895 896 897 898 899

  #run master initialization shell script if one exists

  if [ -f "$master_init_script" ] ;
  then
      /bin/sh $master_init_script
  fi
  cd $BASEDIR # for gcov
  if [ -z "$DO_BENCH" ]
  then
    master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin \
900 901
  	    --server-id=1  \
          --basedir=$MY_BASEDIR \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
902
          --port=$MASTER_MYPORT \
903
          --local-infile \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
904 905
          --exit-info=256 \
          --core \
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
906
          $USE_NDBCLUSTER \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
907 908 909 910 911 912 913 914 915
          --datadir=$MASTER_MYDDIR \
          --pid-file=$MASTER_MYPID \
          --socket=$MASTER_MYSOCK \
          --log=$MASTER_MYLOG \
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
          --innodb_data_file_path=ibdata1:50M \
916
	  --open-files-limit=1024 \
917
	   $MASTER_40_ARGS \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
918 919 920 921 922 923 924
           $SMALL_SERVER \
           $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT"
  else
    master_args="--no-defaults --log-bin=$MYSQL_TEST_DIR/var/log/master-bin \
          --server-id=1 --rpl-recovery-rank=1 \
          --basedir=$MY_BASEDIR --init-rpl-role=master \
          --port=$MASTER_MYPORT \
925
          --local-infile \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
926 927 928 929 930 931
          --datadir=$MASTER_MYDDIR \
          --pid-file=$MASTER_MYPID \
          --socket=$MASTER_MYSOCK \
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core \
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
932
          $USE_NDBCLUSTER \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
933 934 935
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
          --innodb_data_file_path=ibdata1:50M \
936
	   $MASTER_40_ARGS \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
937 938 939 940 941 942 943 944 945 946 947
           $SMALL_SERVER \
           $EXTRA_MASTER_OPT $EXTRA_MASTER_MYSQLD_OPT"
  fi

  CUR_MYERR=$MASTER_MYERR
  CUR_MYSOCK=$MASTER_MYSOCK

  if [ x$DO_DDD = x1 ]
  then
    $ECHO "set args $master_args" > $GDB_MASTER_INIT
    manager_launch master ddd -display $DISPLAY --debugger \
948
    "gdb -x $GDB_MASTER_INIT" $MASTER_MYSQLD
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
949 950
  elif [ x$DO_GDB = x1 ]
  then
951 952 953 954
    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:"
955
      $ECHO "cd $CWD ; gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD"
956 957 958 959
      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
960
    cat <<EOF
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
961 962
b mysql_parse
commands 1
963
disa 1
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
964
end
965 966
r
EOF
967 968
      fi )  > $GDB_MASTER_INIT
      manager_launch master $XTERM -display $DISPLAY \
969
      -title "Master" -e gdb -x $GDB_MASTER_INIT $MASTER_MYSQLD
970
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
971
  else
972
    manager_launch master $MASTER_MYSQLD $master_args
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
973
  fi
974
  sleep_until_file_created $MASTER_MYPID $wait_for_master
975
  wait_for_master=$SLEEP_TIME_FOR_SECOND_MASTER
976 977 978 979 980
  MASTER_RUNNING=1
}

start_slave()
{
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
981 982 983
  [ x$SKIP_SLAVE = x1 ] && return
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  [ x$this_slave_running = 1 ] && return
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
984 985
  # 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
986 987 988 989 990 991 992 993
  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"
994
   slave_datadir="$SLAVE_MYDDIR/../$slave_ident-data/"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
   slave_sock="$SLAVE_MYSOCK-$1"
  else
   slave_server_id=2
   slave_rpl_rank=2
   slave_port=$SLAVE_MYPORT
   slave_log=$SLAVE_MYLOG
   slave_err=$SLAVE_MYERR
   slave_datadir=$SLAVE_MYDDIR
   slave_pid=$SLAVE_MYPID
   slave_sock="$SLAVE_MYSOCK"
 fi
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1007 1008
  # Remove stale binary logs and old master.info files
  $RM -f $MYSQL_TEST_DIR/var/log/$slave_ident-*bin.*
1009
  $RM -f $slave_datadir/master.info $slave_datadir/relay-log.info
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020

  #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 \
1021
          --master-password="" \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
          --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 \
1032
          --relay-log=$MYSQL_TEST_DIR/var/log/$slave_ident-relay-bin \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
          --log-slave-updates \
          --log=$slave_log \
          --basedir=$MY_BASEDIR \
          --datadir=$slave_datadir \
          --pid-file=$slave_pid \
          --port=$slave_port \
          --socket=$slave_sock \
          --character-sets-dir=$CHARSETSDIR \
          --default-character-set=$CHARACTER_SET \
          --core --init-rpl-role=slave \
          --tmpdir=$MYSQL_TMP_DIR \
          --language=$LANGUAGE \
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
1045
          --skip-innodb --skip-ndbcluster --skip-slave-start \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1046 1047 1048
          --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
          --report-host=127.0.0.1 --report-user=root \
          --report-port=$slave_port \
1049
          --master-retry-count=10 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1050
          -O slave_net_timeout=10 \
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1051 1052 1053 1054 1055 1056 1057
           $SMALL_SERVER \
           $EXTRA_SLAVE_OPT $EXTRA_SLAVE_MYSQLD_OPT"
  CUR_MYERR=$slave_err
  CUR_MYSOCK=$slave_sock

  if [ x$DO_DDD = x1 ]
  then
1058
    $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1059 1060 1061 1062
    manager_launch $slave_ident ddd -display $DISPLAY --debugger \
     "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD
  elif [ x$DO_GDB = x1 ]
  then
1063 1064
    if [ x$MANUAL_GDB = x1 ]
    then
1065
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
1066
      echo "To start gdb for the slave, type in another window:"
1067
      echo "cd $CWD ; gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD"
1068 1069
      wait_for_slave=1500
    else
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
      ( $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
1080 1081 1082
      manager_launch $slave_ident $XTERM -display $DISPLAY -title "Slave" -e \
      gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1083 1084 1085 1086
  else
    manager_launch $slave_ident $SLAVE_MYSQLD $slave_args
  fi
  eval "SLAVE$1_RUNNING=1"
1087
  sleep_until_file_created $slave_pid $wait_for_slave
1088
  wait_for_slave=$SLEEP_TIME_FOR_SECOND_SLAVE
1089 1090
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1091 1092
mysql_start ()
{
monty@narttu.mysql.fi's avatar
monty@narttu.mysql.fi committed
1093
# 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
1094
# for the test.  Better to let the test start the daemon
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1095 1096 1097 1098

#  $ECHO "Starting MySQL daemon"
#  start_master
#  start_slave
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1099 1100
  cd $MYSQL_TEST_DIR
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1101 1102
}

1103 1104
stop_slave ()
{
1105 1106 1107
  eval "this_slave_running=\$SLAVE$1_RUNNING"
  slave_ident="slave$1"
  if [ -n "$1" ] ;
1108
  then
1109 1110 1111
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
  else
   slave_pid=$SLAVE_MYPID
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1112
  fi
1113 1114
  if [ x$this_slave_running = x1 ]
  then
1115 1116
    pid=`$CAT $slave_pid`
    manager_term $pid $slave_ident
1117
    if [ $? != 0 ] && [ -f $slave_pid ]
1118
    then # try harder!
1119
      $ECHO "slave not cooperating with mysqladmin, will try manual kill"
1120 1121
      kill $pid
      sleep_until_file_deleted $pid $slave_pid
1122 1123 1124 1125 1126 1127 1128 1129 1130
      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
1131
    fi
1132
    eval "SLAVE$1_RUNNING=0"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1133
  fi
1134
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1135

1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
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
}

1146 1147 1148 1149
stop_master ()
{
  if [ x$MASTER_RUNNING = x1 ]
  then
1150 1151
    pid=`$CAT $MASTER_MYPID`
    manager_term $pid master
1152 1153
    if [ $? != 0 ] && [ -f $MASTER_MYPID ]
    then # try harder!
1154
      $ECHO "master not cooperating with mysqladmin, will try manual kill"
1155 1156
      kill $pid
      sleep_until_file_deleted $pid $MASTER_MYPID
1157 1158 1159 1160 1161 1162 1163 1164 1165
      if [ -f $MASTER_MYPID ] ; then
        $ECHO "master refused to die. Sending SIGKILL"
        kill -9 `$CAT $MASTER_MYPID`
        $RM -f $MASTER_MYPID
      else
        $ECHO "master responded to SIGTERM "
      fi
    else
      sleep $SLEEP_TIME_AFTER_RESTART
1166
    fi
1167 1168 1169
    MASTER_RUNNING=0
  fi
}
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1170

1171 1172
mysql_stop ()
{
1173 1174
 $ECHO  "Ending Tests"
 $ECHO  "Shutting-down MySQL daemon"
1175
 $ECHO  ""
1176
 stop_master
1177
 $ECHO "Master shutdown finished"
1178
 stop_slave
1179 1180
 stop_slave 1
 stop_slave 2
1181
 $ECHO "Slave shutdown finished"
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1182

1183
 return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1184 1185
}

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1186 1187 1188 1189 1190
mysql_restart ()
{
  mysql_stop
  mysql_start
  return 1
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1191 1192 1193
}

mysql_loadstd () {
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1194 1195

    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1196 1197 1198
    return 1
}

1199 1200 1201
run_testcase ()
{
 tf=$1
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1202
 tname=`$BASENAME $tf .test`
1203 1204
 master_opt_file=$TESTDIR/$tname-master.opt
 slave_opt_file=$TESTDIR/$tname-slave.opt
1205 1206
 master_init_script=$TESTDIR/$tname-master.sh
 slave_init_script=$TESTDIR/$tname-slave.sh
1207
 slave_master_info_file=$TESTDIR/$tname.slave-mi
1208
 result_file=$tname
1209
 echo $tname > $CURRENT_TEST
1210
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0`
1211
 if [ "$USE_MANAGER" = 1 ] ; then
1212 1213 1214 1215 1216
   many_slaves=`$EXPR \( \( $tname : rpl_failsafe \) != 0 \) \| \( \( $tname : rpl_chain_temp_table \) != 0 \)`
 fi
 if $EXPR "$tname" '<' "$START_FROM" > /dev/null ; then
   #skip_test $tname
   return
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1217 1218
 fi

1219 1220 1221 1222
 if [ "$SKIP_TEST" ] ; then
   if $EXPR \( "$tname" : "$SKIP_TEST" \) > /dev/null ; then
     skip_test $tname
     return
1223
   fi
1224
 fi
1225

1226 1227
 if [ "$DO_TEST" ] ; then
   if $EXPR \( "$tname" : "$DO_TEST" \) > /dev/null ; then
1228
     : #empty command to keep some shells happy
1229 1230 1231
   else
     #skip_test $tname
     return
1232
   fi
1233
 fi
1234

1235 1236
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ; then
   skip_test $tname
1237 1238 1239
   return
 fi

1240 1241 1242 1243 1244 1245
 # 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

1246
 if [ -z "$USE_RUNNING_SERVER" ] ;
1247
 then
1248 1249
   if [ -f $master_opt_file ] ;
   then
1250
     EXTRA_MASTER_OPT=`$CAT $master_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1251 1252 1253 1254 1255 1256 1257
     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=" "
	 ;;
1258 1259 1260 1261 1262
       --result-file=*)
         result_file=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--result-file=;;"`
	 # Note that this must be set to space, not "" for test-reset to work
	 EXTRA_MASTER_OPT=" "
         ;;
1263
     esac
1264
     stop_master
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1265
     echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1266
     start_master
1267
     TZ=$MY_TZ; export TZ
1268
   else
1269
     if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] || [ -f $master_init_script ]
1270 1271 1272
     then
       EXTRA_MASTER_OPT=""
       stop_master
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1273
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1274
       start_master
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1275 1276
     else
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1277
     fi
1278
   fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1279

monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1280
   do_slave_restart=0
1281 1282
   if [ -f $slave_opt_file ] ;
   then
1283
     EXTRA_SLAVE_OPT=`$CAT $slave_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1284 1285 1286 1287 1288
     do_slave_restart=1
   else
    if [ ! -z "$EXTRA_SLAVE_OPT" ] || [ x$SLAVE_RUNNING != x1 ] ;
    then
      EXTRA_SLAVE_OPT=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1289 1290
      do_slave_restart=1
    fi
1291
   fi
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
1292

1293 1294 1295 1296 1297 1298 1299
   if [ -f $slave_master_info_file ] ; then
     SLAVE_MASTER_INFO=`$CAT $slave_master_info_file`
     do_slave_restart=1
   else
     if [ ! -z "$SLAVE_MASTER_INFO" ] || [ x$SLAVE_RUNNING != x1 ] ;
     then
       SLAVE_MASTER_INFO=""
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1300 1301
       do_slave_restart=1
     fi
1302 1303 1304 1305
   fi

   if [ x$do_slave_restart = x1 ] ; then
     stop_slave
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1306
     echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
1307
     start_slave
monty@mashka.mysql.fi's avatar
monty@mashka.mysql.fi committed
1308 1309
   else
     echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
1310
   fi
1311 1312 1313 1314
   if [ x$many_slaves = x1 ]; then
    start_slave 1
    start_slave 2
   fi
sasha@mysql.sashanet.com's avatar
fixed  
sasha@mysql.sashanet.com committed
1315
 fi
1316
 cd $MYSQL_TEST_DIR
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1317

1318
 if [ -f $tf ] ; then
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1319
    $RM -f r/$tname.*reject
1320
    mysql_test_args="-R r/$result_file.result $EXTRA_MYSQL_TEST_OPT"
1321
    if [ -z "$DO_CLIENT_GDB" ] ; then
1322
      `$MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`;
1323
    else
1324
      do_gdb_test "$mysql_test_args" "$tf"
1325
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1326

bk@work.mysql.com's avatar
bk@work.mysql.com committed
1327 1328
    res=$?

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

1332 1333 1334 1335
    if [ x$many_slaves = x1 ] ; then
     stop_slave 1
     stop_slave 2
    fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1336

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1337
    if [ $res = 0 ]; then
1338 1339
      total_inc
      pass_inc
1340
      $ECHO "$RES$RES_SPACE [ pass ]"
1341
    else
1342
      # why the following ``if'' ? That is why res==1 is special ?
1343 1344 1345 1346
      if [ $res = 2 ]; then
        skip_inc
	$ECHO "$RES$RES_SPACE [ skipped ]"
      else
1347 1348 1349
        if [ $res -gt 2 ]; then
          $ECHO "mysqltest returned unexpected code $res, it has probably crashed" >> $TIMEFILE
        fi
1350
	total_inc
1351
        fail_inc
1352
	$ECHO "$RES$RES_SPACE [ fail ]"
1353 1354
        $ECHO
	error_is
1355
	show_failed_diff $result_file
1356
	$ECHO
1357
	if [ x$FORCE != x1 ] ; then
1358
	 $ECHO "Aborting: $tname failed. To continue, re-run with '--force'."
1359
	 $ECHO
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1360 1361 1362
         if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	 then
	   mysql_stop
1363
	   stop_manager
monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1364
   	 fi
1365 1366
	 exit 1
	fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1367

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1368 1369 1370 1371
        if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
	then
	  mysql_restart
	fi
1372
	$ECHO "Resuming Tests"
1373
	$ECHO ""
1374
      fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1375
    fi
1376
  fi
1377 1378
}

monty@donna.mysql.com's avatar
monty@donna.mysql.com committed
1379 1380 1381 1382
######################################################################
# Main script starts here
######################################################################

1383 1384
[ "$DO_GCOV" -a ! -x "$GCOV" ] && error "No gcov found"

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1385 1386
[ "$DO_GCOV" ] && gcov_prepare
[ "$DO_GPROF" ] && gprof_prepare
1387

1388 1389
if [ -z "$USE_RUNNING_SERVER" ]
then
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
  if [ -z "$FAST_START" ]
  then
    # Ensure that no old mysqld test servers are running
    $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --host=$hostname --port=$SLAVE_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    $MYSQLADMIN --no-defaults --host=$hostname --port=`expr $SLAVE_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
    sleep_until_file_deleted 0 $MASTER_MYPID
    sleep_until_file_deleted 0 $SLAVE_MYPID
  else
    rm $MASTER_MYPID $SLAVE_MYPID
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415

  # 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

tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1416 1417 1418 1419 1420
  if [ ! -z "$USE_NDBCLUSTER" ]
  then
  if [ -z "$USE_RUNNING_NDBCLUSTER" ]
  then
    # Kill any running ndbcluster stuff
1421
    ./ndb/ndbcluster --stop
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1422 1423 1424
  fi
  fi

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1425
  # Remove files that can cause problems
1426
  $RM -rf $MYSQL_TEST_DIR/var/ndbcluster
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1427 1428
  $RM -f $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*

1429 1430 1431
  # Remove old berkeley db log files that can confuse the server
  $RM -f $MASTER_MYDDIR/log.*

1432 1433
  wait_for_master=$SLEEP_TIME_FOR_FIRST_MASTER
  wait_for_slave=$SLEEP_TIME_FOR_FIRST_SLAVE
1434 1435
  $ECHO "Installing Test Databases"
  mysql_install_db
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1436 1437 1438 1439 1440 1441

  if [ ! -z "$USE_NDBCLUSTER" ]
  then
  if [ -z "$USE_RUNNING_NDBCLUSTER" ]
  then
    echo "Starting ndbcluster"
1442
    ./ndb/ndbcluster --initial --data-dir=$MYSQL_TEST_DIR/var || exit 1
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1443 1444 1445 1446 1447 1448 1449
    export NDB_CONNECTSTRING=`cat Ndb.cfg`
  else
    export NDB_CONNECTSTRING="$USE_RUNNING_NDBCLUSTER"
    echo "Using ndbcluster at $NDB_CONNECTSTRING"
  fi
  fi

1450
  start_manager
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1451

paul@ice.snake.net's avatar
paul@ice.snake.net committed
1452
# Do not automagically start daemons if we are in gdb or running only one test
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1453
# case
1454 1455 1456 1457 1458 1459
  if [ -z "$DO_GDB" ] && [ -z "$DO_DDD" ]
  then
    mysql_start
  fi
  $ECHO  "Loading Standard Test Databases"
  mysql_loadstd
1460 1461
fi

1462 1463 1464 1465
if [ "x$START_AND_EXIT" = "x1" ] ; then
 echo "Servers started, exiting"
 exit
fi
1466

1467
$ECHO  "Starting Tests"
1468

1469 1470 1471
#
# This can probably be deleted
#
1472 1473
if [ "$DO_BENCH" = 1 ]
then
1474 1475 1476 1477 1478 1479 1480
  start_master

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

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1481 1482 1483 1484
  BENCHDIR=$BASEDIR/sql-bench/
  savedir=`pwd`
  cd $BENCHDIR
  if [ -z "$1" ]
1485
  then
1486
    ./run-all-tests --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS
1487
  else
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1488 1489
    if [ -x "./$1" ]
    then
1490
       ./$1 --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1491 1492 1493
    else
      echo "benchmark $1 not found"
    fi
1494
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1495 1496 1497 1498
  cd $savedir
  mysql_stop
  stop_manager
  exit
1499 1500
fi

1501
$ECHO
1502
$ECHO " TEST                           RESULT"
1503 1504
$ECHO $DASH72

1505
if [ -z "$1" ] ;
1506
then
1507 1508 1509
  if [ x$RECORD = x1 ]; then
    $ECHO "Will not run in record mode without a specific test case."
  else
1510 1511 1512 1513
    for tf in $TESTDIR/*.$TESTSUFFIX
    do
      run_testcase $tf
    done
1514 1515
    $RM -f $TIMEFILE	# Remove for full test
  fi
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1516
else
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
  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
1527
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1528

1529 1530
$ECHO $DASH72
$ECHO
1531

1532
if [ -z "$DO_GDB" ] && [ -z "$USE_RUNNING_SERVER" ] && [ -z "$DO_DDD" ]
1533 1534 1535
then
    mysql_stop
fi
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1536

tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1537 1538 1539 1540 1541
if [ ! -z "$USE_NDBCLUSTER" ]
then
if [ -z "$USE_RUNNING_NDBCLUSTER" ]
then
  # Kill any running ndbcluster stuff
1542
  ./ndb/ndbcluster --stop
tomas@mc05.(none)'s avatar
tomas@mc05.(none) committed
1543 1544 1545
fi
fi

1546
stop_manager
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1547
report_stats
1548
$ECHO
bk@work.mysql.com's avatar
bk@work.mysql.com committed
1549

1550
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
1551
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
1552

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