Skip to content

Commit

Permalink
merge from 5.5-mtr
Browse files Browse the repository at this point in the history
--BZR--
revision-id: [email protected]
property-branch-nick: main-55
testament3-sha1: 0ed304d18729ec9e7fe11ea0df8f8613f8005a06
  • Loading branch information
bjornmu committed Sep 26, 2011
2 parents be57014 + 0d25f6a commit bdaff02
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 92 deletions.
Binary file modified .bzrfileids
Binary file not shown.
164 changes: 128 additions & 36 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,41 @@ static char **default_argv;
static const char *load_default_groups[]= { "mysqltest", "client", 0 };
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;

/* Info on properties that can be set with --enable_X and --disable_X */

struct property {
my_bool *var; /* Actual variable */
my_bool set; /* Has been set for ONE command */
my_bool old; /* If set, thus is the old value */
my_bool reverse; /* Varible is true if disabled */
const char *env_name; /* Env. variable name */
};

static struct property prop_list[] = {
{ &abort_on_error, 0, 1, 0, "$ENABLED_ABORT_ON_ERROR" },
{ &disable_connect_log, 0, 1, 1, "$ENABLED_CONNECT_LOG" },
{ &disable_info, 0, 1, 1, "$ENABLED_INFO" },
{ &display_metadata, 0, 0, 0, "$ENABLED_METADATA" },
{ &ps_protocol_enabled, 0, 0, 0, "$ENABLED_PS_PROTOCOL" },
{ &disable_query_log, 0, 0, 1, "$ENABLED_QUERY_LOG" },
{ &disable_result_log, 0, 0, 1, "$ENABLED_RESULT_LOG" },
{ &disable_warnings, 0, 0, 1, "$ENABLED_WARNINGS" }
};

static my_bool once_property= FALSE;

enum enum_prop {
P_ABORT= 0,
P_CONNECT,
P_INFO,
P_META,
P_PS,
P_QUERY,
P_RESULT,
P_WARN,
P_MAX
};

static uint start_lineno= 0; /* Start line of current command */
static uint my_end_arg= 0;

Expand Down Expand Up @@ -463,6 +498,7 @@ TYPELIB command_typelib= {array_elements(command_names),"",
DYNAMIC_STRING ds_res;
/* Points to ds_warning in run_query, so it can be freed */
DYNAMIC_STRING *ds_warn= 0;
struct st_command *curr_command= 0;

char builtin_echo[FN_REFLEN];

Expand Down Expand Up @@ -712,6 +748,7 @@ void handle_error(struct st_command*,
unsigned int err_errno, const char *err_error,
const char *err_sqlstate, DYNAMIC_STRING *ds);
void handle_no_error(struct st_command*);
void revert_properties();

#ifdef EMBEDDED_LIBRARY

Expand Down Expand Up @@ -1174,6 +1211,7 @@ void handle_command_error(struct st_command *command, uint error)
{
DBUG_PRINT("info", ("command \"%.*s\" failed with expected error: %d",
command->first_word_len, command->query, error));
revert_properties();
DBUG_VOID_RETURN;
}
if (command->expected_errors.count > 0)
Expand All @@ -1188,6 +1226,7 @@ void handle_command_error(struct st_command *command, uint error)
command->first_word_len, command->query,
command->expected_errors.err[0].code.errnum);
}
revert_properties();
DBUG_VOID_RETURN;
}

Expand Down Expand Up @@ -2267,6 +2306,50 @@ void var_set_errno(int sql_errno)
var_set_string("$mysql_errname", get_errname_from_code(sql_errno));
}

/* Functions to handle --disable and --enable properties */

void set_once_property(enum_prop prop, my_bool val)
{
property &pr= prop_list[prop];
pr.set= 1;
pr.old= *pr.var;
*pr.var= val;
var_set_int(pr.env_name, (val != pr.reverse));
once_property= TRUE;
}

void set_property(st_command *command, enum_prop prop, my_bool val)
{
char* p= command->first_argument;
if (p && !strcmp (p, "ONCE"))
{
command->last_argument= p + 4;
set_once_property(prop, val);
return;
}
property &pr= prop_list[prop];
*pr.var= val;
pr.set= 0;
var_set_int(pr.env_name, (val != pr.reverse));
}

