~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#!/bin/sh
2
# mysql-test-run - originally written by Matt Wagner <matt@mysql.com>
3
# modified by Sasha Pachev <sasha@mysql.com>
4
# Slightly updated by Monty
5
# Cleaned up again by Matt
6
# Fixed by Sergei
7
# List of failed cases (--force) backported from 4.1 by Joerg
8
# :-)
9
10
#echo "##################################################";
11
#echo "This script is deprecated and will soon be removed";
12
#echo "Use mysql-test-run.pl instead";
13
#echo "##################################################";
14
#echo
15
16
#++
17
# Access Definitions
18
#--
19
DB=test
20
DBPASSWD=""
21
VERBOSE=""
22
USE_MANAGER=0
23
MY_TZ=GMT-3
24
TZ=$MY_TZ; export TZ # for UNIX_TIMESTAMP tests to work
25
26
if [ -z "$MYSQL_TCP_PORT" ]; then
27
  MYSQL_TCP_PORT=@MYSQL_TCP_PORT@
28
  if [ @MYSQL_TCP_PORT_DEFAULT@ -eq 0 ]; then
29
    ESP=`getent services mysql/tcp`
30
    if [ $? -eq 0 ]; then
31
      MYSQL_TCP_PORT=`echo "$ESP"|sed -e's-^[a-z]*[ ]*\([0-9]*\)/[a-z]*$-\1-g'`
32
    fi
33
  fi
34
fi
35
36
umask 022
37
38
# For query_cache test
39
case `uname` in
40
    SCO_SV | UnixWare | OpenUNIX )
41
        # do nothing (Causes strange behavior)
42
        ;;
43
    QNX)
44
        # do nothing (avoid error message)
45
        ;;
46
    * )
47
        ulimit -n 1024
48
        ;;
49
esac
50
51
#++
52
# Program Definitions
53
#--
54
55
LC_COLLATE=C
56
export LC_COLLATE
57
PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11:$PATH
58
MASTER_40_ARGS="--rpl-recovery-rank=1 --init-rpl-role=master"
59
60
# Standard functions
61
62
which ()
63
{
64
  IFS="${IFS=   }"; save_ifs="$IFS"; IFS=':'
65
  for file
66
  do
67
    for dir in $PATH
68
    do
69
      if test -f $dir/$file
70
      then
71
        echo "$dir/$file"
72
        continue 2
73
      fi
74
    done
75
    echo "Fatal error: Cannot find program $file in $PATH" 1>&2
76
    exit 1
77
  done
78
  IFS="$save_ifs"
79
  exit 0
80
}
81
82
83
sleep_until_file_deleted ()
84
{
85
  pid=$1;
86
  file=$2
87
  loop=$SLEEP_TIME_FOR_DELETE
88
  while (test $loop -gt 0)
89
  do
90
    if [ ! -r $file ]
91
    then
92
      if test $pid != "0"
93
      then
94
        wait_for_pid $pid
95
      fi
96
      return
97
    fi
98
    sleep 1
99
    loop=`expr $loop - 1`
100
  done
101
}
102
103
sleep_until_file_created ()
104
{
105
  file=$1
106
  loop=$2
107
  org_time=$2
108
  while (test $loop -gt 0)
109
  do
110
    if [ -r $file ]
111
    then
112
      return 0
113
    fi
114
    sleep 1
115
    loop=`expr $loop - 1`
116
  done
117
  echo "ERROR: $file was not created in $org_time seconds;  Aborting"
118
  exit 1;
119
}
120
121
# For the future
122
123
wait_for_pid()
124
{
125
  pid=$1
126
  #$WAIT_PID pid $SLEEP_TIME_FOR_DELETE
127
}
128
129
# Check that valgrind is installed
130
find_valgrind()
131
{
132
  FIND_VALGRIND=`which valgrind` # this will print an error if not found
133
  # Give good warning to the user and stop
134
  if [ -z "$FIND_VALGRIND" ] ; then
135
    $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 ."
136
    exit 1
137
  fi
138
  # >=2.1.2 requires the --tool option, some versions write to stdout, some to stderr
139
  valgrind --help 2>&1 | grep "\-\-tool" > /dev/null && FIND_VALGRIND="$FIND_VALGRIND --tool=memcheck"
140
  FIND_VALGRIND="$FIND_VALGRIND --alignment=8 --leak-check=yes --num-callers=16 --suppressions=$MYSQL_TEST_DIR/valgrind.supp"
141
}
142
143
# No paths below as we can't be sure where the program is!
144
145
SED=sed
146
147
BASENAME=`which basename`
148
if test $? != 0; then exit 1; fi
149
DIFF=`which diff | $SED q`
150
if test $? != 0; then exit 1; fi
151
CAT=cat
152
CUT=cut
153
HEAD=head
154
TAIL=tail
155
ECHO=echo # use internal echo if possible
156
EXPR=expr # use internal if possible
157
FIND=find
158
GREP=grep
159
if test $? != 0; then exit 1; fi
160
PRINTF=printf
161
RM=rm
162
if test $? != 0; then exit 1; fi
163
TR=tr
164
XARGS=`which xargs`
165
if test $? != 0; then exit 1; fi
166
SORT=sort
167
168
# Are we using a source or a binary distribution?
169
170
testdir=@testdir@
171
if [ -d bin/mysqld ] && [ -d mysql-test ] ; then
172
 cd mysql-test
173
else
174
 if [ -d $testdir/mysql-test ] ; then
175
   cd $testdir
176
 fi
177
fi
178
179
if [ ! -f ./mysql-test-run ] ; then
180
  $ECHO "Can't find the location for the mysql-test-run script"
181
182
  $ECHO "Go to to the mysql-test directory and execute the script as follows:"
183
  $ECHO "./mysql-test-run."
184
  exit 1
185
fi
186
187
#++
188
# Misc. Definitions
189
#--
190
191
# BASEDIR is always above mysql-test directory ...
192
MYSQL_TEST_DIR=`pwd`
193
cd ..
194
195
if [ -d ./sql ] ; then
196
   SOURCE_DIST=1
197
else
198
   BINARY_DIST=1
199
200
  # ... one level for tar.gz, two levels for a RPM installation
201
  if [ ! -f ./bin/mysql_upgrade ] ; then
202
     # Has to be RPM installation
203
    cd ..
204
  fi
205
fi
206
BASEDIR=`pwd`
207
208
cd $MYSQL_TEST_DIR
209
MYSQL_TEST_WINDIR=$MYSQL_TEST_DIR
210
MYSQLTEST_VARDIR=$MYSQL_TEST_DIR/var
211
export MYSQL_TEST_DIR MYSQL_TEST_WINDIR MYSQLTEST_VARDIR
212
STD_DATA=$MYSQL_TEST_DIR/std_data
213
hostname=`hostname`		# Installed in the mysql privilege table
214
215
MANAGER_QUIET_OPT="-q"
216
TESTDIR="$MYSQL_TEST_DIR/t"
217
TESTSUFFIX=test
218
TOT_SKIP=0
219
TOT_PASS=0
220
TOT_FAIL=0
221
TOT_TEST=0
222
GOT_WARNINGS=0
223
USERT=0
224
SYST=0
225
REALT=0
226
FAST_START=""
227
MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp
228
export MYSQL_TMP_DIR
229
230
# Use a relative path for where the slave will find the dumps
231
# generated by "LOAD DATA" on the master. The path is relative
232
# since it must have fixed length to test logging
233
# i.e otherwise the output from "SHOW MASTER STATUS" will vary
234
# with the strlen() of MYSQL_TEST_DIR
235
SLAVE_LOAD_TMPDIR=../tmp
236
237
RES_SPACE="      "
238
MYSQLD_SRC_DIRS="strings mysys include extra regex myisam \
239
 myisammrg heap sql"
240
MY_LOG_DIR="$MYSQL_TEST_DIR/var/log" 
241
#
242
# Set LD_LIBRARY_PATH if we are using shared libraries
243
#
244
LD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/libmysql_r/.libs:$BASEDIR/zlib/.libs:$LD_LIBRARY_PATH"
245
DYLD_LIBRARY_PATH="$BASEDIR/lib:$BASEDIR/libmysql/.libs:$BASEDIR/libmysql_r/.libs:$BASEDIR/zlib/.libs:$DYLD_LIBRARY_PATH"
246
export LD_LIBRARY_PATH DYLD_LIBRARY_PATH
247
248
#
249
# Allow anyone in the group to see the generated database files
250
#
251
UMASK=0660
252
UMASK_DIR=0770
253
export UMASK UMASK_DIR
254
255
MASTER_RUNNING=0
256
MASTER1_RUNNING=0
257
MASTER_MYHOST=127.0.0.1
258
MASTER_MYPORT=9306
259
SLAVE_RUNNING=0
260
SLAVE_MYHOST=127.0.0.1
261
SLAVE_MYPORT=9308 # leave room for 2 masters for cluster tests
262
MYSQL_MANAGER_LOG=$MYSQL_TEST_DIR/var/log/manager.log
263
NDBCLUSTER_PORT=9350
264
NDBCLUSTER_PORT_SLAVE=9358
265
266
#
267
# To make it easier for different devs to work on the same host,
268
# an environment variable can be used to control all ports. A small
269
# number is to be used, 0 - 16 or similar.
270
#
271
# Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
272
# versions of this script, else a 4.0 test run might conflict with a
273
# 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
274
# all port numbers might not be used in this version of the script.
275
#
276
if [ -n "$MTR_BUILD_THREAD" ] ; then
277
  MASTER_MYPORT=`expr $MTR_BUILD_THREAD '*' 10 + 10000`
278
  SLAVE_MYPORT=`expr $MASTER_MYPORT + 3`
279
  NDBCLUSTER_PORT=`expr $MASTER_MYPORT + 6`
280
  NDBCLUSTER_PORT_SLAVE=`expr $MASTER_MYPORT + 7`
281
282
  echo "Using MTR_BUILD_THREAD      = $MTR_BUILD_THREAD"
283
  echo "Using MASTER_MYPORT         = $MASTER_MYPORT"
284
  echo "Using SLAVE_MYPORT          = $SLAVE_MYPORT"
285
  echo "Using NDBCLUSTER_PORT       = $NDBCLUSTER_PORT"
286
  echo "Using NDBCLUSTER_PORT_SLAVE = $NDBCLUSTER_PORT_SLAVE"
287
fi
288
289
NO_SLAVE=0
290
USER_TEST=
291
FAILED_CASES=
292
293
EXTRA_MASTER_OPT=""
294
EXTRA_MYSQL_TEST_OPT=""
295
EXTRA_MYSQLCHECK_OPT=""
296
EXTRA_MYSQLDUMP_OPT=""
297
EXTRA_MYSQLSLAP_OPT=""
298
EXTRA_MYSQLSHOW_OPT=""
299
EXTRA_MYSQLBINLOG_OPT=""
300
USE_RUNNING_SERVER=0
301
USE_NDBCLUSTER=@USE_NDBCLUSTER@
302
USE_NDBCLUSTER_SLAVE=@USE_NDBCLUSTER@
303
USE_NDBCLUSTER_ALL=0
304
USE_NDBCLUSTER_ONLY=0
305
USE_RUNNING_NDBCLUSTER=""
306
USE_RUNNING_NDBCLUSTER_SLAVE=""
307
NDB_EXTRA_TEST=0
308
NDB_VERBOSE=0
309
NDBCLUSTER_EXTRA_OPTS=""
310
USE_PURIFY=""
311
PURIFY_LOGS=""
312
DO_GCOV=""
313
DO_GDB=""
314
MANUAL_GDB=""
315
DO_DDD=""
316
DO_CLIENT_GDB=""
317
SLEEP_TIME_AFTER_RESTART=1
318
SLEEP_TIME_FOR_DELETE=10
319
SLEEP_TIME_FOR_FIRST_MASTER=400		# Enough time to create innodb tables
320
SLEEP_TIME_FOR_SECOND_MASTER=400
321
SLEEP_TIME_FOR_FIRST_SLAVE=400
322
SLEEP_TIME_FOR_SECOND_SLAVE=300
323
CHARACTER_SET=latin1
324
DBUSER=""
325
START_WAIT_TIMEOUT=10
326
STOP_WAIT_TIMEOUT=10
327
MYSQL_TEST_SSL_OPTS=""
328
USE_TIMER=""
329
USE_EMBEDDED_SERVER=""
330
TEST_MODE=""
331
332
NDB_MGM_EXTRA_OPTS=
333
NDB_MGMD_EXTRA_OPTS=
334
NDBD_EXTRA_OPTS=
335
MASTER_MYSQLDBINLOG=1
336
SLAVE_MYSQLDBINLOG=1
337
338
DO_STRESS=""
339
STRESS_SUITE="main"
340
STRESS_MODE="random"
341
STRESS_THREADS=5
342
STRESS_TEST_COUNT=""
343
STRESS_LOOP_COUNT=""
344
STRESS_TEST_DURATION=""
345
STRESS_INIT_FILE=""
346
STRESS_TEST_FILE=""
347
STRESS_TEST=""
348
349
$ECHO "Logging: $0 $*"   # To ensure we see all arguments in the output, for the test analysis tool
350
351
while test $# -gt 0; do
352
  case "$1" in
353
    --embedded-server)
354
      USE_EMBEDDED_SERVER=1
355
      USE_MANAGER=0 NO_SLAVE=1
356
      USE_RUNNING_SERVER=0
357
      USE_NDBCLUSTER=""
358
      USE_NDBCLUSTER_SLAVE=""
359
      TEST_MODE="$TEST_MODE embedded" ;;
360
    --purify)
361
      USE_PURIFY=1
362
      USE_MANAGER=0
363
      USE_RUNNING_SERVER=0
364
      TEST_MODE="$TEST_MODE purify" ;;
365
    --user=*) DBUSER=`$ECHO "$1" | $SED -e "s;--user=;;"` ;;
366
    --force)  FORCE=1 ;;
367
    --timer)  USE_TIMER=1 ;;
368
    --old-master) MASTER_40_ARGS="";;
369
    --master-binary=*)
370
      MASTER_MYSQLD=`$ECHO "$1" | $SED -e "s;--master-binary=;;"` ;;
371
    --slave-binary=*)
372
      SLAVE_MYSQLD=`$ECHO "$1" | $SED -e "s;--slave-binary=;;"` ;;
373
    --local)   USE_RUNNING_SERVER=0 ;;
374
    --extern)  USE_RUNNING_SERVER=1 ;;
375
    --with-ndbcluster)
376
      USE_NDBCLUSTER="--ndbcluster" ;;
377
    --with-ndbcluster-slave)
378
      USE_NDBCLUSTER_SLAVE="--ndbcluster" ;;
379
    --with-ndbcluster-all)
380
      USE_NDBCLUSTER="--ndbcluster"
381
      USE_NDBCLUSTER_SLAVE="--ndbcluster"
382
      USE_NDBCLUSTER_ALL=1 ;;
383
    --with-ndbcluster-only)
384
      USE_NDBCLUSTER="--ndbcluster"
385
      USE_NDBCLUSTER_SLAVE="--ndbcluster"
386
      USE_NDBCLUSTER_ONLY=1 ;;
387
    --ndb-connectstring=*)
388
      USE_NDBCLUSTER="--ndbcluster" ;
389
      USE_RUNNING_NDBCLUSTER=`$ECHO "$1" | $SED -e "s;--ndb-connectstring=;;"` ;;
390
    --ndb-connectstring-slave=*)
391
      USE_NDBCLUSTER_SLAVE="--ndbcluster" ;
392
      USE_RUNNING_NDBCLUSTER_SLAVE=`$ECHO "$1" | $SED -e "s;--ndb-connectstring-slave=;;"` ;;
393
    --ndb-extra-test)
394
      NDBCLUSTER_EXTRA_OPTS=" "
395
      NDB_EXTRA_TEST=1 ;
396
      ;;
397
    --ndb-verbose)
398
      NDB_VERBOSE=2 ;;
399
    --ndb_mgm-extra-opts=*)
400
      NDB_MGM_EXTRA_OPTS=`$ECHO "$1" | $SED -e "s;--ndb_mgm-extra-opts=;;"` ;;
401
    --ndb_mgmd-extra-opts=*)
402
      NDB_MGMD_EXTRA_OPTS=`$ECHO "$1" | $SED -e "s;--ndb_mgmd-extra-opts=;;"` ;;
403
    --ndbd-extra-opts=*)
404
      NDBD_EXTRA_OPTS=`$ECHO "$1" | $SED -e "s;--ndbd-extra-opts=;;"` ;;
405
    --tmpdir=*) MYSQL_TMP_DIR=`$ECHO "$1" | $SED -e "s;--tmpdir=;;"` ;;
406
    --local-master)
407
      MASTER_MYPORT=3306;
408
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --host=127.0.0.1 \
409
      --port=$MYSQL_MYPORT"
410
      LOCAL_MASTER=1 ;;
411
    --master_port=*) MASTER_MYPORT=`$ECHO "$1" | $SED -e "s;--master_port=;;"` ;;
412
    --slave_port=*) SLAVE_MYPORT=`$ECHO "$1" | $SED -e "s;--slave_port=;;"` ;;
413
    --ndbcluster_port=*) NDBCLUSTER_PORT=`$ECHO "$1" | $SED -e "s;--ndbcluster_port=;;"` ;;
414
    --ndbcluster-port=*) NDBCLUSTER_PORT=`$ECHO "$1" | $SED -e "s;--ndbcluster-port=;;"` ;;
415
    --ndbcluster-port-slave=*) NDBCLUSTER_PORT_SLAVE=`$ECHO "$1" | $SED -e "s;--ndbcluster-port-slave=;;"` ;;
416
    --with-openssl)
417
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT \
418
     --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem \
419
     --ssl-cert=$MYSQL_TEST_DIR/std_data/server-cert.pem \
420
     --ssl-key=$MYSQL_TEST_DIR/std_data/server-key.pem"
421
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
422
     --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem \
423
     --ssl-cert=$MYSQL_TEST_DIR/std_data/server-cert.pem \
424
     --ssl-key=$MYSQL_TEST_DIR/std_data/server-key.pem"
425
     MYSQL_TEST_SSL_OPTS="--ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem \
426
     --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem \
427
     --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem" ;;
428
    --start-and-exit)
429
     START_AND_EXIT=1
430
     ;;
431
    --skip-rpl) NO_SLAVE=1 ;;
432
    --skip-test=*) SKIP_TEST=`$ECHO "$1" | $SED -e "s;--skip-test=;;"`;;
433
    --do-test=*) DO_TEST=`$ECHO "$1" | $SED -e "s;--do-test=;;"`;;
434
    --start-from=* ) START_FROM=`$ECHO "$1" | $SED -e "s;--start-from=;;"` ;;
435
    --warnings | --log-warnings)
436
     EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --log-warnings"
437
     EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --log-warnings"
438
     ;;
439
    --wait-timeout=*)
440
     START_WAIT_TIMEOUT=`$ECHO "$1" | $SED -e "s;--wait-timeout=;;"`
441
     STOP_WAIT_TIMEOUT=$START_WAIT_TIMEOUT;;
442
    --record)
443
      RECORD=1;
444
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
445
    --small-bench)
446
      DO_SMALL_BENCH=1
447
      DO_BENCH=1
448
      NO_SLAVE=1
449
      ;;
450
    --bench)
451
      DO_BENCH=1
452
      NO_SLAVE=1
453
      ;;
454
    --stress)
455
      DO_STRESS=1
456
      NO_SLAVE=1
457
      SKIP_SLAVE=1
458
      ;;
459
    --stress-suite=*)
460
      STRESS_SUITE=`$ECHO "$1" | $SED -e "s;--stress-suite=;;"`
461
      ;;
462
    --stress-threads=*)
463
      STRESS_THREADS=`$ECHO "$1" | $SED -e "s;--stress-threads=;;"`
464
      ;;
465
    --stress-test-file=*)
466
      STRESS_TEST_FILE=`$ECHO "$1" | $SED -e "s;--stress-test-file=;;"`
467
      ;;
468
    --stress-init-file=*)
469
      STRESS_INIT_FILE=`$ECHO "$1" | $SED -e "s;--stress-init-file=;;"`
470
      ;; 
471
    --stress-mode=*)
472
      STRESS_MODE=`$ECHO "$1" | $SED -e "s;--stress-mode=;;"`
473
      ;;
474
    --stress-loop-count=*)
475
      STRESS_LOOP_COUNT=`$ECHO "$1" | $SED -e "s;--stress-loop-count=;;"`
476
      ;;
477
    --stress-test-count=*)
478
      STRESS_TEST_COUNT=`$ECHO "$1" | $SED -e "s;--stress-test-count=;;"`
479
      ;;      
480
    --stress-test-duration=*)
481
      STRESS_TEST_DURATION=`$ECHO "$1" | $SED -e "s;--stress-test-duration=;;"`
482
      ;;
483
    --big*)			# Actually --big-test
484
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
485
    --compress)
486
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
487
    --sleep=*)
488
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1"
489
      SLEEP_TIME_AFTER_RESTART=`$ECHO "$1" | $SED -e "s;--sleep=;;"`
490
      ;;
491
    --ps-protocol)
492
      TEST_MODE="$TEST_MODE ps-protocol" EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT $1" ;;
493
    --user-test=*)
494
      USER_TEST=`$ECHO "$1" | $SED -e "s;--user-test=;;"`
495
      ;;
496
    --mysqld=*)
497
       TMP=`$ECHO "$1" | $SED -e "s;--mysqld=;;"`
498
       EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $TMP"
499
       EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $TMP"
500
       ;;
501
    --gcov )
502
      if [ x$BINARY_DIST = x1 ] ; then
503
	$ECHO "Cannot do coverage test without the source - please use source dist"
504
	exit 1
505
      fi
506
      DO_GCOV=1
507
      GCOV=`which gcov`
508
      ;;
509
    --gprof )
510
      DO_GPROF=1
511
      ;;
512
    --gdb )
513
      START_WAIT_TIMEOUT=300
514
      STOP_WAIT_TIMEOUT=300
515
      if [ x$BINARY_DIST = x1 ] ; then
516
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --gdb option"
517
      fi
518
      DO_GDB=1
519
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
520
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
521
      # This needs to be checked properly
522
      # USE_MANAGER=1
523
      USE_RUNNING_SERVER=0
524
      ;;
525
    --client-gdb )
526
      if [ x$BINARY_DIST = x1 ] ; then
527
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --client-gdb option"
528
      fi
529
      DO_CLIENT_GDB=1
530
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
531
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
532
      ;;
533
    --manual-gdb )
534
      DO_GDB=1
535
      MANUAL_GDB=1
536
      USE_RUNNING_SERVER=0
537
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
538
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
539
      ;;
540
    --ddd )
541
      if [ x$BINARY_DIST = x1 ] ; then
542
	$ECHO "Note: you will get more meaningful output on a source distribution compiled with debugging option when running tests with --ddd option"
543
      fi
544
      DO_DDD=1
545
      USE_RUNNING_SERVER=0
546
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --gdb"
547
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb"
548
      ;;
549
    --valgrind | --valgrind-all)
550
      find_valgrind;
551
      VALGRIND=$FIND_VALGRIND
552
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc"
553
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-safemalloc"
554
      SLEEP_TIME_AFTER_RESTART=10
555
      SLEEP_TIME_FOR_DELETE=60
556
      USE_RUNNING_SERVER=0
557
      if test "$1" = "--valgrind-all"
558
      then
559
        VALGRIND="$VALGRIND -v --show-reachable=yes"
560
      fi
561
      ;;
562
    --valgrind-options=*)
563
      TMP=`$ECHO "$1" | $SED -e "s;--valgrind-options=;;"`
564
      VALGRIND="$VALGRIND $TMP"
565
      ;;
566
    --skip-ndbcluster-slave | --skip-ndb-slave)
567
      USE_NDBCLUSTER_SLAVE=""
568
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-ndbcluster"
569
      ;;
570
    --valgrind-mysqltest | --valgrind-mysqltest-all)
571
      find_valgrind;
572
      VALGRIND_MYSQLTEST=$FIND_VALGRIND
573
      if test "$1" = "--valgrind-mysqltest-all"
574
      then
575
        VALGRIND_MYSQLTEST="$VALGRIND_MYSQLTEST -v --show-reachable=yes"
576
      fi
577
      ;;
578
    --skip-ndbcluster | --skip-ndb)
579
      USE_NDBCLUSTER=""
580
      USE_NDBCLUSTER_SLAVE=""
581
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-ndbcluster"
582
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-ndbcluster"
583
      ;;
584
    --skip-master-binlog) MASTER_MYSQLDBINLOG=0 ;;
585
    --skip-slave-binlog) SLAVE_MYSQLDBINLOG=0 ;;
586
    --skip-*)
587
      EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT $1"
588
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT $1"
589
      ;;
590
    --strace-client )
591
      STRACE_CLIENT=1
592
      ;;
593
    --debug)
594
      EXTRA_MASTER_MYSQLD_TRACE=" \
595
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/master.trace"
596
      EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT \
597
       --debug=d:t:i:A,$MYSQL_TEST_DIR/var/log/slave.trace"
598
      EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT \
599
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqltest.trace"
600
      EXTRA_MYSQLCHECK_OPT="$EXTRA_MYSQLCHECK_OPT \
601
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlcheck.trace"
602
      EXTRA_MYSQLDUMP_OPT="$EXTRA_MYSQLDUMP_OPT \
603
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqldump.trace"
604
      EXTRA_MYSQLSLAP_OPT="$EXTRA_MYSQLSLAP_OPT \
605
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlslap.trace"
606
      EXTRA_MYSQLSHOW_OPT="$EXTRA_MYSQLSHOW_OPT \
607
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlshow.trace"
608
      EXTRA_MYSQLBINLOG_OPT="$EXTRA_MYSQLBINLOG_OPT \
609
       --debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysqlbinlog.trace"
610
      EXTRA_MYSQL_CLIENT_TEST_OPT="--debug=d:t:A,$MYSQL_TEST_DIR/var/log/mysql_client_test.trace"
611
      ;;
612
    --fast)
613
      FAST_START=1
614
      ;;
615
    --use-old-data)
616
      USE_OLD_DATA=1
617
      ;;
618
    --comment=*)
