From: Mattias Jonsson Date: February 21 2012 2:52pm Subject: bzr push into mysql-trunk branch (mattias.jonsson:3937 to 3938) Bug#12750920 List-Archive: http://lists.mysql.com/commits/143012 X-Bug: 12750920 Message-Id: <201202211452.q1LEqMTg001501@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3938 Mattias Jonsson 2012-02-21 [merge] Merge of bug#12750920 into mysql-trunk added: mysql-test/r/mysql_client_test_embedded.result mysql-test/t/mysql_client_test_embedded.cnf mysql-test/t/mysql_client_test_embedded.test modified: sql/mysqld.cc sql/rpl_handler.cc sql/sql_show.cc sql/sys_vars.cc tests/mysql_client_test.c 3937 Georgi Kodinov 2012-02-21 [merge] merge mysql-5.5->mysql-trunk === added file 'mysql-test/r/mysql_client_test_embedded.result' --- a/mysql-test/r/mysql_client_test_embedded.result 1970-01-01 00:00:00 +0000 +++ b/mysql-test/r/mysql_client_test_embedded.result revid:mattias.jonsson@stripped @@ -0,0 +1,92 @@ +# Run the start/stop test 17 times (* 64 = 1088 restarts) +# --silent to avoid printing out server version etc. + + +##################################### +1 of (1/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (2/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (3/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (4/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (5/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (6/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (7/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (8/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (9/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (10/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (11/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (12/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (13/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (14/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (15/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (16/17): test_embedded_start_stop +##################################### + + +##################################### +1 of (17/17): test_embedded_start_stop +##################################### + + +All '1' tests were successful (in '17' iterations) + +!!! SUCCESS !!! === added file 'mysql-test/t/mysql_client_test_embedded.cnf' --- a/mysql-test/t/mysql_client_test_embedded.cnf 1970-01-01 00:00:00 +0000 +++ b/mysql-test/t/mysql_client_test_embedded.cnf revid:mattias.jonsson@stripped @@ -0,0 +1,6 @@ +# Include original my.cnf +!include include/default_my.cnf + +[embedded] +# Can't run with innodb currently, since mysqltest_embedded have it locked +innodb=OFF === added file 'mysql-test/t/mysql_client_test_embedded.test' --- a/mysql-test/t/mysql_client_test_embedded.test 1970-01-01 00:00:00 +0000 +++ b/mysql-test/t/mysql_client_test_embedded.test revid:mattias.jonsson@stripped @@ -0,0 +1,8 @@ +--source include/is_embedded.inc + +--echo # Run the start/stop test 17 times (* 64 = 1088 restarts) +--echo # --silent to avoid printing out server version etc. +--exec $MYSQL_CLIENT_TEST --silent --count=17 test_embedded_start_stop 2>&1 +# TODO: Test all other tests once. +# (Currently not done, since many fail with embedded server). +#--exec $MYSQL_CLIENT_TEST 2>&1 === modified file 'sql/mysqld.cc' --- a/sql/mysqld.cc revid:georgi.kodinov@stripped +++ b/sql/mysqld.cc revid:mattias.jonsson@stripped @@ -588,6 +588,9 @@ uint mysql_real_data_home_len, mysql_dat uint reg_ext_length; const key_map key_map_empty(0); key_map key_map_full(0); // Will be initialized later +char logname_path[FN_REFLEN]; +char slow_logname_path[FN_REFLEN]; +char secure_file_real_path[FN_REFLEN]; DATE_TIME_FORMAT global_date_format, global_datetime_format, global_time_format; Time_zone *default_tz; @@ -1647,6 +1650,12 @@ void clean_up(bool print_message) #endif free_list(opt_plugin_load_list_ptr); + if (THR_THD) + (void) pthread_key_delete(THR_THD); + + if (THR_MALLOC) + (void) pthread_key_delete(THR_MALLOC); + /* The following lines may never be executed as the main thread may have killed us @@ -3224,7 +3233,6 @@ rpl_make_log_name(const char *opt, int init_common_variables() { - char buff[FN_REFLEN]; umask(((~my_umask) & 0666)); my_decimal_set_zero(&decimal_zero); // set decimal_zero constant; tzset(); // Set tzname @@ -3599,13 +3607,13 @@ int init_common_variables() if (!VAR || !*VAR) \ { \ my_free(VAR); /* it could be an allocated empty string "" */ \ - VAR= my_strdup(ALT, MYF(0)); \ + VAR= ALT; \ } FIX_LOG_VAR(opt_logname, - make_default_log_name(buff, ".log")); + make_default_log_name(logname_path, ".log")); FIX_LOG_VAR(opt_slow_logname, - make_default_log_name(buff, "-slow.log")); + make_default_log_name(slow_logname_path, "-slow.log")); #if defined(ENABLED_DEBUG_SYNC) /* Initialize the debug sync facility. See debug_sync.cc. */ @@ -7282,6 +7290,7 @@ static int mysql_init_variables(void) opt_logname= opt_update_logname= opt_binlog_index_name= opt_slow_logname= 0; opt_tc_log_file= (char *)"tc.log"; // no hostname in tc_log file name ! opt_secure_auth= 0; + opt_secure_file_priv= NULL; opt_bootstrap= opt_myisam_log= 0; mqh_used= 0; kill_in_progress= 0; @@ -7356,7 +7365,12 @@ static int mysql_init_variables(void) relay_log_info_file= (char*) "relay-log.info"; report_user= report_password = report_host= 0; /* TO BE DELETED */ opt_relay_logname= opt_relaylog_index_name= 0; + log_bin_basename= NULL; + log_bin_index= NULL; + /* Handler variables */ + total_ha= 0; + total_ha_2pc= 0; /* Variables in libraries */ charsets_dir= 0; default_character_set_name= (char*) MYSQL_DEFAULT_CHARSET_NAME; @@ -8227,10 +8241,7 @@ static int fix_paths(void) if (opt_secure_file_priv) { if (*opt_secure_file_priv == 0) - { - my_free(opt_secure_file_priv); - opt_secure_file_priv= 0; - } + opt_secure_file_priv= NULL; else { if (strlen(opt_secure_file_priv) >= FN_REFLEN) @@ -8240,9 +8251,7 @@ static int fix_paths(void) sql_print_warning("Failed to normalize the argument for --secure-file-priv."); return 1; } - char *secure_file_real_path= (char *)my_malloc(FN_REFLEN, MYF(MY_FAE)); convert_dirname(secure_file_real_path, buff, NullS); - my_free(opt_secure_file_priv); opt_secure_file_priv= secure_file_real_path; } } === modified file 'sql/rpl_handler.cc' --- a/sql/rpl_handler.cc revid:georgi.kodinov@stripped +++ b/sql/rpl_handler.cc revid:mattias.jonsson@stripped @@ -164,6 +164,8 @@ void delegates_destroy() if (binlog_relay_io_delegate) binlog_relay_io_delegate->~Binlog_relay_IO_delegate(); #endif /* HAVE_REPLICATION */ + if (RPL_TRANS_BINLOG_INFO) + pthread_key_delete(RPL_TRANS_BINLOG_INFO); } /* === modified file 'sql/sql_show.cc' --- a/sql/sql_show.cc revid:georgi.kodinov@stripped +++ b/sql/sql_show.cc revid:mattias.jonsson@stripped @@ -510,7 +510,10 @@ void ignore_db_dirs_free() { if (opt_ignore_db_dirs) + { my_free(opt_ignore_db_dirs); + opt_ignore_db_dirs= NULL; + } ignore_db_dirs_reset(); delete_dynamic(&ignore_db_dirs_array); my_hash_free(&ignore_db_dirs_hash); === modified file 'sql/sys_vars.cc' --- a/sql/sys_vars.cc revid:georgi.kodinov@stripped +++ b/sql/sys_vars.cc revid:mattias.jonsson@stripped @@ -2347,7 +2347,7 @@ static Sys_var_charptr Sys_secure_file_p "secure_file_priv", "Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files " "within specified directory", - PREALLOCATED READ_ONLY GLOBAL_VAR(opt_secure_file_priv), + READ_ONLY GLOBAL_VAR(opt_secure_file_priv), CMD_LINE(REQUIRED_ARG), IN_FS_CHARSET, DEFAULT(0)); static bool fix_server_id(sys_var *self, THD *thd, enum_var_type type) @@ -3345,7 +3345,7 @@ static bool fix_general_log_file(sys_var } static Sys_var_charptr Sys_general_log_path( "general_log_file", "Log connections and queries to given file", - PREALLOCATED GLOBAL_VAR(opt_logname), CMD_LINE(REQUIRED_ARG), + GLOBAL_VAR(opt_logname), CMD_LINE(REQUIRED_ARG), IN_FS_CHARSET, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_log_path), ON_UPDATE(fix_general_log_file)); @@ -3363,7 +3363,7 @@ static Sys_var_charptr Sys_slow_log_path "slow_query_log_file", "Log slow queries to given log file. " "Defaults logging to hostname-slow.log. Must be enabled to activate " "other slow log options", - PREALLOCATED GLOBAL_VAR(opt_slow_logname), CMD_LINE(REQUIRED_ARG), + GLOBAL_VAR(opt_slow_logname), CMD_LINE(REQUIRED_ARG), IN_FS_CHARSET, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_log_path), ON_UPDATE(fix_slow_log_file)); === modified file 'tests/mysql_client_test.c' --- a/tests/mysql_client_test.c revid:georgi.kodinov@stripped +++ b/tests/mysql_client_test.c revid:mattias.jonsson@stripped @@ -58,6 +58,7 @@ static MYSQL *mysql= 0; static char current_db[]= "client_test_db"; static unsigned int test_count= 0; static unsigned int opt_count= 0; +static unsigned int opt_count_read= 0; static unsigned int iter_count= 0; static my_bool have_innodb= FALSE; static char *opt_plugin_dir= 0, *opt_default_auth= 0; @@ -67,6 +68,9 @@ static const char *opt_vardir= "mysql-te static longlong opt_getopt_ll_test= 0; +static char **defaults_argv; +static int original_argc; +static char **original_argv; static int embedded_server_arg_count= 0; static char *embedded_server_args[MAX_SERVER_ARGS]; @@ -82,6 +86,11 @@ static double total_time; const char *default_dbug_option= "d:t:o,/tmp/mysql_client_test.trace"; +/* + Read and parse arguments and MySQL options from my.cnf +*/ +static const char *client_test_load_default_groups[]= { "client", 0 }; + struct my_tests_st { const char *name; @@ -110,6 +119,7 @@ if (!opt_silent) \ static void print_error(const char *msg); static void print_st_error(MYSQL_STMT *stmt, const char *msg); static void client_disconnect(MYSQL* mysql, my_bool drop_db); +static void get_options(int *argc, char ***argv); /* @@ -268,7 +278,7 @@ static my_bool check_have_innodb(MYSQL * MYSQL_RES *res; MYSQL_ROW row; int rc; - my_bool result; + my_bool result= FALSE; rc= mysql_query(conn, "SELECT (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') " @@ -280,7 +290,8 @@ static my_bool check_have_innodb(MYSQL * row= mysql_fetch_row(res); DIE_UNLESS(row); - result= strcmp(row[1], "1") == 0; + if (row[0] && row[1]) + result= strcmp(row[1], "1") == 0; mysql_free_result(res); return result; } @@ -8265,6 +8276,119 @@ static void test_set_option() } +#ifdef EMBEDDED_LIBRARY +static void test_embedded_start_stop() +{ + MYSQL *mysql_emb=NULL; + int i, j; + int argc= original_argc; // Start with the original args + char **argv, **my_argv; + char test_name[]= "test_embedded_start_stop"; +#define EMBEDDED_RESTARTS 64 + + myheader("test_embedded_start_stop"); + + /* Must stop the main embedded server, since we use the same config. */ + client_disconnect(mysql, 0); /* disconnect from server */ + free_defaults(defaults_argv); + mysql_server_end(); + /* Free everything allocated by my_once_alloc */ + my_end(0); + + /* + Use a copy of the original arguments. + The arguments will be altered when reading the configs and parsing + options. + */ + my_argv= malloc((argc + 1) * sizeof(char*)); + if (!my_argv) + exit(1); + + /* Test restarting the embedded library many times. */ + for (i= 1; i <= EMBEDDED_RESTARTS; i++) + { + argv= my_argv; + argv[0]= test_name; + for (j= 1; j < argc; j++) + argv[j]= original_argv[j]; + + /* Initialize everything again. */ + MY_INIT(argv[0]); + + /* Load the client defaults from the .cnf file[s]. */ + if (load_defaults("my", client_test_load_default_groups, &argc, &argv)) + { + myerror("load_defaults failed"); + exit(1); + } + + /* Parse the options (including the ones given from defaults files). */ + get_options(&argc, &argv); + + /* mysql_library_init is the same as mysql_server_init. */ + if (mysql_library_init(embedded_server_arg_count, + embedded_server_args, + (char**) embedded_server_groups)) + { + myerror("mysql_library_init failed"); + exit(1); + } + + /* Create a client connection. */ + if (!(mysql_emb= mysql_client_init(NULL))) + { + myerror("mysql_client_init failed"); + exit(1); + } + + /* Connect it and see if we can use the database. */ + if (!(mysql_real_connect(mysql_emb, opt_host, opt_user, + opt_password, current_db, 0, + NULL, 0))) + { + myerror("mysql_real_connect failed"); + } + + /* Close the client connection */ + mysql_close(mysql_emb); + mysql_emb = NULL; + /* Free arguments allocated for defaults files. */ + free_defaults(defaults_argv); + /* mysql_library_end is a define for mysql_server_end. */ + mysql_library_end(); + /* Free everything allocated by my_once_alloc */ + my_end(0); + } + + argc= original_argc; + argv= my_argv; + argv[0]= test_name; + for (j= 1; j < argc; j++) + argv[j]= original_argv[j]; + + MY_INIT(argv[0]); + + if (load_defaults("my", client_test_load_default_groups, &argc, &argv)) + { + myerror("load_defaults failed \n "); + exit(1); + } + + get_options(&argc, &argv); + + /* Must start the main embedded server again after the test. */ + if (mysql_server_init(embedded_server_arg_count, + embedded_server_args, + (char**) embedded_server_groups)) + DIE("Can't initialize MySQL server"); + + /* connect to server with no flags, default protocol, auto reconnect true */ + mysql= client_connect(0, MYSQL_PROTOCOL_DEFAULT, 1); + free(my_argv); +} +#endif /* EMBEDDED_LIBRARY */ + + /* Test a misc GRANT option bug #89 (reported by mark@stripped) @@ -20008,19 +20132,12 @@ static void test_bug13001491() } -/* - Read and parse arguments and MySQL options from my.cnf -*/ - -static const char *client_test_load_default_groups[]= { "client", 0 }; -static char **defaults_argv; - static struct my_option client_test_long_options[] = { {"basedir", 'b', "Basedir for tests.", &opt_basedir, &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"count", 't', "Number of times test to be executed", &opt_count, - &opt_count, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0}, + {"count", 't', "Number of times test to be executed", &opt_count_read, + &opt_count_read, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0}, {"database", 'D', "Database to use", &opt_db, &opt_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"debug", '#', "Output debug log", &default_dbug_option, @@ -20176,6 +20293,9 @@ static struct my_tests_st my_tests[]= { { "test_stiny_bug", test_stiny_bug }, { "test_field_misc", test_field_misc }, { "test_set_option", test_set_option }, +#ifdef EMBEDDED_LIBRARY + { "test_embedded_start_stop", test_embedded_start_stop }, +#endif #ifndef EMBEDDED_LIBRARY { "test_prepare_grant", test_prepare_grant }, #endif @@ -20434,6 +20554,11 @@ static void get_options(int *argc, char { int ho_error; + /* Copy argv from load_defaults, so we can free it when done. */ + defaults_argv= *argv; + /* reset --silent option */ + opt_silent= 0; + if ((ho_error= handle_options(argc, argv, client_test_long_options, get_one_option))) exit(ho_error); @@ -20454,9 +20579,12 @@ static void print_test_output() fprintf(stdout, "\n\n"); fprintf(stdout, "All '%d' tests were successful (in '%d' iterations)", test_count-1, opt_count); - fprintf(stdout, "\n Total execution time: %g SECS", total_time); - if (opt_count > 1) - fprintf(stdout, " (Avg: %g SECS)", total_time/opt_count); + if (!opt_silent) + { + fprintf(stdout, "\n Total execution time: %g SECS", total_time); + if (opt_count > 1) + fprintf(stdout, " (Avg: %g SECS)", total_time/opt_count); + } fprintf(stdout, "\n\n!!! SUCCESS !!!\n"); } @@ -20469,16 +20597,39 @@ static void print_test_output() int main(int argc, char **argv) { + int i; + char **tests_to_run= NULL, **curr_test; struct my_tests_st *fptr; MY_INIT(argv[0]); + /* Copy the original arguments, so it can be reused for restarting. */ + original_argc= argc; + original_argv= malloc(argc * sizeof(char*)); + if (argc && !original_argv) + exit(1); + for (i= 0; i < argc; i++) + original_argv[i]= strdup(argv[i]); + if (load_defaults("my", client_test_load_default_groups, &argc, &argv)) exit(1); - defaults_argv= argv; get_options(&argc, &argv); + /* Set main opt_count. */ + opt_count= opt_count_read; + + /* If there are any arguments left (named tests), save them. */ + if (argc) + { + tests_to_run= malloc((argc + 1) * sizeof(char*)); + if (!tests_to_run) + exit(1); + for (i= 0; i < argc; i++) + tests_to_run[i]= strdup(argv[i]); + tests_to_run[i]= NULL; + } + if (mysql_server_init(embedded_server_arg_count, embedded_server_args, (char**) embedded_server_groups)) @@ -20493,18 +20644,18 @@ int main(int argc, char **argv) /* Start of tests */ test_count= 1; start_time= time((time_t *)0); - if (!argc) + if (!tests_to_run) { for (fptr= my_tests; fptr->name; fptr++) (*fptr->function)(); } else { - for ( ; *argv ; argv++) + for (curr_test= tests_to_run ; *curr_test ; curr_test++) { for (fptr= my_tests; fptr->name; fptr++) { - if (!strcmp(fptr->name, *argv)) + if (!strcmp(fptr->name, *curr_test)) { (*fptr->function)(); break; @@ -20517,6 +20668,7 @@ int main(int argc, char **argv) my_progname); client_disconnect(mysql, 1); free_defaults(defaults_argv); + mysql_server_end(); exit(1); } } @@ -20540,5 +20692,17 @@ int main(int argc, char **argv) my_end(0); + for (i= 0; i < original_argc; i++) + free(original_argv[i]); + if (original_argc) + free(original_argv); + if (tests_to_run) + { + for (curr_test= tests_to_run ; *curr_test ; curr_test++) + free(*curr_test); + free(tests_to_run); + } + my_free(opt_password); + my_free(opt_host); exit(0); } No bundle (reason: useless for push emails).