From 0120bac7f603dc904b417da7b79f729ab86d6bba Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Mon, 20 Feb 2006 00:32:07 +0100
Subject: [PATCH] mysql-test-run.pl:   Added --restart-cleanup option
 drop-on-restart.inc:   DROP commands to cleanup on restart   new file
 mysqltest.c:   Added option --include=<sql-file>

---
 client/mysqltest.c                     |   8 +
 mysql-test/include/drop-on-restart.inc | 464 +++++++++++++++++++++++++
 mysql-test/mysql-test-run.pl           |  12 +-
 3 files changed, 483 insertions(+), 1 deletion(-)
 create mode 100644 mysql-test/include/drop-on-restart.inc

diff --git a/client/mysqltest.c b/client/mysqltest.c
index 0d97eb38c3..cf5d253fb6 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -157,6 +157,7 @@ static uint global_expected_errors;
 static int record = 0, opt_sleep=0;
 static char *db = 0, *pass=0;
 const char *user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./";
+const char *opt_include= 0;
 static int port = 0;
 static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0;
 static my_bool tty_password= 0;
@@ -3117,6 +3118,8 @@ static struct my_option my_long_options[] =
 #endif
   {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0,
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"include", 'i', "Include SQL before each test case.", (gptr*) &opt_include,
+   (gptr*) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {"manager-host", OPT_MANAGER_HOST, "Undocumented: Used for debugging.",
    (gptr*) &manager_host, (gptr*) &manager_host, 0, GET_STR, REQUIRED_ARG,
    0, 0, 0, 0, 0, 0},
@@ -4924,6 +4927,11 @@ int main(int argc, char **argv)
   */
   var_set_errno(-1);
 
+  if (opt_include)
+  {
+    open_file(opt_include);
+  }
+
   while (!abort_flag && !read_query(&q))
   {
     int current_line_inc = 1, processed = 0;
diff --git a/mysql-test/include/drop-on-restart.inc b/mysql-test/include/drop-on-restart.inc
new file mode 100644
index 0000000000..841b636483
--- /dev/null
+++ b/mysql-test/include/drop-on-restart.inc
@@ -0,0 +1,464 @@
+#
+# Stupid temporary way of cleaning up when restarting the server
+#
+
+--disable_warnings
+--disable_query_log
+
+drop database if exists BANK;
+drop database if exists MySQLTest;
+drop database if exists MySQLtesT;
+drop database if exists TEST_DB;
+drop database if exists `#mysql50#testdb-1`;
+drop database if exists `TEST_$1`;
+drop database if exists `drop-temp+table-test`;
+drop database if exists `test_$1`;
+drop database if exists `testdb-1`;
+drop database if exists `testdb1`;
+drop database if exists client_test_db;
+drop database if exists d1;
+drop database if exists d2;
+drop database if exists db1;
+drop database if exists db1_secret;
+drop database if exists db2;
+drop database if exists federated;
+drop database if exists mysqldump_test_db;
+drop database if exists mysqltest1;
+drop database if exists mysqltest2;
+drop database if exists mysqltest3;
+drop database if exists mysqltest;
+drop database if exists mysqltest;
+drop database if exists mysqltest_1;
+drop database if exists mysqltest_LC2;
+drop database if exists mysqltest_bob;
+drop database if exists mysqltest_db1;
+drop database if exists mysqltest_prometheus;
+drop database if exists mysqltest_sisyfos;
+drop database if exists ndbtest1;
+drop database if exists rewrite;
+drop database if exists test2;
+drop database if exists test_only_ndb_tables;
+drop database if exists test_test;
+drop database if exists testdb1;
+drop database if exists testtets;
+
+drop function if exists append;
+drop function if exists bug10015_1;
+drop function if exists bug10015_2;
+drop function if exists bug10015_3;
+drop function if exists bug10015_4;
+drop function if exists bug10015_5;
+drop function if exists bug10015_6;
+drop function if exists bug10015_7;
+drop function if exists bug10055;
+drop function if exists bug10100f;
+drop function if exists bug11394;
+drop function if exists bug11394_1;
+drop function if exists bug11394_2;
+drop function if exists bug11554;
+drop function if exists bug11555_1;
+drop function if exists bug11555_2;
+drop function if exists bug11834_1;
+drop function if exists bug11834_2;
+drop function if exists bug12379;
+drop function if exists bug12712;
+drop function if exists bug12812;
+drop function if exists bug12953;
+drop function if exists bug12995;
+drop function if exists bug13012;
+drop function if exists bug131333;
+drop function if exists bug13825_0;
+drop function if exists bug13825_1;
+drop function if exists bug13825_2;
+drop function if exists bug13825_3;
+drop function if exists bug13825_4;
+drop function if exists bug13825_5;
+drop function if exists bug13941;
+drop function if exists bug14233;
+drop function if exists bug14270;
+drop function if exists bug14723;
+drop function if exists bug2267_4;
+drop function if exists bug2564_3;
+drop function if exists bug2564_4;
+drop function if exists bug2674;
+drop function if exists bug2772;
+drop function if exists bug3132;
+drop function if exists bug4487;
+drop function if exists bug5240;
+drop function if exists bug5278;
+drop function if exists bug5893;
+drop function if exists bug6022;
+drop function if exists bug7049_1;
+drop function if exists bug7049_2;
+drop function if exists bug7648;
+drop function if exists bug8408_f;
+drop function if exists bug8409;
+drop function if exists bug8861;
+drop function if exists bug9048;
+drop function if exists bug9056_func1;
+drop function if exists bug9056_func2;
+drop function if exists bug9102;
+drop function if exists bug9559;
+drop function if exists bug9775;
+drop function if exists bug_13627_f;
+drop function if exists bug_9503;
+drop function if exists chistics;
+drop function if exists e;
+drop function if exists f0;
+drop function if exists f10;
+drop function if exists f11;
+drop function if exists f12_1;
+drop function if exists f12_2;
+drop function if exists f1;
+drop function if exists f2;
+drop function if exists f3;
+drop function if exists f4;
+drop function if exists f5;
+drop function if exists f6;
+drop function if exists f7;
+drop function if exists f8;
+drop function if exists f9;
+drop function if exists f_bug11247;
+drop function if exists fac;
+drop function if exists foo;
+drop function if exists fun;
+drop function if exists inc;
+drop function if exists mul;
+drop function if exists sp_vars_check_ret1;
+drop function if exists sp_vars_check_ret2;
+drop function if exists sp_vars_check_ret3;
+drop function if exists sp_vars_check_ret4;
+drop function if exists sub1;
+drop function if exists sub2;
+drop function if exists test.f1;
+
+drop procedure if exists BUG3259_2 ;
+drop procedure if exists Bug3259_3 ;
+drop procedure if exists ` bug15658`;
+drop procedure if exists `a'b`;
+drop procedure if exists a0;
+drop procedure if exists a;
+drop procedure if exists avg;
+drop procedure if exists b2;
+drop procedure if exists b;
+drop procedure if exists bar;
+drop procedure if exists bug10015_8;
+drop procedure if exists bug10100p;
+drop procedure if exists bug10100pc;
+drop procedure if exists bug10100pd;
+drop procedure if exists bug10100pt;
+drop procedure if exists bug10100pv;
+drop procedure if exists bug10100t;
+drop procedure if exists bug10136;
+drop procedure if exists bug10537;
+drop procedure if exists bug10961;
+drop procedure if exists bug10969;
+drop procedure if exists bug11158;
+drop procedure if exists bug11333;
+drop procedure if exists bug11394;
+drop procedure if exists bug11529;
+drop procedure if exists bug11587;
+drop procedure if exists bug12168;
+drop procedure if exists bug12297;
+drop procedure if exists bug12379_1;
+drop procedure if exists bug12379_2;
+drop procedure if exists bug12379_3;
+drop procedure if exists bug12589_1;
+drop procedure if exists bug12589_2;
+drop procedure if exists bug12589_3;
+drop procedure if exists bug12712;
+drop procedure if exists bug12849_1;
+drop procedure if exists bug12849_2;
+drop procedure if exists bug12979_1;
+drop procedure if exists bug12979_2;
+drop procedure if exists bug13012;
+drop procedure if exists bug13037_p1;
+drop procedure if exists bug13037_p2;
+drop procedure if exists bug13037_p3;
+drop procedure if exists bug13095;
+drop procedure if exists bug13124;
+drop procedure if exists bug131333;
+drop procedure if exists bug13510_1;
+drop procedure if exists bug13510_2;
+drop procedure if exists bug13510_3;
+drop procedure if exists bug13510_4;
+drop procedure if exists bug13549_1;
+drop procedure if exists bug13549_2;
+drop procedure if exists bug13729;
+drop procedure if exists bug13825_0;
+drop procedure if exists bug13825_1;
+drop procedure if exists bug13825_2;
+drop procedure if exists bug13941;
+drop procedure if exists bug14210;
+drop procedure if exists bug14233;
+drop procedure if exists bug14304;
+drop procedure if exists bug14376;
+drop procedure if exists bug14498_1;
+drop procedure if exists bug14498_2;
+drop procedure if exists bug14498_3;
+drop procedure if exists bug14498_4;
+drop procedure if exists bug14498_5;
+drop procedure if exists bug14643_1;
+drop procedure if exists bug14643_2;
+drop procedure if exists bug14723;
+drop procedure if exists bug14840_1;
+drop procedure if exists bug14840_2;
+drop procedure if exists bug1495;
+drop procedure if exists bug15011;
+drop procedure if exists bug15091;
+drop procedure if exists bug15231_1;
+drop procedure if exists bug15231_2;
+drop procedure if exists bug15231_3;
+drop procedure if exists bug15231_4;
+drop procedure if exists bug15441;
+drop procedure if exists bug1547;
+drop procedure if exists bug1656;
+drop procedure if exists bug1862;
+drop procedure if exists bug1863;
+drop procedure if exists bug1874;
+drop procedure if exists bug2227;
+drop procedure if exists bug2260;
+drop procedure if exists bug2267_1;
+drop procedure if exists bug2267_2;
+drop procedure if exists bug2267_3;
+drop procedure if exists bug2267_4;
+drop procedure if exists bug2460_1;
+drop procedure if exists bug2460_2;
+drop procedure if exists bug2564_1;
+drop procedure if exists bug2564_2;
+drop procedure if exists bug2614;
+drop procedure if exists bug2656_1;
+drop procedure if exists bug2656_2;
+drop procedure if exists bug2773;
+drop procedure if exists bug2776_1;
+drop procedure if exists bug2776_2;
+drop procedure if exists bug2780;
+drop procedure if exists bug3157;
+drop procedure if exists bug3259_1 ;
+drop procedure if exists bug3294;
+drop procedure if exists bug3368;
+drop procedure if exists bug336;
+drop procedure if exists bug3426;
+drop procedure if exists bug3448;
+drop procedure if exists bug3583;
+drop procedure if exists bug3734 ;
+drop procedure if exists bug3788;
+drop procedure if exists bug3843;
+drop procedure if exists bug3863;
+drop procedure if exists bug4318;
+drop procedure if exists bug4579_1;
+drop procedure if exists bug4579_2;
+drop procedure if exists bug4726;
+drop procedure if exists bug4902;
+drop procedure if exists bug4902_2;
+drop procedure if exists bug4904;
+drop procedure if exists bug4905;
+drop procedure if exists bug4941;
+drop procedure if exists bug5251;
+drop procedure if exists bug5258;
+drop procedure if exists bug5258_aux;
+drop procedure if exists bug5287;
+drop procedure if exists bug5307;
+drop procedure if exists bug5963;
+drop procedure if exists bug5967;
+drop procedure if exists bug6029;
+drop procedure if exists bug6063;
+drop procedure if exists bug6127;
+drop procedure if exists bug6129;
+drop procedure if exists bug6642;
+drop procedure if exists bug6807;
+drop procedure if exists bug6857;
+drop procedure if exists bug6866;
+drop procedure if exists bug6898;
+drop procedure if exists bug6900;
+drop procedure if exists bug6900_9074;
+drop procedure if exists bug7013;
+drop procedure if exists bug7049_1;
+drop procedure if exists bug7049_2;
+drop procedure if exists bug7049_3;
+drop procedure if exists bug7049_4;
+drop procedure if exists bug7088_1;
+drop procedure if exists bug7088_2;
+drop procedure if exists bug7293;
+drop procedure if exists bug7299;
+drop procedure if exists bug7743;
+drop procedure if exists bug8116;
+drop procedure if exists bug822;
+drop procedure if exists bug8408_p;
+drop procedure if exists bug8540;
+drop procedure if exists bug8692;
+drop procedure if exists bug8757;
+drop procedure if exists bug8762;
+drop procedure if exists bug8776_1;
+drop procedure if exists bug8776_2;
+drop procedure if exists bug8776_3;
+drop procedure if exists bug8776_4;
+drop procedure if exists bug8849;
+drop procedure if exists bug8850;
+drop procedure if exists bug8937;
+drop procedure if exists bug9004_1;
+drop procedure if exists bug9004_2;
+drop procedure if exists bug9056_proc1;
+drop procedure if exists bug9056_proc2;
+drop procedure if exists bug9073;
+drop procedure if exists bug9074;
+drop procedure if exists bug9367;
+drop procedure if exists bug9486;
+drop procedure if exists bug9538;
+drop procedure if exists bug9565;
+drop procedure if exists bug9565_sub;
+drop procedure if exists bug9566;
+drop procedure if exists bug9598_1;
+drop procedure if exists bug9598_2;
+drop procedure if exists bug9674_1;
+drop procedure if exists bug9674_2;
+drop procedure if exists bug9841;
+drop procedure if exists bug9856;
+drop procedure if exists bug9902;
+drop procedure if exists c1;
+drop procedure if exists c2;
+drop procedure if exists c3;
+drop procedure if exists c4;
+drop procedure if exists c;
+drop procedure if exists cbv1;
+drop procedure if exists cbv2;
+drop procedure if exists chistics;
+drop procedure if exists code_sample;
+drop procedure if exists create_select;
+drop procedure if exists cur1;
+drop procedure if exists cur2;
+drop procedure if exists d;
+drop procedure if exists dummy;
+drop procedure if exists e;
+drop procedure if exists empty;
+drop procedure if exists f1;
+drop procedure if exists f;
+drop procedure if exists fib;
+drop procedure if exists fn3;
+drop procedure if exists foo42;
+drop procedure if exists g;
+drop procedure if exists goto1;
+drop procedure if exists goto2;
+drop procedure if exists goto3;
+drop procedure if exists goto4;
+drop procedure if exists goto5;
+drop procedure if exists goto6;
+drop procedure if exists h;
+drop procedure if exists hndlr1;
+drop procedure if exists hndlr2;
+drop procedure if exists hndlr3;
+drop procedure if exists hndlr4;
+drop procedure if exists i;
+drop procedure if exists ifac;
+drop procedure if exists inc2;
+drop procedure if exists inc;
+drop procedure if exists incr;
+drop procedure if exists into_dumpfile;
+drop procedure if exists into_outfile;
+drop procedure if exists into_tes2;
+drop procedure if exists into_test3;
+drop procedure if exists into_test4;
+drop procedure if exists into_test;
+drop procedure if exists iotest;
+drop procedure if exists ip;
+drop procedure if exists locset;
+drop procedure if exists mixset;
+drop procedure if exists modes;
+drop procedure if exists mysqltest1.p1;
+drop procedure if exists mysqltest1.p2;
+drop procedure if exists nullset;
+drop procedure if exists opp;
+drop procedure if exists p1;
+drop procedure if exists p2;
+drop procedure if exists p3;
+drop procedure if exists p4;
+drop procedure if exists p5;
+drop procedure if exists p6;
+drop procedure if exists p;
+drop procedure if exists p_bug11247;
+drop procedure if exists rc;
+drop procedure if exists scope;
+drop procedure if exists sel1;
+drop procedure if exists sel2;
+drop procedure if exists setcontext;
+drop procedure if exists sp1;
+drop procedure if exists sp2;
+drop procedure if exists sp3;
+drop procedure if exists sp4;
+drop procedure if exists sp_vars_check_assignment;
+drop procedure if exists sp_vars_check_dflt;
+drop procedure if exists sub1;
+drop procedure if exists sub2;
+drop procedure if exists sub3;
+drop procedure if exists sudoku_solve;
+drop procedure if exists test.longprocedure;
+drop procedure if exists test.p1;
+drop procedure if exists test.p2;
+drop procedure if exists test.p3;
+drop procedure if exists test.p4;
+drop procedure if exists test.p5;
+drop procedure if exists test.p6;
+drop procedure if exists test.p7;
+drop procedure if exists two;
+drop procedure if exists zap;
+drop procedure if exists zip;
+
+drop table if exists T1;
+drop table if exists `"t"1`,t1aa,t2aa;
+drop table if exists ```a`;
+drop table if exists `t1 test`;
+drop table if exists `t1a``b`,v1,v2,v3,v4,v5,v6;
+drop table if exists `t2 test`;
+drop table if exists a;
+drop table if exists bug13095_t1;
+drop table if exists bug13894;
+drop table if exists bug14672;
+drop table if exists federated.alter_me;
+drop table if exists federated.archive_table;
+drop table if exists federated.bug_13118_table;
+drop table if exists federated.normal_table;
+drop table if exists federated.t1;
+drop table if exists gis_point,gis_line,gis_polygon,gis_multi_point,gis_multi_line,gis_multi_polygon,gis_geometrycollection,gis_geometry;
+drop table if exists mysqltest1.t1;
+drop table if exists mysqltest1.t2;
+drop table if exists mysqltest1.t3;
+drop table if exists mysqltest1.t4;
+drop table if exists mysqltest_bar;
+drop table if exists mysqltest_foo;
+drop table if exists new_t2;
+drop table if exists not_exist;
+drop table if exists r1;
+drop table if exists t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t21,t70;
+drop table if exists t0_template;
+drop table if exists t1Aa,t2Aa,v1Aa,v2Aa;
+drop table if exists t1_1,t1_2,t9_1,t9_2,t1aa,t2aa;
+drop table if exists t1_c,t2_c,t3_c,t4_c,t5_c,t6_c,t7_c,t8_c,t9_c;
+drop table if exists t1aa,t2aa;
+drop table if exists t2aA,t1Aa;
+drop table if exists test,test1,test2;
+drop table if exists v1,v2,v3;
+
+drop temporary table if exists test.t1;
+
+# This doesn't work
+#drop trigger if exists `test trig`;
+#drop trigger if exists test.t1_bd;
+#drop trigger if exists test.t1_bi;
+#drop trigger if exists test.t1_bi_t2;
+#drop trigger if exists test.t1_bu;
+#drop trigger if exists test.t2_ad;
+#drop trigger if exists test.t2_ai;
+#drop trigger if exists test.t2_au;
+#drop trigger if exists test.t3_bi_t2;
+
+drop view if exists bug13095_v1;
+drop view if exists mysqltest1.v1;
+drop view if exists mysqltest1.v2;
+drop view if exists mysqltest1.v3;
+drop view if exists mysqltest1.v4;
+drop view if exists t1,t2,`t1a``b`;
+drop view if exists t1Aa,t2Aa,v1Aa,v2Aa;
+drop view if exists v0,v1,v2,v3,v4,v5,v6;
+
+--enable_query_log
+--enable_warnings
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 73ca900280..55097a7dee 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -143,6 +143,7 @@ our $glob_use_running_server=     0;
 our $glob_use_running_ndbcluster= 0;
 our $glob_use_running_ndbcluster_slave= 0;
 our $glob_use_embedded_server=    0;
+our $glob_mysqld_restart=         0;
 our @glob_test_mode;
 
 our $using_ndbcluster_master= 0;
@@ -162,6 +163,7 @@ our $path_mysqltest_log;
 our $path_my_basedir;
 our $opt_vardir;                 # A path but set directly on cmd line
 our $opt_tmpdir;                 # A path but set directly on cmd line
+our $opt_restart_cleanup;        # Source a file with SQL drop statements
 
 our $opt_usage;
 our $opt_suite;
@@ -626,14 +628,15 @@ sub command_line_setup () {
 
              # Misc
              'big-test'                 => \$opt_big_test,
+             'comment=s'                => \$opt_comment,
              'debug'                    => \$opt_debug,
              'fast'                     => \$opt_fast,
-             'comment=s'                => \$opt_comment,
              'local'                    => \$opt_local,
              'local-master'             => \$opt_local_master,
              'netware'                  => \$opt_netware,
              'old-master'               => \$opt_old_master,
              'reorder'                  => \$opt_reorder,
+             'restart-cleanup'          => \$opt_restart_cleanup,
              'script-debug'             => \$opt_script_debug,
              'sleep=i'                  => \$opt_sleep,
              'socket=s'                 => \$opt_socket,
@@ -2242,6 +2245,7 @@ sub report_failure_and_restart ($) {
   {
     stop_masters_slaves();
   }
+  $glob_mysqld_restart= 1;
   print "Resuming Tests\n\n";
 }
 
@@ -3063,6 +3067,12 @@ sub run_mysqltest ($) {
     mtr_add_arg($args, "--sleep=%d", $opt_sleep);
   }
 
+  if ( $opt_restart_cleanup and $glob_mysqld_restart )
+  {
+    mtr_add_arg($args, "--include=%s", "include/drop-on-restart.inc");
+    $glob_mysqld_restart= 0;
+  }
+
   if ( $opt_debug )
   {
     mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace", $opt_vardir);
-- 
2.30.9