619
      TMP=`$ECHO "$1" | $SED -e "s;--comment=;;"`
620
      echo
621
      echo '############################################'
622
      echo "# $TMP"
623
      echo '############################################'
624
      ;;
625
    -- )  shift; break ;;
626
    --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
627
    * ) break ;;
628
  esac
629
  shift
630
done
631
632
if [ -z "$TEST_MODE" ] ; then
633
  TEST_MODE="default"
634
else
635
  # Remove the leading space if any
636
  TEST_MODE=`echo $TEST_MODE | sed 's/^ *//'`
637
fi
638
639
#
640
# Skip tests that doesn't work with shell version
641
#
642
SKIP_TEST="$SKIP_TEST bootstrap"
643
644
#++
645
# mysqld Environment Parameters
646
#--
647
648
MYRUN_DIR=$MYSQL_TEST_DIR/var/run
649
650
MASTER_MYDDIR="$MYSQL_TEST_DIR/var/master-data"
651
MASTER_MYSOCK="$MYSQL_TMP_DIR/master.sock"
652
MASTER_MYSOCK1=$MYSQL_MYSOCK"1"
653
MASTER_MYPID="$MYRUN_DIR/master.pid"
654
MASTER_MYLOG="$MYSQL_TEST_DIR/var/log/master.log"
655
MASTER_MYERR="$MYSQL_TEST_DIR/var/log/master.err"
656
657
SLAVE_MYDDIR="$MYSQL_TEST_DIR/var/slave-data"
658
SLAVE_MYSOCK="$MYSQL_TMP_DIR/slave.sock"
659
SLAVE_MYPID="$MYRUN_DIR/slave.pid"
660
SLAVE_MYLOG="$MYSQL_TEST_DIR/var/log/slave.log"
661
SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/slave.err"
662
663
CURRENT_TEST="$MYSQL_TEST_DIR/var/log/current_test"
664
SMALL_SERVER="--key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M"
665
666
export MASTER_MYHOST MASTER_MYPORT SLAVE_MYHOST SLAVE_MYPORT MYSQL_TCP_PORT MASTER_MYSOCK MASTER_MYSOCK1
667
668
NDBCLUSTER_OPTS="--port=$NDBCLUSTER_PORT --data-dir=$MYSQL_TEST_DIR/var --ndb_mgm-extra-opts=$NDB_MGM_EXTRA_OPTS --ndb_mgmd-extra-opts=$NDB_MGMD_EXTRA_OPTS --ndbd-extra-opts=$NDBD_EXTRA_OPTS"
669
NDBCLUSTER_OPTS_SLAVE="--port=$NDBCLUSTER_PORT_SLAVE --data-dir=$MYSQL_TEST_DIR/var"
670
if [ -n "$USE_NDBCLUSTER_SLAVE" ] ; then
671
  USE_NDBCLUSTER_SLAVE="$USE_NDBCLUSTER_SLAVE --ndb-connectstring=localhost:$NDBCLUSTER_PORT_SLAVE --ndb-extra-logging"
672
fi
673
NDB_BACKUP_DIR=$MYSQL_TEST_DIR/var/ndbcluster-$NDBCLUSTER_PORT
674
NDB_TOOLS_OUTPUT=$MYSQL_TEST_DIR/var/log/ndb_tools.log
675
676
if [ x$SOURCE_DIST = x1 ] ; then
677
 MY_BASEDIR=$MYSQL_TEST_DIR
678
else
679
 MY_BASEDIR=$BASEDIR
680
fi
681
682
# Create the directories
683
684
# This should be fixed to be not be dependent on the contence of MYSQL_TMP_DIR
685
# or MYRUN_DIR
686
# (mkdir -p is not portable)
687
[ -d $MYSQL_TEST_DIR/var ] || mkdir $MYSQL_TEST_DIR/var
688
[ -d $MYSQL_TEST_DIR/var/tmp ] || mkdir $MYSQL_TEST_DIR/var/tmp
689
[ -d $MYSQL_TEST_DIR/var/run ] || mkdir $MYSQL_TEST_DIR/var/run
690
[ -d $MYSQL_TEST_DIR/var/log ] || mkdir $MYSQL_TEST_DIR/var/log
691
692
# Use 'test', not '[' as the shell builtin might not have '-L
693
if test ! -L "$MYSQL_TEST_DIR/var/std_data_ln" ; then
694
  ln -s $MYSQL_TEST_DIR/std_data/ $MYSQL_TEST_DIR/var/std_data_ln
695
fi
696
697
if test ${COLUMNS:-0} -lt 80 ; then COLUMNS=80 ; fi
698
E=`$EXPR $COLUMNS - 8`
699
DASH72=`$ECHO '-------------------------------------------------------'|$CUT -c 1-$E`
700
701
# on source dist, we pick up freshly build executables
702
# on binary, use what is installed
703
if [ x$SOURCE_DIST = x1 ] ; then
704
 if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
705
   if [ -f "$BASEDIR/libmysqld/examples/mysqltest_embedded" ] ; then
706
     MYSQL_TEST="$BASEDIR/libmysqld/examples/mysqltest_embedded"
707
   else
708
     echo "Fatal error: Cannot find embedded server 'mysqltest_embedded'" 1>&2
709
     exit 1
710
   fi
711
   MYSQL_CLIENT_TEST="$BASEDIR/libmysqld/examples/mysql_client_test_embedded"
712
 else
713
   MYSQLD="$BASEDIR/sql/mysqld"
714
   if [ -n "$VALGRIND" ] ; then
715
     MYSQLD="$VALGRIND $MYSQLD"
716
   fi
717
   if [ -f "$BASEDIR/client/.libs/lt-mysqltest" ] ; then
718
     MYSQL_TEST="$BASEDIR/client/.libs/lt-mysqltest"
719
   elif [ -f "$BASEDIR/client/.libs/mysqltest" ] ; then
720
     MYSQL_TEST="$BASEDIR/client/.libs/mysqltest"
721
   else
722
     MYSQL_TEST="$BASEDIR/client/mysqltest"
723
   fi
724
   MYSQL_CLIENT_TEST="$BASEDIR/tests/mysql_client_test"
725
 fi
726
 if [ -f "$BASEDIR/client/.libs/mysqlcheck" ] ; then
727
   MYSQL_CHECK="$BASEDIR/client/.libs/mysqlcheck"
728
 else
729
   MYSQL_CHECK="$BASEDIR/client/mysqlcheck"
730
 fi
731
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
732
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
733
 else
734
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
735
 fi
736
 if [ -f "$BASEDIR/client/.libs/mysqlslap" ] ; then
737
   MYSQL_SLAP="$BASEDIR/client/.libs/mysqlslap"
738
 else
739
   MYSQL_SLAP="$BASEDIR/client/mysqlslap"
740
 fi
741
 if [ -f "$BASEDIR/client/.libs/mysqlimport" ] ; then
742
   MYSQL_IMPORT="$BASEDIR/client/.libs/mysqlimport"
743
 else
744
   MYSQL_IMPORT="$BASEDIR/client/mysqlimport"
745
 fi
746
 if [ -f "$BASEDIR/client/.libs/mysqlshow" ] ; then
747
   MYSQL_SHOW="$BASEDIR/client/.libs/mysqlshow"
748
 else
749
   MYSQL_SHOW="$BASEDIR/client/mysqlshow"
750
 fi
751
 if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then
752
   MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog"
753
 else
754
   MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog"
755
 fi
756
 if [ -n "$STRACE_CLIENT" ]; then
757
  MYSQL_TEST="strace -o $MYSQL_TEST_DIR/var/log/mysqltest.strace $MYSQL_TEST"
758
 fi
759
760
 CLIENT_BINDIR="$BASEDIR/client"
761
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
762
 WAIT_PID="$BASEDIR/extra/mysql_waitpid"
763
 MYSQL_MY_PRINT_DEFAULTS="$BASEDIR/extra/my_print_defaults"
764
 MYSQL="$CLIENT_BINDIR/mysql"
765
 LANGUAGE="$BASEDIR/sql/share/english/"
766
 CHARSETSDIR="$BASEDIR/sql/share/charsets"
767
 INSTALL_DB="./install_test_db"
768
 MYSQL_FIX_SYSTEM_TABLES="$BASEDIR/scripts/mysql_fix_privilege_tables"
769
 NDB_TOOLS_DIR="$BASEDIR/storage/ndb/tools"
770
 NDB_MGM="$BASEDIR/storage/ndb/src/mgmclient/ndb_mgm"
771
772
 if [ -n "$USE_PURIFY" ] ; then
773
   PSUP="$MYSQL_TEST_DIR/suppress.purify"
774
   PURIFYOPTIONS="-windows=no -log-file=%v.purifylog -append-logfile -add-suppression-files=$PSUP"
775
   if [ -f "${MYSQL_TEST}-purify" ] ; then
776
     MYSQL_TEST="${MYSQL_TEST}-purify"
777
     PLOG="$MYSQL_TEST.purifylog"
778
     if [ -f $PLOG ]; then
779
       mv $PLOG $PLOG.$$
780
     fi
781
     PURIFY_LOGS="$PLOG"
782
   fi
783
   if [ -f "${MYSQLD}-purify" ] ; then
784
     MYSQLD="${MYSQLD}-purify"
785
     PLOG="$MYSQLD.purifylog"
786
     if [ -f $PLOG ]; then
787
       mv $PLOG $PLOG.$$
788
     fi
789
     PURIFY_LOGS="$PURIFY_LOGS $PLOG"
790
   fi
791
 fi
792
793
else
794
795
 # We have a binary installation. Note that this can be both from
796
 # unpacking a MySQL AB binary distribution (created using
797
 # "scripts/make_binary_distribution", and from a "make install".
798
 # Unfortunately the structure differs a bit, for a "make install"
799
 # currently all binaries are in "bin", for a MySQL AB packaging
800
 # some are in "tests".
801
802
 if test -x "$BASEDIR/libexec/mysqld"
803
 then
804
   MYSQLD="$VALGRIND $BASEDIR/libexec/mysqld"
805
 elif test -x "$BASEDIR/bin/mysqld"
806
 then
807
   MYSQLD="$VALGRIND $BASEDIR/bin/mysqld"
808
 elif test -x "$BASEDIR/sbin/mysqld"
809
 then
810
   MYSQLD="$VALGRIND $BASEDIR/sbin/mysqld"
811
 else
812
   $ECHO "Fatal error: Cannot find program mysqld in $BASEDIR/{libexec,bin,sbin}" 1>&2
813
   exit 1
814
 fi
815
 CLIENT_BINDIR="$BASEDIR/bin"
816
 if test -d "$BASEDIR/tests"
817
 then
818
   TESTS_BINDIR="$BASEDIR/tests"
819
 else
820
   TESTS_BINDIR="$BASEDIR/bin"
821
 fi
822
 MYSQL_TEST="$CLIENT_BINDIR/mysqltest"
823
 MYSQL_CHECK="$CLIENT_BINDIR/mysqlcheck"
824
 MYSQL_SLAP="$CLIENT_BINDIR/mysqlslap"
825
 MYSQL_SHOW="$CLIENT_BINDIR/mysqlshow"
826
 MYSQL_IMPORT="$CLIENT_BINDIR/mysqlimport"
827
 MYSQL_BINLOG="$CLIENT_BINDIR/mysqlbinlog"
828
 MYSQLADMIN="$CLIENT_BINDIR/mysqladmin"
829
 WAIT_PID="$CLIENT_BINDIR/mysql_waitpid"
830
 MYSQL_MY_PRINT_DEFAULTS="$CLIENT_BINDIR/my_print_defaults"
831
 MYSQL="$CLIENT_BINDIR/mysql"
832
 INSTALL_DB="./install_test_db --bin"
833
 MYSQL_FIX_SYSTEM_TABLES="$CLIENT_BINDIR/mysql_fix_privilege_tables"
834
 NDB_TOOLS_DIR="$CLIENT_BINDIR"
835
 NDB_MGM="$CLIENT_BINDIR/ndb_mgm"
836
 if test -d "$BASEDIR/share/mysql/english"
837
 then
838
   LANGUAGE="$BASEDIR/share/mysql/english/"
839
   CHARSETSDIR="$BASEDIR/share/mysql/charsets"
840
 else
841
   LANGUAGE="$BASEDIR/share/english/"
842
   CHARSETSDIR="$BASEDIR/share/charsets"
843
 fi
844
 if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
845
   if [ -f "$CLIENT_BINDIR/mysqltest_embedded" ] ; then
846
     MYSQL_TEST="$CLIENT_BINDIR/mysqltest_embedded"
847
   else
848
     echo "Fatal error: Cannot find embedded server 'mysqltest_embedded'" 1>&2
849
     exit 1
850
   fi
851
   if [ -d "$BASEDIR/tests/mysql_client_test_embedded" ] ; then
852
     MYSQL_CLIENT_TEST="$TESTS_BINDIR/mysql_client_test_embedded"
853
   else
854
     MYSQL_CLIENT_TEST="$CLIENT_BINDIR/mysql_client_test_embedded"
855
   fi
856
 else
857
   MYSQL_TEST="$CLIENT_BINDIR/mysqltest"
858
   MYSQL_CLIENT_TEST="$CLIENT_BINDIR/mysql_client_test"
859
 fi
860
 if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
