You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6248 lines
174 KiB

WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
18 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
18 years ago
17 years ago
18 years ago
18 years ago
18 years ago
18 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
18 years ago
18 years ago
18 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
18 years ago
18 years ago
18 years ago
Bug #42804 --parallel option does not work for MTR under ActiveState perl The problem here was the method how MTR gets its unique thread ids. Prior to this patch, the method to do it was to maintain a global table of pid,mtr_unique_id) pairs. The table was backed by a text file. The table was cleaned up one in a while and dead processes leaking unique_ids were determined with with kill(0) or with scripting tasklist on Windows. This method is flawed specifically on native Windows Perl. fork() is implemented with starting a new thread, give it a syntetic negative PID (threadID*(-1)), until this thread creates a new process with exec() However, neither tasklist nor any other native Windows tool can cope with negative perl PIDs. This lead to incorrect determination of dead process and reusing already used mtr_unique_id. The patch introduces alternative portable method of solving unique-id problem. When a process needs a unique id in range [min...max], it just starts to open files named min, min+1,...max in a loop . After file is opened, we do non-blocking flock(). When flock() succeeds, process has allocated the ID. When process dies, file is unlocked . Checks for zombies are not necessary. Since the change would create a co-existence problems with older version of MTR, because of different way to calculate IDs, the default ID range is changed from 250-299 to 300-349. Another fix that was necessary enable --parallel option was to serialize spawn() calls on Windows. specifically, IO redirects needed to be protected. This patch also fixes hanging CRTL-C (as described in Bug #38629) for the "new" MTR. The fix was already in 6.0 and is now downported.
17 years ago
Bug #42804 --parallel option does not work for MTR under ActiveState perl The problem here was the method how MTR gets its unique thread ids. Prior to this patch, the method to do it was to maintain a global table of pid,mtr_unique_id) pairs. The table was backed by a text file. The table was cleaned up one in a while and dead processes leaking unique_ids were determined with with kill(0) or with scripting tasklist on Windows. This method is flawed specifically on native Windows Perl. fork() is implemented with starting a new thread, give it a syntetic negative PID (threadID*(-1)), until this thread creates a new process with exec() However, neither tasklist nor any other native Windows tool can cope with negative perl PIDs. This lead to incorrect determination of dead process and reusing already used mtr_unique_id. The patch introduces alternative portable method of solving unique-id problem. When a process needs a unique id in range [min...max], it just starts to open files named min, min+1,...max in a loop . After file is opened, we do non-blocking flock(). When flock() succeeds, process has allocated the ID. When process dies, file is unlocked . Checks for zombies are not necessary. Since the change would create a co-existence problems with older version of MTR, because of different way to calculate IDs, the default ID range is changed from 250-299 to 300-349. Another fix that was necessary enable --parallel option was to serialize spawn() calls on Windows. specifically, IO redirects needed to be protected. This patch also fixes hanging CRTL-C (as described in Bug #38629) for the "new" MTR. The fix was already in 6.0 and is now downported.
17 years ago
Bug #42804 --parallel option does not work for MTR under ActiveState perl The problem here was the method how MTR gets its unique thread ids. Prior to this patch, the method to do it was to maintain a global table of pid,mtr_unique_id) pairs. The table was backed by a text file. The table was cleaned up one in a while and dead processes leaking unique_ids were determined with with kill(0) or with scripting tasklist on Windows. This method is flawed specifically on native Windows Perl. fork() is implemented with starting a new thread, give it a syntetic negative PID (threadID*(-1)), until this thread creates a new process with exec() However, neither tasklist nor any other native Windows tool can cope with negative perl PIDs. This lead to incorrect determination of dead process and reusing already used mtr_unique_id. The patch introduces alternative portable method of solving unique-id problem. When a process needs a unique id in range [min...max], it just starts to open files named min, min+1,...max in a loop . After file is opened, we do non-blocking flock(). When flock() succeeds, process has allocated the ID. When process dies, file is unlocked . Checks for zombies are not necessary. Since the change would create a co-existence problems with older version of MTR, because of different way to calculate IDs, the default ID range is changed from 250-299 to 300-349. Another fix that was necessary enable --parallel option was to serialize spawn() calls on Windows. specifically, IO redirects needed to be protected. This patch also fixes hanging CRTL-C (as described in Bug #38629) for the "new" MTR. The fix was already in 6.0 and is now downported.
17 years ago
Bug #42804 --parallel option does not work for MTR under ActiveState perl The problem here was the method how MTR gets its unique thread ids. Prior to this patch, the method to do it was to maintain a global table of pid,mtr_unique_id) pairs. The table was backed by a text file. The table was cleaned up one in a while and dead processes leaking unique_ids were determined with with kill(0) or with scripting tasklist on Windows. This method is flawed specifically on native Windows Perl. fork() is implemented with starting a new thread, give it a syntetic negative PID (threadID*(-1)), until this thread creates a new process with exec() However, neither tasklist nor any other native Windows tool can cope with negative perl PIDs. This lead to incorrect determination of dead process and reusing already used mtr_unique_id. The patch introduces alternative portable method of solving unique-id problem. When a process needs a unique id in range [min...max], it just starts to open files named min, min+1,...max in a loop . After file is opened, we do non-blocking flock(). When flock() succeeds, process has allocated the ID. When process dies, file is unlocked . Checks for zombies are not necessary. Since the change would create a co-existence problems with older version of MTR, because of different way to calculate IDs, the default ID range is changed from 250-299 to 300-349. Another fix that was necessary enable --parallel option was to serialize spawn() calls on Windows. specifically, IO redirects needed to be protected. This patch also fixes hanging CRTL-C (as described in Bug #38629) for the "new" MTR. The fix was already in 6.0 and is now downported.
17 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
15 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
16 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
18 years ago
BUG#49978: Replication tests don't clean up replication state at the end Major replication test framework cleanup. This does the following: - Ensure that all tests clean up the replication state when they finish, by making check-testcase check the output of SHOW SLAVE STATUS. This implies: - Slave must not be running after test finished. This is good because it removes the risk for sporadic errors in subsequent tests when a test forgets to sync correctly. - Slave SQL and IO errors must be cleared when test ends. This is good because we will notice if a test gets an unexpected error in the slave threads near the end. - We no longer have to clean up before a test starts. - Ensure that all tests that wait for an error in one of the slave threads waits for a specific error. It is no longer possible to source wait_for_slave_[sql|io]_to_stop.inc when there is an error in one of the slave threads. This is good because: - If a test expects an error but there is a bug that causes another error to happen, or if it stops the slave thread without an error, then we will notice. - When developing tests, wait_for_*_to_[start|stop].inc will fail immediately if there is an error in the relevant slave thread. Before this patch, we had to wait for the timeout. - Remove duplicated and repeated code for setting up unusual replication topologies. Now, there is a single file that is capable of setting up arbitrary topologies (include/rpl_init.inc, but include/master-slave.inc is still available for the most common topology). Tests can now end with include/rpl_end.inc, which will clean up correctly no matter what topology is used. The topology can be changed with include/rpl_change_topology.inc. - Improved debug information when tests fail. This includes: - debug info is printed on all servers configured by include/rpl_init.inc - User can set $rpl_debug=1, which makes auxiliary replication files print relevant debug info. - Improved documentation for all auxiliary replication files. Now they describe purpose, usage, parameters, and side effects. - Many small code cleanups: - Made have_innodb.inc output a sensible error message. - Moved contents of rpl000017-slave.sh into rpl000017.test - Added mysqltest variables that expose the current state of disable_warnings/enable_warnings and friends. - Too many to list here: see per-file comments for details.
15 years ago
BUG#49978: Replication tests don't clean up replication state at the end Major replication test framework cleanup. This does the following: - Ensure that all tests clean up the replication state when they finish, by making check-testcase check the output of SHOW SLAVE STATUS. This implies: - Slave must not be running after test finished. This is good because it removes the risk for sporadic errors in subsequent tests when a test forgets to sync correctly. - Slave SQL and IO errors must be cleared when test ends. This is good because we will notice if a test gets an unexpected error in the slave threads near the end. - We no longer have to clean up before a test starts. - Ensure that all tests that wait for an error in one of the slave threads waits for a specific error. It is no longer possible to source wait_for_slave_[sql|io]_to_stop.inc when there is an error in one of the slave threads. This is good because: - If a test expects an error but there is a bug that causes another error to happen, or if it stops the slave thread without an error, then we will notice. - When developing tests, wait_for_*_to_[start|stop].inc will fail immediately if there is an error in the relevant slave thread. Before this patch, we had to wait for the timeout. - Remove duplicated and repeated code for setting up unusual replication topologies. Now, there is a single file that is capable of setting up arbitrary topologies (include/rpl_init.inc, but include/master-slave.inc is still available for the most common topology). Tests can now end with include/rpl_end.inc, which will clean up correctly no matter what topology is used. The topology can be changed with include/rpl_change_topology.inc. - Improved debug information when tests fail. This includes: - debug info is printed on all servers configured by include/rpl_init.inc - User can set $rpl_debug=1, which makes auxiliary replication files print relevant debug info. - Improved documentation for all auxiliary replication files. Now they describe purpose, usage, parameters, and side effects. - Many small code cleanups: - Made have_innodb.inc output a sensible error message. - Moved contents of rpl000017-slave.sh into rpl000017.test - Added mysqltest variables that expose the current state of disable_warnings/enable_warnings and friends. - Too many to list here: see per-file comments for details.
15 years ago
BUG#49978: Replication tests don't clean up replication state at the end Major replication test framework cleanup. This does the following: - Ensure that all tests clean up the replication state when they finish, by making check-testcase check the output of SHOW SLAVE STATUS. This implies: - Slave must not be running after test finished. This is good because it removes the risk for sporadic errors in subsequent tests when a test forgets to sync correctly. - Slave SQL and IO errors must be cleared when test ends. This is good because we will notice if a test gets an unexpected error in the slave threads near the end. - We no longer have to clean up before a test starts. - Ensure that all tests that wait for an error in one of the slave threads waits for a specific error. It is no longer possible to source wait_for_slave_[sql|io]_to_stop.inc when there is an error in one of the slave threads. This is good because: - If a test expects an error but there is a bug that causes another error to happen, or if it stops the slave thread without an error, then we will notice. - When developing tests, wait_for_*_to_[start|stop].inc will fail immediately if there is an error in the relevant slave thread. Before this patch, we had to wait for the timeout. - Remove duplicated and repeated code for setting up unusual replication topologies. Now, there is a single file that is capable of setting up arbitrary topologies (include/rpl_init.inc, but include/master-slave.inc is still available for the most common topology). Tests can now end with include/rpl_end.inc, which will clean up correctly no matter what topology is used. The topology can be changed with include/rpl_change_topology.inc. - Improved debug information when tests fail. This includes: - debug info is printed on all servers configured by include/rpl_init.inc - User can set $rpl_debug=1, which makes auxiliary replication files print relevant debug info. - Improved documentation for all auxiliary replication files. Now they describe purpose, usage, parameters, and side effects. - Many small code cleanups: - Made have_innodb.inc output a sensible error message. - Moved contents of rpl000017-slave.sh into rpl000017.test - Added mysqltest variables that expose the current state of disable_warnings/enable_warnings and friends. - Too many to list here: see per-file comments for details.
15 years ago
BUG#49978: Replication tests don't clean up replication state at the end Major replication test framework cleanup. This does the following: - Ensure that all tests clean up the replication state when they finish, by making check-testcase check the output of SHOW SLAVE STATUS. This implies: - Slave must not be running after test finished. This is good because it removes the risk for sporadic errors in subsequent tests when a test forgets to sync correctly. - Slave SQL and IO errors must be cleared when test ends. This is good because we will notice if a test gets an unexpected error in the slave threads near the end. - We no longer have to clean up before a test starts. - Ensure that all tests that wait for an error in one of the slave threads waits for a specific error. It is no longer possible to source wait_for_slave_[sql|io]_to_stop.inc when there is an error in one of the slave threads. This is good because: - If a test expects an error but there is a bug that causes another error to happen, or if it stops the slave thread without an error, then we will notice. - When developing tests, wait_for_*_to_[start|stop].inc will fail immediately if there is an error in the relevant slave thread. Before this patch, we had to wait for the timeout. - Remove duplicated and repeated code for setting up unusual replication topologies. Now, there is a single file that is capable of setting up arbitrary topologies (include/rpl_init.inc, but include/master-slave.inc is still available for the most common topology). Tests can now end with include/rpl_end.inc, which will clean up correctly no matter what topology is used. The topology can be changed with include/rpl_change_topology.inc. - Improved debug information when tests fail. This includes: - debug info is printed on all servers configured by include/rpl_init.inc - User can set $rpl_debug=1, which makes auxiliary replication files print relevant debug info. - Improved documentation for all auxiliary replication files. Now they describe purpose, usage, parameters, and side effects. - Many small code cleanups: - Made have_innodb.inc output a sensible error message. - Moved contents of rpl000017-slave.sh into rpl000017.test - Added mysqltest variables that expose the current state of disable_warnings/enable_warnings and friends. - Too many to list here: see per-file comments for details.
15 years ago
BUG#49978: Replication tests don't clean up replication state at the end Major replication test framework cleanup. This does the following: - Ensure that all tests clean up the replication state when they finish, by making check-testcase check the output of SHOW SLAVE STATUS. This implies: - Slave must not be running after test finished. This is good because it removes the risk for sporadic errors in subsequent tests when a test forgets to sync correctly. - Slave SQL and IO errors must be cleared when test ends. This is good because we will notice if a test gets an unexpected error in the slave threads near the end. - We no longer have to clean up before a test starts. - Ensure that all tests that wait for an error in one of the slave threads waits for a specific error. It is no longer possible to source wait_for_slave_[sql|io]_to_stop.inc when there is an error in one of the slave threads. This is good because: - If a test expects an error but there is a bug that causes another error to happen, or if it stops the slave thread without an error, then we will notice. - When developing tests, wait_for_*_to_[start|stop].inc will fail immediately if there is an error in the relevant slave thread. Before this patch, we had to wait for the timeout. - Remove duplicated and repeated code for setting up unusual replication topologies. Now, there is a single file that is capable of setting up arbitrary topologies (include/rpl_init.inc, but include/master-slave.inc is still available for the most common topology). Tests can now end with include/rpl_end.inc, which will clean up correctly no matter what topology is used. The topology can be changed with include/rpl_change_topology.inc. - Improved debug information when tests fail. This includes: - debug info is printed on all servers configured by include/rpl_init.inc - User can set $rpl_debug=1, which makes auxiliary replication files print relevant debug info. - Improved documentation for all auxiliary replication files. Now they describe purpose, usage, parameters, and side effects. - Many small code cleanups: - Made have_innodb.inc output a sensible error message. - Moved contents of rpl000017-slave.sh into rpl000017.test - Added mysqltest variables that expose the current state of disable_warnings/enable_warnings and friends. - Too many to list here: see per-file comments for details.
15 years ago
17 years ago
18 years ago
16 years ago
18 years ago
18 years ago
20 years ago
20 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
Fixed compiler warnings Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb
19 years ago
18 years ago
WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies
16 years ago
  1. #!/usr/bin/perl
  2. # -*- cperl -*-
  3. # Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; version 2 of the License.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. ##############################################################################
  19. #
  20. # mysql-test-run.pl
  21. #
  22. # Tool used for executing a suite of .test files
  23. #
  24. # See the "MySQL Test framework manual" for more information
  25. # http://dev.mysql.com/doc/mysqltest/en/index.html
  26. #
  27. #
  28. ##############################################################################
  29. use strict;
  30. use warnings;
  31. BEGIN {
  32. # Check that mysql-test-run.pl is started from mysql-test/
  33. unless ( -f "mysql-test-run.pl" )
  34. {
  35. print "**** ERROR **** ",
  36. "You must start mysql-test-run from the mysql-test/ directory\n";
  37. exit(1);
  38. }
  39. # Check that lib exist
  40. unless ( -d "lib/" )
  41. {
  42. print "**** ERROR **** ",
  43. "Could not find the lib/ directory \n";
  44. exit(1);
  45. }
  46. }
  47. BEGIN {
  48. # Check backward compatibility support
  49. # By setting the environment variable MTR_VERSION
  50. # it's possible to use a previous version of
  51. # mysql-test-run.pl
  52. my $version= $ENV{MTR_VERSION} || 2;
  53. if ( $version == 1 )
  54. {
  55. print "=======================================================\n";
  56. print " WARNING: Using mysql-test-run.pl version 1! \n";
  57. print "=======================================================\n";
  58. # Should use exec() here on *nix but this appears not to work on Windows
  59. exit(system($^X, "lib/v1/mysql-test-run.pl", @ARGV) >> 8);
  60. }
  61. elsif ( $version == 2 )
  62. {
  63. # This is the current version, just continue
  64. ;
  65. }
  66. else
  67. {
  68. print "ERROR: Version $version of mysql-test-run does not exist!\n";
  69. exit(1);
  70. }
  71. }
  72. use lib "lib";
  73. use Cwd;
  74. use Getopt::Long;
  75. use My::File::Path; # Patched version of File::Path
  76. use File::Basename;
  77. use File::Copy;
  78. use File::Find;
  79. use File::Temp qw/tempdir/;
  80. use File::Spec::Functions qw/splitdir/;
  81. use My::Platform;
  82. use My::SafeProcess;
  83. use My::ConfigFactory;
  84. use My::Options;
  85. use My::Find;
  86. use My::SysInfo;
  87. use My::CoreDump;
  88. use mtr_cases;
  89. use mtr_report;
  90. use mtr_match;
  91. use mtr_unique;
  92. use mtr_results;
  93. use IO::Socket::INET;
  94. use IO::Select;
  95. require "lib/mtr_process.pl";
  96. require "lib/mtr_io.pl";
  97. require "lib/mtr_gcov.pl";
  98. require "lib/mtr_gprof.pl";
  99. require "lib/mtr_misc.pl";
  100. $SIG{INT}= sub { mtr_error("Got ^C signal"); };
  101. our $mysql_version_id;
  102. my $mysql_version_extra;
  103. our $glob_mysql_test_dir;
  104. our $basedir;
  105. our $bindir;
  106. our $path_charsetsdir;
  107. our $path_client_bindir;
  108. our $path_client_libdir;
  109. our $path_language;
  110. our $path_current_testlog;
  111. our $path_testlog;
  112. our $default_vardir;
  113. our $opt_vardir; # Path to use for var/ dir
  114. my $path_vardir_trace; # unix formatted opt_vardir for trace files
  115. my $opt_tmpdir; # Path to use for tmp/ dir
  116. my $opt_tmpdir_pid;
  117. my $opt_start;
  118. my $opt_start_dirty;
  119. my $opt_start_exit;
  120. my $start_only;
  121. my $auth_plugin; # the path to the authentication test plugin
  122. END {
  123. if ( defined $opt_tmpdir_pid and $opt_tmpdir_pid == $$ )
  124. {
  125. if (!$opt_start_exit)
  126. {
  127. # Remove the tempdir this process has created
  128. mtr_verbose("Removing tmpdir $opt_tmpdir");
  129. rmtree($opt_tmpdir);
  130. }
  131. else
  132. {
  133. mtr_warning("tmpdir $opt_tmpdir should be removed after the server has finished");
  134. }
  135. }
  136. }
  137. sub env_or_val($$) { defined $ENV{$_[0]} ? $ENV{$_[0]} : $_[1] }
  138. my $path_config_file; # The generated config file, var/my.cnf
  139. # Visual Studio produces executables in different sub-directories based on the
  140. # configuration used to build them. To make life easier, an environment
  141. # variable or command-line option may be specified to control which set of
  142. # executables will be used by the test suite.
  143. our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
  144. # If you add a new suite, please check TEST_DIRS in Makefile.am.
  145. #
  146. my $DEFAULT_SUITES= "main,sys_vars,binlog,federated,rpl,innodb,perfschema";
  147. my $opt_suites;
  148. our $opt_verbose= 0; # Verbose output, enable with --verbose
  149. our $exe_mysql;
  150. our $exe_mysql_plugin;
  151. our $exe_mysqladmin;
  152. our $exe_mysqltest;
  153. our $exe_libtool;
  154. our $exe_mysql_embedded;
  155. our $opt_big_test= 0;
  156. our @opt_combinations;
  157. our @opt_extra_mysqld_opt;
  158. our @opt_mysqld_envs;
  159. my $opt_stress;
  160. my $opt_compress;
  161. my $opt_ssl;
  162. my $opt_skip_ssl;
  163. my @opt_skip_test_list;
  164. our $opt_ssl_supported;
  165. my $opt_ps_protocol;
  166. my $opt_sp_protocol;
  167. my $opt_cursor_protocol;
  168. my $opt_view_protocol;
  169. our $opt_debug;
  170. my $debug_d= "d";
  171. my $opt_debug_common;
  172. our $opt_debug_server;
  173. our @opt_cases; # The test cases names in argv
  174. our $opt_embedded_server;
  175. # -1 indicates use default, override with env.var.
  176. our $opt_ctest= env_or_val(MTR_UNIT_TESTS => -1);
  177. # Unit test report stored here for delayed printing
  178. my $ctest_report;
  179. # Options used when connecting to an already running server
  180. my %opts_extern;
  181. sub using_extern { return (keys %opts_extern > 0);};
  182. our $opt_fast= 0;
  183. our $opt_force;
  184. our $opt_mem= $ENV{'MTR_MEM'};
  185. our $opt_clean_vardir= $ENV{'MTR_CLEAN_VARDIR'};
  186. our $opt_gcov;
  187. our $opt_gcov_exe= "gcov";
  188. our $opt_gcov_err= "mysql-test-gcov.err";
  189. our $opt_gcov_msg= "mysql-test-gcov.msg";
  190. our $opt_gprof;
  191. our %gprof_dirs;
  192. our $glob_debugger= 0;
  193. our $opt_gdb;
  194. our $opt_client_gdb;
  195. my $opt_boot_gdb;
  196. our $opt_dbx;
  197. our $opt_client_dbx;
  198. my $opt_boot_dbx;
  199. our $opt_ddd;
  200. our $opt_client_ddd;
  201. my $opt_boot_ddd;
  202. our $opt_manual_gdb;
  203. our $opt_manual_dbx;
  204. our $opt_manual_ddd;
  205. our $opt_manual_debug;
  206. our $opt_debugger;
  207. our $opt_client_debugger;
  208. my $config; # The currently running config
  209. my $current_config_name; # The currently running config file template
  210. our @opt_experimentals;
  211. our $experimental_test_cases= [];
  212. my $baseport;
  213. # $opt_build_thread may later be set from $opt_port_base
  214. my $opt_build_thread= $ENV{'MTR_BUILD_THREAD'} || "auto";
  215. my $opt_port_base= $ENV{'MTR_PORT_BASE'} || "auto";
  216. my $build_thread= 0;
  217. my $opt_record;
  218. my $opt_report_features;
  219. our $opt_resfile= $ENV{'MTR_RESULT_FILE'} || 0;
  220. my $opt_skip_core;
  221. our $opt_check_testcases= 1;
  222. my $opt_mark_progress;
  223. my $opt_max_connections;
  224. our $opt_report_times= 0;
  225. my $opt_sleep;
  226. my $opt_testcase_timeout= $ENV{MTR_TESTCASE_TIMEOUT} || 15; # minutes
  227. my $opt_suite_timeout = $ENV{MTR_SUITE_TIMEOUT} || 300; # minutes
  228. my $opt_shutdown_timeout= $ENV{MTR_SHUTDOWN_TIMEOUT} || 10; # seconds
  229. my $opt_start_timeout = $ENV{MTR_START_TIMEOUT} || 180; # seconds
  230. sub suite_timeout { return $opt_suite_timeout * 60; };
  231. my $opt_wait_all;
  232. my $opt_user_args;
  233. my $opt_repeat= 1;
  234. my $opt_retry= 3;
  235. my $opt_retry_failure= env_or_val(MTR_RETRY_FAILURE => 2);
  236. my $opt_reorder= 1;
  237. my $opt_force_restart= 0;
  238. my $opt_strace_client;
  239. my $opt_strace_server;
  240. our $opt_user = "root";
  241. our $opt_valgrind= 0;
  242. my $opt_valgrind_mysqld= 0;
  243. my $opt_valgrind_mysqltest= 0;
  244. my @default_valgrind_args= ("--show-reachable=yes");
  245. my @valgrind_args;
  246. my $opt_valgrind_path;
  247. my $valgrind_reports= 0;
  248. my $opt_callgrind;
  249. my %mysqld_logs;
  250. my $opt_debug_sync_timeout= 300; # Default timeout for WAIT_FOR actions.
  251. sub testcase_timeout ($) {
  252. my ($tinfo)= @_;
  253. if (exists $tinfo->{'case-timeout'}) {
  254. # Return test specific timeout if *longer* that the general timeout
  255. my $test_to= $tinfo->{'case-timeout'};
  256. $test_to*= 10 if $opt_valgrind;
  257. return $test_to * 60 if $test_to > $opt_testcase_timeout;
  258. }
  259. return $opt_testcase_timeout * 60;
  260. }
  261. sub check_timeout ($) { return testcase_timeout($_[0]) / 10; }
  262. our $opt_warnings= 1;
  263. our $opt_include_ndbcluster= 0;
  264. our $opt_skip_ndbcluster= 1;
  265. my $exe_ndbd;
  266. my $exe_ndbmtd;
  267. my $exe_ndb_mgmd;
  268. my $exe_ndb_waiter;
  269. my $exe_ndb_mgm;
  270. our $debug_compiled_binaries;
  271. our %mysqld_variables;
  272. my $source_dist= 0;
  273. my $opt_max_save_core= env_or_val(MTR_MAX_SAVE_CORE => 5);
  274. my $opt_max_save_datadir= env_or_val(MTR_MAX_SAVE_DATADIR => 20);
  275. my $opt_max_test_fail= env_or_val(MTR_MAX_TEST_FAIL => 10);
  276. my $opt_parallel= $ENV{MTR_PARALLEL} || 1;
  277. select(STDOUT);
  278. $| = 1; # Automatically flush STDOUT
  279. # Used by --result-file for for formatting times
  280. sub isotime($) {
  281. my ($sec,$min,$hr,$day,$mon,$yr)= gmtime($_[0]);
  282. return sprintf "%d-%02d-%02dT%02d:%02d:%02dZ",
  283. $yr+1900, $mon+1, $day, $hr, $min, $sec;
  284. }
  285. main();
  286. sub main {
  287. # Default, verbosity on
  288. report_option('verbose', 0);
  289. # This is needed for test log evaluation in "gen-build-status-page"
  290. # in all cases where the calling tool does not log the commands
  291. # directly before it executes them, like "make test-force-pl" in RPM builds.
  292. mtr_report("Logging: $0 ", join(" ", @ARGV));
  293. command_line_setup();
  294. # --help will not reach here, so now it's safe to assume we have binaries
  295. My::SafeProcess::find_bin();
  296. if ( $opt_gcov ) {
  297. gcov_prepare($basedir);
  298. }
  299. if (!$opt_suites) {
  300. $opt_suites= $DEFAULT_SUITES;
  301. # Check for any extra suites to enable based on the path name
  302. my %extra_suites=
  303. (
  304. "mysql-5.1-new-ndb" => "ndb_team",
  305. "mysql-5.1-new-ndb-merge" => "ndb_team",
  306. "mysql-5.1-telco-6.2" => "ndb_team",
  307. "mysql-5.1-telco-6.2-merge" => "ndb_team",
  308. "mysql-5.1-telco-6.3" => "ndb_team",
  309. "mysql-6.0-ndb" => "ndb_team",
  310. );
  311. foreach my $dir ( reverse splitdir($basedir) ) {
  312. my $extra_suite= $extra_suites{$dir};
  313. if (defined $extra_suite) {
  314. mtr_report("Found extra suite: $extra_suite");
  315. $opt_suites= "$extra_suite,$opt_suites";
  316. last;
  317. }
  318. }
  319. }
  320. mtr_report("Using suites: $opt_suites") unless @opt_cases;
  321. init_timers();
  322. mtr_report("Collecting tests...");
  323. my $tests= collect_test_cases($opt_reorder, $opt_suites, \@opt_cases, \@opt_skip_test_list);
  324. mark_time_used('collect');
  325. if ( $opt_report_features ) {
  326. # Put "report features" as the first test to run
  327. my $tinfo = My::Test->new
  328. (
  329. name => 'report_features',
  330. # No result_file => Prints result
  331. path => 'include/report-features.test',
  332. template_path => "include/default_my.cnf",
  333. master_opt => [],
  334. slave_opt => [],
  335. );
  336. unshift(@$tests, $tinfo);
  337. }
  338. print "vardir: $opt_vardir\n";
  339. initialize_servers();
  340. #######################################################################
  341. my $num_tests= @$tests;
  342. if ( $opt_parallel eq "auto" ) {
  343. # Try to find a suitable value for number of workers
  344. my $sys_info= My::SysInfo->new();
  345. $opt_parallel= $sys_info->num_cpus();
  346. for my $limit (2000, 1500, 1000, 500){
  347. $opt_parallel-- if ($sys_info->min_bogomips() < $limit);
  348. }
  349. my $max_par= $ENV{MTR_MAX_PARALLEL} || 8;
  350. $opt_parallel= $max_par if ($opt_parallel > $max_par);
  351. $opt_parallel= $num_tests if ($opt_parallel > $num_tests);
  352. $opt_parallel= 1 if (IS_WINDOWS and $sys_info->isvm());
  353. $opt_parallel= 1 if ($opt_parallel < 1);
  354. mtr_report("Using parallel: $opt_parallel");
  355. }
  356. $ENV{MTR_PARALLEL} = $opt_parallel;
  357. if ($opt_parallel > 1 && ($opt_start_exit || $opt_stress)) {
  358. mtr_warning("Parallel cannot be used with --start-and-exit or --stress\n" .
  359. "Setting parallel to 1");
  360. $opt_parallel= 1;
  361. }
  362. # Create server socket on any free port
  363. my $server = new IO::Socket::INET
  364. (
  365. LocalAddr => 'localhost',
  366. Proto => 'tcp',
  367. Listen => $opt_parallel,
  368. );
  369. mtr_error("Could not create testcase server port: $!") unless $server;
  370. my $server_port = $server->sockport();
  371. mtr_report("Using server port $server_port");
  372. if ($opt_resfile) {
  373. resfile_init("$opt_vardir/mtr-results.txt");
  374. print_global_resfile();
  375. }
  376. # --------------------------------------------------------------------------
  377. # Read definitions from include/plugin.defs
  378. #
  379. read_plugin_defs("include/plugin.defs");
  380. # Also read from any plugin local or suite specific plugin.defs
  381. for (glob "$basedir/plugin/*/tests/mtr/plugin.defs".
  382. " suite/*/plugin.defs") {
  383. read_plugin_defs($_);
  384. }
  385. # Simplify reference to semisync plugins
  386. $ENV{'SEMISYNC_PLUGIN_OPT'}= $ENV{'SEMISYNC_MASTER_PLUGIN_OPT'};
  387. # Create child processes
  388. my %children;
  389. for my $child_num (1..$opt_parallel){
  390. my $child_pid= My::SafeProcess::Base::_safe_fork();
  391. if ($child_pid == 0){
  392. $server= undef; # Close the server port in child
  393. $tests= {}; # Don't need the tests list in child
  394. # Use subdir of var and tmp unless only one worker
  395. if ($opt_parallel > 1) {
  396. set_vardir("$opt_vardir/$child_num");
  397. $opt_tmpdir= "$opt_tmpdir/$child_num";
  398. }
  399. init_timers();
  400. run_worker($server_port, $child_num);
  401. exit(1);
  402. }
  403. $children{$child_pid}= 1;
  404. }
  405. #######################################################################
  406. mtr_report();
  407. mtr_print_thick_line();
  408. mtr_print_header($opt_parallel > 1);
  409. mark_time_used('init');
  410. my $completed= run_test_server($server, $tests, $opt_parallel);
  411. exit(0) if $opt_start_exit;
  412. # Send Ctrl-C to any children still running
  413. kill("INT", keys(%children));
  414. # Wait for childs to exit
  415. foreach my $pid (keys %children)
  416. {
  417. my $ret_pid= waitpid($pid, 0);
  418. if ($ret_pid != $pid){
  419. mtr_report("Unknown process $ret_pid exited");
  420. }
  421. else {
  422. delete $children{$ret_pid};
  423. }
  424. }
  425. if ( not defined @$completed ) {
  426. mtr_error("Test suite aborted");
  427. }
  428. if ( @$completed != $num_tests){
  429. if ($opt_force){
  430. # All test should have been run, print any that are still in $tests
  431. #foreach my $test ( @$tests ){
  432. # $test->print_test();
  433. #}
  434. }
  435. # Not all tests completed, failure
  436. mtr_report();
  437. mtr_report("Only ", int(@$completed), " of $num_tests completed.");
  438. mtr_error("Not all tests completed");
  439. }
  440. mark_time_used('init');
  441. push @$completed, run_ctest() if $opt_ctest;
  442. if ($opt_valgrind) {
  443. # Create minimalistic "test" for the reporting
  444. my $tinfo = My::Test->new
  445. (
  446. name => 'valgrind_report',
  447. );
  448. # Set dummy worker id to align report with normal tests
  449. $tinfo->{worker} = 0 if $opt_parallel > 1;
  450. if ($valgrind_reports) {
  451. $tinfo->{result}= 'MTR_RES_FAILED';
  452. $tinfo->{comment}= "Valgrind reported failures at shutdown, see above";
  453. $tinfo->{failures}= 1;
  454. } else {
  455. $tinfo->{result}= 'MTR_RES_PASSED';
  456. }
  457. mtr_report_test($tinfo);
  458. push @$completed, $tinfo;
  459. }
  460. mtr_print_line();
  461. if ( $opt_gcov ) {
  462. gcov_collect($bindir, $opt_gcov_exe,
  463. $opt_gcov_msg, $opt_gcov_err);
  464. }
  465. if ($ctest_report) {
  466. print "$ctest_report\n";
  467. mtr_print_line();
  468. }
  469. print_total_times($opt_parallel) if $opt_report_times;
  470. mtr_report_stats("Completed", $completed);
  471. remove_vardir_subs() if $opt_clean_vardir;
  472. exit(0);
  473. }
  474. sub run_test_server ($$$) {
  475. my ($server, $tests, $childs) = @_;
  476. my $num_saved_cores= 0; # Number of core files saved in vardir/log/ so far.
  477. my $num_saved_datadir= 0; # Number of datadirs saved in vardir/log/ so far.
  478. my $num_failed_test= 0; # Number of tests failed so far
  479. # Scheduler variables
  480. my $max_ndb= $ENV{MTR_MAX_NDB} || $childs / 2;
  481. $max_ndb = $childs if $max_ndb > $childs;
  482. $max_ndb = 1 if $max_ndb < 1;
  483. my $num_ndb_tests= 0;
  484. my $completed= [];
  485. my %running;
  486. my $result;
  487. my $exe_mysqld= find_mysqld($basedir) || ""; # Used as hint to CoreDump
  488. my $suite_timeout= start_timer(suite_timeout());
  489. my $s= IO::Select->new();
  490. $s->add($server);
  491. while (1) {
  492. mark_time_used('admin');
  493. my @ready = $s->can_read(1); # Wake up once every second
  494. mark_time_idle();
  495. foreach my $sock (@ready) {
  496. if ($sock == $server) {
  497. # New client connected
  498. my $child= $sock->accept();
  499. mtr_verbose("Client connected");
  500. $s->add($child);
  501. print $child "HELLO\n";
  502. }
  503. else {
  504. my $line= <$sock>;
  505. if (!defined $line) {
  506. # Client disconnected
  507. mtr_verbose("Child closed socket");
  508. $s->remove($sock);
  509. if (--$childs == 0){
  510. return $completed;
  511. }
  512. next;
  513. }
  514. chomp($line);
  515. if ($line eq 'TESTRESULT'){
  516. $result= My::Test::read_test($sock);
  517. # $result->print_test();
  518. # Report test status
  519. mtr_report_test($result);
  520. if ( $result->is_failed() ) {
  521. # Save the workers "savedir" in var/log
  522. my $worker_savedir= $result->{savedir};
  523. my $worker_savename= basename($worker_savedir);
  524. my $savedir= "$opt_vardir/log/$worker_savename";
  525. if ($opt_max_save_datadir > 0 &&
  526. $num_saved_datadir >= $opt_max_save_datadir)
  527. {
  528. mtr_report(" - skipping '$worker_savedir/'");
  529. rmtree($worker_savedir);
  530. }
  531. else {
  532. mtr_report(" - saving '$worker_savedir/' to '$savedir/'");
  533. rename($worker_savedir, $savedir);
  534. # Move any core files from e.g. mysqltest
  535. foreach my $coref (glob("core*"), glob("*.dmp"))
  536. {
  537. mtr_report(" - found '$coref', moving it to '$savedir'");
  538. move($coref, $savedir);
  539. }
  540. if ($opt_max_save_core > 0) {
  541. # Limit number of core files saved
  542. find({ no_chdir => 1,
  543. wanted => sub {
  544. my $core_file= $File::Find::name;
  545. my $core_name= basename($core_file);
  546. # Name beginning with core, not ending in .gz
  547. if (($core_name =~ /^core/ and $core_name !~ /\.gz$/)
  548. or (IS_WINDOWS and $core_name =~ /\.dmp$/)){
  549. # Ending with .dmp
  550. mtr_report(" - found '$core_name'",
  551. "($num_saved_cores/$opt_max_save_core)");
  552. My::CoreDump->show($core_file, $exe_mysqld);
  553. if ($num_saved_cores >= $opt_max_save_core) {
  554. mtr_report(" - deleting it, already saved",
  555. "$opt_max_save_core");
  556. unlink("$core_file");
  557. } else {
  558. mtr_compress_file($core_file) unless @opt_cases;
  559. }
  560. ++$num_saved_cores;
  561. }
  562. }
  563. },
  564. $savedir);
  565. }
  566. }
  567. resfile_print_test();
  568. $num_saved_datadir++;
  569. $num_failed_test++ unless ($result->{retries} ||
  570. $result->{exp_fail});
  571. if ( !$opt_force ) {
  572. # Test has failed, force is off
  573. push(@$completed, $result);
  574. return $completed unless $result->{'dont_kill_server'};
  575. # Prevent kill of server, to get valgrind report
  576. print $sock "BYE\n";
  577. next;
  578. }
  579. elsif ($opt_max_test_fail > 0 and
  580. $num_failed_test >= $opt_max_test_fail) {
  581. push(@$completed, $result);
  582. mtr_report_stats("Too many failed", $completed, 1);
  583. mtr_report("Too many tests($num_failed_test) failed!",
  584. "Terminating...");
  585. return undef;
  586. }
  587. }
  588. resfile_print_test();
  589. # Retry test run after test failure
  590. my $retries= $result->{retries} || 2;
  591. my $test_has_failed= $result->{failures} || 0;
  592. if ($test_has_failed and $retries <= $opt_retry){
  593. # Test should be run one more time unless it has failed
  594. # too many times already
  595. my $tname= $result->{name};
  596. my $failures= $result->{failures};
  597. if ($opt_retry > 1 and $failures >= $opt_retry_failure){
  598. mtr_report("\nTest $tname has failed $failures times,",
  599. "no more retries!\n");
  600. }
  601. else {
  602. mtr_report("\nRetrying test $tname, ".
  603. "attempt($retries/$opt_retry)...\n");
  604. delete($result->{result});
  605. $result->{retries}= $retries+1;
  606. $result->write_test($sock, 'TESTCASE');
  607. next;
  608. }
  609. }
  610. # Repeat test $opt_repeat number of times
  611. my $repeat= $result->{repeat} || 1;
  612. # Don't repeat if test was skipped
  613. if ($repeat < $opt_repeat && $result->{'result'} ne 'MTR_RES_SKIPPED')
  614. {
  615. $result->{retries}= 0;
  616. $result->{rep_failures}++ if $result->{failures};
  617. $result->{failures}= 0;
  618. delete($result->{result});
  619. $result->{repeat}= $repeat+1;
  620. $result->write_test($sock, 'TESTCASE');
  621. next;
  622. }
  623. # Remove from list of running
  624. mtr_error("'", $result->{name},"' is not known to be running")
  625. unless delete $running{$result->key()};
  626. # Update scheduler variables
  627. $num_ndb_tests-- if ($result->{ndb_test});
  628. # Save result in completed list
  629. push(@$completed, $result);
  630. }
  631. elsif ($line eq 'START'){
  632. ; # Send first test
  633. }
  634. elsif ($line =~ /^SPENT/) {
  635. add_total_times($line);
  636. }
  637. elsif ($line eq 'VALGREP' && $opt_valgrind) {
  638. $valgrind_reports= 1;
  639. }
  640. else {
  641. mtr_error("Unknown response: '$line' from client");
  642. }
  643. # Find next test to schedule
  644. # - Try to use same configuration as worker used last time
  645. # - Limit number of parallel ndb tests
  646. my $next;
  647. my $second_best;
  648. for(my $i= 0; $i <= @$tests; $i++)
  649. {
  650. my $t= $tests->[$i];
  651. last unless defined $t;
  652. if (run_testcase_check_skip_test($t)){
  653. # Move the test to completed list
  654. #mtr_report("skip - Moving test $i to completed");
  655. push(@$completed, splice(@$tests, $i, 1));
  656. # Since the test at pos $i was taken away, next
  657. # test will also be at $i -> redo
  658. redo;
  659. }
  660. # Limit number of parallell NDB tests
  661. if ($t->{ndb_test} and $num_ndb_tests >= $max_ndb){
  662. #mtr_report("Skipping, num ndb is already at max, $num_ndb_tests");
  663. next;
  664. }
  665. # Second best choice is the first that does not fulfill
  666. # any of the above conditions
  667. if (!defined $second_best){
  668. #mtr_report("Setting second_best to $i");
  669. $second_best= $i;
  670. }
  671. # Smart allocation of next test within this thread.
  672. if ($opt_reorder and $opt_parallel > 1 and defined $result)
  673. {
  674. my $wid= $result->{worker};
  675. # Reserved for other thread, try next
  676. next if (defined $t->{reserved} and $t->{reserved} != $wid);
  677. if (! defined $t->{reserved})
  678. {
  679. # Force-restart not relevant when comparing *next* test
  680. $t->{criteria} =~ s/force-restart$/no-restart/;
  681. my $criteria= $t->{criteria};
  682. # Reserve similar tests for this worker, but not too many
  683. my $maxres= (@$tests - $i) / $opt_parallel + 1;
  684. for (my $j= $i+1; $j <= $i + $maxres; $j++)
  685. {
  686. my $tt= $tests->[$j];
  687. last unless defined $tt;
  688. last if $tt->{criteria} ne $criteria;
  689. $tt->{reserved}= $wid;
  690. }
  691. }
  692. }
  693. # At this point we have found next suitable test
  694. $next= splice(@$tests, $i, 1);
  695. last;
  696. }
  697. # Use second best choice if no other test has been found
  698. if (!$next and defined $second_best){
  699. #mtr_report("Take second best choice $second_best");
  700. mtr_error("Internal error, second best too large($second_best)")
  701. if $second_best > $#$tests;
  702. $next= splice(@$tests, $second_best, 1);
  703. delete $next->{reserved};
  704. }
  705. if ($next) {
  706. # We don't need this any more
  707. delete $next->{criteria};
  708. $next->write_test($sock, 'TESTCASE');
  709. $running{$next->key()}= $next;
  710. $num_ndb_tests++ if ($next->{ndb_test});
  711. }
  712. else {
  713. # No more test, tell child to exit
  714. #mtr_report("Saying BYE to child");
  715. print $sock "BYE\n";
  716. }
  717. }
  718. }
  719. # ----------------------------------------------------
  720. # Check if test suite timer expired
  721. # ----------------------------------------------------
  722. if ( has_expired($suite_timeout) )
  723. {
  724. mtr_report_stats("Timeout", $completed, 1);
  725. mtr_report("Test suite timeout! Terminating...");
  726. return undef;
  727. }
  728. }
  729. }
  730. sub run_worker ($) {
  731. my ($server_port, $thread_num)= @_;
  732. $SIG{INT}= sub { exit(1); };
  733. # Connect to server
  734. my $server = new IO::Socket::INET
  735. (
  736. PeerAddr => 'localhost',
  737. PeerPort => $server_port,
  738. Proto => 'tcp'
  739. );
  740. mtr_error("Could not connect to server at port $server_port: $!")
  741. unless $server;
  742. # --------------------------------------------------------------------------
  743. # Set worker name
  744. # --------------------------------------------------------------------------
  745. report_option('name',"worker[$thread_num]");
  746. # --------------------------------------------------------------------------
  747. # Set different ports per thread
  748. # --------------------------------------------------------------------------
  749. set_build_thread_ports($thread_num);
  750. # --------------------------------------------------------------------------
  751. # Turn off verbosity in workers, unless explicitly specified
  752. # --------------------------------------------------------------------------
  753. report_option('verbose', undef) if ($opt_verbose == 0);
  754. environment_setup();
  755. # Read hello from server which it will send when shared
  756. # resources have been setup
  757. my $hello= <$server>;
  758. setup_vardir();
  759. check_running_as_root();
  760. if ( using_extern() ) {
  761. create_config_file_for_extern(%opts_extern);
  762. }
  763. # Ask server for first test
  764. print $server "START\n";
  765. mark_time_used('init');
  766. while (my $line= <$server>){
  767. chomp($line);
  768. if ($line eq 'TESTCASE'){
  769. my $test= My::Test::read_test($server);
  770. #$test->print_test();
  771. # Clear comment and logfile, to avoid
  772. # reusing them from previous test
  773. delete($test->{'comment'});
  774. delete($test->{'logfile'});
  775. # A sanity check. Should this happen often we need to look at it.
  776. if (defined $test->{reserved} && $test->{reserved} != $thread_num) {
  777. my $tres= $test->{reserved};
  778. mtr_warning("Test reserved for w$tres picked up by w$thread_num");
  779. }
  780. $test->{worker} = $thread_num if $opt_parallel > 1;
  781. run_testcase($test);
  782. #$test->{result}= 'MTR_RES_PASSED';
  783. # Send it back, now with results set
  784. #$test->print_test();
  785. $test->write_test($server, 'TESTRESULT');
  786. mark_time_used('restart');
  787. }
  788. elsif ($line eq 'BYE'){
  789. mtr_report("Server said BYE");
  790. stop_all_servers($opt_shutdown_timeout);
  791. mark_time_used('restart');
  792. my $valgrind_reports= 0;
  793. if ($opt_valgrind_mysqld) {
  794. $valgrind_reports= valgrind_exit_reports();
  795. print $server "VALGREP\n" if $valgrind_reports;
  796. }
  797. if ( $opt_gprof ) {
  798. gprof_collect (find_mysqld($basedir), keys %gprof_dirs);
  799. }
  800. mark_time_used('admin');
  801. print_times_used($server, $thread_num);
  802. exit($valgrind_reports);
  803. }
  804. else {
  805. mtr_error("Could not understand server, '$line'");
  806. }
  807. }
  808. stop_all_servers();
  809. exit(1);
  810. }
  811. sub ignore_option {
  812. my ($opt, $value)= @_;
  813. mtr_report("Ignoring option '$opt'");
  814. }
  815. # Setup any paths that are $opt_vardir related
  816. sub set_vardir {
  817. my ($vardir)= @_;
  818. $opt_vardir= $vardir;
  819. $path_vardir_trace= $opt_vardir;
  820. # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/...
  821. $path_vardir_trace=~ s/^\w://;
  822. # Location of my.cnf that all clients use
  823. $path_config_file= "$opt_vardir/my.cnf";
  824. $path_testlog= "$opt_vardir/log/mysqltest.log";
  825. $path_current_testlog= "$opt_vardir/log/current_test";
  826. }
  827. sub print_global_resfile {
  828. resfile_global("start_time", isotime $^T);
  829. resfile_global("user_id", $<);
  830. resfile_global("embedded-server", $opt_embedded_server ? 1 : 0);
  831. resfile_global("ps-protocol", $opt_ps_protocol ? 1 : 0);
  832. resfile_global("sp-protocol", $opt_sp_protocol ? 1 : 0);
  833. resfile_global("view-protocol", $opt_view_protocol ? 1 : 0);
  834. resfile_global("cursor-protocol", $opt_cursor_protocol ? 1 : 0);
  835. resfile_global("ssl", $opt_ssl ? 1 : 0);
  836. resfile_global("compress", $opt_compress ? 1 : 0);
  837. resfile_global("parallel", $opt_parallel);
  838. resfile_global("check-testcases", $opt_check_testcases ? 1 : 0);
  839. resfile_global("mysqld", \@opt_extra_mysqld_opt);
  840. resfile_global("debug", $opt_debug ? 1 : 0);
  841. resfile_global("gcov", $opt_gcov ? 1 : 0);
  842. resfile_global("gprof", $opt_gprof ? 1 : 0);
  843. resfile_global("valgrind", $opt_valgrind ? 1 : 0);
  844. resfile_global("callgrind", $opt_callgrind ? 1 : 0);
  845. resfile_global("mem", $opt_mem ? 1 : 0);
  846. resfile_global("tmpdir", $opt_tmpdir);
  847. resfile_global("vardir", $opt_vardir);
  848. resfile_global("fast", $opt_fast ? 1 : 0);
  849. resfile_global("force-restart", $opt_force_restart ? 1 : 0);
  850. resfile_global("reorder", $opt_reorder ? 1 : 0);
  851. resfile_global("sleep", $opt_sleep);
  852. resfile_global("repeat", $opt_repeat);
  853. resfile_global("user", $opt_user);
  854. resfile_global("testcase-timeout", $opt_testcase_timeout);
  855. resfile_global("suite-timeout", $opt_suite_timeout);
  856. resfile_global("shutdown-timeout", $opt_shutdown_timeout ? 1 : 0);
  857. resfile_global("warnings", $opt_warnings ? 1 : 0);
  858. resfile_global("max-connections", $opt_max_connections);
  859. # resfile_global("default-myisam", $opt_default_myisam ? 1 : 0);
  860. resfile_global("product", "MySQL");
  861. # Somewhat hacky code to convert numeric version back to dot notation
  862. my $v1= int($mysql_version_id / 10000);
  863. my $v2= int(($mysql_version_id % 10000)/100);
  864. my $v3= $mysql_version_id % 100;
  865. resfile_global("version", "$v1.$v2.$v3");
  866. }
  867. sub command_line_setup {
  868. my $opt_comment;
  869. my $opt_usage;
  870. my $opt_list_options;
  871. # Read the command line options
  872. # Note: Keep list in sync with usage at end of this file
  873. Getopt::Long::Configure("pass_through");
  874. my %options=(
  875. # Control what engine/variation to run
  876. 'embedded-server' => \$opt_embedded_server,
  877. 'ps-protocol' => \$opt_ps_protocol,
  878. 'sp-protocol' => \$opt_sp_protocol,
  879. 'view-protocol' => \$opt_view_protocol,
  880. 'cursor-protocol' => \$opt_cursor_protocol,
  881. 'ssl|with-openssl' => \$opt_ssl,
  882. 'skip-ssl' => \$opt_skip_ssl,
  883. 'compress' => \$opt_compress,
  884. 'vs-config=s' => \$opt_vs_config,
  885. # Max number of parallel threads to use
  886. 'parallel=s' => \$opt_parallel,
  887. # Config file to use as template for all tests
  888. 'defaults-file=s' => \&collect_option,
  889. # Extra config file to append to all generated configs
  890. 'defaults-extra-file=s' => \&collect_option,
  891. # Control what test suites or cases to run
  892. 'force' => \$opt_force,
  893. 'with-ndbcluster-only' => \&collect_option,
  894. 'include-ndbcluster' => \$opt_include_ndbcluster,
  895. 'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster,
  896. 'suite|suites=s' => \$opt_suites,
  897. 'skip-rpl' => \&collect_option,
  898. 'skip-test=s' => \&collect_option,
  899. 'do-test=s' => \&collect_option,
  900. 'start-from=s' => \&collect_option,
  901. 'big-test' => \$opt_big_test,
  902. 'combination=s' => \@opt_combinations,
  903. 'skip-combinations' => \&collect_option,
  904. 'experimental=s' => \@opt_experimentals,
  905. # skip-im is deprecated and silently ignored
  906. 'skip-im' => \&ignore_option,
  907. # Specify ports
  908. 'build-thread|mtr-build-thread=i' => \$opt_build_thread,
  909. 'port-base|mtr-port-base=i' => \$opt_port_base,
  910. # Test case authoring
  911. 'record' => \$opt_record,
  912. 'check-testcases!' => \$opt_check_testcases,
  913. 'mark-progress' => \$opt_mark_progress,
  914. # Extra options used when starting mysqld
  915. 'mysqld=s' => \@opt_extra_mysqld_opt,
  916. 'mysqld-env=s' => \@opt_mysqld_envs,
  917. # Run test on running server
  918. 'extern=s' => \%opts_extern, # Append to hash
  919. # Debugging
  920. 'debug' => \$opt_debug,
  921. 'debug-common' => \$opt_debug_common,
  922. 'debug-server' => \$opt_debug_server,
  923. 'gdb' => \$opt_gdb,
  924. 'client-gdb' => \$opt_client_gdb,
  925. 'manual-gdb' => \$opt_manual_gdb,
  926. 'boot-gdb' => \$opt_boot_gdb,
  927. 'manual-debug' => \$opt_manual_debug,
  928. 'ddd' => \$opt_ddd,
  929. 'client-ddd' => \$opt_client_ddd,
  930. 'manual-ddd' => \$opt_manual_ddd,
  931. 'boot-ddd' => \$opt_boot_ddd,
  932. 'dbx' => \$opt_dbx,
  933. 'client-dbx' => \$opt_client_dbx,
  934. 'manual-dbx' => \$opt_manual_dbx,
  935. 'debugger=s' => \$opt_debugger,
  936. 'boot-dbx' => \$opt_boot_dbx,
  937. 'client-debugger=s' => \$opt_client_debugger,
  938. 'strace-server' => \$opt_strace_server,
  939. 'strace-client' => \$opt_strace_client,
  940. 'max-save-core=i' => \$opt_max_save_core,
  941. 'max-save-datadir=i' => \$opt_max_save_datadir,
  942. 'max-test-fail=i' => \$opt_max_test_fail,
  943. # Coverage, profiling etc
  944. 'gcov' => \$opt_gcov,
  945. 'gprof' => \$opt_gprof,
  946. 'valgrind|valgrind-all' => \$opt_valgrind,
  947. 'valgrind-mysqltest' => \$opt_valgrind_mysqltest,
  948. 'valgrind-mysqld' => \$opt_valgrind_mysqld,
  949. 'valgrind-options=s' => sub {
  950. my ($opt, $value)= @_;
  951. # Deprecated option unless it's what we know pushbuild uses
  952. if ($value eq "--gen-suppressions=all --show-reachable=yes") {
  953. push(@valgrind_args, $_) for (split(' ', $value));
  954. return;
  955. }
  956. die("--valgrind-options=s is deprecated. Use ",
  957. "--valgrind-option=s, to be specified several",
  958. " times if necessary");
  959. },
  960. 'valgrind-option=s' => \@valgrind_args,
  961. 'valgrind-path=s' => \$opt_valgrind_path,
  962. 'callgrind' => \$opt_callgrind,
  963. 'debug-sync-timeout=i' => \$opt_debug_sync_timeout,
  964. # Directories
  965. 'tmpdir=s' => \$opt_tmpdir,
  966. 'vardir=s' => \$opt_vardir,
  967. 'mem' => \$opt_mem,
  968. 'clean-vardir' => \$opt_clean_vardir,
  969. 'client-bindir=s' => \$path_client_bindir,
  970. 'client-libdir=s' => \$path_client_libdir,
  971. # Misc
  972. 'report-features' => \$opt_report_features,
  973. 'comment=s' => \$opt_comment,
  974. 'fast' => \$opt_fast,
  975. 'force-restart' => \$opt_force_restart,
  976. 'reorder!' => \$opt_reorder,
  977. 'enable-disabled' => \&collect_option,
  978. 'verbose+' => \$opt_verbose,
  979. 'verbose-restart' => \&report_option,
  980. 'sleep=i' => \$opt_sleep,
  981. 'start-dirty' => \$opt_start_dirty,
  982. 'start-and-exit' => \$opt_start_exit,
  983. 'start' => \$opt_start,
  984. 'user-args' => \$opt_user_args,
  985. 'wait-all' => \$opt_wait_all,
  986. 'print-testcases' => \&collect_option,
  987. 'repeat=i' => \$opt_repeat,
  988. 'retry=i' => \$opt_retry,
  989. 'retry-failure=i' => \$opt_retry_failure,
  990. 'timer!' => \&report_option,
  991. 'user=s' => \$opt_user,
  992. 'testcase-timeout=i' => \$opt_testcase_timeout,
  993. 'suite-timeout=i' => \$opt_suite_timeout,
  994. 'shutdown-timeout=i' => \$opt_shutdown_timeout,
  995. 'warnings!' => \$opt_warnings,
  996. 'timestamp' => \&report_option,
  997. 'timediff' => \&report_option,
  998. 'max-connections=i' => \$opt_max_connections,
  999. 'default-myisam!' => \&collect_option,
  1000. 'report-times' => \$opt_report_times,
  1001. 'result-file' => \$opt_resfile,
  1002. 'unit-tests!' => \$opt_ctest,
  1003. 'stress=s' => \$opt_stress,
  1004. 'help|h' => \$opt_usage,
  1005. # list-options is internal, not listed in help
  1006. 'list-options' => \$opt_list_options,
  1007. 'skip-test-list=s' => \@opt_skip_test_list
  1008. );
  1009. GetOptions(%options) or usage("Can't read options");
  1010. usage("") if $opt_usage;
  1011. list_options(\%options) if $opt_list_options;
  1012. # --------------------------------------------------------------------------
  1013. # Setup verbosity
  1014. # --------------------------------------------------------------------------
  1015. if ($opt_verbose != 0){
  1016. report_option('verbose', $opt_verbose);
  1017. }
  1018. if ( -d "../sql" )
  1019. {
  1020. $source_dist= 1;
  1021. }
  1022. # Find the absolute path to the test directory
  1023. $glob_mysql_test_dir= cwd();
  1024. if ($glob_mysql_test_dir =~ / /)
  1025. {
  1026. die("Working directory \"$glob_mysql_test_dir\" contains space\n".
  1027. "Bailing out, cannot function properly with space in path");
  1028. }
  1029. if (IS_CYGWIN)
  1030. {
  1031. # Use mixed path format i.e c:/path/to/
  1032. $glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
  1033. }
  1034. # In most cases, the base directory we find everything relative to,
  1035. # is the parent directory of the "mysql-test" directory. For source
  1036. # distributions, TAR binary distributions and some other packages.
  1037. $basedir= dirname($glob_mysql_test_dir);
  1038. # In the RPM case, binaries and libraries are installed in the
  1039. # default system locations, instead of having our own private base
  1040. # directory. And we install "/usr/share/mysql-test". Moving up one
  1041. # more directory relative to "mysql-test" gives us a usable base
  1042. # directory for RPM installs.
  1043. if ( ! $source_dist and ! -d "$basedir/bin" )
  1044. {
  1045. $basedir= dirname($basedir);
  1046. }
  1047. # Respect MTR_BINDIR variable, which is typically set in to the
  1048. # build directory in out-of-source builds.
  1049. $bindir=$ENV{MTR_BINDIR}||$basedir;
  1050. # Look for the client binaries directory
  1051. if ($path_client_bindir)
  1052. {
  1053. # --client-bindir=path set on command line, check that the path exists
  1054. $path_client_bindir= mtr_path_exists($path_client_bindir);
  1055. }
  1056. else
  1057. {
  1058. $path_client_bindir= mtr_path_exists("$bindir/client_release",
  1059. "$bindir/client_debug",
  1060. vs_config_dirs('client', ''),
  1061. "$bindir/client",
  1062. "$bindir/bin");
  1063. }
  1064. # Look for language files and charsetsdir, use same share
  1065. $path_language= mtr_path_exists("$bindir/share/mysql",
  1066. "$bindir/sql/share",
  1067. "$bindir/share");
  1068. my $path_share= $path_language;
  1069. $path_charsetsdir = mtr_path_exists("$basedir/share/mysql/charsets",
  1070. "$basedir/sql/share/charsets",
  1071. "$basedir/share/charsets");
  1072. ($auth_plugin)= find_plugin("auth_test_plugin", "plugin/auth");
  1073. # --debug[-common] implies we run debug server
  1074. $opt_debug_server= 1 if $opt_debug || $opt_debug_common;
  1075. if (using_extern())
  1076. {
  1077. # Connect to the running mysqld and find out what it supports
  1078. collect_mysqld_features_from_running_server();
  1079. }
  1080. else
  1081. {
  1082. # Run the mysqld to find out what features are available
  1083. collect_mysqld_features();
  1084. }
  1085. if ( $opt_comment )
  1086. {
  1087. mtr_report();
  1088. mtr_print_thick_line('#');
  1089. mtr_report("# $opt_comment");
  1090. mtr_print_thick_line('#');
  1091. }
  1092. if ( @opt_experimentals )
  1093. {
  1094. # $^O on Windows considered not generic enough
  1095. my $plat= (IS_WINDOWS) ? 'windows' : $^O;
  1096. # read the list of experimental test cases from the files specified on
  1097. # the command line
  1098. $experimental_test_cases = [];
  1099. foreach my $exp_file (@opt_experimentals)
  1100. {
  1101. open(FILE, "<", $exp_file)
  1102. or mtr_error("Can't read experimental file: $exp_file");
  1103. mtr_report("Using experimental file: $exp_file");
  1104. while(<FILE>) {
  1105. chomp;
  1106. # remove comments (# foo) at the beginning of the line, or after a
  1107. # blank at the end of the line
  1108. s/(\s+|^)#.*$//;
  1109. # If @ platform specifier given, use this entry only if it contains
  1110. # @<platform> or @!<xxx> where xxx != platform
  1111. if (/\@.*/)
  1112. {
  1113. next if (/\@!$plat/);
  1114. next unless (/\@$plat/ or /\@!/);
  1115. # Then remove @ and everything after it
  1116. s/\@.*$//;
  1117. }
  1118. # remove whitespace
  1119. s/^\s+//;
  1120. s/\s+$//;
  1121. # if nothing left, don't need to remember this line
  1122. if ( $_ eq "" ) {
  1123. next;
  1124. }
  1125. # remember what is left as the name of another test case that should be
  1126. # treated as experimental
  1127. print " - $_\n";
  1128. push @$experimental_test_cases, $_;
  1129. }
  1130. close FILE;
  1131. }
  1132. }
  1133. foreach my $arg ( @ARGV )
  1134. {
  1135. if ( $arg =~ /^--skip-/ )
  1136. {
  1137. push(@opt_extra_mysqld_opt, $arg);
  1138. }
  1139. elsif ( $arg =~ /^--$/ )
  1140. {
  1141. # It is an effect of setting 'pass_through' in option processing
  1142. # that the lone '--' separating options from arguments survives,
  1143. # simply ignore it.
  1144. }
  1145. elsif ( $arg =~ /^-/ )
  1146. {
  1147. usage("Invalid option \"$arg\"");
  1148. }
  1149. else
  1150. {
  1151. push(@opt_cases, $arg);
  1152. }
  1153. }
  1154. # --------------------------------------------------------------------------
  1155. # Find out type of logging that are being used
  1156. # --------------------------------------------------------------------------
  1157. foreach my $arg ( @opt_extra_mysqld_opt )
  1158. {
  1159. if ( $arg =~ /binlog[-_]format=(\S+)/ )
  1160. {
  1161. # Save this for collect phase
  1162. collect_option('binlog-format', $1);
  1163. mtr_report("Using binlog format '$1'");
  1164. }
  1165. }
  1166. # --------------------------------------------------------------------------
  1167. # Find out default storage engine being used(if any)
  1168. # --------------------------------------------------------------------------
  1169. foreach my $arg ( @opt_extra_mysqld_opt )
  1170. {
  1171. if ( $arg =~ /default-storage-engine=(\S+)/ )
  1172. {
  1173. # Save this for collect phase
  1174. collect_option('default-storage-engine', $1);
  1175. mtr_report("Using default engine '$1'")
  1176. }
  1177. }
  1178. if (IS_WINDOWS and defined $opt_mem) {
  1179. mtr_report("--mem not supported on Windows, ignored");
  1180. $opt_mem= undef;
  1181. }
  1182. if ($opt_port_base ne "auto")
  1183. {
  1184. if (my $rem= $opt_port_base % 10)
  1185. {
  1186. mtr_warning ("Port base $opt_port_base rounded down to multiple of 10");
  1187. $opt_port_base-= $rem;
  1188. }
  1189. $opt_build_thread= $opt_port_base / 10 - 1000;
  1190. }
  1191. # --------------------------------------------------------------------------
  1192. # Check if we should speed up tests by trying to run on tmpfs
  1193. # --------------------------------------------------------------------------
  1194. if ( defined $opt_mem)
  1195. {
  1196. mtr_error("Can't use --mem and --vardir at the same time ")
  1197. if $opt_vardir;
  1198. mtr_error("Can't use --mem and --tmpdir at the same time ")
  1199. if $opt_tmpdir;
  1200. # Search through list of locations that are known
  1201. # to be "fast disks" to find a suitable location
  1202. # Use --mem=<dir> as first location to look.
  1203. my @tmpfs_locations= ($opt_mem, "/dev/shm", "/tmp");
  1204. foreach my $fs (@tmpfs_locations)
  1205. {
  1206. if ( -d $fs )
  1207. {
  1208. my $template= "var_${opt_build_thread}_XXXX";
  1209. $opt_mem= tempdir( $template, DIR => $fs, CLEANUP => 0);
  1210. last;
  1211. }
  1212. }
  1213. }
  1214. # --------------------------------------------------------------------------
  1215. # Set the "var/" directory, the base for everything else
  1216. # --------------------------------------------------------------------------
  1217. if(defined $ENV{MTR_BINDIR})
  1218. {
  1219. $default_vardir= "$ENV{MTR_BINDIR}/mysql-test/var";
  1220. }
  1221. else
  1222. {
  1223. $default_vardir= "$glob_mysql_test_dir/var";
  1224. }
  1225. if ( ! $opt_vardir )
  1226. {
  1227. $opt_vardir= $default_vardir;
  1228. }
  1229. # We make the path absolute, as the server will do a chdir() before usage
  1230. unless ( $opt_vardir =~ m,^/, or
  1231. (IS_WINDOWS and $opt_vardir =~ m,^[a-z]:[/\\],i) )
  1232. {
  1233. # Make absolute path, relative test dir
  1234. $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
  1235. }
  1236. set_vardir($opt_vardir);
  1237. # --------------------------------------------------------------------------
  1238. # Set the "tmp" directory
  1239. # --------------------------------------------------------------------------
  1240. if ( ! $opt_tmpdir )
  1241. {
  1242. $opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir;
  1243. if (check_socket_path_length("$opt_tmpdir/mysql_testsocket.sock"))
  1244. {
  1245. mtr_report("Too long tmpdir path '$opt_tmpdir'",
  1246. " creating a shorter one...");
  1247. # Create temporary directory in standard location for temporary files
  1248. $opt_tmpdir= tempdir( TMPDIR => 1, CLEANUP => 0 );
  1249. mtr_report(" - using tmpdir: '$opt_tmpdir'\n");
  1250. # Remember pid that created dir so it's removed by correct process
  1251. $opt_tmpdir_pid= $$;
  1252. }
  1253. }
  1254. $opt_tmpdir =~ s,/+$,,; # Remove ending slash if any
  1255. # --------------------------------------------------------------------------
  1256. # fast option
  1257. # --------------------------------------------------------------------------
  1258. if ($opt_fast){
  1259. $opt_shutdown_timeout= 0; # Kill processes instead of nice shutdown
  1260. }
  1261. # --------------------------------------------------------------------------
  1262. # Check parallel value
  1263. # --------------------------------------------------------------------------
  1264. if ($opt_parallel ne "auto" && $opt_parallel < 1)
  1265. {
  1266. mtr_error("0 or negative parallel value makes no sense, use 'auto' or positive number");
  1267. }
  1268. # --------------------------------------------------------------------------
  1269. # Record flag
  1270. # --------------------------------------------------------------------------
  1271. if ( $opt_record and ! @opt_cases )
  1272. {
  1273. mtr_error("Will not run in record mode without a specific test case");
  1274. }
  1275. if ( $opt_record ) {
  1276. # Use only one worker with --record
  1277. $opt_parallel= 1;
  1278. }
  1279. # --------------------------------------------------------------------------
  1280. # Embedded server flag
  1281. # --------------------------------------------------------------------------
  1282. if ( $opt_embedded_server )
  1283. {
  1284. if ( IS_WINDOWS )
  1285. {
  1286. # Add the location for libmysqld.dll to the path.
  1287. my $separator= ";";
  1288. my $lib_mysqld=
  1289. mtr_path_exists("$bindir/lib", vs_config_dirs('libmysqld',''));
  1290. if ( IS_CYGWIN )
  1291. {
  1292. $lib_mysqld= posix_path($lib_mysqld);
  1293. $separator= ":";
  1294. }
  1295. $ENV{'PATH'}= "$ENV{'PATH'}".$separator.$lib_mysqld;
  1296. }
  1297. $opt_skip_ndbcluster= 1; # Turn off use of NDB cluster
  1298. $opt_skip_ssl= 1; # Turn off use of SSL
  1299. # Turn off use of bin log
  1300. push(@opt_extra_mysqld_opt, "--skip-log-bin");
  1301. if ( using_extern() )
  1302. {
  1303. mtr_error("Can't use --extern with --embedded-server");
  1304. }
  1305. if ($opt_gdb)
  1306. {
  1307. mtr_warning("Silently converting --gdb to --client-gdb in embedded mode");
  1308. $opt_client_gdb= $opt_gdb;
  1309. $opt_gdb= undef;
  1310. }
  1311. if ($opt_ddd)
  1312. {
  1313. mtr_warning("Silently converting --ddd to --client-ddd in embedded mode");
  1314. $opt_client_ddd= $opt_ddd;
  1315. $opt_ddd= undef;
  1316. }
  1317. if ($opt_dbx) {
  1318. mtr_warning("Silently converting --dbx to --client-dbx in embedded mode");
  1319. $opt_client_dbx= $opt_dbx;
  1320. $opt_dbx= undef;
  1321. }
  1322. if ($opt_debugger)
  1323. {
  1324. mtr_warning("Silently converting --debugger to --client-debugger in embedded mode");
  1325. $opt_client_debugger= $opt_debugger;
  1326. $opt_debugger= undef;
  1327. }
  1328. if ( $opt_gdb || $opt_ddd || $opt_manual_gdb || $opt_manual_ddd ||
  1329. $opt_manual_debug || $opt_debugger || $opt_dbx || $opt_manual_dbx)
  1330. {
  1331. mtr_error("You need to use the client debug options for the",
  1332. "embedded server. Ex: --client-gdb");
  1333. }
  1334. }
  1335. # --------------------------------------------------------------------------
  1336. # Big test flags
  1337. # --------------------------------------------------------------------------
  1338. if ( $opt_big_test )
  1339. {
  1340. $ENV{'BIG_TEST'}= 1;
  1341. }
  1342. # --------------------------------------------------------------------------
  1343. # Gcov flag
  1344. # --------------------------------------------------------------------------
  1345. if ( ($opt_gcov or $opt_gprof) and ! $source_dist )
  1346. {
  1347. mtr_error("Coverage test needs the source - please use source dist");
  1348. }
  1349. # --------------------------------------------------------------------------
  1350. # Check debug related options
  1351. # --------------------------------------------------------------------------
  1352. if ( $opt_gdb || $opt_client_gdb || $opt_ddd || $opt_client_ddd ||
  1353. $opt_manual_gdb || $opt_manual_ddd || $opt_manual_debug ||
  1354. $opt_dbx || $opt_client_dbx || $opt_manual_dbx ||
  1355. $opt_debugger || $opt_client_debugger )
  1356. {
  1357. # Indicate that we are using debugger
  1358. $glob_debugger= 1;
  1359. if ( using_extern() )
  1360. {
  1361. mtr_error("Can't use --extern when using debugger");
  1362. }
  1363. # Set one week timeout (check-testcase timeout will be 1/10th)
  1364. $opt_testcase_timeout= 7 * 24 * 60;
  1365. $opt_suite_timeout= 7 * 24 * 60;
  1366. # One day to shutdown
  1367. $opt_shutdown_timeout= 24 * 60;
  1368. # One day for PID file creation (this is given in seconds not minutes)
  1369. $opt_start_timeout= 24 * 60 * 60;
  1370. }
  1371. # --------------------------------------------------------------------------
  1372. # Modified behavior with --start options
  1373. # --------------------------------------------------------------------------
  1374. if ($opt_start or $opt_start_dirty or $opt_start_exit) {
  1375. collect_option ('quick-collect', 1);
  1376. $start_only= 1;
  1377. }
  1378. # --------------------------------------------------------------------------
  1379. # Check use of user-args
  1380. # --------------------------------------------------------------------------
  1381. if ($opt_user_args) {
  1382. mtr_error("--user-args only valid with --start options")
  1383. unless $start_only;
  1384. mtr_error("--user-args cannot be combined with named suites or tests")
  1385. if $opt_suites || @opt_cases;
  1386. }
  1387. # --------------------------------------------------------------------------
  1388. # Don't run ctest if tests or suites named
  1389. # --------------------------------------------------------------------------
  1390. $opt_ctest= 0 if $opt_ctest == -1 && ($opt_suites || @opt_cases);
  1391. # Override: disable if running in the PB test environment
  1392. $opt_ctest= 0 if $opt_ctest == -1 && defined $ENV{PB2WORKDIR};
  1393. # --------------------------------------------------------------------------
  1394. # Check use of wait-all
  1395. # --------------------------------------------------------------------------
  1396. if ($opt_wait_all && ! $start_only)
  1397. {
  1398. mtr_error("--wait-all can only be used with --start options");
  1399. }
  1400. # --------------------------------------------------------------------------
  1401. # Gather stress-test options and modify behavior
  1402. # --------------------------------------------------------------------------
  1403. if ($opt_stress)
  1404. {
  1405. $opt_stress=~ s/,/ /g;
  1406. $opt_user_args= 1;
  1407. mtr_error("--stress cannot be combined with named ordinary suites or tests")
  1408. if $opt_suites || @opt_cases;
  1409. $opt_suites="stress";
  1410. @opt_cases= ("wrapper");
  1411. $ENV{MST_OPTIONS}= $opt_stress;
  1412. $opt_ctest= 0;
  1413. }
  1414. # --------------------------------------------------------------------------
  1415. # Check timeout arguments
  1416. # --------------------------------------------------------------------------
  1417. mtr_error("Invalid value '$opt_testcase_timeout' supplied ".
  1418. "for option --testcase-timeout")
  1419. if ($opt_testcase_timeout <= 0);
  1420. mtr_error("Invalid value '$opt_suite_timeout' supplied ".
  1421. "for option --testsuite-timeout")
  1422. if ($opt_suite_timeout <= 0);
  1423. # --------------------------------------------------------------------------
  1424. # Check valgrind arguments
  1425. # --------------------------------------------------------------------------
  1426. if ( $opt_valgrind or $opt_valgrind_path or @valgrind_args)
  1427. {
  1428. mtr_report("Turning on valgrind for all executables");
  1429. $opt_valgrind= 1;
  1430. $opt_valgrind_mysqld= 1;
  1431. $opt_valgrind_mysqltest= 1;
  1432. # Increase the timeouts when running with valgrind
  1433. $opt_testcase_timeout*= 10;
  1434. $opt_suite_timeout*= 6;
  1435. $opt_start_timeout*= 10;
  1436. }
  1437. elsif ( $opt_valgrind_mysqld )
  1438. {
  1439. mtr_report("Turning on valgrind for mysqld(s) only");
  1440. $opt_valgrind= 1;
  1441. }
  1442. elsif ( $opt_valgrind_mysqltest )
  1443. {
  1444. mtr_report("Turning on valgrind for mysqltest and mysql_client_test only");
  1445. $opt_valgrind= 1;
  1446. }
  1447. if ( $opt_callgrind )
  1448. {
  1449. mtr_report("Turning on valgrind with callgrind for mysqld(s)");
  1450. $opt_valgrind= 1;
  1451. $opt_valgrind_mysqld= 1;
  1452. # Set special valgrind options unless options passed on command line
  1453. push(@valgrind_args, "--trace-children=yes")
  1454. unless @valgrind_args;
  1455. }
  1456. if ( $opt_valgrind )
  1457. {
  1458. # Set valgrind_options to default unless already defined
  1459. push(@valgrind_args, @default_valgrind_args)
  1460. unless @valgrind_args;
  1461. # Don't add --quiet; you will loose the summary reports.
  1462. mtr_report("Running valgrind with options \"",
  1463. join(" ", @valgrind_args), "\"");
  1464. }
  1465. if ($opt_debug_common)
  1466. {
  1467. $opt_debug= 1;
  1468. $debug_d= "d,query,info,error,enter,exit";
  1469. }
  1470. if ( $opt_strace_server && ($^O ne "linux") )
  1471. {
  1472. $opt_strace_server=0;
  1473. mtr_warning("Strace only supported in Linux ");
  1474. }
  1475. if ( $opt_strace_client && ($^O ne "linux") )
  1476. {
  1477. $opt_strace_client=0;
  1478. mtr_warning("Strace only supported in Linux ");
  1479. }
  1480. mtr_report("Checking supported features...");
  1481. check_ndbcluster_support(\%mysqld_variables);
  1482. check_ssl_support(\%mysqld_variables);
  1483. check_debug_support(\%mysqld_variables);
  1484. executable_setup();
  1485. }
  1486. #
  1487. # To make it easier for different devs to work on the same host,
  1488. # an environment variable can be used to control all ports. A small
  1489. # number is to be used, 0 - 16 or similar.
  1490. #
  1491. # Note the MASTER_MYPORT has to be set the same in all 4.x and 5.x
  1492. # versions of this script, else a 4.0 test run might conflict with a
  1493. # 5.1 test run, even if different MTR_BUILD_THREAD is used. This means
  1494. # all port numbers might not be used in this version of the script.
  1495. #
  1496. # Also note the limitation of ports we are allowed to hand out. This
  1497. # differs between operating systems and configuration, see
  1498. # http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
  1499. # But a fairly safe range seems to be 5001 - 32767
  1500. #
  1501. sub set_build_thread_ports($) {
  1502. my $thread= shift || 0;
  1503. if ( lc($opt_build_thread) eq 'auto' ) {
  1504. my $found_free = 0;
  1505. $build_thread = 300; # Start attempts from here
  1506. while (! $found_free)
  1507. {
  1508. $build_thread= mtr_get_unique_id($build_thread, 349);
  1509. if ( !defined $build_thread ) {
  1510. mtr_error("Could not get a unique build thread id");
  1511. }
  1512. $found_free= check_ports_free($build_thread);
  1513. # If not free, release and try from next number
  1514. if (! $found_free) {
  1515. mtr_release_unique_id();
  1516. $build_thread++;
  1517. }
  1518. }
  1519. }
  1520. else
  1521. {
  1522. $build_thread = $opt_build_thread + $thread - 1;
  1523. if (! check_ports_free($build_thread)) {
  1524. # Some port was not free(which one has already been printed)
  1525. mtr_error("Some port(s) was not free")
  1526. }
  1527. }
  1528. $ENV{MTR_BUILD_THREAD}= $build_thread;
  1529. # Calculate baseport
  1530. $baseport= $build_thread * 10 + 10000;
  1531. if ( $baseport < 5001 or $baseport + 9 >= 32767 )
  1532. {
  1533. mtr_error("MTR_BUILD_THREAD number results in a port",
  1534. "outside 5001 - 32767",
  1535. "($baseport - $baseport + 9)");
  1536. }
  1537. mtr_report("Using MTR_BUILD_THREAD $build_thread,",
  1538. "with reserved ports $baseport..".($baseport+9));
  1539. }
  1540. sub collect_mysqld_features {
  1541. my $found_variable_list_start= 0;
  1542. my $use_tmpdir;
  1543. if ( defined $opt_tmpdir and -d $opt_tmpdir){
  1544. # Create the tempdir in $opt_tmpdir
  1545. $use_tmpdir= $opt_tmpdir;
  1546. }
  1547. my $tmpdir= tempdir(CLEANUP => 0, # Directory removed by this function
  1548. DIR => $use_tmpdir);
  1549. #
  1550. # Execute "mysqld --no-defaults --help --verbose" to get a
  1551. # list of all features and settings
  1552. #
  1553. # --no-defaults and --skip-grant-tables are to avoid loading
  1554. # system-wide configs and plugins
  1555. #
  1556. # --datadir must exist, mysqld will chdir into it
  1557. #
  1558. my $args;
  1559. mtr_init_args(\$args);
  1560. mtr_add_arg($args, "--no-defaults");
  1561. mtr_add_arg($args, "--datadir=%s", mixed_path($tmpdir));
  1562. mtr_add_arg($args, "--lc-messages-dir=%s", $path_language);
  1563. mtr_add_arg($args, "--skip-grant-tables");
  1564. mtr_add_arg($args, "--verbose");
  1565. mtr_add_arg($args, "--help");
  1566. # Need --user=root if running as *nix root user
  1567. if (!IS_WINDOWS and $> == 0)
  1568. {
  1569. mtr_add_arg($args, "--user=root");
  1570. }
  1571. my $exe_mysqld= find_mysqld($basedir);
  1572. my $cmd= join(" ", $exe_mysqld, @$args);
  1573. my $list= `$cmd`;
  1574. foreach my $line (split('\n', $list))
  1575. {
  1576. # First look for version
  1577. if ( !$mysql_version_id )
  1578. {
  1579. # Look for version
  1580. my $exe_name= basename($exe_mysqld);
  1581. mtr_verbose("exe_name: $exe_name");
  1582. if ( $line =~ /^\S*$exe_name\s\sVer\s([0-9]*)\.([0-9]*)\.([0-9]*)([^\s]*)/ )
  1583. {
  1584. #print "Major: $1 Minor: $2 Build: $3\n";
  1585. $mysql_version_id= $1*10000 + $2*100 + $3;
  1586. #print "mysql_version_id: $mysql_version_id\n";
  1587. mtr_report("MySQL Version $1.$2.$3");
  1588. $mysql_version_extra= $4;
  1589. }
  1590. }
  1591. else
  1592. {
  1593. if (!$found_variable_list_start)
  1594. {
  1595. # Look for start of variables list
  1596. if ( $line =~ /[\-]+\s[\-]+/ )
  1597. {
  1598. $found_variable_list_start= 1;
  1599. }
  1600. }
  1601. else
  1602. {
  1603. # Put variables into hash
  1604. if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
  1605. {
  1606. # print "$1=\"$2\"\n";
  1607. $mysqld_variables{$1}= $2;
  1608. }
  1609. else
  1610. {
  1611. # The variable list is ended with a blank line
  1612. if ( $line =~ /^[\s]*$/ )
  1613. {
  1614. last;
  1615. }
  1616. else
  1617. {
  1618. # Send out a warning, we should fix the variables that has no
  1619. # space between variable name and it's value
  1620. # or should it be fixed width column parsing? It does not
  1621. # look like that in function my_print_variables in my_getopt.c
  1622. mtr_warning("Could not parse variable list line : $line");
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. rmtree($tmpdir);
  1629. mtr_error("Could not find version of MySQL") unless $mysql_version_id;
  1630. mtr_error("Could not find variabes list") unless $found_variable_list_start;
  1631. }
  1632. sub collect_mysqld_features_from_running_server ()
  1633. {
  1634. my $mysql= mtr_exe_exists("$path_client_bindir/mysql");
  1635. my $args;
  1636. mtr_init_args(\$args);
  1637. mtr_add_arg($args, "--no-defaults");
  1638. mtr_add_arg($args, "--user=%s", $opt_user);
  1639. while (my ($option, $value)= each( %opts_extern )) {
  1640. mtr_add_arg($args, "--$option=$value");
  1641. }
  1642. mtr_add_arg($args, "--silent"); # Tab separated output
  1643. mtr_add_arg($args, "-e '%s'", "use mysql; SHOW VARIABLES");
  1644. my $cmd= "$mysql " . join(' ', @$args);
  1645. mtr_verbose("cmd: $cmd");
  1646. my $list = `$cmd` or
  1647. mtr_error("Could not connect to extern server using command: '$cmd'");
  1648. foreach my $line (split('\n', $list ))
  1649. {
  1650. # Put variables into hash
  1651. if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ )
  1652. {
  1653. # print "$1=\"$2\"\n";
  1654. $mysqld_variables{$1}= $2;
  1655. }
  1656. }
  1657. # "Convert" innodb flag
  1658. $mysqld_variables{'innodb'}= "ON"
  1659. if ($mysqld_variables{'have_innodb'} eq "YES");
  1660. # Parse version
  1661. my $version_str= $mysqld_variables{'version'};
  1662. if ( $version_str =~ /^([0-9]*)\.([0-9]*)\.([0-9]*)([^\s]*)/ )
  1663. {
  1664. #print "Major: $1 Minor: $2 Build: $3\n";
  1665. $mysql_version_id= $1*10000 + $2*100 + $3;
  1666. #print "mysql_version_id: $mysql_version_id\n";
  1667. mtr_report("MySQL Version $1.$2.$3");
  1668. $mysql_version_extra= $4;
  1669. }
  1670. mtr_error("Could not find version of MySQL") unless $mysql_version_id;
  1671. }
  1672. sub find_mysqld {
  1673. my ($mysqld_basedir)= $ENV{MTR_BINDIR}|| @_;
  1674. my @mysqld_names= ("mysqld", "mysqld-max-nt", "mysqld-max",
  1675. "mysqld-nt");
  1676. if ( $opt_debug_server ){
  1677. # Put mysqld-debug first in the list of binaries to look for
  1678. mtr_verbose("Adding mysqld-debug first in list of binaries to look for");
  1679. unshift(@mysqld_names, "mysqld-debug");
  1680. }
  1681. return my_find_bin($mysqld_basedir,
  1682. ["sql", "libexec", "sbin", "bin"],
  1683. [@mysqld_names]);
  1684. }
  1685. sub executable_setup () {
  1686. #
  1687. # Check if libtool is available in this distribution/clone
  1688. # we need it when valgrinding or debugging non installed binary
  1689. # Otherwise valgrind will valgrind the libtool wrapper or bash
  1690. # and gdb will not find the real executable to debug
  1691. #
  1692. if ( -x "../libtool")
  1693. {
  1694. $exe_libtool= "../libtool";
  1695. if ($opt_valgrind or $glob_debugger)
  1696. {
  1697. mtr_report("Using \"$exe_libtool\" when running valgrind or debugger");
  1698. }
  1699. }
  1700. # Look for the client binaries
  1701. $exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin");
  1702. $exe_mysql= mtr_exe_exists("$path_client_bindir/mysql");
  1703. $exe_mysql_plugin= mtr_exe_exists("$path_client_bindir/mysql_plugin");
  1704. $exe_mysql_embedded= mtr_exe_maybe_exists("$basedir/libmysqld/examples/mysql_embedded");
  1705. if ( ! $opt_skip_ndbcluster )
  1706. {
  1707. # Look for single threaded NDB
  1708. $exe_ndbd=
  1709. my_find_bin($bindir,
  1710. ["storage/ndb/src/kernel", "libexec", "sbin", "bin"],
  1711. "ndbd");
  1712. # Look for multi threaded NDB
  1713. $exe_ndbmtd=
  1714. my_find_bin($bindir,
  1715. ["storage/ndb/src/kernel", "libexec", "sbin", "bin"],
  1716. "ndbmtd", NOT_REQUIRED);
  1717. if ($exe_ndbmtd)
  1718. {
  1719. my $mtr_ndbmtd = $ENV{MTR_NDBMTD};
  1720. if ($mtr_ndbmtd)
  1721. {
  1722. mtr_report(" - multi threaded ndbd found, will be used always");
  1723. $exe_ndbd = $exe_ndbmtd;
  1724. }
  1725. else
  1726. {
  1727. mtr_report(" - multi threaded ndbd found, will be ".
  1728. "used \"round robin\"");
  1729. }
  1730. }
  1731. $exe_ndb_mgmd=
  1732. my_find_bin($bindir,
  1733. ["storage/ndb/src/mgmsrv", "libexec", "sbin", "bin"],
  1734. "ndb_mgmd");
  1735. $exe_ndb_mgm=
  1736. my_find_bin($bindir,
  1737. ["storage/ndb/src/mgmclient", "bin"],
  1738. "ndb_mgm");
  1739. $exe_ndb_waiter=
  1740. my_find_bin($bindir,
  1741. ["storage/ndb/tools/", "bin"],
  1742. "ndb_waiter");
  1743. }
  1744. # Look for mysqltest executable
  1745. if ( $opt_embedded_server )
  1746. {
  1747. $exe_mysqltest=
  1748. mtr_exe_exists(vs_config_dirs('libmysqld/examples','mysqltest_embedded'),
  1749. "$basedir/libmysqld/examples/mysqltest_embedded",
  1750. "$path_client_bindir/mysqltest_embedded");
  1751. }
  1752. else
  1753. {
  1754. $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest");
  1755. }
  1756. }
  1757. sub client_debug_arg($$) {
  1758. my ($args, $client_name)= @_;
  1759. # Workaround for Bug #50627: drop any debug opt
  1760. return if $client_name =~ /^mysqlbinlog/;
  1761. if ( $opt_debug ) {
  1762. mtr_add_arg($args,
  1763. "--loose-debug=$debug_d:t:A,%s/log/%s.trace",
  1764. $path_vardir_trace, $client_name)
  1765. }
  1766. }
  1767. sub client_arguments ($;$) {
  1768. my $client_name= shift;
  1769. my $group_suffix= shift;
  1770. my $client_exe= mtr_exe_exists("$path_client_bindir/$client_name");
  1771. my $args;
  1772. mtr_init_args(\$args);
  1773. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1774. if (defined($group_suffix)) {
  1775. mtr_add_arg($args, "--defaults-group-suffix=%s", $group_suffix);
  1776. client_debug_arg($args, "$client_name-$group_suffix");
  1777. }
  1778. else
  1779. {
  1780. client_debug_arg($args, $client_name);
  1781. }
  1782. return mtr_args2str($client_exe, @$args);
  1783. }
  1784. sub mysqlslap_arguments () {
  1785. my $exe= mtr_exe_maybe_exists("$path_client_bindir/mysqlslap");
  1786. if ( $exe eq "" ) {
  1787. # mysqlap was not found
  1788. if (defined $mysql_version_id and $mysql_version_id >= 50100 ) {
  1789. mtr_error("Could not find the mysqlslap binary");
  1790. }
  1791. return ""; # Don't care about mysqlslap
  1792. }
  1793. my $args;
  1794. mtr_init_args(\$args);
  1795. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1796. client_debug_arg($args, "mysqlslap");
  1797. return mtr_args2str($exe, @$args);
  1798. }
  1799. sub mysqldump_arguments ($) {
  1800. my($group_suffix) = @_;
  1801. my $exe= mtr_exe_exists("$path_client_bindir/mysqldump");
  1802. my $args;
  1803. mtr_init_args(\$args);
  1804. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1805. mtr_add_arg($args, "--defaults-group-suffix=%s", $group_suffix);
  1806. client_debug_arg($args, "mysqldump-$group_suffix");
  1807. return mtr_args2str($exe, @$args);
  1808. }
  1809. sub mysql_client_test_arguments(){
  1810. my $exe;
  1811. # mysql_client_test executable may _not_ exist
  1812. if ( $opt_embedded_server ) {
  1813. $exe= mtr_exe_maybe_exists(
  1814. vs_config_dirs('libmysqld/examples','mysql_client_test_embedded'),
  1815. "$basedir/libmysqld/examples/mysql_client_test_embedded",
  1816. "$basedir/bin/mysql_client_test_embedded");
  1817. } else {
  1818. $exe= mtr_exe_maybe_exists(vs_config_dirs('tests', 'mysql_client_test'),
  1819. "$basedir/tests/mysql_client_test",
  1820. "$basedir/bin/mysql_client_test");
  1821. }
  1822. my $args;
  1823. mtr_init_args(\$args);
  1824. if ( $opt_valgrind_mysqltest ) {
  1825. valgrind_arguments($args, \$exe);
  1826. }
  1827. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  1828. mtr_add_arg($args, "--testcase");
  1829. mtr_add_arg($args, "--vardir=$opt_vardir");
  1830. client_debug_arg($args,"mysql_client_test");
  1831. return mtr_args2str($exe, @$args);
  1832. }
  1833. #
  1834. # Set environment to be used by childs of this process for
  1835. # things that are constant during the whole lifetime of mysql-test-run
  1836. #
  1837. sub find_plugin($$)
  1838. {
  1839. my ($plugin, $location) = @_;
  1840. my $plugin_filename;
  1841. if (IS_WINDOWS)
  1842. {
  1843. $plugin_filename = $plugin.".dll";
  1844. }
  1845. else
  1846. {
  1847. $plugin_filename = $plugin.".so";
  1848. }
  1849. my $lib_plugin=
  1850. mtr_file_exists(vs_config_dirs($location,$plugin_filename),
  1851. "$basedir/lib/plugin/".$plugin_filename,
  1852. "$basedir/lib64/plugin/".$plugin_filename,
  1853. "$basedir/$location/.libs/".$plugin_filename,
  1854. "$basedir/lib/mysql/plugin/".$plugin_filename,
  1855. "$basedir/lib64/mysql/plugin/".$plugin_filename,
  1856. );
  1857. return $lib_plugin;
  1858. }
  1859. #
  1860. # Read plugin defintions file
  1861. #
  1862. sub read_plugin_defs($)
  1863. {
  1864. my ($defs_file)= @_;
  1865. my $running_debug= 0;
  1866. open(PLUGDEF, '<', $defs_file)
  1867. or mtr_error("Can't read plugin defintions file $defs_file");
  1868. # Need to check if we will be running mysqld-debug
  1869. if ($opt_debug_server) {
  1870. $running_debug= 1 if find_mysqld($basedir) =~ /mysqld-debug/;
  1871. }
  1872. while (<PLUGDEF>) {
  1873. next if /^#/;
  1874. my ($plug_file, $plug_loc, $plug_var, $plug_names)= split;
  1875. # Allow empty lines
  1876. next unless $plug_file;
  1877. mtr_error("Lines in $defs_file must have 3 or 4 items") unless $plug_var;
  1878. # If running debug server, plugins will be in 'debug' subdirectory
  1879. $plug_file= "debug/$plug_file" if $running_debug;
  1880. my ($plugin)= find_plugin($plug_file, $plug_loc);
  1881. # Set env. variables that tests may use, set to empty if plugin
  1882. # listed in def. file but not found.
  1883. if ($plugin) {
  1884. $ENV{$plug_var}= basename($plugin);
  1885. $ENV{$plug_var.'_DIR'}= dirname($plugin);
  1886. $ENV{$plug_var.'_OPT'}= "--plugin-dir=".dirname($plugin);
  1887. if ($plug_names) {
  1888. my $lib_name= basename($plugin);
  1889. my $load_var= "--plugin_load=";
  1890. my $semi= '';
  1891. foreach my $plug_name (split (',', $plug_names)) {
  1892. $load_var .= $semi . "$plug_name=$lib_name";
  1893. $semi= ';';
  1894. }
  1895. $ENV{$plug_var.'_LOAD'}= $load_var;
  1896. }
  1897. } else {
  1898. $ENV{$plug_var}= "";
  1899. $ENV{$plug_var.'_DIR'}= "";
  1900. $ENV{$plug_var.'_OPT'}= "";
  1901. $ENV{$plug_var.'_LOAD'}= "" if $plug_names;
  1902. }
  1903. }
  1904. close PLUGDEF;
  1905. }
  1906. sub environment_setup {
  1907. umask(022);
  1908. my @ld_library_paths;
  1909. if ($path_client_libdir)
  1910. {
  1911. # Use the --client-libdir passed on commandline
  1912. push(@ld_library_paths, "$path_client_libdir");
  1913. }
  1914. else
  1915. {
  1916. # Setup LD_LIBRARY_PATH so the libraries from this distro/clone
  1917. # are used in favor of the system installed ones
  1918. if ( $source_dist )
  1919. {
  1920. push(@ld_library_paths, "$basedir/libmysql/.libs/",
  1921. "$basedir/libmysql_r/.libs/",
  1922. "$basedir/zlib/.libs/");
  1923. }
  1924. else
  1925. {
  1926. push(@ld_library_paths, "$basedir/lib", "$basedir/lib/mysql");
  1927. }
  1928. }
  1929. # --------------------------------------------------------------------------
  1930. # Add the path where libndbclient can be found
  1931. # --------------------------------------------------------------------------
  1932. if ( !$opt_skip_ndbcluster )
  1933. {
  1934. push(@ld_library_paths, "$basedir/storage/ndb/src/.libs");
  1935. }
  1936. # Plugin settings should no longer be added here, instead
  1937. # place definitions in include/plugin.defs.
  1938. # See comment in that file for details.
  1939. # --------------------------------------------------------------------------
  1940. # Valgrind need to be run with debug libraries otherwise it's almost
  1941. # impossible to add correct supressions, that means if "/usr/lib/debug"
  1942. # is available, it should be added to
  1943. # LD_LIBRARY_PATH
  1944. #
  1945. # But pthread is broken in libc6-dbg on Debian <= 3.1 (see Debian
  1946. # bug 399035, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=399035),
  1947. # so don't change LD_LIBRARY_PATH on that platform.
  1948. # --------------------------------------------------------------------------
  1949. my $debug_libraries_path= "/usr/lib/debug";
  1950. my $deb_version;
  1951. if ( $opt_valgrind and -d $debug_libraries_path and
  1952. (! -e '/etc/debian_version' or
  1953. ($deb_version=
  1954. mtr_grab_file('/etc/debian_version')) !~ /^[0-9]+\.[0-9]$/ or
  1955. $deb_version > 3.1 ) )
  1956. {
  1957. push(@ld_library_paths, $debug_libraries_path);
  1958. }
  1959. $ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths,
  1960. $ENV{'LD_LIBRARY_PATH'} ?
  1961. split(':', $ENV{'LD_LIBRARY_PATH'}) : ());
  1962. mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}");
  1963. $ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths,
  1964. $ENV{'DYLD_LIBRARY_PATH'} ?
  1965. split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ());
  1966. mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}");
  1967. # The environment variable used for shared libs on AIX
  1968. $ENV{'SHLIB_PATH'}= join(":", @ld_library_paths,
  1969. $ENV{'SHLIB_PATH'} ?
  1970. split(':', $ENV{'SHLIB_PATH'}) : ());
  1971. mtr_debug("SHLIB_PATH: $ENV{'SHLIB_PATH'}");
  1972. # The environment variable used for shared libs on hp-ux
  1973. $ENV{'LIBPATH'}= join(":", @ld_library_paths,
  1974. $ENV{'LIBPATH'} ?
  1975. split(':', $ENV{'LIBPATH'}) : ());
  1976. mtr_debug("LIBPATH: $ENV{'LIBPATH'}");
  1977. $ENV{'UMASK'}= "0660"; # The octal *string*
  1978. $ENV{'UMASK_DIR'}= "0770"; # The octal *string*
  1979. #
  1980. # MySQL tests can produce output in various character sets
  1981. # (especially, ctype_xxx.test). To avoid confusing Perl
  1982. # with output which is incompatible with the current locale
  1983. # settings, we reset the current values of LC_ALL and LC_CTYPE to "C".
  1984. # For details, please see
  1985. # Bug#27636 tests fails if LC_* variables set to *_*.UTF-8
  1986. #
  1987. $ENV{'LC_ALL'}= "C";
  1988. $ENV{'LC_CTYPE'}= "C";
  1989. $ENV{'LC_COLLATE'}= "C";
  1990. $ENV{'USE_RUNNING_SERVER'}= using_extern();
  1991. $ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir;
  1992. $ENV{'DEFAULT_MASTER_PORT'}= $mysqld_variables{'port'};
  1993. $ENV{'MYSQL_TMP_DIR'}= $opt_tmpdir;
  1994. $ENV{'MYSQLTEST_VARDIR'}= $opt_vardir;
  1995. $ENV{'MYSQL_BINDIR'}= "$bindir";
  1996. $ENV{'MYSQL_SHAREDIR'}= $path_language;
  1997. $ENV{'MYSQL_CHARSETSDIR'}= $path_charsetsdir;
  1998. if (IS_WINDOWS)
  1999. {
  2000. $ENV{'SECURE_LOAD_PATH'}= $glob_mysql_test_dir."\\std_data";
  2001. }
  2002. else
  2003. {
  2004. $ENV{'SECURE_LOAD_PATH'}= $glob_mysql_test_dir."/std_data";
  2005. }
  2006. # ----------------------------------------------------
  2007. # Setup env for NDB
  2008. # ----------------------------------------------------
  2009. if ( ! $opt_skip_ndbcluster )
  2010. {
  2011. $ENV{'NDB_MGM'}=
  2012. my_find_bin($bindir,
  2013. ["storage/ndb/src/mgmclient", "bin"],
  2014. "ndb_mgm");
  2015. $ENV{'NDB_TOOLS_DIR'}=
  2016. my_find_dir($bindir,
  2017. ["storage/ndb/tools", "bin"]);
  2018. $ENV{'NDB_EXAMPLES_DIR'}=
  2019. my_find_dir($basedir,
  2020. ["storage/ndb/ndbapi-examples", "bin"]);
  2021. $ENV{'NDB_EXAMPLES_BINARY'}=
  2022. my_find_bin($bindir,
  2023. ["storage/ndb/ndbapi-examples/ndbapi_simple", "bin"],
  2024. "ndbapi_simple", NOT_REQUIRED);
  2025. my $path_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log";
  2026. $ENV{'NDB_TOOLS_OUTPUT'}= $path_ndb_testrun_log;
  2027. $ENV{'NDB_EXAMPLES_OUTPUT'}= $path_ndb_testrun_log;
  2028. }
  2029. # ----------------------------------------------------
  2030. # mysql clients
  2031. # ----------------------------------------------------
  2032. $ENV{'MYSQL_CHECK'}= client_arguments("mysqlcheck");
  2033. $ENV{'MYSQL_DUMP'}= mysqldump_arguments(".1");
  2034. $ENV{'MYSQL_DUMP_SLAVE'}= mysqldump_arguments(".2");
  2035. $ENV{'MYSQL_SLAP'}= mysqlslap_arguments();
  2036. $ENV{'MYSQL_IMPORT'}= client_arguments("mysqlimport");
  2037. $ENV{'MYSQL_SHOW'}= client_arguments("mysqlshow");
  2038. $ENV{'MYSQL_BINLOG'}= client_arguments("mysqlbinlog");
  2039. $ENV{'MYSQL'}= client_arguments("mysql");
  2040. $ENV{'MYSQL_SLAVE'}= client_arguments("mysql", ".2");
  2041. $ENV{'MYSQL_UPGRADE'}= client_arguments("mysql_upgrade");
  2042. $ENV{'MYSQLADMIN'}= native_path($exe_mysqladmin);
  2043. $ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments();
  2044. $ENV{'EXE_MYSQL'}= $exe_mysql;
  2045. $ENV{'MYSQL_PLUGIN'}= $exe_mysql_plugin;
  2046. $ENV{'MYSQL_EMBEDDED'}= $exe_mysql_embedded;
  2047. my $exe_mysqld= find_mysqld($basedir);
  2048. $ENV{'MYSQLD'}= $exe_mysqld;
  2049. my $extra_opts= join (" ", @opt_extra_mysqld_opt);
  2050. $ENV{'MYSQLD_CMD'}= "$exe_mysqld --defaults-group-suffix=.1 ".
  2051. "--defaults-file=$path_config_file $extra_opts";
  2052. # ----------------------------------------------------
  2053. # bug25714 executable may _not_ exist in
  2054. # some versions, test using it should be skipped
  2055. # ----------------------------------------------------
  2056. my $exe_bug25714=
  2057. mtr_exe_maybe_exists(vs_config_dirs('tests', 'bug25714'),
  2058. "$basedir/tests/bug25714");
  2059. $ENV{'MYSQL_BUG25714'}= native_path($exe_bug25714);
  2060. # ----------------------------------------------------
  2061. # mysql_fix_privilege_tables.sql
  2062. # ----------------------------------------------------
  2063. my $file_mysql_fix_privilege_tables=
  2064. mtr_file_exists("$basedir/scripts/mysql_fix_privilege_tables.sql",
  2065. "$basedir/share/mysql_fix_privilege_tables.sql",
  2066. "$basedir/share/mysql/mysql_fix_privilege_tables.sql");
  2067. $ENV{'MYSQL_FIX_PRIVILEGE_TABLES'}= $file_mysql_fix_privilege_tables;
  2068. # ----------------------------------------------------
  2069. # my_print_defaults
  2070. # ----------------------------------------------------
  2071. my $exe_my_print_defaults=
  2072. mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'),
  2073. "$path_client_bindir/my_print_defaults",
  2074. "$basedir/extra/my_print_defaults");
  2075. $ENV{'MYSQL_MY_PRINT_DEFAULTS'}= native_path($exe_my_print_defaults);
  2076. # ----------------------------------------------------
  2077. # Setup env so childs can execute myisampack and myisamchk
  2078. # ----------------------------------------------------
  2079. $ENV{'MYISAMCHK'}= native_path(mtr_exe_exists(
  2080. vs_config_dirs('storage/myisam', 'myisamchk'),
  2081. vs_config_dirs('myisam', 'myisamchk'),
  2082. "$path_client_bindir/myisamchk",
  2083. "$basedir/storage/myisam/myisamchk",
  2084. "$basedir/myisam/myisamchk"));
  2085. $ENV{'MYISAMPACK'}= native_path(mtr_exe_exists(
  2086. vs_config_dirs('storage/myisam', 'myisampack'),
  2087. vs_config_dirs('myisam', 'myisampack'),
  2088. "$path_client_bindir/myisampack",
  2089. "$basedir/storage/myisam/myisampack",
  2090. "$basedir/myisam/myisampack"));
  2091. # ----------------------------------------------------
  2092. # mysqlhotcopy
  2093. # ----------------------------------------------------
  2094. my $mysqlhotcopy=
  2095. mtr_pl_maybe_exists("$bindir/scripts/mysqlhotcopy") ||
  2096. mtr_pl_maybe_exists("$path_client_bindir/mysqlhotcopy");
  2097. if ($mysqlhotcopy)
  2098. {
  2099. $ENV{'MYSQLHOTCOPY'}= $mysqlhotcopy;
  2100. }
  2101. # ----------------------------------------------------
  2102. # perror
  2103. # ----------------------------------------------------
  2104. my $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'),
  2105. "$basedir/extra/perror",
  2106. "$path_client_bindir/perror");
  2107. $ENV{'MY_PERROR'}= native_path($exe_perror);
  2108. # Create an environment variable to make it possible
  2109. # to detect that valgrind is being used from test cases
  2110. $ENV{'VALGRIND_TEST'}= $opt_valgrind;
  2111. # Add dir of this perl to aid mysqltest in finding perl
  2112. my $perldir= dirname($^X);
  2113. my $pathsep= ":";
  2114. $pathsep= ";" if IS_WINDOWS && ! IS_CYGWIN;
  2115. $ENV{'PATH'}= "$ENV{'PATH'}".$pathsep.$perldir;
  2116. }
  2117. sub remove_vardir_subs() {
  2118. foreach my $sdir ( glob("$opt_vardir/*") ) {
  2119. mtr_verbose("Removing subdir $sdir");
  2120. rmtree($sdir);
  2121. }
  2122. }
  2123. #
  2124. # Remove var and any directories in var/ created by previous
  2125. # tests
  2126. #
  2127. sub remove_stale_vardir () {
  2128. mtr_report("Removing old var directory...");
  2129. # Safety!
  2130. mtr_error("No, don't remove the vardir when running with --extern")
  2131. if using_extern();
  2132. mtr_verbose("opt_vardir: $opt_vardir");
  2133. if ( $opt_vardir eq $default_vardir )
  2134. {
  2135. #
  2136. # Running with "var" in mysql-test dir
  2137. #
  2138. if ( -l $opt_vardir)
  2139. {
  2140. # var is a symlink
  2141. if ( $opt_mem )
  2142. {
  2143. # Remove the directory which the link points at
  2144. mtr_verbose("Removing " . readlink($opt_vardir));
  2145. rmtree(readlink($opt_vardir));
  2146. # Remove the "var" symlink
  2147. mtr_verbose("unlink($opt_vardir)");
  2148. unlink($opt_vardir);
  2149. }
  2150. else
  2151. {
  2152. # Some users creates a soft link in mysql-test/var to another area
  2153. # - allow it, but remove all files in it
  2154. mtr_report(" - WARNING: Using the 'mysql-test/var' symlink");
  2155. # Make sure the directory where it points exist
  2156. mtr_error("The destination for symlink $opt_vardir does not exist")
  2157. if ! -d readlink($opt_vardir);
  2158. remove_vardir_subs();
  2159. }
  2160. }
  2161. else
  2162. {
  2163. # Remove the entire "var" dir
  2164. mtr_verbose("Removing $opt_vardir/");
  2165. rmtree("$opt_vardir/");
  2166. }
  2167. if ( $opt_mem )
  2168. {
  2169. # A symlink from var/ to $opt_mem will be set up
  2170. # remove the $opt_mem dir to assure the symlink
  2171. # won't point at an old directory
  2172. mtr_verbose("Removing $opt_mem");
  2173. rmtree($opt_mem);
  2174. }
  2175. }
  2176. else
  2177. {
  2178. #
  2179. # Running with "var" in some other place
  2180. #
  2181. # Remove the var/ dir in mysql-test dir if any
  2182. # this could be an old symlink that shouldn't be there
  2183. mtr_verbose("Removing $default_vardir");
  2184. rmtree($default_vardir);
  2185. # Remove the "var" dir
  2186. mtr_verbose("Removing $opt_vardir/");
  2187. rmtree("$opt_vardir/");
  2188. }
  2189. # Remove the "tmp" dir
  2190. mtr_verbose("Removing $opt_tmpdir/");
  2191. rmtree("$opt_tmpdir/");
  2192. }
  2193. #
  2194. # Create var and the directories needed in var
  2195. #
  2196. sub setup_vardir() {
  2197. mtr_report("Creating var directory '$opt_vardir'...");
  2198. if ( $opt_vardir eq $default_vardir )
  2199. {
  2200. #
  2201. # Running with "var" in mysql-test dir
  2202. #
  2203. if ( -l $opt_vardir )
  2204. {
  2205. # it's a symlink
  2206. # Make sure the directory where it points exist
  2207. mtr_error("The destination for symlink $opt_vardir does not exist")
  2208. if ! -d readlink($opt_vardir);
  2209. }
  2210. elsif ( $opt_mem )
  2211. {
  2212. # Runinng with "var" as a link to some "memory" location, normally tmpfs
  2213. mtr_verbose("Creating $opt_mem");
  2214. mkpath($opt_mem);
  2215. mtr_report(" - symlinking 'var' to '$opt_mem'");
  2216. symlink($opt_mem, $opt_vardir);
  2217. }
  2218. }
  2219. if ( ! -d $opt_vardir )
  2220. {
  2221. mtr_verbose("Creating $opt_vardir");
  2222. mkpath($opt_vardir);
  2223. }
  2224. # Ensure a proper error message if vardir couldn't be created
  2225. unless ( -d $opt_vardir and -w $opt_vardir )
  2226. {
  2227. mtr_error("Writable 'var' directory is needed, use the " .
  2228. "'--vardir=<path>' option");
  2229. }
  2230. mkpath("$opt_vardir/log");
  2231. mkpath("$opt_vardir/run");
  2232. # Create var/tmp and tmp - they might be different
  2233. mkpath("$opt_vardir/tmp");
  2234. mkpath($opt_tmpdir) if ($opt_tmpdir ne "$opt_vardir/tmp");
  2235. # On some operating systems, there is a limit to the length of a
  2236. # UNIX domain socket's path far below PATH_MAX.
  2237. # Don't allow that to happen
  2238. if (check_socket_path_length("$opt_tmpdir/testsocket.sock")){
  2239. mtr_error("Socket path '$opt_tmpdir' too long, it would be ",
  2240. "truncated and thus not possible to use for connection to ",
  2241. "MySQL Server. Set a shorter with --tmpdir=<path> option");
  2242. }
  2243. # copy all files from std_data into var/std_data
  2244. # and make them world readable
  2245. copytree("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data", "0022");
  2246. # Remove old log files
  2247. foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
  2248. {
  2249. unlink($name);
  2250. }
  2251. }
  2252. #
  2253. # Check if running as root
  2254. # i.e a file can be read regardless what mode we set it to
  2255. #
  2256. sub check_running_as_root () {
  2257. my $test_file= "$opt_vardir/test_running_as_root.txt";
  2258. mtr_tofile($test_file, "MySQL");
  2259. chmod(oct("0000"), $test_file);
  2260. my $result="";
  2261. if (open(FILE,"<",$test_file))
  2262. {
  2263. $result= join('', <FILE>);
  2264. close FILE;
  2265. }
  2266. # Some filesystems( for example CIFS) allows reading a file
  2267. # although mode was set to 0000, but in that case a stat on
  2268. # the file will not return 0000
  2269. my $file_mode= (stat($test_file))[2] & 07777;
  2270. mtr_verbose("result: $result, file_mode: $file_mode");
  2271. if ($result eq "MySQL" && $file_mode == 0)
  2272. {
  2273. mtr_warning("running this script as _root_ will cause some " .
  2274. "tests to be skipped");
  2275. $ENV{'MYSQL_TEST_ROOT'}= "YES";
  2276. }
  2277. chmod(oct("0755"), $test_file);
  2278. unlink($test_file);
  2279. }
  2280. sub check_ssl_support ($) {
  2281. my $mysqld_variables= shift;
  2282. if ($opt_skip_ssl)
  2283. {
  2284. mtr_report(" - skipping SSL");
  2285. $opt_ssl_supported= 0;
  2286. $opt_ssl= 0;
  2287. return;
  2288. }
  2289. if ( ! $mysqld_variables->{'ssl'} )
  2290. {
  2291. if ( $opt_ssl)
  2292. {
  2293. mtr_error("Couldn't find support for SSL");
  2294. return;
  2295. }
  2296. mtr_report(" - skipping SSL, mysqld not compiled with SSL");
  2297. $opt_ssl_supported= 0;
  2298. $opt_ssl= 0;
  2299. return;
  2300. }
  2301. mtr_report(" - SSL connections supported");
  2302. $opt_ssl_supported= 1;
  2303. }
  2304. sub check_debug_support ($) {
  2305. my $mysqld_variables= shift;
  2306. if ( ! $mysqld_variables->{'debug'} )
  2307. {
  2308. #mtr_report(" - binaries are not debug compiled");
  2309. $debug_compiled_binaries= 0;
  2310. if ( $opt_debug_server )
  2311. {
  2312. mtr_error("Can't use --debug[-server], binary does not support it");
  2313. }
  2314. return;
  2315. }
  2316. mtr_report(" - binaries are debug compiled");
  2317. $debug_compiled_binaries= 1;
  2318. }
  2319. #
  2320. # Helper function to handle configuration-based subdirectories which Visual
  2321. # Studio uses for storing binaries. If opt_vs_config is set, this returns
  2322. # a path based on that setting; if not, it returns paths for the default
  2323. # /release/ and /debug/ subdirectories.
  2324. #
  2325. # $exe can be undefined, if the directory itself will be used
  2326. #
  2327. sub vs_config_dirs ($$) {
  2328. my ($path_part, $exe) = @_;
  2329. $exe = "" if not defined $exe;
  2330. if ($opt_vs_config)
  2331. {
  2332. return ("$bindir/$path_part/$opt_vs_config/$exe");
  2333. }
  2334. return ("$bindir/$path_part/Release/$exe",
  2335. "$bindir/$path_part/RelWithDebinfo/$exe",
  2336. "$bindir/$path_part/Debug/$exe",
  2337. "$bindir/$path_part/$exe");
  2338. }
  2339. sub check_ndbcluster_support ($) {
  2340. my $mysqld_variables= shift;
  2341. # Check if this is MySQL Cluster, ie. mysql version string ends
  2342. # with -ndb-Y.Y.Y[-status]
  2343. if ( defined $mysql_version_extra &&
  2344. $mysql_version_extra =~ /^-ndb-/ )
  2345. {
  2346. mtr_report(" - MySQL Cluster");
  2347. # Enable ndb engine and add more test suites
  2348. $opt_include_ndbcluster = 1;
  2349. $DEFAULT_SUITES.=",ndb";
  2350. }
  2351. if ($opt_include_ndbcluster)
  2352. {
  2353. $opt_skip_ndbcluster= 0;
  2354. }
  2355. if ($opt_skip_ndbcluster)
  2356. {
  2357. mtr_report(" - skipping ndbcluster");
  2358. return;
  2359. }
  2360. if ( ! $mysqld_variables{'ndb-connectstring'} )
  2361. {
  2362. mtr_report(" - skipping ndbcluster, mysqld not compiled with ndbcluster");
  2363. $opt_skip_ndbcluster= 2;
  2364. return;
  2365. }
  2366. mtr_report(" - using ndbcluster when necessary, mysqld supports it");
  2367. return;
  2368. }
  2369. sub ndbcluster_wait_started($$){
  2370. my $cluster= shift;
  2371. my $ndb_waiter_extra_opt= shift;
  2372. my $path_waitlog= join('/', $opt_vardir, $cluster->name(), "ndb_waiter.log");
  2373. my $args;
  2374. mtr_init_args(\$args);
  2375. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2376. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  2377. mtr_add_arg($args, "--timeout=%d", $opt_start_timeout);
  2378. if ($ndb_waiter_extra_opt)
  2379. {
  2380. mtr_add_arg($args, "$ndb_waiter_extra_opt");
  2381. }
  2382. # Start the ndb_waiter which will connect to the ndb_mgmd
  2383. # and poll it for state of the ndbd's, will return when
  2384. # all nodes in the cluster is started
  2385. my $res= My::SafeProcess->run
  2386. (
  2387. name => "ndb_waiter ".$cluster->name(),
  2388. path => $exe_ndb_waiter,
  2389. args => \$args,
  2390. output => $path_waitlog,
  2391. error => $path_waitlog,
  2392. append => 1,
  2393. );
  2394. # Check that ndb_mgmd(s) are still alive
  2395. foreach my $ndb_mgmd ( in_cluster($cluster, ndb_mgmds()) )
  2396. {
  2397. my $proc= $ndb_mgmd->{proc};
  2398. if ( ! $proc->wait_one(0) )
  2399. {
  2400. mtr_warning("$proc died");
  2401. return 2;
  2402. }
  2403. }
  2404. # Check that all started ndbd(s) are still alive
  2405. foreach my $ndbd ( in_cluster($cluster, ndbds()) )
  2406. {
  2407. my $proc= $ndbd->{proc};
  2408. next unless defined $proc;
  2409. if ( ! $proc->wait_one(0) )
  2410. {
  2411. mtr_warning("$proc died");
  2412. return 3;
  2413. }
  2414. }
  2415. if ($res)
  2416. {
  2417. mtr_verbose("ndbcluster_wait_started failed");
  2418. return 1;
  2419. }
  2420. return 0;
  2421. }
  2422. sub ndb_mgmd_wait_started($) {
  2423. my ($cluster)= @_;
  2424. my $retries= 100;
  2425. while ($retries)
  2426. {
  2427. my $result= ndbcluster_wait_started($cluster, "--no-contact");
  2428. if ($result == 0)
  2429. {
  2430. # ndb_mgmd is started
  2431. mtr_verbose("ndb_mgmd is started");
  2432. return 0;
  2433. }
  2434. elsif ($result > 1)
  2435. {
  2436. mtr_warning("Cluster process failed while waiting for start");
  2437. return $result;
  2438. }
  2439. mtr_milli_sleep(100);
  2440. $retries--;
  2441. }
  2442. return 1;
  2443. }
  2444. sub ndb_mgmd_stop{
  2445. my $ndb_mgmd= shift or die "usage: ndb_mgmd_stop(<ndb_mgmd>)";
  2446. my $host=$ndb_mgmd->value('HostName');
  2447. my $port=$ndb_mgmd->value('PortNumber');
  2448. mtr_verbose("Stopping cluster '$host:$port'");
  2449. my $args;
  2450. mtr_init_args(\$args);
  2451. mtr_add_arg($args, "--ndb-connectstring=%s:%s", $host,$port);
  2452. mtr_add_arg($args, "-e");
  2453. mtr_add_arg($args, "shutdown");
  2454. My::SafeProcess->run
  2455. (
  2456. name => "ndb_mgm shutdown $host:$port",
  2457. path => $exe_ndb_mgm,
  2458. args => \$args,
  2459. output => "/dev/null",
  2460. );
  2461. }
  2462. sub ndb_mgmd_start ($$) {
  2463. my ($cluster, $ndb_mgmd)= @_;
  2464. mtr_verbose("ndb_mgmd_start");
  2465. my $dir= $ndb_mgmd->value("DataDir");
  2466. mkpath($dir) unless -d $dir;
  2467. my $args;
  2468. mtr_init_args(\$args);
  2469. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2470. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  2471. mtr_add_arg($args, "--mycnf");
  2472. mtr_add_arg($args, "--nodaemon");
  2473. my $path_ndb_mgmd_log= "$dir/ndb_mgmd.log";
  2474. $ndb_mgmd->{'proc'}= My::SafeProcess->new
  2475. (
  2476. name => $ndb_mgmd->after('cluster_config.'),
  2477. path => $exe_ndb_mgmd,
  2478. args => \$args,
  2479. output => $path_ndb_mgmd_log,
  2480. error => $path_ndb_mgmd_log,
  2481. append => 1,
  2482. verbose => $opt_verbose,
  2483. shutdown => sub { ndb_mgmd_stop($ndb_mgmd) },
  2484. );
  2485. mtr_verbose("Started $ndb_mgmd->{proc}");
  2486. # FIXME Should not be needed
  2487. # Unfortunately the cluster nodes will fail to start
  2488. # if ndb_mgmd has not started properly
  2489. if (ndb_mgmd_wait_started($cluster))
  2490. {
  2491. mtr_warning("Failed to wait for start of ndb_mgmd");
  2492. return 1;
  2493. }
  2494. return 0;
  2495. }
  2496. sub ndbd_stop {
  2497. # Intentionally left empty, ndbd nodes will be shutdown
  2498. # by sending "shutdown" to ndb_mgmd
  2499. }
  2500. my $exe_ndbmtd_counter= 0;
  2501. sub ndbd_start {
  2502. my ($cluster, $ndbd)= @_;
  2503. mtr_verbose("ndbd_start");
  2504. my $dir= $ndbd->value("DataDir");
  2505. mkpath($dir) unless -d $dir;
  2506. my $args;
  2507. mtr_init_args(\$args);
  2508. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2509. mtr_add_arg($args, "--defaults-group-suffix=%s", $cluster->suffix());
  2510. mtr_add_arg($args, "--nodaemon");
  2511. # > 5.0 { 'character-sets-dir' => \&fix_charset_dir },
  2512. my $exe= $exe_ndbd;
  2513. if ($exe_ndbmtd and ($exe_ndbmtd_counter++ % 2) == 0)
  2514. {
  2515. # Use ndbmtd every other time
  2516. $exe= $exe_ndbmtd;
  2517. }
  2518. my $path_ndbd_log= "$dir/ndbd.log";
  2519. my $proc= My::SafeProcess->new
  2520. (
  2521. name => $ndbd->after('cluster_config.'),
  2522. path => $exe,
  2523. args => \$args,
  2524. output => $path_ndbd_log,
  2525. error => $path_ndbd_log,
  2526. append => 1,
  2527. verbose => $opt_verbose,
  2528. shutdown => sub { ndbd_stop($ndbd) },
  2529. );
  2530. mtr_verbose("Started $proc");
  2531. $ndbd->{proc}= $proc;
  2532. return;
  2533. }
  2534. sub ndbcluster_start ($) {
  2535. my $cluster= shift;
  2536. mtr_verbose("ndbcluster_start '".$cluster->name()."'");
  2537. foreach my $ndb_mgmd ( in_cluster($cluster, ndb_mgmds()) )
  2538. {
  2539. next if started($ndb_mgmd);
  2540. ndb_mgmd_start($cluster, $ndb_mgmd);
  2541. }
  2542. foreach my $ndbd ( in_cluster($cluster, ndbds()) )
  2543. {
  2544. next if started($ndbd);
  2545. ndbd_start($cluster, $ndbd);
  2546. }
  2547. return 0;
  2548. }
  2549. sub create_config_file_for_extern {
  2550. my %opts=
  2551. (
  2552. socket => '/tmp/mysqld.sock',
  2553. port => 3306,
  2554. user => $opt_user,
  2555. password => '',
  2556. @_
  2557. );
  2558. mtr_report("Creating my.cnf file for extern server...");
  2559. my $F= IO::File->new($path_config_file, "w")
  2560. or mtr_error("Can't write to $path_config_file: $!");
  2561. print $F "[client]\n";
  2562. while (my ($option, $value)= each( %opts )) {
  2563. print $F "$option= $value\n";
  2564. mtr_report(" $option= $value");
  2565. }
  2566. print $F <<EOF
  2567. # binlog reads from [client] and [mysqlbinlog]
  2568. [mysqlbinlog]
  2569. character-sets-dir= $path_charsetsdir
  2570. local-load= $opt_tmpdir
  2571. EOF
  2572. ;
  2573. $F= undef; # Close file
  2574. }
  2575. #
  2576. # Kill processes left from previous runs, normally
  2577. # there should be none so make sure to warn
  2578. # if there is one
  2579. #
  2580. sub kill_leftovers ($) {
  2581. my $rundir= shift;
  2582. return unless ( -d $rundir );
  2583. mtr_report("Checking leftover processes...");
  2584. # Scan the "run" directory for process id's to kill
  2585. opendir(RUNDIR, $rundir)
  2586. or mtr_error("kill_leftovers, can't open dir \"$rundir\": $!");
  2587. while ( my $elem= readdir(RUNDIR) )
  2588. {
  2589. # Only read pid from files that end with .pid
  2590. if ( $elem =~ /.*[.]pid$/ )
  2591. {
  2592. my $pidfile= "$rundir/$elem";
  2593. next unless -f $pidfile;
  2594. my $pid= mtr_fromfile($pidfile);
  2595. unlink($pidfile);
  2596. unless ($pid=~ /^(\d+)/){
  2597. # The pid was not a valid number
  2598. mtr_warning("Got invalid pid '$pid' from '$elem'");
  2599. next;
  2600. }
  2601. mtr_report(" - found old pid $pid in '$elem', killing it...");
  2602. my $ret= kill("KILL", $pid);
  2603. if ($ret == 0) {
  2604. mtr_report(" process did not exist!");
  2605. next;
  2606. }
  2607. my $check_counter= 100;
  2608. while ($ret > 0 and $check_counter--) {
  2609. mtr_milli_sleep(100);
  2610. $ret= kill(0, $pid);
  2611. }
  2612. mtr_report($check_counter ? " ok!" : " failed!");
  2613. }
  2614. else
  2615. {
  2616. mtr_warning("Found non pid file '$elem' in '$rundir'")
  2617. if -f "$rundir/$elem";
  2618. }
  2619. }
  2620. closedir(RUNDIR);
  2621. }
  2622. #
  2623. # Check that all the ports that are going to
  2624. # be used are free
  2625. #
  2626. sub check_ports_free ($)
  2627. {
  2628. my $bthread= shift;
  2629. my $portbase = $bthread * 10 + 10000;
  2630. for ($portbase..$portbase+9){
  2631. if (mtr_ping_port($_)){
  2632. mtr_report(" - 'localhost:$_' was not free");
  2633. return 0; # One port was not free
  2634. }
  2635. }
  2636. return 1; # All ports free
  2637. }
  2638. sub initialize_servers {
  2639. if ( using_extern() )
  2640. {
  2641. # Running against an already started server, if the specified
  2642. # vardir does not already exist it should be created
  2643. if ( ! -d $opt_vardir )
  2644. {
  2645. setup_vardir();
  2646. }
  2647. else
  2648. {
  2649. mtr_verbose("No need to create '$opt_vardir' it already exists");
  2650. }
  2651. }
  2652. else
  2653. {
  2654. # Kill leftovers from previous run
  2655. # using any pidfiles found in var/run
  2656. kill_leftovers("$opt_vardir/run");
  2657. if ( ! $opt_start_dirty )
  2658. {
  2659. remove_stale_vardir();
  2660. setup_vardir();
  2661. mysql_install_db(default_mysqld(), "$opt_vardir/install.db");
  2662. }
  2663. }
  2664. }
  2665. #
  2666. # Remove all newline characters expect after semicolon
  2667. #
  2668. sub sql_to_bootstrap {
  2669. my ($sql) = @_;
  2670. my @lines= split(/\n/, $sql);
  2671. my $result= "\n";
  2672. my $delimiter= ';';
  2673. foreach my $line (@lines) {
  2674. # Change current delimiter if line starts with "delimiter"
  2675. if ( $line =~ /^delimiter (.*)/ ) {
  2676. my $new= $1;
  2677. # Remove old delimiter from end of new
  2678. $new=~ s/\Q$delimiter\E$//;
  2679. $delimiter = $new;
  2680. mtr_debug("changed delimiter to $delimiter");
  2681. # No need to add the delimiter to result
  2682. next;
  2683. }
  2684. # Add newline if line ends with $delimiter
  2685. # and convert the current delimiter to semicolon
  2686. if ( $line =~ /\Q$delimiter\E$/ ){
  2687. $line =~ s/\Q$delimiter\E$/;/;
  2688. $result.= "$line\n";
  2689. mtr_debug("Added default delimiter");
  2690. next;
  2691. }
  2692. # Remove comments starting with --
  2693. if ( $line =~ /^\s*--/ ) {
  2694. mtr_debug("Discarded $line");
  2695. next;
  2696. }
  2697. # Replace @HOSTNAME with localhost
  2698. $line=~ s/\'\@HOSTNAME\@\'/localhost/;
  2699. # Default, just add the line without newline
  2700. # but with a space as separator
  2701. $result.= "$line ";
  2702. }
  2703. return $result;
  2704. }
  2705. sub default_mysqld {
  2706. # Generate new config file from template
  2707. my $config= My::ConfigFactory->new_config
  2708. ( {
  2709. basedir => $basedir,
  2710. testdir => $glob_mysql_test_dir,
  2711. template_path => "include/default_my.cnf",
  2712. vardir => $opt_vardir,
  2713. tmpdir => $opt_tmpdir,
  2714. baseport => 0,
  2715. user => $opt_user,
  2716. password => '',
  2717. }
  2718. );
  2719. my $mysqld= $config->group('mysqld.1')
  2720. or mtr_error("Couldn't find mysqld.1 in default config");
  2721. return $mysqld;
  2722. }
  2723. sub mysql_install_db {
  2724. my ($mysqld, $datadir)= @_;
  2725. my $install_datadir= $datadir || $mysqld->value('datadir');
  2726. my $install_basedir= $mysqld->value('basedir');
  2727. my $install_lang= $mysqld->value('lc-messages-dir');
  2728. my $install_chsdir= $mysqld->value('character-sets-dir');
  2729. mtr_report("Installing system database...");
  2730. my $args;
  2731. mtr_init_args(\$args);
  2732. mtr_add_arg($args, "--no-defaults");
  2733. mtr_add_arg($args, "--bootstrap");
  2734. mtr_add_arg($args, "--basedir=%s", $install_basedir);
  2735. mtr_add_arg($args, "--datadir=%s", $install_datadir);
  2736. mtr_add_arg($args, "--loose-skip-falcon");
  2737. mtr_add_arg($args, "--loose-skip-ndbcluster");
  2738. mtr_add_arg($args, "--tmpdir=%s", "$opt_vardir/tmp/");
  2739. mtr_add_arg($args, "--core-file");
  2740. if ( $opt_debug )
  2741. {
  2742. mtr_add_arg($args, "--debug=$debug_d:t:i:A,%s/log/bootstrap.trace",
  2743. $path_vardir_trace);
  2744. }
  2745. mtr_add_arg($args, "--lc-messages-dir=%s", $install_lang);
  2746. mtr_add_arg($args, "--character-sets-dir=%s", $install_chsdir);
  2747. # On some old linux kernels, aio on tmpfs is not supported
  2748. # Remove this if/when Bug #58421 fixes this in the server
  2749. if ($^O eq "linux" && $opt_mem) {
  2750. mtr_add_arg($args, "--loose-skip-innodb-use-native-aio");
  2751. }
  2752. # InnoDB arguments that affect file location and sizes may
  2753. # need to be given to the bootstrap process as well as the
  2754. # server process.
  2755. foreach my $extra_opt ( @opt_extra_mysqld_opt ) {
  2756. if ($extra_opt =~ /--innodb/) {
  2757. mtr_add_arg($args, $extra_opt);
  2758. }
  2759. }
  2760. # If DISABLE_GRANT_OPTIONS is defined when the server is compiled (e.g.,
  2761. # configure --disable-grant-options), mysqld will not recognize the
  2762. # --bootstrap or --skip-grant-tables options. The user can set
  2763. # MYSQLD_BOOTSTRAP to the full path to a mysqld which does accept
  2764. # --bootstrap, to accommodate this.
  2765. my $exe_mysqld_bootstrap =
  2766. $ENV{'MYSQLD_BOOTSTRAP'} || find_mysqld($install_basedir);
  2767. # ----------------------------------------------------------------------
  2768. # export MYSQLD_BOOTSTRAP_CMD variable containing <path>/mysqld <args>
  2769. # ----------------------------------------------------------------------
  2770. $ENV{'MYSQLD_BOOTSTRAP_CMD'}= "$exe_mysqld_bootstrap " . join(" ", @$args);
  2771. # ----------------------------------------------------------------------
  2772. # Create the bootstrap.sql file
  2773. # ----------------------------------------------------------------------
  2774. my $bootstrap_sql_file= "$opt_vardir/tmp/bootstrap.sql";
  2775. if ($opt_boot_gdb) {
  2776. gdb_arguments(\$args, \$exe_mysqld_bootstrap, $mysqld->name(),
  2777. $bootstrap_sql_file);
  2778. }
  2779. if ($opt_boot_dbx) {
  2780. dbx_arguments(\$args, \$exe_mysqld_bootstrap, $mysqld->name(),
  2781. $bootstrap_sql_file);
  2782. }
  2783. if ($opt_boot_ddd) {
  2784. ddd_arguments(\$args, \$exe_mysqld_bootstrap, $mysqld->name(),
  2785. $bootstrap_sql_file);
  2786. }
  2787. my $path_sql= my_find_file($install_basedir,
  2788. ["mysql", "sql/share", "share/mysql",
  2789. "share", "scripts"],
  2790. "mysql_system_tables.sql",
  2791. NOT_REQUIRED);
  2792. if (-f $path_sql )
  2793. {
  2794. my $sql_dir= dirname($path_sql);
  2795. # Use the mysql database for system tables
  2796. mtr_tofile($bootstrap_sql_file, "use mysql\n");
  2797. # Add the offical mysql system tables
  2798. # for a production system
  2799. mtr_appendfile_to_file("$sql_dir/mysql_system_tables.sql",
  2800. $bootstrap_sql_file);
  2801. # Add the mysql system tables initial data
  2802. # for a production system
  2803. mtr_appendfile_to_file("$sql_dir/mysql_system_tables_data.sql",
  2804. $bootstrap_sql_file);
  2805. # Add test data for timezone - this is just a subset, on a real
  2806. # system these tables will be populated either by mysql_tzinfo_to_sql
  2807. # or by downloading the timezone table package from our website
  2808. mtr_appendfile_to_file("$sql_dir/mysql_test_data_timezone.sql",
  2809. $bootstrap_sql_file);
  2810. # Fill help tables, just an empty file when running from bk repo
  2811. # but will be replaced by a real fill_help_tables.sql when
  2812. # building the source dist
  2813. mtr_appendfile_to_file("$sql_dir/fill_help_tables.sql",
  2814. $bootstrap_sql_file);
  2815. }
  2816. else
  2817. {
  2818. # Install db from init_db.sql that exist in early 5.1 and 5.0
  2819. # versions of MySQL
  2820. my $init_file= "$install_basedir/mysql-test/lib/init_db.sql";
  2821. mtr_report(" - from '$init_file'");
  2822. my $text= mtr_grab_file($init_file) or
  2823. mtr_error("Can't open '$init_file': $!");
  2824. mtr_tofile($bootstrap_sql_file,
  2825. sql_to_bootstrap($text));
  2826. }
  2827. # Remove anonymous users
  2828. mtr_tofile($bootstrap_sql_file,
  2829. "DELETE FROM mysql.user where user= '';\n");
  2830. # Create mtr database
  2831. mtr_tofile($bootstrap_sql_file,
  2832. "CREATE DATABASE mtr;\n");
  2833. # Add help tables and data for warning detection and supression
  2834. mtr_tofile($bootstrap_sql_file,
  2835. sql_to_bootstrap(mtr_grab_file("include/mtr_warnings.sql")));
  2836. # Add procedures for checking server is restored after testcase
  2837. mtr_tofile($bootstrap_sql_file,
  2838. sql_to_bootstrap(mtr_grab_file("include/mtr_check.sql")));
  2839. # Log bootstrap command
  2840. my $path_bootstrap_log= "$opt_vardir/log/bootstrap.log";
  2841. mtr_tofile($path_bootstrap_log,
  2842. "$exe_mysqld_bootstrap " . join(" ", @$args) . "\n");
  2843. # Create directories mysql and test
  2844. mkpath("$install_datadir/mysql");
  2845. mkpath("$install_datadir/test");
  2846. if ( My::SafeProcess->run
  2847. (
  2848. name => "bootstrap",
  2849. path => $exe_mysqld_bootstrap,
  2850. args => \$args,
  2851. input => $bootstrap_sql_file,
  2852. output => $path_bootstrap_log,
  2853. error => $path_bootstrap_log,
  2854. append => 1,
  2855. verbose => $opt_verbose,
  2856. ) != 0)
  2857. {
  2858. mtr_error("Error executing mysqld --bootstrap\n" .
  2859. "Could not install system database from $bootstrap_sql_file\n" .
  2860. "see $path_bootstrap_log for errors");
  2861. }
  2862. }
  2863. sub run_testcase_check_skip_test($)
  2864. {
  2865. my ($tinfo)= @_;
  2866. # ----------------------------------------------------------------------
  2867. # If marked to skip, just print out and return.
  2868. # Note that a test case not marked as 'skip' can still be
  2869. # skipped later, because of the test case itself in cooperation
  2870. # with the mysqltest program tells us so.
  2871. # ----------------------------------------------------------------------
  2872. if ( $tinfo->{'skip'} )
  2873. {
  2874. mtr_report_test_skipped($tinfo) unless $start_only;
  2875. return 1;
  2876. }
  2877. return 0;
  2878. }
  2879. sub run_query {
  2880. my ($tinfo, $mysqld, $query)= @_;
  2881. my $args;
  2882. mtr_init_args(\$args);
  2883. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  2884. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  2885. mtr_add_arg($args, "-e %s", $query);
  2886. my $res= My::SafeProcess->run
  2887. (
  2888. name => "run_query -> ".$mysqld->name(),
  2889. path => $exe_mysql,
  2890. args => \$args,
  2891. output => '/dev/null',
  2892. error => '/dev/null'
  2893. );
  2894. return $res
  2895. }
  2896. sub do_before_run_mysqltest($)
  2897. {
  2898. my $tinfo= shift;
  2899. # Remove old files produced by mysqltest
  2900. my $base_file= mtr_match_extension($tinfo->{result_file},
  2901. "result"); # Trim extension
  2902. if (defined $base_file ){
  2903. unlink("$base_file.reject");
  2904. unlink("$base_file.progress");
  2905. unlink("$base_file.log");
  2906. unlink("$base_file.warnings");
  2907. }
  2908. if ( $mysql_version_id < 50000 ) {
  2909. # Set environment variable NDB_STATUS_OK to 1
  2910. # if script decided to run mysqltest cluster _is_ installed ok
  2911. $ENV{'NDB_STATUS_OK'} = "1";
  2912. } elsif ( $mysql_version_id < 50100 ) {
  2913. # Set environment variable NDB_STATUS_OK to YES
  2914. # if script decided to run mysqltest cluster _is_ installed ok
  2915. $ENV{'NDB_STATUS_OK'} = "YES";
  2916. }
  2917. }
  2918. #
  2919. # Check all server for sideffects
  2920. #
  2921. # RETURN VALUE
  2922. # 0 ok
  2923. # 1 Check failed
  2924. # >1 Fatal errro
  2925. sub check_testcase($$)
  2926. {
  2927. my ($tinfo, $mode)= @_;
  2928. my $tname= $tinfo->{name};
  2929. # Start the mysqltest processes in parallel to save time
  2930. # also makes it possible to wait for any process to exit during the check
  2931. my %started;
  2932. foreach my $mysqld ( mysqlds() )
  2933. {
  2934. # Skip if server has been restarted with additional options
  2935. if ( defined $mysqld->{'proc'} && ! exists $mysqld->{'restart_opts'} )
  2936. {
  2937. my $proc= start_check_testcase($tinfo, $mode, $mysqld);
  2938. $started{$proc->pid()}= $proc;
  2939. }
  2940. }
  2941. # Return immediately if no check proceess was started
  2942. return 0 unless ( keys %started );
  2943. my $timeout= start_timer(check_timeout($tinfo));
  2944. while (1){
  2945. my $result;
  2946. my $proc= My::SafeProcess->wait_any_timeout($timeout);
  2947. mtr_report("Got $proc");
  2948. if ( delete $started{$proc->pid()} ) {
  2949. my $err_file= $proc->user_data();
  2950. my $base_file= mtr_match_extension($err_file, "err"); # Trim extension
  2951. # One check testcase process returned
  2952. my $res= $proc->exit_status();
  2953. if ( $res == 0){
  2954. # Check completed without problem
  2955. # Remove the .err file the check generated
  2956. unlink($err_file);
  2957. # Remove the .result file the check generated
  2958. if ( $mode eq 'after' ){
  2959. unlink("$base_file.result");
  2960. }
  2961. if ( keys(%started) == 0){
  2962. # All checks completed
  2963. mark_time_used('check');
  2964. return 0;
  2965. }
  2966. # Wait for next process to exit
  2967. next;
  2968. }
  2969. else
  2970. {
  2971. if ( $mode eq "after" and $res == 1 )
  2972. {
  2973. # Test failed, grab the report mysqltest has created
  2974. my $report= mtr_grab_file($err_file);
  2975. $tinfo->{check}.=
  2976. "\nMTR's internal check of the test case '$tname' failed.
  2977. This means that the test case does not preserve the state that existed
  2978. before the test case was executed. Most likely the test case did not
  2979. do a proper clean-up. It could also be caused by the previous test run
  2980. by this thread, if the server wasn't restarted.
  2981. This is the diff of the states of the servers before and after the
  2982. test case was executed:\n";
  2983. $tinfo->{check}.= $report;
  2984. # Check failed, mark the test case with that info
  2985. $tinfo->{'check_testcase_failed'}= 1;
  2986. $result= 1;
  2987. }
  2988. elsif ( $res )
  2989. {
  2990. my $report= mtr_grab_file($err_file);
  2991. $tinfo->{comment}.=
  2992. "Could not execute 'check-testcase' $mode ".
  2993. "testcase '$tname' (res: $res):\n";
  2994. $tinfo->{comment}.= $report;
  2995. $result= 2;
  2996. }
  2997. # Remove the .result file the check generated
  2998. unlink("$base_file.result");
  2999. }
  3000. }
  3001. elsif ( $proc->{timeout} ) {
  3002. $tinfo->{comment}.= "Timeout for 'check-testcase' expired after "
  3003. .check_timeout($tinfo)." seconds";
  3004. $result= 4;
  3005. }
  3006. else {
  3007. # Unknown process returned, most likley a crash, abort everything
  3008. $tinfo->{comment}=
  3009. "The server $proc crashed while running ".
  3010. "'check testcase $mode test'".
  3011. get_log_from_proc($proc, $tinfo->{name});
  3012. $result= 3;
  3013. }
  3014. # Kill any check processes still running
  3015. map($_->kill(), values(%started));
  3016. mtr_warning("Check-testcase failed, this could also be caused by the" .
  3017. " previous test run by this worker thread")
  3018. if $result > 1 && $mode eq "before";
  3019. mark_time_used('check');
  3020. return $result;
  3021. }
  3022. mtr_error("INTERNAL_ERROR: check_testcase");
  3023. }
  3024. # Start run mysqltest on one server
  3025. #
  3026. # RETURN VALUE
  3027. # 0 OK
  3028. # 1 Check failed
  3029. #
  3030. sub start_run_one ($$) {
  3031. my ($mysqld, $run)= @_;
  3032. my $name= "$run-".$mysqld->name();
  3033. my $args;
  3034. mtr_init_args(\$args);
  3035. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  3036. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  3037. mtr_add_arg($args, "--silent");
  3038. mtr_add_arg($args, "--test-file=%s", "include/$run.test");
  3039. my $errfile= "$opt_vardir/tmp/$name.err";
  3040. my $proc= My::SafeProcess->new
  3041. (
  3042. name => $name,
  3043. path => $exe_mysqltest,
  3044. error => $errfile,
  3045. output => $errfile,
  3046. args => \$args,
  3047. user_data => $errfile,
  3048. verbose => $opt_verbose,
  3049. );
  3050. mtr_verbose("Started $proc");
  3051. return $proc;
  3052. }
  3053. #
  3054. # Run script on all servers, collect results
  3055. #
  3056. # RETURN VALUE
  3057. # 0 ok
  3058. # 1 Failure
  3059. sub run_on_all($$)
  3060. {
  3061. my ($tinfo, $run)= @_;
  3062. # Start the mysqltest processes in parallel to save time
  3063. # also makes it possible to wait for any process to exit during the check
  3064. # and to have a timeout process
  3065. my %started;
  3066. foreach my $mysqld ( mysqlds() )
  3067. {
  3068. if ( defined $mysqld->{'proc'} )
  3069. {
  3070. my $proc= start_run_one($mysqld, $run);
  3071. $started{$proc->pid()}= $proc;
  3072. }
  3073. }
  3074. # Return immediately if no check proceess was started
  3075. return 0 unless ( keys %started );
  3076. my $timeout= start_timer(check_timeout($tinfo));
  3077. while (1){
  3078. my $result;
  3079. my $proc= My::SafeProcess->wait_any_timeout($timeout);
  3080. mtr_report("Got $proc");
  3081. if ( delete $started{$proc->pid()} ) {
  3082. # One mysqltest process returned
  3083. my $err_file= $proc->user_data();
  3084. my $res= $proc->exit_status();
  3085. # Append the report from .err file
  3086. $tinfo->{comment}.= " == $err_file ==\n";
  3087. $tinfo->{comment}.= mtr_grab_file($err_file);
  3088. $tinfo->{comment}.= "\n";
  3089. # Remove the .err file
  3090. unlink($err_file);
  3091. if ( keys(%started) == 0){
  3092. # All completed
  3093. return 0;
  3094. }
  3095. # Wait for next process to exit
  3096. next;
  3097. }
  3098. elsif ($proc->{timeout}) {
  3099. $tinfo->{comment}.= "Timeout for '$run' expired after "
  3100. .check_timeout($tinfo)." seconds";
  3101. }
  3102. else {
  3103. # Unknown process returned, most likley a crash, abort everything
  3104. $tinfo->{comment}.=
  3105. "The server $proc crashed while running '$run'".
  3106. get_log_from_proc($proc, $tinfo->{name});
  3107. }
  3108. # Kill any check processes still running
  3109. map($_->kill(), values(%started));
  3110. return 1;
  3111. }
  3112. mtr_error("INTERNAL_ERROR: run_on_all");
  3113. }
  3114. sub mark_log {
  3115. my ($log, $tinfo)= @_;
  3116. my $log_msg= "CURRENT_TEST: $tinfo->{name}\n";
  3117. mtr_tofile($log, $log_msg);
  3118. }
  3119. sub find_testcase_skipped_reason($)
  3120. {
  3121. my ($tinfo)= @_;
  3122. # Set default message
  3123. $tinfo->{'comment'}= "Detected by testcase(no log file)";
  3124. # Open the test log file
  3125. my $F= IO::File->new($path_current_testlog)
  3126. or return;
  3127. my $reason;
  3128. while ( my $line= <$F> )
  3129. {
  3130. # Look for "reason: <reason for skipping test>"
  3131. if ( $line =~ /reason: (.*)/ )
  3132. {
  3133. $reason= $1;
  3134. }
  3135. }
  3136. if ( ! $reason )
  3137. {
  3138. mtr_warning("Could not find reason for skipping test in $path_current_testlog");
  3139. $reason= "Detected by testcase(reason unknown) ";
  3140. }
  3141. $tinfo->{'comment'}= $reason;
  3142. }
  3143. sub find_analyze_request
  3144. {
  3145. # Open the test log file
  3146. my $F= IO::File->new($path_current_testlog)
  3147. or return;
  3148. my $analyze;
  3149. while ( my $line= <$F> )
  3150. {
  3151. # Look for "reason: <reason for skipping test>"
  3152. if ( $line =~ /analyze: (.*)/ )
  3153. {
  3154. $analyze= $1;
  3155. }
  3156. }
  3157. return $analyze;
  3158. }
  3159. # The test can leave a file in var/tmp/ to signal
  3160. # that all servers should be restarted
  3161. sub restart_forced_by_test($)
  3162. {
  3163. my $file = shift;
  3164. my $restart = 0;
  3165. foreach my $mysqld ( mysqlds() )
  3166. {
  3167. my $datadir = $mysqld->value('datadir');
  3168. my $force_restart_file = "$datadir/mtr/$file";
  3169. if ( -f $force_restart_file )
  3170. {
  3171. mtr_verbose("Restart of servers forced by test");
  3172. $restart = 1;
  3173. last;
  3174. }
  3175. }
  3176. return $restart;
  3177. }
  3178. # Return timezone value of tinfo or default value
  3179. sub timezone {
  3180. my ($tinfo)= @_;
  3181. return $tinfo->{timezone} || "GMT-3";
  3182. }
  3183. # Storage for changed environment variables
  3184. my %old_env;
  3185. sub resfile_report_test ($) {
  3186. my $tinfo= shift;
  3187. resfile_new_test();
  3188. resfile_test_info("name", $tinfo->{name});
  3189. resfile_test_info("variation", $tinfo->{combination})
  3190. if $tinfo->{combination};
  3191. resfile_test_info("start_time", isotime time);
  3192. }
  3193. #
  3194. # Run a single test case
  3195. #
  3196. # RETURN VALUE
  3197. # 0 OK
  3198. # > 0 failure
  3199. #
  3200. sub run_testcase ($) {
  3201. my $tinfo= shift;
  3202. mtr_verbose("Running test:", $tinfo->{name});
  3203. resfile_report_test($tinfo) if $opt_resfile;
  3204. # Allow only alpanumerics pluss _ - + . in combination names,
  3205. # or anything beginning with -- (the latter comes from --combination)
  3206. my $combination= $tinfo->{combination};
  3207. if ($combination && $combination !~ /^\w[-\w\.\+]+$/
  3208. && $combination !~ /^--/)
  3209. {
  3210. mtr_error("Combination '$combination' contains illegal characters");
  3211. }
  3212. # -------------------------------------------------------
  3213. # Init variables that can change between each test case
  3214. # -------------------------------------------------------
  3215. my $timezone= timezone($tinfo);
  3216. $ENV{'TZ'}= $timezone;
  3217. mtr_verbose("Setting timezone: $timezone");
  3218. if ( ! using_extern() )
  3219. {
  3220. my @restart= servers_need_restart($tinfo);
  3221. if ( @restart != 0) {
  3222. stop_servers($tinfo, @restart );
  3223. }
  3224. if ( started(all_servers()) == 0 )
  3225. {
  3226. # Remove old datadirs
  3227. clean_datadir() unless $opt_start_dirty;
  3228. # Restore old ENV
  3229. while (my ($option, $value)= each( %old_env )) {
  3230. if (defined $value){
  3231. mtr_verbose("Restoring $option to $value");
  3232. $ENV{$option}= $value;
  3233. } else {
  3234. mtr_verbose("Removing $option");
  3235. delete($ENV{$option});
  3236. }
  3237. }
  3238. %old_env= ();
  3239. mtr_verbose("Generating my.cnf from '$tinfo->{template_path}'");
  3240. # Generate new config file from template
  3241. $config= My::ConfigFactory->new_config
  3242. ( {
  3243. basedir => $basedir,
  3244. testdir => $glob_mysql_test_dir,
  3245. template_path => $tinfo->{template_path},
  3246. extra_template_path => $tinfo->{extra_template_path},
  3247. vardir => $opt_vardir,
  3248. tmpdir => $opt_tmpdir,
  3249. baseport => $baseport,
  3250. #hosts => [ 'host1', 'host2' ],
  3251. user => $opt_user,
  3252. password => '',
  3253. ssl => $opt_ssl_supported,
  3254. embedded => $opt_embedded_server,
  3255. }
  3256. );
  3257. # Write the new my.cnf
  3258. $config->save($path_config_file);
  3259. # Remember current config so a restart can occur when a test need
  3260. # to use a different one
  3261. $current_config_name= $tinfo->{template_path};
  3262. #
  3263. # Set variables in the ENV section
  3264. #
  3265. foreach my $option ($config->options_in_group("ENV"))
  3266. {
  3267. # Save old value to restore it before next time
  3268. $old_env{$option->name()}= $ENV{$option->name()};
  3269. mtr_verbose($option->name(), "=",$option->value());
  3270. $ENV{$option->name()}= $option->value();
  3271. }
  3272. }
  3273. # Write start of testcase to log
  3274. mark_log($path_current_testlog, $tinfo);
  3275. if (start_servers($tinfo))
  3276. {
  3277. report_failure_and_restart($tinfo);
  3278. return 1;
  3279. }
  3280. }
  3281. mark_time_used('restart');
  3282. # --------------------------------------------------------------------
  3283. # If --start or --start-dirty given, stop here to let user manually
  3284. # run tests
  3285. # If --wait-all is also given, do the same, but don't die if one
  3286. # server exits
  3287. # ----------------------------------------------------------------------
  3288. if ( $start_only )
  3289. {
  3290. mtr_print("\nStarted", started(all_servers()));
  3291. mtr_print("Using config for test", $tinfo->{name});
  3292. mtr_print("Port and socket path for server(s):");
  3293. foreach my $mysqld ( mysqlds() )
  3294. {
  3295. mtr_print ($mysqld->name() . " " . $mysqld->value('port') .
  3296. " " . $mysqld->value('socket'));
  3297. }
  3298. if ( $opt_start_exit )
  3299. {
  3300. mtr_print("Server(s) started, not waiting for them to finish");
  3301. if (IS_WINDOWS)
  3302. {
  3303. POSIX::_exit(0); # exit hangs here in ActiveState Perl
  3304. }
  3305. else
  3306. {
  3307. exit(0);
  3308. }
  3309. }
  3310. mtr_print("Waiting for server(s) to exit...");
  3311. if ( $opt_wait_all ) {
  3312. My::SafeProcess->wait_all();
  3313. mtr_print( "All servers exited" );
  3314. exit(1);
  3315. }
  3316. else {
  3317. my $proc= My::SafeProcess->wait_any();
  3318. if ( grep($proc eq $_, started(all_servers())) )
  3319. {
  3320. mtr_print("Server $proc died");
  3321. exit(1);
  3322. }
  3323. mtr_print("Unknown process $proc died");
  3324. exit(1);
  3325. }
  3326. }
  3327. my $test_timeout= start_timer(testcase_timeout($tinfo));
  3328. do_before_run_mysqltest($tinfo);
  3329. mark_time_used('admin');
  3330. if ( $opt_check_testcases and check_testcase($tinfo, "before") ){
  3331. # Failed to record state of server or server crashed
  3332. report_failure_and_restart($tinfo);
  3333. return 1;
  3334. }
  3335. my $test= start_mysqltest($tinfo);
  3336. # Set only when we have to keep waiting after expectedly died server
  3337. my $keep_waiting_proc = 0;
  3338. while (1)
  3339. {
  3340. my $proc;
  3341. if ($keep_waiting_proc)
  3342. {
  3343. # Any other process exited?
  3344. $proc = My::SafeProcess->check_any();
  3345. if ($proc)
  3346. {
  3347. mtr_verbose ("Found exited process $proc");
  3348. }
  3349. else
  3350. {
  3351. $proc = $keep_waiting_proc;
  3352. # Also check if timer has expired, if so cancel waiting
  3353. if ( has_expired($test_timeout) )
  3354. {
  3355. $keep_waiting_proc = 0;
  3356. }
  3357. }
  3358. }
  3359. if (! $keep_waiting_proc)
  3360. {
  3361. $proc= My::SafeProcess->wait_any_timeout($test_timeout);
  3362. }
  3363. # Will be restored if we need to keep waiting
  3364. $keep_waiting_proc = 0;
  3365. unless ( defined $proc )
  3366. {
  3367. mtr_error("wait_any failed");
  3368. }
  3369. mtr_verbose("Got $proc");
  3370. mark_time_used('test');
  3371. # ----------------------------------------------------
  3372. # Was it the test program that exited
  3373. # ----------------------------------------------------
  3374. if ($proc eq $test)
  3375. {
  3376. my $res= $test->exit_status();
  3377. if ($res == 0 and $opt_warnings and check_warnings($tinfo) )
  3378. {
  3379. # Test case suceeded, but it has produced unexpected
  3380. # warnings, continue in $res == 1
  3381. $res= 1;
  3382. resfile_output($tinfo->{'warnings'}) if $opt_resfile;
  3383. }
  3384. if ( $res == 0 )
  3385. {
  3386. my $check_res;
  3387. if ( restart_forced_by_test('force_restart') )
  3388. {
  3389. stop_all_servers($opt_shutdown_timeout);
  3390. }
  3391. elsif ( $opt_check_testcases and
  3392. $check_res= check_testcase($tinfo, "after"))
  3393. {
  3394. if ($check_res == 1) {
  3395. # Test case had sideeffects, not fatal error, just continue
  3396. stop_all_servers($opt_shutdown_timeout);
  3397. mtr_report("Resuming tests...\n");
  3398. resfile_output($tinfo->{'check'}) if $opt_resfile;
  3399. }
  3400. else {
  3401. # Test case check failed fatally, probably a server crashed
  3402. report_failure_and_restart($tinfo);
  3403. return 1;
  3404. }
  3405. }
  3406. mtr_report_test_passed($tinfo);
  3407. }
  3408. elsif ( $res == 62 )
  3409. {
  3410. # Testcase itself tell us to skip this one
  3411. $tinfo->{skip_detected_by_test}= 1;
  3412. # Try to get reason from test log file
  3413. find_testcase_skipped_reason($tinfo);
  3414. mtr_report_test_skipped($tinfo);
  3415. # Restart if skipped due to missing perl, it may have had side effects
  3416. if ( restart_forced_by_test('force_restart_if_skipped') ||
  3417. $tinfo->{'comment'} =~ /^perl not found/ )
  3418. {
  3419. stop_all_servers($opt_shutdown_timeout);
  3420. }
  3421. }
  3422. elsif ( $res == 65 )
  3423. {
  3424. # Testprogram killed by signal
  3425. $tinfo->{comment}=
  3426. "testprogram crashed(returned code $res)";
  3427. report_failure_and_restart($tinfo);
  3428. }
  3429. elsif ( $res == 1 )
  3430. {
  3431. # Check if the test tool requests that
  3432. # an analyze script should be run
  3433. my $analyze= find_analyze_request();
  3434. if ($analyze){
  3435. run_on_all($tinfo, "analyze-$analyze");
  3436. }
  3437. # Wait a bit and see if a server died, if so report that instead
  3438. mtr_milli_sleep(100);
  3439. my $srvproc= My::SafeProcess::check_any();
  3440. if ($srvproc && grep($srvproc eq $_, started(all_servers()))) {
  3441. $proc= $srvproc;
  3442. goto SRVDIED;
  3443. }
  3444. # Test case failure reported by mysqltest
  3445. report_failure_and_restart($tinfo);
  3446. }
  3447. else
  3448. {
  3449. # mysqltest failed, probably crashed
  3450. $tinfo->{comment}=
  3451. "mysqltest failed with unexpected return code $res\n";
  3452. report_failure_and_restart($tinfo);
  3453. }
  3454. # Save info from this testcase run to mysqltest.log
  3455. if( -f $path_current_testlog)
  3456. {
  3457. if ($opt_resfile && $res && $res != 62) {
  3458. resfile_output_file($path_current_testlog);
  3459. }
  3460. mtr_appendfile_to_file($path_current_testlog, $path_testlog);
  3461. unlink($path_current_testlog);
  3462. }
  3463. return ($res == 62) ? 0 : $res;
  3464. }
  3465. # ----------------------------------------------------
  3466. # Check if it was an expected crash
  3467. # ----------------------------------------------------
  3468. my $check_crash = check_expected_crash_and_restart($proc);
  3469. if ($check_crash)
  3470. {
  3471. # Keep waiting if it returned 2, if 1 don't wait or stop waiting.
  3472. $keep_waiting_proc = 0 if $check_crash == 1;
  3473. $keep_waiting_proc = $proc if $check_crash == 2;
  3474. next;
  3475. }
  3476. SRVDIED:
  3477. # ----------------------------------------------------
  3478. # Stop the test case timer
  3479. # ----------------------------------------------------
  3480. $test_timeout= 0;
  3481. # ----------------------------------------------------
  3482. # Check if it was a server that died
  3483. # ----------------------------------------------------
  3484. if ( grep($proc eq $_, started(all_servers())) )
  3485. {
  3486. # Server failed, probably crashed
  3487. $tinfo->{comment}=
  3488. "Server $proc failed during test run" .
  3489. get_log_from_proc($proc, $tinfo->{name});
  3490. # ----------------------------------------------------
  3491. # It's not mysqltest that has exited, kill it
  3492. # ----------------------------------------------------
  3493. $test->kill();
  3494. report_failure_and_restart($tinfo);
  3495. return 1;
  3496. }
  3497. # Try to dump core for mysqltest and all servers
  3498. foreach my $proc ($test, started(all_servers()))
  3499. {
  3500. mtr_print("Trying to dump core for $proc");
  3501. if ($proc->dump_core())
  3502. {
  3503. $proc->wait_one(20);
  3504. }
  3505. }
  3506. # ----------------------------------------------------
  3507. # It's not mysqltest that has exited, kill it
  3508. # ----------------------------------------------------
  3509. $test->kill();
  3510. # ----------------------------------------------------
  3511. # Check if testcase timer expired
  3512. # ----------------------------------------------------
  3513. if ( $proc->{timeout} )
  3514. {
  3515. my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log";
  3516. $tinfo->{comment}=
  3517. "Test case timeout after ".testcase_timeout($tinfo).
  3518. " seconds\n\n";
  3519. # Add 20 last executed commands from test case log file
  3520. if (-e $log_file_name)
  3521. {
  3522. $tinfo->{comment}.=
  3523. "== $log_file_name == \n".
  3524. mtr_lastlinesfromfile($log_file_name, 20)."\n";
  3525. }
  3526. $tinfo->{'timeout'}= testcase_timeout($tinfo); # Mark as timeout
  3527. run_on_all($tinfo, 'analyze-timeout');
  3528. report_failure_and_restart($tinfo);
  3529. return 1;
  3530. }
  3531. mtr_error("Unhandled process $proc exited");
  3532. }
  3533. mtr_error("Should never come here");
  3534. }
  3535. # Extract server log from after the last occurrence of named test
  3536. # Return as an array of lines
  3537. #
  3538. sub extract_server_log ($$) {
  3539. my ($error_log, $tname) = @_;
  3540. # Open the servers .err log file and read all lines
  3541. # belonging to current tets into @lines
  3542. my $Ferr = IO::File->new($error_log)
  3543. or mtr_error("Could not open file '$error_log' for reading: $!");
  3544. my @lines;
  3545. my $found_test= 0; # Set once we've found the log of this test
  3546. while ( my $line = <$Ferr> )
  3547. {
  3548. if ($found_test)
  3549. {
  3550. # If test wasn't last after all, discard what we found, test again.
  3551. if ( $line =~ /^CURRENT_TEST:/)
  3552. {
  3553. @lines= ();
  3554. $found_test= $line =~ /^CURRENT_TEST: $tname/;
  3555. }
  3556. else
  3557. {
  3558. push(@lines, $line);
  3559. if (scalar(@lines) > 1000000) {
  3560. $Ferr = undef;
  3561. mtr_warning("Too much log from test, bailing out from extracting");
  3562. return ();
  3563. }
  3564. }
  3565. }
  3566. else
  3567. {
  3568. # Search for beginning of test, until found
  3569. $found_test= 1 if ($line =~ /^CURRENT_TEST: $tname/);
  3570. }
  3571. }
  3572. $Ferr = undef; # Close error log file
  3573. return @lines;
  3574. }
  3575. # Get log from server identified from its $proc object, from named test
  3576. # Return as a single string
  3577. #
  3578. sub get_log_from_proc ($$) {
  3579. my ($proc, $name)= @_;
  3580. my $srv_log= "";
  3581. foreach my $mysqld (mysqlds()) {
  3582. if ($mysqld->{proc} eq $proc) {
  3583. my @srv_lines= extract_server_log($mysqld->value('#log-error'), $name);
  3584. $srv_log= "\nServer log from this test:\n" .
  3585. "----------SERVER LOG START-----------\n". join ("", @srv_lines) .
  3586. "----------SERVER LOG END-------------\n";
  3587. last;
  3588. }
  3589. }
  3590. return $srv_log;
  3591. }
  3592. # Perform a rough examination of the servers
  3593. # error log and write all lines that look
  3594. # suspicious into $error_log.warnings
  3595. #
  3596. sub extract_warning_lines ($$) {
  3597. my ($error_log, $tname) = @_;
  3598. my @lines= extract_server_log($error_log, $tname);
  3599. # Write all suspicious lines to $error_log.warnings file
  3600. my $warning_log = "$error_log.warnings";
  3601. my $Fwarn = IO::File->new($warning_log, "w")
  3602. or die("Could not open file '$warning_log' for writing: $!");
  3603. print $Fwarn "Suspicious lines from $error_log\n";
  3604. my @patterns =
  3605. (
  3606. qr/^Warning:|mysqld: Warning|\[Warning\]/,
  3607. qr/^Error:|\[ERROR\]/,
  3608. qr/^==\d+==\s+\S/, # valgrind errors
  3609. qr/InnoDB: Warning|InnoDB: Error/,
  3610. qr/^safe_mutex:|allocated at line/,
  3611. qr/missing DBUG_RETURN/,
  3612. qr/Attempting backtrace/,
  3613. qr/Assertion .* failed/,
  3614. );
  3615. my $skip_valgrind= 0;
  3616. my $last_pat= "";
  3617. my $num_rep= 0;
  3618. foreach my $line ( @lines )
  3619. {
  3620. if ($opt_valgrind_mysqld) {
  3621. # Skip valgrind summary from tests where server has been restarted
  3622. # Should this contain memory leaks, the final report will find it
  3623. # Use a generic pattern for summaries
  3624. $skip_valgrind= 1 if $line =~ /^==\d+== [A-Z ]+ SUMMARY:/;
  3625. $skip_valgrind= 0 unless $line =~ /^==\d+==/;
  3626. next if $skip_valgrind;
  3627. }
  3628. foreach my $pat ( @patterns )
  3629. {
  3630. if ( $line =~ /$pat/ )
  3631. {
  3632. # Remove initial timestamp and look for consecutive identical lines
  3633. my $line_pat= $line;
  3634. $line_pat =~ s/^[0-9: ]*//;
  3635. if ($line_pat eq $last_pat) {
  3636. $num_rep++;
  3637. } else {
  3638. # Previous line had been repeated, report that first
  3639. if ($num_rep) {
  3640. print $Fwarn ".... repeated $num_rep times: $last_pat";
  3641. $num_rep= 0;
  3642. }
  3643. $last_pat= $line_pat;
  3644. print $Fwarn $line;
  3645. }
  3646. last;
  3647. }
  3648. }
  3649. }
  3650. # Catch the case of last warning being repeated
  3651. if ($num_rep) {
  3652. print $Fwarn ".... repeated $num_rep times: $last_pat";
  3653. }
  3654. $Fwarn = undef; # Close file
  3655. }
  3656. # Run include/check-warnings.test
  3657. #
  3658. # RETURN VALUE
  3659. # 0 OK
  3660. # 1 Check failed
  3661. #
  3662. sub start_check_warnings ($$) {
  3663. my $tinfo= shift;
  3664. my $mysqld= shift;
  3665. my $name= "warnings-".$mysqld->name();
  3666. my $log_error= $mysqld->value('#log-error');
  3667. # To be communicated to the test
  3668. $ENV{MTR_LOG_ERROR}= $log_error;
  3669. extract_warning_lines($log_error, $tinfo->{name});
  3670. my $args;
  3671. mtr_init_args(\$args);
  3672. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  3673. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  3674. mtr_add_arg($args, "--test-file=%s", "include/check-warnings.test");
  3675. if ( $opt_embedded_server )
  3676. {
  3677. # Get the args needed for the embedded server
  3678. # and append them to args prefixed
  3679. # with --sever-arg=
  3680. my $mysqld= $config->group('embedded')
  3681. or mtr_error("Could not get [embedded] section");
  3682. my $mysqld_args;
  3683. mtr_init_args(\$mysqld_args);
  3684. my $extra_opts= get_extra_opts($mysqld, $tinfo);
  3685. mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
  3686. mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
  3687. }
  3688. my $errfile= "$opt_vardir/tmp/$name.err";
  3689. my $proc= My::SafeProcess->new
  3690. (
  3691. name => $name,
  3692. path => $exe_mysqltest,
  3693. error => $errfile,
  3694. output => $errfile,
  3695. args => \$args,
  3696. user_data => $errfile,
  3697. verbose => $opt_verbose,
  3698. );
  3699. mtr_verbose("Started $proc");
  3700. return $proc;
  3701. }
  3702. #
  3703. # Loop through our list of processes and check the error log
  3704. # for unexepcted errors and warnings
  3705. #
  3706. sub check_warnings ($) {
  3707. my ($tinfo)= @_;
  3708. my $res= 0;
  3709. my $tname= $tinfo->{name};
  3710. # Clear previous warnings
  3711. delete($tinfo->{warnings});
  3712. # Start the mysqltest processes in parallel to save time
  3713. # also makes it possible to wait for any process to exit during the check
  3714. my %started;
  3715. foreach my $mysqld ( mysqlds() )
  3716. {
  3717. if ( defined $mysqld->{'proc'} )
  3718. {
  3719. my $proc= start_check_warnings($tinfo, $mysqld);
  3720. $started{$proc->pid()}= $proc;
  3721. }
  3722. }
  3723. # Return immediately if no check proceess was started
  3724. return 0 unless ( keys %started );
  3725. my $timeout= start_timer(check_timeout($tinfo));
  3726. while (1){
  3727. my $result= 0;
  3728. my $proc= My::SafeProcess->wait_any_timeout($timeout);
  3729. mtr_report("Got $proc");
  3730. if ( delete $started{$proc->pid()} ) {
  3731. # One check warning process returned
  3732. my $res= $proc->exit_status();
  3733. my $err_file= $proc->user_data();
  3734. if ( $res == 0 or $res == 62 ){
  3735. if ( $res == 0 ) {
  3736. # Check completed with problem
  3737. my $report= mtr_grab_file($err_file);
  3738. # Log to var/log/warnings file
  3739. mtr_tofile("$opt_vardir/log/warnings",
  3740. $tname."\n".$report);
  3741. $tinfo->{'warnings'}.= $report;
  3742. $result= 1;
  3743. }
  3744. if ( $res == 62 ) {
  3745. # Test case was ok and called "skip"
  3746. # Remove the .err file the check generated
  3747. unlink($err_file);
  3748. }
  3749. if ( keys(%started) == 0){
  3750. # All checks completed
  3751. mark_time_used('ch-warn');
  3752. return $result;
  3753. }
  3754. # Wait for next process to exit
  3755. next;
  3756. }
  3757. else
  3758. {
  3759. my $report= mtr_grab_file($err_file);
  3760. $tinfo->{comment}.=
  3761. "Could not execute 'check-warnings' for ".
  3762. "testcase '$tname' (res: $res):\n";
  3763. $tinfo->{comment}.= $report;
  3764. $result= 2;
  3765. }
  3766. }
  3767. elsif ( $proc->{timeout} ) {
  3768. $tinfo->{comment}.= "Timeout for 'check warnings' expired after "
  3769. .check_timeout($tinfo)." seconds";
  3770. $result= 4;
  3771. }
  3772. else {
  3773. # Unknown process returned, most likley a crash, abort everything
  3774. $tinfo->{comment}=
  3775. "The server $proc crashed while running 'check warnings'".
  3776. get_log_from_proc($proc, $tinfo->{name});
  3777. $result= 3;
  3778. }
  3779. # Kill any check processes still running
  3780. map($_->kill(), values(%started));
  3781. mark_time_used('ch-warn');
  3782. return $result;
  3783. }
  3784. mtr_error("INTERNAL_ERROR: check_warnings");
  3785. }
  3786. #
  3787. # Loop through our list of processes and look for and entry
  3788. # with the provided pid, if found check for the file indicating
  3789. # expected crash and restart it.
  3790. #
  3791. sub check_expected_crash_and_restart {
  3792. my ($proc)= @_;
  3793. foreach my $mysqld ( mysqlds() )
  3794. {
  3795. next unless ( $mysqld->{proc} and $mysqld->{proc} eq $proc );
  3796. # Check if crash expected by looking at the .expect file
  3797. # in var/tmp
  3798. my $expect_file= "$opt_vardir/tmp/".$mysqld->name().".expect";
  3799. if ( -f $expect_file )
  3800. {
  3801. mtr_verbose("Crash was expected, file '$expect_file' exists");
  3802. for (my $waits = 0; $waits < 50; mtr_milli_sleep(100), $waits++)
  3803. {
  3804. # Race condition seen on Windows: try again until file not empty
  3805. next if -z $expect_file;
  3806. # If last line in expect file starts with "wait"
  3807. # sleep a little and try again, thus allowing the
  3808. # test script to control when the server should start
  3809. # up again. Keep trying for up to 5s at a time.
  3810. my $last_line= mtr_lastlinesfromfile($expect_file, 1);
  3811. if ($last_line =~ /^wait/ )
  3812. {
  3813. mtr_verbose("Test says wait before restart") if $waits == 0;
  3814. next;
  3815. }
  3816. # Ignore any partial or unknown command
  3817. next unless $last_line =~ /^restart/;
  3818. # If last line begins "restart:", the rest of the line is read as
  3819. # extra command line options to add to the restarted mysqld.
  3820. # Anything other than 'wait' or 'restart:' (with a colon) will
  3821. # result in a restart with original mysqld options.
  3822. if ($last_line =~ /restart:(.+)/) {
  3823. my @rest_opt= split(' ', $1);
  3824. $mysqld->{'restart_opts'}= \@rest_opt;
  3825. } else {
  3826. delete $mysqld->{'restart_opts'};
  3827. }
  3828. unlink($expect_file);
  3829. # Start server with same settings as last time
  3830. mysqld_start($mysqld, $mysqld->{'started_opts'});
  3831. return 1;
  3832. }
  3833. # Loop ran through: we should keep waiting after a re-check
  3834. return 2;
  3835. }
  3836. }
  3837. # Not an expected crash
  3838. return 0;
  3839. }
  3840. # Remove all files and subdirectories of a directory
  3841. sub clean_dir {
  3842. my ($dir)= @_;
  3843. mtr_verbose("clean_dir: $dir");
  3844. finddepth(
  3845. { no_chdir => 1,
  3846. wanted => sub {
  3847. if (-d $_){
  3848. # A dir
  3849. if ($_ eq $dir){
  3850. # The dir to clean
  3851. return;
  3852. } else {
  3853. mtr_verbose("rmdir: '$_'");
  3854. rmdir($_) or mtr_warning("rmdir($_) failed: $!");
  3855. }
  3856. } else {
  3857. # Hopefully a file
  3858. mtr_verbose("unlink: '$_'");
  3859. unlink($_) or mtr_warning("unlink($_) failed: $!");
  3860. }
  3861. }
  3862. },
  3863. $dir);
  3864. }
  3865. sub clean_datadir {
  3866. mtr_verbose("Cleaning datadirs...");
  3867. if (started(all_servers()) != 0){
  3868. mtr_error("Trying to clean datadir before all servers stopped");
  3869. }
  3870. foreach my $cluster ( clusters() )
  3871. {
  3872. my $cluster_dir= "$opt_vardir/".$cluster->{name};
  3873. mtr_verbose(" - removing '$cluster_dir'");
  3874. rmtree($cluster_dir);
  3875. }
  3876. foreach my $mysqld ( mysqlds() )
  3877. {
  3878. my $mysqld_dir= dirname($mysqld->value('datadir'));
  3879. if (-d $mysqld_dir ) {
  3880. mtr_verbose(" - removing '$mysqld_dir'");
  3881. rmtree($mysqld_dir);
  3882. }
  3883. }
  3884. # Remove all files in tmp and var/tmp
  3885. clean_dir("$opt_vardir/tmp");
  3886. if ($opt_tmpdir ne "$opt_vardir/tmp"){
  3887. clean_dir($opt_tmpdir);
  3888. }
  3889. }
  3890. #
  3891. # Save datadir before it's removed
  3892. #
  3893. sub save_datadir_after_failure($$) {
  3894. my ($dir, $savedir)= @_;
  3895. mtr_report(" - saving '$dir'");
  3896. my $dir_name= basename($dir);
  3897. rename("$dir", "$savedir/$dir_name");
  3898. }
  3899. sub remove_ndbfs_from_ndbd_datadir {
  3900. my ($ndbd_datadir)= @_;
  3901. # Remove the ndb_*_fs directory from ndbd.X/ dir
  3902. foreach my $ndbfs_dir ( glob("$ndbd_datadir/ndb_*_fs") )
  3903. {
  3904. next unless -d $ndbfs_dir; # Skip if not a directory
  3905. rmtree($ndbfs_dir);
  3906. }
  3907. }
  3908. sub after_failure ($) {
  3909. my ($tinfo)= @_;
  3910. mtr_report("Saving datadirs...");
  3911. my $save_dir= "$opt_vardir/log/";
  3912. $save_dir.= $tinfo->{name};
  3913. # Add combination name if any
  3914. $save_dir.= "-$tinfo->{combination}"
  3915. if defined $tinfo->{combination};
  3916. # Save savedir path for server
  3917. $tinfo->{savedir}= $save_dir;
  3918. mkpath($save_dir) if ! -d $save_dir;
  3919. # Save the used my.cnf file
  3920. copy($path_config_file, $save_dir);
  3921. # Copy the tmp dir
  3922. copytree("$opt_vardir/tmp/", "$save_dir/tmp/");
  3923. if ( clusters() ) {
  3924. foreach my $cluster ( clusters() ) {
  3925. my $cluster_dir= "$opt_vardir/".$cluster->{name};
  3926. # Remove the fileystem of each ndbd
  3927. foreach my $ndbd ( in_cluster($cluster, ndbds()) )
  3928. {
  3929. my $ndbd_datadir= $ndbd->value("DataDir");
  3930. remove_ndbfs_from_ndbd_datadir($ndbd_datadir);
  3931. }
  3932. save_datadir_after_failure($cluster_dir, $save_dir);
  3933. }
  3934. }
  3935. else {
  3936. foreach my $mysqld ( mysqlds() ) {
  3937. my $data_dir= $mysqld->value('datadir');
  3938. save_datadir_after_failure(dirname($data_dir), $save_dir);
  3939. }
  3940. }
  3941. }
  3942. sub report_failure_and_restart ($) {
  3943. my $tinfo= shift;
  3944. if ($opt_valgrind_mysqld && ($tinfo->{'warnings'} || $tinfo->{'timeout'})) {
  3945. # In these cases we may want valgrind report from normal termination
  3946. $tinfo->{'dont_kill_server'}= 1;
  3947. }
  3948. # Shotdown properly if not to be killed (for valgrind)
  3949. stop_all_servers($tinfo->{'dont_kill_server'} ? $opt_shutdown_timeout : 0);
  3950. $tinfo->{'result'}= 'MTR_RES_FAILED';
  3951. my $test_failures= $tinfo->{'failures'} || 0;
  3952. $tinfo->{'failures'}= $test_failures + 1;
  3953. if ( $tinfo->{comment} )
  3954. {
  3955. # The test failure has been detected by mysql-test-run.pl
  3956. # when starting the servers or due to other error, the reason for
  3957. # failing the test is saved in "comment"
  3958. ;
  3959. }
  3960. if ( !defined $tinfo->{logfile} )
  3961. {
  3962. my $logfile= $path_current_testlog;
  3963. if ( defined $logfile )
  3964. {
  3965. if ( -f $logfile )
  3966. {
  3967. # Test failure was detected by test tool and its report
  3968. # about what failed has been saved to file. Save the report
  3969. # in tinfo
  3970. $tinfo->{logfile}= mtr_fromfile($logfile);
  3971. # If no newlines in the test log:
  3972. # (it will contain the CURRENT_TEST written by mtr, so is not empty)
  3973. if ($tinfo->{logfile} !~ /\n/)
  3974. {
  3975. # Show how far it got before suddenly failing
  3976. $tinfo->{comment}.= "mysqltest failed but provided no output\n";
  3977. my $log_file_name= $opt_vardir."/log/".$tinfo->{shortname}.".log";
  3978. if (-e $log_file_name) {
  3979. $tinfo->{comment}.=
  3980. "The result from queries just before the failure was:".
  3981. "\n< snip >\n".
  3982. mtr_lastlinesfromfile($log_file_name, 20)."\n";
  3983. }
  3984. }
  3985. }
  3986. else
  3987. {
  3988. # The test tool report didn't exist, display an
  3989. # error message
  3990. $tinfo->{logfile}= "Could not open test tool report '$logfile'";
  3991. }
  3992. }
  3993. }
  3994. after_failure($tinfo);
  3995. mtr_report_test($tinfo);
  3996. }
  3997. sub run_sh_script {
  3998. my ($script)= @_;
  3999. return 0 unless defined $script;
  4000. mtr_verbose("Running '$script'");
  4001. my $ret= system("/bin/sh $script") >> 8;
  4002. return $ret;
  4003. }
  4004. sub mysqld_stop {
  4005. my $mysqld= shift or die "usage: mysqld_stop(<mysqld>)";
  4006. my $args;
  4007. mtr_init_args(\$args);
  4008. mtr_add_arg($args, "--no-defaults");
  4009. mtr_add_arg($args, "--character-sets-dir=%s", $mysqld->value('character-sets-dir'));
  4010. mtr_add_arg($args, "--user=%s", $opt_user);
  4011. mtr_add_arg($args, "--password=");
  4012. mtr_add_arg($args, "--port=%d", $mysqld->value('port'));
  4013. mtr_add_arg($args, "--host=%s", $mysqld->value('#host'));
  4014. mtr_add_arg($args, "--connect_timeout=20");
  4015. mtr_add_arg($args, "--protocol=tcp");
  4016. mtr_add_arg($args, "shutdown");
  4017. My::SafeProcess->run
  4018. (
  4019. name => "mysqladmin shutdown ".$mysqld->name(),
  4020. path => $exe_mysqladmin,
  4021. args => \$args,
  4022. error => "/dev/null",
  4023. );
  4024. }
  4025. sub mysqld_arguments ($$$) {
  4026. my $args= shift;
  4027. my $mysqld= shift;
  4028. my $extra_opts= shift;
  4029. my @defaults = grep(/^--defaults-file=/, @$extra_opts);
  4030. if (@defaults > 0) {
  4031. mtr_add_arg($args, pop(@defaults))
  4032. }
  4033. else {
  4034. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  4035. }
  4036. # When mysqld is run by a root user(euid is 0), it will fail
  4037. # to start unless we specify what user to run as, see BUG#30630
  4038. my $euid= $>;
  4039. if (!IS_WINDOWS and $euid == 0 and
  4040. (grep(/^--user/, @$extra_opts)) == 0) {
  4041. mtr_add_arg($args, "--user=root");
  4042. }
  4043. if ( $opt_valgrind_mysqld )
  4044. {
  4045. if ( $mysql_version_id < 50100 )
  4046. {
  4047. mtr_add_arg($args, "--skip-bdb");
  4048. }
  4049. }
  4050. # On some old linux kernels, aio on tmpfs is not supported
  4051. # Remove this if/when Bug #58421 fixes this in the server
  4052. if ($^O eq "linux" && $opt_mem)
  4053. {
  4054. mtr_add_arg($args, "--loose-skip-innodb-use-native-aio");
  4055. }
  4056. if ( $mysql_version_id >= 50106 && !$opt_user_args)
  4057. {
  4058. # Turn on logging to file
  4059. mtr_add_arg($args, "--log-output=file");
  4060. }
  4061. # Check if "extra_opt" contains skip-log-bin
  4062. my $skip_binlog= grep(/^(--|--loose-)skip-log-bin/, @$extra_opts);
  4063. # Indicate to mysqld it will be debugged in debugger
  4064. if ( $glob_debugger )
  4065. {
  4066. mtr_add_arg($args, "--gdb");
  4067. }
  4068. my $found_skip_core= 0;
  4069. foreach my $arg ( @$extra_opts )
  4070. {
  4071. # Skip --defaults-file option since it's handled above.
  4072. next if $arg =~ /^--defaults-file/;
  4073. # Allow --skip-core-file to be set in <testname>-[master|slave].opt file
  4074. if ($arg eq "--skip-core-file")
  4075. {
  4076. $found_skip_core= 1;
  4077. }
  4078. elsif ($skip_binlog and mtr_match_prefix($arg, "--binlog-format"))
  4079. {
  4080. ; # Dont add --binlog-format when running without binlog
  4081. }
  4082. elsif ($arg eq "--loose-skip-log-bin" and
  4083. $mysqld->option("log-slave-updates"))
  4084. {
  4085. ; # Dont add --skip-log-bin when mysqld have --log-slave-updates in config
  4086. }
  4087. elsif ($arg eq "")
  4088. {
  4089. # We can get an empty argument when we set environment variables to ""
  4090. # (e.g plugin not found). Just skip it.
  4091. }
  4092. else
  4093. {
  4094. mtr_add_arg($args, "%s", $arg);
  4095. }
  4096. }
  4097. $opt_skip_core = $found_skip_core;
  4098. if ( !$found_skip_core && !$opt_user_args )
  4099. {
  4100. mtr_add_arg($args, "%s", "--core-file");
  4101. }
  4102. # Enable the debug sync facility, set default wait timeout.
  4103. # Facility stays disabled if timeout value is zero.
  4104. mtr_add_arg($args, "--loose-debug-sync-timeout=%s",
  4105. $opt_debug_sync_timeout) unless $opt_user_args;
  4106. return $args;
  4107. }
  4108. sub mysqld_start ($$) {
  4109. my $mysqld= shift;
  4110. my $extra_opts= shift;
  4111. mtr_verbose(My::Options::toStr("mysqld_start", @$extra_opts));
  4112. my $exe= find_mysqld($mysqld->value('basedir'));
  4113. my $wait_for_pid_file= 1;
  4114. mtr_error("Internal error: mysqld should never be started for embedded")
  4115. if $opt_embedded_server;
  4116. my $args;
  4117. mtr_init_args(\$args);
  4118. # implementation for strace-server
  4119. if ( $opt_strace_server )
  4120. {
  4121. strace_server_arguments($args, \$exe, $mysqld->name());
  4122. }
  4123. if ( $opt_valgrind_mysqld )
  4124. {
  4125. valgrind_arguments($args, \$exe);
  4126. }
  4127. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  4128. # Add any additional options from an in-test restart
  4129. my @all_opts= @$extra_opts;
  4130. if (exists $mysqld->{'restart_opts'}) {
  4131. push (@all_opts, @{$mysqld->{'restart_opts'}});
  4132. mtr_verbose(My::Options::toStr("mysqld_start restart",
  4133. @{$mysqld->{'restart_opts'}}));
  4134. }
  4135. mysqld_arguments($args,$mysqld,\@all_opts);
  4136. if ( $opt_debug )
  4137. {
  4138. mtr_add_arg($args, "--debug=$debug_d:t:i:A,%s/log/%s.trace",
  4139. $path_vardir_trace, $mysqld->name());
  4140. }
  4141. if (IS_WINDOWS)
  4142. {
  4143. # Trick the server to send output to stderr, with --console
  4144. mtr_add_arg($args, "--console");
  4145. }
  4146. if ( $opt_gdb || $opt_manual_gdb )
  4147. {
  4148. gdb_arguments(\$args, \$exe, $mysqld->name());
  4149. }
  4150. elsif ( $opt_ddd || $opt_manual_ddd )
  4151. {
  4152. ddd_arguments(\$args, \$exe, $mysqld->name());
  4153. }
  4154. if ( $opt_dbx || $opt_manual_dbx ) {
  4155. dbx_arguments(\$args, \$exe, $mysqld->name());
  4156. }
  4157. elsif ( $opt_debugger )
  4158. {
  4159. debugger_arguments(\$args, \$exe, $mysqld->name());
  4160. }
  4161. elsif ( $opt_manual_debug )
  4162. {
  4163. print "\nStart " .$mysqld->name()." in your debugger\n" .
  4164. "dir: $glob_mysql_test_dir\n" .
  4165. "exe: $exe\n" .
  4166. "args: " . join(" ", @$args) . "\n\n" .
  4167. "Waiting ....\n";
  4168. # Indicate the exe should not be started
  4169. $exe= undef;
  4170. }
  4171. else
  4172. {
  4173. # Default to not wait until pid file has been created
  4174. $wait_for_pid_file= 0;
  4175. }
  4176. # Remove the old pidfile if any
  4177. unlink($mysqld->value('pid-file'));
  4178. my $output= $mysqld->value('#log-error');
  4179. # Remember this log file for valgrind error report search
  4180. $mysqld_logs{$output}= 1 if $opt_valgrind;
  4181. # Remember data dir for gmon.out files if using gprof
  4182. $gprof_dirs{$mysqld->value('datadir')}= 1 if $opt_gprof;
  4183. if ( defined $exe )
  4184. {
  4185. $mysqld->{'proc'}= My::SafeProcess->new
  4186. (
  4187. name => $mysqld->name(),
  4188. path => $exe,
  4189. args => \$args,
  4190. output => $output,
  4191. error => $output,
  4192. append => 1,
  4193. verbose => $opt_verbose,
  4194. nocore => $opt_skip_core,
  4195. host => undef,
  4196. shutdown => sub { mysqld_stop($mysqld) },
  4197. envs => \@opt_mysqld_envs,
  4198. );
  4199. mtr_verbose("Started $mysqld->{proc}");
  4200. }
  4201. if ( $wait_for_pid_file &&
  4202. !sleep_until_file_created($mysqld->value('pid-file'),
  4203. $opt_start_timeout,
  4204. $mysqld->{'proc'}))
  4205. {
  4206. my $mname= $mysqld->name();
  4207. mtr_error("Failed to start mysqld $mname with command $exe");
  4208. }
  4209. # Remember options used when starting
  4210. $mysqld->{'started_opts'}= $extra_opts;
  4211. return;
  4212. }
  4213. sub stop_all_servers () {
  4214. my $shutdown_timeout = $_[0] or 0;
  4215. mtr_verbose("Stopping all servers...");
  4216. # Kill all started servers
  4217. My::SafeProcess::shutdown($shutdown_timeout,
  4218. started(all_servers()));
  4219. # Remove pidfiles
  4220. foreach my $server ( all_servers() )
  4221. {
  4222. my $pid_file= $server->if_exist('pid-file');
  4223. unlink($pid_file) if defined $pid_file;
  4224. }
  4225. # Mark servers as stopped
  4226. map($_->{proc}= undef, all_servers());
  4227. }
  4228. # Find out if server should be restarted for this test
  4229. sub server_need_restart {
  4230. my ($tinfo, $server)= @_;
  4231. if ( using_extern() )
  4232. {
  4233. mtr_verbose_restart($server, "no restart for --extern server");
  4234. return 0;
  4235. }
  4236. if ( $tinfo->{'force_restart'} ) {
  4237. mtr_verbose_restart($server, "forced in .opt file");
  4238. return 1;
  4239. }
  4240. if ( $opt_force_restart ) {
  4241. mtr_verbose_restart($server, "forced restart turned on");
  4242. return 1;
  4243. }
  4244. if ( $tinfo->{template_path} ne $current_config_name)
  4245. {
  4246. mtr_verbose_restart($server, "using different config file");
  4247. return 1;
  4248. }
  4249. if ( $tinfo->{'master_sh'} || $tinfo->{'slave_sh'} )
  4250. {
  4251. mtr_verbose_restart($server, "sh script to run");
  4252. return 1;
  4253. }
  4254. if ( ! started($server) )
  4255. {
  4256. mtr_verbose_restart($server, "not started");
  4257. return 1;
  4258. }
  4259. my $started_tinfo= $server->{'started_tinfo'};
  4260. if ( defined $started_tinfo )
  4261. {
  4262. # Check if timezone of test that server was started
  4263. # with differs from timezone of next test
  4264. if ( timezone($started_tinfo) ne timezone($tinfo) )
  4265. {
  4266. mtr_verbose_restart($server, "different timezone");
  4267. return 1;
  4268. }
  4269. }
  4270. my $is_mysqld= grep ($server eq $_, mysqlds());
  4271. if ($is_mysqld)
  4272. {
  4273. # Check that running process was started with same options
  4274. # as the current test requires
  4275. my $extra_opts= get_extra_opts($server, $tinfo);
  4276. my $started_opts= $server->{'started_opts'};
  4277. # Also, always restart if server had been restarted with additional
  4278. # options within test.
  4279. if (!My::Options::same($started_opts, $extra_opts) ||
  4280. exists $server->{'restart_opts'})
  4281. {
  4282. my $use_dynamic_option_switch= 0;
  4283. if (!$use_dynamic_option_switch)
  4284. {
  4285. mtr_verbose_restart($server, "running with different options '" .
  4286. join(" ", @{$extra_opts}) . "' != '" .
  4287. join(" ", @{$started_opts}) . "'" );
  4288. return 1;
  4289. }
  4290. mtr_verbose(My::Options::toStr("started_opts", @$started_opts));
  4291. mtr_verbose(My::Options::toStr("extra_opts", @$extra_opts));
  4292. # Get diff and check if dynamic switch is possible
  4293. my @diff_opts= My::Options::diff($started_opts, $extra_opts);
  4294. mtr_verbose(My::Options::toStr("diff_opts", @diff_opts));
  4295. my $query= My::Options::toSQL(@diff_opts);
  4296. mtr_verbose("Attempting dynamic switch '$query'");
  4297. if (run_query($tinfo, $server, $query)){
  4298. mtr_verbose("Restart: running with different options '" .
  4299. join(" ", @{$extra_opts}) . "' != '" .
  4300. join(" ", @{$started_opts}) . "'" );
  4301. return 1;
  4302. }
  4303. # Remember the dynamically set options
  4304. $server->{'started_opts'}= $extra_opts;
  4305. }
  4306. }
  4307. # Default, no restart
  4308. return 0;
  4309. }
  4310. sub servers_need_restart($) {
  4311. my ($tinfo)= @_;
  4312. return grep { server_need_restart($tinfo, $_); } all_servers();
  4313. }
  4314. #
  4315. # Return list of specific servers
  4316. # - there is no servers in an empty config
  4317. #
  4318. sub _like { return $config ? $config->like($_[0]) : (); }
  4319. sub mysqlds { return _like('mysqld.'); }
  4320. sub ndbds { return _like('cluster_config.ndbd.');}
  4321. sub ndb_mgmds { return _like('cluster_config.ndb_mgmd.'); }
  4322. sub clusters { return _like('mysql_cluster.'); }
  4323. sub all_servers { return ( mysqlds(), ndb_mgmds(), ndbds() ); }
  4324. #
  4325. # Filter a list of servers and return only those that are part
  4326. # of the specified cluster
  4327. #
  4328. sub in_cluster {
  4329. my ($cluster)= shift;
  4330. # Return only processes for a specific cluster
  4331. return grep { $_->suffix() eq $cluster->suffix() } @_;
  4332. }
  4333. #
  4334. # Filter a list of servers and return the SafeProcess
  4335. # for only those that are started or stopped
  4336. #
  4337. sub started { return grep(defined $_, map($_->{proc}, @_)); }
  4338. sub stopped { return grep(!defined $_, map($_->{proc}, @_)); }
  4339. sub envsubst {
  4340. my $string= shift;
  4341. if ( ! defined $ENV{$string} )
  4342. {
  4343. mtr_error(".opt file references '$string' which is not set");
  4344. }
  4345. return $ENV{$string};
  4346. }
  4347. sub get_extra_opts {
  4348. # No extra options if --user-args
  4349. return \@opt_extra_mysqld_opt if $opt_user_args;
  4350. my ($mysqld, $tinfo)= @_;
  4351. my $opts=
  4352. $mysqld->option("#!use-slave-opt") ?
  4353. $tinfo->{slave_opt} : $tinfo->{master_opt};
  4354. # Expand environment variables
  4355. foreach my $opt ( @$opts )
  4356. {
  4357. $opt =~ s/\$\{(\w+)\}/envsubst($1)/ge;
  4358. $opt =~ s/\$(\w+)/envsubst($1)/ge;
  4359. }
  4360. return $opts;
  4361. }
  4362. sub stop_servers($$) {
  4363. my ($tinfo, @servers)= @_;
  4364. # Remember if we restarted for this test case (count restarts)
  4365. $tinfo->{'restarted'}= 1;
  4366. if ( join('|', @servers) eq join('|', all_servers()) )
  4367. {
  4368. # All servers are going down, use some kind of order to
  4369. # avoid too many warnings in the log files
  4370. mtr_report("Restarting all servers");
  4371. # mysqld processes
  4372. My::SafeProcess::shutdown( $opt_shutdown_timeout, started(mysqlds()) );
  4373. # cluster processes
  4374. My::SafeProcess::shutdown( $opt_shutdown_timeout,
  4375. started(ndbds(), ndb_mgmds()) );
  4376. }
  4377. else
  4378. {
  4379. mtr_report("Restarting ", started(@servers));
  4380. # Stop only some servers
  4381. My::SafeProcess::shutdown( $opt_shutdown_timeout,
  4382. started(@servers) );
  4383. }
  4384. foreach my $server (@servers)
  4385. {
  4386. # Mark server as stopped
  4387. $server->{proc}= undef;
  4388. # Forget history
  4389. delete $server->{'started_tinfo'};
  4390. delete $server->{'started_opts'};
  4391. delete $server->{'started_cnf'};
  4392. }
  4393. }
  4394. #
  4395. # start_servers
  4396. #
  4397. # Start servers not already started
  4398. #
  4399. # RETURN
  4400. # 0 OK
  4401. # 1 Start failed
  4402. #
  4403. sub start_servers($) {
  4404. my ($tinfo)= @_;
  4405. # Make sure the safe_process also exits from now on
  4406. # Could not be done before, as we don't want this for the bootstrap
  4407. if ($opt_start_exit) {
  4408. My::SafeProcess->start_exit();
  4409. }
  4410. # Start clusters
  4411. foreach my $cluster ( clusters() )
  4412. {
  4413. ndbcluster_start($cluster);
  4414. }
  4415. # Start mysqlds
  4416. foreach my $mysqld ( mysqlds() )
  4417. {
  4418. if ( $mysqld->{proc} )
  4419. {
  4420. # Already started
  4421. # Write start of testcase to log file
  4422. mark_log($mysqld->value('#log-error'), $tinfo);
  4423. next;
  4424. }
  4425. my $datadir= $mysqld->value('datadir');
  4426. if ($opt_start_dirty)
  4427. {
  4428. # Don't delete anything if starting dirty
  4429. ;
  4430. }
  4431. else
  4432. {
  4433. my @options= ('log-bin', 'relay-log');
  4434. foreach my $option_name ( @options ) {
  4435. next unless $mysqld->option($option_name);
  4436. my $file_name= $mysqld->value($option_name);
  4437. next unless
  4438. defined $file_name and
  4439. -e $file_name;
  4440. mtr_debug(" -removing '$file_name'");
  4441. unlink($file_name) or die ("unable to remove file '$file_name'");
  4442. }
  4443. if (-d $datadir ) {
  4444. mtr_verbose(" - removing '$datadir'");
  4445. rmtree($datadir);
  4446. }
  4447. }
  4448. my $mysqld_basedir= $mysqld->value('basedir');
  4449. if ( $basedir eq $mysqld_basedir )
  4450. {
  4451. if (! $opt_start_dirty) # If dirty, keep possibly grown system db
  4452. {
  4453. # Copy datadir from installed system db
  4454. for my $path ( "$opt_vardir", "$opt_vardir/..") {
  4455. my $install_db= "$path/install.db";
  4456. copytree($install_db, $datadir)
  4457. if -d $install_db;
  4458. }
  4459. mtr_error("Failed to copy system db to '$datadir'")
  4460. unless -d $datadir;
  4461. }
  4462. }
  4463. else
  4464. {
  4465. mysql_install_db($mysqld); # For versional testing
  4466. mtr_error("Failed to install system db to '$datadir'")
  4467. unless -d $datadir;
  4468. }
  4469. # Create the servers tmpdir
  4470. my $tmpdir= $mysqld->value('tmpdir');
  4471. mkpath($tmpdir) unless -d $tmpdir;
  4472. # Write start of testcase to log file
  4473. mark_log($mysqld->value('#log-error'), $tinfo);
  4474. # Run <tname>-master.sh
  4475. if ($mysqld->option('#!run-master-sh') and
  4476. run_sh_script($tinfo->{master_sh}) )
  4477. {
  4478. $tinfo->{'comment'}= "Failed to execute '$tinfo->{master_sh}'";
  4479. return 1;
  4480. }
  4481. # Run <tname>-slave.sh
  4482. if ($mysqld->option('#!run-slave-sh') and
  4483. run_sh_script($tinfo->{slave_sh}))
  4484. {
  4485. $tinfo->{'comment'}= "Failed to execute '$tinfo->{slave_sh}'";
  4486. return 1;
  4487. }
  4488. if (!$opt_embedded_server)
  4489. {
  4490. my $extra_opts= get_extra_opts($mysqld, $tinfo);
  4491. mysqld_start($mysqld,$extra_opts);
  4492. # Save this test case information, so next can examine it
  4493. $mysqld->{'started_tinfo'}= $tinfo;
  4494. }
  4495. }
  4496. # Wait for clusters to start
  4497. foreach my $cluster ( clusters() )
  4498. {
  4499. if (ndbcluster_wait_started($cluster, ""))
  4500. {
  4501. # failed to start
  4502. $tinfo->{'comment'}= "Start of '".$cluster->name()."' cluster failed";
  4503. return 1;
  4504. }
  4505. }
  4506. # Wait for mysqlds to start
  4507. foreach my $mysqld ( mysqlds() )
  4508. {
  4509. next if !started($mysqld);
  4510. if (sleep_until_file_created($mysqld->value('pid-file'),
  4511. $opt_start_timeout,
  4512. $mysqld->{'proc'}) == 0) {
  4513. $tinfo->{comment}=
  4514. "Failed to start ".$mysqld->name();
  4515. my $logfile= $mysqld->value('#log-error');
  4516. if ( defined $logfile and -f $logfile )
  4517. {
  4518. my @srv_lines= extract_server_log($logfile, $tinfo->{name});
  4519. $tinfo->{logfile}= "Server log is:\n" . join ("", @srv_lines);
  4520. }
  4521. else
  4522. {
  4523. $tinfo->{logfile}= "Could not open server logfile: '$logfile'";
  4524. }
  4525. return 1;
  4526. }
  4527. }
  4528. return 0;
  4529. }
  4530. #
  4531. # Run include/check-testcase.test
  4532. # Before a testcase, run in record mode and save result file to var/tmp
  4533. # After testcase, run and compare with the recorded file, they should be equal!
  4534. #
  4535. # RETURN VALUE
  4536. # The newly started process
  4537. #
  4538. sub start_check_testcase ($$$) {
  4539. my $tinfo= shift;
  4540. my $mode= shift;
  4541. my $mysqld= shift;
  4542. my $name= "check-".$mysqld->name();
  4543. # Replace dots in name with underscore to avoid that mysqltest
  4544. # misinterpret's what the filename extension is :(
  4545. $name=~ s/\./_/g;
  4546. my $args;
  4547. mtr_init_args(\$args);
  4548. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  4549. mtr_add_arg($args, "--defaults-group-suffix=%s", $mysqld->after('mysqld'));
  4550. mtr_add_arg($args, "--result-file=%s", "$opt_vardir/tmp/$name.result");
  4551. mtr_add_arg($args, "--test-file=%s", "include/check-testcase.test");
  4552. mtr_add_arg($args, "--verbose");
  4553. if ( $mode eq "before" )
  4554. {
  4555. mtr_add_arg($args, "--record");
  4556. }
  4557. my $errfile= "$opt_vardir/tmp/$name.err";
  4558. my $proc= My::SafeProcess->new
  4559. (
  4560. name => $name,
  4561. path => $exe_mysqltest,
  4562. error => $errfile,
  4563. output => $errfile,
  4564. args => \$args,
  4565. user_data => $errfile,
  4566. verbose => $opt_verbose,
  4567. );
  4568. mtr_report("Started $proc");
  4569. return $proc;
  4570. }
  4571. sub run_mysqltest ($) {
  4572. my $proc= start_mysqltest(@_);
  4573. $proc->wait();
  4574. }
  4575. sub start_mysqltest ($) {
  4576. my ($tinfo)= @_;
  4577. my $exe= $exe_mysqltest;
  4578. my $args;
  4579. mark_time_used('admin');
  4580. mtr_init_args(\$args);
  4581. if ( $opt_strace_client )
  4582. {
  4583. $exe= "strace";
  4584. mtr_add_arg($args, "-o");
  4585. mtr_add_arg($args, "%s/log/mysqltest.strace", $opt_vardir);
  4586. mtr_add_arg($args, "$exe_mysqltest");
  4587. }
  4588. mtr_add_arg($args, "--defaults-file=%s", $path_config_file);
  4589. mtr_add_arg($args, "--silent");
  4590. mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir);
  4591. mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir);
  4592. mtr_add_arg($args, "--logdir=%s/log", $opt_vardir);
  4593. if ($auth_plugin)
  4594. {
  4595. mtr_add_arg($args, "--plugin_dir=%s", dirname($auth_plugin));
  4596. }
  4597. # Log line number and time for each line in .test file
  4598. mtr_add_arg($args, "--mark-progress")
  4599. if $opt_mark_progress;
  4600. mtr_add_arg($args, "--database=test");
  4601. if ( $opt_ps_protocol )
  4602. {
  4603. mtr_add_arg($args, "--ps-protocol");
  4604. }
  4605. if ( $opt_sp_protocol )
  4606. {
  4607. mtr_add_arg($args, "--sp-protocol");
  4608. }
  4609. if ( $opt_view_protocol )
  4610. {
  4611. mtr_add_arg($args, "--view-protocol");
  4612. }
  4613. if ( $opt_cursor_protocol )
  4614. {
  4615. mtr_add_arg($args, "--cursor-protocol");
  4616. }
  4617. mtr_add_arg($args, "--timer-file=%s/log/timer", $opt_vardir);
  4618. if ( $opt_compress )
  4619. {
  4620. mtr_add_arg($args, "--compress");
  4621. }
  4622. if ( $opt_sleep )
  4623. {
  4624. mtr_add_arg($args, "--sleep=%d", $opt_sleep);
  4625. }
  4626. if ( $opt_ssl )
  4627. {
  4628. # Turn on SSL for _all_ test cases if option --ssl was used
  4629. mtr_add_arg($args, "--ssl");
  4630. }
  4631. if ( $opt_max_connections ) {
  4632. mtr_add_arg($args, "--max-connections=%d", $opt_max_connections);
  4633. }
  4634. if ( $opt_embedded_server )
  4635. {
  4636. # Get the args needed for the embedded server
  4637. # and append them to args prefixed
  4638. # with --sever-arg=
  4639. my $mysqld= $config->group('embedded')
  4640. or mtr_error("Could not get [embedded] section");
  4641. my $mysqld_args;
  4642. mtr_init_args(\$mysqld_args);
  4643. my $extra_opts= get_extra_opts($mysqld, $tinfo);
  4644. mysqld_arguments($mysqld_args, $mysqld, $extra_opts);
  4645. mtr_add_arg($args, "--server-arg=%s", $_) for @$mysqld_args;
  4646. if (IS_WINDOWS)
  4647. {
  4648. # Trick the server to send output to stderr, with --console
  4649. mtr_add_arg($args, "--server-arg=--console");
  4650. }
  4651. }
  4652. # ----------------------------------------------------------------------
  4653. # export MYSQL_TEST variable containing <path>/mysqltest <args>
  4654. # ----------------------------------------------------------------------
  4655. $ENV{'MYSQL_TEST'}= mtr_args2str($exe_mysqltest, @$args);
  4656. # ----------------------------------------------------------------------
  4657. # Add arguments that should not go into the MYSQL_TEST env var
  4658. # ----------------------------------------------------------------------
  4659. if ( $opt_valgrind_mysqltest )
  4660. {
  4661. # Prefix the Valgrind options to the argument list.
  4662. # We do this here, since we do not want to Valgrind the nested invocations
  4663. # of mysqltest; that would mess up the stderr output causing test failure.
  4664. my @args_saved = @$args;
  4665. mtr_init_args(\$args);
  4666. valgrind_arguments($args, \$exe);
  4667. mtr_add_arg($args, "%s", $_) for @args_saved;
  4668. }
  4669. mtr_add_arg($args, "--test-file=%s", $tinfo->{'path'});
  4670. # Number of lines of resut to include in failure report
  4671. mtr_add_arg($args, "--tail-lines=20");
  4672. if ( defined $tinfo->{'result_file'} ) {
  4673. mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'});
  4674. }
  4675. client_debug_arg($args, "mysqltest");
  4676. if ( $opt_record )
  4677. {
  4678. mtr_add_arg($args, "--record");
  4679. # When recording to a non existing result file
  4680. # the name of that file is in "record_file"
  4681. if ( defined $tinfo->{'record_file'} ) {
  4682. mtr_add_arg($args, "--result-file=%s", $tinfo->{record_file});
  4683. }
  4684. }
  4685. if ( $opt_client_gdb )
  4686. {
  4687. gdb_arguments(\$args, \$exe, "client");
  4688. }
  4689. elsif ( $opt_client_ddd )
  4690. {
  4691. ddd_arguments(\$args, \$exe, "client");
  4692. }
  4693. if ( $opt_client_dbx ) {
  4694. dbx_arguments(\$args, \$exe, "client");
  4695. }
  4696. elsif ( $opt_client_debugger )
  4697. {
  4698. debugger_arguments(\$args, \$exe, "client");
  4699. }
  4700. my $proc= My::SafeProcess->new
  4701. (
  4702. name => "mysqltest",
  4703. path => $exe,
  4704. args => \$args,
  4705. append => 1,
  4706. error => $path_current_testlog,
  4707. verbose => $opt_verbose,
  4708. );
  4709. mtr_verbose("Started $proc");
  4710. return $proc;
  4711. }
  4712. #
  4713. # Modify the exe and args so that program is run in gdb in xterm
  4714. #
  4715. sub gdb_arguments {
  4716. my $args= shift;
  4717. my $exe= shift;
  4718. my $type= shift;
  4719. my $input= shift;
  4720. my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
  4721. # Remove the old gdbinit file
  4722. unlink($gdb_init_file);
  4723. # Put $args into a single string
  4724. my $str= join(" ", @$$args);
  4725. my $runline= $input ? "run $str < $input" : "run $str";
  4726. # write init file for mysqld or client
  4727. mtr_tofile($gdb_init_file,
  4728. "break main\n" .
  4729. $runline);
  4730. if ( $opt_manual_gdb )
  4731. {
  4732. print "\nTo start gdb for $type, type in another window:\n";
  4733. print "gdb -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
  4734. # Indicate the exe should not be started
  4735. $$exe= undef;
  4736. return;
  4737. }
  4738. $$args= [];
  4739. mtr_add_arg($$args, "-title");
  4740. mtr_add_arg($$args, "$type");
  4741. mtr_add_arg($$args, "-e");
  4742. if ( $exe_libtool )
  4743. {
  4744. mtr_add_arg($$args, $exe_libtool);
  4745. mtr_add_arg($$args, "--mode=execute");
  4746. }
  4747. mtr_add_arg($$args, "gdb");
  4748. mtr_add_arg($$args, "-x");
  4749. mtr_add_arg($$args, "$gdb_init_file");
  4750. mtr_add_arg($$args, "$$exe");
  4751. $$exe= "xterm";
  4752. }
  4753. #
  4754. # Modify the exe and args so that program is run in ddd
  4755. #
  4756. sub ddd_arguments {
  4757. my $args= shift;
  4758. my $exe= shift;
  4759. my $type= shift;
  4760. my $input= shift;
  4761. my $gdb_init_file= "$opt_vardir/tmp/gdbinit.$type";
  4762. # Remove the old gdbinit file
  4763. unlink($gdb_init_file);
  4764. # Put $args into a single string
  4765. my $str= join(" ", @$$args);
  4766. my $runline= $input ? "run $str < $input" : "run $str";
  4767. # write init file for mysqld or client
  4768. mtr_tofile($gdb_init_file,
  4769. "file $$exe\n" .
  4770. "break main\n" .
  4771. $runline);
  4772. if ( $opt_manual_ddd )
  4773. {
  4774. print "\nTo start ddd for $type, type in another window:\n";
  4775. print "ddd -cd $glob_mysql_test_dir -x $gdb_init_file $$exe\n";
  4776. # Indicate the exe should not be started
  4777. $$exe= undef;
  4778. return;
  4779. }
  4780. my $save_exe= $$exe;
  4781. $$args= [];
  4782. if ( $exe_libtool )
  4783. {
  4784. $$exe= $exe_libtool;
  4785. mtr_add_arg($$args, "--mode=execute");
  4786. mtr_add_arg($$args, "ddd");
  4787. }
  4788. else
  4789. {
  4790. $$exe= "ddd";
  4791. }
  4792. mtr_add_arg($$args, "--command=$gdb_init_file");
  4793. mtr_add_arg($$args, "$save_exe");
  4794. }
  4795. #
  4796. # Modify the exe and args so that program is run in dbx in xterm
  4797. #
  4798. sub dbx_arguments {
  4799. my $args= shift;
  4800. my $exe= shift;
  4801. my $type= shift;
  4802. my $input= shift;
  4803. # Put $args into a single string
  4804. my $str= join " ", @$$args;
  4805. my $runline= $input ? "run $str < $input" : "run $str";
  4806. if ( $opt_manual_dbx ) {
  4807. print "\nTo start dbx for $type, type in another window:\n";
  4808. print "cd $glob_mysql_test_dir; dbx -c \"stop in main; " .
  4809. "$runline\" $$exe\n";
  4810. # Indicate the exe should not be started
  4811. $$exe= undef;
  4812. return;
  4813. }
  4814. $$args= [];
  4815. mtr_add_arg($$args, "-title");
  4816. mtr_add_arg($$args, "$type");
  4817. mtr_add_arg($$args, "-e");
  4818. if ( $exe_libtool ) {
  4819. mtr_add_arg($$args, $exe_libtool);
  4820. mtr_add_arg($$args, "--mode=execute");
  4821. }
  4822. mtr_add_arg($$args, "dbx");
  4823. mtr_add_arg($$args, "-c");
  4824. mtr_add_arg($$args, "stop in main; $runline");
  4825. mtr_add_arg($$args, "$$exe");
  4826. $$exe= "xterm";
  4827. }
  4828. #
  4829. # Modify the exe and args so that program is run in the selected debugger
  4830. #
  4831. sub debugger_arguments {
  4832. my $args= shift;
  4833. my $exe= shift;
  4834. my $debugger= $opt_debugger || $opt_client_debugger;
  4835. if ( $debugger =~ /vcexpress|vc|devenv/ )
  4836. {
  4837. # vc[express] /debugexe exe arg1 .. argn
  4838. # Add name of the exe and /debugexe before args
  4839. unshift(@$$args, "$$exe");
  4840. unshift(@$$args, "/debugexe");
  4841. # Set exe to debuggername
  4842. $$exe= $debugger;
  4843. }
  4844. elsif ( $debugger =~ /windbg/ )
  4845. {
  4846. # windbg exe arg1 .. argn
  4847. # Add name of the exe before args
  4848. unshift(@$$args, "$$exe");
  4849. # Set exe to debuggername
  4850. $$exe= $debugger;
  4851. }
  4852. else
  4853. {
  4854. mtr_error("Unknown argument \"$debugger\" passed to --debugger");
  4855. }
  4856. }
  4857. #
  4858. # Modify the exe and args so that program is run in strace
  4859. #
  4860. sub strace_server_arguments {
  4861. my $args= shift;
  4862. my $exe= shift;
  4863. my $type= shift;
  4864. mtr_add_arg($args, "-o");
  4865. mtr_add_arg($args, "%s/log/%s.strace", $opt_vardir, $type);
  4866. mtr_add_arg($args, $$exe);
  4867. $$exe= "strace";
  4868. }
  4869. #
  4870. # Modify the exe and args so that program is run in valgrind
  4871. #
  4872. sub valgrind_arguments {
  4873. my $args= shift;
  4874. my $exe= shift;
  4875. if ( $opt_callgrind)
  4876. {
  4877. mtr_add_arg($args, "--tool=callgrind");
  4878. mtr_add_arg($args, "--base=$opt_vardir/log");
  4879. }
  4880. else
  4881. {
  4882. mtr_add_arg($args, "--tool=memcheck"); # From >= 2.1.2 needs this option
  4883. mtr_add_arg($args, "--leak-check=yes");
  4884. mtr_add_arg($args, "--num-callers=16");
  4885. mtr_add_arg($args, "--suppressions=%s/valgrind.supp", $glob_mysql_test_dir)
  4886. if -f "$glob_mysql_test_dir/valgrind.supp";
  4887. }
  4888. # Add valgrind options, can be overriden by user
  4889. mtr_add_arg($args, '%s', $_) for (@valgrind_args);
  4890. mtr_add_arg($args, $$exe);
  4891. $$exe= $opt_valgrind_path || "valgrind";
  4892. if ($exe_libtool)
  4893. {
  4894. # Add "libtool --mode-execute" before the test to execute
  4895. # if running in valgrind(to avoid valgrinding bash)
  4896. unshift(@$args, "--mode=execute", $$exe);
  4897. $$exe= $exe_libtool;
  4898. }
  4899. }
  4900. #
  4901. # Search server logs for valgrind reports printed at mysqld termination
  4902. #
  4903. sub valgrind_exit_reports() {
  4904. my $found_err= 0;
  4905. foreach my $log_file (keys %mysqld_logs)
  4906. {
  4907. my @culprits= ();
  4908. my $valgrind_rep= "";
  4909. my $found_report= 0;
  4910. my $err_in_report= 0;
  4911. my $LOGF = IO::File->new($log_file)
  4912. or mtr_error("Could not open file '$log_file' for reading: $!");
  4913. while ( my $line = <$LOGF> )
  4914. {
  4915. if ($line =~ /^CURRENT_TEST: (.+)$/)
  4916. {
  4917. my $testname= $1;
  4918. # If we have a report, report it if needed and start new list of tests
  4919. if ($found_report)
  4920. {
  4921. if ($err_in_report)
  4922. {
  4923. mtr_print ("Valgrind report from $log_file after tests:\n",
  4924. @culprits);
  4925. mtr_print_line();
  4926. print ("$valgrind_rep\n");
  4927. $found_err= 1;
  4928. $err_in_report= 0;
  4929. }
  4930. # Make ready to collect new report
  4931. @culprits= ();
  4932. $found_report= 0;
  4933. $valgrind_rep= "";
  4934. }
  4935. push (@culprits, $testname);
  4936. next;
  4937. }
  4938. # This line marks the start of a valgrind report
  4939. $found_report= 1 if $line =~ /^==\d+== .* SUMMARY:/;
  4940. if ($found_report) {
  4941. $line=~ s/^==\d+== //;
  4942. $valgrind_rep .= $line;
  4943. $err_in_report= 1 if $line =~ /ERROR SUMMARY: [1-9]/;
  4944. $err_in_report= 1 if $line =~ /definitely lost: [1-9]/;
  4945. $err_in_report= 1 if $line =~ /possibly lost: [1-9]/;
  4946. }
  4947. }
  4948. $LOGF= undef;
  4949. if ($err_in_report) {
  4950. mtr_print ("Valgrind report from $log_file after tests:\n", @culprits);
  4951. mtr_print_line();
  4952. print ("$valgrind_rep\n");
  4953. $found_err= 1;
  4954. }
  4955. }
  4956. return $found_err;
  4957. }
  4958. sub run_ctest() {
  4959. my $olddir= getcwd();
  4960. chdir ($bindir) or die ("Could not chdir to $bindir");
  4961. my $tinfo;
  4962. my $no_ctest= (IS_WINDOWS) ? 256 : -1;
  4963. my $ctest_vs= "";
  4964. # Just ignore if not configured/built to run ctest
  4965. if (! -f "CTestTestfile.cmake") {
  4966. chdir($olddir);
  4967. return;
  4968. }
  4969. # Add vs-config option if needed
  4970. $ctest_vs= "-C $opt_vs_config" if $opt_vs_config;
  4971. # Also silently ignore if we don't have ctest and didn't insist
  4972. # Special override: also ignore in Pushbuild, some platforms may not have it
  4973. # Now, run ctest and collect output
  4974. my $ctest_out= `ctest $ctest_vs 2>&1`;
  4975. if ($? == $no_ctest && $opt_ctest == -1 && ! defined $ENV{PB2WORKDIR}) {
  4976. chdir($olddir);
  4977. return;
  4978. }
  4979. # Create minimalistic "test" for the reporting
  4980. $tinfo = My::Test->new
  4981. (
  4982. name => 'unit_tests',
  4983. );
  4984. # Set dummy worker id to align report with normal tests
  4985. $tinfo->{worker} = 0 if $opt_parallel > 1;
  4986. my $ctfail= 0; # Did ctest fail?
  4987. if ($?) {
  4988. $ctfail= 1;
  4989. $tinfo->{result}= 'MTR_RES_FAILED';
  4990. $tinfo->{comment}= "ctest failed with exit code $?, see result below";
  4991. $ctest_out= "" unless $ctest_out;
  4992. }
  4993. my $ctfile= "$opt_vardir/ctest.log";
  4994. my $ctres= 0; # Did ctest produce report summary?
  4995. open (CTEST, " > $ctfile") or die ("Could not open output file $ctfile");
  4996. # Put ctest output in log file, while analyzing results
  4997. for (split ('\n', $ctest_out)) {
  4998. print CTEST "$_\n";
  4999. if (/tests passed/) {
  5000. $ctres= 1;
  5001. $ctest_report .= "\nUnit tests: $_\n";
  5002. }
  5003. if ( /FAILED/ or /\(Failed\)/ ) {
  5004. $ctfail= 1;
  5005. $ctest_report .= " $_\n";
  5006. }
  5007. }
  5008. close CTEST;
  5009. # Set needed 'attributes' for test reporting
  5010. $tinfo->{comment}.= "\nctest did not pruduce report summary" if ! $ctres;
  5011. $tinfo->{result}= ($ctres && !$ctfail)
  5012. ? 'MTR_RES_PASSED' : 'MTR_RES_FAILED';
  5013. $ctest_report .= "Report from unit tests in $ctfile";
  5014. $tinfo->{failures}= ($tinfo->{result} eq 'MTR_RES_FAILED');
  5015. mark_time_used('test');
  5016. mtr_report_test($tinfo);
  5017. chdir($olddir);
  5018. return $tinfo;
  5019. }
  5020. #
  5021. # Usage
  5022. #
  5023. sub usage ($) {
  5024. my ($message)= @_;
  5025. if ( $message )
  5026. {
  5027. print STDERR "$message\n";
  5028. }
  5029. print <<HERE;
  5030. $0 [ OPTIONS ] [ TESTCASE ]
  5031. Options to control what engine/variation to run
  5032. embedded-server Use the embedded server, i.e. no mysqld daemons
  5033. ps-protocol Use the binary protocol between client and server
  5034. cursor-protocol Use the cursor protocol between client and server
  5035. (implies --ps-protocol)
  5036. view-protocol Create a view to execute all non updating queries
  5037. sp-protocol Create a stored procedure to execute all queries
  5038. compress Use the compressed protocol between client and server
  5039. ssl Use ssl protocol between client and server
  5040. skip-ssl Dont start server with support for ssl connections
  5041. vs-config Visual Studio configuration used to create executables
  5042. (default: MTR_VS_CONFIG environment variable)
  5043. defaults-file=<config template> Use fixed config template for all
  5044. tests
  5045. defaults-extra-file=<config template> Extra config template to add to
  5046. all generated configs
  5047. combination=<opt> Use at least twice to run tests with specified
  5048. options to mysqld
  5049. skip-combinations Ignore combination file (or options)
  5050. Options to control directories to use
  5051. tmpdir=DIR The directory where temporary files are stored
  5052. (default: ./var/tmp).
  5053. vardir=DIR The directory where files generated from the test run
  5054. is stored (default: ./var). Specifying a ramdisk or
  5055. tmpfs will speed up tests.
  5056. mem Run testsuite in "memory" using tmpfs or ramdisk
  5057. Attempts to find a suitable location
  5058. using a builtin list of standard locations
  5059. for tmpfs (/dev/shm)
  5060. The option can also be set using environment
  5061. variable MTR_MEM=[DIR]
  5062. clean-vardir Clean vardir if tests were successful and if
  5063. running in "memory". Otherwise this option is ignored
  5064. client-bindir=PATH Path to the directory where client binaries are located
  5065. client-libdir=PATH Path to the directory where client libraries are located
  5066. Options to control what test suites or cases to run
  5067. force Continue to run the suite after failure
  5068. with-ndbcluster-only Run only tests that include "ndb" in the filename
  5069. skip-ndb[cluster] Skip all tests that need cluster. Default.
  5070. include-ndb[cluster] Enable all tests that need cluster
  5071. do-test=PREFIX or REGEX
  5072. Run test cases which name are prefixed with PREFIX
  5073. or fulfills REGEX
  5074. skip-test=PREFIX or REGEX
  5075. Skip test cases which name are prefixed with PREFIX
  5076. or fulfills REGEX
  5077. start-from=PREFIX Run test cases starting test prefixed with PREFIX where
  5078. prefix may be suite.testname or just testname
  5079. suite[s]=NAME1,..,NAMEN
  5080. Collect tests in suites from the comma separated
  5081. list of suite names.
  5082. The default is: "$DEFAULT_SUITES"
  5083. skip-rpl Skip the replication test cases.
  5084. big-test Also run tests marked as "big"
  5085. enable-disabled Run also tests marked as disabled
  5086. print-testcases Don't run the tests but print details about all the
  5087. selected tests, in the order they would be run.
  5088. skip-test-list=FILE Skip the tests listed in FILE. Each line in the file
  5089. is an entry and should be formatted as:
  5090. <TESTNAME> : <COMMENT>
  5091. Options that specify ports
  5092. mtr-port-base=# Base for port numbers, ports from this number to
  5093. port-base=# number+9 are reserved. Should be divisible by 10;
  5094. if not it will be rounded down. May be set with
  5095. environment variable MTR_PORT_BASE. If this value is
  5096. set and is not "auto", it overrides build-thread.
  5097. mtr-build-thread=# Specify unique number to calculate port number(s) from.
  5098. build-thread=# Can be set in environment variable MTR_BUILD_THREAD.
  5099. Set MTR_BUILD_THREAD="auto" to automatically aquire
  5100. a build thread id that is unique to current host
  5101. Options for test case authoring
  5102. record TESTNAME (Re)genereate the result file for TESTNAME
  5103. check-testcases Check testcases for sideeffects
  5104. mark-progress Log line number and elapsed time to <testname>.progress
  5105. Options that pass on options (these may be repeated)
  5106. mysqld=ARGS Specify additional arguments to "mysqld"
  5107. mysqld-env=VAR=VAL Specify additional environment settings for "mysqld"
  5108. Options to run test on running server
  5109. extern option=value Run only the tests against an already started server
  5110. the options to use for connection to the extern server
  5111. must be specified using name-value pair notation
  5112. For example:
  5113. ./$0 --extern socket=/tmp/mysqld.sock
  5114. Options for debugging the product
  5115. boot-dbx Start bootstrap server in dbx
  5116. boot-ddd Start bootstrap server in ddd
  5117. boot-gdb Start bootstrap server in gdb
  5118. client-dbx Start mysqltest client in dbx
  5119. client-ddd Start mysqltest client in ddd
  5120. client-debugger=NAME Start mysqltest in the selected debugger
  5121. client-gdb Start mysqltest client in gdb
  5122. dbx Start the mysqld(s) in dbx
  5123. ddd Start the mysqld(s) in ddd
  5124. debug Dump trace output for all servers and client programs
  5125. debug-common Same as debug, but sets 'd' debug flags to
  5126. "query,info,error,enter,exit"
  5127. debug-server Use debug version of server, but without turning on
  5128. tracing
  5129. debugger=NAME Start mysqld in the selected debugger
  5130. gdb Start the mysqld(s) in gdb
  5131. manual-debug Let user manually start mysqld in debugger, before
  5132. running test(s)
  5133. manual-gdb Let user manually start mysqld in gdb, before running
  5134. test(s)
  5135. manual-ddd Let user manually start mysqld in ddd, before running
  5136. test(s)
  5137. manual-dbx Let user manually start mysqld in dbx, before running
  5138. test(s)
  5139. strace-client Create strace output for mysqltest client,
  5140. strace-server Create strace output for mysqltest server,
  5141. max-save-core Limit the number of core files saved (to avoid filling
  5142. up disks for heavily crashing server). Defaults to
  5143. $opt_max_save_core, set to 0 for no limit. Set
  5144. it's default with MTR_MAX_SAVE_CORE
  5145. max-save-datadir Limit the number of datadir saved (to avoid filling
  5146. up disks for heavily crashing server). Defaults to
  5147. $opt_max_save_datadir, set to 0 for no limit. Set
  5148. it's default with MTR_MAX_SAVE_DATDIR
  5149. max-test-fail Limit the number of test failurs before aborting
  5150. the current test run. Defaults to
  5151. $opt_max_test_fail, set to 0 for no limit. Set
  5152. it's default with MTR_MAX_TEST_FAIL
  5153. Options for valgrind
  5154. valgrind Run the "mysqltest" and "mysqld" executables using
  5155. valgrind with default options
  5156. valgrind-all Synonym for --valgrind
  5157. valgrind-mysqltest Run the "mysqltest" and "mysql_client_test" executable
  5158. with valgrind
  5159. valgrind-mysqld Run the "mysqld" executable with valgrind
  5160. valgrind-options=ARGS Deprecated, use --valgrind-option
  5161. valgrind-option=ARGS Option to give valgrind, replaces default option(s),
  5162. can be specified more then once
  5163. valgrind-path=<EXE> Path to the valgrind executable
  5164. callgrind Instruct valgrind to use callgrind
  5165. Misc options
  5166. user=USER User for connecting to mysqld(default: $opt_user)
  5167. comment=STR Write STR to the output
  5168. timer Show test case execution time.
  5169. verbose More verbose output(use multiple times for even more)
  5170. verbose-restart Write when and why servers are restarted
  5171. start Only initialize and start the servers, using the
  5172. startup settings for the first specified test case
  5173. Example:
  5174. $0 --start alias &
  5175. start-and-exit Same as --start, but mysql-test-run terminates and
  5176. leaves just the server running
  5177. start-dirty Only start the servers (without initialization) for
  5178. the first specified test case
  5179. user-args In combination with start* and no test name, drops
  5180. arguments to mysqld except those speficied with
  5181. --mysqld (if any)
  5182. wait-all If --start or --start-dirty option is used, wait for all
  5183. servers to exit before finishing the process
  5184. fast Run as fast as possible, dont't wait for servers
  5185. to shutdown etc.
  5186. force-restart Always restart servers between tests
  5187. parallel=N Run tests in N parallel threads (default=1)
  5188. Use parallel=auto for auto-setting of N
  5189. repeat=N Run each test N number of times
  5190. retry=N Retry tests that fail N times, limit number of failures
  5191. to $opt_retry_failure
  5192. retry-failure=N Limit number of retries for a failed test
  5193. reorder Reorder tests to get fewer server restarts
  5194. help Get this help text
  5195. testcase-timeout=MINUTES Max test case run time (default $opt_testcase_timeout)
  5196. suite-timeout=MINUTES Max test suite run time (default $opt_suite_timeout)
  5197. shutdown-timeout=SECONDS Max number of seconds to wait for server shutdown
  5198. before killing servers (default $opt_shutdown_timeout)
  5199. warnings Scan the log files for warnings. Use --nowarnings
  5200. to turn off.
  5201. sleep=SECONDS Passed to mysqltest, will be used as fixed sleep time
  5202. debug-sync-timeout=NUM Set default timeout for WAIT_FOR debug sync
  5203. actions. Disable facility with NUM=0.
  5204. gcov Collect coverage information after the test.
  5205. The result is a gcov file per source and header file.
  5206. gprof Collect profiling information using gprof.
  5207. experimental=<file> Refer to list of tests considered experimental;
  5208. failures will be marked exp-fail instead of fail.
  5209. report-features First run a "test" that reports mysql features
  5210. timestamp Print timestamp before each test report line
  5211. timediff With --timestamp, also print time passed since
  5212. *previous* test started
  5213. max-connections=N Max number of open connection to server in mysqltest
  5214. default-myisam Set default storage engine to MyISAM for non-innodb
  5215. tests. This is needed after switching default storage
  5216. engine to InnoDB.
  5217. report-times Report how much time has been spent on different
  5218. phases of test execution.
  5219. nounit-tests Do not run unit tests. Normally run if configured
  5220. and if not running named tests/suites
  5221. unit-tests Run unit tests even if they would otherwise not be run
  5222. stress=ARGS Run stress test, providing options to
  5223. mysql-stress-test.pl. Options are separated by comma.
  5224. Some options that control enabling a feature for normal test runs,
  5225. can be turned off by prepending 'no' to the option, e.g. --notimer.
  5226. This applies to reorder, timer, check-testcases and warnings.
  5227. HERE
  5228. exit(1);
  5229. }
  5230. sub list_options ($) {
  5231. my $hash= shift;
  5232. for (keys %$hash) {
  5233. s/([:=].*|[+!])$//;
  5234. s/\|/\n--/g;
  5235. print "--$_\n" unless /list-options/;
  5236. }
  5237. exit(1);
  5238. }