void revert_properties()
{
if (! once_property)
return;
for (int i= 0; i < (int) P_MAX; i++)
{
property &pr= prop_list[i];
if (pr.set)
{
*pr.var= pr.old;
pr.set= 0;
var_set_int(pr.env_name, (pr.old != pr.reverse));
}
}
once_property=FALSE;
}


/*
Set variable from the result of a query
Expand Down Expand Up @@ -2318,9 +2401,16 @@ void var_query_set(VAR *var, const char *query, const char** query_end)
init_dynamic_string(&ds_query, 0, (end - query) + 32, 256);
do_eval(&ds_query, query, end, FALSE);

if (mysql_real_query(mysql, ds_query.str, ds_query.length))
die("Error running query '%s': %d %s", ds_query.str,
mysql_errno(mysql), mysql_error(mysql));
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
{
handle_error (curr_command, mysql_errno(mysql), mysql_error(mysql),
mysql_sqlstate(mysql), &ds_res);
/* If error was acceptable, return empty string */
dynstr_free(&ds_query);
eval_expr(var, "", 0);
DBUG_VOID_RETURN;
}

if (!(res= mysql_store_result(mysql)))
die("Query '%s' didn't return a result set", ds_query.str);
dynstr_free(&ds_query);
Expand Down Expand Up @@ -2474,8 +2564,15 @@ void var_set_query_get_value(struct st_command *command, VAR *var)

/* Run the query */
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
die("Error running query '%s': %d %s", ds_query.str,
mysql_errno(mysql), mysql_error(mysql));
{
handle_error (curr_command, mysql_errno(mysql), mysql_error(mysql),
mysql_sqlstate(mysql), &ds_res);
/* If error was acceptable, return empty string */
dynstr_free(&ds_query);
eval_expr(var, "", 0);
DBUG_VOID_RETURN;
}

if (!(res= mysql_store_result(mysql)))
die("Query '%s' didn't return a result set", ds_query.str);

Expand Down Expand Up @@ -4426,6 +4523,7 @@ void do_let(struct st_command *command)
var_set(var_name, var_name_end, let_rhs_expr.str,
(let_rhs_expr.str + let_rhs_expr.length));
dynstr_free(&let_rhs_expr);
revert_properties();
DBUG_VOID_RETURN;
}

Expand Down Expand Up @@ -7354,6 +7452,7 @@ void handle_error(struct st_command *command,
dynstr_append(ds,"Got one of the listed errors\n");
}
/* OK */
revert_properties();
DBUG_VOID_RETURN;
}

Expand Down Expand Up @@ -7381,6 +7480,7 @@ void handle_error(struct st_command *command,
command->expected_errors.err[0].code.sqlstate);
}

revert_properties();
DBUG_VOID_RETURN;
}

Expand Down Expand Up @@ -7415,6 +7515,7 @@ void handle_no_error(struct st_command *command)
command->query, command->expected_errors.err[0].code.sqlstate);
}

revert_properties();
DBUG_VOID_RETURN;
}

Expand Down Expand Up @@ -7445,6 +7546,9 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
DBUG_ENTER("run_query_stmt");
DBUG_PRINT("query", ("'%-.60s'", query));

/* Remember disable_result_log since handle_no_error() may reset it */
my_bool dis_res= disable_result_log;

/*
Init a new stmt if it's not already one created for this connection
*/
Expand Down Expand Up @@ -7540,7 +7644,7 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,

