summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/mysqltest.c88
1 files changed, 59 insertions, 29 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c
index d2efead3413..875cfd03c15 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -43,7 +43,7 @@
**********************************************************************/
-#define MTEST_VERSION "1.5"
+#define MTEST_VERSION "1.6"
#include <global.h>
#include <my_sys.h>
@@ -70,24 +70,26 @@
#define INIT_Q_LINES 1024
#define MIN_VAR_ALLOC 32
#define BLOCK_STACK_DEPTH 32
+#define MAX_EXPECTED_ERRORS 10
-int record = 0, verbose = 0, silent = 0, opt_sleep=0;
+static int record = 0, verbose = 0, silent = 0, opt_sleep=0;
static char *db = 0, *pass=0;
const char* user = 0, *host = 0, *unix_sock = 0;
-int port = 0;
+static int port = 0;
static uint start_lineno, *lineno;
static char **default_argv;
static const char *load_default_groups[]= { "mysqltest","client",0 };
-FILE* file_stack[MAX_INCLUDE_DEPTH];
-FILE** cur_file;
-FILE** file_stack_end;
-uint lineno_stack[MAX_INCLUDE_DEPTH];
-char TMPDIR[FN_REFLEN];
+static FILE* file_stack[MAX_INCLUDE_DEPTH];
+static FILE** cur_file;
+static FILE** file_stack_end;
+static uint lineno_stack[MAX_INCLUDE_DEPTH];
+static char TMPDIR[FN_REFLEN];
-int block_stack[BLOCK_STACK_DEPTH];
-int *cur_block, *block_stack_end;
+static int block_stack[BLOCK_STACK_DEPTH];
+static int *cur_block, *block_stack_end;
+static uint global_expected_errno[MAX_EXPECTED_ERRORS];
DYNAMIC_ARRAY q_lines;
@@ -131,19 +133,19 @@ struct st_query
char *query, *first_argument;
int first_word_len;
my_bool abort_on_error, require_file;
- uint expected_errno;
+ uint expected_errno[MAX_EXPECTED_ERRORS];
char record_file[FN_REFLEN];
/* Add new commands before Q_UNKNOWN */
enum { Q_CONNECTION=1, Q_QUERY, Q_CONNECT,
Q_SLEEP, Q_INC, Q_DEC,Q_SOURCE,
Q_DISCONNECT,Q_LET, Q_ECHO, Q_WHILE, Q_END_BLOCK,
- Q_SYSTEM, Q_RESULT, Q_REQUIRE,
+ Q_SYSTEM, Q_RESULT, Q_REQUIRE, Q_ERROR,
Q_UNKNOWN, Q_COMMENT, Q_COMMENT_WITH_COMMAND} type;
};
const char *command_names[] = {
"connection", "query","connect","sleep","inc","dec","source","disconnect",
-"let","echo","while","end","system","result", "require",0
+"let","echo","while","end","system","result", "require","error",0
};
TYPELIB command_typelib= {array_elements(command_names),"",
@@ -541,6 +543,27 @@ static void get_file_name(char *filename, struct st_query* q)
}
+static void get_ints(uint *to,struct st_query* q)
+{
+ char* p=q->first_argument;
+ long val;
+ DBUG_ENTER("get_ints");
+
+ while (*p && isspace(*p)) p++;
+ if (!*p)
+ die("Missing argument in %s\n", q->query);
+
+ for (; (p=str2int(p,10,(long) INT_MIN, (long) INT_MAX, &val)) ; p++)
+ {
+ *to++= (uint) val;
+ if (*p != ',')
+ break;
+ }
+ *to++=0; /* End of data */
+ DBUG_VOID_RETURN;
+}
+
+
int select_connection(struct st_query* q)
{
char* p=q->first_argument, *name;
@@ -896,16 +919,17 @@ int read_query(struct st_query** q_ptr)
get_dynamic(&q_lines, (gptr) q_ptr, parser.current_line) ;
return 0;
}
- if (!(*q_ptr=q=(struct st_query*) my_malloc(sizeof(*q), MYF(MY_WME)))
- || insert_dynamic(&q_lines, (gptr) &q)
- )
- die("Out of memory");
+ if (!(*q_ptr=q=(struct st_query*) my_malloc(sizeof(*q), MYF(MY_WME))) ||
+ insert_dynamic(&q_lines, (gptr) &q))
+ die(NullS);
q->record_file[0] = 0;
q->require_file=0;
- q->abort_on_error = 1;
q->first_word_len = 0;
- q->expected_errno = 0;
+ memcpy((gptr) q->expected_errno, (gptr) global_expected_errno,
+ sizeof(global_expected_errno));
+ q->abort_on_error = global_expected_errno[0] == 0;
+ bzero((gptr) global_expected_errno,sizeof(global_expected_errno));
q->type = Q_UNKNOWN;
q->query=0;
if (read_line(read_query_buf, sizeof(read_query_buf)))
@@ -932,7 +956,8 @@ int read_query(struct st_query** q_ptr)
p++;
for (;isdigit(*p);p++)
expected_errno = expected_errno * 10 + *p - '0';
- q->expected_errno = expected_errno;
+ q->expected_errno[0] = expected_errno;
+ q->expected_errno[1] = 0;
}
}
@@ -1163,15 +1188,17 @@ int run_query(MYSQL* mysql, struct st_query* q)
mysql_errno(mysql), mysql_error(mysql));
else
{
- if (q->expected_errno)
+ for (i=0 ; q->expected_errno[i] ; i++)
{
- error = (q->expected_errno != mysql_errno(mysql));
- if (error)
- verbose_msg("query '%s' failed with wrong errno\
- %d instead of %d", q->query, mysql_errno(mysql), q->expected_errno);
+ if ((q->expected_errno[i] == mysql_errno(mysql)))
+ goto end; /* Ok */
+ }
+ if (i)
+ {
+ verbose_msg("query '%s' failed with wrong errno\
+ %d instead of %d...", q->query, mysql_errno(mysql), q->expected_errno[0]);
goto end;
}
-
verbose_msg("query '%s' failed: %d: %s", q->query, mysql_errno(mysql),
mysql_error(mysql));
/* if we do not abort on error, failure to run the query does
@@ -1181,11 +1208,11 @@ int run_query(MYSQL* mysql, struct st_query* q)
}
}
- if (q->expected_errno)
+ if (q->expected_errno[0])
{
error = 1;
- verbose_msg("query '%s' succeeded - should have failed with errno %d",
- q->query, q->expected_errno);
+ verbose_msg("query '%s' succeeded - should have failed with errno %d...",
+ q->query, q->expected_errno[0]);
goto end;
}
@@ -1357,6 +1384,9 @@ int main(int argc, char** argv)
get_file_name(save_file,q);
require_file=0;
break;
+ case Q_ERROR:
+ get_ints(global_expected_errno,q);
+ break;
case Q_REQUIRE:
get_file_name(save_file,q);
require_file=1;