861
   MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
862
 elif  [ -f "$BASEDIR/client/mysqldump" ] ; then
863
   MYSQL_DUMP="$BASEDIR/client/mysqldump"
864
 else
865
   MYSQL_DUMP="$BASEDIR/bin/mysqldump"
866
 fi
867
fi
868
869
if [ -z "$MASTER_MYSQLD" ]
870
then
871
MASTER_MYSQLD=$MYSQLD
872
fi
873
874
if [ -z "$SLAVE_MYSQLD" ]
875
then
876
SLAVE_MYSQLD=$MYSQLD
877
fi
878
879
# If we should run all tests cases, we will use a local server for that
880
881
if [ -z "$1" -a -z "$DO_STRESS" ]
882
then
883
   USE_RUNNING_SERVER=0
884
fi
885
if [ $USE_RUNNING_SERVER -eq 1 ]
886
then
887
   DBUSER=${DBUSER:-test}
888
else
889
   DBUSER=${DBUSER:-root}		# We want to do FLUSH xxx commands
890
fi
891
892
if [ -w / ]
893
then
894
  # We are running as root;  We need to add the --root argument
895
  EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --user=root"
896
  EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --user=root"
897
fi
898
899
MYSQL_CLIENT_TEST="$MYSQL_CLIENT_TEST --no-defaults --testcase --user=root --socket=$MASTER_MYSOCK --port=$MYSQL_TCP_PORT --silent $EXTRA_MYSQL_CLIENT_TEST_OPT"
900
# Need to pass additional arguments to MYSQL_CLIENT_TEST for embedded server
901
# -A marks each argument for passing to the function which initializes the
902
# embedded library
903
if [ "x$USE_EMBEDDED_SERVER" = "x1" ]; then
904
  MYSQL_CLIENT_TEST="$MYSQL_CLIENT_TEST -A --language=$LANGUAGE -A --datadir=$SLAVE_MYDDIR -A --character-sets-dir=$CHARSETSDIR"
905
fi
906
# Save path and name of mysqldump
907
MYSQL_DUMP_DIR="$MYSQL_DUMP"
908
export MYSQL_DUMP_DIR
909
MYSQL_CHECK="$MYSQL_CHECK --no-defaults --debug-info -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLCHECK_OPT"
910
MYSQL_DUMP="$MYSQL_DUMP --no-defaults --debug-info -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
911
MYSQL_SLAP="$MYSQL_SLAP -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLSLAP_OPT"
912
MYSQL_DUMP_SLAVE="$MYSQL_DUMP_DIR --no-defaults -uroot --socket=$SLAVE_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
913
MYSQL_SHOW="$MYSQL_SHOW --no-defaults --debug-info -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLSHOW_OPT"
914
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --debug-info --local-load=$MYSQL_TMP_DIR  --character-sets-dir=$CHARSETSDIR $EXTRA_MYSQLBINLOG_OPT"
915
MYSQL_IMPORT="$MYSQL_IMPORT --no-defaults --debug-info -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD $EXTRA_MYSQLDUMP_OPT"
916
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"
917
MYSQL="$MYSQL --no-defaults --debug-info --host=localhost --port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD"
918
export MYSQL MYSQL_CHECK MYSQL_DUMP MYSQL_DUMP_SLAVE MYSQL_SHOW MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES MYSQL_IMPORT
919
export CLIENT_BINDIR MYSQL_CLIENT_TEST CHARSETSDIR MYSQL_MY_PRINT_DEFAULTS
920
export MYSQL_SLAP
921
export NDB_TOOLS_DIR
922
export NDB_MGM
923
export NDB_BACKUP_DIR
924
export NDB_TOOLS_OUTPUT
925
export PURIFYOPTIONS
926
NDB_STATUS_OK=1
927
export NDB_STATUS_OK
928
NDB_SLAVE_STATUS_OK=1
929
export NDB_SLAVE_STATUS_OK
930
export NDB_EXTRA_TEST NDBCLUSTER_PORT NDBCLUSTER_PORT_SLAVE
931
932
MYSQL_TEST_ARGS="--no-defaults --socket=$MASTER_MYSOCK --database=$DB \
933
 --user=$DBUSER --password=$DBPASSWD --silent -v --skip-safemalloc \
934
 --tmpdir=$MYSQL_TMP_DIR --port=$MASTER_MYPORT $MYSQL_TEST_SSL_OPTS"
935
if [ x$USE_TIMER = x1 ] ; then
936
  MYSQL_TEST_ARGS="$MYSQL_TEST_ARGS --timer-file=$MY_LOG_DIR/timer"
937
fi
938
MYSQL_TEST_BIN=$MYSQL_TEST
939
MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS"
940
941
# Export MYSQL_TEST variable for use from .test files
942
export MYSQL_TEST
943
944
GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client
945
GDB_MASTER_INIT=$MYSQL_TMP_DIR/gdbinit.master
946
GDB_SLAVE_INIT=$MYSQL_TMP_DIR/gdbinit.slave
947
GCOV_MSG=$MYSQL_TMP_DIR/mysqld-gcov.out
948
GCOV_ERR=$MYSQL_TMP_DIR/mysqld-gcov.err
949
GPROF_DIR=$MYSQL_TMP_DIR/gprof
950
GPROF_MASTER=$GPROF_DIR/master.gprof
951
GPROF_SLAVE=$GPROF_DIR/slave.gprof
952
TIMEFILE="$MYSQL_TEST_DIR/var/log/mysqltest-time"
953
MYSQLTEST_LOG="$MYSQL_TEST_DIR/var/log/mysqltest.log"
954
if [ -n "$DO_CLIENT_GDB" -o -n "$DO_GDB" ] ; then
955
  XTERM=`which xterm`
