WL#4189

 - dynamic configuration support
 - safe process
 - cleanups
 - create new suite for fedarated
parent 601cb9f9
......@@ -2174,8 +2174,19 @@ void eval_expr(VAR *v, const char *p, const char **p_end)
int open_file(const char *name)
{
char buff[FN_REFLEN];
size_t length;
DBUG_ENTER("open_file");
DBUG_PRINT("enter", ("name: %s", name));
/* Extract path from current file and try it as base first */
if (dirname_part(buff, cur_file->file_name, &length))
{
strxmov(buff, buff, name, NullS);
if (access(buff, F_OK) == 0){
DBUG_PRINT("info", ("The file exists"));
name= buff;
}
}
if (!test_if_hard_path(name))
{
strxmov(buff, opt_basedir, name, NullS);
......
......@@ -2681,7 +2681,7 @@ AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
cmd-line-utils/Makefile cmd-line-utils/libedit/Makefile dnl
libmysqld/Makefile libmysqld/examples/Makefile dnl
mysql-test/Makefile dnl
mysql-test/ndb/Makefile netware/Makefile sql-bench/Makefile dnl
netware/Makefile sql-bench/Makefile dnl
include/mysql_version.h plugin/Makefile win/Makefile)
AC_CONFIG_COMMANDS([default], , test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h)
......
......@@ -17,115 +17,22 @@
## Process this file with automake to create Makefile.in
SUBDIRS = ndb
testdir = $(prefix)/mysql-test
benchdir_root= $(prefix)
testdir = $(benchdir_root)/mysql-test
EXTRA_SCRIPTS = mysql-test-run-shell.sh install_test_db.sh \
valgrind.supp $(PRESCRIPTS)
EXTRA_DIST = $(EXTRA_SCRIPTS) suite
GENSCRIPTS = mysql-test-run-shell install_test_db mtr mysql-test-run
PRESCRIPTS = mysql-test-run.pl mysql-stress-test.pl
test_SCRIPTS = $(GENSCRIPTS) $(PRESCRIPTS)
CLEANFILES = $(GENSCRIPTS)
EXTRA_DIST = README \
mysql-test-run.pl \
mysql-stress-test.pl \
t r include suite extra \
lib std_data \
valgrind.supp
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I..
test_SCRIPTS = mtr mysql-test-run
CLEANFILES = $(test_SCRIPTS)
dist-hook:
mkdir -p \
$(distdir)/t \
$(distdir)/extra/binlog_tests \
$(distdir)/extra/rpl_tests \
$(distdir)/r \
$(distdir)/include \
$(distdir)/std_data \
$(distdir)/std_data/ndb_backup50 \
$(distdir)/std_data/ndb_backup51 \
$(distdir)/std_data/ndb_backup51_data_be \
$(distdir)/std_data/ndb_backup51_data_le \
$(distdir)/lib \
$(distdir)/lib/My
-$(INSTALL_DATA) $(srcdir)/t/*.def $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.test $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.imtest $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.sql $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.disabled $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.opt $(srcdir)/t/*.slave-mi $(distdir)/t
-$(INSTALL_SCRIPT) $(srcdir)/t/*.sh $(distdir)/t
$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.test $(distdir)/extra/binlog_tests
$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.test $(distdir)/extra/rpl_tests
-$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.opt $(distdir)/extra/binlog_tests
-$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.opt $(distdir)/extra/rpl_tests
$(INSTALL_DATA) $(srcdir)/include/*.inc $(distdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.sql $(distdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.test $(distdir)/include
$(INSTALL_DATA) $(srcdir)/r/*.result $(srcdir)/r/*.require $(distdir)/r
$(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Index.xml $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.dat $(srcdir)/std_data/*.000001 $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.pem $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.frm $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.MY* $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup50/BACKUP* $(distdir)/std_data/ndb_backup50
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51/BACKUP* $(distdir)/std_data/ndb_backup51
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_be/BACKUP* $(distdir)/std_data/ndb_backup51_data_be
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_le/BACKUP* $(distdir)/std_data/ndb_backup51_data_le
$(INSTALL_DATA) $(srcdir)/lib/*.pl $(distdir)/lib
$(INSTALL_DATA) $(srcdir)/lib/My/*.pm $(distdir)/lib/My
-rm -rf `find $(distdir)/suite -type d -name SCCS` $(distdir)/suite/row_lock
# Install all files and files in directories listed in EXTRA_DIST
install-data-local:
$(mkinstalldirs) \
$(DESTDIR)$(testdir)/t \
$(DESTDIR)$(testdir)/extra/binlog_tests \
$(DESTDIR)$(testdir)/extra/rpl_tests \
$(DESTDIR)$(testdir)/r \
$(DESTDIR)$(testdir)/include \
$(DESTDIR)$(testdir)/std_data \
$(DESTDIR)$(testdir)/std_data/ndb_backup50 \
$(DESTDIR)$(testdir)/std_data/ndb_backup51 \
$(DESTDIR)$(testdir)/std_data/ndb_backup51_data_be \
$(DESTDIR)$(testdir)/std_data/ndb_backup51_data_le \
$(DESTDIR)$(testdir)/lib \
$(DESTDIR)$(testdir)/lib/My
$(INSTALL_DATA) $(srcdir)/README $(DESTDIR)$(testdir)
-$(INSTALL_DATA) $(srcdir)/t/*.def $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.test $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.imtest $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.sql $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.disabled $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.opt $(DESTDIR)$(testdir)/t
-$(INSTALL_SCRIPT) $(srcdir)/t/*.sh $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.slave-mi $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/r/*.result $(DESTDIR)$(testdir)/r
$(INSTALL_DATA) $(srcdir)/r/*.require $(DESTDIR)$(testdir)/r
$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.test $(DESTDIR)$(testdir)/extra/binlog_tests
$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.test $(DESTDIR)$(testdir)/extra/rpl_tests
-$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.opt $(DESTDIR)$(testdir)/extra/binlog_tests
-$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.opt $(DESTDIR)$(testdir)/extra/rpl_tests
$(INSTALL_DATA) $(srcdir)/include/*.inc $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.sql $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.test $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/std_data/*.dat $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.*001 $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Index.xml $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.pem $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.frm $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.MY* $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup50/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup50
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_be/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51_data_be
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_le/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51_data_le
$(INSTALL_DATA) $(srcdir)/lib/*.pl $(DESTDIR)$(testdir)/lib
$(INSTALL_DATA) $(srcdir)/lib/My/*.pm $(DESTDIR)$(testdir)/lib/My
for f in `(cd $(srcdir); find suite -type f | egrep -v 'SCCS|row_lock')`; \
for f in `(cd $(srcdir); find $(EXTRA_DIST) -type f)`; \
do \
d=$(DESTDIR)$(testdir)/`dirname $$f`; \
mkdir -p $$d ; \
......@@ -145,31 +52,5 @@ mysql-test-run:
$(RM) -f mysql-test-run
$(LN_S) mysql-test-run.pl mysql-test-run
SUFFIXES = .sh
.sh:
@RM@ -f $@ $@-t
@SED@ \
-e 's!@''testdir''@!$(testdir)!g' \
-e 's!@''bindir''@!$(bindir)!g' \
-e 's!@''scriptdir''@!$(bindir)!g' \
-e 's!@''prefix''@!$(prefix)!g' \
-e 's!@''datadir''@!$(datadir)!g' \
-e 's!@''localstatedir''@!$(localstatedir)!g' \
-e 's!@''libexecdir''@!$(libexecdir)!g' \
-e 's!@''PERL''@!@PERL@!' \
-e 's!@''VERSION''@!@VERSION@!' \
-e 's!@''MYSQL_TCP_PORT''@!@MYSQL_TCP_PORT@!' \
-e 's!@''MYSQL_TCP_PORT_DEFAULT''@!@MYSQL_TCP_PORT_DEFAULT@!' \
-e 's!@''MYSQL_BASE_VERSION''@!@MYSQL_BASE_VERSION@!' \
-e 's!@''MYSQL_UNIX_ADDR''@!@MYSQL_UNIX_ADDR@!' \
-e 's!@''MYSQL_TCP_PORT''@!@MYSQL_TCP_PORT@!' \
-e 's!@''MYSQL_NO_DASH_VERSION''@!@MYSQL_NO_DASH_VERSION@!' \
-e 's!@''MYSQL_SERVER_SUFFIX''@!@MYSQL_SERVER_SUFFIX@!' \
-e 's!@''USE_NDBCLUSTER''@!@TEST_NDBCLUSTER@!g' \
$< > $@-t
@CHMOD@ +x $@-t
@MV@ $@-t $@
# Don't update the files from bitkeeper
%::SCCS/s.%
#! /bin/sh
# This script is a hack for lazy developers who want to get a quick
# start on the result file. The code here is rather dirty, but it works
# If you have a spare moment feel free to improve it - the right way is
# to start mysqld yourself and run mysqltest -r
RESULT_DIR=r
if [ -z "$EDITOR" ] ; then
EDITOR=vi
fi
function die()
{
echo $1
exit 1
}
function usage()
{
echo "Usage: $0 test_name"
exit 1
}
test_name=$1
[ -z "$test_name" ] && usage
result_file=$RESULT_DIR/$test_name.result
reject_file=$RESULT_DIR/$test_name.reject
[ -f $result_file ] && die "result file $result_file has already been created"
touch $result_file
echo "Running the test case against empty file, will fail, but don't worry"
./mysql-test-run --local $test_name
if [ -f $reject_file ] ; then
echo "Below are the contents of the reject file:"
echo "-----start---------------------"
cat $reject_file
echo "-----end-----------------------"
echo "Is this the output you expected from your test case?(y/n)[n]"
read yes_no
if [ x$yes_no = xy ] ; then
echo "Press any key to edit it in $EDITOR, or Ctrl-C to abort"
read junk
$EDITOR $reject_file
edited="edited"
fi
echo "Save $edited file as master result? (y/n)[y]"
read yes_no
if [ x$yes_no != xn ]; then
mv $reject_file $result_file
fi
else
echo "Your test failed so bad, it did not even produce a reject file"
echo "You need to fix your bugs in the test case, the code, or both"
exit 1
fi
......@@ -7,7 +7,7 @@
-- source include/have_log_bin.inc
# The server need to be started in $MYSQLTEST_VARDIR since it
# uses ../std_data_ln/
# uses ../../std_data/
-- source include/uses_vardir.inc
--disable_warnings
......@@ -114,7 +114,7 @@ insert into t1 values(1);
insert ignore into t1 values(1);
replace into t1 values(100);
create table t2 (a varchar(200)) engine=blackhole;
eval load data infile '../std_data_ln/words.dat' into table t2;
eval load data infile '../../std_data/words.dat' into table t2;
alter table t1 add b int;
alter table t1 drop b;
create table t3 like t1;
......
......@@ -16,7 +16,8 @@ source include/show_binlog_events.inc;
# escaped).
flush logs;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001
let $MYSQLD_DATADIR= `select @@datadir`;
--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
drop table t2;
# End of 4.1 tests
......@@ -282,7 +282,7 @@ CREATE TABLE t5 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
# execute
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
load data infile '../../std_data/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
# check
select * from t4;
select count(*) from t1 /* must be 2 */;
......
......@@ -20,7 +20,8 @@
eval create table t1 (a int) engine=$engine_type;
flush tables;
system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYI ;
let $MYSQLD_DATADIR= `select @@datadir`;
system rm $MYSQLD_DATADIR/test/t1.MYI ;
drop table if exists t1;
save_master_pos;
connection slave;
......
......@@ -23,12 +23,12 @@ connection master;
select last_insert_id();
create table t1(a int not null auto_increment, b int, primary key(a) );
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
# verify that LAST_INSERT_ID() is set by LOAD DATA INFILE
select last_insert_id();
create temporary table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60));
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
create table t3 (day date,id int(9),category enum('a','b','c'),name varchar(60));
insert into t3 select * from t2;
......@@ -63,7 +63,7 @@ sync_with_master;
insert into t1 values(1,10);
connection master;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
......@@ -87,7 +87,7 @@ connection master;
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
# The SQL slave thread should be stopped now.
......@@ -112,7 +112,7 @@ connection master;
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
# The SQL slave thread should be stopped now.
......@@ -132,7 +132,7 @@ reset master;
eval create table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60),
unique(day)) engine=$engine_type; # no transactions
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
'\n##\n' starting by '>' ignore 1 lines;
select * from t2;
......@@ -148,7 +148,7 @@ alter table t2 drop key day;
connection master;
delete from t2;
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
'\n##\n' starting by '>' ignore 1 lines;
connection slave;
......@@ -162,7 +162,7 @@ drop table t1;
CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=INNODB;
--error ER_DUP_ENTRY
LOAD DATA INFILE "../std_data_ln/words.dat" INTO TABLE t1;
LOAD DATA INFILE "../../std_data/words.dat" INTO TABLE t1;
--disable_warnings
DROP TABLE IF EXISTS t1;
......
......@@ -33,7 +33,7 @@ eval create table t1(n int not null auto_increment primary key)ENGINE=$engine_ty
insert into t1 values (NULL);
drop table t1;
eval create table t1 (word char(20) not null)ENGINE=$engine_type;
load data infile '../std_data_ln/words.dat' into table t1 ignore 1 lines;
load data infile '../../std_data/words.dat' into table t1 ignore 1 lines;
select count(*) from t1;
--replace_result $VERSION VERSION
--replace_column 2 # 5 #
......
CREATE TABLE t1 (word CHAR(20) NOT NULL);
LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1;
LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval LOAD DATA LOCAL INFILE '$MYSQL_TEST_DIR/std_data/words.dat' INTO TABLE t1;
SELECT * FROM t1 ORDER BY word LIMIT 10;
......
......@@ -160,7 +160,8 @@ select hex(c1), hex(c2) from t1;
connection master;
# Let's have a look at generated SETs.
--replace_result $MYSQLTEST_VARDIR MYSQL_TEST_DIR/var
#--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001
let $MYSQLD_DATADIR= `select @@datadir`;
#--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
drop table t1;
sync_slave_with_master;
......
......@@ -2,7 +2,7 @@
-- source include/master-slave.inc
create table t1 (word char(20) not null);
load data infile '../std_data_ln/words.dat' into table t1;
load data infile '../../std_data/words.dat' into table t1;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval load data local infile '$MYSQL_TEST_DIR/std_data/words.dat' into table t1;
select * from t1 limit 10;
......
......@@ -156,7 +156,8 @@ connection master;
# Let's have a look at generated SETs.
flush logs;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001
let $MYSQLD_DATADIR= `select @@datadir`;
--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
drop table t1;
sync_slave_with_master;
......
#! /bin/sh
# Sasha's hack to fix results generated with mysql-test-run --record
# to be version and test port independent. In some cases, further minor
# manual edititing may be required, but most of the time it should not
# happen
#It is assumed we are running the script in mysql-test directory
VERSION=4.0.1-alpha-debug-log
TEST_CASE=$1
if [ -z "$TEST_CASE" ] ;
then
echo "usage: $0 test_case_name"
exit 1
fi
../extra/replace $VERSION '$VERSION' 9306 '$MASTER_MYPORT' 9307 \
'$SLAVE_MYPORT' \\ \\\\ -- r/$TEST_CASE.result
# Use default setting for mysqld processes
!include default_mysqld.cnf
[mysqld.1]
# Run the master.sh script before starting this process
#!run-master-sh
log-bin= master-bin
[mysqlbinlog]
disable-force-if-open
# mysql_fix_privilege_tables.sh does not read from [client] so it
# need its own section
[mysql_fix_privilege_tables]
socket= @client.socket
port= @client.port
user= @client.user
password= @client.password
[ENV]
MASTER_MYPORT= @mysqld.1.port
MASTER_MYSOCK= @mysqld.1.socket
# Default values that applies to all MySQL Servers
[mysqld]
open-files-limit= 1024
local-infile
default-character-set= latin1
# Increase default connect_timeout to avoid intermittent
# disconnects when test servers are put under load see BUG#28359
connect-timeout= 60
log-bin-trust-function-creators=1
key_buffer_size= 1M
sort_buffer= 256K
max_heap_table_size= 1M
loose-innodb_data_file_path= ibdata1:10M:autoextend
set-variable= slave_net_timeout=120
[cluster_config]
MaxNoOfSavedMessages= 1000
MaxNoOfConcurrentTransactions= 64
MaxNoOfConcurrentOperations= 10000
DataMemory= 20M
IndexMemory= 1M
Diskless= 0
TimeBetweenWatchDogCheck= 30000
MaxNoOfOrderedIndexes= 32
MaxNoOfAttributes= 2048
TimeBetweenGlobalCheckpoints= 500
NoOfFragmentLogFiles= 4
FragmentLogFileSize= 12M
DiskPageBufferMemory= 4M
# O_DIRECT has issues on 2.4 whach have not been handled, Bug #29612
#ODirect= 1
# the following parametes just function as a small regression
# test that the parameter exists
InitialNoOfOpenFiles= 27
# Increase timeouts for slow test-machines
HeartbeatIntervalDbDb= 30000
HeartbeatIntervalDbApi= 30000
#TransactionDeadlockDetectionTimeout= 7500
disable_query_log;
--require r/true.require
select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'blackhole';
enable_query_log;
if (`select (support = 'YES' or support = 'DEFAULT')=0 from information_schema.engines where engine = 'blackhole'`){
skip Need blackhole engine;
}
#
# Check if the variable MYSQL_BUG25714 is set
#
--require r/have_bug25714.require
disable_query_log;
eval select LENGTH("$MYSQL_BUG25714") > 0 as "have_bug25714_exe";
enable_query_log;
disable_query_log;
--require r/true.require
select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'federated';
enable_query_log;
--require r/have_ndbapi_examples.require
disable_query_log;
eval select LENGTH("$MY_NDB_EXAMPLES_BINARY") > 0 as "have_ndb_example";
eval select LENGTH("$NDB_EXAMPLES_BINARY") > 0 as "have_ndb_example";
enable_query_log;
......@@ -7,16 +7,20 @@ eval SET SESSION STORAGE_ENGINE = $engine_type;
drop table if exists t1;
--enable_warnings
let $load_file= $MYSQLTEST_VARDIR/std_data/loaddata2.dat;
# NDB does not support the create option 'Binlog of table with BLOB attribute and no PK'
# So use a dummy PK here.
create table t1 (id int unsigned not null auto_increment primary key, a text, b text);
start transaction;
load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''' (a, b);
--replace_result $load_file LOAD_FILE
eval load data infile '$load_file' into table t1 fields terminated by ',' enclosed by '''' (a, b);
commit;
select count(*) from t1;
truncate table t1;
start transaction;
load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''' (a, b);
--replace_result $load_file LOAD_FILE
eval load data infile '$load_file' into table t1 fields terminated by ',' enclosed by '''' (a, b);
rollback;
select count(*) from t1;
......
......@@ -623,7 +623,8 @@ DROP TABLE t1,t2,t3;
#
create table t1 (a int) engine=innodb;
copy_file $MYSQLTEST_VARDIR/master-data/test/t1.frm $MYSQLTEST_VARDIR/master-data/test/bug29807.frm;
let $MYSQLD_DATADIR= `select @@datadir`;
copy_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/bug29807.frm;
--error 1146
select * from bug29807;
drop table t1;
......
......@@ -2,23 +2,21 @@
# By JBM 2006-02-16 So that the code is not repeated #
# in test cases and can be reused. #
######################################################
--exec $NDB_MGM --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -e "start backup" >> $NDB_TOOLS_OUTPUT
--exec $NDB_MGM --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -e "start backup" >> $NDB_TOOLS_OUTPUT
# there is no neat way to find the backupid, this is a hack to find it...
let $dump_file= $MYSQLTEST_VARDIR/tmp/tmp.dat;
--exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="$NDB_CONNECTSTRING" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $dump_file
--exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $MYSQLTEST_VARDIR/tmp.dat
CREATE TEMPORARY TABLE test.backup_info (id INT, backup_id INT) ENGINE = HEAP;
CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP;
--replace_result $dump_file DUMP_FILE
eval LOAD DATA INFILE '$dump_file' INTO TABLE test.backup_info FIELDS TERMINATED BY ',';
DELETE FROM test.backup_info;
LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ',';
--replace_column 1 <the_backup_id>
SELECT @the_backup_id:=backup_id FROM test.backup_info;
# Load backup id into environment variable
let the_backup_id=`SELECT backup_id from test.backup_info`;
DROP TABLE test.backup_info;
let the_backup_id=`select @the_backup_id`;
remove_file $dump_file;
DROP TABLE test.backup_info;
......@@ -3,6 +3,6 @@
# in test cases and can be reused. #
######################################################
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -p 8 -b $the_backup_id -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -p 8 -b $the_backup_id -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
......@@ -3,9 +3,9 @@
# in test cases and can be reused. #
######################################################
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT_SLAVE" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING_SLAVE" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT_SLAVE" -p 8 -b $the_backup_id -n 2 -r -e --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING_SLAVE" -p 8 -b $the_backup_id -n 2 -r -e --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
......@@ -19,12 +19,6 @@
# #
###################################################################
--disable_query_log
eval set @USE_RUNNING_SERVER= '$USE_RUNNING_SERVER';
--require r/testdb_only.require
SELECT 'use extern server'
AS "Variable_name ",
IF(@USE_RUNNING_SERVER= '1','YES',
IF(@USE_RUNNING_SERVER= '0','NO','UNEXPECTED'))
AS "Value" ;
--enable_query_log
if ($USE_RUNNING_SERVER){
skip Not with extern server;
}
#!/bin/sh
# Copyright (C) 1997-2006 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This scripts creates the privilege tables db, host, user, tables_priv,
# columns_priv in the mysql database, as well as the func table.
if [ x$1 = x"--bin" ]; then
shift 1
BINARY_DIST=1
bindir=../bin
scriptdir=bin
libexecdir=../libexec
# Check if it's a binary distribution or a 'make install'
if test -x ../libexec/mysqld
then
execdir=../libexec
elif test -x ../../sbin/mysqld # RPM installation
then
execdir=../../sbin
bindir=../../bin
scriptdir=../bin
libexecdir=../../libexec
else
execdir=../bin
fi
fix_bin=mysql-test
else
execdir=../sql
bindir=../client
fix_bin=.
scriptdir=scripts
libexecdir=../libexec
fi
vardir=var
logdir=$vardir/log
if [ x$1 = x"-slave" ]
then
shift 1
data=var/slave-data
else
if [ x$1 = x"-1" ]
then
data=var/master-data1
else
data=var/master-data
fi
fi
ldata=$fix_bin/$data
mdata=$data/mysql
EXTRA_ARG=""
mysqld=
if test -x $execdir/mysqld
then
mysqld=$execdir/mysqld
else
if test ! -x $libexecdir/mysqld
then
echo "mysqld is missing - looked in $execdir and in $libexecdir"
exit 1
else
mysqld=$libexecdir/mysqld
fi
fi
# On IRIX hostname is in /usr/bsd so add this to the path
PATH=$PATH:/usr/bsd
hostname=`hostname` # Install this too in the user table
hostname="$hostname%" # Fix if not fully qualified hostname
#create the directories
[ -d $vardir ] || mkdir $vardir
[ -d $logdir ] || mkdir $logdir
# Create database directories mysql & test
if [ -d $data ] ; then rm -rf $data ; fi
mkdir $data $data/mysql $data/test
#for error messages
if [ x$BINARY_DIST = x1 ] ; then
basedir=..
else
basedir=.
EXTRA_ARG="--windows"
fi
INSTALL_CMD="$scriptdir/mysql_install_db --no-defaults $EXTRA_ARG --basedir=$basedir --datadir=mysql-test/$ldata --srcdir=."
echo "running $INSTALL_CMD"
cd ..
if $INSTALL_CMD
then
exit 0
else
echo "Error executing mysqld --bootstrap"
exit 1
fi
......@@ -4,6 +4,7 @@ package My::Config::Option;
use strict;
use warnings;
use Carp;
sub new {
......@@ -31,7 +32,7 @@ package My::Config::Group;
use strict;
use warnings;
use Carp;
sub new {
my ($class, $group_name)= @_;
......@@ -68,7 +69,7 @@ sub remove {
return undef unless defined $option;
# Remove from the hash
delete($self->{options_by_name}->{$option_name}) or die;
delete($self->{options_by_name}->{$option_name}) or croak;
# Remove from the array
@{$self->{options}}= grep { $_->name ne $option_name } @{$self->{options}};
......@@ -88,6 +89,33 @@ sub name {
return $self->{name};
}
sub suffix {
my ($self)= @_;
# Everything in name from the last .
my @parts= split(/\./, $self->{name});
my $suffix= pop(@parts);
return ".$suffix";
}
sub after {
my ($self, $prefix)= @_;
die unless defined $prefix;
# everything after $prefix
my $name= $self->{name};
if ($name =~ /^\Q$prefix\E(.*)$/)
{
return $1;
}
die "Failed to extract the value after '$prefix' in $name";
}
sub split {
my ($self)= @_;
# Return an array with name parts
return split(/\./, $self->{name});
}
#
# Return a specific option in the group
......@@ -100,23 +128,37 @@ sub option {
#
# Return a specific value for an option in the group
# Return value for an option in the group, fail if it does not exist
#
sub value {
my ($self, $option_name)= @_;
my $option= $self->option($option_name);
die "No option named '$option_name' in this group"
croak "No option named '$option_name' in group '$self->{name}'"
if ! defined($option);
return $option->value();
}
#
# Return value for an option if it exist
#
sub if_exist {
my ($self, $option_name)= @_;
my $option= $self->option($option_name);
return undef if ! defined($option);
return $option->value();
}
package My::Config;
use strict;
use warnings;
use Carp;
use IO::File;
use File::Basename;
......@@ -132,13 +174,13 @@ sub new {
my $self= bless { groups => [] }, $class;
my $F= IO::File->new($path, "<")
or die "Could not open '$path': $!";
or croak "Could not open '$path': $!";
while ( my $line= <$F> ) {
chomp($line);
# [group]
if ( $line =~ /\[(.*)\]/ ) {
if ( $line =~ /^\[(.*)\]/ ) {
# New group found
$group_name= $1;
#print "group: $group_name\n";
......@@ -149,7 +191,7 @@ sub new {
# Magic #! comments
elsif ( $line =~ /^#\!/) {
my $magic= $line;
die "Found magic comment '$magic' outside of group"
croak "Found magic comment '$magic' outside of group"
unless $group_name;
#print "$magic\n";
......@@ -171,8 +213,13 @@ sub new {
# !include <filename>
elsif ( $line =~ /^\!include\s*(.*?)\s*$/ ) {
my $include_file_name= dirname($path)."/".$1;
# Check that the file exists
die "The include file '$include_file_name' does not exist"
# Check that the file exists relative to path of first config file
if (! -f $include_file_name){
# Try to include file relativ to current dir
$include_file_name= $1;
}
croak "The include file '$include_file_name' does not exist"
unless -f $include_file_name;
$self->append(My::Config->new($include_file_name));
......@@ -182,7 +229,7 @@ sub new {
elsif ( $line =~ /^([\@\w-]+)\s*$/ ) {
my $option= $1;
die "Found option '$option' outside of group"
croak "Found option '$option' outside of group"
unless $group_name;
#print "$option\n";
......@@ -194,13 +241,13 @@ sub new {
my $option= $1;
my $value= $2;
die "Found option '$option=$value' outside of group"
croak "Found option '$option=$value' outside of group"
unless $group_name;
#print "$option=$value\n";
$self->insert($group_name, $option, $value);
} else {
die "Unexpected line '$line' found in '$path'";
croak "Unexpected line '$line' found in '$path'";
}
}
......@@ -231,6 +278,7 @@ sub insert {
# Add the option to the group
$group->insert($option, $value, $if_not_exist);
}
return $group;
}
#
......@@ -240,11 +288,11 @@ sub remove {
my ($self, $group_name, $option_name)= @_;
my $group= $self->group($group_name);
die "group '$group_name' does not exist"
croak "group '$group_name' does not exist"
unless defined($group);
$group->remove($option_name) or
die "option '$option_name' does not exist";
croak "option '$option_name' does not exist";
}
......@@ -267,10 +315,10 @@ sub group_exists {
#
sub _group_insert {
my ($self, $group_name)= @_;
caller eq __PACKAGE__ or die;
caller eq __PACKAGE__ or croak;
# Check that group does not already exist
die "Group already exists" if $self->group_exists($group_name);
croak "Group already exists" if $self->group_exists($group_name);
my $group= My::Config::Group->new($group_name);
push(@{$self->{groups}}, $group);
......@@ -354,11 +402,11 @@ sub value {
my ($self, $group_name, $option_name)= @_;
my $group= $self->group($group_name);
die "group '$group_name' does not exist"
croak "group '$group_name' does not exist"
unless defined($group);
my $option= $group->option($option_name);
die "option '$option_name' does not exist"
croak "option '$option_name' does not exist"
unless defined($option);
return $option->value();
......@@ -372,7 +420,7 @@ sub exists {
my ($self, $group_name, $option_name)= @_;
my $group= $self->group($group_name);
die "group '$group_name' does not exist"
croak "group '$group_name' does not exist"
unless defined($group);
my $option= $group->option($option_name);
......@@ -412,11 +460,11 @@ sub stringify {
# Save the config to named file
#
sub save {
my ($self, $path)= @_;
my $F= IO::File->new($path, ">")
or die "Could not open '$path': $!";
print $F $self;
undef $F; # Close the file
my ($self, $path)= @_;
my $F= IO::File->new($path, ">")
or croak "Could not open '$path': $!";
print $F $self;
undef $F; # Close the file
}
1;
This diff is collapsed.
# -*- cperl -*-
package My::File::Path;
use strict;
#
# File::Path::rmtree has a problem with deleting files
# and directories where it hasn't got read permission
#
# Patch this by installing a 'rmtree' function in local
# scope that first chmod all files to 0777 before calling
# the original rmtree function.
#
# This is almost gone in version 1.08 of File::Path -
# but unfortunately some hosts still suffers
# from this also in 1.08
#
use Exporter;
use base "Exporter";
our @EXPORT= qw / rmtree mkpath copytree /;
use File::Find;
use File::Path;
use File::Copy;
use Carp;
no warnings 'redefine';
sub rmtree {
my ($dir)= @_;
#
# chmod all files to 0777 before calling rmtree
#
find( {
no_chdir => 1,
wanted => sub {
chmod(0777, $_)
or warn("couldn't chmod(0777, $_): $!");
}
},
$dir
);
# Call rmtree from File::Path
goto &File::Path::rmtree;
};
sub mkpath {
goto &File::Path::mkpath;
};
sub copytree {
my ($from_dir, $to_dir) = @_;
die "Usage: copytree(<fromdir>, <todir>" unless @_ == 2;
mkpath("$to_dir");
opendir(DIR, "$from_dir")
or croak("Can't find $from_dir$!");
for(readdir(DIR)) {
next if "$_" eq "." or "$_" eq "..";
# Skip SCCS/ directories
next if "$_" eq "SCCS";
if ( -d "$from_dir/$_" )
{
copytree("$from_dir/$_", "$to_dir/$_");
next;
}
copy("$from_dir/$_", "$to_dir/$_");
}
closedir(DIR);
}
1;
# -*- cperl -*-
# Copyright (C) 2004-2006 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package My::Find;
#
# Utility functions to find files in a MySQL source or bindist
#
use strict;
use base qw(Exporter);
our @EXPORT= qw(my_find_bin my_find_dir);
our $vs_config_dir;
my $is_win= ($^O eq "MSWin32" or $^O eq "Win32");
#
# my_find_bin - find an executable with "name_1...name_n" in
# paths "path_1...path_n" and return the full path
#
# Example:
# my $mysqld_exe= my_find_bin($basedir.
# ["sql", "bin"],
# ["mysqld", "mysqld-debug"]);
# my $mysql_exe= my_find_bin($basedir,
# ["client", "bin"],
# "mysql");
#
# NOTE: The function honours MTR_VS_CONFIG environment variable
#
#
sub my_find_bin {
my ($base, $paths, $names)= @_;
die "usage: my_find_bin(<base>, <paths>, <names>)"
unless @_ == 3;
# -------------------------------------------------------
# Find and return the first executable
# -------------------------------------------------------
foreach my $path (my_find_paths($base, $paths, $names)) {
return $path if ( -x $path or ($is_win and -f $path) );
}
find_error($base, $paths, $names);
}
#
# my_find_dir - find the first existing directory in one of
# the given paths
#
# Example:
# my $charset_set= my_find_dir($basedir,
# ["mysql/share","sql/share", "share"],
# ["charset"]);
# or
# my $charset_set= my_find_dir($basedir,
# ['client_release', 'client_debug',
# 'client', 'bin']);
#
# NOTE: The function honours MTR_VS_CONFIG environment variable
#
#
sub my_find_dir {
my ($base, $paths, $dirs)= @_;
die "usage: my_find_dir(<base>, <paths>[, <dirs>])"
unless (@_ == 3 or @_ == 2);
# -------------------------------------------------------
# Find and return the first directory
# -------------------------------------------------------
foreach my $path (my_find_paths($base, $paths, $dirs)) {
return $path if ( -d $path );
}
find_error($base, $paths, $dirs);
}
sub my_find_paths {
my ($base, $paths, $names)= @_;
# Convert the arguments into two normal arrays to ease
# further mappings
my (@names, @paths);
push(@names, ref $names eq "ARRAY" ? @$names : $names);
push(@paths, ref $paths eq "ARRAY" ? @$paths : $paths);
#print "base: $base\n";
#print "names: @names\n";
#print "paths: @paths\n";
# User can select to look in a special build dir
# which is a subdirectory of any of the paths
my @extra_dirs;
my $build_dir= $vs_config_dir || $ENV{MTR_VS_CONFIG} || $ENV{MTR_BUILD_DIR};
push(@extra_dirs, $build_dir) if defined $build_dir;
# -------------------------------------------------------
# Windows specific
# -------------------------------------------------------
if ($is_win) {
# Append .exe to names, if name does not already have extension
map { $_.=".exe" unless /\.(.*)+$/ } @names;
# Add the default extra build dirs unless a specific one has
# already been selected
push(@extra_dirs,
("release",
"relwithdebinfo",
"debug")) if @extra_dirs == 0;
}
#print "extra_build_dir: @extra_dirs\n";
# -------------------------------------------------------
# Build cross product of "paths * extra_build_dirs"
# -------------------------------------------------------
push(@paths, map { my $path= $_;
map { "$path/$_" } @extra_dirs
} @paths);
#print "paths: @paths\n";
# -------------------------------------------------------
# Build cross product of "paths * names"
# -------------------------------------------------------
@paths= map { my $path= $_;
map { "$path/$_" } @names
} @paths;
#print "paths: @paths\n";
# -------------------------------------------------------
# Prepend base to all paths
# -------------------------------------------------------
@paths= map { "$base/$_" } @paths;
#print "paths: @paths\n";
# -------------------------------------------------------
# Return the list of paths
# -------------------------------------------------------
return @paths;
}
sub find_error {
my ($base, $paths, $names)= @_;
my (@names, @paths);
push(@names, ref $names eq "ARRAY" ? @$names : $names);
push(@paths, ref $paths eq "ARRAY" ? @$paths : $paths);
die "Could not find ",
join(", ", @names), " in ",
join(", ", my_find_paths($base, $paths, $names));
}
1;
This diff is collapsed.
# -*- cperl -*-
# Copyright (C) 2004-2006 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This is a library file used by the Perl version of mysql-test-run,
# and is part of the translation of the Bourne shell script with the
# same name.
use strict;
package My::SafeProcess::Base;
#
# Utility functions for Process management
#
use Carp;
use IO::Pipe;
use base qw(Exporter);
our @EXPORT= qw(create_process);
sub winpid {
my ($pid)= @_;
return undef unless $^O eq "cygwin";
# The child get a new winpid when the exec takes
# place, wait for that to happen
my $winpid;
my $delay= 0;
do
{
# Yield to the child
select(undef, undef, undef, $delay);
# Increase the delay slightly for each loop
$delay += 0.000001;
$winpid= Cygwin::pid_to_winpid($pid);
} until ($winpid != $pid);
return $winpid;
}
#
# safe_fork
# Retry a couple of times if fork returns EAGAIN
#
sub _safe_fork {
my $retries= 5;
my $pid;
FORK:
{
$pid= fork;
if ( not defined($pid)) {
croak("fork failed after: $!") if (!$retries--);
warn("fork failed sleep 1 second and redo: $!");
sleep(1);
redo FORK;
}
}
return $pid;
};
#
# Decode exit status
#
sub exit_status {
my $self= shift;
my $raw= $self->{EXIT_STATUS};
croak("Can't call exit_status before process has died")
unless defined $raw;
if ($raw & 127)
{
# Killed by signal
my $signal_num= $raw & 127;
my $dumped_core= $raw & 128;
return 1; # Return error code
}
else
{
# Normal process exit
return $raw >> 8;
};
}
#
# Create a new process
# Return pid of the new process
#
sub create_process {
my %opts=
(
@_
);
my $path = delete($opts{'path'}) or die "path required";
my $args = delete($opts{'args'}) or die "args required";
my $input = delete($opts{'input'});
my $output = delete($opts{'output'});
my $error = delete($opts{'error'});
my $open_mode= $opts{append} ? ">>" : ">";
if ($^O eq "MSWin32"){
#printf STDERR "stdin %d, stdout %d, stderr %d\n",
# fileno STDIN, fileno STDOUT, fileno STDERR;
# input output redirect
my ($oldin, $oldout, $olderr);
open $oldin, '<&', \*STDIN or die "Failed to save old stdin: $!";
open $oldout, '>&', \*STDOUT or die "Failed to save old stdout: $!";
open $olderr, '>&', \*STDERR or die "Failed to save old stderr: $!";
if ( $input ) {
if ( ! open(STDIN, "<", $input) ) {
croak("can't redirect STDIN to '$input': $!");
}
}
if ( $output ) {
if ( ! open(STDOUT, $open_mode, $output) ) {
croak("can't redirect STDOUT to '$output': $!");
}
}
if ( $error ) {
if ( $output eq $error ) {
if ( ! open(STDERR, ">&STDOUT") ) {
croak("can't dup STDOUT: $!");
}
}
elsif ( ! open(STDERR, $open_mode, $error) ) {
croak("can't redirect STDERR to '$error': $!");
}
}
# Magic use of 'system(1, @args)' to spawn a process
# and get a proper Win32 pid
unshift (@$args, $path);
my $pid= system(1, @$args);
if ( $pid == 0 ){
print $olderr "create_process failed: $^E\n";
die "create_process failed: $^E";
}
# Retore IO redirects
open STDERR, '>&', $olderr
or croak("unable to reestablish STDERR");
open STDOUT, '>&', $oldout
or croak("unable to reestablish STDOUT");
open STDIN, '<&', $oldin
or croak("unable to reestablish STDIN");
#printf STDERR "stdin %d, stdout %d, stderr %d\n",
# fileno STDIN, fileno STDOUT, fileno STDERR;
return wantarray ? ($pid, $pid) : $pid;
}
local $SIG{PIPE}= sub { print STDERR "Got signal $@\n"; };
my $pipe= IO::Pipe->new();
my $pid= _safe_fork();
if ($pid){
# Parent
$pipe->reader();
my $line= <$pipe>; # Wait for child to say it's ready
return wantarray ? ($pid, winpid($pid)) : $pid;
}
$SIG{INT}= 'DEFAULT';
# Make this process it's own process group to be able to kill
# it and any childs(that hasn't changed group themself)
setpgrp(0,0) if $opts{setpgrp};
if ( $output and !open(STDOUT, $open_mode, $output) ) {
croak("can't redirect STDOUT to '$output': $!");
}
if ( $error ) {
if ( defined $output and $output eq $error ) {
if ( ! open(STDERR, ">&STDOUT") ) {
croak("can't dup STDOUT: $!");
}
}
elsif ( ! open(STDERR, $open_mode, $error) ) {
croak("can't redirect STDERR to '$error': $!");
}
}
if ( $input ) {
if ( ! open(STDIN, "<", $input) ) {
croak("can't redirect STDIN to '$input': $!");
}
}
# Tell parent to continue
$pipe->writer();
print $pipe "ready\n";
if ( !exec($path, @$args) ){
croak("Failed to exec '$path': $!");
}
croak("Should never come here");
}
1;
/* Copyright (C) 2004 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
Utility program used to signal a safe_process it's time to shutdown
Usage:
safe_kill <pid>
*/
#include <windows.h>
#include <stdio.h>
int main(int argc, const char** argv )
{
DWORD pid= -1;
HANDLE shutdown_event;
char safe_process_name[32]= {0};
if (argc != 2) {
fprintf(stderr, "safe_kill <pid>\n");
exit(2);
}
pid= atoi(argv[1]);
_snprintf(safe_process_name, sizeof(safe_process_name), "safe_process[%d]", pid);
/* Open the event to signal */
if ((shutdown_event=
OpenEvent(EVENT_MODIFY_STATE, FALSE, safe_process_name)) == NULL){
fprintf(stderr, "Failed to open shutdown_event\n");
exit(1);
}
if(SetEvent(shutdown_event) == 0) {
fprintf(stderr, "Failed to signal shutdown_event\n");
CloseHandle(shutdown_event);
exit(1);
}
CloseHandle(shutdown_event);
exit(0);
}
#!/usr/bin/perl
# -*- cperl -*-
use strict;
use warnings;
use Time::localtime;
use lib 'lib';
use My::SafeProcess::Base;
use POSIX qw(WNOHANG);
###########################################################################
# Util functions
###########################################################################
#
#Print message to stderr
#
my $verbose= 0;
sub message {
if ($verbose > 0){
my $tm= localtime();
my $timestamp= sprintf("%02d%02d%02d %2d:%02d:%02d",
$tm->year % 100, $tm->mon+1, $tm->mday,
$tm->hour, $tm->min, $tm->sec);
print STDERR $timestamp, " monitor[$$]: ", @_, "\n";
}
}
###########################################################################
# Main program
###########################################################################
my $terminated= 0;
# Protect against being killed in the middle
# of child creation, just set the terminated flag
# to make sure the child will be killed off
# when program is ready to do that
$SIG{TERM}= sub { message("!Got signal @_"); $terminated= 1; };
$SIG{INT}= sub { message("!Got signal @_"); $terminated= 1; };
my $parent_pid= getppid();
use Getopt::Long;
GetOptions(
'verbose' => \$verbose,
) or die "GetOptions failed";
shift(@ARGV) if defined($ARGV[0]) and $ARGV[0] eq "--";
my $path= shift(@ARGV); # Executable
die "usage:\n" .
" safe_process.pl [opts] -- <path> [<args> [...<args_n>]]"
unless defined $path;
message("started");
#message("path: '$path'");
message("parent: $parent_pid");
# Start process to monitor
my $child_pid=
create_process(
path => $path,
args => \@ARGV,
setpgrp => 1,
);
message("Started child $child_pid");
eval {
sub handle_signal {
$terminated= 1;
message("Got signal @_");
# Ignore all signals
foreach my $name (keys %SIG){
$SIG{$name}= 'IGNORE';
}
die "signaled\n";
};
local $SIG{TERM}= \&handle_signal;
local $SIG{INT}= \&handle_signal;
local $SIG{CHLD}= sub {
message("Got signal @_");
kill(9, -$child_pid);
my $ret= waitpid($child_pid, 0);
if ($? & 127){
exit(65); # Killed by signal
}
exit($? >> 8);
};
# Monitoring loop
while(!$terminated) {
# Check if parent is still alive
if (kill(0, $parent_pid) < 1){
message("Parent is not alive anymore");
last;
}
# Wait for child to terminate but wakeup every
# second to also check that parent is still alive
my $ret_pid;
$ret_pid= waitpid($child_pid, &WNOHANG);
if ($ret_pid == $child_pid) {
# Process has exited, collect return status
my $ret_code= $? >> 8;
message("Child exit: $ret_code");
# Exit with exit status of the child
exit ($ret_code);
}
sleep(1);
}
};
if ( $@ ) {
# The monitoring loop should have been
# broken by handle_signal
warn "Unexpected: $@" unless ( $@ =~ /signaled/ );
}
# Use negative pid in order to kill the whole
# process group
#
my $ret= kill(9, -$child_pid);
message("Killed child: $child_pid, ret: $ret");
if ($ret > 0) {
message("Killed child: $child_pid");
# Wait blocking for the child to return
my $ret_pid= waitpid($child_pid, 0);
if ($ret_pid != $child_pid){
message("unexpected pid $ret_pid returned from waitpid($child_pid)");
}
}
message("DONE!");
exit (1);
/* Copyright (C) 2004 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
Utility program that encapsulates process creation, monitoring
and bulletproof process cleanup
Usage:
safe_process [options to safe_process] -- progname arg1 ... argn
To safeguard mysqld you would invoke safe_process with a few options
for safe_process itself followed by a double dash to indicate start
of the command line for the program you really want to start
$> safe_process --output=output.log -- mysqld --datadir=var/data1 ...
This would redirect output to output.log and then start mysqld,
once it has done that it will continue to monitor the child as well
as the parent.
The safe_process then checks the follwing things:
1. Child exits, propagate the childs return code to the parent
by exiting with the same return code as the child.
2. Parent dies, immediately kill the child and exit, thus the
parent does not need to properly cleanup any child, it is handled
automatically.
3. Signal's recieced by the process will trigger same action as 2)
4. The named event "safe_process[pid]" can be signaled and will
trigger same action as 2)
WARNING! Be careful when using ProcessExplorer, since it will open
a handle to each process(and maybe also the Job), the process
spawned by safe_process will not be closed off when safe_process
is killed.
*/
/* Requires Windows 2000 or higher */
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <signal.h>
static int verbose= 0;
static char safe_process_name[32]= {0};
static void message(const char* fmt, ...)
{
if (!verbose)
return;
va_list args;
fprintf(stderr, "%s: ", safe_process_name);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
fflush(stderr);
}
static void die(const char* fmt, ...)
{
va_list args;
fprintf(stderr, "%s: FATAL ERROR, ", safe_process_name);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
if (int last_err= GetLastError())
fprintf(stderr, "error: %d, %s\n", last_err, strerror(last_err));
exit(1);
}
DWORD get_parent_pid(DWORD pid)
{
HANDLE snapshot;
DWORD parent_pid= -1;
PROCESSENTRY32 pe32;
pe32.dwSize= sizeof(PROCESSENTRY32);
snapshot= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE)
die("CreateToolhelp32Snapshot failed");
if (!Process32First(snapshot, &pe32))
{
CloseHandle(snapshot);
die("Process32First failed");
}
do
{
if (pe32.th32ProcessID == pid)
parent_pid= pe32.th32ParentProcessID;
} while(Process32Next( snapshot, &pe32));
CloseHandle(snapshot);
if (parent_pid == -1)
die("Could not find parent pid");
return parent_pid;
}
enum {
PARENT,
CHILD,
EVENT,
NUM_HANDLES
};
HANDLE shutdown_event;
void handle_signal (int signal)
{
message("Got signal: %d", signal);
if(SetEvent(shutdown_event) == 0) {
/* exit safe_process and (hopefully) kill off the child */
die("Failed to SetEvent");
}
}
int main(int argc, const char** argv )
{
char child_args[4096]= {0};
DWORD pid= GetCurrentProcessId();
DWORD parent_pid= get_parent_pid(pid);
HANDLE job_handle;
HANDLE wait_handles[NUM_HANDLES]= {0};
PROCESS_INFORMATION process_info= {0};
sprintf(safe_process_name, "safe_process[%d]", pid);
/* Create an event for the signal handler */
if ((shutdown_event=
CreateEvent(NULL, TRUE, FALSE, safe_process_name)) == NULL)
die("Failed to create shutdown_event");
wait_handles[EVENT]= shutdown_event;
signal(SIGINT, handle_signal);
signal(SIGBREAK, handle_signal);
signal(SIGTERM, handle_signal);
message("Started");
/* Parse arguments */
for (int i= 1; i < argc; i++) {
const char* arg= argv[i];
char* to= child_args;
if (strcmp(arg, "--") == 0 && strlen(arg) == 2) {
/* Got the "--" delimiter */
if (i >= argc)
die("No real args -> nothing to do");
/* Copy the remaining args to child_arg */
for (int j= i+1; j < argc; j++) {
to+= _snprintf(to, child_args + sizeof(child_args) - to, "%s ", argv[j]);
}
break;
} else {
if ( strcmp(arg, "--verbose") == 0 )
verbose++;
else if ( strncmp(arg, "--parent-pid", 10) == 0 )
{
/* Override parent_pid with a value provided by user */
const char* start;
if ((start= strstr(arg, "=")) == NULL)
die("Could not find start of option value in '%s'", arg);
start++; /* Step past = */
if ((parent_pid= atoi(start)) == 0)
die("Invalid value '%s' passed to --parent-id", start);
}
else
die("Unknown option: %s", arg);
}
}
if (*child_args == '\0')
die("nothing to do");
/* Open a handle to the parent process */
message("parent_pid: %d", parent_pid);
if (parent_pid == pid)
die("parent_pid is equal to own pid!");
if ((wait_handles[PARENT]=
OpenProcess(SYNCHRONIZE, FALSE, parent_pid)) == NULL)
die("Failed to open parent process with pid: %d", parent_pid);
/* Create the child process in a job */
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
/*
Create the job object to make it possible to kill the process
and all of it's children in one go
*/
if ((job_handle= CreateJobObject(NULL, NULL)) == NULL)
die("CreateJobObject failed");
/*
Make all processes associated with the job terminate when the
last handle to the job is closed.
*/
jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
if (SetInformationJobObject(job_handle, JobObjectExtendedLimitInformation,
&jeli, sizeof(jeli)) == 0)
message("SetInformationJobObject failed, continue anyway...");
#if 0
/* Setup stdin, stdout and stderr redirect */
si.dwFlags= STARTF_USESTDHANDLES;
si.hStdInput= GetStdHandle(STD_INPUT_HANDLE);
si.hStdOutput= GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError= GetStdHandle(STD_ERROR_HANDLE);
#endif
/*
Create the process suspended to make sure it's assigned to the
Job before it creates any process of it's own
*/
if (CreateProcess(NULL, (LPSTR)child_args,
NULL,
NULL,
TRUE, /* inherit handles */
CREATE_SUSPENDED,
NULL,
NULL,
&si,
&process_info) == 0)
die("CreateProcess failed");
if (AssignProcessToJobObject(job_handle, process_info.hProcess) == 0)
{
TerminateProcess(process_info.hProcess, 200);
die("AssignProcessToJobObject failed");
}
ResumeThread(process_info.hThread);
CloseHandle(process_info.hThread);
wait_handles[CHILD]= process_info.hProcess;
message("Started child %d", process_info.dwProcessId);
/* Monitor loop */
DWORD child_exit_code= 1;
DWORD wait_res= WaitForMultipleObjects(NUM_HANDLES, wait_handles,
FALSE, INFINITE);
switch (wait_res)
{
case WAIT_OBJECT_0 + PARENT:
message("Parent exit");
break;
case WAIT_OBJECT_0 + CHILD:
if (GetExitCodeProcess(wait_handles[CHILD], &child_exit_code) == 0)
message("Child exit: could not get exit_code");
else
message("Child exit: exit_code: %d", child_exit_code);
break;
case WAIT_OBJECT_0 + EVENT:
message("Wake up from shutdown_event");
break;
default:
message("Unexpected result %d from WaitForMultipleObjects", wait_res);
break;
}
message("Exiting, child: %d", process_info.dwProcessId);
if (TerminateJobObject(job_handle, 201) == 0)
message("TerminateJobObject failed");
CloseHandle(job_handle);
if (wait_res != WAIT_OBJECT_0 + CHILD)
{
/* The child has not yet returned, wait for it */
message("waiting for child to exit");
if ((wait_res= WaitForSingleObject(wait_handles[CHILD], INFINITE)) != WAIT_OBJECT_0)
{
message("child wait failed: %d", wait_res);
}
else
{
message("child wait succeeded");
}
/* Child's exit code should now be 201, no need to get it */
}
for (int i= 0; i < NUM_HANDLES; i++)
CloseHandle(wait_handles[i]);
exit(child_exit_code);
}
# -*- cperl -*-
# Copyright (C) 2005 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This is a library file used by the Perl version of mysql-test-run,
# and is part of the translation of the Bourne shell script with the
# same name.
#use Data::Dumper;
use strict;
# $Data::Dumper::Indent= 1;
sub mtr_diff($$);
##############################################################################
#
# This is a simplified unified diff, with some special handling
# of unsorted result sets
#
##############################################################################
# FIXME replace die with mtr_error
#require "mtr_report.pl";
#mtr_diff("a.txt","b.txt");
sub mtr_diff ($$) {
my $file1 = shift;
my $file2 = shift;
# ----------------------------------------------------------------------
# We read in all of the files at once
# ----------------------------------------------------------------------
unless ( open(FILE1, $file1) )
{
mtr_warning("can't open \"$file1\": $!");
return;
}
unless ( open(FILE2, $file2) )
{
mtr_warning("can't open \"$file2\": $!");
return;
}
my $lines1= collect_lines(<FILE1>);
my $lines2= collect_lines(<FILE2>);
close FILE1;
close FILE2;
# print Dumper($lines1);
# print Dumper($lines2);
# ----------------------------------------------------------------------
# We compare line by line, but don't shift off elements until we know
# what to do. This way we use the "restart" method, do simple change
# and restart by entering the diff loop from the beginning again.
# ----------------------------------------------------------------------
my @context;
my @info; # Collect information, and output later
my $lno1= 1;
my $lno2= 1;
while ( @$lines1 or @$lines2 )
{
unless ( @$lines1 )
{
push(@info, map {['+',$lno1,$lno2++,$_]} @$lines2);
last;
}
unless ( @$lines2 )
{
push(@info, map {['-',$lno1++,$lno2,$_]} @$lines1);
last;
}
# ----------------------------------------------------------------------
# We know both have lines
# ----------------------------------------------------------------------
if ( $lines1->[0] eq $lines2->[0] )
{
# Simple case, first line match and all is well
push(@info, ['',$lno1++,$lno2++,$lines1->[0]]);
shift @$lines1;
shift @$lines2;
next;
}
# ----------------------------------------------------------------------
# Now, we know they differ
# ----------------------------------------------------------------------
# How far in the other one, is there a match?
my $idx2= find_next_match($lines1->[0], $lines2);
my $idx1= find_next_match($lines2->[0], $lines1);
# Here we could test "if ( !defined $idx2 or !defined $idx1 )" and
# use a more complicated diff algorithm in the case both contains
# each others lines, just dislocated. But for this application, there
# should be no need.
if ( !defined $idx2 )
{
push(@info, ['-',$lno1++,$lno2,$lines1->[0]]);
shift @$lines1;
}
else
{
push(@info, ['+',$lno1,$lno2++,$lines2->[0]]);
shift @$lines2;
}
}
# ----------------------------------------------------------------------
# Try to output nicely
# ----------------------------------------------------------------------
# print Dumper(\@info);
# We divide into "chunks" to output
# We want at least three lines of context
my @chunks;
my @chunk;
my $state= 'pre'; # 'pre', 'in' and 'post' difference
my $post_count= 0;
foreach my $info ( @info )
{
if ( $info->[0] eq '' and $state eq 'pre' )
{
# Collect no more than three lines of context before diff
push(@chunk, $info);
shift(@chunk) if @chunk > 3;
next;
}
if ( $info->[0] =~ /(\+|\-)/ and $state =~ /(pre|in)/ )
{
# Start/continue collecting diff
$state= 'in';
push(@chunk, $info);
next;
}
if ( $info->[0] eq '' and $state eq 'in' )
{
# Stop collecting diff, and collect context after diff
$state= 'post';
$post_count= 1;
push(@chunk, $info);
next;
}
if ( $info->[0] eq '' and $state eq 'post' and $post_count < 6 )
{
# We might find a new diff sequence soon, continue to collect
# non diffs but five up on 6.
$post_count++;
push(@chunk, $info);
next;
}
if ( $info->[0] eq '' and $state eq 'post' )
{
# We put an end to this, giving three non diff lines to
# the old chunk, and three to the new one.
my @left= splice(@chunk, -3, 3);
push(@chunks, [@chunk]);
$state= 'pre';
$post_count= 0;
@chunk= @left;
next;
}
if ( $info->[0] =~ /(\+|\-)/ and $state eq 'post' )
{
# We didn't split, continue collect diff
$state= 'in';
push(@chunk, $info);
next;
}
}
if ( $post_count > 3 )
{
$post_count -= 3;
splice(@chunk, -$post_count, $post_count);
}
push(@chunks, [@chunk]) if @chunk and $state ne 'pre';
foreach my $chunk ( @chunks )
{
my $from_file_start= $chunk->[0]->[1];
my $to_file_start= $chunk->[0]->[2];
my $from_file_offset= $chunk->[$#$chunk]->[1] - $from_file_start;
my $to_file_offset= $chunk->[$#$chunk]->[2] - $to_file_start;
print "\@\@ -$from_file_start,$from_file_offset ",
"+$to_file_start,$to_file_offset \@\@\n";
foreach my $info ( @$chunk )
{
if ( $info->[0] eq '' )
{
print " $info->[3]\n";
}
elsif ( $info->[0] eq '-' )
{
print "- $info->[3]\n";
}
elsif ( $info->[0] eq '+' )
{
print "+ $info->[3]\n";
}
}
}
# print Dumper(\@chunks);
}
##############################################################################
# Find if the string is found in the array, return the index if found,
# if not found, return "undef"
##############################################################################
sub find_next_match {
my $line= shift;
my $lines= shift;
for ( my $idx= 0; $idx < @$lines; $idx++ )
{
return $idx if $lines->[$idx] eq $line;
}
return undef; # No match found
}
##############################################################################
# Just read the lines, but handle "sets" of lines that are unordered
##############################################################################
sub collect_lines {
my @recordset;
my @lines;
while (@_)
{
my $line= shift @_;
chomp($line);
if ( $line =~ /^\Q%unordered%\E\t/ )
{
push(@recordset, $line);
}
elsif ( @recordset )
{
push(@lines, sort @recordset);
@recordset= (); # Clear it
}
else
{
push(@lines, $line);
}
}
if ( @recordset )
{
push(@lines, sort @recordset);
@recordset= (); # Clear it
}
return \@lines;
}
1;
This diff is collapsed.
......@@ -20,135 +20,14 @@
use strict;
sub mtr_get_pid_from_file ($);
sub mtr_get_opts_from_file ($);
sub mtr_fromfile ($);
sub mtr_tofile ($@);
sub mtr_tonewfile($@);
sub mtr_lastlinefromfile($);
sub mtr_appendfile_to_file ($$);
sub mtr_grab_file($);
sub mtr_printfile($);
##############################################################################
#
#
#
##############################################################################
sub mtr_get_pid_from_file ($) {
my $pid_file_path= shift;
my $TOTAL_ATTEMPTS= 30;
my $timeout= 1;
# We should read from the file until we get correct pid. As it is
# stated in BUG#21884, pid file can be empty at some moment. So, we should
# read it until we get valid data.
for (my $cur_attempt= 1; $cur_attempt <= $TOTAL_ATTEMPTS; ++$cur_attempt)
{
mtr_debug("Reading pid file '$pid_file_path' " .
"($cur_attempt of $TOTAL_ATTEMPTS)...");
open(FILE, '<', $pid_file_path)
or mtr_error("can't open file \"$pid_file_path\": $!");
# Read pid number from file
my $pid= <FILE>;
chomp $pid;
close FILE;
return $pid if $pid=~ /^(\d+)/;
mtr_debug("Pid file '$pid_file_path' does not yet contain pid number.\n" .
"Sleeping $timeout second(s) more...");
sleep($timeout);
}
mtr_error("Pid file '$pid_file_path' is corrupted. " .
"Can not retrieve PID in " .
($timeout * $TOTAL_ATTEMPTS) . " seconds.");
}
sub mtr_get_opts_from_file ($) {
my $file= shift;
open(FILE,"<",$file) or mtr_error("can't open file \"$file\": $!");
my @args;
while ( <FILE> )
{
chomp;
# --set-variable=init_connect=set @a='a\\0c'
s/^\s+//; # Remove leading space
s/\s+$//; # Remove ending space
# This is strange, but we need to fill whitespace inside
# quotes with something, to remove later. We do this to
# be able to split on space. Else, we have trouble with
# options like
#
# --someopt="--insideopt1 --insideopt2"
#
# But still with this, we are not 100% sure it is right,
# we need a shell to do it right.
# print STDERR "\n";
# print STDERR "AAA: $_\n";
s/\'([^\'\"]*)\'/unspace($1,"\x0a")/ge;
s/\"([^\'\"]*)\"/unspace($1,"\x0b")/ge;
s/\'([^\'\"]*)\'/unspace($1,"\x0a")/ge;
s/\"([^\'\"]*)\"/unspace($1,"\x0b")/ge;
# print STDERR "BBB: $_\n";
# foreach my $arg (/(--?\w.*?)(?=\s+--?\w|$)/)
# FIXME ENV vars should be expanded!!!!
foreach my $arg (split(/[ \t]+/))
{
$arg =~ tr/\x11\x0a\x0b/ \'\"/; # Put back real chars
# The outermost quotes has to go
$arg =~ s/^([^\'\"]*)\'(.*)\'([^\'\"]*)$/$1$2$3/
or $arg =~ s/^([^\'\"]*)\"(.*)\"([^\'\"]*)$/$1$2$3/;
$arg =~ s/\\\\/\\/g;
$arg =~ s/\$\{(\w+)\}/envsubst($1)/ge;
$arg =~ s/\$(\w+)/envsubst($1)/ge;
# print STDERR "ARG: $arg\n";
# Do not pass empty string since my_getopt is not capable to handle it.
if (length($arg))
{
push(@args, $arg)
}
}
}
close FILE;
return \@args;
}
sub envsubst {
my $string= shift;
if ( ! defined $ENV{$string} )
{
mtr_error("opt file referense \$$string that is unknown");
}
return $ENV{$string};
}
sub unspace {
my $string= shift;
my $quote= shift;
$string =~ s/[ \t]/\x11/g;
return "$quote$string$quote";
}
# Read a whole file, stripping leading and trailing whitespace.
sub mtr_fromfile ($) {
my $file= shift;
......@@ -161,19 +40,6 @@ sub mtr_fromfile ($) {
return $text;
}
sub mtr_lastlinefromfile ($) {
my $file= shift;
my $text;
open(FILE,"<",$file) or mtr_error("can't open file \"$file\": $!");
while (my $line= <FILE>)
{
$text= $line;
}
close FILE;
return $text;
}
sub mtr_tofile ($@) {
my $file= shift;
......@@ -183,6 +49,7 @@ sub mtr_tofile ($@) {
close FILE;
}
sub mtr_tonewfile ($@) {
my $file= shift;
......@@ -191,6 +58,7 @@ sub mtr_tonewfile ($@) {
close FILE;
}
sub mtr_appendfile_to_file ($$) {
my $from_file= shift;
my $to_file= shift;
......@@ -203,6 +71,7 @@ sub mtr_appendfile_to_file ($$) {
close TOFILE;
}
# Read a whole file verbatim.
sub mtr_grab_file($) {
my $file= shift;
......@@ -215,4 +84,15 @@ sub mtr_grab_file($) {
}
# Print the file to STDOUT
sub mtr_printfile($) {
my $file= shift;
open(FILE, '<', $file)
or warn $!;
print while(<FILE>);
close FILE;
return;
}
1;
......@@ -19,18 +19,16 @@
# same name.
use strict;
use File::Find;
sub mtr_native_path($);
sub mtr_init_args ($);
sub mtr_add_arg ($$@);
sub mtr_args2str($@);
sub mtr_path_exists(@);
sub mtr_script_exists(@);
sub mtr_file_exists(@);
sub mtr_exe_exists(@);
sub mtr_exe_maybe_exists(@);
sub mtr_copy_dir($$);
sub mtr_rmtree($);
sub mtr_same_opts($$);
sub mtr_cmp_opts($$);
......@@ -56,7 +54,11 @@ sub mtr_native_path($)
}
# FIXME move to own lib
##############################################################################
#
# Args
#
##############################################################################
sub mtr_init_args ($) {
my $args = shift;
......@@ -68,9 +70,18 @@ sub mtr_add_arg ($$@) {
my $format= shift;
my @fargs = @_;
# Quote args if args contain space
$format= "\"$format\""
if ($::glob_win32 and grep(/\s/, @fargs));
push(@$args, sprintf($format, @fargs));
}
sub mtr_args2str($@) {
my $exe= shift or die;
return join(" ", mtr_native_path($exe), @_);
}
##############################################################################
#
......@@ -141,7 +152,6 @@ sub mtr_exe_maybe_exists (@) {
my @path= @_;
map {$_.= ".exe"} @path if $::glob_win32;
map {$_.= ".nlm"} @path if $::glob_netware;
foreach my $path ( @path )
{
if($::glob_win32)
......@@ -179,79 +189,6 @@ sub mtr_exe_exists (@) {
}
sub mtr_copy_dir($$) {
my $from_dir= shift;
my $to_dir= shift;
# mtr_verbose("Copying from $from_dir to $to_dir");
mkpath("$to_dir");
opendir(DIR, "$from_dir")
or mtr_error("Can't find $from_dir$!");
for(readdir(DIR)) {
next if "$_" eq "." or "$_" eq "..";
if ( -d "$from_dir/$_" )
{
mtr_copy_dir("$from_dir/$_", "$to_dir/$_");
next;
}
copy("$from_dir/$_", "$to_dir/$_");
}
closedir(DIR);
}
sub mtr_rmtree($) {
my ($dir)= @_;
mtr_verbose("mtr_rmtree: $dir");
# Try to use File::Path::rmtree. Recent versions
# handles removal of directories and files that don't
# have full permissions, while older versions
# may have a problem with that and we use our own version
eval { rmtree($dir); };
if ( $@ ) {
mtr_warning("rmtree($dir) failed, trying with File::Find...");
my $errors= 0;
# chmod
find( {
no_chdir => 1,
wanted => sub {
chmod(0777, $_)
or mtr_warning("couldn't chmod(0777, $_): $!") and $errors++;
}
},
$dir
);
# rm
finddepth( {
no_chdir => 1,
wanted => sub {
my $file= $_;
# Use special underscore (_) filehandle, caches stat info
if (!-l $file and -d _ ) {
rmdir($file) or
mtr_warning("couldn't rmdir($file): $!") and $errors++;
} else {
unlink($file)
or mtr_warning("couldn't unlink($file): $!") and $errors++;
}
}
},
$dir
);
mtr_error("Failed to remove '$dir'") if $errors;
mtr_report("OK, that worked!");
}
}
sub mtr_same_opts ($$) {
my $l1= shift;
......@@ -280,33 +217,41 @@ sub mtr_cmp_opts ($$) {
return 0; # They are the same
}
sub mtr_milli_sleep {
die "usage: mtr_milli_sleep(milliseconds)" unless @_ == 1;
my ($millis)= @_;
select(undef, undef, undef, ($millis/1000));
}
#
# Compare two arrays and put all unequal elements into a new one
#
sub mtr_diff_opts ($$) {
my $l1= shift;
my $l2= shift;
my $f;
my $l= [];
foreach my $e1 (@$l1)
{
$f= undef;
foreach my $e2 (@$l2)
my $found;
my @result;
foreach my $e1 (@$l1)
{
$found= undef;
foreach my $e2 (@$l2)
{
$f= 1 unless ($e1 ne $e2);
$found= 1 unless ($e1 ne $e2);
}
push(@$l, $e1) unless (defined $f);
push(@result, $e1) unless (defined $found);
}
foreach my $e2 (@$l2)
foreach my $e2 (@$l2)
{
$f= undef;
foreach my $e1 (@$l1)
$found= undef;
foreach my $e1 (@$l1)
{
$f= 1 unless ($e1 ne $e2);
$found= 1 unless ($e1 ne $e2);
}
push(@$l, $e2) unless (defined $f);
push(@result, $e2) unless (defined $found);
}
return $l;
return @result;
}
1;
This diff is collapsed.
This diff is collapsed.
#
# Defines used to control how mysql-test-run.pl
# should work in the current version of MySQL
#
# Control if the suite name should be output before testname
sub SHOW_SUITE_NAME { return 1; };
# Control which suites are run by default
sub DEFAULT_SUITES { return "main,binlog,federated,rpl,rpl_ndb,ndb"; };
1;
......@@ -135,7 +135,7 @@ sub run_stress_test ()
}
mtr_init_args(\$args);
mtr_add_args($args, "$::glob_mysql_test_dir/mysql-stress-test.pl");
mtr_add_arg($args, "--server-socket=%s", $::master->[0]->{'path_sock'});
mtr_add_arg($args, "--server-user=%s", $::opt_user);
mtr_add_arg($args, "--server-database=%s", "test");
......@@ -181,7 +181,13 @@ sub run_stress_test ()
}
#Run stress test
mtr_run("$::glob_mysql_test_dir/mysql-stress-test.pl", $args, "", "", "", "");
My::SafeProcess->run
(
name => "stress test",
path => $^X,
args => \$args,
);
if ( ! $::glob_use_embedded_server )
{
stop_all_servers();
......
This diff is collapsed.
# -*- cperl -*-
use Test::More qw(no_plan);
use strict;
use_ok ("My::SafeProcess::Base");
my $count= 0;
for (1..100){
my $pid= My::SafeProcess::Base::_safe_fork();
exit unless $pid;
(waitpid($pid, 0) == $pid) and $count++;
}
ok($count == 100, "safe_fork");
# A nice little forkbomb
SKIP: {
skip("forkbomb", 1);
eval {
while(1){
my $pid= My::SafeProcess::Base::_safe_fork();
exit unless $pid;
}
};
ok($@, "forkbomb");
}
# -*- cperl -*-
use Test::More qw(no_plan);
use strict;
use_ok ("My::Find");
my $basedir= "../..";
print "=" x 40, "\n";
my $mysqld_exe= my_find_bin($basedir,
["sql", "bin"],
["mysqld", "mysqld-debug"]);
print "mysqld_exe: $mysqld_exe\n";
print "=" x 40, "\n";
my $mysql_exe= my_find_bin($basedir,
["client", "bin"],
"mysql");
print "mysql_exe: $mysql_exe\n";
print "=" x 40, "\n";
my $mtr_build_dir= $ENV{MTR_BUILD_DIR};
$ENV{MTR_BUILD_DIR}= "debug";
my $mysql_exe= my_find_bin($basedir,
["client", "bin"],
"mysql");
print "mysql_exe: $mysql_exe\n";
$ENV{MTR_BUILD_DIR}= $mtr_build_dir;
print "=" x 40, "\n";
my $charset_dir= my_find_dir($basedir,
["share/mysql", "sql/share", "share"],
"charsets");
print "charset_dir: $charset_dir\n";
print "=" x 40, "\n";
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
kill -9 `cat var/run/master.pid`
# The kill may fail if process has already gone away,
# so don't use the exit code of the kill. Use 0.
exit 0
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment