📄 mysql-test-run.pl
字号:
#!/usr/bin/perl# -*- cperl -*-# This is a transformation of the "mysql-test-run" Bourne shell script# to Perl. There are reasons this rewrite is not the prettiest Perl# you have seen## - The original script is huge and for most part uncommented,# not even a usage description of the flags.## - There has been an attempt to write a replacement in C for the# original Bourne shell script. It was kind of working but lacked# lot of functionality to really be a replacement. Not to redo# that mistake and catch all the obscure features of the original# script, the rewrite in Perl is more close to the original script# meaning it also share some of the ugly parts as well.## - The original intention was that this script was to be a prototype# to be the base for a new C version with full functionality. Since# then it was decided that the Perl version should replace the# Bourne shell version, but the Perl style still reflects the wish# to make the Perl to C step easy.## Some coding style from the original intent has been kept## - To make this Perl script easy to alter even for those that not# code Perl that often, the coding style is as close as possible to# the C/C++ MySQL coding standard.## - All lists of arguments to send to commands are Perl lists/arrays,# not strings we append args to. Within reason, most string# concatenation for arguments should be avoided.## - Functions defined in the main program are not to be prefixed,# functions in "library files" are to be prefixed with "mtr_" (for# Mysql-Test-Run). There are some exceptions, code that fits best in# the main program, but are put into separate files to avoid# clutter, may be without prefix.## - All stat/opendir/-f/ is to be kept in collect_test_cases(). It# will create a struct that the rest of the program can use to get# the information. This separates the "find information" from the# "do the work" and makes the program more easy to maintain.## - At the moment, there are tons of "global" variables that control# this script, even accessed from the files in "lib/*.pl". This# will change over time, for now global variables are used instead# of using %opt, %path and %exe hashes, because I want more# compile time checking, that hashes would not give me. Once this# script is debugged, hashes will be used and passed as parameters# to functions, to more closely mimic how it would be coded in C# using structs.## - The rule when it comes to the logic of this program is## command_line_setup() - is to handle the logic between flags# collect_test_cases() - is to do its best to select what tests# to run, dig out options, if needs restart etc.# run_testcase() - is to run a single testcase, and follow the# logic set in both above. No, or rare file# system operations. If a test seems complex,# it should probably not be here.## A nice way to trace the execution of this script while debugging# is to use the Devel::Trace package found at# "http://www.plover.com/~mjd/perl/Trace/" and run this script like# "perl -d:Trace mysql-test-run.pl"## FIXME Save a PID file from this code as well, to record the process# id we think it has. In Cygwin, a fork creates one Cygwin process,# and then the real Win32 process. Cygwin Perl can only kill Cygwin# processes. And "mysqld --bootstrap ..." doesn't save a PID file.$Devel::Trace::TRACE= 0; # Don't trace boring init stuff#require 5.6.1;use File::Path;use File::Basename;use Cwd;use Getopt::Long;use Sys::Hostname;#use Carp;use IO::Socket;use IO::Socket::INET;use Data::Dumper;use strict;#use diagnostics;require "lib/mtr_cases.pl";require "lib/mtr_process.pl";require "lib/mtr_timer.pl";require "lib/mtr_io.pl";require "lib/mtr_gcov.pl";require "lib/mtr_gprof.pl";require "lib/mtr_report.pl";require "lib/mtr_diff.pl";require "lib/mtr_match.pl";require "lib/mtr_misc.pl";require "lib/mtr_stress.pl";$Devel::Trace::TRACE= 1;# Used by gcovour @mysqld_src_dirs= ( "strings", "mysys", "include", "extra", "regex", "isam", "merge", "myisam", "myisammrg", "heap", "sql", );################################################################################ Default settings################################################################################ We are to use handle_options() in "mysys/my_getopt.c" for the C version## In the C version we want to use structs and, in some cases, arrays of# structs. We let each struct be a separate hash.# Misc global variablesour $glob_win32= 0; # OS and native Win32 executablesour $glob_win32_perl= 0; # ActiveState Win32 Perlour $glob_cygwin_perl= 0; # Cygwin Perlour $glob_cygwin_shell= undef;our $glob_mysql_test_dir= undef;our $glob_mysql_bench_dir= undef;our $glob_hostname= undef;our $glob_scriptname= undef;our $glob_timers= undef;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_test_mode;our $using_ndbcluster_master= 0;our $using_ndbcluster_slave= 0;our $glob_basedir;# The total resultour $path_charsetsdir;our $path_client_bindir;our $path_language;our $path_timefile;our $path_manager_log; # Used by mysqldadminour $path_mysqltest_log;our $path_slave_load_tmpdir; # What is this?!our $path_my_basedir;our $opt_vardir; # A path but set directly on cmd lineour $opt_tmpdir; # A path but set directly on cmd lineour $opt_usage;our $opt_suite;our $opt_netware;our $opt_script_debug= 0; # Script debugging, enable with --script-debug# Options FIXME not all....our $exe_master_mysqld;our $exe_mysql;our $exe_mysqladmin;our $exe_mysqlbinlog;our $exe_mysql_client_test;our $exe_mysqld;our $exe_mysqlcheck; # Called from test caseour $exe_mysqldump; # Called from test caseour $exe_mysqlslap; # Called from test caseour $exe_mysqlimport; # Called from test caseour $exe_mysqlshow; # Called from test caseour $exe_mysql_fix_system_tables;our $exe_mysqltest;our $exe_slave_mysqld;our $exe_im;our $exe_my_print_defaults;our $opt_bench= 0;our $opt_small_bench= 0;our $opt_big_test= 0; # Send --big-test to mysqltestour @opt_extra_mysqld_opt;our $opt_compress;our $opt_ssl;our $opt_skip_ssl;our $opt_ssl_supported;our $opt_ps_protocol;our $opt_sp_protocol;our $opt_cursor_protocol;our $opt_view_protocol;our $opt_current_test;our $opt_ddd;our $opt_debug;our $opt_do_test;our @opt_cases; # The test cases names in argvour $opt_embedded_server;our $opt_extern;our $opt_fast;our $opt_force;our $opt_reorder;our $opt_gcov;our $opt_gcov_err;our $opt_gcov_msg;our $opt_gdb;our $opt_client_gdb;our $opt_manual_gdb;our $opt_gprof;our $opt_gprof_dir;our $opt_gprof_master;our $opt_gprof_slave;our $opt_local;our $opt_local_master;our $master; # Will be struct in Cour $slave;our $instance_manager;our $opt_ndbcluster_port;our $opt_ndbconnectstring;our $opt_ndbcluster_port_slave;our $opt_ndbconnectstring_slave;our $opt_no_manager; # Does nothing now, we never use managerour $opt_manager_port; # Does nothing now, we never use managerour $opt_old_master;our $opt_record;our $opt_result_ext;our $opt_skip;our $opt_skip_rpl;our $opt_skip_test;our $opt_skip_im;our $opt_sleep;our $opt_sleep_time_after_restart= 1;our $opt_sleep_time_for_delete= 10;our $opt_testcase_timeout;our $opt_suite_timeout;my $default_testcase_timeout= 15; # 15 min maxmy $default_suite_timeout= 120; # 2 hours maxour $opt_socket;our $opt_source_dist;our $opt_start_and_exit;our $opt_start_dirty;our $opt_start_from;our $opt_strace_client;our $opt_timer;our $opt_user;our $opt_user_test;our $opt_valgrind;our $opt_valgrind_mysqld;our $opt_valgrind_mysqltest;our $opt_valgrind_all;our $opt_valgrind_options;our $opt_stress= "";our $opt_stress_suite= "main";our $opt_stress_mode= "random";our $opt_stress_threads= 5;our $opt_stress_test_count= 0;our $opt_stress_loop_count= 0;our $opt_stress_test_duration= 0;our $opt_stress_init_file= "";our $opt_stress_test_file= "";our $opt_verbose;our $opt_wait_for_master;our $opt_wait_for_slave;our $opt_wait_timeout= 10;our $opt_warnings;our $opt_udiff;our $opt_skip_ndbcluster;our $opt_with_ndbcluster;our $opt_skip_ndbcluster_slave;our $opt_with_ndbcluster_slave;our $opt_ndb_extra_test;our $exe_ndb_mgm;our $path_ndb_tools_dir;our $path_ndb_backup_dir;our $file_ndb_testrun_log;our $flag_ndb_status_ok= 1;our $flag_ndb_slave_status_ok= 1;######################################################################## Function declarations#######################################################################sub main ();sub initial_setup ();sub command_line_setup ();sub executable_setup ();sub environment_setup ();sub kill_running_server ();sub kill_and_cleanup ();sub check_ssl_support ();sub check_ndbcluster_support ();sub rm_ndbcluster_tables ($);sub ndbcluster_install ();sub ndbcluster_start ($);sub ndbcluster_stop ();sub ndbcluster_install_slave ();sub ndbcluster_start_slave ($);sub ndbcluster_stop_slave ();sub run_benchmarks ($);sub run_tests ();sub mysql_install_db ();sub install_db ($$);sub run_testcase ($);sub report_failure_and_restart ($);sub do_before_start_master ($$);sub do_before_start_slave ($$);sub mysqld_start ($$$$$);sub mysqld_arguments ($$$$$$);sub stop_masters_slaves ();sub stop_masters ();sub stop_slaves ();sub im_start ($$);sub im_stop ($);sub run_mysqltest ($);sub usage ($);######################################################################## Main program#######################################################################main();sub main () { initial_setup(); command_line_setup(); executable_setup(); check_ndbcluster_support(); check_ssl_support(); environment_setup(); signal_setup(); if ( $opt_gcov ) { gcov_prepare(); } if ( $opt_gprof ) { gprof_prepare(); } if ( ! $glob_use_running_server ) { if ( $opt_start_dirty ) { kill_running_server(); } else { kill_and_cleanup(); mysql_install_db();# mysql_loadstd(); FIXME copying from "std_data" .frm and# .MGR but there are none?! } } if ( $opt_start_dirty ) { if ( ndbcluster_start($opt_with_ndbcluster) ) { mtr_error("Can't start ndbcluster"); } if ( mysqld_start('master',0,[],[],$using_ndbcluster_master) ) { mtr_report("Servers started, exiting"); } else { mtr_error("Can't start the mysqld server"); } } elsif ( $opt_bench ) { run_benchmarks(shift); # Shift what? Extra arguments?! } elsif ( $opt_stress ) { run_stress_test() } else { run_tests(); } mtr_exit(0);}################################################################################ Initial setup independent on command line arguments###############################################################################
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -