diff options
Diffstat (limited to 'client/mysqltest.c')
-rw-r--r-- | client/mysqltest.c | 101 |
1 files changed, 70 insertions, 31 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index be2270850fa..5ba4ad7336c 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -59,7 +59,8 @@ #include <sys/stat.h> #include <violite.h> -#define MAX_QUERY 65536 +#define MAX_QUERY 131072 +#define MAX_VAR_NAME 256 #define MAX_COLUMNS 256 #define PAD_SIZE 128 #define MAX_CONS 128 @@ -187,7 +188,7 @@ typedef struct */ static char *subst_env_var(const char *cmd); -static int my_popen(const char *cmd, const char *mode); +static FILE *my_popen(const char *cmd, const char *mode); #define popen(A,B) my_popen((A),(B)) #endif /* __NETWARE__ */ @@ -223,7 +224,7 @@ Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG, Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG, Q_SERVER_START, Q_SERVER_STOP,Q_REQUIRE_MANAGER, Q_WAIT_FOR_SLAVE_TO_STOP, -Q_REQUIRE_VERSION, +Q_REQUIRE_VERSION, Q_REQUIRE_OS, Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS, Q_ENABLE_INFO, Q_DISABLE_INFO, Q_ENABLE_METADATA, Q_DISABLE_METADATA, @@ -297,6 +298,7 @@ const char *command_names[]= "require_manager", "wait_for_slave_to_stop", "require_version", + "require_os", "enable_warnings", "disable_warnings", "enable_info", @@ -318,6 +320,7 @@ TYPELIB command_typelib= {array_elements(command_names),"", DYNAMIC_STRING ds_res; static void die(const char *fmt, ...); static void init_var_hash(); +static VAR* var_from_env(const char *, const char *); static byte* get_var_key(const byte* rec, uint* len, my_bool __attribute__((unused)) t); static VAR* var_init(VAR* v, const char *name, int name_len, const char *val, @@ -385,6 +388,7 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char* query) register char c; register int escaped = 0; VAR* v; + DBUG_ENTER("do_eval"); for (p= query; (c = *p); ++p) { @@ -416,6 +420,7 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char* query) break; } } + DBUG_VOID_RETURN; } @@ -627,6 +632,7 @@ static int check_result(DYNAMIC_STRING* ds, const char* fname, return error; } + VAR* var_get(const char* var_name, const char** var_name_end, my_bool raw, my_bool ignore_not_existing) { @@ -641,26 +647,26 @@ VAR* var_get(const char* var_name, const char** var_name_end, my_bool raw, if (!(digit < 10 && digit >= 0)) { const char* save_var_name = var_name, *end; + uint length; end = (var_name_end) ? *var_name_end : 0; while (my_isvar(charset_info,*var_name) && var_name != end) - ++var_name; + var_name++; if (var_name == save_var_name) { if (ignore_not_existing) DBUG_RETURN(0); die("Empty variable"); } + length= (uint) (var_name - save_var_name); - if (!(v = (VAR*) hash_search(&var_hash, save_var_name, - var_name - save_var_name))) + if (!(v = (VAR*) hash_search(&var_hash, save_var_name, length)) && + length < MAX_VAR_NAME) { - if (ignore_not_existing) - DBUG_RETURN(0); - if (end) - *(char*) end = 0; - die("Variable '%s' used uninitialized", save_var_name); + char buff[MAX_VAR_NAME+1]; + strmake(buff, save_var_name, length); + v= var_from_env(buff, ""); } - --var_name; /* Point at last character */ + var_name--; /* Point at last character */ } else v = var_reg + digit; @@ -848,6 +854,27 @@ int do_require_version(struct st_query* q) return 0; } +int do_require_os(struct st_query* q) +{ + char *p=q->first_argument, *os_arg; + DBUG_ENTER("do_require_os"); + + if (!*p) + die("Missing version argument in require_os\n"); + os_arg= p; + while (*p && !my_isspace(charset_info,*p)) + p++; + *p = 0; + + if (strcmp(os_arg, "unix")) + die("For now only testing of os=unix is implemented\n"); + +#if defined(__NETWARE__) || defined(__WIN__) || defined(__OS2__) + abort_not_supported_test(); +#endif + DBUG_RETURN(0); +} + int do_source(struct st_query* q) { char* p=q->first_argument, *name; @@ -1737,6 +1764,7 @@ int read_line(char* buf, int size) enum {R_NORMAL, R_Q1, R_ESC_Q_Q1, R_ESC_Q_Q2, R_ESC_SLASH_Q1, R_ESC_SLASH_Q2, R_Q2, R_COMMENT, R_LINE_START} state= R_LINE_START; + DBUG_ENTER("read_line"); start_lineno= *lineno; for (; p < buf_end ;) @@ -1750,7 +1778,7 @@ int read_line(char* buf, int size) cur_file--; lineno--; if (cur_file == file_stack) - return 1; + DBUG_RETURN(1); continue; } @@ -1760,7 +1788,7 @@ int read_line(char* buf, int size) if (end_of_query(c)) { *p= 0; - return 0; + DBUG_RETURN(0); } else if (c == '\'') state = R_Q1; @@ -1777,7 +1805,7 @@ int read_line(char* buf, int size) { *p= 0; (*lineno)++; - return 0; + DBUG_RETURN(0); } break; case R_LINE_START: @@ -1795,12 +1823,12 @@ int read_line(char* buf, int size) { *buf++= '}'; *buf= 0; - return 0; + DBUG_RETURN(0); } else if (end_of_query(c) || c == '{') { *p= 0; - return 0; + DBUG_RETURN(0); } else if (c == '\'') state= R_Q1; @@ -1820,7 +1848,7 @@ int read_line(char* buf, int size) if (end_of_query(c)) { *p= 0; - return 0; + DBUG_RETURN(0); } if (c != '\'') state= R_NORMAL; @@ -1841,7 +1869,7 @@ int read_line(char* buf, int size) if (end_of_query(c)) { *p= 0; - return 0; + DBUG_RETURN(0); } if (c != '"') state= R_NORMAL; @@ -1857,7 +1885,7 @@ int read_line(char* buf, int size) *p++= c; } *p= 0; /* Always end with \0 */ - return feof(*cur_file); + DBUG_RETURN(feof(*cur_file)); } @@ -1892,8 +1920,11 @@ int read_query(struct st_query** q_ptr) q->type = Q_UNKNOWN; q->query_buf= q->query= 0; if (read_line(read_query_buf, sizeof(read_query_buf))) + { + DBUG_PRINT("warning",("too long query")); DBUG_RETURN(1); - + } + DBUG_PRINT("info", ("query: %s", read_query_buf)); if (*p == '#') { q->type = Q_COMMENT; @@ -2259,6 +2290,7 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags) char* query; int query_len, got_error_on_send= 0; DBUG_ENTER("run_query"); + DBUG_PRINT("enter",("flags: %d", flags)); if (q->type != Q_EVAL) { @@ -2580,7 +2612,7 @@ static void var_free(void *v) } -static void var_from_env(const char *name, const char *def_val) +static VAR* var_from_env(const char *name, const char *def_val) { const char *tmp; VAR *v; @@ -2589,6 +2621,7 @@ static void var_from_env(const char *name, const char *def_val) v = var_init(0, name, 0, tmp, 0); my_hash_insert(&var_hash, (byte*)v); + return v; } @@ -2599,10 +2632,8 @@ static void init_var_hash(MYSQL *mysql) if (hash_init(&var_hash, charset_info, 1024, 0, 0, get_var_key, var_free, MYF(0))) die("Variable hash initialization failed"); - var_from_env("MASTER_MYPORT", "9306"); - var_from_env("SLAVE_MYPORT", "9307"); - var_from_env("MYSQL_TEST_DIR", "/tmp"); - var_from_env("BIG_TEST", opt_big_test ? "1" : "0"); + if (opt_big_test) + my_hash_insert(&var_hash, (byte*) var_init(0,"BIG_TEST", 0, "1",0)); v= var_init(0,"MAX_TABLES", 0, (sizeof(ulong) == 4) ? "31" : "62",0); my_hash_insert(&var_hash, (byte*) v); v= var_init(0,"SERVER_VERSION", 0, mysql_get_server_info(mysql), 0); @@ -2706,6 +2737,7 @@ int main(int argc, char **argv) case Q_SLEEP: do_sleep(q, 0); break; case Q_REAL_SLEEP: do_sleep(q, 1); break; case Q_REQUIRE_VERSION: do_require_version(q); break; + case Q_REQUIRE_OS: do_require_os(q); break; case Q_WAIT_FOR_SLAVE_TO_STOP: do_wait_for_slave_to_stop(q); break; case Q_REQUIRE_MANAGER: do_require_manager(q); break; #ifndef EMBEDDED_LIBRARY @@ -2727,7 +2759,10 @@ int main(int argc, char **argv) case Q_EVAL_RESULT: eval_result = 1; break; case Q_EVAL: if (q->query == q->query_buf) + { q->query= q->first_argument; + q->first_word_len= 0; + } /* fall through */ case Q_QUERY_VERTICAL: case Q_QUERY_HORIZONTAL: @@ -2737,13 +2772,16 @@ int main(int argc, char **argv) { /* This happens when we use 'query_..' on it's own line */ q_send_flag=1; + DBUG_PRINT("info", + ("query: '%s' first_word_len: %d send_flag=1", + q->query, q->first_word_len)); break; } /* fix up query pointer if this is * first iteration for this line */ if (q->query == q->query_buf) q->query += q->first_word_len + 1; display_result_vertically= (q->type==Q_QUERY_VERTICAL); - error |= run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND); + error|= run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND); display_result_vertically= old_display_result_vertically; break; } @@ -3710,6 +3748,7 @@ static void get_replace_column(struct st_query *q) static char *subst_env_var(const char *str) { char *result; + char *pos; result= pos= my_malloc(MAX_QUERY, MYF(MY_FAE)); while (*str) @@ -3729,7 +3768,7 @@ static char *subst_env_var(const char *str) *str && !isspace(*str) && *str != '\\' && *str != '/' && *str != '$'; str++) - *env_pos++ *str; + *env_pos++= *str; *env_pos= 0; if (!(subst= getenv(env_var))) @@ -3772,11 +3811,11 @@ static char *subst_env_var(const char *str) #undef popen /* Remove wrapper */ -int my_popen(const char *cmd, const char *mode __attribute__((unused)) t) +FILE *my_popen(const char *cmd, const char *mode __attribute__((unused))) { char *subst_cmd; - int res_file; - + FILE *res_file; + subst_cmd= subst_env_var(cmd); res_file= popen(subst_cmd, "r0"); my_free(subst_cmd, MYF(0)); |