Commit bd286b23 authored by unknown's avatar unknown

support for eval_result and let $var = `query` syntax in mysql-test

fixes for rpl_log test to make it config-independent


BitKeeper/etc/ignore:
  Added mysql-test/r/rpl_log.eval to the ignore list
client/mysqltest.c:
  support for eval_result and let $var = `query` syntax
mysql-test/Makefile.am:
  import more variables into mysql-test-run
mysql-test/mysql-test-run.sh:
  if we got wrong result on eval_result test case, diff against the
  expanded result, not the template
mysql-test/r/rpl_log.result:
  change config-dependent parts of the result to dynamic variables
mysql-test/t/rpl_log.test:
  get server version from the server
  remove obsoleted replace hack to solve port problem - use eval_result
  instead
parent 0a6cf93d
...@@ -371,3 +371,4 @@ sql/share/mysql ...@@ -371,3 +371,4 @@ sql/share/mysql
.gdbinit .gdbinit
.vimrc .vimrc
scripts/mysqld_safe scripts/mysqld_safe
mysql-test/r/rpl_log.eval
...@@ -164,7 +164,7 @@ Q_SEND, Q_REAP, ...@@ -164,7 +164,7 @@ Q_SEND, Q_REAP,
Q_DIRTY_CLOSE, Q_REPLACE, Q_DIRTY_CLOSE, Q_REPLACE,
Q_PING, Q_EVAL, Q_PING, Q_EVAL,
Q_RPL_PROBE, Q_ENABLE_RPL_PARSE, Q_RPL_PROBE, Q_ENABLE_RPL_PARSE,
Q_DISABLE_RPL_PARSE, Q_DISABLE_RPL_PARSE, Q_EVAL_RESULT,
Q_UNKNOWN, /* Unknown command. */ Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */ Q_COMMENT, /* Comments, ignored. */
Q_COMMENT_WITH_COMMAND Q_COMMENT_WITH_COMMAND
...@@ -173,7 +173,7 @@ Q_COMMENT_WITH_COMMAND ...@@ -173,7 +173,7 @@ Q_COMMENT_WITH_COMMAND
/* this should really be called command */ /* this should really be called command */
struct st_query struct st_query
{ {
char *query, *query_buf,*first_argument; char *query, *query_buf,*first_argument,*end;
int first_word_len; int first_word_len;
my_bool abort_on_error, require_file; my_bool abort_on_error, require_file;
uint expected_errno[MAX_EXPECTED_ERRORS]; uint expected_errno[MAX_EXPECTED_ERRORS];
...@@ -195,7 +195,7 @@ const char *command_names[] = { ...@@ -195,7 +195,7 @@ const char *command_names[] = {
"dirty_close", "replace_result", "dirty_close", "replace_result",
"ping", "eval", "ping", "eval",
"rpl_probe", "enable_rpl_parse", "rpl_probe", "enable_rpl_parse",
"disable_rpl_parse", "disable_rpl_parse", "eval_result",
0 0
}; };
...@@ -238,10 +238,12 @@ void free_pointer_array(POINTER_ARRAY *pa); ...@@ -238,10 +238,12 @@ void free_pointer_array(POINTER_ARRAY *pa);
static int initialize_replace_buffer(void); static int initialize_replace_buffer(void);
static void free_replace_buffer(void); static void free_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);
void str_to_file(const char* fname, char* str, int size);
struct st_replace *glob_replace; struct st_replace *glob_replace;
static char *out_buff; static char *out_buff;
static uint out_length; static uint out_length;
static int eval_result = 0;
static void do_eval(DYNAMIC_STRING* query_eval, const char* query) static void do_eval(DYNAMIC_STRING* query_eval, const char* query)
{ {
...@@ -298,7 +300,7 @@ static void close_files() ...@@ -298,7 +300,7 @@ static void close_files()
{ {
do do
{ {
if (*cur_file != stdin) if (*cur_file != stdin && *cur_file)
my_fclose(*cur_file,MYF(0)); my_fclose(*cur_file,MYF(0));
} while (cur_file-- != file_stack); } while (cur_file-- != file_stack);
} }
...@@ -393,25 +395,53 @@ int hex_val(int c) ...@@ -393,25 +395,53 @@ int hex_val(int c)
int dyn_string_cmp(DYNAMIC_STRING* ds, const char* fname) int dyn_string_cmp(DYNAMIC_STRING* ds, const char* fname)
{ {
MY_STAT stat_info; MY_STAT stat_info;
char *tmp; char *tmp, *res_ptr;
char eval_file[FN_REFLEN];
int res; int res;
uint res_len;
int fd; int fd;
DYNAMIC_STRING res_ds;
DBUG_ENTER("dyn_string_cmp"); DBUG_ENTER("dyn_string_cmp");
if (!my_stat(fname, &stat_info, MYF(MY_WME))) if (!my_stat(fname, &stat_info, MYF(MY_WME)))
die(NullS); die(NullS);
if (stat_info.st_size != ds->length) if (!eval_result && stat_info.st_size != ds->length)
DBUG_RETURN(2); DBUG_RETURN(2);
if (!(tmp = (char*) my_malloc(ds->length, MYF(MY_WME)))) if (!(tmp = (char*) my_malloc(stat_info.st_size + 1, MYF(MY_WME))))
die(NullS); die(NullS);
if ((fd = my_open(fname, O_RDONLY, MYF(MY_WME))) < 0) if ((fd = my_open(fname, O_RDONLY, MYF(MY_WME))) < 0)
die(NullS); die(NullS);
if (my_read(fd, (byte*)tmp, stat_info.st_size, MYF(MY_WME|MY_NABP))) if (my_read(fd, (byte*)tmp, stat_info.st_size, MYF(MY_WME|MY_NABP)))
die(NullS); die(NullS);
res = (memcmp(tmp, ds->str, stat_info.st_size)) ? 1 : 0; tmp[stat_info.st_size] = 0;
init_dynamic_string(&res_ds, "", 0, 65536);
if (eval_result)
{
do_eval(&res_ds, tmp);
res_ptr = res_ds.str;
if((res_len = res_ds.length) != ds->length)
{
res = 2;
goto err;
}
}
else
{
res_ptr = tmp;
res_len = stat_info.st_size;
}
res = (memcmp(res_ptr, ds->str, res_len)) ? 1 : 0;
err:
if(res && eval_result)
str_to_file(fn_format(eval_file, fname, "", ".eval",2), res_ptr,
res_len);
my_free((gptr) tmp, MYF(0)); my_free((gptr) tmp, MYF(0));
my_close(fd, MYF(MY_WME)); my_close(fd, MYF(MY_WME));
dynstr_free(&res_ds);
DBUG_RETURN(res); DBUG_RETURN(res);
} }
...@@ -508,7 +538,6 @@ int var_set(char* var_name, char* var_name_end, char* var_val, ...@@ -508,7 +538,6 @@ int var_set(char* var_name, char* var_name_end, char* var_val,
char* var_val_end) char* var_val_end)
{ {
int digit; int digit;
int val_len;
VAR* v; VAR* v;
if (*var_name++ != '$') if (*var_name++ != '$')
{ {
...@@ -523,21 +552,8 @@ int var_set(char* var_name, char* var_name_end, char* var_val, ...@@ -523,21 +552,8 @@ int var_set(char* var_name, char* var_name_end, char* var_val,
} }
else else
v = var_reg + digit; v = var_reg + digit;
if (v->alloced_len < (val_len = (int)(var_val_end - var_val)+1))
{ return eval_expr(v, var_val, (const char**)&var_val_end);
v->alloced_len = (val_len < MIN_VAR_ALLOC) ? MIN_VAR_ALLOC : val_len;
if (!(v->str_val =
v->str_val ? my_realloc(v->str_val, v->alloced_len, MYF(MY_WME)) :
my_malloc(v->alloced_len, MYF(MY_WME))))
die("Out of memory");
}
val_len--;
memcpy(v->str_val, var_val, val_len);
v->str_val_len = val_len;
v->str_val[val_len] = 0;
v->int_val = atoi(v->str_val);
v->int_dirty=0;
return 0;
} }
int open_file(const char* name) int open_file(const char* name)
...@@ -565,6 +581,35 @@ int do_source(struct st_query* q) ...@@ -565,6 +581,35 @@ int do_source(struct st_query* q)
return open_file(name); return open_file(name);
} }
int var_query_set(VAR* v, const char* p, const char** p_end)
{
char* end = (char*)((p_end && *p_end) ? *p_end : p + strlen(p));
MYSQL_RES *res;
MYSQL_ROW row;
MYSQL* mysql = &cur_con->mysql;
LINT_INIT(res);
while (end > p && *end != '`')
--end;
if (p == end)
die("Syntax error in query, missing '`'");
++p;
if (mysql_real_query(mysql, p, (int)(end - p)) ||
!(res = mysql_store_result(mysql)))
{
*end = 0;
die("Error running query '%s': %s", p, mysql_error(mysql));
}
if ((row = mysql_fetch_row(res)) && row[0])
eval_expr(v, row[0], 0);
else
eval_expr(v, "", 0);
mysql_free_result(res);
return 0;
}
int eval_expr(VAR* v, const char* p, const char** p_end) int eval_expr(VAR* v, const char* p, const char** p_end)
{ {
...@@ -577,10 +622,27 @@ int eval_expr(VAR* v, const char* p, const char** p_end) ...@@ -577,10 +622,27 @@ int eval_expr(VAR* v, const char* p, const char** p_end)
return 0; return 0;
} }
} }
else if(*p == '`')
{
return var_query_set(v, p, p_end);
}
else else
{ {
v->str_val = (char*)p; int new_val_len = (p_end && *p_end) ?
v->str_val_len = (p_end && *p_end) ? (int) (*p_end - p) : (int) strlen(p); (int) (*p_end - p) : (int) strlen(p);
if (new_val_len + 1 >= v->alloced_len)
{
v->alloced_len = (new_val_len < MIN_VAR_ALLOC - 1) ?
MIN_VAR_ALLOC : new_val_len + 1;
if (!(v->str_val =
v->str_val ? my_realloc(v->str_val, v->alloced_len,
MYF(MY_WME)) :
my_malloc(v->alloced_len, MYF(MY_WME))))
die("Out of memory");
}
v->str_val_len = new_val_len;
memcpy(v->str_val, p, new_val_len);
v->str_val[new_val_len] = 0;
v->int_val=atoi(p); v->int_val=atoi(p);
v->int_dirty=0; v->int_dirty=0;
return 0; return 0;
...@@ -724,9 +786,7 @@ int do_let(struct st_query* q) ...@@ -724,9 +786,7 @@ int do_let(struct st_query* q)
while(*p && isspace(*p)) while(*p && isspace(*p))
p++; p++;
var_val_start = p; var_val_start = p;
while(*p && !isspace(*p)) return var_set(var_name, var_name_end, var_val_start, q->end);
p++;
return var_set(var_name, var_name_end, var_val_start, p);
} }
int do_rpl_probe(struct st_query* __attribute__((unused)) q) int do_rpl_probe(struct st_query* __attribute__((unused)) q)
...@@ -1400,7 +1460,7 @@ int read_query(struct st_query** q_ptr) ...@@ -1400,7 +1460,7 @@ int read_query(struct st_query** q_ptr)
q->first_word_len = (uint) (p - q->query); q->first_word_len = (uint) (p - q->query);
while (*p && isspace(*p)) p++; while (*p && isspace(*p)) p++;
q->first_argument=p; q->first_argument=p;
q->end = strend(q->query);
parser.read_lines++; parser.read_lines++;
return 0; return 0;
} }
...@@ -1787,11 +1847,13 @@ static VAR* var_init(const char* name, int name_len, const char* val, ...@@ -1787,11 +1847,13 @@ static VAR* var_init(const char* name, int name_len, const char* val,
if(!val_len) if(!val_len)
val_len = strlen(val) ; val_len = strlen(val) ;
val_alloc_len = val_len + 16; /* room to grow */ val_alloc_len = val_len + 16; /* room to grow */
if(!(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var) + val_alloc_len if(!(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
+ name_len, MYF(MY_WME)))) + name_len, MYF(MY_WME))))
die("Out of memory"); die("Out of memory");
tmp_var->name = (char*)tmp_var + sizeof(*tmp_var); tmp_var->name = (char*)tmp_var + sizeof(*tmp_var);
tmp_var->str_val = tmp_var->name + name_len; if(!(tmp_var->str_val = my_malloc(val_alloc_len, MYF(MY_WME))))
die("Out of memory");
memcpy(tmp_var->name, name, name_len); memcpy(tmp_var->name, name, name_len);
memcpy(tmp_var->str_val, val, val_len + 1); memcpy(tmp_var->str_val, val, val_len + 1);
tmp_var->name_len = name_len; tmp_var->name_len = name_len;
...@@ -1804,6 +1866,7 @@ static VAR* var_init(const char* name, int name_len, const char* val, ...@@ -1804,6 +1866,7 @@ static VAR* var_init(const char* name, int name_len, const char* val,
static void var_free(void* v) static void var_free(void* v)
{ {
my_free(((VAR*)v)->str_val, MYF(MY_WME));
my_free(v, MYF(MY_WME)); my_free(v, MYF(MY_WME));
} }
...@@ -1901,6 +1964,7 @@ int main(int argc, char** argv) ...@@ -1901,6 +1964,7 @@ int main(int argc, char** argv)
case Q_ECHO: do_echo(q); break; case Q_ECHO: do_echo(q); break;
case Q_SYSTEM: do_system(q); break; case Q_SYSTEM: do_system(q); break;
case Q_LET: do_let(q); break; case Q_LET: do_let(q); break;
case Q_EVAL_RESULT: eval_result = 1; break;
case Q_EVAL: case Q_EVAL:
if (q->query == q->query_buf) if (q->query == q->query_buf)
q->query += q->first_word_len; q->query += q->first_word_len;
......
...@@ -59,6 +59,8 @@ SUFFIXES = .sh ...@@ -59,6 +59,8 @@ SUFFIXES = .sh
-e 's!@''libexecdir''@!$(libexecdir)!g' \ -e 's!@''libexecdir''@!$(libexecdir)!g' \
-e 's!@''PERL''@!@PERL@!' \ -e 's!@''PERL''@!@PERL@!' \
-e 's!@''VERSION''@!@VERSION@!' \ -e 's!@''VERSION''@!@VERSION@!' \
-e 's!@''MYSQL_BASE_VERSION''@!@MYSQL_BASE_VERSION@!' \
-e 's!@''MYSQL_NO_DASH_VERSION''@!@MYSQL_NO_DASH_VERSION@!' \
-e 's!@''MYSQL_SERVER_SUFFIX''@!@MYSQL_SERVER_SUFFIX@!' \ -e 's!@''MYSQL_SERVER_SUFFIX''@!@MYSQL_SERVER_SUFFIX@!' \
$< > $@-t $< > $@-t
@CHMOD@ +x $@-t @CHMOD@ +x $@-t
......
...@@ -333,6 +333,13 @@ show_failed_diff () ...@@ -333,6 +333,13 @@ show_failed_diff ()
{ {
reject_file=r/$1.reject reject_file=r/$1.reject
result_file=r/$1.result result_file=r/$1.result
eval_file=r/$1.eval
if [ -f $eval_file ]
then
result_file=$eval_file
fi
if [ -x "$DIFF" ] && [ -f $reject_file ] if [ -x "$DIFF" ] && [ -f $reject_file ]
then then
echo "Below are the diffs between actual and expected results:" echo "Below are the diffs between actual and expected results:"
......
Log_name Pos Event_type Server_id Log_seq Info Log_name Pos Event_type Server_id Log_seq Info
master-bin.001 4 Start 1 1 Server ver: 4.0.0-debug-log, Binlog ver: 2 master-bin.001 4 Start 1 1 Server ver: $VERSION, Binlog ver: 2
master-bin.001 79 Query 1 2 use test; create table t1(n int not null auto_increment primary key) master-bin.001 79 Query 1 2 use test; create table t1(n int not null auto_increment primary key)
master-bin.001 172 Intvar 1 3 INSERT_ID=1 master-bin.001 172 Intvar 1 3 INSERT_ID=1
master-bin.001 200 Query 1 4 use test; insert into t1 values (NULL) master-bin.001 200 Query 1 4 use test; insert into t1 values (NULL)
master-bin.001 263 Query 1 5 use test; drop table t1 master-bin.001 263 Query 1 5 use test; drop table t1
master-bin.001 311 Query 1 6 use test; create table t1 (word char(20) not null) master-bin.001 311 Query 1 6 use test; create table t1 (word char(20) not null)
master-bin.001 386 Load 1 7 use test; LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 FIELDS TERMINATED BY '\t' ESCAPED BY '\\' LINES TERMINATED BY '\n' (word) master-bin.001 386 Load 1 7 use test; LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 FIELDS TERMINATED BY '\\t' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n' (word)
master-bin.001 468 Query 1 8 use test; drop table t1 master-bin.001 468 Query 1 8 use test; drop table t1
Log_name Pos Event_type Server_id Log_seq Info Log_name Pos Event_type Server_id Log_seq Info
master-bin.001 79 Query 1 2 use test; create table t1(n int not null auto_increment primary key) master-bin.001 79 Query 1 2 use test; create table t1(n int not null auto_increment primary key)
...@@ -21,12 +21,12 @@ master-bin.001 172 Intvar 1 3 INSERT_ID=1 ...@@ -21,12 +21,12 @@ master-bin.001 172 Intvar 1 3 INSERT_ID=1
master-bin.001 200 Query 1 4 use test; insert into t1 values (NULL) master-bin.001 200 Query 1 4 use test; insert into t1 values (NULL)
master-bin.001 263 Query 1 5 use test; drop table t1 master-bin.001 263 Query 1 5 use test; drop table t1
master-bin.001 311 Query 1 6 use test; create table t1 (word char(20) not null) master-bin.001 311 Query 1 6 use test; create table t1 (word char(20) not null)
master-bin.001 386 Load 1 7 use test; LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 FIELDS TERMINATED BY '\t' ESCAPED BY '\\' LINES TERMINATED BY '\n' (word) master-bin.001 386 Load 1 7 use test; LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 FIELDS TERMINATED BY '\\t' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n' (word)
master-bin.001 468 Query 1 8 use test; drop table t1 master-bin.001 468 Query 1 8 use test; drop table t1
master-bin.001 516 Rotate 1 9 master-bin.002;pos=4 master-bin.001 516 Rotate 1 9 master-bin.002;pos=4
master-bin.001 557 Stop 1 10 master-bin.001 557 Stop 1 10
Log_name Pos Event_type Server_id Log_seq Info Log_name Pos Event_type Server_id Log_seq Info
master-bin.002 4 Start 1 1 Server ver: 4.0.0-debug-log, Binlog ver: 2 master-bin.002 4 Start 1 1 Server ver: $VERSION, Binlog ver: 2
master-bin.002 79 Query 1 2 use test; create table t1 (n int) master-bin.002 79 Query 1 2 use test; create table t1 (n int)
master-bin.002 137 Query 1 3 use test; insert into t1 values (1) master-bin.002 137 Query 1 3 use test; insert into t1 values (1)
master-bin.002 197 Query 1 4 use test; drop table t1 master-bin.002 197 Query 1 4 use test; drop table t1
...@@ -38,7 +38,7 @@ slave-bin.001 ...@@ -38,7 +38,7 @@ slave-bin.001
slave-bin.002 slave-bin.002
Log_name Pos Event_type Server_id Log_seq Info Log_name Pos Event_type Server_id Log_seq Info
slave-bin.001 4 Start 2 1 Server ver: 4.0.0-debug-log, Binlog ver: 2 slave-bin.001 4 Start 2 1 Server ver: 4.0.0-debug-log, Binlog ver: 2
slave-bin.001 79 Slave 2 2 host=127.0.0.1,port=9306,log=master-bin.001,pos=4 slave-bin.001 79 Slave 2 2 host=127.0.0.1,port=$MASTER_MYPORT,log=master-bin.001,pos=4
slave-bin.001 132 Query 1 2 use test; create table t1(n int not null auto_increment primary key) slave-bin.001 132 Query 1 2 use test; create table t1(n int not null auto_increment primary key)
slave-bin.001 225 Intvar 1 3 INSERT_ID=1 slave-bin.001 225 Intvar 1 3 INSERT_ID=1
slave-bin.001 253 Query 1 4 use test; insert into t1 values (NULL) slave-bin.001 253 Query 1 4 use test; insert into t1 values (NULL)
...@@ -49,9 +49,9 @@ slave-bin.001 487 Rotate 2 3 slave-bin.002;pos=4; forced by master ...@@ -49,9 +49,9 @@ slave-bin.001 487 Rotate 2 3 slave-bin.002;pos=4; forced by master
slave-bin.001 527 Stop 2 4 slave-bin.001 527 Stop 2 4
Log_name Pos Event_type Server_id Log_seq Info Log_name Pos Event_type Server_id Log_seq Info
slave-bin.002 4 Start 2 1 Server ver: 4.0.0-debug-log, Binlog ver: 2 slave-bin.002 4 Start 2 1 Server ver: 4.0.0-debug-log, Binlog ver: 2
slave-bin.002 79 Slave 2 2 host=127.0.0.1,port=9306,log=master-bin.002,pos=4 slave-bin.002 79 Slave 2 2 host=127.0.0.1,port=$MASTER_MYPORT,log=master-bin.002,pos=4
slave-bin.002 132 Query 1 2 use test; create table t1 (n int) slave-bin.002 132 Query 1 2 use test; create table t1 (n int)
slave-bin.002 190 Query 1 3 use test; insert into t1 values (1) slave-bin.002 190 Query 1 3 use test; insert into t1 values (1)
slave-bin.002 250 Query 1 4 use test; drop table t1 slave-bin.002 250 Query 1 4 use test; drop table t1
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 1 master-bin.002 245 Yes 0 0 4 127.0.0.1 root $MASTER_MYPORT 1 master-bin.002 245 Yes 0 0 4
source include/master-slave.inc; source include/master-slave.inc;
eval_result; #result depends on some server specific params
#clean up slave binlogs #clean up slave binlogs
connection slave; connection slave;
...@@ -28,10 +29,10 @@ show binlog events in 'master-bin.002'; ...@@ -28,10 +29,10 @@ show binlog events in 'master-bin.002';
show master logs; show master logs;
save_master_pos; save_master_pos;
connection slave; connection slave;
let $VERSION=`select version()`;
slave start; slave start;
sync_with_master; sync_with_master;
show master logs; show master logs;
show binlog events in 'slave-bin.001' from 4; show binlog events in 'slave-bin.001' from 4;
show binlog events in 'slave-bin.002' from 4; show binlog events in 'slave-bin.002' from 4;
--replace_result 9306 9999 3334 9999 3335 9999
show slave status; show slave status;
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