Commit c61fb3c3 authored by unknown's avatar unknown

Replace win filename s with unix equivalent

Evaluate commands passed to "exec" and "system" to expand any $variables before executing command.


client/mysqltest.c:
  do_exec, do_system 
   - call do_eval on the command to be executed in order to expand any $variables
   - Remove old subst_env_var and my_popen, not needed anymore
  Rewrite 'replace_strings' into 'replace_strings_append'
   - copy whole strings instead of byte by byte copy
   - insert result directly inito dynamic_string, no need to check if out 
     string needs to be realloced for every byte.
   - Add comments and DBUG_PRINT's
  New function 'fix_win_paths', detect filenames in win format that should be converted 
  do_eval
  - Only set "escaped" if next char is \ or $
mysql-test/mysql-test-run.pl:
  Always pass path for DBUG .trace file in unix format
  Add search path client_debug to find debug compiled windows binaries
  Remove unused MYSQL_TEST_WINDIR and MASTER_WINMYSOCK
mysql-test/r/mysqldump.result:
  Update test result
mysql-test/t/client_xml.test:
  Use " instead of '
mysql-test/t/mysql_client_test.test:
  Remove the useless "exec echo" command
mysql-test/t/mysqltest.test:
  Escape $variables passed to --exec, that should not be evaluated in exec.
mysql-test/t/rpl000015.test:
  Remove unneccessary replace
mysql-test/t/system_mysql_db_fix.test:
  Call the "shell script" $MYSQL_FIX_SYSTEM_TABLE using --system
parent 1be9ba8a
...@@ -74,7 +74,6 @@ ...@@ -74,7 +74,6 @@
#define MAX_QUERY (256*1024) #define MAX_QUERY (256*1024)
#define MAX_VAR_NAME 256 #define MAX_VAR_NAME 256
#define MAX_COLUMNS 256 #define MAX_COLUMNS 256
#define PAD_SIZE 128
#define MAX_CONS 128 #define MAX_CONS 128
#define MAX_INCLUDE_DEPTH 16 #define MAX_INCLUDE_DEPTH 16
#define INIT_Q_LINES 1024 #define INIT_Q_LINES 1024
...@@ -275,18 +274,6 @@ typedef struct ...@@ -275,18 +274,6 @@ typedef struct
int alloced; int alloced;
} VAR; } VAR;
#if defined(__NETWARE__) || defined(__WIN__)
/*
Netware doesn't proved environment variable substitution that is done
by the shell in unix environments. We do this in the following function:
*/
static char *subst_env_var(const char *cmd);
static FILE *my_popen(const char *cmd, const char *mode);
#undef popen
#define popen(A,B) my_popen((A),(B))
#endif /* __NETWARE__ */
VAR var_reg[10]; VAR var_reg[10];
/*Perl/shell-like variable registers */ /*Perl/shell-like variable registers */
HASH var_hash; HASH var_hash;
...@@ -465,19 +452,19 @@ typedef struct st_pointer_array { /* when using array-strings */ ...@@ -465,19 +452,19 @@ typedef struct st_pointer_array { /* when using array-strings */
struct st_replace; struct st_replace;
struct st_replace *init_replace(my_string *from, my_string *to, uint count, struct st_replace *init_replace(my_string *from, my_string *to, uint count,
my_string word_end_chars); my_string word_end_chars);
uint replace_strings(struct st_replace *rep, my_string *start,
uint *max_length, const char *from);
void free_replace(); void free_replace();
static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name); static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name);
static void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
const char *from, int len);
void free_pointer_array(POINTER_ARRAY *pa); void free_pointer_array(POINTER_ARRAY *pa);
static int initialize_replace_buffer(void);
static void do_eval(DYNAMIC_STRING *query_eval, const char *query); static void do_eval(DYNAMIC_STRING *query_eval, const char *query);
static void str_to_file(const char *fname, char *str, int size); static void str_to_file(const char *fname, char *str, int size);
int do_server_op(struct st_query *q,const char *op);
#ifdef __WIN__
static void free_win_path_patterns();
#endif
struct st_replace *glob_replace; struct st_replace *glob_replace;
static char *out_buff;
static uint out_length;
static int eval_result = 0; static int eval_result = 0;
/* For column replace */ /* For column replace */
...@@ -505,7 +492,7 @@ static void handle_no_error(struct st_query *q); ...@@ -505,7 +492,7 @@ static void handle_no_error(struct st_query *q);
static void do_eval(DYNAMIC_STRING* query_eval, const char *query) static void do_eval(DYNAMIC_STRING* query_eval, const char *query)
{ {
const char *p; const char *p;
register char c; register char c, next_c;
register int escaped = 0; register int escaped = 0;
VAR* v; VAR* v;
DBUG_ENTER("do_eval"); DBUG_ENTER("do_eval");
...@@ -527,13 +514,19 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char *query) ...@@ -527,13 +514,19 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char *query)
} }
break; break;
case '\\': case '\\':
next_c= *(p+1);
if (escaped) if (escaped)
{ {
escaped = 0; escaped = 0;
dynstr_append_mem(query_eval, p, 1); dynstr_append_mem(query_eval, p, 1);
} }
else else if (next_c == '\\' || next_c == '$')
{
/* Set escaped only if next char is \ or $ */
escaped = 1; escaped = 1;
}
else
dynstr_append_mem(query_eval, p, 1);
break; break;
default: default:
dynstr_append_mem(query_eval, p, 1); dynstr_append_mem(query_eval, p, 1);
...@@ -609,6 +602,9 @@ static void free_used_memory() ...@@ -609,6 +602,9 @@ static void free_used_memory()
free_defaults(default_argv); free_defaults(default_argv);
mysql_server_end(); mysql_server_end();
free_re(); free_re();
#ifdef __WIN__
free_win_path_patterns();
#endif
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -971,17 +967,7 @@ int do_require_manager(struct st_query *query __attribute__((unused)) ) ...@@ -971,17 +967,7 @@ int do_require_manager(struct st_query *query __attribute__((unused)) )
} }
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
int do_server_start(struct st_query *q) static int do_server_op(struct st_query *q, const char *op)
{
return do_server_op(q, "start");
}
int do_server_stop(struct st_query *q)
{
return do_server_op(q, "stop");
}
int do_server_op(struct st_query *q, const char *op)
{ {
char *p= q->first_argument; char *p= q->first_argument;
char com_buf[256], *com_p; char com_buf[256], *com_p;
...@@ -1011,6 +997,17 @@ int do_server_op(struct st_query *q, const char *op) ...@@ -1011,6 +997,17 @@ int do_server_op(struct st_query *q, const char *op)
q->last_argument= p; q->last_argument= p;
return 0; return 0;
} }
int do_server_start(struct st_query *q)
{
return do_server_op(q, "start");
}
int do_server_stop(struct st_query *q)
{
return do_server_op(q, "stop");
}
#endif #endif
...@@ -1064,16 +1061,21 @@ int do_source(struct st_query *query) ...@@ -1064,16 +1061,21 @@ int do_source(struct st_query *query)
expected error array, previously set with the --error command. expected error array, previously set with the --error command.
It can thus be used to execute a command that shall fail. It can thus be used to execute a command that shall fail.
NOTE
Although mysqltest is executed from cygwin shell, the command will be
executed in "cmd.exe". Thus commands like "rm" etc can NOT be used, use
system for those commands.
*/ */
static void do_exec(struct st_query *query) static void do_exec(struct st_query *query)
{ {
int error; int error;
DYNAMIC_STRING *ds= NULL;
char buf[1024]; char buf[1024];
FILE *res_file; FILE *res_file;
char *cmd= query->first_argument; char *cmd= query->first_argument;
DYNAMIC_STRING ds_cmd;
DBUG_ENTER("do_exec"); DBUG_ENTER("do_exec");
DBUG_PRINT("enter", ("cmd: '%s'", cmd));
while (*cmd && my_isspace(charset_info, *cmd)) while (*cmd && my_isspace(charset_info, *cmd))
cmd++; cmd++;
...@@ -1081,24 +1083,28 @@ static void do_exec(struct st_query *query) ...@@ -1081,24 +1083,28 @@ static void do_exec(struct st_query *query)
die("Missing argument in exec"); die("Missing argument in exec");
query->last_argument= query->end; query->last_argument= query->end;
DBUG_PRINT("info", ("Executing '%s'", cmd)); init_dynamic_string(&ds_cmd, 0, strlen(cmd)+256, 256);
/* Eval the command, thus replacing all environment variables */
do_eval(&ds_cmd, cmd);
cmd= ds_cmd.str;
DBUG_PRINT("info", ("Executing '%' as '%s'",
query->first_argument, cmd));
if (!(res_file= popen(cmd, "r")) && query->abort_on_error) if (!(res_file= popen(cmd, "r")) && query->abort_on_error)
die("popen(\"%s\", \"r\") failed", cmd); die("popen(\"%s\", \"r\") failed", query->first_argument);
if (disable_result_log) while (fgets(buf, sizeof(buf), res_file))
{ {
while (fgets(buf, sizeof(buf), res_file)) if (disable_result_log)
{ {
buf[strlen(buf)-1]=0; buf[strlen(buf)-1]=0;
DBUG_PRINT("exec_result",("%s", buf)); DBUG_PRINT("exec_result",("%s", buf));
} }
} else
else {
{ replace_dynstr_append(&ds_res, buf);
ds= &ds_res; }
while (fgets(buf, sizeof(buf), res_file))
replace_dynstr_append(ds, buf);
} }
error= pclose(res_file); error= pclose(res_file);
if (error != 0) if (error != 0)
...@@ -1107,7 +1113,7 @@ static void do_exec(struct st_query *query) ...@@ -1107,7 +1113,7 @@ static void do_exec(struct st_query *query)
my_bool ok= 0; my_bool ok= 0;
if (query->abort_on_error) if (query->abort_on_error)
die("command \"%s\" failed", cmd); die("command \"%s\" failed", query->first_argument);
DBUG_PRINT("info", DBUG_PRINT("info",
("error: %d, status: %d", error, status)); ("error: %d, status: %d", error, status));
...@@ -1122,19 +1128,19 @@ static void do_exec(struct st_query *query) ...@@ -1122,19 +1128,19 @@ static void do_exec(struct st_query *query)
{ {
ok= 1; ok= 1;
DBUG_PRINT("info", ("command \"%s\" failed with expected error: %d", DBUG_PRINT("info", ("command \"%s\" failed with expected error: %d",
cmd, status)); query->first_argument, status));
} }
} }
if (!ok) if (!ok)
die("command \"%s\" failed with wrong error: %d", die("command \"%s\" failed with wrong error: %d",
cmd, status); query->first_argument, status);
} }
else if (query->expected_errno[0].type == ERR_ERRNO && else if (query->expected_errno[0].type == ERR_ERRNO &&
query->expected_errno[0].code.errnum != 0) query->expected_errno[0].code.errnum != 0)
{ {
/* Error code we wanted was != 0, i.e. not an expected success */ /* Error code we wanted was != 0, i.e. not an expected success */
die("command \"%s\" succeeded - should have failed with errno %d...", die("command \"%s\" succeeded - should have failed with errno %d...",
cmd, query->expected_errno[0].code.errnum); query->first_argument, query->expected_errno[0].code.errnum);
} }
free_replace(); free_replace();
...@@ -1346,38 +1352,49 @@ int do_modify_var(struct st_query *query, const char *name, ...@@ -1346,38 +1352,49 @@ int do_modify_var(struct st_query *query, const char *name,
} }
int do_system(struct st_query *q) /*
SYNOPSIS
do_system
command called command
DESCRIPTION
system <command>
Eval the query to expand any $variables in the command.
Execute the command withe the "system" command.
NOTE
If mysqltest is executed from cygwin shell, the command will be
executed in cygwin shell. Thus commands like "rm" etc can be used.
*/
int do_system(struct st_query *command)
{ {
DYNAMIC_STRING *ds; DYNAMIC_STRING ds_cmd;
char *p=q->first_argument;
VAR v;
var_init(&v, 0, 0, 0, 0);
eval_expr(&v, p, 0); /* NULL terminated */
ds= &ds_res;
if (v.str_val_len) if (strlen(command->first_argument) == 0)
die("Missing arguments to system, nothing to do!");
init_dynamic_string(&ds_cmd, 0, strlen(command->first_argument) + 64, 256);
/* Eval the system command, thus replacing all environment variables */
do_eval(&ds_cmd, command->first_argument);
DBUG_PRINT("info", ("running system command '%s' as '%s'",
command->first_argument, ds_cmd.str));
if (system(ds_cmd.str))
{ {
char expr_buf[1024]; if (command->abort_on_error)
if ((uint)v.str_val_len > sizeof(expr_buf) - 1) die("system command '%s' failed", command->first_argument);
v.str_val_len = sizeof(expr_buf) - 1;
memcpy(expr_buf, v.str_val, v.str_val_len);
expr_buf[v.str_val_len] = 0;
DBUG_PRINT("info", ("running system command '%s'", expr_buf));
if (system(expr_buf))
{
if (q->abort_on_error)
die("system command '%s' failed", expr_buf);
/* If ! abort_on_error, log message and continue */ /* If ! abort_on_error, log message and continue */
dynstr_append(ds, "system command '"); dynstr_append(&ds_res, "system command '");
replace_dynstr_append(ds, expr_buf); replace_dynstr_append(&ds_res, command->first_argument);
dynstr_append(ds, "' failed\n"); dynstr_append(&ds_res, "' failed\n");
}
} }
else
die("Missing arguments to system, nothing to do!"); command->last_argument= command->end;
var_free(&v);
q->last_argument= q->end;
return 0; return 0;
} }
...@@ -1857,8 +1874,7 @@ static void get_replace(struct st_query *q) ...@@ -1857,8 +1874,7 @@ static void get_replace(struct st_query *q)
if (!(glob_replace=init_replace((char**) from_array.typelib.type_names, if (!(glob_replace=init_replace((char**) from_array.typelib.type_names,
(char**) to_array.typelib.type_names, (char**) to_array.typelib.type_names,
(uint) from_array.typelib.count, (uint) from_array.typelib.count,
word_end_chars)) || word_end_chars)))
initialize_replace_buffer())
die("Can't initialize replace from '%s'", q->query); die("Can't initialize replace from '%s'", q->query);
free_pointer_array(&from_array); free_pointer_array(&from_array);
free_pointer_array(&to_array); free_pointer_array(&to_array);
...@@ -1874,7 +1890,6 @@ void free_replace() ...@@ -1874,7 +1890,6 @@ void free_replace()
{ {
my_free((char*) glob_replace,MYF(0)); my_free((char*) glob_replace,MYF(0));
glob_replace=0; glob_replace=0;
my_free(out_buff,MYF(MY_WME));
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -2530,7 +2545,11 @@ int read_line(char *buf, int size) ...@@ -2530,7 +2545,11 @@ int read_line(char *buf, int size)
/* Line counting is independent of state */ /* Line counting is independent of state */
if (c == '\n') if (c == '\n')
{
cur_file->lineno++; cur_file->lineno++;
if (p != buf && *(p-1) == '\r')
*(p-1)=0;
}
switch(state) { switch(state) {
case R_NORMAL: case R_NORMAL:
...@@ -2700,7 +2719,7 @@ int read_query(struct st_query** q_ptr) ...@@ -2700,7 +2719,7 @@ int read_query(struct st_query** q_ptr)
check_eol_junk(read_query_buf); check_eol_junk(read_query_buf);
DBUG_RETURN(1); DBUG_RETURN(1);
} }
DBUG_PRINT("info", ("query: %s", read_query_buf)); DBUG_PRINT("info", ("query: %s", read_query_buf));
if (*p == '#') if (*p == '#')
{ {
...@@ -3015,24 +3034,127 @@ void dump_result_to_reject_file(const char *record_file, char *buf, int size) ...@@ -3015,24 +3034,127 @@ void dump_result_to_reject_file(const char *record_file, char *buf, int size)
} }
/* Append the string to ds, with optional replace */ #ifdef __WIN__
static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, DYNAMIC_ARRAY patterns;
int len)
/*
init_win_path_patterns
DESCRIPTION
Setup string patterns that will be used to detect filenames that
needs to be converted from Win to Unix format
*/
static void init_win_path_patterns()
{ {
if (glob_replace) /* List of string patterns to match in order to find paths */
const char* paths[] = { "$MYSQL_TEST_DIR", "./test/", 0 };
int num_paths= 2;
int i;
char* p;
DBUG_ENTER("init_win_path_patterns");
my_init_dynamic_array(&patterns, sizeof(const char*), 16, 16);
/* Loop through all paths in the array */
for (i= 0; i < num_paths; i++)
{ {
len=(int) replace_strings(glob_replace, &out_buff, &out_length, val); VAR* v;
if (len == -1) if (*(paths[i]) == '$')
die("Out of memory in replace"); {
val=out_buff; v= var_get(paths[i], 0, 0, 0);
p= my_strdup(v->str_val, MYF(MY_FAE));
}
else
p= my_strdup(paths[i], MYF(MY_FAE));
if (insert_dynamic(&patterns, (gptr) &p))
die(NullS);
DBUG_PRINT("info", ("p: %s", p));
while (*p)
{
if (*p == '/')
*p='\\';
p++;
}
} }
dynstr_append_mem(ds, val, len); DBUG_VOID_RETURN;
} }
static void free_win_path_patterns()
{
int i= 0;
for (i=0 ; i < patterns.elements ; i++)
{
const char** pattern= dynamic_element(&patterns, i, const char**);
my_free((gptr) *pattern, MYF(0));
}
delete_dynamic(&patterns);
}
/* Append zero-terminated string to ds, with optional replace */ /*
fix_win_paths
DESCRIPTION
Search the string 'val' for the patterns that are known to be
strings that contain filenames. Convert all \ to / in the
filenames that are found.
Ex:
val = 'Error "c:\mysql\mysql-test\var\test\t1.frm" didn't exist'
=> $MYSQL_TEST_DIR is found by strstr
=> all \ from c:\mysql\m... until next space is converted into /
*/
static void fix_win_paths(const char* val, int len)
{
uint i;
char *p;
DBUG_ENTER("fix_win_paths");
for (i= 0; i < patterns.elements; i++)
{
const char** pattern= dynamic_element(&patterns, i, const char**);
DBUG_PRINT("info", ("pattern: %s", *pattern));
/* Search for the path in string */
while ((p= strstr(val, *pattern)))
{
DBUG_PRINT("info", ("Found %s in val p: %s", *pattern, p));
while (*p && !my_isspace(charset_info, *p))
{
if (*p == '\\')
*p= '/';
p++;
}
DBUG_PRINT("info", ("Converted \\ to /, p: %s", p));
}
}
DBUG_PRINT("exit", (" val: %s, len: %d", val, len));
DBUG_VOID_RETURN;
}
#endif
/* Append the string to ds, with optional replace */
static void replace_dynstr_append_mem(DYNAMIC_STRING *ds,
const char *val, int len)
{
#ifdef __WIN__
fix_win_paths(val, len);
#endif
if (glob_replace)
replace_strings_append(glob_replace, ds, val, len);
else
dynstr_append_mem(ds, val, len);
}
/* Append zero-terminated string to ds, with optional replace */
static void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val) static void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val)
{ {
replace_dynstr_append_mem(ds, val, strlen(val)); replace_dynstr_append_mem(ds, val, strlen(val));
...@@ -4353,6 +4475,10 @@ int main(int argc, char **argv) ...@@ -4353,6 +4475,10 @@ int main(int argc, char **argv)
init_var_hash(&cur_con->mysql); init_var_hash(&cur_con->mysql);
#ifdef __WIN__
init_win_path_patterns();
#endif
/* /*
Initialize $mysql_errno with -1, so we can Initialize $mysql_errno with -1, so we can
- distinguish it from valid values ( >= 0 ) and - distinguish it from valid values ( >= 0 ) and
...@@ -5414,60 +5540,57 @@ static uint replace_len(my_string str) ...@@ -5414,60 +5540,57 @@ static uint replace_len(my_string str)
} }
/* Replace strings; Return length of result string */ /* Replace strings while appending to ds */
void replace_strings_append(REPLACE *rep, DYNAMIC_STRING* ds,
uint replace_strings(REPLACE *rep, my_string *start,uint *max_length, const char *str, int len)
const char *from)
{ {
reg1 REPLACE *rep_pos; reg1 REPLACE *rep_pos;
reg2 REPLACE_STRING *rep_str; reg2 REPLACE_STRING *rep_str;
my_string to,end,pos,new_str; const char *start, *from;
DBUG_ENTER("replace_strings_append");
end=(to= *start) + *max_length-1; start= from= str;
rep_pos=rep+1; rep_pos=rep+1;
for (;;) for (;;)
{ {
/* Loop through states */
DBUG_PRINT("info", ("Looping through states"));
while (!rep_pos->found) while (!rep_pos->found)
{ rep_pos= rep_pos->next[(uchar) *from++];
rep_pos= rep_pos->next[(uchar) *from];
if (to == end) /* Does this state contain a string to be replaced */
{
(*max_length)+=8192;
if (!(new_str=my_realloc(*start,*max_length,MYF(MY_WME))))
return (uint) -1;
to=new_str+(to - *start);
end=(*start=new_str)+ *max_length-1;
}
*to++= *from++;
}
if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string) if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string)
return (uint) (to - *start)-1;
to-=rep_str->to_offset;
for (pos=rep_str->replace_string; *pos ; pos++)
{ {
if (to == end) /* No match found */
{ dynstr_append_mem(ds, start, from - start - 1);
(*max_length)*=2; DBUG_PRINT("exit", ("Found no more string to replace, appended: %s", start));
if (!(new_str=my_realloc(*start,*max_length,MYF(MY_WME)))) DBUG_VOID_RETURN;
return (uint) -1;
to=new_str+(to - *start);
end=(*start=new_str)+ *max_length-1;
}
*to++= *pos;
} }
/* Found a string that needs to be replaced */
DBUG_PRINT("info", ("found: %d, to_offset: %d, from_offset: %d, string: %s",
rep_str->found, rep_str->to_offset,
rep_str->from_offset, rep_str->replace_string));
/* Append part of original string before replace string */
dynstr_append_mem(ds, start, (from - rep_str->to_offset) - start);
/* Append replace string */
dynstr_append_mem(ds, rep_str->replace_string,
strlen(rep_str->replace_string));
if (!*(from-=rep_str->from_offset) && rep_pos->found != 2) if (!*(from-=rep_str->from_offset) && rep_pos->found != 2)
return (uint) (to - *start); {
/* End of from string */
DBUG_PRINT("exit", ("Found end of from string"));
DBUG_VOID_RETURN;
}
DBUG_ASSERT(from <= str+len);
start= from;
rep_pos=rep; rep_pos=rep;
} }
} }
static int initialize_replace_buffer(void)
{
out_length=8192;
if (!(out_buff=my_malloc(out_length,MYF(MY_WME))))
return(1);
return 0;
}
/**************************************************************************** /****************************************************************************
Replace results for a column Replace results for a column
...@@ -5526,105 +5649,6 @@ static void get_replace_column(struct st_query *q) ...@@ -5526,105 +5649,6 @@ static void get_replace_column(struct st_query *q)
q->last_argument= q->end; q->last_argument= q->end;
} }
#if defined(__NETWARE__) || defined(__WIN__)
/*
Substitute environment variables with text.
SYNOPSIS
subst_env_var()
arg String that should be substitute
DESCRIPTION
This function takes a string as an input and replaces the
environment variables, that starts with '$' character, with it value.
NOTES
Return string must be freed with my_free()
RETURN
String with environment variables replaced.
*/
static char *subst_env_var(const char *str)
{
char *result;
char *pos;
result= pos= my_malloc(MAX_QUERY, MYF(MY_FAE));
while (*str)
{
/*
need this only when we want to provide the functionality of
escaping through \ 'backslash'
if ((result == pos && *str=='$') ||
(result != pos && *str=='$' && str[-1] !='\\'))
*/
if (*str == '$')
{
char env_var[256], *env_pos= env_var, *subst;
/* Search for end of environment variable */
for (str++;
*str && !isspace(*str) && *str != '\\' && *str != '/' &&
*str != '$';
str++)
*env_pos++= *str;
*env_pos= 0;
if (!(subst= getenv(env_var)))
{
my_free(result, MYF(0));
die("MYSQLTEST.NLM: Environment variable %s is not defined",
env_var);
}
/* get the string to be substitued for env_var */
pos= strmov(pos, subst);
/* Process delimiter in *str again */
}
else
*pos++= *str++;
}
*pos= 0;
return result;
}
/*
popen replacement for Netware
SYNPOSIS
my_popen()
name Command to execute (with possible env variables)
mode Mode for popen.
NOTES
Environment variable expansion does not take place for popen function
on NetWare, so we use this function to wrap around popen to do this.
For the moment we ignore 'mode' and always use 'r0'
RETURN
# >= 0 File handle
-1 Error
*/
#undef popen /* Remove wrapper */
#ifdef __WIN__
#define popen _popen /* redefine for windows */
#endif
FILE *my_popen(const char *cmd, const char *mode __attribute__((unused)))
{
char *subst_cmd;
FILE *res_file;
subst_cmd= subst_env_var(cmd);
res_file= popen(subst_cmd, "r0");
my_free(subst_cmd, MYF(0));
return res_file;
}
#endif /* __NETWARE__ or __WIN__*/
...@@ -156,6 +156,7 @@ our $path_mysqltest_log; ...@@ -156,6 +156,7 @@ our $path_mysqltest_log;
our $path_slave_load_tmpdir; # What is this?! our $path_slave_load_tmpdir; # What is this?!
our $path_my_basedir; our $path_my_basedir;
our $opt_vardir; # A path but set directly on cmd line our $opt_vardir; # A path but set directly on cmd line
our $opt_vardir_unix; # Always unix formatted opt_vardir
our $opt_tmpdir; # A path but set directly on cmd line our $opt_tmpdir; # A path but set directly on cmd line
our $opt_usage; our $opt_usage;
...@@ -640,7 +641,7 @@ sub command_line_setup () { ...@@ -640,7 +641,7 @@ sub command_line_setup () {
{ {
$opt_vardir= "$glob_mysql_test_dir/var"; $opt_vardir= "$glob_mysql_test_dir/var";
} }
$opt_vardir_unix= $opt_vardir;
# We make the path absolute, as the server will do a chdir() before usage # We make the path absolute, as the server will do a chdir() before usage
unless ( $opt_vardir =~ m,^/, or unless ( $opt_vardir =~ m,^/, or
($glob_win32 and $opt_vardir =~ m,^[a-z]:/,i) ) ($glob_win32 and $opt_vardir =~ m,^[a-z]:/,i) )
...@@ -937,7 +938,8 @@ sub executable_setup () { ...@@ -937,7 +938,8 @@ sub executable_setup () {
if ( $glob_win32 ) if ( $glob_win32 )
{ {
$path_client_bindir= mtr_path_exists("$glob_basedir/client_release", $path_client_bindir= mtr_path_exists("$glob_basedir/client_release",
"$glob_basedir/bin"); "$glob_basedir/client_debug",
"$glob_basedir/bin",);
$exe_mysqld= mtr_exe_exists ("$path_client_bindir/mysqld-nt", $exe_mysqld= mtr_exe_exists ("$path_client_bindir/mysqld-nt",
"$path_client_bindir/mysqld", "$path_client_bindir/mysqld",
"$path_client_bindir/mysqld-debug",); "$path_client_bindir/mysqld-debug",);
...@@ -980,6 +982,7 @@ sub executable_setup () { ...@@ -980,6 +982,7 @@ sub executable_setup () {
} }
$exe_mysql_client_test= $exe_mysql_client_test=
mtr_exe_exists("$glob_basedir/tests/mysql_client_test", mtr_exe_exists("$glob_basedir/tests/mysql_client_test",
"$path_client_bindir/mysql_client_test",
"/usr/bin/false"); "/usr/bin/false");
} }
$exe_mysqlcheck= mtr_exe_exists("$path_client_bindir/mysqlcheck"); $exe_mysqlcheck= mtr_exe_exists("$path_client_bindir/mysqlcheck");
...@@ -1093,14 +1096,11 @@ sub environment_setup () { ...@@ -1093,14 +1096,11 @@ sub environment_setup () {
$ENV{'LC_COLLATE'}= "C"; $ENV{'LC_COLLATE'}= "C";
$ENV{'USE_RUNNING_SERVER'}= $glob_use_running_server; $ENV{'USE_RUNNING_SERVER'}= $glob_use_running_server;
$ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir; $ENV{'MYSQL_TEST_DIR'}= $glob_mysql_test_dir;
$ENV{'MYSQL_TEST_WINDIR'}= $glob_mysql_test_dir;
$ENV{'MASTER_MYSOCK'}= $master->[0]->{'path_mysock'}; $ENV{'MASTER_MYSOCK'}= $master->[0]->{'path_mysock'};
$ENV{'MASTER_WINMYSOCK'}= $master->[0]->{'path_mysock'};
$ENV{'MASTER_MYSOCK1'}= $master->[1]->{'path_mysock'}; $ENV{'MASTER_MYSOCK1'}= $master->[1]->{'path_mysock'};
$ENV{'MASTER_MYPORT'}= $master->[0]->{'path_myport'}; $ENV{'MASTER_MYPORT'}= $master->[0]->{'path_myport'};
$ENV{'MASTER_MYPORT1'}= $master->[1]->{'path_myport'}; $ENV{'MASTER_MYPORT1'}= $master->[1]->{'path_myport'};
$ENV{'SLAVE_MYPORT'}= $slave->[0]->{'path_myport'}; $ENV{'SLAVE_MYPORT'}= $slave->[0]->{'path_myport'};
# $ENV{'MYSQL_TCP_PORT'}= '@MYSQL_TCP_PORT@'; # FIXME
$ENV{'MYSQL_TCP_PORT'}= 3306; $ENV{'MYSQL_TCP_PORT'}= 3306;
$ENV{'IM_PATH_PID'}= $instance_manager->{path_pid}; $ENV{'IM_PATH_PID'}= $instance_manager->{path_pid};
...@@ -1112,16 +1112,6 @@ sub environment_setup () { ...@@ -1112,16 +1112,6 @@ sub environment_setup () {
$ENV{'IM_MYSQLD2_PORT'}= $instance_manager->{instances}->[1]->{port}; $ENV{'IM_MYSQLD2_PORT'}= $instance_manager->{instances}->[1]->{port};
$ENV{'IM_MYSQLD2_PATH_PID'}=$instance_manager->{instances}->[1]->{path_pid}; $ENV{'IM_MYSQLD2_PATH_PID'}=$instance_manager->{instances}->[1]->{path_pid};
if ( $glob_cygwin_perl )
{
foreach my $key ('MYSQL_TEST_WINDIR','MASTER_MYSOCK')
{
$ENV{$key}= `cygpath -w $ENV{$key}`;
$ENV{$key} =~ s,\\,\\\\,g;
chomp($ENV{$key});
}
}
# We are nice and report a bit about our settings # We are nice and report a bit about our settings
print "Using MTR_BUILD_THREAD = ",$ENV{MTR_BUILD_THREAD} || 0,"\n"; print "Using MTR_BUILD_THREAD = ",$ENV{MTR_BUILD_THREAD} || 0,"\n";
print "Using MASTER_MYPORT = $ENV{MASTER_MYPORT}\n"; print "Using MASTER_MYPORT = $ENV{MASTER_MYPORT}\n";
...@@ -2171,12 +2161,12 @@ sub mysqld_arguments ($$$$$) { ...@@ -2171,12 +2161,12 @@ sub mysqld_arguments ($$$$$) {
if ( $type eq 'master' ) if ( $type eq 'master' )
{ {
mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/master%s.trace", mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/master%s.trace",
$prefix, $opt_vardir, $sidx); $prefix, $opt_vardir_unix, $sidx);
} }
if ( $type eq 'slave' ) if ( $type eq 'slave' )
{ {
mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/slave%s.trace", mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/slave%s.trace",
$prefix, $opt_vardir, $sidx); $prefix, $opt_vardir_unix, $sidx);
} }
} }
...@@ -2506,7 +2496,7 @@ sub run_mysqltest ($) { ...@@ -2506,7 +2496,7 @@ sub run_mysqltest ($) {
if ( $opt_debug ) if ( $opt_debug )
{ {
$cmdline_mysqlcheck .= $cmdline_mysqlcheck .=
" --debug=d:t:A,$opt_vardir/log/mysqldump.trace"; " --debug=d:t:A,$opt_vardir_unix/log/mysqldump.trace";
} }
my $cmdline_mysqldump= "$exe_mysqldump --no-defaults -uroot " . my $cmdline_mysqldump= "$exe_mysqldump --no-defaults -uroot " .
...@@ -2515,7 +2505,7 @@ sub run_mysqltest ($) { ...@@ -2515,7 +2505,7 @@ sub run_mysqltest ($) {
if ( $opt_debug ) if ( $opt_debug )
{ {
$cmdline_mysqldump .= $cmdline_mysqldump .=
" --debug=d:t:A,$opt_vardir/log/mysqldump.trace"; " --debug=d:t:A,$opt_vardir_unix/log/mysqldump.trace";
} }
my $cmdline_mysqlimport= "$exe_mysqlimport -uroot " . my $cmdline_mysqlimport= "$exe_mysqlimport -uroot " .
"--port=$master->[0]->{'path_myport'} " . "--port=$master->[0]->{'path_myport'} " .
...@@ -2523,7 +2513,7 @@ sub run_mysqltest ($) { ...@@ -2523,7 +2513,7 @@ sub run_mysqltest ($) {
if ( $opt_debug ) if ( $opt_debug )
{ {
$cmdline_mysqlimport .= $cmdline_mysqlimport .=
" --debug=d:t:A,$opt_vardir/log/mysqlimport.trace"; " --debug=d:t:A,$opt_vardir_unix/log/mysqlimport.trace";
} }
my $cmdline_mysqlshow= "$exe_mysqlshow -uroot " . my $cmdline_mysqlshow= "$exe_mysqlshow -uroot " .
...@@ -2532,7 +2522,7 @@ sub run_mysqltest ($) { ...@@ -2532,7 +2522,7 @@ sub run_mysqltest ($) {
if ( $opt_debug ) if ( $opt_debug )
{ {
$cmdline_mysqlshow .= $cmdline_mysqlshow .=
" --debug=d:t:A,$opt_vardir/log/mysqlshow.trace"; " --debug=d:t:A,$opt_vardir_unix/log/mysqlshow.trace";
} }
my $cmdline_mysqlbinlog= my $cmdline_mysqlbinlog=
...@@ -2543,7 +2533,7 @@ sub run_mysqltest ($) { ...@@ -2543,7 +2533,7 @@ sub run_mysqltest ($) {
if ( $opt_debug ) if ( $opt_debug )
{ {
$cmdline_mysqlbinlog .= $cmdline_mysqlbinlog .=
" --debug=d:t:A,$opt_vardir/log/mysqlbinlog.trace"; " --debug=d:t:A,$opt_vardir_unix/log/mysqlbinlog.trace";
} }
my $cmdline_mysql= my $cmdline_mysql=
...@@ -2675,7 +2665,7 @@ sub run_mysqltest ($) { ...@@ -2675,7 +2665,7 @@ sub run_mysqltest ($) {
if ( $opt_debug ) if ( $opt_debug )
{ {
mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace", $opt_vardir); mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace", $opt_vardir_unix);
} }
if ( $opt_ssl_supported ) if ( $opt_ssl_supported )
......
...@@ -2330,10 +2330,10 @@ drop table t1; ...@@ -2330,10 +2330,10 @@ drop table t1;
set global time_zone=default; set global time_zone=default;
set time_zone=default; set time_zone=default;
DROP TABLE IF EXISTS `t1 test`; DROP TABLE IF EXISTS `t1 test`;
DROP TABLE IF EXISTS `t2 test`;
CREATE TABLE `t1 test` ( CREATE TABLE `t1 test` (
`a1` int(11) default NULL `a1` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `t2 test`;
CREATE TABLE `t2 test` ( CREATE TABLE `t2 test` (
`a2` int(11) default NULL `a2` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
......
...@@ -9,13 +9,13 @@ create table t1 ( ...@@ -9,13 +9,13 @@ create table t1 (
`a>b` text `a>b` text
); );
insert into t1 values (1, 2, 'a&b a<b a>b'); insert into t1 values (1, 2, 'a&b a<b a>b');
--exec $MYSQL --xml test -e 'select * from t1' --exec $MYSQL --xml test -e "select * from t1"
--exec $MYSQL_DUMP --xml --skip-create test --exec $MYSQL_DUMP --xml --skip-create test
--exec $MYSQL --xml test -e 'select count(*) from t1' --exec $MYSQL --xml test -e "select count(*) from t1"
--exec $MYSQL --xml test -e 'select 1 < 2 from dual' --exec $MYSQL --xml test -e "select 1 < 2 from dual"
--exec $MYSQL --xml test -e 'select 1 > 2 from dual' --exec $MYSQL --xml test -e "select 1 > 2 from dual"
--exec $MYSQL --xml test -e 'select 1 & 3 from dual' --exec $MYSQL --xml test -e "select 1 & 3 from dual"
--exec $MYSQL --xml test -e 'select null from dual' --exec $MYSQL --xml test -e "select null from dual"
drop table t1; drop table t1;
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
# var/log/mysql_client_test.trace # var/log/mysql_client_test.trace
--disable_result_log --disable_result_log
--exec echo $MYSQL_CLIENT_TEST --getopt-ll-test=25600M
--exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M --exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M
# End of 4.1 tests # End of 4.1 tests
......
...@@ -429,7 +429,7 @@ echo ; ...@@ -429,7 +429,7 @@ echo ;
# Illegal use of echo # Illegal use of echo
--error 1 --error 1
--exec echo "echo $;" | $MYSQL_TEST 2>&1 --exec echo "echo \$;" | $MYSQL_TEST 2>&1
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
...@@ -516,22 +516,22 @@ echo $novar1; ...@@ -516,22 +516,22 @@ echo $novar1;
--exec echo "let ;" | $MYSQL_TEST 2>&1 --exec echo "let ;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let $=hi;" | $MYSQL_TEST 2>&1 --exec echo "let \$=hi;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let hi=hi;" | $MYSQL_TEST 2>&1 --exec echo "let hi=hi;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let $1 hi;" | $MYSQL_TEST 2>&1 --exec echo "let \$1 hi;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let $m hi;" | $MYSQL_TEST 2>&1 --exec echo "let \$m hi;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let $hi;" | $MYSQL_TEST 2>&1 --exec echo "let \$hi;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let $ hi;" | $MYSQL_TEST 2>&1 --exec echo "let \$ hi;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let =hi;" | $MYSQL_TEST 2>&1 --exec echo "let =hi;" | $MYSQL_TEST 2>&1
...@@ -678,7 +678,7 @@ echo $i; ...@@ -678,7 +678,7 @@ echo $i;
--error 1 --error 1
--exec echo "inc i;" | $MYSQL_TEST 2>&1 --exec echo "inc i;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let \$i=100; inc \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1 --exec echo "let \\\$i=100; inc \\\$i 1000; echo \\\$i;" | $MYSQL_TEST 2>&1
inc $i; inc $i; inc $i; --echo $i inc $i; inc $i; inc $i; --echo $i
echo $i; echo $i;
...@@ -706,7 +706,7 @@ echo $d; ...@@ -706,7 +706,7 @@ echo $d;
--error 1 --error 1
--exec echo "dec i;" | $MYSQL_TEST 2>&1 --exec echo "dec i;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let \$i=100; dec \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1 --exec echo "let \\\$i=100; dec \\\$i 1000; echo \\\$i;" | $MYSQL_TEST 2>&1
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
...@@ -761,11 +761,11 @@ while ($i) ...@@ -761,11 +761,11 @@ while ($i)
--error 1 --error 1
--exec echo "source include/mysqltest_while.inc;" | $MYSQL_TEST 2>&1 --exec echo "source include/mysqltest_while.inc;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "while \$i;" | $MYSQL_TEST 2>&1 --exec echo "while \\\$i;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "while (\$i;" | $MYSQL_TEST 2>&1 --exec echo "while (\\\$i;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "let \$i=1; while (\$i) dec \$i;" | $MYSQL_TEST 2>&1 --exec echo "let \\\$i=1; while (\\\$i) dec \\\$i;" | $MYSQL_TEST 2>&1
--error 1 --error 1
--exec echo "};" | $MYSQL_TEST 2>&1 --exec echo "};" | $MYSQL_TEST 2>&1
--error 1 --error 1
...@@ -877,22 +877,22 @@ select "a" as col1, "c" as col2; ...@@ -877,22 +877,22 @@ select "a" as col1, "c" as col2;
--exec echo "connect (con1,localhost,root,,,,,SMTP POP);" | $MYSQL_TEST 2>&1 --exec echo "connect (con1,localhost,root,,,,,SMTP POP);" | $MYSQL_TEST 2>&1
# Repeat connect/disconnect # Repeat connect/disconnect
--exec echo "let \$i=100;" > var/tmp/con.sql --exec echo "let \\\$i=100;" > var/tmp/con.sql
--exec echo "while (\$i)" >> var/tmp/con.sql --exec echo "while (\\\$i)" >> var/tmp/con.sql
--exec echo "{" >> var/tmp/con.sql --exec echo "{" >> var/tmp/con.sql
--exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql --exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql
--exec echo " disconnect test_con1; " >> var/tmp/con.sql --exec echo " disconnect test_con1; " >> var/tmp/con.sql
--exec echo " dec \$i; " >> var/tmp/con.sql --exec echo " dec \\\$i; " >> var/tmp/con.sql
--exec echo "}" >> var/tmp/con.sql --exec echo "}" >> var/tmp/con.sql
--exec echo "source var/tmp/con.sql; echo OK;" | $MYSQL_TEST 2>&1 --exec echo "source var/tmp/con.sql; echo OK;" | $MYSQL_TEST 2>&1
# Repeat connect/disconnect, exceed max number of connections # Repeat connect/disconnect, exceed max number of connections
--exec echo "let \$i=200;" > var/tmp/con.sql --exec echo "let \\\$i=200;" > var/tmp/con.sql
--exec echo "while (\$i)" >> var/tmp/con.sql --exec echo "while (\\\$i)" >> var/tmp/con.sql
--exec echo "{" >> var/tmp/con.sql --exec echo "{" >> var/tmp/con.sql
--exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql --exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql
--exec echo " disconnect test_con1; " >> var/tmp/con.sql --exec echo " disconnect test_con1; " >> var/tmp/con.sql
--exec echo " dec \$i; " >> var/tmp/con.sql --exec echo " dec \\\$i; " >> var/tmp/con.sql
--exec echo "}" >> var/tmp/con.sql --exec echo "}" >> var/tmp/con.sql
--error 1 --error 1
--exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1 --exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1
...@@ -1001,7 +1001,7 @@ select "this will be executed"; ...@@ -1001,7 +1001,7 @@ select "this will be executed";
# #
# Test that a test file that does not generate any output fails. # Test that a test file that does not generate any output fails.
# #
--exec echo "let \$i= 1;" > $MYSQL_TEST_DIR/var/tmp/query.sql --exec echo "let \\\$i= 1;" > $MYSQL_TEST_DIR/var/tmp/query.sql
--error 1 --error 1
--exec $MYSQL_TEST -x var/tmp/query.sql 2>&1 --exec $MYSQL_TEST -x var/tmp/query.sql 2>&1
......
...@@ -12,7 +12,7 @@ show slave status; ...@@ -12,7 +12,7 @@ show slave status;
change master to master_host='127.0.0.1'; change master to master_host='127.0.0.1';
# The following needs to be cleaned up when change master is fixed # The following needs to be cleaned up when change master is fixed
--replace_result $MASTER_MYPORT MASTER_PORT $MYSQL_TCP_PORT MASTER_PORT --replace_result $MYSQL_TCP_PORT MASTER_PORT
--replace_column 1 # 8 # 9 # 23 # 33 # --replace_column 1 # 8 # 9 # 23 # 33 #
show slave status; show slave status;
--replace_result $MASTER_MYPORT MASTER_PORT --replace_result $MASTER_MYPORT MASTER_PORT
......
...@@ -77,7 +77,8 @@ type=ISAM; ...@@ -77,7 +77,8 @@ type=ISAM;
INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y'); INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y');
INSERT INTO user VALUES ('localhost','', '','N','N','N','N','N','N','N','N','N'); INSERT INTO user VALUES ('localhost','', '','N','N','N','N','N','N','N','N','N');
-- exec $MYSQL_FIX_SYSTEM_TABLES --database=test # Call the "shell script" $MYSQL_FIX_SYSTEM_TABLES using system
-- system $MYSQL_FIX_SYSTEM_TABLES --database=test > /dev/null
-- enable_query_log -- enable_query_log
-- enable_result_log -- enable_result_log
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment