From 600a74b0d404e98103c4ddf5a9019e04512f0dcc Mon Sep 17 00:00:00 2001 From: "msvensson@neptunus.(none)" <> Date: Tue, 6 Dec 2005 21:28:13 +0100 Subject: [PATCH] WL#2930 - Updated after review --- client/mysqltest.c | 138 +++++++++++++++++--------- mysql-test/include/have_multi_ndb.inc | 8 +- mysql-test/r/init_file.result | 1 + mysql-test/r/mysql_client_test.result | 1 + mysql-test/r/mysqltest.result | 4 + mysql-test/t/init_file.test | 1 + mysql-test/t/mysql_client_test.test | 2 + mysql-test/t/mysqltest.test | 54 +++++++--- 8 files changed, 146 insertions(+), 63 deletions(-) create mode 100644 mysql-test/r/init_file.result create mode 100644 mysql-test/r/mysql_client_test.result diff --git a/client/mysqltest.c b/client/mysqltest.c index 224985227cd..91791145db5 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -628,6 +628,10 @@ static void die(const char *fmt, ...) va_end(args); free_used_memory(); my_end(MY_CHECK_ERROR); + + if (!silent) + printf("not ok\n"); + exit(1); } @@ -3050,11 +3054,7 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, for (col_idx= 0; col_idx < num_fields; col_idx++) { /* Allocate data for output */ - /* - FIXME it may be a bug that for non string/blob types - 'max_length' is 0, should try out 'length' in that case - */ - uint max_length= max(field[col_idx].max_length + 1, 1024); + uint max_length= field[col_idx].max_length + 1; char *str_data= (char *) my_malloc(max_length, MYF(MY_WME | MY_FAE)); bind[col_idx].buffer_type= MYSQL_TYPE_STRING; @@ -3062,6 +3062,11 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, bind[col_idx].buffer_length= max_length; bind[col_idx].is_null= &is_null[col_idx]; bind[col_idx].length= &length[col_idx]; + + DBUG_PRINT("bind", ("col[%d]: buffer_type: %d, buffer_length: %d", + col_idx, + bind[col_idx].buffer_type, + bind[col_idx].buffer_length)); } /* Fill in the data into the structures created above */ @@ -3197,11 +3202,11 @@ static void append_metadata(DYNAMIC_STRING *ds, Append affected row count and other info to output */ -static void append_info(DYNAMIC_STRING *ds, ulong affected_rows, +static void append_info(DYNAMIC_STRING *ds, ulonglong affected_rows, const char *info) { char buf[40]; - sprintf(buf,"affected rows: %lu\n", affected_rows); + sprintf(buf,"affected rows: %llu\n", affected_rows); dynstr_append(ds, buf); if (info) { @@ -3231,17 +3236,20 @@ static void append_table_headings(DYNAMIC_STRING *ds, } /* - Fetch warnings from server and append to output + Fetch warnings from server and append to ds + + RETURN VALUE + Number of warnings appended to ds */ -static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) +static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) { uint count; MYSQL_RES *warn_res; DBUG_ENTER("append_warnings"); if (!(count= mysql_warning_count(mysql))) - DBUG_VOID_RETURN; + DBUG_RETURN(0); /* If one day we will support execution of multi-statements @@ -3257,14 +3265,14 @@ static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) die("Warning count is %u but didn't get any warnings", count); - dynstr_append_mem(ds, "Warnings:\n", 10); append_result(ds, warn_res); mysql_free_result(warn_res); - DBUG_VOID_RETURN; + DBUG_RETURN(count); } + /* Run query using MySQL C API @@ -3287,6 +3295,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, { MYSQL_RES *res= 0; int err= 0, counter= 0; + DYNAMIC_STRING ds_warnings; DBUG_ENTER("run_query_normal"); DBUG_PRINT("enter",("flags: %d", flags)); DBUG_PRINT("enter", ("query: '%-.60s'", query)); @@ -3334,7 +3343,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, if (!disable_result_log) { - ulong affected_rows; /* Ok to be undef if 'disable_info' is set */ + ulonglong affected_rows; /* Ok to be undef if 'disable_info' is set */ LINT_INIT(affected_rows); if (res) @@ -3356,7 +3365,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, query to find the warnings */ if (!disable_info) - affected_rows= (ulong)mysql_affected_rows(mysql); + affected_rows= mysql_affected_rows(mysql); /* Add all warnings to the result. We can't do this if we are in @@ -3364,7 +3373,15 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, this will break protocol. */ if (!disable_warnings && !mysql_more_results(mysql)) - append_warnings(ds, mysql); + { + init_dynamic_string(&ds_warnings, NULL, 0, 256); + if (append_warnings(&ds_warnings, mysql)) + { + dynstr_append_mem(ds, "Warnings:\n", 10); + dynstr_append_mem(ds, ds_warnings.str, ds_warnings.length); + } + dynstr_free(&ds_warnings); + } if (!disable_info) append_info(ds, affected_rows, mysql_info(mysql)); @@ -3542,6 +3559,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ MYSQL_STMT *stmt; DYNAMIC_STRING ds_prepare_warnings; + DYNAMIC_STRING ds_execute_warnings; DBUG_ENTER("run_query_stmt"); DBUG_PRINT("query", ("'%-.60s'", query)); @@ -3562,6 +3580,10 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, { handle_error(query, command, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); +#ifndef BUG15518_FIXED + mysql_stmt_close(stmt); + cur_con->stmt= NULL; +#endif goto end; } @@ -3569,10 +3591,10 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, Get the warnings from mysql_stmt_prepare and keep them in a separate string */ - if (!disable_warnings) { - init_dynamic_string(&ds_prepare_warnings, "", 1024, 1024); + init_dynamic_string(&ds_prepare_warnings, NULL, 0, 256); + init_dynamic_string(&ds_execute_warnings, NULL, 0, 256); append_warnings(&ds_prepare_warnings, mysql); } @@ -3588,7 +3610,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, */ if (cursor_protocol_enabled) { - unsigned long type= CURSOR_TYPE_READ_ONLY; + ulong type= CURSOR_TYPE_READ_ONLY; if (mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type)) die("mysql_stmt_attr_set(STMT_ATTR_CURSOR_TYPE) failed': %d %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); @@ -3654,25 +3676,36 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, mysql_free_result(res); /* Free normal result set with meta data */ + /* Clear prepare warnings */ + dynstr_set(&ds_prepare_warnings, NULL); } else { /* This is a query without resultset */ - - /* - Add warnings from prepare to output - */ - if (!disable_warnings) - dynstr_append(ds, ds_prepare_warnings.str); } if (!disable_warnings) - append_warnings(ds, mysql); + { + /* Get the warnings from execute */ + + /* Append warnings to ds - if there are any */ + if (append_warnings(&ds_execute_warnings, mysql) || + ds_prepare_warnings.length) + { + dynstr_append_mem(ds, "Warnings:\n", 10); + if (ds_prepare_warnings.length) + dynstr_append_mem(ds, ds_prepare_warnings.str, + ds_prepare_warnings.length); + if (ds_execute_warnings.length) + dynstr_append_mem(ds, ds_execute_warnings.str, + ds_execute_warnings.length); + } + } if (!disable_info) - append_info(ds, (ulong)mysql_affected_rows(mysql), mysql_info(mysql)); + append_info(ds, mysql_affected_rows(mysql), mysql_info(mysql)); } @@ -3680,7 +3713,10 @@ end: free_replace(); if (!disable_warnings) + { dynstr_free(&ds_prepare_warnings); + dynstr_free(&ds_execute_warnings); + } /* We save the return code (mysql_stmt_errno(stmt)) from the last call sent @@ -3778,6 +3814,10 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) DBUG_PRINT("view_create_error", ("Failed to create view '%s': %d: %s", query_str.str, mysql_errno(mysql), mysql_error(mysql))); + + /* Log error to create view */ + verbose_msg("Failed to create view '%s' %d: %s", query_str.str, + mysql_errno(mysql), mysql_error(mysql)); } else { @@ -3817,6 +3857,11 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) DBUG_PRINT("sp_create_error", ("Failed to create sp '%s': %d: %s", query_str.str, mysql_errno(mysql), mysql_error(mysql))); + + /* Log error to create sp */ + verbose_msg("Failed to create sp '%s' %d: %s", query_str.str, + mysql_errno(mysql), mysql_error(mysql)); + } else { @@ -4446,24 +4491,10 @@ int main(int argc, char **argv) } /* - The whole test has been executed sucessfully + The whole test has been executed _sucessfully_ Time to compare result or save it to record file The entire output from test is now kept in ds_res - */ - - if (!query_executed && result_file && my_stat(result_file, &res_info, 0)) - { - /* - my_stat() successful on result file. Check if we have not run a - single query, but we do have a result file that contains data. - Note that we don't care, if my_stat() fails. For example for - non-existing or non-readable file we assume it's fine to have - no query output from the test file, e.g. regarded as no error. - */ - if (res_info.st_size) - die("No queries executed but result file found!"); - } - + */ if (ds_res.length) { if (result_file) @@ -4475,20 +4506,37 @@ int main(int argc, char **argv) } else { - /* Check that the output from test is equal to result file */ + /* Check that the output from test is equal to result file + - detect missing result file + - detect zero size result file + */ check_result(&ds_res, result_file, 0); } } else { - /* No result_file to compare with, print the result to stdout */ + /* No result_file specified to compare with, print to stdout */ printf("%s", ds_res.str); } } else { - /* The test didn't produce any output */ + die("The test didn't produce any output"); } + + if (!query_executed && result_file && my_stat(result_file, &res_info, 0)) + { + /* + my_stat() successful on result file. Check if we have not run a + single query, but we do have a result file that contains data. + Note that we don't care, if my_stat() fails. For example for + non-existing or non-readable file we assume it's fine to have + no query output from the test file, e.g. regarded as no error. + */ + die("No queries executed but result file found!"); + } + + dynstr_free(&ds_res); if (!got_end_timer) diff --git a/mysql-test/include/have_multi_ndb.inc b/mysql-test/include/have_multi_ndb.inc index ec1a93311fb..45a551274f7 100644 --- a/mysql-test/include/have_multi_ndb.inc +++ b/mysql-test/include/have_multi_ndb.inc @@ -9,8 +9,8 @@ disable_query_log; drop table if exists t1, t2; --enable_warnings flush tables; -@r/have_ndb.require show variables like "have_ndbcluster"; -# @r/server_id.require show variables like "server_id"; +--require r/have_ndb.require +show variables like "have_ndbcluster"; enable_query_log; # Check that server2 has NDB support @@ -20,8 +20,8 @@ disable_query_log; drop table if exists t1, t2; --enable_warnings flush tables; -@r/have_ndb.require show variables like "have_ndbcluster"; -# @r/server_id1.require show variables like "server_id"; +--require r/have_ndb.require +show variables like "have_ndbcluster"; enable_query_log; # Set the default connection to 'server1' diff --git a/mysql-test/r/init_file.result b/mysql-test/r/init_file.result new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/mysql-test/r/init_file.result @@ -0,0 +1 @@ +ok diff --git a/mysql-test/r/mysql_client_test.result b/mysql-test/r/mysql_client_test.result new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/mysql-test/r/mysql_client_test.result @@ -0,0 +1 @@ +ok diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index df4c2091f3b..22c7fb02f00 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -331,6 +331,7 @@ mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_re mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a;' mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a' mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a ' +OK mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a b c' mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a b c ' select "a" as col1, "c" as col2; @@ -356,6 +357,7 @@ mysqltest: At line 1: Missing connection db mysqltest: At line 1: Could not open connection 'con2': Unknown database 'illegal_db' mysqltest: At line 1: Illegal argument for port: 'illegal_port' mysqltest: At line 1: Illegal option to connect: SMTP +OK mysqltest: In included file "./var/tmp/con.sql": At line 7: Connection limit exhausted - increase MAX_CONS in mysqltest.c mysqltest: In included file "./var/tmp/con.sql": At line 3: connection 'test_con1' not found in connection pool mysqltest: In included file "./var/tmp/con.sql": At line 2: Connection test_con1 already exists @@ -394,3 +396,5 @@ root@localhost -------------------------------------------------------------------------------- this will be executed this will be executed +mysqltest: Result length mismatch +mysqltest: The test didn't produce any output diff --git a/mysql-test/t/init_file.test b/mysql-test/t/init_file.test index de6aca455bd..8b4b788777b 100644 --- a/mysql-test/t/init_file.test +++ b/mysql-test/t/init_file.test @@ -7,3 +7,4 @@ # # End of 4.1 tests +echo ok; diff --git a/mysql-test/t/mysql_client_test.test b/mysql-test/t/mysql_client_test.test index 66b57dd5fb7..9cacb008d09 100644 --- a/mysql-test/t/mysql_client_test.test +++ b/mysql-test/t/mysql_client_test.test @@ -10,3 +10,5 @@ --exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M # End of 4.1 tests +echo ok; + diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 26e25af2a8d..f229b5cdc1d 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -368,10 +368,10 @@ select 3 from t1 ; # Missing delimiter until eof # The comment will be "sucked into" the sleep command since # delimiter is missing ---system echo "sleep 7" > var/log/mysqltest.sql ---system echo "# Another comment" >> var/log/mysqltest.sql +--system echo "sleep 7" > var/tmp/mysqltest.sql +--system echo "# Another comment" >> var/tmp/mysqltest.sql --error 1 ---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +--exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1 # # Extra delimiter @@ -737,20 +737,20 @@ while ($i) --error 1 --exec echo "{;" | $MYSQL_TEST 2>&1 ---system echo "while (0)" > var/log/mysqltest.sql ---system echo "echo hej;" >> var/log/mysqltest.sql +--system echo "while (0)" > var/tmp/mysqltest.sql +--system echo "echo hej;" >> var/tmp/mysqltest.sql --error 1 ---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +--exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1 ---system echo "while (0)" > var/log/mysqltest.sql ---system echo "{echo hej;" >> var/log/mysqltest.sql +--system echo "while (0)" > var/tmp/mysqltest.sql +--system echo "{echo hej;" >> var/tmp/mysqltest.sql --error 1 ---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +--exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1 ---system echo "while (0){" > var/log/mysqltest.sql ---system echo "echo hej;" >> var/log/mysqltest.sql +--system echo "while (0){" > var/tmp/mysqltest.sql +--system echo "echo hej;" >> var/tmp/mysqltest.sql --error 1 ---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +--exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1 # ---------------------------------------------------------------------------- # Test error messages returned from comments starting with a command @@ -778,7 +778,7 @@ select "a" as col1, "c" as col2; --exec echo "replace_result a;" | $MYSQL_TEST 2>&1 --error 1 --exec echo "replace_result a ;" | $MYSQL_TEST 2>&1 ---exec echo "replace_result a b;" | $MYSQL_TEST 2>&1 +--exec echo "replace_result a b; echo OK;" | $MYSQL_TEST 2>&1 --error 1 --exec echo "--replace_result a b c" | $MYSQL_TEST 2>&1 --error 1 @@ -848,7 +848,7 @@ select "a" as col1, "c" as col2; --exec echo " disconnect test_con1; " >> var/tmp/con.sql --exec echo " dec \$i; " >> var/tmp/con.sql --exec echo "}" >> var/tmp/con.sql ---exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1 +--exec echo "source var/tmp/con.sql; echo OK;" | $MYSQL_TEST 2>&1 # Repeat connect/disconnect, exceed max number of connections --exec echo "let \$i=200;" > var/tmp/con.sql @@ -954,3 +954,29 @@ select "this will not be executed"; --enable_parsing select "this will be executed"; --enable_query_log + +# +# Test zero length result file. Should not pass +# +--exec touch $MYSQL_TEST_DIR/var/tmp/zero_length_file.result +--exec echo "echo ok;" > $MYSQL_TEST_DIR/var/tmp/query.sql +--error 1 +--exec $MYSQL_TEST -x var/tmp/query.sql -R var/tmp/zero_length_file.result 2>&1 +# +# Test that a test file that does not generate any output fails. +# +--exec echo "let \$i= 1;" > $MYSQL_TEST_DIR/var/tmp/query.sql +--error 1 +--exec $MYSQL_TEST -x var/tmp/query.sql 2>&1 + +# +# Test that mysqltest fails when there are no queries executed +# but a result file exist +# NOTE! This will never happen as long as it's not allowed to have +# test files that does not produce any output +#--exec echo "something" > $MYSQL_TEST_DIR/var/tmp/result_file.result +#--exec echo "let \$i= 1;" > $MYSQL_TEST_DIR/var/tmp/query.sql +#--error 1 +#--exec $MYSQL_TEST -x var/tmp/query.sql -R var/tmp/result_file.result 2>&1 + +