39
39
#define MTEST_VERSION "3.3"
41
#include "client_priv.h"
49
#include "client_priv.h"
50
50
#include <mysys/hash.h>
51
51
#include <stdarg.h>
53
53
#include "errname.h"
55
/* Added this for string translation. */
56
#include <drizzled/gettext.h>
55
58
using namespace std;
57
60
#define MAX_VAR_NAME_LENGTH 256
58
61
#define MAX_COLUMNS 256
59
62
#define MAX_EMBEDDED_SERVER_ARGS 64
60
63
#define MAX_DELIMITER_LENGTH 16
62
64
/* Flags controlling send and reap */
63
65
#define QUERY_SEND_FLAG 1
64
66
#define QUERY_REAP_FLAG 2
67
69
OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
68
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
70
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES,
71
74
static int record= 0, opt_sleep= -1;
72
static char *opt_db= 0, *opt_pass= 0;
73
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
75
static char *opt_db= NULL, *opt_pass= NULL;
76
const char *opt_user= NULL, *opt_host= NULL, *unix_sock= NULL,
74
78
const char *opt_logdir= "";
75
const char *opt_include= 0, *opt_charsets_dir;
76
static int opt_port= 0;
79
const char *opt_include= NULL, *opt_charsets_dir;
80
const char *opt_testdir= NULL;
81
static uint32_t opt_port= 0;
77
82
static int opt_max_connect_retries;
78
static bool opt_compress= 0, silent= 0, verbose= 0;
79
static bool debug_info_flag= 0, debug_check_flag= 0;
80
static bool tty_password= 0;
81
static bool opt_mark_progress= 0;
82
static bool parsing_disabled= 0;
83
static bool opt_compress= false, silent= false, verbose= false;
84
static bool debug_info_flag= false, debug_check_flag= false;
85
static bool tty_password= false;
86
static bool opt_mark_progress= false;
87
static bool parsing_disabled= false;
83
88
static bool display_result_vertically= false,
84
89
display_metadata= false, display_result_sorted= false;
85
static bool disable_query_log= 0, disable_result_log= 0;
86
static bool disable_warnings= 0;
87
static bool disable_info= 1;
88
static bool abort_on_error= 1;
89
static bool server_initialized= 0;
90
static bool is_windows= 0;
90
static bool disable_query_log= false, disable_result_log= false;
91
static bool disable_warnings= false;
92
static bool disable_info= true;
93
static bool abort_on_error= true;
94
static bool server_initialized= false;
95
static bool is_windows= false;
91
96
static char **default_argv;
92
97
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
93
98
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
227
232
Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS,
228
233
Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_SORTED_RESULT,
229
234
Q_START_TIMER, Q_END_TIMER,
230
Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL,
231
236
Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT,
233
238
Q_DISABLE_PARSING, Q_ENABLE_PARSING,
388
393
VAR* var_from_env(const char *, const char *);
389
394
VAR* var_init(VAR* v, const char *name, int name_len, const char *val,
391
void var_free(void* v);
396
extern "C" void var_free(void* v);
392
397
VAR* var_get(const char *var_name, const char** var_name_end,
393
398
bool raw, bool ignore_not_existing);
394
399
void eval_expr(VAR* v, const char *p, const char** p_end);
1285
1289
uint len, len2;
1286
1290
char buff[512], buff2[512];
1291
const char *fname= filename2;
1288
if ((fd2= my_open(filename2, O_RDONLY, MYF(0))) < 0)
1294
if ((fd2= my_open(fname, O_RDONLY, MYF(0))) < 0)
1290
1296
my_close(fd, MYF(0));
1291
die("Failed to open second file: '%s'", filename2);
1297
if (opt_testdir != NULL)
1299
tmpfile= opt_testdir;
1300
if (tmpfile[tmpfile.length()] != '/')
1301
tmpfile.append("/");
1302
tmpfile.append(filename2);
1303
fname= tmpfile.c_str();
1305
if ((fd2= my_open(fname, O_RDONLY, MYF(0))) < 0)
1307
my_close(fd, MYF(0));
1309
die("Failed to open second file: '%s'", fname);
1293
1312
while((len= my_read(fd, (unsigned char*)&buff,
1294
1313
sizeof(buff), MYF(0))) > 0)
1374
1393
char temp_file_path[FN_REFLEN];
1376
1395
if ((fd= create_temp_file(temp_file_path, NULL,
1377
"tmp", O_CREAT | O_SHARE | O_RDWR,
1396
"tmp", O_CREAT | O_RDWR,
1378
1397
MYF(MY_WME))) < 0)
1379
1398
die("Failed to create temporary file for ds");
1381
1400
/* Write ds to temporary file and set file pos to beginning*/
1382
1401
if (my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
1383
1402
MYF(MY_FNABP | MY_WME)) ||
1384
my_seek(fd, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR)
1403
lseek(fd, 0, SEEK_SET) == MY_FILEPOS_ERROR)
1386
1405
my_close(fd, MYF(0));
1387
1406
/* Remove the temporary file */
1558
1577
if (!val_len && val)
1559
1578
val_len = strlen(val) ;
1560
1579
val_alloc_len = val_len + 16; /* room to grow */
1561
if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
1562
+ name_len+1, MYF(MY_WME))))
1580
if (!(tmp_var=v) && !(tmp_var = (VAR*)malloc(sizeof(*tmp_var)
1563
1582
die("Out of memory");
1565
1584
tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0;
1566
1585
tmp_var->alloced = (v == 0);
1568
if (!(tmp_var->str_val = (char *)my_malloc(val_alloc_len+1, MYF(MY_WME))))
1587
if (!(tmp_var->str_val = (char *)malloc(val_alloc_len+1)))
1569
1588
die("Out of memory");
1571
1590
memcpy(tmp_var->name, name, name_len);
1955
1976
dest->int_dirty= src->int_dirty;
1957
1978
/* Alloc/realloc data for str_val in dest */
1958
if (dest->alloced_len < src->alloced_len &&
1959
!(dest->str_val= dest->str_val
1960
? (char *)my_realloc(dest->str_val, src->alloced_len, MYF(MY_WME))
1961
: (char *)my_malloc(src->alloced_len, MYF(MY_WME))))
1962
die("Out of memory");
1979
if (dest->alloced_len < src->alloced_len)
1981
char *tmpptr= (char *)realloc(dest->str_val, src->alloced_len);
1983
die("Out of memory");
1984
dest->str_val= tmpptr;
1964
1987
dest->alloced_len= src->alloced_len;
2011
2034
static int MIN_VAR_ALLOC= 32;
2012
2035
v->alloced_len = (new_val_len < MIN_VAR_ALLOC - 1) ?
2013
2036
MIN_VAR_ALLOC : new_val_len + 1;
2015
v->str_val ? (char *)my_realloc(v->str_val, v->alloced_len+1,
2017
(char *)my_malloc(v->alloced_len+1, MYF(MY_WME))))
2037
char *tmpptr= (char *)realloc(v->str_val, v->alloced_len+1);
2018
2039
die("Out of memory");
2020
2042
v->str_val_len = new_val_len;
2021
2043
memcpy(v->str_val, p, new_val_len);
2041
2063
if (cur_file == file_stack_end)
2042
2064
die("Source directives are nesting too deep");
2044
if (!(cur_file->file = my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0))))
2066
if (!(cur_file->file = my_fopen(buff, O_RDONLY, MYF(0))))
2047
2069
die("Could not open '%s' for reading", buff);
2049
cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
2071
if (!(cur_file->file_name= strdup(buff)))
2072
die("Out of memory");
2050
2073
cur_file->lineno=1;
2892
2923
/* If no delimiter was provided, use EOF */
2893
2924
if (ds_delimiter.length() == 0)
2894
ds_delimiter= "EOF";
2925
ds_delimiter.append("EOF");
2896
2927
read_until_delimiter(&ds_script, &ds_delimiter);
2898
2929
/* Create temporary file name */
2899
2930
if ((fd= create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"),
2900
"tmp", O_CREAT | O_SHARE | O_RDWR,
2931
"tmp", O_CREAT | O_RDWR,
2901
2932
MYF(MY_WME))) < 0)
2902
2933
die("Failed to create temporary file for perl command");
2903
2934
my_close(fd, MYF(0));
3081
3112
die("drizzle_store_result() retuned NULL for '%s'", query);
3082
3113
if (!(row = drizzle_fetch_row(res)))
3083
3114
die("empty result in show master status");
3084
my_stpncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3115
strncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3085
3116
master_pos.pos = strtoul(row[1], (char**) 0, 10);
3086
3117
drizzle_free_result(res);
4440
4472
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4441
4473
{"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4442
4474
(char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4475
{"testdir", OPT_TESTDIR, "Path to use to search for test files",
4476
(char**) &opt_testdir,
4477
(char**) &opt_testdir, 0,GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4443
4478
{"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4444
4479
(char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4445
4480
{"mark-progress", OPT_MARK_PROGRESS,
4450
4485
"Max number of connection attempts when connecting to server",
4451
4486
(char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4452
4487
GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4453
{"password", 'p', "Password to use when connecting to server.",
4488
{"password", 'P', "Password to use when connecting to server.",
4454
4489
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
4455
{"port", 'P', "Port number to use for connection or 0 for default to, in "
4456
"order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
4490
{"port", 'p', "Port number to use for connection or 0 for default to, in "
4491
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
4457
4492
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4459
(char**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4493
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4460
4494
{"quiet", 's', "Suppress all normal output.", (char**) &silent,
4461
4495
(char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4462
4496
{"record", 'r', "Record output of test_file into result file.",
4570
4606
char buff[FN_REFLEN];
4571
4607
if (!test_if_hard_path(argument))
4573
strxmov(buff, opt_basedir, argument, NULL);
4609
sprintf(buff,"%s%s",opt_basedir,argument);
4574
4610
argument= buff;
4576
4612
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4577
4613
assert(cur_file == file_stack && cur_file->file == 0);
4578
4614
if (!(cur_file->file=
4579
my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0))))
4615
my_fopen(buff, O_RDONLY, MYF(0))))
4580
4616
die("Could not open '%s' for reading: errno = %d", buff, errno);
4581
cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
4617
if (!(cur_file->file_name= strdup(buff)))
4618
die("Out of memory");
4582
4619
cur_file->lineno= 1;
4636
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
4637
/* if there is an alpha character this is not a valid port */
4638
if (strlen(endchar) != 0)
4640
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
4643
/* If the port number is > 65535 it is not a valid port
4644
This also helps with potential data loss casting unsigned long to a
4646
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
4648
fprintf(stderr, _("Value supplied for port is not valid.\n"));
4653
opt_port= (uint32_t) temp_drizzle_port;
4602
opt_pass= my_strdup(argument, MYF(MY_FAE));
4603
while (*argument) *argument++= 'x'; /* Destroy argument */
4661
opt_pass = strdup(argument);
4662
if (opt_pass == NULL)
4663
die("Out of memory");
4666
/* Overwriting password with 'x' */
4604
4669
tty_password= 0;
4607
4672
tty_password= 1;
4610
my_stpncpy(TMPDIR, argument, sizeof(TMPDIR));
4675
strncpy(TMPDIR, argument, sizeof(TMPDIR));
4613
4678
if (!embedded_server_arg_count)
4689
4754
if ((fd= my_open(buff, flags,
4690
4755
MYF(MY_WME | MY_FFNF))) < 0)
4691
4756
die("Could not open '%s' for writing: errno = %d", buff, errno);
4692
if (append && my_seek(fd, 0, SEEK_END, MYF(0)) == MY_FILEPOS_ERROR)
4757
if (append && lseek(fd, 0, SEEK_END) == MY_FILEPOS_ERROR)
4693
4758
die("Could not find end of file '%s': errno = %d", buff, errno);
4694
4759
if (my_write(fd, (unsigned char*)str, size, MYF(MY_WME|MY_FNABP)))
4695
4760
die("write failed");
6384
6440
char *replace, char *in_string, int icase)
6386
6442
string string_to_match(in_string);
6387
pcrecpp::RE_Options opt;
6390
opt.set_caseless(true);
6392
if (!pcrecpp::RE(pattern, opt).Replace(replace,&string_to_match)){
6443
const char *error= NULL;
6446
pcre *re= pcre_compile(pattern,
6447
icase ? PCRE_CASELESS : 0,
6448
&error, &erroffset, NULL);
6452
int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
6396
const char * new_str= string_to_match.c_str();
6397
*buf_len_p= strlen(new_str);
6460
char *substring_to_replace= in_string + ovector[0];
6461
int substring_length= ovector[1] - ovector[0];
6462
*buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6398
6463
char * new_buf = (char *)malloc(*buf_len_p+1);
6399
6464
if (new_buf == NULL)
6403
strcpy(new_buf, new_str);
6470
memset(new_buf, 0, *buf_len_p+1);
6471
strncpy(new_buf, in_string, substring_to_replace-in_string);
6472
strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
6473
strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
6474
substring_to_replace + substring_length,
6477
- (substring_to_replace-in_string));
6723
6798
/* Alloc replace structure for the replace-state-machine */
6725
if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+
6726
sizeof(REPLACE_STRING)*(found_sets+1)+
6727
sizeof(char *)*count+result_len,
6728
MYF(MY_WME | MY_ZEROFILL))))
6800
if ((replace=(REPLACE*) malloc(sizeof(REPLACE)*(sets.count)+
6801
sizeof(REPLACE_STRING)*(found_sets+1)+
6802
sizeof(char *)*count+result_len)))
6804
memset(replace, 0, sizeof(REPLACE)*(sets.count)+
6805
sizeof(REPLACE_STRING)*(found_sets+1)+
6806
sizeof(char *)*count+result_len);
6730
6807
rep_str=(REPLACE_STRING*) (replace+sets.count);
6731
6808
to_array= (char **) (rep_str+found_sets+1);
6732
6809
to_pos=(char *) (to_array+count);
6733
6810
for (i=0 ; i < count ; i++)
6735
6812
to_array[i]=to_pos;
6736
to_pos=my_stpcpy(to_pos,to[i])+1;
6813
to_pos=strcpy(to_pos,to[i])+strlen(to[i])+1;
6738
6815
rep_str[0].found=1;
6739
6816
rep_str[0].replace_string=0;
6806
6882
count=sets->count+sets->invisible+SET_MALLOC_HUNC;
6807
if (!(set=(REP_SET*) my_realloc((unsigned char*) sets->set_buffer,
6808
sizeof(REP_SET)*count,
6883
if (!(set=(REP_SET*) realloc((unsigned char*) sets->set_buffer,
6884
sizeof(REP_SET)*count)))
6811
6886
sets->set_buffer=set;
6812
6887
sets->set=set+sets->invisible;
6813
if (!(bit_buffer=(uint*) my_realloc((unsigned char*) sets->bit_buffer,
6814
(sizeof(uint)*sets->size_of_bits)*count,
6888
if (!(bit_buffer=(uint*) realloc((unsigned char*) sets->bit_buffer,
6889
(sizeof(uint)*sets->size_of_bits)*count)))
6817
6891
sets->bit_buffer=bit_buffer;
6818
6892
for (i=0 ; i < count ; i++)
6964
7038
if (! pa->typelib.count)
6966
7040
if (!(pa->typelib.type_names=(const char **)
6967
my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
7041
malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
6968
7042
(sizeof(char *)+sizeof(*pa->flag))*
6969
(sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
7043
(sizeof(char *)+sizeof(*pa->flag))))))
6971
if (!(pa->str= (unsigned char*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
7045
if (!(pa->str= (unsigned char*) malloc(PS_MALLOC-MALLOC_OVERHEAD)))
6974
7047
free((char*) pa->typelib.type_names);
7001
7073
if (pa->typelib.count >= pa->max_count-1)
7004
7076
pa->array_allocs++;
7005
7077
len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD);
7006
if (!(new_array=(const char **) my_realloc((unsigned char*) pa->typelib.type_names,
7008
(sizeof(unsigned char*)+sizeof(*pa->flag))*
7009
(sizeof(unsigned char*)+sizeof(*pa->flag)),
7079
(const char **)realloc((unsigned char*) pa->typelib.type_names,
7081
(sizeof(unsigned char*)+sizeof(*pa->flag))*
7082
(sizeof(unsigned char*)+sizeof(*pa->flag)))))
7012
7084
pa->typelib.type_names=new_array;
7013
7085
old_count=pa->max_count;