diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/async_queries.c | 2 | ||||
-rw-r--r-- | tests/bug25714.c | 1 | ||||
-rwxr-xr-x | tests/fork_big.pl | 36 | ||||
-rw-r--r-- | tests/mysql_client_fw.c | 87 | ||||
-rw-r--r-- | tests/mysql_client_test.c | 492 | ||||
-rw-r--r-- | tests/nonblock-wrappers.h | 2 | ||||
-rw-r--r-- | tests/thread_test.c | 4 |
8 files changed, 566 insertions, 60 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8b3f9230c5d..5134a90e589 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -35,4 +35,6 @@ MARK_AS_ADVANCED(EVENT_LIBRARY) IF(HAVE_EVENT_H AND EVENT_LIBRARY) ADD_EXECUTABLE(async_queries async_queries.c) TARGET_LINK_LIBRARIES(async_queries mysqlclient ${EVENT_LIBRARY}) + SET_TARGET_PROPERTIES(async_queries PROPERTIES LINKER_LANGUAGE CXX) + ENDIF() diff --git a/tests/async_queries.c b/tests/async_queries.c index c91edf5bb3b..a8889fc8d5a 100644 --- a/tests/async_queries.c +++ b/tests/async_queries.c @@ -265,7 +265,7 @@ again: { if (mysql_errno(&sd->mysql)) { - /* An error occured. */ + /* An error occurred. */ printf("%d | Error: %s\n", sd->index, mysql_error(&sd->mysql)); } else diff --git a/tests/bug25714.c b/tests/bug25714.c index 5321419679b..35a13518a03 100644 --- a/tests/bug25714.c +++ b/tests/bug25714.c @@ -70,6 +70,7 @@ int main (int argc, char **argv) (long) mysql_insert_id(&conn)); mysql_close(&conn); + mysql_server_end(); my_end(0); return 0; diff --git a/tests/fork_big.pl b/tests/fork_big.pl index a294ac96e5b..623377ab5cd 100755 --- a/tests/fork_big.pl +++ b/tests/fork_big.pl @@ -1,4 +1,5 @@ #!/usr/bin/perl -w +use strict; # Copyright (c) 2001, 2006 MySQL AB # Use is subject to license terms @@ -21,7 +22,7 @@ # # Tested a lot with: --threads=30 -$opt_loop_count=500000; # Change this to make test harder/easier +my $opt_loop_count=500000; # Change this to make test harder/easier ##################### Standard benchmark inits ############################## @@ -31,6 +32,13 @@ use Benchmark; package main; +our ($opt_skip_create,$opt_skip_in,$opt_verbose,$opt_fast_insert); +our ($opt_lock_tables,$opt_debug,$opt_skip_delete,$opt_fast,$opt_force); +our ($opt_threads); +our ($opt_host,$opt_user,$opt_password,$opt_db); +my (@testtables, $abort_table, $numtables, $start_time, $end_time); +my ($dbh); + $opt_skip_create=$opt_skip_in=$opt_verbose=$opt_fast_insert= $opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=0; $opt_threads=5; @@ -94,6 +102,8 @@ $|= 1; # Autoflush #### Start the tests #### +my ($i, $pid, %work); + for ($i=0 ; $i < $opt_threads ; $i ++) { test_insert() if (($pid=fork()) == 0); $work{$pid}="insert"; @@ -118,10 +128,13 @@ test_alter() if (($pid=fork()) == 0); $work{$pid}="alter"; print "Started " . ($opt_threads*2+4) . " threads\n"; +my ($errors, $running_insert_threads); + $errors=0; $running_insert_threads=$opt_threads+$numtables; while (($pid=wait()) != -1) { + my ($ret); $ret=$?/256; print "thread '" . $work{$pid} . "' finished with exit code $ret\n"; if ($work{$pid} =~ /^insert/) @@ -203,7 +216,7 @@ sub test_insert sub test_select { - my ($dbh, $i, $j, $count, $loop); + my ($dbh, $i, $j, $count, $loop, $count_query, $row_counts); $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", $opt_user, $opt_password, @@ -270,7 +283,7 @@ sub test_select_count sub test_join { - my ($dbh, $i, $j, $count, $loop); + my ($dbh, $i, $j, $count, $loop, $count_query, $row_counts); $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", $opt_user, $opt_password, @@ -389,7 +402,7 @@ sub test_update sub test_check { - my ($dbh, $row, $i, $j, $type, $table); + my ($dbh, $sth, $row, $i, $j, $type, $table); $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", $opt_user, $opt_password, { PrintError => 0}) || die $DBI::errstr; @@ -397,7 +410,7 @@ sub test_check $type= "check"; for ($i=$j=0 ; !test_if_abort($dbh) ; $i++) { - sleep(1000); + sleep(200); $table=$testtables[$j]->[0]; $sth=$dbh->prepare("$type table $table") || die "Got error on prepare: $DBI::errstr\n"; $sth->execute || die $DBI::errstr; @@ -426,7 +439,7 @@ sub test_check sub test_repair { - my ($dbh, $row, $i, $type, $table); + my ($dbh, $sth, $row, $i, $type, $table); $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", $opt_user, $opt_password, { PrintError => 0}) || die $DBI::errstr; @@ -434,7 +447,7 @@ sub test_repair $type= "repair"; for ($i=0 ; !test_if_abort($dbh) ; $i++) { - sleep(2000); + sleep(100); $table=$testtables[0]->[0]; $sth=$dbh->prepare("$type table $table") || die "Got error on prepare: $DBI::errstr\n"; $sth->execute || die $DBI::errstr; @@ -470,7 +483,7 @@ sub test_flush $count=0; while (!test_if_abort($dbh)) { - sleep(3000); + sleep(300); $dbh->do("flush tables $tables") || die "Got error on flush $DBI::errstr\n"; $count++; @@ -488,7 +501,7 @@ sub test_flush sub test_database { my ($database) = @_; - my ($dbh, $row, $i, $type, $tables); + my ($dbh, $sth, $row, $i, $type, $tables); $dbh = DBI->connect("DBI:mysql:$database:$opt_host", $opt_user, $opt_password, { PrintError => 0}) || die $DBI::errstr; @@ -521,7 +534,7 @@ sub test_database sub test_alter { - my ($dbh, $row, $i, $type, $table); + my ($dbh, $sth, $row, $i, $type, $table); $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", $opt_user, $opt_password, { PrintError => 0}) || die $DBI::errstr; @@ -559,6 +572,7 @@ sub signal_abort sub test_if_abort() { my ($dbh)=@_; + my ($row); $row=simple_query($dbh,"select * from $opt_db.$abort_table"); return (defined($row) && defined($row->[0]) != 0) ? 1 : 0; } @@ -567,7 +581,7 @@ sub test_if_abort() sub make_count_query { my ($table_count)= @_; - my ($tables, $count_query, $i, $tables_def); + my ($tables, $count_query, $i, $table_def); $tables=""; $count_query="select high_priority "; $table_count--; diff --git a/tests/mysql_client_fw.c b/tests/mysql_client_fw.c index eb4a241dffe..9687e3794b5 100644 --- a/tests/mysql_client_fw.c +++ b/tests/mysql_client_fw.c @@ -59,6 +59,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; @@ -66,9 +67,13 @@ static unsigned int opt_drop_db= 1; static const char *opt_basedir= "./"; static const char *opt_vardir= "mysql-test/var"; +static char mysql_charsets_dir[FN_REFLEN+1]; 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]; @@ -112,6 +117,7 @@ DBUG_PRINT("test", ("name: %s", str)); \ static void print_error(const char *msg); static void print_st_error(MYSQL_STMT *stmt, const char *msg); static void client_disconnect(MYSQL* mysql); +static void get_options(int *argc, char ***argv); /* @@ -273,9 +279,11 @@ static my_bool check_have_innodb(MYSQL *conn) MYSQL_RES *res; MYSQL_ROW row; int rc; - my_bool result; + my_bool result= FALSE; - rc= mysql_query(conn, "show variables like 'have_innodb'"); + rc= mysql_query(conn, + "SELECT (support = 'YES' or support = 'DEFAULT' or support = 'ENABLED') " + "AS `TRUE` FROM information_schema.engines WHERE engine = 'innodb'"); myquery(rc); res= mysql_use_result(conn); DIE_UNLESS(res); @@ -283,7 +291,8 @@ static my_bool check_have_innodb(MYSQL *conn) row= mysql_fetch_row(res); DIE_UNLESS(row); - result= strcmp(row[1], "YES") == 0; + if (row[0] && row[1]) + result= strcmp(row[1], "1") == 0; mysql_free_result(res); return result; } @@ -583,7 +592,7 @@ static int my_process_stmt_result(MYSQL_STMT *stmt) return row_count; } - field_count= min(mysql_num_fields(result), MAX_RES_FIELDS); + field_count= MY_MIN(mysql_num_fields(result), MAX_RES_FIELDS); bzero((char*) buffer, sizeof(buffer)); bzero((char*) length, sizeof(length)); @@ -1179,8 +1188,11 @@ 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}, + {"character-sets-dir", 'C', + "Directory for character set files.", &charsets_dir, + &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 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}, {"do-not-drop-database", 'd', "Do not drop database while disconnecting", @@ -1324,6 +1336,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), exit(0); break; } + case 'C': + strmake_buf(mysql_charsets_dir, argument); + charsets_dir = mysql_charsets_dir; + break; case '?': case 'I': /* Info */ usage(); @@ -1336,6 +1352,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), static void get_options(int *argc, char ***argv) { 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))) @@ -1357,9 +1377,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"); } @@ -1372,16 +1395,36 @@ 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_testlist= get_my_tests(); MY_INIT(argv[0]); - - if (load_defaults("my", client_test_load_default_groups, &argc, &argv)) + /* 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]); + + load_defaults_or_exit("my", client_test_load_default_groups, &argc, &argv); - 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, @@ -1397,18 +1440,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_testlist; fptr->name; fptr++) (*fptr->function)(); } else { - for ( ; *argv ; argv++) + for (curr_test= tests_to_run ; *curr_test ; curr_test++) { for (fptr= my_testlist; fptr->name; fptr++) { - if (!strcmp(fptr->name, *argv)) + if (!strcmp(fptr->name, *curr_test)) { (*fptr->function)(); break; @@ -1421,6 +1464,7 @@ int main(int argc, char **argv) my_progname); client_disconnect(mysql); free_defaults(defaults_argv); + mysql_server_end(); exit(1); } } @@ -1444,5 +1488,18 @@ 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); } diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 3758c4f1ff7..c7d79b692e1 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -422,6 +422,55 @@ static void test_prepare_simple() mysql_stmt_close(stmt); + /* show create */ + strmov(query, "SHOW CREATE TABLE test_prepare_simple"); + stmt= mysql_simple_prepare(mysql, query); + check_stmt(stmt); + DIE_UNLESS(mysql_stmt_field_count(stmt) == 2); + mysql_stmt_close(stmt); + + /* show create database */ + strmov(query, "SHOW CREATE DATABASE test"); + stmt= mysql_simple_prepare(mysql, query); + check_stmt(stmt); + DIE_UNLESS(mysql_stmt_field_count(stmt) == 2); + mysql_stmt_close(stmt); + + /* show grants */ + strmov(query, "SHOW GRANTS"); + stmt= mysql_simple_prepare(mysql, query); + check_stmt(stmt); + DIE_UNLESS(mysql_stmt_field_count(stmt) == 1); + mysql_stmt_close(stmt); + + /* show slave status */ + strmov(query, "SHOW SLAVE STATUS"); + stmt= mysql_simple_prepare(mysql, query); + check_stmt(stmt); + DIE_UNLESS(mysql_stmt_field_count(stmt) == 47); + mysql_stmt_close(stmt); + + /* show master status */ + strmov(query, "SHOW MASTER STATUS"); + stmt= mysql_simple_prepare(mysql, query); + check_stmt(stmt); + DIE_UNLESS(mysql_stmt_field_count(stmt) == 4); + mysql_stmt_close(stmt); + + /* show create procedure */ + strmov(query, "SHOW CREATE PROCEDURE e1;"); + stmt= mysql_simple_prepare(mysql, query); + check_stmt(stmt); + DIE_UNLESS(mysql_stmt_field_count(stmt) == 6); + mysql_stmt_close(stmt); + + /* show create function */ + strmov(query, "SHOW CREATE FUNCTION e1;"); + stmt= mysql_simple_prepare(mysql, query); + check_stmt(stmt); + DIE_UNLESS(mysql_stmt_field_count(stmt) == 6); + mysql_stmt_close(stmt); + /* now fetch the results ..*/ rc= mysql_commit(mysql); myquery(rc); @@ -1033,6 +1082,7 @@ static void test_wl4435_2() \ rs_metadata= mysql_stmt_result_metadata(ps); \ fields= mysql_fetch_fields(rs_metadata); \ + mysql_free_result(rs_metadata); \ \ rc= mysql_stmt_bind_result(ps, &psp); \ check_execute(ps, rc); \ @@ -2093,7 +2143,7 @@ static void test_ps_conj_select() "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')"); myquery(rc); - strmov(query, "select id1, value1 from t1 where id1= ? or " + strmov(query, "SELECT id1, value1 from t1 where id1= ? or " "CONVERT(value1 USING utf8)= ?"); stmt= mysql_simple_prepare(mysql, query); check_stmt(stmt); @@ -2261,7 +2311,7 @@ static void test_ps_query_cache() return; } - rc= mysql_query(mysql, "SET SQL_MODE=''"); + rc= mysql_set_character_set(mysql, "utf8"); myquery(rc); /* prepare the table */ @@ -2277,6 +2327,11 @@ static void test_ps_query_cache() "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')"); myquery(rc); + rc= mysql_query(lmysql, "set global query_cache_type=ON"); + myquery(rc); + rc= mysql_query(lmysql, "set local query_cache_type=ON"); + myquery(rc); + for (iteration= TEST_QCACHE_ON; iteration <= TEST_QCACHE_ON_OFF; iteration++) { @@ -2308,6 +2363,8 @@ static void test_ps_query_cache() } rc= mysql_query(lmysql, "SET SQL_MODE=''"); myquery(rc); + rc= mysql_set_character_set(lmysql, "utf8"); + myquery(rc); if (!opt_silent) fprintf(stdout, "OK"); @@ -2426,7 +2483,9 @@ static void test_ps_query_cache() if (lmysql != mysql) mysql_close(lmysql); - rc= mysql_query(mysql, "set global query_cache_size=0"); + rc= mysql_query(mysql, "set global query_cache_size=default"); + myquery(rc); + rc= mysql_query(mysql, "set global query_cache_type=default"); myquery(rc); } @@ -5976,6 +6035,10 @@ static void test_bind_date_conv(uint row_count) MYSQL_TIME tm[4]; ulong second_part; uint year, month, day, hour, minute, sec; + uint now_year= 1990, now_month= 3, now_day= 13; + + rc= mysql_query(mysql, "SET timestamp=UNIX_TIMESTAMP('1990-03-13')"); + myquery(rc); stmt= mysql_simple_prepare(mysql, "INSERT INTO test_date VALUES(?, ?, ?, ?)"); check_stmt(stmt); @@ -6076,9 +6139,15 @@ static void test_bind_date_conv(uint row_count) i, tm[i].year, tm[i].month, tm[i].day, tm[i].hour, tm[i].minute, tm[i].second, tm[i].second_part); - DIE_UNLESS(tm[i].year == 0 || tm[i].year == year+count); - DIE_UNLESS(tm[i].month == 0 || tm[i].month == month+count); - DIE_UNLESS(tm[i].day == 0 || tm[i].day == day+count); + DIE_UNLESS(tm[i].year == 0 || tm[i].year == year + count || + (tm[i].year == now_year && + my_bind[i].buffer_type == MYSQL_TYPE_TIME)); + DIE_UNLESS(tm[i].month == 0 || tm[i].month == month + count || + (tm[i].month == now_month && + my_bind[i].buffer_type == MYSQL_TYPE_TIME)); + DIE_UNLESS(tm[i].day == 0 || tm[i].day == day + count || + (tm[i].day == now_day && + my_bind[i].buffer_type == MYSQL_TYPE_TIME)); DIE_UNLESS(tm[i].hour == 0 || tm[i].hour == hour+count); DIE_UNLESS(tm[i].minute == 0 || tm[i].minute == minute+count); @@ -6930,7 +6999,7 @@ static void test_set_option() mysql_autocommit(mysql, TRUE); /* LIMIT the rows count to 2 */ - rc= mysql_query(mysql, "SET OPTION SQL_SELECT_LIMIT= 2"); + rc= mysql_query(mysql, "SET SQL_SELECT_LIMIT= 2"); myquery(rc); rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_limit"); @@ -6971,7 +7040,7 @@ static void test_set_option() /* RESET the LIMIT the rows count to 0 */ if (!opt_silent) fprintf(stdout, "\n with SQL_SELECT_LIMIT=DEFAULT (prepare)"); - rc= mysql_query(mysql, "SET OPTION SQL_SELECT_LIMIT=DEFAULT"); + rc= mysql_query(mysql, "SET SQL_SELECT_LIMIT=DEFAULT"); myquery(rc); stmt= mysql_simple_prepare(mysql, "SELECT * FROM test_limit"); @@ -6986,6 +7055,109 @@ static void test_set_option() mysql_stmt_close(stmt); } +#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); /* 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]. */ + load_defaults_or_exit("my", client_test_load_default_groups, &argc, &argv); + + /* 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]); + + load_defaults_or_exit("my", client_test_load_default_groups, &argc, &argv); + 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 @@ -9864,11 +10036,11 @@ static void test_bug3035() const uint32 uint32_max= 4294967295U; /* it might not work okay everyplace */ - const longlong int64_max= LL(9223372036854775807); + const longlong int64_max= 9223372036854775807LL; const longlong int64_min= -int64_max - 1; const ulonglong uint64_min= 0U; - const ulonglong uint64_max= ULL(18446744073709551615); + const ulonglong uint64_max= 18446744073709551615ULL; const char *stmt_text; @@ -11603,10 +11775,10 @@ static void test_bug5315() rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); DIE_UNLESS(rc == 0); if (!opt_silent) - printf("Excuting mysql_change_user\n"); + printf("Executing mysql_change_user\n"); mysql_change_user(mysql, opt_user, opt_password, current_db); if (!opt_silent) - printf("Excuting mysql_stmt_execute\n"); + printf("Executing mysql_stmt_execute\n"); rc= mysql_stmt_execute(stmt); DIE_UNLESS(rc != 0); if (rc) @@ -11616,10 +11788,10 @@ static void test_bug5315() } /* check that connection is OK */ if (!opt_silent) - printf("Excuting mysql_stmt_close\n"); + printf("Executing mysql_stmt_close\n"); mysql_stmt_close(stmt); if (!opt_silent) - printf("Excuting mysql_stmt_init\n"); + printf("Executing mysql_stmt_init\n"); stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text)); DIE_UNLESS(rc == 0); @@ -12535,7 +12707,7 @@ static void test_truncation() /* double -> longlong, negative fp number to signed integer: no loss */ DIE_UNLESS(my_bind++ < bind_array + bind_count); - DIE_UNLESS(! *my_bind->error && * (longlong*) my_bind->buffer == LL(-12345678910)); + DIE_UNLESS(! *my_bind->error && * (longlong*) my_bind->buffer == -12345678910LL); /* big numeric string -> number */ DIE_UNLESS(my_bind++ < bind_array + bind_count); @@ -13045,6 +13217,10 @@ static void test_open_cursor_prepared_statement_query_cache() return; } + rc= mysql_query(mysql, "set global query_cache_type=ON"); + myquery(rc); + rc= mysql_query(mysql, "set local query_cache_type=ON"); + myquery(rc); rc= mysql_query(mysql, "set global query_cache_size=1000000"); myquery(rc); @@ -13067,7 +13243,9 @@ static void test_open_cursor_prepared_statement_query_cache() check_execute(stmt, rc); mysql_stmt_close(stmt); - rc= mysql_query(mysql, "set global query_cache_size=1000000"); + rc= mysql_query(mysql, "set global query_cache_type=default"); + myquery(rc); + rc= mysql_query(mysql, "set global query_cache_size=default"); myquery(rc); } @@ -14537,7 +14715,7 @@ static void test_bug12925() { myheader("test_bug12925"); if (opt_getopt_ll_test) - DIE_UNLESS(opt_getopt_ll_test == LL(25600*1024*1024)); + DIE_UNLESS(opt_getopt_ll_test == 25600LL*1024*1024); } @@ -15189,6 +15367,9 @@ static void test_bug14169() rc= mysql_query(mysql, "drop table t1"); myquery(rc); + + rc= mysql_query(mysql, "set session group_concat_max_len=@@global.group_concat_max_len"); + myquery(rc); } /* @@ -16525,7 +16706,7 @@ static void test_bug30472() /* Switch client character set. */ - DIE_IF(mysql_set_character_set(&con, "utf8")); + DIE_IF(mysql_set_character_set(&con, "latin2")); /* Retrieve character set information. */ @@ -16541,10 +16722,10 @@ static void test_bug30472() 2) new character set is different from the original one. */ - DIE_UNLESS(strcmp(character_set_name_2, "utf8") == 0); - DIE_UNLESS(strcmp(character_set_client_2, "utf8") == 0); - DIE_UNLESS(strcmp(character_set_results_2, "utf8") == 0); - DIE_UNLESS(strcmp(collation_connnection_2, "utf8_general_ci") == 0); + DIE_UNLESS(strcmp(character_set_name_2, "latin2") == 0); + DIE_UNLESS(strcmp(character_set_client_2, "latin2") == 0); + DIE_UNLESS(strcmp(character_set_results_2, "latin2") == 0); + DIE_UNLESS(strcmp(collation_connnection_2, "latin2_general_ci") == 0); DIE_UNLESS(strcmp(character_set_name_1, character_set_name_2) != 0); DIE_UNLESS(strcmp(character_set_client_1, character_set_client_2) != 0); @@ -17040,7 +17221,7 @@ static void test_bug28386() if (! opt_silent) printf("Skipping the test since logging to tables is not enabled\n"); /* Log output is not to tables */ - return; + DBUG_VOID_RETURN; } mysql_free_result(result); @@ -17344,11 +17525,10 @@ static void test_wl4166_3() rc= mysql_stmt_execute(stmt); check_execute(stmt, rc); /* - Sic: only one warning, instead of two. The warning - about data truncation when assigning a parameter is lost. + The warning about data truncation when assigning a parameter is lost. This is a bug. */ - my_process_warnings(mysql, 1); + my_process_warnings(mysql, 0); verify_col_data("t1", "year", "0000-00-00 00:00:00"); @@ -17838,6 +18018,8 @@ static void test_bug36326() myquery(rc); rc= mysql_query(mysql, "SET GLOBAL query_cache_type = 1"); myquery(rc); + rc= mysql_query(mysql, "SET LOCAL query_cache_type = 1"); + myquery(rc); rc= mysql_query(mysql, "SET GLOBAL query_cache_size = 1048576"); myquery(rc); DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS)); @@ -17861,7 +18043,8 @@ static void test_bug36326() DIE_UNLESS(rc == 1); rc= mysql_query(mysql, "DROP TABLE t1"); myquery(rc); - rc= mysql_query(mysql, "SET GLOBAL query_cache_size = 0"); + rc= mysql_query(mysql, "SET GLOBAL query_cache_size = default"); + rc= mysql_query(mysql, "SET GLOBAL query_cache_type = default"); myquery(rc); DBUG_VOID_RETURN; @@ -18319,6 +18502,7 @@ static void test_bug58036() /* Part1: try to connect with ucs2 client character set */ conn= mysql_client_init(NULL); mysql_options(conn, MYSQL_SET_CHARSET_NAME, "ucs2"); + if (mysql_real_connect(conn, opt_host, opt_user, opt_password, opt_db ? opt_db : "test", opt_port, opt_unix_socket, 0)) @@ -18369,7 +18553,6 @@ static void test_bug58036() printf("Got mysql_change_user() error (expected): %s (%d)\n", mysql_error(conn), mysql_errno(conn)); mysql_close(conn); - DBUG_VOID_RETURN; } @@ -18495,7 +18678,7 @@ static void test_bug56976() const char* query = "SELECT LENGTH(?)"; char *long_buffer; unsigned long i, packet_len = 256 * 1024L; - unsigned long dos_len = 2 * 1024 * 1024L; + unsigned long dos_len = 35000000; DBUG_ENTER("test_bug56976"); myheader("test_bug56976"); @@ -18586,13 +18769,31 @@ static void test_progress_reporting() rc= mysql_query(conn, "insert into t1 (f2) select f2 from t2"); myquery(rc); } - rc= mysql_query(conn, "alter table t1 add f1 int primary key auto_increment, add key (f2), order by f2"); + + progress_stage= progress_max_stage= progress_count= 0; + rc= mysql_query(conn, "alter table t1 add f1 int primary key auto_increment, order by f2"); myquery(rc); if (!opt_silent) printf("Got progress_count: %u stage: %u max_stage: %u\n", progress_count, progress_stage, progress_max_stage); DIE_UNLESS(progress_count > 0 && progress_stage >=2 && progress_max_stage == 3); + + progress_stage= progress_max_stage= progress_count= 0; + rc= mysql_query(conn, "create index f2 on t1 (f2)"); myquery(rc); + if (!opt_silent) + printf("Got progress_count: %u stage: %u max_stage: %u\n", + progress_count, progress_stage, progress_max_stage); + DIE_UNLESS(progress_count > 0 && progress_stage >=2 && progress_max_stage == 2); + + progress_stage= progress_max_stage= progress_count= 0; + rc= mysql_query(conn, "drop index f2 on t1"); + myquery(rc); + if (!opt_silent) + printf("Got progress_count: %u stage: %u max_stage: %u\n", + progress_count, progress_stage, progress_max_stage); + DIE_UNLESS(progress_count > 0 && progress_stage >=2 && progress_max_stage == 2); + rc= mysql_query(conn, "set @@global.progress_report_time=@save"); myquery(rc); mysql_close(conn); @@ -18750,6 +18951,109 @@ static void test_bug12337762() DBUG_VOID_RETURN; } +/* + MDEV-4603: mysql_stmt_reset doesn't clear + all result sets (from stored procedures). + This test requires also fix for MDEV-4604 +*/ +static void test_mdev4603() +{ + MYSQL *my; + MYSQL_STMT *stmt; + int i, rc; + int a[] = {10,20,30}; + MYSQL_BIND bind[3]; + + myheader("test_mdev4603"); + my= mysql_client_init(NULL); + + if (!mysql_real_connect(my, opt_host, opt_user, + opt_password, current_db, opt_port, + opt_unix_socket, CLIENT_MULTI_RESULTS)) + DIE("mysql_real_connect failed"); + + /* 1st test: + use a procedure with out param + */ + rc= mysql_query(my, "DROP PROCEDURE IF EXISTS p1"); + myquery(rc); + + rc= mysql_query(mysql, "CREATE PROCEDURE p1(OUT p_out VARCHAR(19), IN p_in INT, INOUT p_inout INT)" + "BEGIN " + " SET p_in = 300, p_out := 'This is OUT param', p_inout = 200; " + " SELECT p_inout, p_in, substring(p_out, 9);" + "END"); + myquery(rc); + + stmt= mysql_stmt_init(mysql); + DIE_UNLESS(stmt != NULL); + + rc= mysql_stmt_prepare(stmt, "CALL P1(?,?,?)", 14); + DIE_UNLESS(rc == 0); + + DIE_UNLESS(mysql_stmt_param_count(stmt) == 3); + + memset(bind, 0, sizeof(MYSQL_BIND) * 3); + for (i=0; i < 3; i++) + { + bind[i].buffer= &a[i]; + bind[i].buffer_type= MYSQL_TYPE_LONG; + } + bind[0].buffer_type= MYSQL_TYPE_NULL; + rc= mysql_stmt_bind_param(stmt, bind); + DIE_UNLESS(rc == 0); + + rc= mysql_stmt_execute(stmt); + DIE_UNLESS(rc == 0); + + rc= mysql_stmt_fetch(stmt); + DIE_UNLESS(rc == 0); + + rc= mysql_stmt_reset(stmt); + DIE_UNLESS(rc == 0); + + /*connection shouldn't be blocked now */ + + rc= mysql_query(mysql, "DROP PROCEDURE p1"); + myquery(rc); + + /* 2nd test: + reset all result sets */ + rc= mysql_query(my, "CREATE PROCEDURE p1() " + "BEGIN" + " SELECT 1,2,3 FROM DUAL;" + " SELECT 'foo' FROM DUAL;" + "END"); + myquery(rc); + + rc= mysql_stmt_prepare(stmt, "CALL P1()", 9); + DIE_UNLESS(rc == 0); + + rc= mysql_stmt_execute(stmt); + DIE_UNLESS(rc == 0); + + rc= mysql_stmt_reset(stmt); + DIE_UNLESS(rc == 0); + + /* 3rd test: + mysql_stmt_close should also flush all pending + result sets + */ + + rc= mysql_stmt_prepare(stmt, "CALL P1()", 9); + DIE_UNLESS(rc == 0); + + rc= mysql_stmt_execute(stmt); + DIE_UNLESS(rc == 0); + + rc= mysql_stmt_close(stmt); + DIE_UNLESS(rc == 0); + + rc= mysql_query(my, "DROP PROCEDURE p1"); + myquery(rc); + + mysql_close(my); +} /* BUG 11754979 - 46675: ON DUPLICATE KEY UPDATE AND UPDATECOUNT() POSSIBLY WRONG @@ -19074,11 +19378,134 @@ static void test_bug17512527() } + +/* + Check compressed protocol +*/ + +static void test_compressed_protocol() +{ + MYSQL *mysql_local; + char query[4096], *end; + int i; + myheader("test_compressed_protocol"); + + if (!(mysql_local= mysql_client_init(NULL))) + { + fprintf(stderr, "\n mysql_client_init() failed"); + exit(1); + } + + if (!(mysql_real_connect(mysql_local, opt_host, opt_user, + opt_password, current_db, opt_port, + opt_unix_socket, CLIENT_COMPRESS))) + { + fprintf(stderr, "\n connection failed(%s)", mysql_error(mysql_local)); + exit(1); + } + mysql_options(mysql_local,MYSQL_OPT_COMPRESS,NullS); + + end= strmov(strfill(strmov(query, "select length(\""),1000,'a'),"\")"); + + for (i=0 ; i < 2 ; i++) + { + MYSQL_RES *res; + + int rc= mysql_real_query(mysql, query, (int) (end-query)); + myquery(rc); + res= mysql_store_result(mysql); + DBUG_ASSERT(res != 0); + mysql_free_result(res); + } + + mysql_close(mysql_local); +} + +/* + Check big packets +*/ + +static void test_big_packet() +{ + MYSQL *mysql_local; + char *query, *end; + /* We run the tests with a server with max packet size of 3200000 */ + size_t big_packet= 31000000L; + int i; + MYSQL_PARAMETERS *mysql_params= mysql_get_parameters(); + long org_max_allowed_packet= *mysql_params->p_max_allowed_packet; + long opt_net_buffer_length= *mysql_params->p_net_buffer_length; + + myheader("test_big_packet"); + + query= (char*) my_malloc(big_packet+1024, MYF(MY_WME)); + DIE_UNLESS(query); + + if (!(mysql_local= mysql_client_init(NULL))) + { + fprintf(stderr, "\n mysql_client_init() failed"); + exit(1); + } + + if (!(mysql_real_connect(mysql_local, opt_host, opt_user, + opt_password, current_db, opt_port, + opt_unix_socket, 0))) + { + fprintf(stderr, "\n connection failed(%s)", mysql_error(mysql_local)); + mysql_close(mysql_local); + exit(1); + } + + *mysql_params->p_max_allowed_packet= big_packet+1000; + *mysql_params->p_net_buffer_length= 8L*256L*256L; + + end= strmov(strfill(strmov(query, "select length(\""), big_packet,'a'),"\")"); + + for (i=0 ; i < 2 ; i++) + { + MYSQL_RES *res; + int rc= mysql_real_query(mysql, query, (int) (end-query)); + myquery(rc); + res= mysql_store_result(mysql); + DBUG_ASSERT(res != 0); + mysql_free_result(res); + } + + mysql_close(mysql_local); + my_free(query); + + *mysql_params->p_max_allowed_packet= org_max_allowed_packet; + *mysql_params->p_net_buffer_length = opt_net_buffer_length; +} + + +/* Test simple prepares of all DML statements */ + +static void test_prepare_analyze() +{ + MYSQL_STMT *stmt; + int rc; + myheader("test_prepare_analyze"); + + stmt= mysql_stmt_init(mysql); + check_stmt(stmt); + rc= mysql_stmt_prepare(stmt, STRING_WITH_LEN("ANALYZE SELECT 1")); + check_execute(stmt, rc); + verify_param_count(stmt, 0); + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + mysql_stmt_close(stmt); +} + static struct my_tests_st my_tests[]= { { "disable_query_logs", disable_query_logs }, { "test_view_sp_list_fields", test_view_sp_list_fields }, { "client_query", client_query }, { "test_prepare_insert_update", test_prepare_insert_update}, +#ifdef EMBEDDED_LIBRARY + { "test_embedded_start_stop", test_embedded_start_stop }, +#endif #if NOT_YET_WORKING { "test_drop_temp", test_drop_temp }, #endif @@ -19157,6 +19584,7 @@ static struct my_tests_st my_tests[]= { { "test_set_option", test_set_option }, #ifndef EMBEDDED_LIBRARY { "test_prepare_grant", test_prepare_grant }, + #endif { "test_frm_bug", test_frm_bug }, { "test_explain_bug", test_explain_bug }, @@ -19333,6 +19761,7 @@ static struct my_tests_st my_tests[]= { { "test_bug57058", test_bug57058 }, { "test_bug56976", test_bug56976 }, { "test_mdev3885", test_mdev3885 }, + { "test_mdev4603", test_mdev4603 }, { "test_bug11766854", test_bug11766854 }, { "test_bug12337762", test_bug12337762 }, { "test_progress_reporting", test_progress_reporting }, @@ -19343,6 +19772,9 @@ static struct my_tests_st my_tests[]= { #ifndef _WIN32 { "test_bug17512527", test_bug17512527}, #endif + { "test_compressed_protocol", test_compressed_protocol }, + { "test_big_packet", test_big_packet }, + { "test_prepare_analyze", test_prepare_analyze }, { 0, 0 } }; diff --git a/tests/nonblock-wrappers.h b/tests/nonblock-wrappers.h index 3ed470b3400..d6f42511f3a 100644 --- a/tests/nonblock-wrappers.h +++ b/tests/nonblock-wrappers.h @@ -30,7 +30,7 @@ /* Run the appropriate poll() syscall to wait for the event that libmysql - requested. Return which event(s) occured. + requested. Return which event(s) occurred. */ static int wait_for_mysql(MYSQL *mysql, int status) diff --git a/tests/thread_test.c b/tests/thread_test.c index c73690a6e51..0fa92d505a3 100644 --- a/tests/thread_test.c +++ b/tests/thread_test.c @@ -168,8 +168,8 @@ static void get_options(int argc, char **argv) { int ho_error; - if ((ho_error= load_defaults("my",load_default_groups,&argc,&argv)) || - (ho_error= handle_options(&argc, &argv, my_long_options, get_one_option))) + load_defaults_or_exit("my", load_default_groups, &argc, &argv); + if ((ho_error= handle_options(&argc, &argv, my_long_options, get_one_option))) exit(ho_error); free_defaults(argv); |