956
fi
957
958
export MYSQL MYSQL_CHECK MYSQL_DUMP MYSQL_SHOW MYSQL_BINLOG MYSQL_FIX_SYSTEM_TABLES CLIENT_BINDIR MASTER_MYSOCK
959
960
#++
961
# Function Definitions
962
#--
963
964
prompt_user ()
965
{
966
 $ECHO $1
967
 read unused
968
}
969
970
# We can't use diff -u or diff -a as these are not portable
971
972
show_failed_diff ()
973
{
974
  reject_file=r/$1.reject
975
  result_file=r/$1.result
976
  eval_file=r/$1.eval
977
978
  if [ -f $eval_file ]
979
  then
980
    result_file=$eval_file
981
  fi
982
983
  if [ -x "$DIFF" ] && [ -f $reject_file ]
984
  then
985
    echo "Below are the diffs between actual and expected results:"
986
    echo "-------------------------------------------------------"
987
    $DIFF -c $result_file $reject_file
988
    echo "-------------------------------------------------------"
989
    echo "Please follow the instructions outlined at"
990
    echo "http://forge.mysql.com/wiki/MySQL_Internals_Porting#Debugging_a_MySQL_Server"
991
    echo "to find the reason to this problem and how to report this."
992
    echo ""
993
  fi
994
}
995
996
do_gdb_test ()
997
{
998
  mysql_test_args="$MYSQL_TEST_ARGS $1"
999
  $ECHO "set args $mysql_test_args < $2" > $GDB_CLIENT_INIT
1000
  echo "Set breakpoints ( if needed) and type 'run' in gdb window"
1001
  #this xterm should not be backgrounded
1002
  $XTERM -title "Client" -e gdb -x $GDB_CLIENT_INIT $MYSQL_TEST_BIN
1003
}
1004
1005
error () {
1006
    $ECHO  "Error:  $1"
1007
    exit 1
1008
}
1009
1010
error_is () {
1011
    $ECHO "Errors are (from $TIMEFILE) :"
1012
    $CAT < $TIMEFILE
1013
    $ECHO "(the last lines may be the most important ones)"
1014
}
1015
1016
prefix_to_8() {
1017
 $ECHO "        $1" | $SED -e 's:.*\(........\)$:\1:'
1018
}
1019
1020
pass_inc () {
1021
    TOT_PASS=`$EXPR $TOT_PASS + 1`
1022
}
1023
1024
fail_inc () {
1025
    TOT_FAIL=`$EXPR $TOT_FAIL + 1`
1026
}
1027
1028
skip_inc () {
1029
    TOT_SKIP=`$EXPR $TOT_SKIP + 1`
1030
}
1031
1032
total_inc () {
1033
    TOT_TEST=`$EXPR $TOT_TEST + 1`
1034
}
1035
1036
1037
skip_test() {
1038
   USERT="    ...."
1039
   SYST="    ...."
1040
   REALT="    ...."
1041
   pname=`$ECHO "$1                        "|$CUT -c 1-24`
1042
   RES="$pname"
1043
   skip_inc
1044
   $ECHO "$RES$RES_SPACE [ skipped ]"
1045
}
1046
1047
1048
disable_test() {
1049
   USERT="    ...."
1050
   SYST="    ...."
1051
   REALT="    ...."
1052
   pname=`$ECHO "$1                        "|$CUT -c 1-24`
1053
   RES="$pname"
1054
   skip_inc
1055
   $ECHO "$RES$RES_SPACE [ disabled ]  $2"
1056
}
1057
1058
1059
report_current_test () {
1060
   tname=$1
1061
   echo "CURRENT_TEST: $tname" >> $MASTER_MYERR
1062
   eval "master1_running=\$MASTER1_RUNNING"
1063
   if [ x$master1_running = x1 ] ; then
1064
     echo "CURRENT_TEST: $tname" >> $MASTER_MYERR"1"
1065
   fi
1066
   if [ -n "$PURIFY_LOGS" ] ; then
1067
     for log in $PURIFY_LOGS
1068
     do
1069
       echo "CURRENT_TEST: $tname" >> $log
1070
     done
1071
   fi
1072
}
1073
1074
1075
report_stats () {
1076
    if [ $TOT_FAIL = 0 ]; then
1077
	$ECHO "All $TOT_TEST tests were successful."
1078
    else
1079
	xten=`$EXPR $TOT_PASS \* 10000`
1080
	raw=`$EXPR $xten / $TOT_TEST`
1081
	raw=`$PRINTF %.4d $raw`
1082
	whole=`$PRINTF %.2s $raw`
1083
	xwhole=`$EXPR $whole \* 100`
1084
	deci=`$EXPR $raw - $xwhole`
1085
	$ECHO  "Failed ${TOT_FAIL}/${TOT_TEST} tests, ${whole}.${deci}% were successful."
1086
	$ECHO ""
1087
        $ECHO "The log files in $MY_LOG_DIR may give you some hint"
1088
	$ECHO "of what went wrong."
1089
	$ECHO "If you want to report this error, please read first the documentation at"
1090
        $ECHO "http://dev.mysql.com/doc/mysql/en/mysql-test-suite.html"
1091
    fi
1092
1093
    if [ $USE_RUNNING_SERVER -eq 0 ]
1094
    then
1095
1096
    # Report if there was any fatal warnings/errors in the log files
1097
    #
1098
    $RM -f $MY_LOG_DIR/warnings $MY_LOG_DIR/warnings.tmp
1099
    # Remove some non fatal warnings from the log files
1100
    $SED -e 's!Warning:  Table:.* on delete!!g' -e 's!Warning: Setting lower_case_table_names=2!!g' -e 's!Warning: One can only use the --user.*root!!g' -e 's|InnoDB: Warning: we did not need to do crash recovery||g' \
1101
        $MY_LOG_DIR/*.err \
1102
        | $SED -e 's!Warning:  Table:.* on rename!!g' \
1103
        > $MY_LOG_DIR/warnings.tmp
1104
1105
    # Find errors
1106
    for i in "^Warning:" "^Error:" "^==.* at 0x" "InnoDB: Warning" "missing DBUG_RETURN" "mysqld: Warning" "Attempting backtrace" "Assertion .* failed"
1107
    do
1108
      if $GREP "$i" $MY_LOG_DIR/warnings.tmp >> $MY_LOG_DIR/warnings
1109
      then
1110
        GOT_WARNINGS=1
1111
      fi
1112
    done
1113
    $RM -f $MY_LOG_DIR/warnings.tmp
1114
    if [ $GOT_WARNINGS = "1" ]
1115
    then
1116
      echo "WARNING: Got errors/warnings while running tests. Please examine"
1117
      echo "$MY_LOG_DIR/warnings for details."
1118
    fi
1119
1120
    fi # USE_RUNNING_SERVER
1121
1122
    # Check valgrind errors from mysqltest
1123
    if [ ! -z "$VALGRIND_MYSQLTEST" ]
1124
    then
1125
      if $GREP "ERROR SUMMARY" $MYSQLTEST_LOG | $GREP -v "0 errors" > /dev/null
1126
      then
1127
	  $ECHO "Valgrind detected errors!"
1128
	  $GREP "ERROR SUMMARY" $MYSQLTEST_LOG | $GREP -v "0 errors"
1129
	  $ECHO "See $MYSQLTEST_LOG"
1130
      fi
1131
    fi
1132
}
1133
1134
mysql_install_db () {
1135
    $ECHO "Removing Stale Files"
1136
    if [ -z "$USE_OLD_DATA" ]; then
1137
      $RM -rf $MASTER_MYDDIR $MASTER_MYDDIR"1"
1138
      $ECHO "Installing Master Databases"
1139
      $INSTALL_DB
1140
      if [ $? != 0 ]; then
1141
	error "Could not install master test DBs"
1142
        exit 1
1143
      fi
1144
    fi
1145
    if [ ! -z "$USE_NDBCLUSTER" ]
1146
    then
1147
      $ECHO "Installing Master Databases 1"
1148
#     $INSTALL_DB -1
1149
      $RM -rf var/master-data1
1150
      mkdir var/master-data1
1151
      cp -r var/master-data/* var/master-data1
1152
      if [ $? != 0 ]; then
1153
	error "Could not install master test DBs 1"
1154
	exit 1
1155
      fi
1156
    fi
1157
    $ECHO "Installing Slave Databases"
1158
    $RM -rf $SLAVE_MYDDIR $MY_LOG_DIR/* 
1159
#    $INSTALL_DB -slave
1160
    mkdir var/slave-data
1161
    cp -r var/master-data/* var/slave-data
1162
    if [ $? != 0 ]; then
1163
	error "Could not install slave test DBs"
1164
	exit 1
1165
    fi
1166
1167
    for slave_num in 1 2 ;
1168
    do
1169
      $RM -rf var/slave$slave_num-data
1170
      mkdir -p var/slave$slave_num-data/mysql
1171
      mkdir -p var/slave$slave_num-data/test
1172
      cp var/slave-data/mysql/* var/slave$slave_num-data/mysql
1173
    done
1174
    return 0
1175
}
1176
1177
gprof_prepare ()
1178
{
1179
 $RM -rf $GPROF_DIR
1180
 mkdir -p $GPROF_DIR
1181
}
1182
1183
gprof_collect ()
1184
{
1185
 if [ -f $MASTER_MYDDIR/gmon.out ]; then
1186
   gprof $MASTER_MYSQLD $MASTER_MYDDIR/gmon.out > $GPROF_MASTER
1187
   echo "Master execution profile has been saved in $GPROF_MASTER"
1188
 fi
1189
 if [ -f $SLAVE_MYDDIR/gmon.out ]; then
1190
   gprof $SLAVE_MYSQLD $SLAVE_MYDDIR/gmon.out > $GPROF_SLAVE
1191
   echo "Slave execution profile has been saved in $GPROF_SLAVE"
1192
 fi
1193
}
1194
1195
gcov_prepare () {
1196
    $FIND $BASEDIR -name \*.gcov \
1197
    -or -name \*.da | $XARGS $RM
1198
}
1199
1200
gcov_collect () {
1201
    $ECHO "Collecting source coverage info..."
1202
    [ -f $GCOV_MSG ] && $RM $GCOV_MSG
1203
    [ -f $GCOV_ERR ] && $RM $GCOV_ERR
1204
    for d in $MYSQLD_SRC_DIRS; do
1205
	cd $BASEDIR/$d
1206
	for f in *.h *.cc *.c; do
1207
	    $GCOV $f 2>>$GCOV_ERR  >>$GCOV_MSG
1208
	done
1209
	cd $MYSQL_TEST_DIR
1210
    done
1211
1212
    $ECHO "gcov info in $GCOV_MSG, errors in $GCOV_ERR"
1213
}
1214
1215
abort_if_failed()
1216
{
1217
 if [ ! $? = 0 ] ; then
1218
  echo $1
1219
  exit 1
1220
 fi
1221
}
1222
1223
launch_in_background()
1224
{
1225
  shift
1226
  echo $@ | /bin/sh  >> $CUR_MYERR 2>&1  &
1227
  sleep 2 #hack
1228
  return
1229
}
1230
1231
shutdown_mysqld()
1232
{
1233
  pid=$1
1234
  ident=$2
1235
  # Shutdown time must be high as slave may be in reconnect
1236
  $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock$3 --connect_timeout=5 --shutdown_timeout=70 shutdown >> $MYSQL_MANAGER_LOG 2>&1
1237
  res=$?
1238
  # Some systems require an extra connect
1239
  $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock$3 --connect_timeout=1 ping >> $MYSQL_MANAGER_LOG 2>&1
1240
  if test $res = 0
1241
  then
1242
    wait_for_pid $pid
1243
  fi
1244
  return $res
1245
}
1246
1247
start_ndbcluster()
1248
{
1249
  if [ ! -n "$USE_NDBCLUSTER" ] ;
1250
  then
1251
    USING_NDBCLUSTER=0
1252
    USE_NDBCLUSTER_OPT=
1253
  fi
1254
  
1255
  if [ x$USING_NDBCLUSTER = x1 -a -z "$USE_NDBCLUSTER_OPT" ]
1256
  then
1257
  rm -f $NDB_TOOLS_OUTPUT
1258
  if [ -z "$USE_RUNNING_NDBCLUSTER" ]
1259
  then
1260
    if [ "$DO_BENCH" != 1 -a -z "$NDBCLUSTER_EXTRA_OPTS" ]
1261
    then
1262
      NDBCLUSTER_EXTRA_OPTS="--small"
1263
    fi
1264
    OPTS="$NDBCLUSTER_OPTS $NDBCLUSTER_EXTRA_OPTS --character-sets-dir=$CHARSETSDIR --verbose=$NDB_VERBOSE --initial --relative-config-data-dir --core"
1265
    if [ "x$NDB_VERBOSE" != "x0" ] ; then
1266
      echo "Starting master ndbcluster " $OPTS
1267
    fi
1268
    ./ndb/ndbcluster $OPTS || NDB_STATUS_OK=0
1269
    if [ x$NDB_STATUS_OK != x1 ] ; then
1270
      if [ x$FORCE != x1 ] ; then
1271
        exit 1
1272
      fi
1273
      USING_NDBCLUSTER=0
1274
      USE_NDBCLUSTER_OPT=
1275
      return
1276
    fi
1277
1278
    NDB_CONNECTSTRING="host=localhost:$NDBCLUSTER_PORT"
1279
  else
1280
    NDB_CONNECTSTRING="$USE_RUNNING_NDBCLUSTER"
1281
    echo "Using ndbcluster at $NDB_CONNECTSTRING"
1282
  fi
1283
  USE_NDBCLUSTER_OPT="$USE_NDBCLUSTER --ndb-connectstring=\"$NDB_CONNECTSTRING\" --ndb-extra-logging"
1284
  export NDB_CONNECTSTRING
1285
  fi
1286
}
1287
1288
rm_ndbcluster_tables()
1289
{
1290
  $RM -f $1/mysql/apply_status*
1291
  $RM -f $1/mysql/schema*
1292
}
1293
1294
stop_ndbcluster()
1295
{
1296
 if [ -n "$USE_NDBCLUSTER_OPT" ]
1297
 then
1298
 USE_NDBCLUSTER_OPT=
1299
 if [ -z "$USE_RUNNING_NDBCLUSTER" ]
1300
 then
1301
   # Kill any running ndbcluster stuff
1302
   $ECHO "Stopping master cluster"
1303
   ./ndb/ndbcluster $NDBCLUSTER_OPTS --stop
1304
   # remove ndb table the hard way as not to upset later tests
1305
   rm_ndbcluster_tables $MASTER_MYDDIR
1306
   rm_ndbcluster_tables $MASTER_MYDDIR"1"
1307
 fi
1308
 fi
1309
}
1310
1311
# The embedded server needs the cleanup so we do some of the start work
1312
# but stop before actually running mysqld or anything.
1313
1314
start_master()
1315
{
1316
  eval "this_master_running=\$MASTER$1_RUNNING"
1317
  if [ x$this_master_running = x1 ] || [ x$LOCAL_MASTER = x1 ] ; then
1318
    return
1319
  fi
1320
  # Remove stale binary logs except for 2 tests which need them
1321
  if [ "$tname" != "rpl_crash_binlog_ib_1b" ] && [ "$tname" != "rpl_crash_binlog_ib_2b" ] && [ "$tname" != "rpl_crash_binlog_ib_3b" ] 
1322
  then
1323
    $RM -f $MYSQL_TEST_DIR/var/log/master-bin$1.*
1324
  fi
1325
1326
  # Remove old master.info and relay-log.info files
1327
  $RM -f $MYSQL_TEST_DIR/var/master-data$1/master.info $MYSQL_TEST_DIR/var/master-data$1/relay-log.info
1328
1329
  #run master initialization shell script if one exists
1330
1331
  if [ -f "$master_init_script" ] ;
1332
  then
1333
      /bin/sh $master_init_script
1334
  fi
1335
  cd $BASEDIR # for gcov
1336
  if [ -n "$1" ] ; then
1337
   id=`$EXPR $1 + 101`;
1338
   this_master_myport=`$EXPR $MASTER_MYPORT + $1`
1339
   NOT_FIRST_MASTER_EXTRA_OPTS="--skip-innodb"
1340
   eval "MASTER_MYPORT$1=$this_master_myport"
1341
   export MASTER_MYPORT$1
1342
  else
1343
   id=1;
1344
   this_master_myport=$MASTER_MYPORT
1345
   NOT_FIRST_MASTER_EXTRA_OPTS=""
1346
  fi
1347
  if [ -n "$EXTRA_MASTER_MYSQLD_TRACE" ] 
1348
  then
1349
      CURR_MASTER_MYSQLD_TRACE="$EXTRA_MASTER_MYSQLD_TRACE$1"
1350
  fi
1351
  if [ x$MASTER_MYSQLDBINLOG = x1 ]
1352
  then
1353
    MASTER_MYSQLD_BINLOG_OPT="--log-bin=$MYSQL_TEST_DIR/var/log/master-bin$1"
1354
  fi
1355
  if [ -z "$DO_BENCH" -a -z "$DO_STRESS"  ]
1356
  then
1357
    master_args="--no-defaults \
1358
  	    --server-id=$id  \
1359
          --basedir=$MY_BASEDIR \
1360
          --port=$this_master_myport \
1361
          --port-open-timeout=380 \
1362
          --local-infile \
1363
          --exit-info=256 \
1364
          --core \
1365
          $USE_NDBCLUSTER_OPT \
1366
          --datadir=$MASTER_MYDDIR$1 \
1367
          --pid-file=$MASTER_MYPID$1 \
1368
          --socket=$MASTER_MYSOCK$1 \
1369
          --log=$MASTER_MYLOG$1 \
1370
          --character-sets-dir=$CHARSETSDIR \
1371
          --default-character-set=$CHARACTER_SET \
1372
          --tmpdir=$MYSQL_TMP_DIR \
1373
          --language=$LANGUAGE \
1374
          --innodb_data_file_path=ibdata1:128M:autoextend \
1375
	  --open-files-limit=1024 \
1376
          --log-bin-trust-function-creators \
1377
	   $MASTER_40_ARGS \
1378
           $SMALL_SERVER \
1379
           $MASTER_MYSQLD_BINLOG_OPT \
1380
           $EXTRA_MASTER_MYSQLD_OPT $EXTRA_MASTER_OPT \
1381
           $NOT_FIRST_MASTER_EXTRA_OPTS $CURR_MASTER_MYSQLD_TRACE"
1382
  else
1383
    master_args="--no-defaults \
1384
          --server-id=$id --rpl-recovery-rank=1 \
1385
          --basedir=$MY_BASEDIR --init-rpl-role=master \
1386
          --port=$this_master_myport \
1387
          --port-open-timeout=380 \
1388
          --local-infile \
1389
          --datadir=$MASTER_MYDDIR$1 \
1390
          --pid-file=$MASTER_MYPID$1 \
1391
          --socket=$MASTER_MYSOCK$1 \
1392
          --character-sets-dir=$CHARSETSDIR \
1393
          --default-character-set=$CHARACTER_SET \
1394
          --core \
1395
          $USE_NDBCLUSTER_OPT \
1396
          --tmpdir=$MYSQL_TMP_DIR \
1397
          --language=$LANGUAGE \
1398
          --innodb_data_file_path=ibdata1:128M:autoextend \
1399
          --log-bin-trust-function-creators \
1400
	   $MASTER_40_ARGS \
1401
           $SMALL_SERVER \
1402
           $MASTER_MYSQLD_BINLOG_OPT \
1403
           $EXTRA_MASTER_MYSQLD_OPT $EXTRA_MASTER_OPT \
1404
           $NOT_FIRST_MASTER_EXTRA_OPTS"
1405
  fi
1406
1407
  CUR_MYERR=$MASTER_MYERR$1
1408
  CUR_MYSOCK=$MASTER_MYSOCK$1
1409
1410
  # For embedded server we collect the server flags and return
1411
  if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then
1412
    # Add a -A to each argument to pass it to embedded server
1413
    EMBEDDED_SERVER_OPTS=""
1414
    for opt in $master_args
1415
    do
1416
      EMBEDDED_SERVER_OPTS="$EMBEDDED_SERVER_OPTS -A $opt"
1417
    done
1418
    EXTRA_MYSQL_TEST_OPT="$EMBEDDED_SERVER_OPTS"
1419
    return
1420
  fi
1421
1422
  if [ x$DO_DDD = x1 ]
1423
  then
1424
    $ECHO "set args $master_args" > $GDB_MASTER_INIT$1
1425
    launch_in_background master ddd -display $DISPLAY --debugger \
1426
    "gdb -x $GDB_MASTER_INIT$1" $MASTER_MYSQLD
1427
  elif [ x$DO_GDB = x1 ]
1428
  then
1429
    if [ x$MANUAL_GDB = x1 ]
1430
    then
1431
      $ECHO "set args $master_args" > $GDB_MASTER_INIT$1
1432
      $ECHO "To start gdb for the master , type in another window:"
1433
      $ECHO "cd $MYSQL_TEST_DIR ; gdb -x $GDB_MASTER_INIT$1 $MASTER_MYSQLD"
1434
      wait_for_master=1500
1435
    else
1436
      ( $ECHO set args $master_args;
1437
      if [ $USE_MANAGER = 0 ] ; then
1438
    cat <<EOF
1439
b mysql_parse
1440
commands 1
1441
disa 1
1442
end
1443
r
1444
EOF
1445
      fi )  > $GDB_MASTER_INIT$1
1446
      launch_in_background master $XTERM -display $DISPLAY \
1447
      -title "Master" -e gdb -x $GDB_MASTER_INIT$1 $MASTER_MYSQLD
1448
    fi
1449
  else
1450
    launch_in_background master $MASTER_MYSQLD $master_args
1451
  fi
1452
  sleep_until_file_created $MASTER_MYPID$1 $wait_for_master
1453
  wait_for_master=$SLEEP_TIME_FOR_SECOND_MASTER
1454
  eval "MASTER$1_RUNNING=1"
1455
}
1456
1457
start_slave()
1458
{
1459
  [ x$SKIP_SLAVE = x1 ] && return
1460
  eval "this_slave_running=\$SLAVE$1_RUNNING"
1461
  [ x$this_slave_running = 1 ] && return
1462
1463
  # When testing fail-safe replication, we will have more than one slave
1464
  # in this case, we start secondary slaves with an argument
1465
  slave_ident="slave$1"
1466
  if [ -n "$1" ] ;
1467
  then
1468
   slave_server_id=`$EXPR 2 + $1`
1469
   slave_rpl_rank=$slave_server_id
1470
   slave_port=`expr $SLAVE_MYPORT + $1`
1471
   slave_log="$SLAVE_MYLOG.$1"
1472
   slave_err="$SLAVE_MYERR.$1"
1473
   slave_datadir="$SLAVE_MYDDIR/../$slave_ident-data/"
1474
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
1475
   slave_sock="$SLAVE_MYSOCK-$1"
1476
  else
1477
   slave_server_id=2
1478
   slave_rpl_rank=2
1479
   slave_port=$SLAVE_MYPORT
1480
   slave_log=$SLAVE_MYLOG
1481
   slave_err=$SLAVE_MYERR
1482
   slave_datadir=$SLAVE_MYDDIR
1483
   slave_pid=$SLAVE_MYPID
1484
   slave_sock="$SLAVE_MYSOCK"
1485
 fi
1486
1487
  #
1488
  if [ x$USING_NDBCLUSTER = x1 -a -n "$USE_NDBCLUSTER_SLAVE" ] ; then
1489
    if [ $slave_server_id -eq 2 ] ; then
1490
      savedir=`pwd`
1491
      cd $MYSQL_TEST_DIR
1492
      if [ "$DO_BENCH" != 1 -a -z "$NDBCLUSTER_EXTRA_OPTS" ]
1493
       then
1494
         NDBCLUSTER_EXTRA_OPTS="--small"
1495
      fi
1496
1497
      OPTS="$NDBCLUSTER_OPTS_SLAVE --initial $NDBCLUSTER_EXTRA_OPTS --ndbd-nodes=1 --verbose=$NDB_VERBOSE --relative-config-data-dir --core"
1498
      if [ "x$NDB_VERBOSE" != "x0" ] ; then
1499
        echo "Starting slave ndbcluster " $OPTS
1500
      fi
1501
      ./ndb/ndbcluster $OPTS \
1502
                      || NDB_SLAVE_STATUS_OK=0
1503
      #                > /dev/null 2>&1 || NDB_SLAVE_STATUS_OK=0
1504
      cd $savedir
1505
      if [ x$NDB_SLAVE_STATUS_OK != x1 ] ; then
1506
        if [ x$FORCE != x1 ] ; then
1507
          exit 1
1508
        fi
1509
        USE_NDBCLUSTER_SLAVE_OPT=
1510
        USE_NDBCLUSTER_SLAVE=
1511
      fi
1512
      USE_NDBCLUSTER_SLAVE_OPT=$USE_NDBCLUSTER_SLAVE
1513
    fi
1514
  else
1515
    USE_NDBCLUSTER_SLAVE_OPT=
1516
  fi
1517
1518
  # Remove stale binary logs and old master.info files
1519
  # except for too tests which need them
1520
  if [ "$tname" != "rpl_crash_binlog_ib_1b" ] && [ "$tname" != "rpl_crash_binlog_ib_2b" ] && [ "$tname" != "rpl_crash_binlog_ib_3b" ]
1521
  then
1522
    $RM -f $MYSQL_TEST_DIR/var/log/$slave_ident-*bin.*
1523
    $RM -f $slave_datadir/master.info $slave_datadir/relay-log.info
1524
  fi
1525
1526
  #run slave initialization shell script if one exists
1527
  if [ -f "$slave_init_script" ] ;
1528
  then
1529
        /bin/sh $slave_init_script
1530
  fi
1531
1532
  if [ -z "$SLAVE_MASTER_INFO" ] ; then
1533
    master_info="--master-user=root \
1534
          --master-connect-retry=1 \
1535
          --master-host=127.0.0.1 \
1536
          --master-password="" \
1537
          --master-port=$MASTER_MYPORT \
1538
          --server-id=$slave_server_id --rpl-recovery-rank=$slave_rpl_rank"
1539
 else
1540
   master_info=$SLAVE_MASTER_INFO
1541
 fi
1542
1543
  if [ x$SLAVE_MYSQLDBINLOG = x1 ]
1544
  then
1545
    SLAVE_MYSQLD_BINLOG_OPT="--log-bin=$MYSQL_TEST_DIR/var/log/$slave_ident-bin --log-slave-updates"
1546
  fi
1547
1548
  $RM -f $slave_datadir/log.*
1549
  slave_args="--no-defaults $master_info \
1550
  	    --exit-info=256 \
1551
          $SLAVE_MYSQLDBINLOG_OPT \
1552
          --relay-log=$MYSQL_TEST_DIR/var/log/$slave_ident-relay-bin \
1553
          --log=$slave_log \
1554
          --basedir=$MY_BASEDIR \
1555
          --datadir=$slave_datadir \
1556
          --pid-file=$slave_pid \
1557
          --port=$slave_port \
1558
          --port-open-timeout=380 \
1559
          --socket=$slave_sock \
1560
          --character-sets-dir=$CHARSETSDIR \
1561
          --default-character-set=$CHARACTER_SET \
1562
          --core --init-rpl-role=slave \
1563
          --tmpdir=$MYSQL_TMP_DIR \
1564
          --language=$LANGUAGE \
1565
          --skip-innodb --skip-ndbcluster --skip-slave-start \
1566
          --slave-load-tmpdir=$SLAVE_LOAD_TMPDIR \
1567
          --report-host=127.0.0.1 --report-user=root \
1568
          --report-port=$slave_port \
1569
          --master-retry-count=10 \
1570
          -O slave_net_timeout=10 \
1571
          --log-bin-trust-function-creators \
1572
           $SMALL_SERVER \
1573
           $SLAVE_MYSQLD_BINLOG_OPT \
1574
           $EXTRA_SLAVE_MYSQLD_OPT $EXTRA_SLAVE_OPT \
1575
           $USE_NDBCLUSTER_SLAVE_OPT"
1576
  CUR_MYERR=$slave_err
1577
  CUR_MYSOCK=$slave_sock
1578
1579
  if [ x$DO_DDD = x1 ]
1580
  then
1581
    $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
1582
    launch_in_background $slave_ident ddd -display $DISPLAY --debugger \
1583
     "gdb -x $GDB_SLAVE_INIT" $SLAVE_MYSQLD
1584
  elif [ x$DO_GDB = x1 ]
1585
  then
1586
    if [ x$MANUAL_GDB = x1 ]
1587
    then
1588
      $ECHO "set args $slave_args" > $GDB_SLAVE_INIT
1589
      echo "To start gdb for the slave, type in another window:"
1590
      echo "cd $MYSQL_TEST_DIR ; gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD"
1591
      wait_for_slave=1500
1592
    else
1593
      ( $ECHO set args $slave_args;
1594
      if [ $USE_MANAGER = 0 ] ; then
1595
    cat <<EOF
1596
b mysql_parse
1597
commands 1
1598
disa 1
1599
end
1600
r
1601
EOF
1602
      fi )  > $GDB_SLAVE_INIT
1603
      launch_in_background $slave_ident $XTERM -display $DISPLAY -title "Slave" -e \
1604
      gdb -x $GDB_SLAVE_INIT $SLAVE_MYSQLD
1605
    fi
1606
  else
1607
    launch_in_background $slave_ident $SLAVE_MYSQLD $slave_args
1608
  fi
1609
  eval "SLAVE$1_RUNNING=1"
1610
  sleep_until_file_created $slave_pid $wait_for_slave
1611
  wait_for_slave=$SLEEP_TIME_FOR_SECOND_SLAVE
1612
}
1613
1614
mysql_start ()
1615
{
1616
# We should not start the daemon here as we don't know the arguments
1617
# for the test.  Better to let the test start the daemon
1618
1619
#  $ECHO "Starting MySQL daemon"
1620
#  start_master
1621
#  start_slave
1622
  cd $MYSQL_TEST_DIR
1623
  return 1
1624
}
1625
1626
stop_slave ()
1627
{
1628
  eval "this_slave_running=\$SLAVE$1_RUNNING"
1629
  slave_ident="slave$1"
1630
  if [ -n "$1" ] ;
1631
  then
1632
   slave_pid="$MYRUN_DIR/mysqld-$slave_ident.pid"
1633
  else
1634
   slave_pid=$SLAVE_MYPID
1635
  fi
1636
  if [ x$this_slave_running = x1 ]
1637
  then
1638
    pid=`$CAT $slave_pid`
1639
    shutdown_mysqld $pid $slave_ident
1640
    if [ $? != 0 ] && [ -f $slave_pid ]
1641
    then # try harder!
1642
      $ECHO "slave not cooperating with mysqladmin, will try manual kill"
1643
      kill $pid
1644
      sleep_until_file_deleted $pid $slave_pid
1645
      if [ -f $slave_pid ] ; then
1646
        $ECHO "slave refused to die. Sending SIGKILL"
1647
        kill -9 `$CAT $slave_pid`
1648
        $RM -f $slave_pid
1649
      else
1650
        $ECHO "slave responded to SIGTERM "
1651
      fi
1652
    else
1653
      sleep $SLEEP_TIME_AFTER_RESTART
1654
    fi
1655
    eval "SLAVE$1_RUNNING=0"
1656
    if [ -n "$USE_NDBCLUSTER_SLAVE_OPT" ] ; then
1657
      savedir=`pwd`
1658
      cd $MYSQL_TEST_DIR
1659
        $ECHO "Stopping slave cluster"
1660
      ./ndb/ndbcluster $NDBCLUSTER_OPTS_SLAVE --stop
1661
      rm_ndbcluster_tables $SLAVE_MYDDIR
1662
      cd $savedir
1663
    fi
1664
  fi
1665
}
1666
1667
stop_slave_threads ()
1668
{
1669
  eval "this_slave_running=\$SLAVE$1_RUNNING"
1670
  slave_ident="slave$1"
1671
  if [ x$this_slave_running = x1 ]
1672
  then
1673
    $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$slave_ident.sock stop-slave > /dev/null 2>&1
1674
  fi
1675
}
1676
1677
stop_master ()
1678
{
1679
  eval "this_master_running=\$MASTER$1_RUNNING"
1680
  if [ x$this_master_running = x1 ]
1681
  then
1682
    # For embedded server we don't stop anyting but mark that
1683
    # MASTER_RUNNING=0 to get cleanup when calling start_master().
1684
    if [ x$USE_EMBEDDED_SERVER != x1 ] ; then
1685
      pid=`$CAT $MASTER_MYPID$1`
1686
      shutdown_mysqld $pid master $1
1687
      if [ $? != 0 ] && [ -f $MASTER_MYPID$1 ]
1688
      then # try harder!
1689
	$ECHO "master not cooperating with mysqladmin, will try manual kill"
1690
	kill $pid
1691
	sleep_until_file_deleted $pid $MASTER_MYPID$1
1692
	if [ -f $MASTER_MYPID$1 ] ; then
1693
	  $ECHO "master refused to die. Sending SIGKILL"
1694
	  kill -9 `$CAT $MASTER_MYPID$1`
1695
	  $RM -f $MASTER_MYPID$1
1696
	else
1697
	  $ECHO "master responded to SIGTERM "
1698
	fi
1699
      else
1700
	sleep $SLEEP_TIME_AFTER_RESTART
1701
      fi
1702
    fi
1703
    eval "MASTER$1_RUNNING=0"
1704
  fi
1705
}
1706
1707
mysql_stop ()
1708
{
1709
  if [ "$MASTER_RUNNING" = 1 ]
1710
  then
1711
    $ECHO  "Ending Tests"
1712
    $ECHO  "Shutting-down MySQL daemon"
1713
    $ECHO  ""
1714
    stop_master
1715
    stop_master 1
1716
    $ECHO "Master shutdown finished"
1717
    stop_slave
1718
    stop_slave 1
1719
    stop_slave 2
1720
    $ECHO "Slave shutdown finished"
1721
    stop_ndbcluster
1722
  fi
1723
  return 1
1724
}
1725
1726
mysql_restart ()
1727
{
1728
  mysql_stop
1729
  mysql_start
1730
  return 1
1731
}
1732
1733
mysql_loadstd () {
1734
1735
    # cp $STD_DATA/*.frm $STD_DATA/*.MRG $MASTER_MYDDIR/test
1736
    return 1
1737
}
1738
1739
run_testcase ()
1740
{
1741
 tf=$1
1742
 tname=`$BASENAME $tf .test`
1743
 master_opt_file=$TESTDIR/$tname-master.opt
1744
 slave_opt_file=$TESTDIR/$tname-slave.opt
1745
 master_init_script=$TESTDIR/$tname-master.sh
1746
 slave_init_script=$TESTDIR/$tname-slave.sh
1747
 slave_master_info_file=$TESTDIR/$tname.slave-mi
1748
 tsrcdir=$TESTDIR/$tname-src
1749
 result_file="r/$tname.result"
1750
 echo $tname > $CURRENT_TEST
1751
 SKIP_SLAVE=`$EXPR \( $tname : rpl \) = 0 \& \( $tname : federated \) = 0`
1752
 NDBCLUSTER_TEST=`$EXPR \( $tname : '.*ndb.*' \) != 0`
1753
 if [ "x$USE_NDBCLUSTER_ALL" = "x1" ] ; then
1754
   NDBCLUSTER_TEST=1
1755
 fi
1756
 if [ "x$USE_NDBCLUSTER_ONLY" = "x1" -a "x$NDBCLUSTER_TEST" != "x1" ] ; then
1757
   skip_test $tname
1758
   return
1759
 fi
1760
 if [ "$USE_MANAGER" = 1 ] ; then
1761
  many_slaves=`$EXPR \( \( $tname : rpl_failsafe \) != 0 \) \| \( \( $tname : rpl_chain_temp_table \) != 0 \)`
1762
 fi
1763
 if $EXPR "$tname" '<' "$START_FROM" > /dev/null ; then
1764
   #skip_test $tname
1765
   return
1766
 fi
1767
1768
 if [ "$SKIP_TEST" ] ; then
1769
   if $EXPR \( "$tname" : "$SKIP_TEST" \) > /dev/null ; then
1770
     skip_test $tname
1771
     return
1772
   fi
1773
 fi
1774
1775
 if [ "$DO_TEST" ] ; then
1776
   if $EXPR \( "$tname" : "$DO_TEST" \) > /dev/null ; then
1777
     : #empty command to keep some shells happy
1778
   else
1779
     #skip_test $tname
1780
     return
1781
   fi
1782
 fi
1783
1784
 if [ x${NO_SLAVE}x$SKIP_SLAVE = x1x0 ] ; then
1785
   skip_test $tname
1786
   return
1787
 fi
1788
1789
# if [ -f "$TESTDIR/$tname.disabled" ]
1790
# then
1791
#   comment=`$CAT $TESTDIR/$tname.disabled`;
1792
#   disable_test $tname "$comment"
1793
#   return
1794
# fi
1795
 if [ -f "$TESTDIR/disabled.def" ] ; then
1796
   comment=`$GREP "^$tname *: *" $TESTDIR/disabled.def`;
1797
   if [ -n "$comment" ]
1798
   then
1799
     comment=`echo $comment | sed 's/^[^:]*: *//'`
1800
     disable_test $tname "$comment"
1801
     return
1802
   fi
1803
 fi
1804
1805
 if [ "x$USE_EMBEDDED_SERVER" != "x1" ] ; then
1806
   # Stop all slave threads, so that we don't have useless reconnection
1807
   #  attempts and error messages in case the slave and master servers restart.
1808
   stop_slave_threads
1809
   stop_slave_threads 1
1810
   stop_slave_threads 2
1811
 fi
1812
1813
 # FIXME temporary solution, we will get a new C version of this
1814
 # script soon anyway so it is not worth it spending the time
1815
 if [ "x$USE_EMBEDDED_SERVER" = "x1" -a -z "$DO_TEST" ] ; then
1816
   for t in \
1817
       "init_connect" \
1818
       "init_file"
1819
   do
1820
     if [ "$tname" = "$t" ] ; then
1821
       skip_test $tname
1822
       return
1823
     fi
1824
   done
1825
 fi
1826
1827
 if [ $USE_RUNNING_SERVER -eq 0 ] ;
1828
 then
1829
   if [ -f $master_opt_file ] ;
1830
   then
1831
     EXTRA_MASTER_OPT=`$CAT $master_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1832
     case "$EXTRA_MASTER_OPT" in
1833
       --timezone=*)
1834
	 TZ=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--timezone=;;"`
1835
	 export TZ
1836
	 # Note that this must be set to space, not "" for test-reset to work
1837
	 EXTRA_MASTER_OPT=" "
1838
	 ;;
1839
       --result-file=*)
