From f98f12582e2a026e060b47f544f16426731aaca3 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 3 Aug 2007 12:36:32 +0200 Subject: [PATCH 01/16] Send output to var/log/mysql-test-run.log to facilitate easier debugging of mysql-test-run.pl mysql-test/lib/mtr_process.pl: Change from "print" to "mtr_debug" to get messages logged to file as well mysql-test/lib/mtr_report.pl: - Add "mtr_log_init" function used for opening the log file - Change from "print" to "mtr_report" to get the messages logged - Make printout functions log to the log file mysql-test/mysql-test-run.pl: - Open the mysql-test-run log file as soon as var/log has been created - Change from "print" to "mtr_report" to get the messgages to log as well --- mysql-test/lib/mtr_process.pl | 21 ++++++------- mysql-test/lib/mtr_report.pl | 55 ++++++++++++++++++++++++++++------- mysql-test/mysql-test-run.pl | 13 +++++---- 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl index f5ef028fa24..a60b2822a14 100644 --- a/mysql-test/lib/mtr_process.pl +++ b/mysql-test/lib/mtr_process.pl @@ -99,25 +99,26 @@ sub spawn_impl ($$$$$$$) { if ( $::opt_script_debug ) { - print STDERR "\n"; - print STDERR "#### ", "-" x 78, "\n"; - print STDERR "#### ", "STDIN $input\n" if $input; - print STDERR "#### ", "STDOUT $output\n" if $output; - print STDERR "#### ", "STDERR $error\n" if $error; - print STDERR "#### ", "$mode : $path ", join(" ",@$arg_list_t), "\n"; - print STDERR "#### ", "spawn options:\n"; + mtr_report(""); + mtr_debug("-" x 73); + mtr_debug("STDIN $input") if $input; + mtr_debug("STDOUT $output") if $output; + mtr_debug("STDERR $error") if $error; + mtr_debug("$mode: $path ", join(" ",@$arg_list_t)); + mtr_debug("spawn options:"); if ($spawn_opts) { foreach my $key (sort keys %{$spawn_opts}) { - print STDERR "#### ", " - $key: $spawn_opts->{$key}\n"; + mtr_debug(" - $key: $spawn_opts->{$key}"); } } else { - print STDERR "#### ", " none\n"; + mtr_debug(" none"); } - print STDERR "#### ", "-" x 78, "\n"; + mtr_debug("-" x 73); + mtr_report(""); } mtr_error("Can't spawn with empty \"path\"") unless defined $path; diff --git a/mysql-test/lib/mtr_report.pl b/mysql-test/lib/mtr_report.pl index 1abfc6b6b57..0493ecad329 100644 --- a/mysql-test/lib/mtr_report.pl +++ b/mysql-test/lib/mtr_report.pl @@ -19,6 +19,7 @@ # same name. use strict; +use warnings; sub mtr_report_test_name($); sub mtr_report_test_passed($); @@ -97,6 +98,7 @@ sub mtr_show_failed_diff ($) { sub mtr_report_test_name ($) { my $tinfo= shift; + _mtr_log("$tinfo->{name}"); printf "%-30s ", $tinfo->{'name'}; } @@ -106,15 +108,15 @@ sub mtr_report_test_skipped ($) { $tinfo->{'result'}= 'MTR_RES_SKIPPED'; if ( $tinfo->{'disable'} ) { - print "[ disabled ] $tinfo->{'comment'}\n"; + mtr_report("[ disabled ] $tinfo->{'comment'}"); } elsif ( $tinfo->{'comment'} ) { - print "[ skipped ] $tinfo->{'comment'}\n"; + mtr_report("[ skipped ] $tinfo->{'comment'}"); } else { - print "[ skipped ]\n"; + mtr_report("[ skipped ]"); } } @@ -146,7 +148,7 @@ sub mtr_report_test_passed ($) { $timer= sprintf "%12s", $timer; } $tinfo->{'result'}= 'MTR_RES_PASSED'; - print "[ pass ] $timer\n"; + mtr_report("[ pass ] $timer"); } sub mtr_report_test_failed ($) { @@ -155,17 +157,17 @@ sub mtr_report_test_failed ($) { $tinfo->{'result'}= 'MTR_RES_FAILED'; if ( defined $tinfo->{'timeout'} ) { - print "[ fail ] timeout\n"; + mtr_report("[ fail ] timeout"); return; } else { - print "[ fail ]\n"; + mtr_report("[ fail ]"); } if ( $tinfo->{'comment'} ) { - print "\nERROR: $tinfo->{'comment'}\n"; + mtr_report("\nERROR: $tinfo->{'comment'}"); } elsif ( -f $::path_timefile ) { @@ -175,7 +177,7 @@ sub mtr_report_test_failed ($) { } else { - print "\nUnexpected termination, probably when starting mysqld\n"; + mtr_report("\nUnexpected termination, probably when starting mysqld");; } } @@ -243,8 +245,8 @@ sub mtr_report_stats ($) { if ( $::opt_timer ) { - print - "Spent $::glob_tot_real_time seconds actually executing testcases\n" + printf("Spent %.3f seconds actually executing testcases\n", + $::glob_tot_real_time); } # ---------------------------------------------------------------------- @@ -397,35 +399,66 @@ sub mtr_print_header () { ############################################################################## # -# Misc +# Log and reporting functions # ############################################################################## +use IO::File; + +my $log_file_ref= undef; + +sub mtr_log_init ($) { + my ($filename)= @_; + + mtr_error("Log is already open") if defined $log_file_ref; + + $log_file_ref= IO::File->new($filename, "a") or + mtr_warning("Could not create logfile $filename: $!"); +} + +sub _mtr_log (@) { + print $log_file_ref join(" ", @_),"\n" + if defined $log_file_ref; +} + sub mtr_report (@) { + # Print message to screen and log + _mtr_log(@_); print join(" ", @_),"\n"; } sub mtr_warning (@) { + # Print message to screen and log + _mtr_log("WARNING: ", @_); print STDERR "mysql-test-run: WARNING: ",join(" ", @_),"\n"; } sub mtr_error (@) { + # Print message to screen and log + _mtr_log("ERROR: ", @_); print STDERR "mysql-test-run: *** ERROR: ",join(" ", @_),"\n"; mtr_exit(1); } sub mtr_child_error (@) { + # Print message to screen and log + _mtr_log("ERROR(child): ", @_); print STDERR "mysql-test-run: *** ERROR(child): ",join(" ", @_),"\n"; exit(1); } sub mtr_debug (@) { + # Only print if --script-debug is used if ( $::opt_script_debug ) { + _mtr_log("###: ", @_); print STDERR "####: ",join(" ", @_),"\n"; } } + sub mtr_verbose (@) { + # Always print to log, print to screen only when --verbose is used + _mtr_log("> ",@_); if ( $::opt_verbose ) { print STDERR "> ",join(" ", @_),"\n"; diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index c58ed308bd8..208127358c2 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2891,6 +2891,9 @@ sub initialize_servers () { } } check_running_as_root(); + + mtr_log_init("$opt_vardir/log/mysql-test-run.log"); + } sub mysql_install_db () { @@ -3612,13 +3615,13 @@ sub report_failure_and_restart ($) { # Restore the snapshot of the installed test db restore_installed_db($tinfo->{'name'}); - print "Resuming Tests\n\n"; + mtr_report("Resuming Tests\n"); return; } my $test_mode= join(" ", @::glob_test_mode) || "default"; - print "Aborting: $tinfo->{'name'} failed in $test_mode mode. "; - print "To continue, re-run with '--force'.\n"; + mtr_report("Aborting: $tinfo->{'name'} failed in $test_mode mode. "); + mtr_report("To continue, re-run with '--force'."); if ( ! $glob_debugger and ! $opt_extern and ! $glob_use_embedded_server ) @@ -4076,11 +4079,11 @@ sub mysqld_start ($$$) { sub stop_all_servers () { - print "Stopping All Servers\n"; + mtr_report("Stopping All Servers"); if ( ! $opt_skip_im ) { - print "Shutting-down Instance Manager\n"; + mtr_report("Shutting-down Instance Manager"); unless (mtr_im_stop($instance_manager, "stop_all_servers")) { mtr_error("Failed to stop Instance Manager.") From 78a3a625cf949eea90141f4d0cc693bc77ce9aef Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 3 Aug 2007 12:50:00 +0200 Subject: [PATCH 02/16] Improve report on test execution time Define tot_real_tim locally in mtr_report.pl mysql-test/mysql-test-run.pl: Move global variable to local scope in the file it's being used --- mysql-test/lib/mtr_report.pl | 11 ++++++++--- mysql-test/mysql-test-run.pl | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mysql-test/lib/mtr_report.pl b/mysql-test/lib/mtr_report.pl index 1abfc6b6b57..69a7abec465 100644 --- a/mysql-test/lib/mtr_report.pl +++ b/mysql-test/lib/mtr_report.pl @@ -38,6 +38,9 @@ sub mtr_child_error (@); sub mtr_debug (@); sub mtr_verbose (@); +my $tot_real_time= 0; + + ############################################################################## # @@ -142,7 +145,7 @@ sub mtr_report_test_passed ($) { if ( $::opt_timer and -f "$::opt_vardir/log/timer" ) { $timer= mtr_fromfile("$::opt_vardir/log/timer"); - $::glob_tot_real_time += ($timer/1000); + $tot_real_time += ($timer/1000); $timer= sprintf "%12s", $timer; } $tinfo->{'result'}= 'MTR_RES_PASSED'; @@ -243,8 +246,10 @@ sub mtr_report_stats ($) { if ( $::opt_timer ) { - print - "Spent $::glob_tot_real_time seconds actually executing testcases\n" + use English; + + mtr_report("Spent", sprintf("%.3f", $tot_real_time),"of", + time - $BASETIME, "seconds executing testcases"); } # ---------------------------------------------------------------------- diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 43b1ef7ac86..b072298756f 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -307,7 +307,6 @@ our @data_dir_lst; our $used_binlog_format; our $used_default_engine; our $debug_compiled_binaries; -our $glob_tot_real_time= 0; our %mysqld_variables; From a1552e8f8da5fc3edb3734be72c2e1f7a7ae3ebb Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 3 Aug 2007 12:54:06 +0200 Subject: [PATCH 03/16] Remove the temporary file created by mysql_upgrade client/mysql_upgrade.c: Remove the temporary file after it's been used --- client/mysql_upgrade.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 64de3d19882..13f5d2606a9 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -457,6 +457,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res, NULL); my_close(fd, MYF(0)); + my_delete(query_file_path, MYF(0)); DBUG_RETURN(ret); } From 8b265ffcc1222be7b19c1f1ca908acca847f8a6b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 3 Aug 2007 12:56:45 +0200 Subject: [PATCH 04/16] Cleanup created procedures in sp.test mysql-test/r/sp.result: Cleanup created procedures mysql-test/t/sp.test: Cleanup created procedures --- mysql-test/r/sp.result | 1 + mysql-test/t/sp.test | 1 + 2 files changed, 2 insertions(+) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 7a4deb3ea5f..481ddcd838e 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5743,6 +5743,7 @@ bug23760_rc_test(ROW_COUNT()) DROP TABLE bug23760, bug23760_log| DROP PROCEDURE bug23760_update_log| DROP PROCEDURE bug23760_test_row_count| +DROP PROCEDURE bug23760_test_row_count2| DROP FUNCTION bug23760_rc_test| DROP PROCEDURE IF EXISTS bug24117| DROP TABLE IF EXISTS t3| diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index ef66f1c98f0..c98d12a34a6 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -6710,6 +6710,7 @@ SELECT bug23760_rc_test(ROW_COUNT())| DROP TABLE bug23760, bug23760_log| DROP PROCEDURE bug23760_update_log| DROP PROCEDURE bug23760_test_row_count| +DROP PROCEDURE bug23760_test_row_count2| DROP FUNCTION bug23760_rc_test| # From 2cedc54d335b99c7e755981fe3cfc1f8f4ab61dd Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 3 Aug 2007 13:12:53 +0200 Subject: [PATCH 05/16] WL#3935 Improve mysqltest report and exitcode for diff - Move the code to generate test report to the test tool(in this case mysqltest) where the best control of what failed is - Simplify the code in mysql-test-run.pl - mysqltest will now find what diff to use in a best effort attempt using "diff -u", "diff -c" and finally dumping the two files verbatim in the report. client/mysqltest.c: - Add new option --tail-lines indicating how many lines of the result to output when generating report for a failure - Remove eval_result, noone knows what it should do and it's not used. - Add support for best effort execution of systems builtin "diff", try with "diff -u" and "diff -c" and if that fails dump the whole content of teh two files to report - Use one common function when comapring two files, used when test has completed and the result should be compared to the .result file as well as using it from myqltest's builtin diff_files command. - Output the last lines og the result so far in the report that mysqltest generates in case of a test failure. mysql-test/lib/mtr_report.pl: - Remove code for generating diff between .reject and .result file, that is handled by mysqltest(or the test tool) from now on. - Add better comments mysql-test/mysql-test-run.pl: - Remove the --udiff flag to mysql-test-run.pl, if the systems diff supports unified diff it will be used automatically - Remove the code for "mtr_show_failed_diff", the report from mysqltest will know include the diff so if mysqltest(or another test tool) fails, just display it's report what went wrong - Pass --tail-lines=20 to mysqltest to it will shos the last 20 lines from the result in the report in case of failure. mysql-test/r/mysqltest.result: Update result file now when the output from mysqltest has been sent to /dev/null mysql-test/t/mysqltest.test: - Improve tests for --diff_files - Remove temporary files in var/tmp generated in the fly - Send output from test for --diff_files to /deb/null since only the error code it returns are of interest and tyhe outpu may vary depending on what builtin diff is being used. --- client/mysqltest.c | 561 +++++++++++++++++++++++++--------- mysql-test/lib/mtr_report.pl | 61 +--- mysql-test/mysql-test-run.pl | 9 +- mysql-test/r/mysqltest.result | 3 +- mysql-test/t/mysqltest.test | 57 +++- 5 files changed, 479 insertions(+), 212 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index d1ec753b54b..337a31ad7af 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -74,18 +74,12 @@ #define QUERY_SEND_FLAG 1 #define QUERY_REAP_FLAG 2 - enum { - RESULT_OK= 0, - RESULT_CONTENT_MISMATCH= 1, - RESULT_LENGTH_MISMATCH= 2 - }; - enum { OPT_SKIP_SAFEMALLOC=256, OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH, OPT_SSL_CIPHER, OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL, OPT_SSL_VERIFY_SERVER_CERT, OPT_MAX_CONNECT_RETRIES, - OPT_MARK_PROGRESS, OPT_CHARSETS_DIR, OPT_LOG_DIR + OPT_MARK_PROGRESS, OPT_CHARSETS_DIR, OPT_LOG_DIR, OPT_TAIL_LINES }; static int record= 0, opt_sleep= -1; @@ -117,6 +111,9 @@ static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer; static uint start_lineno= 0; /* Start line of current command */ +/* Number of lines of the result to include in failure report */ +static uint opt_tail_lines= 0; + static char delimiter[MAX_DELIMITER_LENGTH]= ";"; static uint delimiter_length= 1; @@ -455,7 +452,6 @@ void free_tmp_sh_file(); void free_win_path_patterns(); #endif -static int eval_result = 0; /* For replace_column */ static char *replace_column[MAX_COLUMNS]; @@ -881,6 +877,24 @@ void die(const char *fmt, ...) fprintf(stderr, "\n"); fflush(stderr); + /* Show results from queries just before failure */ + if (ds_res.length && opt_tail_lines) + { + int tail_lines= opt_tail_lines; + char* show_from= ds_res.str + ds_res.length - 1; + while(show_from > ds_res.str && tail_lines > 0 ) + { + show_from--; + if (*show_from == '\n') + tail_lines--; + } + fprintf(stderr, "\nThe result from queries just before the failure was:\n"); + if (show_from > ds_res.str) + fprintf(stderr, "< snip >"); + fprintf(stderr, "%s", show_from); + fflush(stderr); + } + /* Dump the result that has been accumulated so far to .log file */ if (result_file_name && ds_res.length) dump_result_to_log_file(ds_res.str, ds_res.length); @@ -1009,77 +1023,372 @@ void log_msg(const char *fmt, ...) /* - Compare content of the string ds to content of file fname + Read a file and append it to ds + + SYNOPSIS + cat_file + ds - pointer to dynamic string where to add the files content + filename - name of the file to read + +*/ + +void cat_file(DYNAMIC_STRING* ds, const char* filename) +{ + int fd; + uint len; + char buff[512]; + + if ((fd= my_open(filename, O_RDONLY, MYF(0))) < 0) + die("Failed to open file %s", filename); + while((len= my_read(fd, (byte*)&buff, + sizeof(buff), MYF(0))) > 0) + { + char *p= buff, *start= buff; + while (p < buff+len) + { + /* Convert cr/lf to lf */ + if (*p == '\r' && *(p+1) && *(p+1)== '\n') + { + /* Add fake newline instead of cr and output the line */ + *p= '\n'; + p++; /* Step past the "fake" newline */ + dynstr_append_mem(ds, start, p-start); + p++; /* Step past the "fake" newline */ + start= p; + } + else + p++; + } + /* Output any chars that migh be left */ + dynstr_append_mem(ds, start, p-start); + } + my_close(fd, MYF(0)); +} + + +/* + Run the specified command with popen + + SYNOPSIS + run_command + cmd - command to execute(should be properly quoted + ds_res- pointer to dynamic string where to store the result + +*/ + +static int run_command(char* cmd, + DYNAMIC_STRING *ds_res) +{ + char buf[512]= {0}; + FILE *res_file; + int error; + + if (!(res_file= popen(cmd, "r"))) + die("popen(\"%s\", \"r\") failed", cmd); + + while (fgets(buf, sizeof(buf), res_file)) + { + DBUG_PRINT("info", ("buf: %s", buf)); + if(ds_res) + { + /* Save the output of this command in the supplied string */ + dynstr_append(ds_res, buf); + } + else + { + /* Print it directly on screen */ + fprintf(stdout, "%s", buf); + } + } + + error= pclose(res_file); + return WEXITSTATUS(error); +} + + +/* + Run the specified tool with variable number of arguments + + SYNOPSIS + run_tool + tool_path - the name of the tool to run + ds_res - pointer to dynamic string where to store the result + ... - variable number of arguments that will be properly + quoted and appended after the tool's name + +*/ + +static int run_tool(const char *tool_path, DYNAMIC_STRING *ds_res, ...) +{ + int ret; + const char* arg; + va_list args; + DYNAMIC_STRING ds_cmdline; + + DBUG_ENTER("run_tool"); + DBUG_PRINT("enter", ("tool_path: %s", tool_path)); + + if (init_dynamic_string(&ds_cmdline, IF_WIN("\"", ""), FN_REFLEN, FN_REFLEN)) + die("Out of memory"); + + dynstr_append_os_quoted(&ds_cmdline, tool_path, NullS); + dynstr_append(&ds_cmdline, " "); + + va_start(args, ds_res); + + while ((arg= va_arg(args, char *))) + { + /* Options should be os quoted */ + if (strncmp(arg, "--", 2) == 0) + dynstr_append_os_quoted(&ds_cmdline, arg, NullS); + else + dynstr_append(&ds_cmdline, arg); + dynstr_append(&ds_cmdline, " "); + } + + va_end(args); + +#ifdef __WIN__ + dynstr_append(&ds_cmdline, "\""); +#endif + + DBUG_PRINT("info", ("Running: %s", ds_cmdline.str)); + ret= run_command(ds_cmdline.str, ds_res); + DBUG_PRINT("exit", ("ret: %d", ret)); + dynstr_free(&ds_cmdline); + DBUG_RETURN(ret); +} + + +/* + Show the diff of two files using the systems builtin diff + command. If no such diff command exist, just dump the content + of the two files and inform about how to get "diff" + + SYNOPSIS + show_diff + ds - pointer to dynamic string where to add the diff(may be NULL) + filename1 - name of first file + filename2 - name of second file + +*/ + +void show_diff(DYNAMIC_STRING* ds, + const char* filename1, const char* filename2) +{ + + DYNAMIC_STRING ds_tmp; + + if (init_dynamic_string(&ds_tmp, "", 256, 256)) + die("Out of memory"); + + /* First try with unified diff */ + if (run_tool("diff", + &ds_tmp, /* Get output from diff in ds_tmp */ + "-u", + filename1, + filename2, + "2>&1", + NULL) > 1) /* Most "diff" tools return >1 if error */ + { + dynstr_set(&ds_tmp, ""); + + /* Fallback to context diff with "diff -c" */ + if (run_tool("diff", + &ds_tmp, /* Get output from diff in ds_tmp */ + "-c", + filename1, + filename2, + "2>&1", + NULL) > 1) /* Most "diff" tools return >1 if error */ + { + /* + Fallback to dump both files to result file and inform + about installing "diff" + */ + dynstr_set(&ds_tmp, ""); + + dynstr_append(&ds_tmp, +"\n" +"The two files differ but it was not possible to execute 'diff' in\n" +"order to show only the difference, tried both 'diff -u' or 'diff -c'.\n" +"Instead the whole content of the two files was shown for you to diff manually. ;)\n\n" +"To get a better report you should install 'diff' on your system, which you\n" +"for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n" +#ifdef __WIN__ +"or http://gnuwin32.sourceforge.net/packages/diffutils.htm\n" +#endif +"\n"); + + dynstr_append(&ds_tmp, " --- "); + dynstr_append(&ds_tmp, filename1); + dynstr_append(&ds_tmp, " >>>\n"); + cat_file(&ds_tmp, filename1); + dynstr_append(&ds_tmp, "<<<\n --- "); + dynstr_append(&ds_tmp, filename1); + dynstr_append(&ds_tmp, " >>>\n"); + cat_file(&ds_tmp, filename2); + dynstr_append(&ds_tmp, "<<<<\n"); + } + } + + if (ds) + { + /* Add the diff to output */ + dynstr_append_mem(ds, ds_tmp.str, ds_tmp.length); + } + else + { + /* Print diff directly to stdout */ + fprintf(stderr, "%s", ds_tmp.str); + } + + dynstr_free(&ds_tmp); + +} + + +enum compare_files_result_enum { + RESULT_OK= 0, + RESULT_CONTENT_MISMATCH= 1, + RESULT_LENGTH_MISMATCH= 2 +}; + +/* + Compare two files, given a fd to the first file and + name of the second file + + SYNOPSIS + compare_files2 + fd - Open file descriptor of the first file + filename2 - Name of second file + + RETURN VALUES + According to the values in "compare_files_result_enum" + +*/ + +int compare_files2(File fd, const char* filename2) +{ + int error= RESULT_OK; + File fd2; + uint len, len2; + char buff[512], buff2[512]; + + if ((fd2= my_open(filename2, O_RDONLY, MYF(0))) < 0) + { + my_close(fd, MYF(0)); + die("Failed to open second file: %s", filename2); + } + while((len= my_read(fd, (byte*)&buff, + sizeof(buff), MYF(0))) > 0) + { + if ((len2= my_read(fd2, (byte*)&buff2, + sizeof(buff2), MYF(0))) < len) + { + /* File 2 was smaller */ + error= RESULT_LENGTH_MISMATCH; + break; + } + if (len2 > len) + { + /* File 1 was smaller */ + error= RESULT_LENGTH_MISMATCH; + break; + } + if ((memcmp(buff, buff2, len))) + { + /* Content of this part differed */ + error= RESULT_CONTENT_MISMATCH; + break; + } + } + if (!error && my_read(fd2, (byte*)&buff2, + sizeof(buff2), MYF(0)) > 0) + { + /* File 1 was smaller */ + error= RESULT_LENGTH_MISMATCH; + } + + my_close(fd2, MYF(0)); + + return error; +} + + +/* + Compare two files, given their filenames + + SYNOPSIS + compare_files + filename1 - Name of first file + filename2 - Name of second file + + RETURN VALUES + See 'compare_files2' + +*/ + +int compare_files(const char* filename1, const char* filename2) +{ + File fd; + int error; + + if ((fd= my_open(filename1, O_RDONLY, MYF(0))) < 0) + die("Failed to open first file: %s", filename1); + + error= compare_files2(fd, filename2); + + my_close(fd, MYF(0)); + + return error; +} + + +/* + Compare content of the string in ds to content of file fname + + SYNOPSIS + dyn_string_cmp + ds - Dynamic string containing the string o be compared + fname - Name of file to compare with + + RETURN VALUES + See 'compare_files2' */ int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) { - MY_STAT stat_info; - char *tmp, *res_ptr; - char eval_file[FN_REFLEN]; - int res; - uint res_len; - int fd; - DYNAMIC_STRING res_ds; + int error; + File fd; + char ds_temp_file_path[FN_REFLEN]; + DBUG_ENTER("dyn_string_cmp"); + DBUG_PRINT("enter", ("fname: %s", fname)); - if (!test_if_hard_path(fname)) - { - strxmov(eval_file, opt_basedir, fname, NullS); - fn_format(eval_file, eval_file, "", "", MY_UNPACK_FILENAME); - } - else - fn_format(eval_file, fname, "", "", MY_UNPACK_FILENAME); + if ((fd= create_temp_file(ds_temp_file_path, NULL, + "tmp", O_CREAT | O_SHARE | O_RDWR, + MYF(MY_WME))) < 0) + die("Failed to create temporary file for ds"); - if (!my_stat(eval_file, &stat_info, MYF(MY_WME))) - die(NullS); - if (!eval_result && (uint) stat_info.st_size != ds->length) + /* Write ds to temporary file and set file pos to beginning*/ + if (my_write(fd, ds->str, ds->length, + MYF(MY_FNABP | MY_WME)) || + my_seek(fd, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR) { - DBUG_PRINT("info",("Size differs: result size: %u file size: %lu", - ds->length, (ulong) stat_info.st_size)); - DBUG_PRINT("info",("result: '%s'", ds->str)); - DBUG_RETURN(RESULT_LENGTH_MISMATCH); - } - if (!(tmp = (char*) my_malloc(stat_info.st_size + 1, MYF(MY_WME)))) - die("Out of memory"); - - if ((fd = my_open(eval_file, O_RDONLY, MYF(MY_WME))) < 0) - die("Failed to open file %s", eval_file); - if (my_read(fd, (byte*)tmp, stat_info.st_size, MYF(MY_WME|MY_NABP))) - die("Failed to read from file %s, errno: %d", eval_file, errno); - tmp[stat_info.st_size] = 0; - init_dynamic_string(&res_ds, "", stat_info.st_size+256, 256); - if (eval_result) - { - do_eval(&res_ds, tmp, tmp + stat_info.st_size, FALSE); - res_ptr= res_ds.str; - res_len= res_ds.length; - if (res_len != ds->length) - { - res= RESULT_LENGTH_MISMATCH; - goto err; - } - } - else - { - res_ptr = tmp; - res_len = stat_info.st_size; + my_close(fd, MYF(0)); + /* Remove the temporary file */ + my_delete(ds_temp_file_path, MYF(0)); + die("Failed to write to '%s'", ds_temp_file_path); } - res= (memcmp(res_ptr, ds->str, res_len)) ? - RESULT_CONTENT_MISMATCH : RESULT_OK; + error= compare_files2(fd, fname); -err: - if (res && eval_result) - str_to_file(fn_format(eval_file, fname, "", ".eval", - MY_REPLACE_EXT), - res_ptr, res_len); + my_close(fd, MYF(0)); + /* Remove the temporary file */ + my_delete(ds_temp_file_path, MYF(0)); - dynstr_free(&res_ds); - my_free((gptr) tmp, MYF(0)); - my_close(fd, MYF(MY_WME)); - - DBUG_RETURN(res); + DBUG_RETURN(error); } @@ -1097,21 +1406,34 @@ err: void check_result(DYNAMIC_STRING* ds) { + const char* mess= "Result content mismatch\n"; + DBUG_ENTER("check_result"); DBUG_ASSERT(result_file_name); + DBUG_PRINT("enter", ("result_file_name: %s", result_file_name)); switch (dyn_string_cmp(ds, result_file_name)) { case RESULT_OK: break; /* ok */ case RESULT_LENGTH_MISMATCH: - dump_result_to_reject_file(ds->str, ds->length); - die("Result length mismatch"); - break; + mess= "Result length mismatch\n"; + /* Fallthrough */ case RESULT_CONTENT_MISMATCH: - dump_result_to_reject_file(ds->str, ds->length); - die("Result content mismatch"); + { + /* Result mismatched, dump results to .reject file and then show the diff */ + char reject_file[FN_REFLEN]; + fn_format(reject_file, result_file_name, "", ".reject", + MY_REPLACE_EXT); + DBUG_PRINT("enter", ("reject_file_name: %s", reject_file)); + str_to_file(reject_file, ds->str, ds->length); + + dynstr_set(ds, NULL); /* Don't create a .log file */ + + show_diff(NULL, result_file_name, reject_file); + die(mess); break; + } default: /* impossible */ die("Unknown error code from dyn_string_cmp()"); } @@ -1126,7 +1448,7 @@ void check_result(DYNAMIC_STRING* ds) indicating that test is not supported SYNOPSIS - check_result + check_require ds - content to be checked fname - name of file to check against @@ -1530,7 +1852,7 @@ void var_query_set(VAR *var, const char *query, const char** query_end) void var_set_query_get_value(struct st_command *command, VAR *var) { - ulong row_no; + long row_no; int col_no= -1; MYSQL_RES* res; MYSQL* mysql= &cur_con->mysql; @@ -1602,7 +1924,7 @@ void var_set_query_get_value(struct st_command *command, VAR *var) { /* Get the value */ MYSQL_ROW row; - ulong rows= 0; + long rows= 0; const char* value= "No such row"; while ((row= mysql_fetch_row(res))) @@ -2438,9 +2760,6 @@ void do_append_file(struct st_command *command) void do_cat_file(struct st_command *command) { - int fd; - uint len; - char buff[512]; static DYNAMIC_STRING ds_filename; const struct command_arg cat_file_args[] = { "filename", ARG_STRING, TRUE, &ds_filename, "File to read from" @@ -2455,37 +2774,13 @@ void do_cat_file(struct st_command *command) DBUG_PRINT("info", ("Reading from, file: %s", ds_filename.str)); - if ((fd= my_open(ds_filename.str, O_RDONLY, MYF(0))) < 0) - die("Failed to open file %s", ds_filename.str); - while((len= my_read(fd, (byte*)&buff, - sizeof(buff), MYF(0))) > 0) - { - char *p= buff, *start= buff; - while (p < buff+len) - { - /* Convert cr/lf to lf */ - if (*p == '\r' && *(p+1) && *(p+1)== '\n') - { - /* Add fake newline instead of cr and output the line */ - *p= '\n'; - p++; /* Step past the "fake" newline */ - dynstr_append_mem(&ds_res, start, p-start); - p++; /* Step past the "fake" newline */ - start= p; - } - else - p++; - } - /* Output any chars that migh be left */ - dynstr_append_mem(&ds_res, start, p-start); - } - my_close(fd, MYF(0)); + cat_file(&ds_res, ds_filename.str); + dynstr_free(&ds_filename); DBUG_VOID_RETURN; } - /* SYNOPSIS do_diff_files @@ -2501,9 +2796,6 @@ void do_cat_file(struct st_command *command) void do_diff_files(struct st_command *command) { int error= 0; - int fd, fd2; - uint len, len2; - char buff[512], buff2[512]; static DYNAMIC_STRING ds_filename; static DYNAMIC_STRING ds_filename2; const struct command_arg diff_file_args[] = { @@ -2518,39 +2810,14 @@ void do_diff_files(struct st_command *command) sizeof(diff_file_args)/sizeof(struct command_arg), ' '); - if ((fd= my_open(ds_filename.str, O_RDONLY, MYF(0))) < 0) - die("Failed to open first file %s", ds_filename.str); - if ((fd2= my_open(ds_filename2.str, O_RDONLY, MYF(0))) < 0) + if ((error= compare_files(ds_filename.str, ds_filename2.str))) { - my_close(fd, MYF(0)); - die("Failed to open second file %s", ds_filename2.str); - } - while((len= my_read(fd, (byte*)&buff, - sizeof(buff), MYF(0))) > 0) - { - if ((len2= my_read(fd2, (byte*)&buff2, - sizeof(buff2), MYF(0))) != len) - { - /* File 2 was smaller */ - error= 1; - break; - } - if ((memcmp(buff, buff2, len))) - { - /* Content of this part differed */ - error= 1; - break; - } - } - if (my_read(fd2, (byte*)&buff2, - sizeof(buff2), MYF(0)) > 0) - { - /* File 1 was smaller */ - error= 1; + /* Compare of the two files failed, append them to output + so the failure can be analyzed + */ + show_diff(&ds_res, ds_filename.str, ds_filename2.str); } - my_close(fd, MYF(0)); - my_close(fd2, MYF(0)); dynstr_free(&ds_filename); dynstr_free(&ds_filename2); handle_command_error(command, error); @@ -4408,7 +4675,7 @@ void check_eol_junk(const char *eol) terminated by new line '\n' regardless how many "delimiter" it contain. */ -#define MAX_QUERY (256*1024) /* 256K -- a test in sp-big is >128K */ +#define MAX_QUERY (256*1024*2) /* 256K -- a test in sp-big is >128K */ static char read_command_buf[MAX_QUERY]; int read_command(struct st_command** command_ptr) @@ -4542,6 +4809,10 @@ static struct my_option my_long_options[] = {"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select", (gptr*) &sp_protocol, (gptr*) &sp_protocol, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"tail-lines", OPT_TAIL_LINES, + "Number of lines of the resul to include in a failure report", + (gptr*) &opt_tail_lines, (gptr*) &opt_tail_lines, 0, + GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0}, #include "sslopt-longopts.h" {"test-file", 'x', "Read test from/in this file (default stdin).", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -4793,14 +5064,6 @@ void str_to_file(const char *fname, char *str, int size) } -void dump_result_to_reject_file(char *buf, int size) -{ - char reject_file[FN_REFLEN]; - str_to_file(fn_format(reject_file, result_file_name, "", ".reject", - MY_REPLACE_EXT), - buf, size); -} - void dump_result_to_log_file(char *buf, int size) { char log_file[FN_REFLEN]; @@ -4808,6 +5071,8 @@ void dump_result_to_log_file(char *buf, int size) *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT : MY_REPLACE_EXT), buf, size); + fprintf(stderr, "\nMore results from queries before failure can be found in %s\n", + log_file); } void dump_progress(void) @@ -5792,7 +6057,7 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags) init_dynamic_string(&ds_warnings, NULL, 0, 256); - /* Scan for warning before sendign to server */ + /* Scan for warning before sending to server */ scan_command_for_warnings(command); /* @@ -6424,7 +6689,7 @@ int main(int argc, char **argv) break; case Q_LET: do_let(command); break; case Q_EVAL_RESULT: - eval_result = 1; break; + die("'eval_result' command is deprecated"); case Q_EVAL: case Q_QUERY_VERTICAL: case Q_QUERY_HORIZONTAL: diff --git a/mysql-test/lib/mtr_report.pl b/mysql-test/lib/mtr_report.pl index 1abfc6b6b57..aa83d42acc7 100644 --- a/mysql-test/lib/mtr_report.pl +++ b/mysql-test/lib/mtr_report.pl @@ -26,7 +26,6 @@ sub mtr_report_test_failed($); sub mtr_report_test_skipped($); sub mtr_report_test_not_skipped_though_disabled($); -sub mtr_show_failed_diff ($); sub mtr_report_stats ($); sub mtr_print_line (); sub mtr_print_thick_line (); @@ -45,55 +44,6 @@ sub mtr_verbose (@); # ############################################################################## -# We can't use diff -u or diff -a as these are not portable - -sub mtr_show_failed_diff ($) { - my $result_file_name= shift; - - # The reject and log files have been dumped to - # to filenames based on the result_file's name - my $tname= basename($result_file_name); - $tname=~ s/\..*$//; - - my $reject_file= "r/$tname.reject"; - my $result_file= "r/$tname.result"; - my $log_file= "r/$tname.log"; - my $eval_file= "r/$tname.eval"; - - if ( $::opt_suite ne "main" ) - { - $reject_file= "$::glob_mysql_test_dir/suite/$::opt_suite/$reject_file"; - $result_file= "$::glob_mysql_test_dir/suite/$::opt_suite/$result_file"; - $eval_file= "$::glob_mysql_test_dir/suite/$::opt_suite/$eval_file"; - $log_file= "$::glob_mysql_test_dir/suite/$::opt_suite/$log_file"; - } - - if ( -f $eval_file ) - { - $result_file= $eval_file; - } - - my $diffopts= $::opt_udiff ? "-u" : "-c"; - - if ( -f $reject_file ) - { - print "Below are the diffs between actual and expected results:\n"; - print "-------------------------------------------------------\n"; - # FIXME check result code?! - mtr_run("diff",[$diffopts,$result_file,$reject_file], "", "", "", ""); - print "-------------------------------------------------------\n"; - print "Please follow the instructions outlined at\n"; - print "http://www.mysql.com/doc/en/Reporting_mysqltest_bugs.html\n"; - print "to find the reason to this problem and how to report this.\n\n"; - } - - if ( -f $log_file ) - { - print "Result from queries before failure can be found in $log_file\n"; - # FIXME Maybe a tail -f -n 10 $log_file here - } -} - sub mtr_report_test_name ($) { my $tinfo= shift; @@ -165,16 +115,23 @@ sub mtr_report_test_failed ($) { if ( $tinfo->{'comment'} ) { + # The test failure has been detected by mysql-test-run.pl + # when starting the servers or due to other error, the reason for + # failing the test is saved in "comment" print "\nERROR: $tinfo->{'comment'}\n"; } elsif ( -f $::path_timefile ) { - print "\nErrors are (from $::path_timefile) :\n"; + # Test failure was detected by test tool and it's report + # about what failed has been saved to file. Display the report. + print "\n"; print mtr_fromfile($::path_timefile); # FIXME print_file() instead - print "\n(the last lines may be the most important ones)\n"; + print "\n"; } else { + # Neither this script or the test tool has recorded info + # about why the test has failed. Should be debugged. print "\nUnexpected termination, probably when starting mysqld\n"; } } diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index c58ed308bd8..8422d749c08 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -83,7 +83,6 @@ require "lib/mtr_io.pl"; require "lib/mtr_gcov.pl"; require "lib/mtr_gprof.pl"; require "lib/mtr_report.pl"; -require "lib/mtr_diff.pl"; require "lib/mtr_match.pl"; require "lib/mtr_misc.pl"; require "lib/mtr_stress.pl"; @@ -281,8 +280,6 @@ our $opt_wait_for_slave; our $opt_warnings; -our $opt_udiff; - our $opt_skip_ndbcluster= 0; our $opt_skip_ndbcluster_slave= 0; our $opt_with_ndbcluster= 0; @@ -619,7 +616,6 @@ sub command_line_setup () { 'start-dirty' => \$opt_start_dirty, 'start-and-exit' => \$opt_start_and_exit, 'timer!' => \$opt_timer, - 'unified-diff|udiff' => \$opt_udiff, 'user=s' => \$opt_user, 'testcase-timeout=i' => \$opt_testcase_timeout, 'suite-timeout=i' => \$opt_suite_timeout, @@ -3603,7 +3599,6 @@ sub report_failure_and_restart ($) { my $tinfo= shift; mtr_report_test_failed($tinfo); - mtr_show_failed_diff($tinfo->{'result_file'}); print "\n"; if ( $opt_force ) { @@ -4788,6 +4783,9 @@ sub run_mysqltest ($) { mtr_add_arg($args, "--test-file=%s", $tinfo->{'path'}); + # Number of lines of resut to include in failure report + mtr_add_arg($args, "--tail-lines=20"); + if ( defined $tinfo->{'result_file'} ) { mtr_add_arg($args, "--result-file=%s", $tinfo->{'result_file'}); } @@ -5199,7 +5197,6 @@ Misc options fast Don't try to clean up from earlier runs reorder Reorder tests to get fewer server restarts help Get this help text - unified-diff | udiff When presenting differences, use unified diff testcase-timeout=MINUTES Max test case run time (default $default_testcase_timeout) suite-timeout=MINUTES Max test suite run time (default $default_suite_timeout) diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 55f78d22272..300ca69f2b4 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -461,7 +461,6 @@ root@localhost -------------------------------------------------------------------------------- this will be executed this will be executed -mysqltest: Result length mismatch mysqltest: The test didn't produce any output Failing multi statement query mysqltest: At line 3: query 'create table t1 (a int primary key); @@ -473,6 +472,8 @@ mysqltest: At line 3: query 'create table t1 (a int primary key); insert into t1 values (1); select 'select-me'; insertz 'error query'' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insertz 'error query'' at line 1 + +More results from queries before failure can be found in MYSQLTEST_VARDIR/tmp/bug11731.log drop table t1; Multi statement using expected error create table t1 (a int primary key); diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index b01579dce53..9c29840ba9b 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -436,6 +436,8 @@ EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; + # # Extra delimiter # @@ -786,6 +788,7 @@ echo $var3_var3; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/recursive.sql; # Source a file with error --exec echo "garbage ;" > $MYSQLTEST_VARDIR/tmp/error.sql @@ -793,6 +796,7 @@ echo $var3_var3; --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/error.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/error.sql; # Test execution of source in a while loop --write_file $MYSQLTEST_VARDIR/tmp/sourced.inc @@ -1171,6 +1175,8 @@ EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; + # ---------------------------------------------------------------------------- # Test error messages returned from comments starting with a command # ---------------------------------------------------------------------------- @@ -1296,6 +1302,8 @@ EOF --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; + # connect when "disable_abort_on_error" caused "connection not found" --replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT --disable_abort_on_error @@ -1399,7 +1407,11 @@ select "this will be executed"; --exec touch $MYSQLTEST_VARDIR/tmp/zero_length_file.result --exec echo "echo ok;" > $MYSQLTEST_VARDIR/tmp/query.sql --error 1 ---exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/zero_length_file.result 2>&1 +--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/zero_length_file.result > /dev/null 2>&1 + +remove_file $MYSQLTEST_VARDIR/tmp/zero_length_file.result; +remove_file $MYSQLTEST_VARDIR/tmp/zero_length_file.reject; + # # Test that a test file that does not generate any output fails. # @@ -1407,6 +1419,8 @@ select "this will be executed"; --error 1 --exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/query.sql; + # # Test that mysqltest fails when there are no queries executed # but a result file exists @@ -1436,6 +1450,7 @@ echo Failing multi statement query; --exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1 drop table t1; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 --exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1 # The .out file should be non existent @@ -1462,6 +1477,9 @@ drop table t1; # The .out file should exist --exec test -s $MYSQLTEST_VARDIR/tmp/bug11731.out drop table t1; +remove_file $MYSQLTEST_VARDIR/tmp/bug11731.out; +remove_file $MYSQLTEST_VARDIR/tmp/bug11731.log; +remove_file $MYSQLTEST_VARDIR/tmp/bug11731.sql; # # Bug#19890 mysqltest: "query" command is broken @@ -1607,19 +1625,48 @@ for diff_file command of mysqltest EOF +--write_file $MYSQLTEST_VARDIR/tmp/diff4.tmp +Some data +for diff_file command +of musqltest +EOF + # Compare equal files --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp --diff_files $MYSQLTEST_VARDIR/tmp/diff2.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp -# Compare files that differ ---error 1 ---diff_files $MYSQLTEST_VARDIR/tmp/diff3.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp ---error 1 +# Write the below commands to a intermediary file and execute them with +# mysqltest in --exec, since the output will vary depending on what "diff" +# is available it is sent to /dev/null +--write_file $MYSQLTEST_VARDIR/tmp/diff.test +# Compare files that differ in size +--error 2 --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff3.tmp +--error 2 +--diff_files $MYSQLTEST_VARDIR/tmp/diff3.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp + +# Compare files that differ only in content +--error 1 +--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff4.tmp +--error 1 +--diff_files $MYSQLTEST_VARDIR/tmp/diff4.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp +EOF + +# Execute the above diffs, and send their output to /dev/null - only +# interesting to see that it returns correct error codes +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/diff.test > /dev/null 2>&1 + # Compare equal files, again... --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff1.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff2.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff3.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff4.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff.test + + # ---------------------------------------------------------------------------- # test for file_exist # ---------------------------------------------------------------------------- From 841ae6731f7979b10ec7493e2802e769bd5c01a5 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 3 Aug 2007 13:39:55 +0200 Subject: [PATCH 06/16] Add extra newline between diff and error message --- client/mysqltest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 337a31ad7af..183374ea095 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1240,7 +1240,7 @@ void show_diff(DYNAMIC_STRING* ds, else { /* Print diff directly to stdout */ - fprintf(stderr, "%s", ds_tmp.str); + fprintf(stderr, "%s\n", ds_tmp.str); } dynstr_free(&ds_tmp); From 135b586378d50124815cfd71e097ad1782117ae0 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Aug 2007 10:39:48 +0200 Subject: [PATCH 07/16] Fix spelling errors --- client/mysqltest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 337a31ad7af..0b1565af16d 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -499,11 +499,11 @@ void handle_no_error(struct st_command*); pthread_attr_t cn_thd_attrib; /* - send_one_query executes query in separate thread what is + send_one_query executes query in separate thread, which is necessary in embedded library to run 'send' in proper way. This implementation doesn't handle errors returned by mysql_send_query. It's technically possible, though - i don't see where it is needed. + I don't see where it is needed. */ pthread_handler_t send_one_query(void *arg) { From 050256c2d74b4b358670039e92b33cf2051b9559 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Aug 2007 11:20:36 +0200 Subject: [PATCH 08/16] Remove NOT_YET code Update comments Add more tests for "let from query" client/mysqltest.c: Remove NOT_YET code Update comments mysql-test/r/mysqltest.result: Add more tests for "let from query" mysql-test/t/mysqltest.test: Add more tests for "let from query" --- client/mysqltest.c | 30 ++++++------------------------ mysql-test/r/mysqltest.result | 12 ++++++++++++ mysql-test/t/mysqltest.test | 34 ++++++++++++++++++---------------- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 0b1565af16d..7e10c040851 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1777,40 +1777,22 @@ void var_query_set(VAR *var, const char *query, const char** query_end) die("Query '%s' didn't return a result set", ds_query.str); dynstr_free(&ds_query); - if ((row = mysql_fetch_row(res)) && row[0]) + if ((row= mysql_fetch_row(res)) && row[0]) { /* - Concatenate all row results with tab in between to allow us to work - with results from many columns (for example from SHOW VARIABLES) + Concatenate all fields in the first row with tab in between + and assign that string to the $variable */ DYNAMIC_STRING result; uint i; ulong *lengths; -#ifdef NOT_YET - MYSQL_FIELD *fields= mysql_fetch_fields(res); -#endif - init_dynamic_string(&result, "", 2048, 2048); + init_dynamic_string(&result, "", 512, 512); lengths= mysql_fetch_lengths(res); - for (i=0; i < mysql_num_fields(res); i++) + for (i= 0; i < mysql_num_fields(res); i++) { - if (row[0]) + if (row[i]) { -#ifdef NOT_YET - /* Add to _ */ - uint j; - char var_col_name[MAX_VAR_NAME_LENGTH]; - uint length= snprintf(var_col_name, MAX_VAR_NAME_LENGTH, - "$%s_%s", var->name, fields[i].name); - /* Convert characters not allowed in variable names to '_' */ - for (j= 1; j < length; j++) - { - if (!my_isvar(charset_info,var_col_name[j])) - var_col_name[j]= '_'; - } - var_set(var_col_name, var_col_name + length, - row[i], row[i] + lengths[i]); -#endif /* Add column to tab separated string */ dynstr_append_mem(&result, row[i], lengths[i]); } diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 300ca69f2b4..513216c062e 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -280,6 +280,18 @@ let $B = changed value of B; var2: content of variable 1 var3: content of variable 1 content of variable 1 length of var3 is longer than 0 +var1 +hi 1 hi there +var2 +2 +var2 again +2 +var3 two columns with same name +1 2 3 +var4 from query that returns NULL +var5 from query that returns no row +failing query in let +mysqltest: At line 1: Error running query 'failing query': 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'failing query' at line 1 mysqltest: At line 1: Missing required argument 'filename' to command 'source' mysqltest: At line 1: Could not open file ./non_existingFile mysqltest: In included file "MYSQLTEST_VARDIR/tmp/recursive.sql": At line 1: Source directives are nesting too deep diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 9c29840ba9b..20140307e57 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -736,38 +736,40 @@ if (`select length("$var3") > 0`) # Test to assign let from query # let $=``; # ---------------------------------------------------------------------------- ---disable_parsing echo var1; let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`; echo $var1; -echo $var1_Col; -echo $var1_Column1; -echo $var1_Col3; echo var2; let $var2= `select 2 as "Column num 2"`; echo $var2; -echo $var2_Column num 2; -echo $var2_Column; echo var2 again; let $var2= `select 2 as "Column num 2"`; echo $var2; -echo $var2_Column num 2; -echo $var2_Column_num_2; -echo $var2_Column; echo var3 two columns with same name; let $var3= `select 1 as "Col", 2 as "Col", 3 as "var3"`; echo $var3; -echo $var3_Col; -echo $var3_Col; -echo $var3_var3; -#echo failing query in let; -#--error 1 -#--exec echo "let $var2= `failing query;`" | $MYSQL_TEST 2>&1 ---enable_parsing +echo var4 from query that returns NULL; +let $var4= `select NULL`; + +echo var5 from query that returns no row; +let $var5= `SHOW VARIABLES LIKE "nonexisting_variable"`; + +echo failing query in let; +--write_file $MYSQLTEST_VARDIR/tmp/let.sql +let $var2= `failing query`; +echo $var2; +EOF + +--error 1 +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/let.sql 2>&1 + +remove_file $MYSQLTEST_VARDIR/tmp/let.sql; + + # ---------------------------------------------------------------------------- # Test source command # ---------------------------------------------------------------------------- From 275a80302173140f93579caa857a48b5e4a291ed Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Aug 2007 13:42:00 +0200 Subject: [PATCH 09/16] Add missing ' Extend buffer size to allow for longer log messages --- client/mysqltest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 7e10c040851..1659c7e6ac5 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1006,7 +1006,7 @@ void warning_msg(const char *fmt, ...) void log_msg(const char *fmt, ...) { va_list args; - char buff[512]; + char buff[1024]; size_t len; DBUG_ENTER("log_msg"); @@ -2269,7 +2269,7 @@ void do_exec(struct st_command *command) if (command->abort_on_error) { - log_msg("exec of '%s failed, error: %d, status: %d, errno: %d", + log_msg("exec of '%s' failed, error: %d, status: %d, errno: %d", ds_cmd.str, error, status, errno); die("command \"%s\" failed", command->first_argument); } From 04e8c93c20a5517cfd57ef71ea91a3cea531828b Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Aug 2007 11:40:03 +0200 Subject: [PATCH 10/16] Bug#20037 mysqltest requires cygwin on windows(part 1, new mysqltest commands) - Update comments - Make "write_file" fail if file already exist - Remove temporary files created by test cases client/mysqltest.c: Improve function comments Make write_file fail if file already exist mysql-test/r/mysqltest.result: Update test result after adding new test and updating description of argumements to chmod mysql-test/t/bootstrap.test: Remove temporary file created by testcase mysql-test/t/mysql.test: Remove temporary file created by testcase mysql-test/t/mysqladmin.test: Remove temporary file created by testcase mysql-test/t/mysqltest.test: Remove temporary file created by testcase Add test to show that "write_file" fails if file already exist mysql-test/t/sp-destruct.test: Remove temporary file created by testcase --- client/mysqltest.c | 16 +++++++++++----- mysql-test/r/mysqltest.result | 3 ++- mysql-test/t/bootstrap.test | 7 +++++-- mysql-test/t/mysql.test | 3 +++ mysql-test/t/mysqladmin.test | 3 ++- mysql-test/t/mysqltest.test | 20 ++++++++++++++++++++ mysql-test/t/sp-destruct.test | 1 + 7 files changed, 44 insertions(+), 9 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 183374ea095..a863284921a 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -2525,8 +2525,8 @@ void do_copy_file(struct st_command *command) command command handle DESCRIPTION - chmod - Change file permission of + chmod_file + Change file permission of */ @@ -2536,8 +2536,8 @@ void do_chmod_file(struct st_command *command) static DYNAMIC_STRING ds_mode; static DYNAMIC_STRING ds_file; const struct command_arg chmod_file_args[] = { - "mode", ARG_STRING, TRUE, &ds_mode, "Mode of file", - "file", ARG_STRING, TRUE, &ds_file, "Filename of file to modify" + "mode", ARG_STRING, TRUE, &ds_mode, "Mode of file(octal) ex. 0660", + "filename", ARG_STRING, TRUE, &ds_file, "Filename of file to modify" }; DBUG_ENTER("do_chmod_file"); @@ -2671,6 +2671,12 @@ void do_write_file_command(struct st_command *command, my_bool append) if (ds_delimiter.length == 0) dynstr_set(&ds_delimiter, "EOF"); + if (!append && access(ds_filename.str, F_OK) == 0) + { + /* The file should not be overwritten */ + die("File already exist: '%s'", ds_filename.str); + } + init_dynamic_string(&ds_content, "", 1024, 1024); read_until_delimiter(&ds_content, &ds_delimiter); DBUG_PRINT("info", ("Writing to file: %s", ds_filename.str)); @@ -2703,7 +2709,7 @@ void do_write_file_command(struct st_command *command, my_bool append) Write everything between the "write_file" command and 'delimiter' to "file_name" - NOTE! Overwrites existing file + NOTE! Will fail if exists Default is EOF diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 300ca69f2b4..7c63bb78967 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -521,6 +521,7 @@ drop table t1; mysqltest: At line 1: Missing required argument 'filename' to command 'remove_file' mysqltest: At line 1: Missing required argument 'filename' to command 'write_file' mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found +mysqltest: At line 1: File already exist: 'MYSQLTEST_VARDIR/tmp/test_file1.tmp' Some data for cat_file command of mysqltest @@ -531,7 +532,7 @@ mysqltest: At line 1: Missing required argument 'to_file' to command 'copy_file' mysqltest: At line 1: Missing required argument 'mode' to command 'chmod' mysqltest: At line 1: You must write a 4 digit octal number for mode mysqltest: At line 1: You must write a 4 digit octal number for mode -mysqltest: At line 1: Missing required argument 'file' to command 'chmod' +mysqltest: At line 1: Missing required argument 'filename' to command 'chmod' mysqltest: At line 1: You must write a 4 digit octal number for mode mysqltest: At line 1: You must write a 4 digit octal number for mode hello diff --git a/mysql-test/t/bootstrap.test b/mysql-test/t/bootstrap.test index 1c2952e93d0..203ba9b2914 100644 --- a/mysql-test/t/bootstrap.test +++ b/mysql-test/t/bootstrap.test @@ -9,12 +9,13 @@ drop table if exists t1; # # Check that --bootstrap reads from stdin # ---write_file $MYSQLTEST_VARDIR/tmp/bootstrap.sql +--write_file $MYSQLTEST_VARDIR/tmp/bootstrap_test.sql use test; CREATE TABLE t1(a int); EOF ---exec $MYSQLD_BOOTSTRAP_CMD < $MYSQLTEST_VARDIR/tmp/bootstrap.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 +--exec $MYSQLD_BOOTSTRAP_CMD < $MYSQLTEST_VARDIR/tmp/bootstrap_test.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 drop table t1; +remove_file $MYSQLTEST_VARDIR/tmp/bootstrap_test.sql; # # Check that --bootstrap of file with SQL error returns error @@ -28,6 +29,7 @@ EOF # Table t1 should not exists --error 1051 drop table t1; +remove_file $MYSQLTEST_VARDIR/tmp/bootstrap_error.sql; # # Bootstrap with a query larger than 2*thd->net.max_packet @@ -40,6 +42,7 @@ eval select * into outfile '$MYSQLTEST_VARDIR/tmp/long_query.sql' from t1; --enable_query_log --error 1 --exec $MYSQLD_BOOTSTRAP_CMD < $MYSQLTEST_VARDIR/tmp/long_query.sql >> $MYSQLTEST_VARDIR/tmp/bootstrap.log 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/long_query.sql; set global max_allowed_packet=@my_max_allowed_packet; drop table t1; diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index 37bbca77d9f..66bd2f67512 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -241,18 +241,21 @@ DELIMITER / SELECT 1/ EOF --exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug21412.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug21412.sql; # This should give an error... --write_file $MYSQLTEST_VARDIR/tmp/bug21412.sql DELIMITER \ EOF --exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug21412.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug21412.sql; # As should this... --write_file $MYSQLTEST_VARDIR/tmp/bug21412.sql DELIMITER \\ EOF --exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug21412.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug21412.sql; # # Some coverage of not normally used parts diff --git a/mysql-test/t/mysqladmin.test b/mysql-test/t/mysqladmin.test index 3fa03fa910e..839ecf00b60 100644 --- a/mysql-test/t/mysqladmin.test +++ b/mysql-test/t/mysqladmin.test @@ -20,7 +20,7 @@ EOF --replace_regex /.*mysqladmin.*: unknown/mysqladmin: unknown/ --error 7 --exec $MYSQLADMIN --defaults-file=$MYSQLTEST_VARDIR/tmp/bug10608.cnf -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1 - +remove_file $MYSQLTEST_VARDIR/tmp/bug10608.cnf; # When mysqladmin finds "loose-database" in .cnf file it shall print # a warning and continue @@ -32,3 +32,4 @@ EOF --replace_regex /Warning: .*mysqladmin.*: unknown/Warning: mysqladmin: unknown/ --exec $MYSQLADMIN --defaults-file=$MYSQLTEST_VARDIR/tmp/bug10608.cnf -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug10608.cnf; diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 9c29840ba9b..b892b433369 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -366,6 +366,7 @@ show status; EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until eof @@ -377,6 +378,7 @@ sleep 7 EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until "disable_query_log" @@ -391,6 +393,7 @@ disable_query_log; EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until "disable_query_log" @@ -406,6 +409,7 @@ disable_query_log; EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until eof @@ -422,6 +426,7 @@ disconnect default EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until eof @@ -1160,6 +1165,7 @@ echo hej; EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql while (0) @@ -1167,6 +1173,7 @@ while (0) EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql while (0){ @@ -1268,6 +1275,7 @@ while ($i) } EOF --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql; echo OK;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # Repeat connect/disconnect --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql @@ -1282,6 +1290,7 @@ EOF --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # Select disconnected connection --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql @@ -1292,6 +1301,7 @@ EOF --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # Connection name already used --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql @@ -1568,6 +1578,12 @@ write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp END_DELIMITER; Content for test_file1 contains EOF END_DELIMITER file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; + +# write to already exisiting file +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--error 1 +--exec echo "write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;" | $MYSQL_TEST 2>&1 + remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; # ---------------------------------------------------------------------------- @@ -1589,6 +1605,8 @@ append_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; Appended text on nonexisting file EOF +remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; + # ---------------------------------------------------------------------------- # test for cat_file # ---------------------------------------------------------------------------- @@ -1599,6 +1617,7 @@ for cat_file command of mysqltest EOF cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; --error 1 --exec echo "cat_file non_existing_file;" | $MYSQL_TEST 2>&1 @@ -1719,6 +1738,7 @@ chmod 0000 $MYSQLTEST_VARDIR/tmp/file1.tmp; #EOF chmod 0777 $MYSQLTEST_VARDIR/tmp/file1.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp; --write_file $MYSQLTEST_VARDIR/tmp/file1.tmp test2 EOF diff --git a/mysql-test/t/sp-destruct.test b/mysql-test/t/sp-destruct.test index 13ddaa43fad..c568e6bb8f4 100644 --- a/mysql-test/t/sp-destruct.test +++ b/mysql-test/t/sp-destruct.test @@ -42,6 +42,7 @@ insert into t1 values (0); flush table mysql.proc; # Thrashing the .frm file +--remove_file $MYSQLTEST_VARDIR/master-data/mysql/proc.frm --write_file $MYSQLTEST_VARDIR/master-data/mysql/proc.frm saljdfa EOF From c35318cee16459c96be5803e80e2a2d9857615b3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 7 Aug 2007 11:56:30 +0200 Subject: [PATCH 11/16] Bug#29547 mysql-test-run to retrieve warnings for failed command - Run "SHOW WARNINGS" when mysqltest fails and display all but the last warning(since it's the same as "last error") on stderr - Fix typo client/mysqltest.c: - Display any warnings produced prior to the error that caused mysqltest to die. - Fix typo "cur_con" -> "con_slot" - Move initialization of the "cur_con" pointer to just before it's initialized so it can be used to check if a connection to mysql exist. --- client/mysqltest.c | 85 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 1659c7e6ac5..1d481f33f47 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -235,7 +235,7 @@ struct st_connection #endif /*EMBEDDED_LIBRARY*/ }; struct st_connection connections[128]; -struct st_connection* cur_con, *next_con, *connections_end; +struct st_connection* cur_con= NULL, *next_con, *connections_end; /* List of commands in mysqltest @@ -604,6 +604,77 @@ void do_eval(DYNAMIC_STRING *query_eval, const char *query, } +/* + Show any warnings just before the error. Since the last error + is added to the warning stack, only print @@warning_count-1 warnings. + + NOTE! This function should be safe to call when an error + has occured and this any further errors will be ignored(although logged) + + SYNOPSIS + show_warnings_before_error + mysql - connection to use + +*/ + +static void show_warnings_before_error(MYSQL* mysql) +{ + MYSQL_RES* res; + const char* query= "SHOW WARNINGS"; + DBUG_ENTER("show_warnings_before_error"); + + if (!mysql) + DBUG_VOID_RETURN; + + if (mysql_query(mysql, query)) + { + log_msg("Error running query '%s': %d %s", + query, mysql_errno(mysql), mysql_error(mysql)); + DBUG_VOID_RETURN; + } + + if ((res= mysql_store_result(mysql)) == NULL) + { + /* No result set returned */ + DBUG_VOID_RETURN; + } + + if (mysql_num_rows(res) <= 1) + { + /* Don't display the last row, it's "last error" */ + } + else + { + MYSQL_ROW row; + unsigned int row_num= 0; + unsigned int num_fields= mysql_num_fields(res); + + fprintf(stderr, "\nWarnings from just before the error:\n"); + while ((row= mysql_fetch_row(res))) + { + unsigned int i; + unsigned long *lengths= mysql_fetch_lengths(res); + + if (++row_num >= mysql_num_rows(res)) + { + /* Don't display the last row, it's "last error" */ + break; + } + + for(i= 0; i < num_fields; i++) + { + fprintf(stderr, "%.*s ", lengths[i], + row[i] ? row[i] : "NULL"); + } + fprintf(stderr, "\n"); + } + } + mysql_free_result(res); + + DBUG_VOID_RETURN; +} + + enum arg_type { ARG_STRING, @@ -903,6 +974,13 @@ void die(const char *fmt, ...) if (result_file_name && ds_warning_messages.length) dump_warning_messages(); + /* + Help debugging by displaying any warnings that might have + been produced prior to the error + */ + if (cur_con) + show_warnings_before_error(&cur_con->mysql); + cleanup_and_exit(1); } @@ -1010,7 +1088,6 @@ void log_msg(const char *fmt, ...) size_t len; DBUG_ENTER("log_msg"); - memset(buff, 0, sizeof(buff)); va_start(args, fmt); len= my_vsnprintf(buff, sizeof(buff)-1, fmt, args); va_end(args); @@ -4044,7 +4121,7 @@ void do_connect(struct st_command *command) mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_NAME, charset_info->csname); if (opt_charsets_dir) - mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR, + mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_DIR, opt_charsets_dir); #ifdef HAVE_OPENSSL @@ -6471,7 +6548,6 @@ int main(int argc, char **argv) connections_end= connections + (sizeof(connections)/sizeof(struct st_connection)) - 1; next_con= connections + 1; - cur_con= connections; #ifdef EMBEDDED_LIBRARY /* set appropriate stack for the 'query' threads */ @@ -6547,6 +6623,7 @@ int main(int argc, char **argv) if (cursor_protocol_enabled) ps_protocol_enabled= 1; + cur_con= connections; if (!( mysql_init(&cur_con->mysql))) die("Failed in mysql_init()"); if (opt_compress) From 79b0f8d30d36d7f925ddc38a10f58c183b91bc4f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2007 09:31:45 +0200 Subject: [PATCH 12/16] Fix warning --- client/mysqltest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 4951e88849f..e5daae2ffbe 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -663,7 +663,7 @@ static void show_warnings_before_error(MYSQL* mysql) for(i= 0; i < num_fields; i++) { - fprintf(stderr, "%.*s ", lengths[i], + fprintf(stderr, "%.*s ", (int)lengths[i], row[i] ? row[i] : "NULL"); } fprintf(stderr, "\n"); From 0193dbd7f90486a2fb5447fe65d289699c50fc27 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2007 10:04:26 +0200 Subject: [PATCH 13/16] Improve comments and log messages in lib/mtr_timer.pl --- mysql-test/lib/mtr_timer.pl | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/mysql-test/lib/mtr_timer.pl b/mysql-test/lib/mtr_timer.pl index 86a9f58514f..d8b6953fb46 100644 --- a/mysql-test/lib/mtr_timer.pl +++ b/mysql-test/lib/mtr_timer.pl @@ -52,12 +52,10 @@ sub mtr_init_timers () { sub mtr_timer_start($$$) { my ($timers,$name,$duration)= @_; - mtr_verbose("mtr_timer_start: $name, $duration"); - if ( exists $timers->{'timers'}->{$name} ) { # We have an old running timer, kill it - mtr_verbose("There is an old timer running"); + mtr_warning("There is an old timer running"); mtr_timer_stop($timers,$name); } @@ -75,22 +73,22 @@ sub mtr_timer_start($$$) { } else { - mtr_error("can't fork"); + mtr_error("can't fork timer, error: $!"); } } if ( $tpid ) { # Parent, record the information - mtr_verbose("timer parent, record info($name, $tpid, $duration)"); + mtr_verbose("Starting timer for '$name',", + "duration: $duration, pid: $tpid"); $timers->{'timers'}->{$name}->{'pid'}= $tpid; $timers->{'timers'}->{$name}->{'duration'}= $duration; $timers->{'pids'}->{$tpid}= $name; } else { - # Child, redirect output and exec - # FIXME do we need to redirect streams? + # Child, install signal handlers and sleep for "duration" # Don't do the ^C cleanup in the timeout child processes! # There is actually a race here, if we get ^C after fork(), but before @@ -98,13 +96,13 @@ sub mtr_timer_start($$$) { $SIG{INT}= 'DEFAULT'; $SIG{TERM}= sub { - mtr_verbose("timer woke up, exiting!"); + mtr_verbose("timer $$ woke up, exiting!"); exit(0); }; $0= "mtr_timer(timers,$name,$duration)"; sleep($duration); - mtr_verbose("timer expired after $duration seconds"); + mtr_verbose("timer $$ expired after $duration seconds"); exit(0); } } @@ -114,12 +112,10 @@ sub mtr_timer_start($$$) { sub mtr_timer_stop ($$) { my ($timers,$name)= @_; - mtr_verbose("mtr_timer_stop: $name"); - if ( exists $timers->{'timers'}->{$name} ) { my $tpid= $timers->{'timers'}->{$name}->{'pid'}; - mtr_verbose("Stopping timer with pid $tpid"); + mtr_verbose("Stopping timer for '$name' with pid $tpid"); # FIXME as Cygwin reuses pids fast, maybe check that is # the expected process somehow?! @@ -134,11 +130,8 @@ sub mtr_timer_stop ($$) { return 1; } - else - { - mtr_error("Asked to stop timer \"$name\" not started"); - return 0; - } + + mtr_error("Asked to stop timer '$name' not started"); } @@ -158,7 +151,8 @@ sub mtr_timer_timeout ($$) { return "" unless exists $timers->{'pids'}->{$pid}; - # We got a timeout, return the name ot the timer + # Got a timeout(the process with $pid is recorded as being a timer) + # return the name of the timer return $timers->{'pids'}->{$pid}; } From 5501f528f5a6f41f8e38cabbbd2d52fcb29993a6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2007 16:44:01 +0200 Subject: [PATCH 14/16] Remove extra newline added to files created by write_file and append_file client/mysqltest.c: - Remove the extra newline first in the file produced by write_file and append_file - Add check for too many arguments passed to 'check_command_args' mysql-test/r/mysqltest.result: Update test result mysql-test/t/mysqltest.test: Add test to check that no extra newline is created --- client/mysqltest.c | 23 +++++++++++++++++++++++ mysql-test/r/mysqltest.result | 1 + mysql-test/t/mysqltest.test | 1 + 3 files changed, 25 insertions(+) diff --git a/client/mysqltest.c b/client/mysqltest.c index 1d481f33f47..541c0cb4394 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -753,6 +753,15 @@ void check_command_args(struct st_command *command, command->first_word_len, command->query); } + /* Check for too many arguments passed */ + ptr= command->last_argument; + while(ptr <= command->end) + { + if (*ptr && *ptr != ' ') + die("Extra argument '%s' passed to '%.*s'", + ptr, command->first_word_len, command->query); + ptr++; + } DBUG_VOID_RETURN; } @@ -2691,8 +2700,22 @@ void read_until_delimiter(DYNAMIC_STRING *ds, c= my_getc(cur_file->file); if (c == '\n') + { cur_file->lineno++; + /* Skip newline from the same line as the command */ + if (start_lineno == (cur_file->lineno - 1)) + continue; + } + else if (start_lineno == cur_file->lineno) + { + /* + No characters except \n are allowed on + the same line as the command + */ + die("Trailing characters found after command"); + } + if (feof(cur_file->file)) die("End of file encountered before '%s' delimiter was found", ds_delimiter->str); diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 513216c062e..5ee1bc4dc0d 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -533,6 +533,7 @@ drop table t1; mysqltest: At line 1: Missing required argument 'filename' to command 'remove_file' mysqltest: At line 1: Missing required argument 'filename' to command 'write_file' mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found +Content for test_file1 Some data for cat_file command of mysqltest diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 20140307e57..791bacd636c 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -1564,6 +1564,7 @@ write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; Content for test_file1 EOF file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp END_DELIMITER; From c48a3d7943edd420da6314c389e9501a85331d49 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2007 16:45:18 +0200 Subject: [PATCH 15/16] Use "create_temp_file" to create a temporary file name for the perl script --- client/mysqltest.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 541c0cb4394..543dabf52f0 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -2970,8 +2970,10 @@ void do_send_quit(struct st_command *command) void do_perl(struct st_command *command) { int error; - char buf[FN_REFLEN]; + File fd; FILE *res_file; + char buf[FN_REFLEN]; + char temp_file_path[FN_REFLEN]; static DYNAMIC_STRING ds_script; static DYNAMIC_STRING ds_delimiter; const struct command_arg perl_args[] = { @@ -2994,14 +2996,17 @@ void do_perl(struct st_command *command) DBUG_PRINT("info", ("Executing perl: %s", ds_script.str)); - /* Format a name for a tmp .pl file that is unique for this process */ - my_snprintf(buf, sizeof(buf), "%s/tmp/tmp_%d.pl", - getenv("MYSQLTEST_VARDIR"), getpid()); - str_to_file(buf, ds_script.str, ds_script.length); + /* Create temporary file name */ + if ((fd= create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"), + "tmp", O_CREAT | O_SHARE | O_RDWR, + MYF(MY_WME))) < 0) + die("Failed to create temporary file for perl command"); + my_close(fd, MYF(0)); - /* Format the perl command */ - my_snprintf(buf, sizeof(buf), "perl %s/tmp/tmp_%d.pl", - getenv("MYSQLTEST_VARDIR"), getpid()); + str_to_file(temp_file_path, ds_script.str, ds_script.length); + + /* Format the "perl " command */ + my_snprintf(buf, sizeof(buf), "perl %s", temp_file_path); if (!(res_file= popen(buf, "r")) && command->abort_on_error) die("popen(\"%s\", \"r\") failed", buf); @@ -3019,6 +3024,10 @@ void do_perl(struct st_command *command) } } error= pclose(res_file); + + /* Remove the temporary file */ + my_delete(temp_file_path, MYF(0)); + handle_command_error(command, WEXITSTATUS(error)); dynstr_free(&ds_script); dynstr_free(&ds_delimiter); From ddbf9fdc1cc39978add9762f71cd77106e3ce8c4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 Aug 2007 18:03:44 +0200 Subject: [PATCH 16/16] Don't require a space between "if" and "(". This should also fix "while" and "connect" It's now possible to write "if(" client/mysqltest.c: Don't require a space between for example "if" and "(". This should also fix "while" and "connect" mysql-test/t/mysqltest.test: Remove space between if and ( to check it works --- client/mysqltest.c | 8 ++++++-- mysql-test/t/mysqltest.test | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 543dabf52f0..65e965ef128 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -4814,9 +4814,13 @@ int read_command(struct st_command** command_ptr) if (!(command->query_buf= command->query= my_strdup(p, MYF(MY_WME)))) die("Out of memory"); - /* Calculate first word and first argument */ - for (p= command->query; *p && !my_isspace(charset_info, *p) ; p++) ; + /* Calculate first word length(the command), terminated by space or ( */ + p= command->query; + while (*p && !my_isspace(charset_info, *p) && *p != '(') + p++; command->first_word_len= (uint) (p - command->query); + DBUG_PRINT("info", ("first_word: %.*s", + command->first_word_len, command->query)); /* Skip spaces between command and first argument */ while (*p && my_isspace(charset_info, *p)) diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 791bacd636c..4f9964552d9 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -969,7 +969,7 @@ if (!$counter) echo Counter is not 0, (counter=10); } let $counter=0; -if ($counter) +if($counter) { echo Counter is greater than 0, (counter=0); }