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.

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