/* If we got here the statement was both executed and read successfully */
handle_no_error(command);
if (!disable_result_log)
if (!dis_res)
{
/*
Not all statements creates a result set. If there is one we can
Expand Down Expand Up @@ -8466,6 +8570,8 @@ int main(int argc, char **argv)
{
command->last_argument= command->first_argument;
processed = 1;
/* Need to remember this for handle_error() */
curr_command= command;
switch (command->type) {
case Q_CONNECT:
do_connect(command);
Expand All @@ -8475,60 +8581,46 @@ int main(int argc, char **argv)
case Q_DIRTY_CLOSE:
do_close_connection(command); break;
case Q_ENABLE_QUERY_LOG:
disable_query_log= 0;
var_set_int("$ENABLED_QUERY_LOG", 1);
set_property(command, P_QUERY, 0);
break;
case Q_DISABLE_QUERY_LOG:
disable_query_log= 1;
var_set_int("$ENABLED_QUERY_LOG", 0);
set_property(command, P_QUERY, 1);
break;
case Q_ENABLE_ABORT_ON_ERROR:
abort_on_error= 1;
var_set_int("$ENABLED_ABORT_ON_ERROR", 1);
set_property(command, P_ABORT, 1);
break;
case Q_DISABLE_ABORT_ON_ERROR:
abort_on_error= 0;
var_set_int("$ENABLED_ABORT_ON_ERROR", 0);
set_property(command, P_ABORT, 0);
break;
case Q_ENABLE_RESULT_LOG:
disable_result_log= 0;
var_set_int("$ENABLED_RESULT_LOG", 1);
set_property(command, P_RESULT, 0);
break;
case Q_DISABLE_RESULT_LOG:
disable_result_log=1;
var_set_int("$ENABLED_RESULT_LOG", 0);
set_property(command, P_RESULT, 1);
break;
case Q_ENABLE_CONNECT_LOG:
disable_connect_log=0;
var_set_int("$ENABLED_CONNECT_LOG", 1);
set_property(command, P_CONNECT, 0);
break;
case Q_DISABLE_CONNECT_LOG:
disable_connect_log=1;
var_set_int("$ENABLED_CONNECT_LOG", 0);
set_property(command, P_CONNECT, 1);
break;
case Q_ENABLE_WARNINGS:
disable_warnings= 0;
var_set_int("$ENABLED_WARNINGS", 1);
set_property(command, P_WARN, 0);
break;
case Q_DISABLE_WARNINGS:
disable_warnings= 1;
var_set_int("$ENABLED_WARNINGS", 0);
set_property(command, P_WARN, 1);
break;
case Q_ENABLE_INFO:
disable_info= 0;
var_set_int("$ENABLED_INFO", 1);
set_property(command, P_INFO, 0);
break;
case Q_DISABLE_INFO:
disable_info= 1;
var_set_int("$ENABLED_INFO", 0);
set_property(command, P_INFO, 1);
break;
case Q_ENABLE_METADATA:
display_metadata= 1;
var_set_int("$ENABLED_METADATA", 1);
set_property(command, P_META, 1);
break;
case Q_DISABLE_METADATA:
display_metadata= 0;
var_set_int("$ENABLED_METADATA", 0);
set_property(command, P_META, 0);
break;
case Q_SOURCE: do_source(command); break;
case Q_SLEEP: do_sleep(command, 0); break;
Expand Down Expand Up @@ -8744,12 +8836,12 @@ int main(int argc, char **argv)
do_set_charset(command);
break;
case Q_DISABLE_PS_PROTOCOL:
ps_protocol_enabled= 0;
set_property(command, P_PS, 0);
/* Close any open statements */
close_statements();
break;
case Q_ENABLE_PS_PROTOCOL:
ps_protocol_enabled= ps_protocol;
set_property(command, P_PS, ps_protocol);
break;
case Q_DISABLE_RECONNECT:
set_reconnect(&cur_con->mysql, 0);
Expand Down
7 changes: 4 additions & 3 deletions mysql-test/mysql-stress-test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ sub set_exit_code {
"test-duration=i", "test-suffix=s", "check-tests-file",
"verbose", "log-error-details", "cleanup", "mysqltest=s",
# OBN: (changing 'abort-on-error' to numberic for WL-4626/4685)
"abort-on-error=i" => \$opt_abort_on_error, "help") || usage();
"abort-on-error=i" => \$opt_abort_on_error, "help") || usage(1);

usage() if ($opt_help);
usage(0) if ($opt_help);

#$opt_abort_on_error=1;

Expand Down Expand Up @@ -1131,6 +1131,7 @@ sub sig_TERM_handler

sub usage
{
my $retcode= shift;
print <<EOF;
The MySQL Stress suite Ver $stress_suite_version
Expand Down Expand Up @@ -1234,7 +1235,7 @@ sub usage
--cleanup \
EOF
exit(0);
exit($retcode);
}


Loading

0 comments on commit bdaff02

Please sign in to comment.