1840
         result_file=`$ECHO "$EXTRA_MASTER_OPT" | $SED -e "s;--result-file=;;"`
1841
         result_file="r/$result_file.result"
1842
         # Note that this must be set to space, not "" for test-reset to work
1843
	 EXTRA_MASTER_OPT=" "
1844
         ;;
1845
       --force-restart)
1846
         # Note that this must be set to space, not "" for test-reset to work
1847
	 EXTRA_MASTER_OPT=" "
1848
	 ;;
1849
     esac
1850
     stop_master
1851
     stop_master 1
1852
1853
     # only stop the cluster if this test will not use cluster
1854
     if [ x$NDBCLUSTER_TEST != x1 ] ;
1855
     then
1856
       stop_ndbcluster
1857
     fi
1858
1859
     report_current_test $tname
1860
     USING_NDBCLUSTER=$NDBCLUSTER_TEST
1861
     # start_ndbcluster knows if cluster is already started
1862
     start_ndbcluster
1863
     start_master
1864
     if [ x$USING_NDBCLUSTER = x1 -a -z "$DO_BENCH" -a -z "$DO_STRESS" ] ; then
1865
       echo "CURRENT_TEST: $tname" >> $MASTER_MYERR"1"
1866
       start_master 1
1867
     fi
1868
     TZ=$MY_TZ; export TZ
