Skip to content

Commit ea2e911

Browse files
author
sasha@mysql.sashanet.com
committed
support for eval_result and let $var = query syntax in mysql-test
fixes for rpl_log test to make it config-independent
1 parent 12b442b commit ea2e911

File tree

6 files changed

+116
-41
lines changed

6 files changed

+116
-41
lines changed

.bzrignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,4 @@ sql/share/mysql
371371
.gdbinit
372372
.vimrc
373373
scripts/mysqld_safe
374+
mysql-test/r/rpl_log.eval

client/mysqltest.c

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Q_SEND, Q_REAP,
164164
Q_DIRTY_CLOSE, Q_REPLACE,
165165
Q_PING, Q_EVAL,
166166
Q_RPL_PROBE, Q_ENABLE_RPL_PARSE,
167-
Q_DISABLE_RPL_PARSE,
167+
Q_DISABLE_RPL_PARSE, Q_EVAL_RESULT,
168168
Q_UNKNOWN, /* Unknown command. */
169169
Q_COMMENT, /* Comments, ignored. */
170170
Q_COMMENT_WITH_COMMAND
@@ -173,7 +173,7 @@ Q_COMMENT_WITH_COMMAND
173173
/* this should really be called command */
174174
struct st_query
175175
{
176-
char *query, *query_buf,*first_argument;
176+
char *query, *query_buf,*first_argument,*end;
177177
int first_word_len;
178178
my_bool abort_on_error, require_file;
179179
uint expected_errno[MAX_EXPECTED_ERRORS];
@@ -195,7 +195,7 @@ const char *command_names[] = {
195195
"dirty_close", "replace_result",
196196
"ping", "eval",
197197
"rpl_probe", "enable_rpl_parse",
198-
"disable_rpl_parse",
198+
"disable_rpl_parse", "eval_result",
199199
0
200200
};
201201

@@ -238,10 +238,12 @@ void free_pointer_array(POINTER_ARRAY *pa);
238238
static int initialize_replace_buffer(void);
239239
static void free_replace_buffer(void);
240240
static void do_eval(DYNAMIC_STRING* query_eval, const char* query);
241+
void str_to_file(const char* fname, char* str, int size);
241242

242243
struct st_replace *glob_replace;
243244
static char *out_buff;
244245
static uint out_length;
246+
static int eval_result = 0;
245247

246248
static void do_eval(DYNAMIC_STRING* query_eval, const char* query)
247249
{
@@ -298,7 +300,7 @@ static void close_files()
298300
{
299301
do
300302
{
301-
if (*cur_file != stdin)
303+
if (*cur_file != stdin && *cur_file)
302304
my_fclose(*cur_file,MYF(0));
303305
} while (cur_file-- != file_stack);
304306
}
@@ -393,25 +395,53 @@ int hex_val(int c)
393395
int dyn_string_cmp(DYNAMIC_STRING* ds, const char* fname)
394396
{
395397
MY_STAT stat_info;
396-
char *tmp;
398+
char *tmp, *res_ptr;
399+
char eval_file[FN_REFLEN];
397400
int res;
401+
uint res_len;
398402
int fd;
403+
DYNAMIC_STRING res_ds;
399404
DBUG_ENTER("dyn_string_cmp");
400405

401406
if (!my_stat(fname, &stat_info, MYF(MY_WME)))
402407
die(NullS);
403-
if (stat_info.st_size != ds->length)
408+
if (!eval_result && stat_info.st_size != ds->length)
404409
DBUG_RETURN(2);
405-
if (!(tmp = (char*) my_malloc(ds->length, MYF(MY_WME))))
410+
if (!(tmp = (char*) my_malloc(stat_info.st_size + 1, MYF(MY_WME))))
406411
die(NullS);
407412
if ((fd = my_open(fname, O_RDONLY, MYF(MY_WME))) < 0)
408413
die(NullS);
409414
if (my_read(fd, (byte*)tmp, stat_info.st_size, MYF(MY_WME|MY_NABP)))
410415
die(NullS);
411-
res = (memcmp(tmp, ds->str, stat_info.st_size)) ? 1 : 0;
416+
tmp[stat_info.st_size] = 0;
417+
init_dynamic_string(&res_ds, "", 0, 65536);
418+
if (eval_result)
419+
{
420+
do_eval(&res_ds, tmp);
421+
res_ptr = res_ds.str;
422+
if((res_len = res_ds.length) != ds->length)
423+
{
424+
res = 2;
425+
goto err;
426+
}
427+
}
428+
else
429+
{
430+
res_ptr = tmp;
431+
res_len = stat_info.st_size;
432+
}
433+
434+
res = (memcmp(res_ptr, ds->str, res_len)) ? 1 : 0;
435+
436+
err:
437+
if(res && eval_result)
438+
str_to_file(fn_format(eval_file, fname, "", ".eval",2), res_ptr,
439+
res_len);
440+
412441
my_free((gptr) tmp, MYF(0));
413442
my_close(fd, MYF(MY_WME));
414-
443+
dynstr_free(&res_ds);
444+
415445
DBUG_RETURN(res);
416446
}
417447

@@ -508,7 +538,6 @@ int var_set(char* var_name, char* var_name_end, char* var_val,
508538
char* var_val_end)
509539
{
510540
int digit;
511-
int val_len;
512541
VAR* v;
513542
if (*var_name++ != '$')
514543
{
@@ -523,21 +552,8 @@ int var_set(char* var_name, char* var_name_end, char* var_val,
523552
}
524553
else
525554
v = var_reg + digit;
526-
if (v->alloced_len < (val_len = (int)(var_val_end - var_val)+1))
527-
{
528-
v->alloced_len = (val_len < MIN_VAR_ALLOC) ? MIN_VAR_ALLOC : val_len;
529-
if (!(v->str_val =
530-
v->str_val ? my_realloc(v->str_val, v->alloced_len, MYF(MY_WME)) :
531-
my_malloc(v->alloced_len, MYF(MY_WME))))
532-
die("Out of memory");
533-
}
534-
val_len--;
535-
memcpy(v->str_val, var_val, val_len);
536-
v->str_val_len = val_len;
537-
v->str_val[val_len] = 0;
538-
v->int_val = atoi(v->str_val);
539-
v->int_dirty=0;
540-
return 0;
555+
556+
return eval_expr(v, var_val, (const char**)&var_val_end);
541557
}
542558

543559
int open_file(const char* name)
@@ -565,6 +581,35 @@ int do_source(struct st_query* q)
565581
return open_file(name);
566582
}
567583

584+
int var_query_set(VAR* v, const char* p, const char** p_end)
585+
{
586+
char* end = (char*)((p_end && *p_end) ? *p_end : p + strlen(p));
587+
MYSQL_RES *res;
588+
MYSQL_ROW row;
589+
MYSQL* mysql = &cur_con->mysql;
590+
LINT_INIT(res);
591+
592+
while (end > p && *end != '`')
593+
--end;
594+
if (p == end)
595+
die("Syntax error in query, missing '`'");
596+
++p;
597+
598+
if (mysql_real_query(mysql, p, (int)(end - p)) ||
599+
!(res = mysql_store_result(mysql)))
600+
{
601+
*end = 0;
602+
die("Error running query '%s': %s", p, mysql_error(mysql));
603+
}
604+
605+
if ((row = mysql_fetch_row(res)) && row[0])
606+
eval_expr(v, row[0], 0);
607+
else
608+
eval_expr(v, "", 0);
609+
610+
mysql_free_result(res);
611+
return 0;
612+
}
568613

569614
int eval_expr(VAR* v, const char* p, const char** p_end)
570615
{
@@ -577,10 +622,27 @@ int eval_expr(VAR* v, const char* p, const char** p_end)
577622
return 0;
578623
}
579624
}
625+
else if(*p == '`')
626+
{
627+
return var_query_set(v, p, p_end);
628+
}
580629
else
581630
{
582-
v->str_val = (char*)p;
583-
v->str_val_len = (p_end && *p_end) ? (int) (*p_end - p) : (int) strlen(p);
631+
int new_val_len = (p_end && *p_end) ?
632+
(int) (*p_end - p) : (int) strlen(p);
633+
if (new_val_len + 1 >= v->alloced_len)
634+
{
635+
v->alloced_len = (new_val_len < MIN_VAR_ALLOC - 1) ?
636+
MIN_VAR_ALLOC : new_val_len + 1;
637+
if (!(v->str_val =
638+
v->str_val ? my_realloc(v->str_val, v->alloced_len,
639+
MYF(MY_WME)) :
640+
my_malloc(v->alloced_len, MYF(MY_WME))))
641+
die("Out of memory");
642+
}
643+
v->str_val_len = new_val_len;
644+
memcpy(v->str_val, p, new_val_len);
645+
v->str_val[new_val_len] = 0;
584646
v->int_val=atoi(p);
585647
v->int_dirty=0;
586648
return 0;
@@ -724,9 +786,7 @@ int do_let(struct st_query* q)
724786
while(*p && isspace(*p))
725787
p++;
726788
var_val_start = p;
727-
while(*p && !isspace(*p))
728-
p++;
729-
return var_set(var_name, var_name_end, var_val_start, p);
789+
return var_set(var_name, var_name_end, var_val_start, q->end);
730790
}
731791

732792
int do_rpl_probe(struct st_query* __attribute__((unused)) q)
@@ -1400,7 +1460,7 @@ int read_query(struct st_query** q_ptr)
14001460
q->first_word_len = (uint) (p - q->query);
14011461
while (*p && isspace(*p)) p++;
14021462
q->first_argument=p;
1403-
1463+
q->end = strend(q->query);
14041464
parser.read_lines++;
14051465
return 0;
14061466
}
@@ -1787,11 +1847,13 @@ static VAR* var_init(const char* name, int name_len, const char* val,
17871847
if(!val_len)
17881848
val_len = strlen(val) ;
17891849
val_alloc_len = val_len + 16; /* room to grow */
1790-
if(!(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var) + val_alloc_len
1850+
if(!(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
17911851
+ name_len, MYF(MY_WME))))
17921852
die("Out of memory");
17931853
tmp_var->name = (char*)tmp_var + sizeof(*tmp_var);
1794-
tmp_var->str_val = tmp_var->name + name_len;
1854+
if(!(tmp_var->str_val = my_malloc(val_alloc_len, MYF(MY_WME))))
1855+
die("Out of memory");
1856+
17951857
memcpy(tmp_var->name, name, name_len);
17961858
memcpy(tmp_var->str_val, val, val_len + 1);
17971859
tmp_var->name_len = name_len;
@@ -1804,6 +1866,7 @@ static VAR* var_init(const char* name, int name_len, const char* val,
18041866

18051867
static void var_free(void* v)
18061868
{
1869+
my_free(((VAR*)v)->str_val, MYF(MY_WME));
18071870
my_free(v, MYF(MY_WME));
18081871
}
18091872

@@ -1901,6 +1964,7 @@ int main(int argc, char** argv)
19011964
case Q_ECHO: do_echo(q); break;
19021965
case Q_SYSTEM: do_system(q); break;
19031966
case Q_LET: do_let(q); break;
1967+
case Q_EVAL_RESULT: eval_result = 1; break;
19041968
case Q_EVAL:
19051969
if (q->query == q->query_buf)
19061970
q->query += q->first_word_len;

mysql-test/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ SUFFIXES = .sh
5959
-e 's!@''libexecdir''@!$(libexecdir)!g' \
6060
-e 's!@''PERL''@!@PERL@!' \
6161
-e 's!@''VERSION''@!@VERSION@!' \
62+
-e 's!@''MYSQL_BASE_VERSION''@!@MYSQL_BASE_VERSION@!' \
63+
-e 's!@''MYSQL_NO_DASH_VERSION''@!@MYSQL_NO_DASH_VERSION@!' \
6264
-e 's!@''MYSQL_SERVER_SUFFIX''@!@MYSQL_SERVER_SUFFIX@!' \
6365
$< > $@-t
6466
@CHMOD@ +x $@-t

mysql-test/mysql-test-run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ show_failed_diff ()
333333
{
334334
reject_file=r/$1.reject
335335
result_file=r/$1.result
336+
eval_file=r/$1.eval
337+
338+
if [ -f $eval_file ]
339+
then
340+
result_file=$eval_file
341+
fi
342+
336343
if [ -x "$DIFF" ] && [ -f $reject_file ]
337344
then
338345
echo "Below are the diffs between actual and expected results:"

mysql-test/r/rpl_log.result

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Log_name Pos Event_type Server_id Log_seq Info
2-
master-bin.001 4 Start 1 1 Server ver: 4.0.0-debug-log, Binlog ver: 2
2+
master-bin.001 4 Start 1 1 Server ver: $VERSION, Binlog ver: 2
33
master-bin.001 79 Query 1 2 use test; create table t1(n int not null auto_increment primary key)
44
master-bin.001 172 Intvar 1 3 INSERT_ID=1
55
master-bin.001 200 Query 1 4 use test; insert into t1 values (NULL)
66
master-bin.001 263 Query 1 5 use test; drop table t1
77
master-bin.001 311 Query 1 6 use test; create table t1 (word char(20) not null)
8-
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)
8+
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)
99
master-bin.001 468 Query 1 8 use test; drop table t1
1010
Log_name Pos Event_type Server_id Log_seq Info
1111
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
2121
master-bin.001 200 Query 1 4 use test; insert into t1 values (NULL)
2222
master-bin.001 263 Query 1 5 use test; drop table t1
2323
master-bin.001 311 Query 1 6 use test; create table t1 (word char(20) not null)
24-
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)
24+
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)
2525
master-bin.001 468 Query 1 8 use test; drop table t1
2626
master-bin.001 516 Rotate 1 9 master-bin.002;pos=4
2727
master-bin.001 557 Stop 1 10
2828
Log_name Pos Event_type Server_id Log_seq Info
29-
master-bin.002 4 Start 1 1 Server ver: 4.0.0-debug-log, Binlog ver: 2
29+
master-bin.002 4 Start 1 1 Server ver: $VERSION, Binlog ver: 2
3030
master-bin.002 79 Query 1 2 use test; create table t1 (n int)
3131
master-bin.002 137 Query 1 3 use test; insert into t1 values (1)
3232
master-bin.002 197 Query 1 4 use test; drop table t1
@@ -38,7 +38,7 @@ slave-bin.001
3838
slave-bin.002
3939
Log_name Pos Event_type Server_id Log_seq Info
4040
slave-bin.001 4 Start 2 1 Server ver: 4.0.0-debug-log, Binlog ver: 2
41-
slave-bin.001 79 Slave 2 2 host=127.0.0.1,port=9306,log=master-bin.001,pos=4
41+
slave-bin.001 79 Slave 2 2 host=127.0.0.1,port=$MASTER_MYPORT,log=master-bin.001,pos=4
4242
slave-bin.001 132 Query 1 2 use test; create table t1(n int not null auto_increment primary key)
4343
slave-bin.001 225 Intvar 1 3 INSERT_ID=1
4444
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
4949
slave-bin.001 527 Stop 2 4
5050
Log_name Pos Event_type Server_id Log_seq Info
5151
slave-bin.002 4 Start 2 1 Server ver: 4.0.0-debug-log, Binlog ver: 2
52-
slave-bin.002 79 Slave 2 2 host=127.0.0.1,port=9306,log=master-bin.002,pos=4
52+
slave-bin.002 79 Slave 2 2 host=127.0.0.1,port=$MASTER_MYPORT,log=master-bin.002,pos=4
5353
slave-bin.002 132 Query 1 2 use test; create table t1 (n int)
5454
slave-bin.002 190 Query 1 3 use test; insert into t1 values (1)
5555
slave-bin.002 250 Query 1 4 use test; drop table t1
5656
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
57-
127.0.0.1 root 9999 1 master-bin.002 245 Yes 0 0 4
57+
127.0.0.1 root $MASTER_MYPORT 1 master-bin.002 245 Yes 0 0 4

mysql-test/t/rpl_log.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
source include/master-slave.inc;
2+
eval_result; #result depends on some server specific params
23

34
#clean up slave binlogs
45
connection slave;
@@ -28,10 +29,10 @@ show binlog events in 'master-bin.002';
2829
show master logs;
2930
save_master_pos;
3031
connection slave;
32+
let $VERSION=`select version()`;
3133
slave start;
3234
sync_with_master;
3335
show master logs;
3436
show binlog events in 'slave-bin.001' from 4;
3537
show binlog events in 'slave-bin.002' from 4;
36-
--replace_result 9306 9999 3334 9999 3335 9999
3738
show slave status;

0 commit comments

Comments
 (0)