diff options
Diffstat (limited to 'mysql-test')
-rwxr-xr-x | mysql-test/mybin/mysql-test_install_db | 215 | ||||
-rwxr-xr-x | mysql-test/mysql-test-run | 262 |
2 files changed, 477 insertions, 0 deletions
diff --git a/mysql-test/mybin/mysql-test_install_db b/mysql-test/mybin/mysql-test_install_db new file mode 100755 index 00000000000..592220f54ff --- /dev/null +++ b/mysql-test/mybin/mysql-test_install_db @@ -0,0 +1,215 @@ +#!/bin/sh +# Copyright (C) 1997, 1998, 1999 TCX DataKonsult AB & Monty Program KB & Detron HB +# For a more info consult the file COPYRIGHT distributed with this file + +# This scripts creates the privilege tables db, host, user, tables_priv, +# columns_priv in the mysql database, as well as the func table. + +ldata=var/lib +mdata=$ldata/mysql +execdir=../sql +bindir=../client + +# Get mysqld/safe_mysqld options from /etc/my.cnf or ~/.my.cnf +if test -w / +then + conf=@sysconfdir@/my.cnf +else + conf=$HOME/.my.cnf +fi + +if test -f "$conf" +then + if grep "^datadir" $conf >/dev/null + then + ldata=`grep "^datadir" $conf | sed '.*=[ \t]*//` + fi + if grep "^execdir" $conf >/dev/null + then + execdir=`grep "^execdir" $conf | sed '.*=[ \t]*//` + fi + if grep "^bindir" $conf >/dev/null + then + bindir=`grep "^bindir" $conf | sed '.*=[ \t]*//` + fi + if grep "^user" $conf >/dev/null + then + user=`grep "^user" $conf | sed '.*=[ \t]*//` + fi +fi + +if test ! -x $execdir/mysqld +then + echo "I can't find no stinking mysqld!" + exit 1 +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 + +resolved=127.0.0.1 + +# Create database directories mysql & test +if test ! -d $ldata; then mkdir $ldata; chmod 700 $ldata ; fi +if test ! -d $ldata/mysql; then mkdir $ldata/mysql; chmod 700 $ldata/mysql ; fi +if test ! -d $ldata/test; then mkdir $ldata/test; chmod 700 $ldata/test ; fi +if test -w / -a ! -z "$user"; then + chown $user $ldata $ldata/mysql $ldata/test; +fi + +# Initialize variables +c_d="" i_d="" +c_h="" i_h="" +c_u="" i_u="" +c_f="" i_f="" +c_t="" c_c="" + +# Check for old tables +if test ! -f $mdata/db.frm +then + # mysqld --bootstrap wants one command/line + c_d="$c_d CREATE TABLE db (" + c_d="$c_d Host char(60) DEFAULT '' NOT NULL," + c_d="$c_d Db char(64) DEFAULT '' NOT NULL," + c_d="$c_d User char(16) DEFAULT '' NOT NULL," + c_d="$c_d Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d References_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_d="$c_d PRIMARY KEY Host (Host,Db,User)," + c_d="$c_d KEY User (User)" + c_d="$c_d )" + c_d="$c_d comment='Database privileges';" + + i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y'); + INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');" +fi + +if test ! -f $mdata/host.frm +then + c_h="$c_h CREATE TABLE host (" + c_h="$c_h Host char(60) DEFAULT '' NOT NULL," + c_h="$c_h Db char(64) DEFAULT '' NOT NULL," + c_h="$c_h Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h References_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_h="$c_h PRIMARY KEY Host (Host,Db)" + c_h="$c_h )" + c_h="$c_h comment='Host privileges; Merged with database privileges';" +fi + +if test ! -f $mdata/user.frm +then + c_u="$c_u CREATE TABLE user (" + c_u="$c_u Host char(60) DEFAULT '' NOT NULL," + c_u="$c_u User char(16) DEFAULT '' NOT NULL," + c_u="$c_u Password char(16) DEFAULT '' NOT NULL," + c_u="$c_u Select_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Update_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Create_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Process_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u File_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u References_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Index_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL," + c_u="$c_u PRIMARY KEY Host (Host,User)" + c_u="$c_u )" + c_u="$c_u comment='Users and global privileges';" + + i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); + INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); + + REPLACE INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); + REPLACE INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); + + INSERT INTO user VALUES ('localhost','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); + INSERT INTO user VALUES ('$hostname','','','N','N','N','N','N','N','N','N','N','N','N','N','N','N');" +fi + +if test ! -f $mdata/func.frm +then + c_f="$c_f CREATE TABLE func (" + c_f="$c_f name char(64) DEFAULT '' NOT NULL," + c_f="$c_f ret tinyint(1) DEFAULT '0' NOT NULL," + c_f="$c_f dl char(128) DEFAULT '' NOT NULL," + c_f="$c_f type enum ('function','aggregate') NOT NULL," + c_f="$c_f PRIMARY KEY (name)" + c_f="$c_f )" + c_f="$c_f comment='User defined functions';" +fi + +if test ! -f $mdata/tables_priv.frm +then + c_t="$c_t CREATE TABLE tables_priv (" + c_t="$c_t Host char(60) DEFAULT '' NOT NULL," + c_t="$c_t Db char(64) DEFAULT '' NOT NULL," + c_t="$c_t User char(16) DEFAULT '' NOT NULL," + c_t="$c_t Table_name char(60) DEFAULT '' NOT NULL," + c_t="$c_t Grantor char(77) DEFAULT '' NOT NULL," + c_t="$c_t Timestamp timestamp(14)," + c_t="$c_t Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL," + c_t="$c_t Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," + c_t="$c_t PRIMARY KEY (Host,Db,User,Table_name)," + c_t="$c_t KEY Grantor (Grantor)" + c_t="$c_t )" + c_t="$c_t comment='Table privileges';" +fi + +if test ! -f $mdata/columns_priv.frm +then + c_c="$c_c CREATE TABLE columns_priv (" + c_c="$c_c Host char(60) DEFAULT '' NOT NULL," + c_c="$c_c Db char(64) DEFAULT '' NOT NULL," + c_c="$c_c User char(16) DEFAULT '' NOT NULL," + c_c="$c_c Table_name char(64) DEFAULT '' NOT NULL," + c_c="$c_c Column_name char(64) DEFAULT '' NOT NULL," + c_c="$c_c Timestamp timestamp(14)," + c_c="$c_c Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL," + c_c="$c_c PRIMARY KEY (Host,Db,User,Table_name,Column_name)" + c_c="$c_c )" + c_c="$c_c comment='Column privileges';" +fi + +if $execdir/mysqld --bootstrap --skip-grant-tables \ + --basedir=. --datadir=$ldata "$@" << END_OF_DATA +use mysql; +$c_d +$i_d + +$c_h +$i_h + +$c_u +$i_u + +$c_f +$i_f + +$c_t +$c_c +END_OF_DATA +then + exit 0 +else + exit 1 +fi diff --git a/mysql-test/mysql-test-run b/mysql-test/mysql-test-run new file mode 100755 index 00000000000..55ee153dd65 --- /dev/null +++ b/mysql-test/mysql-test-run @@ -0,0 +1,262 @@ +#! /bin/sh + +#++ +# Access Definitions +#-- +DB=test +USER=test +PASSWD= + +#++ +# Misc. Definitions +#-- +CWD=`pwd` +cd .. +BASEDIR=`pwd` +cd $CWD +MYBIN="$CWD/mybin" +TESTVER=3.23 +TESTDIR="$CWD/t/$TESTVER" +TOT_PASS=0 +TOT_FAIL=0 +TOT_TEST=0 +TIME_FORMAT='%U\t%S\t%E\t%P' +DASHBLANK="----\t----\t-------\t----" + +[ -z $COLUMNS ] && COLUMNS=80 +E=`expr $COLUMNS - 8` +C=0 + +while [ $C != $E ] +do + DASH72="${DASH72}-" + C=`expr $C + 1` +done + +#++ +# mysqld Environment Parameters +#-- +MYPORT=9306 +MYDDIR="$CWD/var/lib" +MYSOCK="$CWD/var/tmp/mysql.sock" +MYPID="$CWD/var/run/mysqld.pid" +MYLOG="$CWD/var/log/mysqld.log" +MYERR="$CWD/var/log/mysqld.err" + +#++ +# Program Definitions +#-- +TIME=/usr/bin/time +MYSQLD="$BASEDIR/sql/mysqld" +MYSQL_TEST="$BASEDIR/client/mysql-test" +MYSQLADMIN="$BASEDIR/client/mysqladmin" +MYSQL_TEST="$MYSQL_TEST --socket=$MYSOCK --database=$DB --user=$USER --password=$PASSWD --silent" +INSTALL_DB="$MYBIN/mysql-test_install_db" + + +#++ +# Terminal Modifications +#-- +MOVE_TO_COL="echo -en \\033[300C\\033[20D" +SETCOLOR_SUCCESS="echo -en \\033[1;32m" +SETCOLOR_FAILURE="echo -en \\033[1;31m" +SETCOLOR_WARNING="echo -en \\033[1;33m" +SETCOLOR_NORMAL="echo -en \\033[0;39m" + + + +#++ +# Function Definitions +#-- +echo_ok() { + $MOVE_TO_COL && $SETCOLOR_NORMAL + echo -n "[ " + $SETCOLOR_SUCCESS + echo -n "ok" + $SETCOLOR_NORMAL + echo " ]" + return 0 +} + +echo_notok() { + $MOVE_TO_COL && $SETCOLOR_NORMAL + echo -n "[ " + $SETCOLOR_FAILURE + echo -n "not ok" + $SETCOLOR_NORMAL + echo " ]" + return 0 +} + +echo_pass () { + $MOVE_TO_COL && $SETCOLOR_NORMAL + echo -n "[ " + $SETCOLOR_SUCCESS + echo -n "pass" + $SETCOLOR_NORMAL + echo " ]" + return 0 +} + +echo_fail () { + $MOVE_TO_COL && $SETCOLOR_NORMAL + echo -n "[ " + $SETCOLOR_FAILURE + echo -n "fail" + $SETCOLOR_NORMAL + echo " ]" + return 0 +} + +error () { + + $SETCOLOR_FAILURE + echo -n "Error: " && $SETCOLOR_NORMAL && echo $1 + $SETCOLOR_NORMAL + exit 1 +} + +pass_inc () { + TOT_PASS=`expr $TOT_PASS + 1` +} + +fail_inc () { + TOT_FAIL=`expr $TOT_FAIL + 1` +} + +total_inc () { + TOT_TEST=`expr $TOT_TEST + 1` +} + +report_stats () { + if [ $TOT_FAIL == 0 ]; then + echo "All tests successful." + else + echo -n "Failed ${TOT_FAIL}/${TOT_TEST} tests, " + + xten=`expr $TOT_PASS \* 10000` # + raw=`expr $xten / $TOT_TEST` # My God + raw=`printf %.4d $raw` # This is such a ... + whole=`printf %.2s $raw` # Narttu!! + xwhole=`expr $whole \* 100` # Hynda!!! + deci=`expr $raw - $xwhole` # + + echo "${whole}.${deci}% successful." + fi +} + +mysql_install_db () { + if [ `$INSTALL_DB` ]; then + error "Could not install tmp DBs" + fi + + return 0 +} + +mysql_start () { + + `$MYSQLD --no-defaults \ + --skip-networking \ + --basedir=$CWD \ + --datadir=$MYDDIR \ + --pid-file=$MYPID \ + --socket=$MYSOCK \ + --log=$MYLOG \ + --language=english >> $MYERR 2>&1 &` + + return 1 +} + +mysql_stop () { + + `$MYSQLADMIN --socket=$MYSOCK -u root shutdown` + + return 1 +} + +mysql_restart () { + + mysql_stop + res=$? + [ $res != 1 ] && echo_notok && error "Stopping mysqld" + + mysql_start + res=$? + [ $res != 1 ] && echo_notok && error "Starting mysqld" + + return 1 +} + +mysql_loadstd () { + + sleep 2 + return 1 +} + + +mysql_install_db + +$SETCOLOR_NORMAL && echo -n "Starting mysqld for Testing" +mysql_start +res=$? +res=1 +[ $res != 1 ] && echo_notok && error "Starting mysqld" +[ $res == 1 ] && echo_ok + +$SETCOLOR_NORMAL && echo -n "Loading Standard Test Database" +mysql_loadstd +res=$? +[ $res != 1 ] && echo_notok && error "Loading STD" +[ $res == 1 ] && echo_ok + +$SETCOLOR_NORMAL && echo -n "Starting Tests for MySQL $TESTVER Series" +$SETCOLOR_SUCCESS && echo_ok + +echo +echo -e " TEST\t\t\tUSER\tSYSTEM\tELAPSED\t%CPU\t RESULT" +echo $DASH72 + +for tf in $TESTDIR/* +do + mytime=`$TIME -f $TIME_FORMAT $MYSQL_TEST < $tf 2>&1` + res=$? + + tf=`basename $tf` + + [ $res == 1 ] && mytime=`echo -ne $mytime | cut -b 39-` && mytime=${mytime// /\\t} + $SETCOLOR_NORMAL && echo -ne "$tf\t\t$mytime" + [ $res == 1 ] && fail_inc && echo_fail + [ $res != 1 ] && pass_inc && echo_pass + + total_inc + + if [ $res != 0 ]; then + echo + $SETCOLOR_NORMAL && echo -ne "Restarting mysqld\t$DASHBLANK" + mysql_restart + $SETCOLOR_SUCCESS && echo_ok + $SETCOLOR_NORMAL && echo -ne "Resuming Tests\t\t$DASHBLANK" + $SETCOLOR_SUCCESS && echo_ok + echo + fi +done + +echo $DASH72 +echo +$SETCOLOR_NORMAL && echo -n "Ending Tests for MySQL $TESTVER Series" +$SETCOLOR_SUCCESS && echo_ok + +$SETCOLOR_NORMAL && echo -n "Shutdown mysqld" +mysql_stop +res=$? +res=1 +[ $res != 1 ] && echo_notok && error "Shutdown mysqld" +[ $res == 1 ] && echo_ok + +$SETCOLOR_NORMAL + +echo +report_stats +echo + +exit 0 |