1869
   else
1870
     # If we had extra master opts to the previous run
1871
     # or there is no master running (FIXME strange.....)
1872
     # or there is a master init script
1873
     if [ ! -z "$EXTRA_MASTER_OPT" ] || [ x$MASTER_RUNNING != x1 ] || \
1874
	[ -f $master_init_script ] || \
1875
        [ -n "$USE_NDBCLUSTER" -a x$NDBCLUSTER_TEST != x$USING_NDBCLUSTER ]
1876
     then
1877
       EXTRA_MASTER_OPT=""
1878
       stop_master
1879
       stop_master 1
1880
1881
       # only stop the cluster if this test will not use cluster
1882
       if [ x$NDBCLUSTER_TEST != x1 ] ;
1883
       then
1884
         stop_ndbcluster
1885
       fi
1886
1887
       report_current_test $tname
1888
       USING_NDBCLUSTER=$NDBCLUSTER_TEST
1889
       # start_ndbcluster knows if cluster is already started
1890
       start_ndbcluster
1891
       start_master
1892
       if [ x$USING_NDBCLUSTER = x1  -a -z "$DO_BENCH" -a -z "$DO_STRESS" ] ; then
1893
         echo "CURRENT_TEST: $tname" >> $MASTER_MYERR"1"
1894
         start_master 1
1895
       fi
1896
     else
1897
       report_current_test $tname
1898
     fi
1899
   fi
1900
1901
   # We never start a slave if embedded server is used
1902
   if [ "x$USE_EMBEDDED_SERVER" != "x1" ] ; then
1903
     do_slave_restart=0
1904
     if [ -f $slave_opt_file ] ;
1905
     then
1906
       EXTRA_SLAVE_OPT=`$CAT $slave_opt_file | $SED -e "s;\\$MYSQL_TEST_DIR;$MYSQL_TEST_DIR;"`
1907
       do_slave_restart=1
1908
     else
1909
      if [ ! -z "$EXTRA_SLAVE_OPT" ] || [ x$SLAVE_RUNNING != x1 ] ;
1910
      then
1911
	EXTRA_SLAVE_OPT=""
1912
	do_slave_restart=1
1913
      fi
1914
     fi
1915
1916
     if [ -f $slave_master_info_file ] ; then
1917
       SLAVE_MASTER_INFO=`$CAT $slave_master_info_file`
1918
       do_slave_restart=1
1919
     else
1920
       if [ ! -z "$SLAVE_MASTER_INFO" ] || [ x$SLAVE_RUNNING != x1 ] ;
1921
       then
1922
	 SLAVE_MASTER_INFO=""
1923
	 do_slave_restart=1
1924
       fi
1925
     fi
1926
1927
     USING_NDBCLUSTER=$NDBCLUSTER_TEST
1928
     if [ -n "$USE_NDBCLUSTER_SLAVE_OPT" ] ; then
1929
       if [ x$USING_NDBCLUSTER != x1 ] ; then
1930
         do_slave_restart=1
1931
       fi
1932
     else
1933
       if [ x$USING_NDBCLUSTER = x1 ] ; then
1934
         do_slave_restart=1
1935
       fi
1936
     fi
1937
1938
1939
     if [ x$do_slave_restart = x1 ] ; then
1940
       stop_slave
1941
       echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
1942
       start_slave
1943
     else
1944
       echo "CURRENT_TEST: $tname" >> $SLAVE_MYERR
1945
     fi
1946
     if [ x$many_slaves = x1 ]; then
1947
      start_slave 1
1948
      start_slave 2
1949
     fi
1950
   fi
1951
 fi
1952
1953
 if [ "x$START_AND_EXIT" = "x1" ] ; then
1954
  echo "Servers started, exiting"
1955
  exit
1956
 fi
1957
1958
 cd $MYSQL_TEST_DIR
1959
1960
 if [ -f $tf ] ; then
1961
    $RM -f r/$tname.*reject
1962
    mysql_test_args="-R $result_file $EXTRA_MYSQL_TEST_OPT"
1963
    if [ -z "$DO_CLIENT_GDB" ] ; then
1964
      `$VALGRIND_MYSQLTEST $MYSQL_TEST  $mysql_test_args < $tf 2> $TIMEFILE`;
1965
    else
1966
      do_gdb_test "$mysql_test_args" "$tf"
1967
    fi
1968
1969
    res=$?
1970
1971
    # Save the testcase log to mysqltest log file
1972
    echo "CURRENT_TEST: $tname" >> $MYSQLTEST_LOG
1973
    cat $TIMEFILE >> $MYSQLTEST_LOG
1974
1975
    pname=`$ECHO "$tname                        "|$CUT -c 1-24`
1976
    RES="$pname"
1977
1978
    if [ x$many_slaves = x1 ] ; then
1979
     stop_slave 1
1980
     stop_slave 2
1981
    fi
1982
1983
    if [ $res = 0 ]; then
1984
      total_inc
1985
      pass_inc
1986
      TIMER=""
1987
      if [ x$USE_TIMER = x1 -a -f "$MY_LOG_DIR/timer" ]; then
1988
	TIMER=`cat $MY_LOG_DIR/timer`
1989
	TIMER=`$PRINTF "%13s" $TIMER`
1990
      fi
1991
      $ECHO "$RES$RES_SPACE [ pass ]   $TIMER"
1992
    else
1993
      # why the following ``if'' ? That is why res==1 is special ?
1994
      if [ $res = 62 ]; then
1995
        skip_inc
1996
	$ECHO "$RES$RES_SPACE [ skipped ]"
1997
      else
1998
        if [ $res -ne 1 ]; then
1999
          $ECHO "mysqltest returned unexpected code $res, it has probably crashed" >> $TIMEFILE
2000
        fi
2001
	total_inc
2002
        fail_inc
2003
	$ECHO "$RES$RES_SPACE [ fail ]"
2004
        $ECHO
2005
	error_is
2006
	show_failed_diff $tname
2007
	$ECHO
2008
	if [ x$FORCE != x1 ] ; then
2009
	 $ECHO "Aborting: $tname failed in $TEST_MODE mode. To continue, re-run with '--force'."
2010
	 $ECHO
2011
         if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && \
