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.

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