2012
	    [ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
2013
	 then
2014
	   mysql_stop
2015
   	 fi
2016
	 exit 1
2017
	fi
2018
	FAILED_CASES="$FAILED_CASES $tname"
2019
        if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && \
2020
	   [ -z "$DO_DDD" ] && [ -z "$USE_EMBEDDED_SERVER" ]
2021
	then
2022
	  mysql_restart
2023
	fi
2024
      fi
2025
    fi
2026
  fi
2027
}
2028
2029
run_stress_test()
2030
{
2031
2032
  STRESS_BASEDIR="$MYSQL_TEST_DIR/var/stress"
2033
2034
  #Clean-up old stress test basedir
2035
  if [ -d $STRESS_BASEDIR ] ; then 
2036
    $RM -rf $STRESS_BASEDIR
2037
  fi
2038
  #Create stress test basedir 
2039
  mkdir $STRESS_BASEDIR
2040
2041
  if [ "$STRESS_SUITE" != "main" -a "$STRESS_SUITE" != "default" ] ; then
2042
    STRESS_SUITE_DIR="$MYSQL_TEST_DIR/suite/$STRESS_SUITE"
2043
  else
2044
    STRESS_SUITE_DIR="$MYSQL_TEST_DIR"
2045
  fi
2046
2047
  if [ -d "$STRESS_SUITE_DIR" ] ; then 
2048
    STRESS_SUITE_T_DIR="$STRESS_SUITE_DIR/t"
2049
    STRESS_SUITE_R_DIR="$STRESS_SUITE_DIR/r"
2050
    #FIXME: check that dirs above are exist
2051
  else
2052
    echo "Directory $STRESS_SUITE_DIR with test suite doesn't exists. Abort stress testing"
2053
    exit 1
2054
  fi
2055
  
2056
  if [ -n "$STRESS_TEST" ] ; then 
2057
    STRESS_TEST_FILE="$STRESS_BASEDIR/stress_tests.txt"
2058
    echo $STRESS_TEST > $STRESS_TEST_FILE
2059
  elif [ -n "$STRESS_TEST_FILE" ] ; then    
2060
    STRESS_TEST_FILE="$STRESS_SUITE_DIR/$STRESS_TEST_FILE"
2061
    if [ ! -f  "$STRESS_TEST_FILE" ] ; then 
2062
      echo "Specified file $STRESS_TEST_FILE with list of tests does not exist"
2063
      echo "Please ensure that file exists and has proper permissions"
2064
      exit 1
2065
    fi
2066
  else 
2067
    STRESS_TEST_FILE="$STRESS_SUITE_DIR/stress_tests.txt"
2068
    if [ ! -f  "$STRESS_TEST_FILE" ] ; then 
2069
      echo "Default file $STRESS_TEST_FILE with list of tests does not exist."
2070
      echo "Please use --stress-test-file option to specify custom one or you can" 
2071
      echo "just specify name of test for testing as last argument in command line"
2072
      exit 1
2073
    fi
2074
  fi
2075
2076
  if [ -n "$STRESS_INIT_FILE" ] ; then 
2077
    STRESS_INIT_FILE="$STRESS_SUITE_DIR/$STRESS_INIT_FILE"
2078
    if [ ! -f  "$STRESS_INIT_FILE" ] ; then 
2079
      echo "Specified file $STRESS_INIT_FILE with list of tests doesn't exist."
2080
      echo "Please ensure that file exists and has proper permissions"
2081
      exit 1
2082
    fi
2083
  else
2084
    STRESS_INIT_FILE="$STRESS_SUITE_DIR/stress_init.txt"
2085
    #Check for default init file
2086
    if [ ! -f "$STRESS_INIT_FILE" ] ; then 
2087
      STRESS_INIT_FILE=""
2088
    fi
2089
  fi
2090
2091
  if [ "$STRESS_MODE" != "random" -a "$STRESS_MODE" != "seq" ] ; then
2092
    echo "You specified wrong mode '$STRESS_MODE' for stress test."
2093
    echo "Correct values are 'random' or 'seq'"
2094
    exit 1
2095
  fi
2096
 
2097
  STRESS_TEST_ARGS="--server-socket=$MASTER_MYSOCK \
2098
                    --server-user=$DBUSER \
2099
                    --server-database=$DB \
2100
                    --stress-suite-basedir=$MYSQL_TEST_DIR \
2101
                    --suite=$STRESS_SUITE \
2102
                    --stress-tests-file=$STRESS_TEST_FILE \
2103
                    --stress-basedir=$STRESS_BASEDIR \
2104
                    --server-logs-dir=$STRESS_BASEDIR \
2105
                    --stress-mode=$STRESS_MODE \
2106
                    --mysqltest=$CLIENT_BINDIR/mysqltest \
2107
                    --threads=$STRESS_THREADS \
2108
                    --verbose \
2109
                    --cleanup \
2110
                    --log-error-details \
2111
                    --abort-on-error" 
2112
  
2113
  if [ -n "$STRESS_INIT_FILE" ] ; then 
2114
    STRESS_TEST_ARGS="$STRESS_TEST_ARGS --stress-init-file=$STRESS_INIT_FILE"
2115
  fi
2116
2117
  if [ -z "$STRESS_LOOP_COUNT" -a -z  "$STRESS_TEST_COUNT" -a 
2118
       -z "$STRESS_TEST_DURATION" ] ; then 
2119
2120
    #Limit stress testing with 20 loops in case when any limit parameter
2121
    #was specified
2122
    STRESS_TEST_COUNT=20
2123
  fi
2124
2125
  if [ -n "$STRESS_LOOP_COUNT" ] ; then 
2126
    STRESS_TEST_ARGS="$STRESS_TEST_ARGS --loop-count=$STRESS_LOOP_COUNT"
2127
  fi
2128
2129
  if [ -n "$STRESS_TEST_COUNT" ] ; then 
2130
    STRESS_TEST_ARGS="$STRESS_TEST_ARGS --test-count=$STRESS_TEST_COUNT"
2131
  fi
2132
2133
  if [ -n "$STRESS_TEST_DURATION" ] ; then 
2134
    STRESS_TEST_ARGS="$STRESS_TEST_ARGS --test-duration=$STRESS_TEST_DURATION"
2135
  fi  
2136
2137
  echo "Stress test related variables:"
2138
  echo "TESTS                - $1"
2139
  echo "STRESS               - $DO_STRESS"
2140
  echo "STRESS_SUITE         - $STRESS_SUITE"
2141
  echo "STRESS_TEST_FILE     - $STRESS_TEST_FILE"
2142
  echo "STRESS_INIT_FILE     - $STRESS_INIT_FILE"
2143
  echo "STRESS_THREADS       - $STRESS_THREADS"
2144
  echo "STRESS_MODE          - $STRESS_MODE"
2145
  echo "STRESS_TEST_COUNT    - $STRESS_TEST_COUNT"
2146
  echo "STRESS_LOOP_COUNT    - $STRESS_LOOP_COUNT"  
2147
  echo "STRESS_TEST_DURATION - $STRESS_TEST_DURATION"
2148
2149
  #echo "$STRESS_TEST_ARGS";
2150
  #Run stress test 
2151
  $MYSQL_TEST_DIR/mysql-stress-test.pl $STRESS_TEST_ARGS
2152
2153
2154
}
2155
2156
######################################################################
2157
# Main script starts here
2158
######################################################################
2159
2160
[ "$DO_GCOV" -a ! -x "$GCOV" ] && error "No gcov found"
2161
2162
[ "$DO_GCOV" ] && gcov_prepare
2163
[ "$DO_GPROF" ] && gprof_prepare
2164
2165
if [ $USE_RUNNING_SERVER -eq 0 ]
2166
then
2167
  if [ -z "$FAST_START" ]
2168
  then
2169
    # Ensure that no old mysqld test servers are running
2170
    $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2171
    $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK1 -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2172
    $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2173
    $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT --protocol=tcp -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2174
    $MYSQLADMIN --no-defaults --host=$hostname --protocol=tcp --port=`expr $MASTER_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2175
    $MYSQLADMIN --no-defaults --host=$hostname --protocol=tcp --port=$SLAVE_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2176
    $MYSQLADMIN --no-defaults --host=$hostname --protocol=tcp --port=`expr $SLAVE_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
2177
    sleep_until_file_deleted 0 $MASTER_MYPID
2178
    sleep_until_file_deleted 0 $MASTER_MYPID"1"
2179
    sleep_until_file_deleted 0 $SLAVE_MYPID
2180
  else
2181
    rm $MASTER_MYPID $MASTER_MYPID"1" $SLAVE_MYPID
2182
  fi
2183
2184
  # just to force stopping anything from previous runs
2185
  USE_NDBCLUSTER_OPT=$USE_NDBCLUSTER
2186
  stop_ndbcluster
2187
2188
  # Remove files that can cause problems
2189
  $RM -rf $MYSQL_TEST_DIR/var/ndbcluster
2190
  $RM -rf $MYSQL_TEST_DIR/var/tmp/snapshot*
2191
  $RM -rf $MYSQL_TEST_DIR/var/run/* $MYSQL_TEST_DIR/var/tmp/*
2192
2193
  # Remove old berkeley db log files that can confuse the server
2194
  $RM -f $MASTER_MYDDIR/log.*
2195
  $RM -f $MASTER_MYDDIR"1"/log.*
2196
2197
  # Remove old log and reject files
2198
  $RM -f r/*.reject r/*.progress r/*.log r/*.warnings
2199
2200
  wait_for_master=$SLEEP_TIME_FOR_FIRST_MASTER
2201
  wait_for_slave=$SLEEP_TIME_FOR_FIRST_SLAVE
2202
  $ECHO "Installing Test Databases"
2203
  mysql_install_db
2204
2205
  if [ -n "$1" -a `expr "X$*" : '.*ndb'` -eq 0 ]
2206
  then
2207
    USING_NDBCLUSTER=0
2208
    USE_NDBCLUSTER_OPT=
2209
  fi
2210
2211
  mysql_start
2212
  $ECHO  "Loading Standard Test Databases"
2213
  mysql_loadstd
2214
fi
2215
2216
$ECHO  "Starting Tests"
2217
2218
# Some test cases need USE_RUNNING_SERVER
2219
export USE_RUNNING_SERVER
2220
2221
#
2222
# This can probably be deleted
2223
#
2224
if [ "$DO_BENCH" = 1 ]
2225
then
2226
  start_master
2227
2228
  if [ "$DO_SMALL_BENCH" = 1 ]
2229
  then
2230
    EXTRA_BENCH_ARGS="--small-test --small-tables"
2231
  fi
2232
2233
  if [ x$USING_NDBCLUSTER = x1 ]
2234
  then
2235
    EXTRA_BENCH_ARGS="--create-options=TYPE=ndb $EXTRA_BENCH_ARGS"
2236
  fi 
2237
2238
  BENCHDIR=$BASEDIR/sql-bench/
2239
  savedir=`pwd`
2240
  cd $BENCHDIR
2241
  if [ -z "$1" ]
2242
  then
2243
    ./run-all-tests --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS --log
2244
  else
2245
    if [ -x "./$1" ]
2246
    then
2247
       ./$1 --socket=$MASTER_MYSOCK --user=root $EXTRA_BENCH_ARGS
2248
    else
2249
      echo "benchmark $1 not found"
2250
    fi
2251
  fi
2252
  cd $savedir
2253
  mysql_stop
2254
  exit
2255
fi
2256
2257
#
2258
# Stress testing
2259
#
2260
if [ "$DO_STRESS" = 1 ] 
2261
then
2262
2263
  if [ -n "$1" ] ; then
2264
    STRESS_TEST="$1";
2265
  fi                      
2266
 
2267
  if [ $USE_RUNNING_SERVER -eq 0 ] ; then 
2268
    start_master
2269
  fi
2270
 
2271
  run_stress_test
2272
2273
  if [ $USE_RUNNING_SERVER -eq 0 ] ; then
2274
    mysql_stop
2275
  fi
2276
  
2277
  exit
2278
2279
fi
2280
2281
2282
$ECHO
2283
if [ x$USE_TIMER = x1 ] ; then
2284
$ECHO "TEST                            RESULT        TIME (ms)"
2285
else
2286
$ECHO "TEST                            RESULT"
2287
fi
2288
$ECHO $DASH72
2289
2290
if [ -z "$1" ] ;
2291
then
2292
  if [ x$RECORD = x1 ]; then
2293
    $ECHO "Will not run in record mode without a specific test case."
2294
  else
2295
    for tf in $TESTDIR/*.$TESTSUFFIX
2296
    do
2297
      run_testcase $tf
2298
    done
2299
    $RM -f $TIMEFILE	# Remove for full test
2300
  fi
2301
else
2302
  while [ ! -z "$1" ]; do
2303
    tname=`$BASENAME $1 .test`
2304
    tf=$TESTDIR/$tname.$TESTSUFFIX
2305
    if [ -f $tf ] ; then
2306
      run_testcase $tf
2307
    else
2308
      $ECHO "Test case $tf does not exist."
2309
    fi
2310
    shift
2311
  done
2312
fi
2313
2314
$ECHO $DASH72
2315
$ECHO
2316
2317
if [ -z "$DO_GDB" ] && [ $USE_RUNNING_SERVER -eq 0 ] && [ -z "$DO_DDD" ]
2318
then
2319
    mysql_stop
2320
fi
2321
report_stats
2322
$ECHO
2323
2324
[ "$DO_GCOV" ] && gcov_collect # collect coverage information
2325
[ "$DO_GPROF" ] && gprof_collect # collect coverage information
2326
2327
if [ $TOT_FAIL -ne 0 ]; then
2328
  $ECHO "mysql-test-run in $TEST_MODE mode: *** Failing the test(s):$FAILED_CASES"
2329
  $ECHO
2330
  exit 1
2331
fi
2332
if [ $GOT_WARNINGS -ne 0 ]; then
2333
  exit 1
2334
fi
2335
exit 0