40
39
#define MTEST_VERSION "3.3"
42
#include "client_priv.h"
52
#ifdef HAVE_SYS_WAIT_H
57
#include <sys/types.h>
59
#include <boost/program_options.hpp>
47
#include "client_priv.h"
48
#include <mysys/hash.h>
63
49
#include <stdarg.h>
64
#include <boost/unordered_map.hpp>
66
/* Added this for string translation. */
67
#include "drizzled/gettext.h"
68
#include "drizzled/type/time.h"
69
#include "drizzled/charset.h"
70
#include "drizzled/typelib.h"
71
#include <drizzled/configmake.h>
73
#ifndef DRIZZLE_RETURN_SERVER_GONE
74
#define DRIZZLE_RETURN_HANDSHAKE_FAILED DRIZZLE_RETURN_ERROR_CODE
76
namespace po= boost::program_options;
77
53
using namespace std;
78
using namespace drizzled;
81
unsigned char *get_var_key(const unsigned char* var, size_t *len, bool);
83
int get_one_option(int optid, const struct option *, char *argument);
85
55
#define MAX_VAR_NAME_LENGTH 256
86
56
#define MAX_COLUMNS 256
57
#define MAX_EMBEDDED_SERVER_ARGS 64
87
58
#define MAX_DELIMITER_LENGTH 16
88
60
/* Flags controlling send and reap */
89
61
#define QUERY_SEND_FLAG 1
90
62
#define QUERY_REAP_FLAG 2
92
typedef boost::unordered_map<std::string, uint32_t> ErrorCodes;
93
ErrorCodes global_error_names;
96
65
OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
97
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES,
66
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
101
69
static int record= 0, opt_sleep= -1;
102
static char *opt_pass= NULL;
103
const char *unix_sock= NULL;
104
static uint32_t opt_port= 0;
105
static uint32_t opt_max_connect_retries;
106
static bool silent= false, verbose= false;
107
static bool opt_mark_progress= false;
108
static bool parsing_disabled= false;
70
static char *opt_db= 0, *opt_pass= 0;
71
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
72
const char *opt_logdir= "";
73
const char *opt_include= 0, *opt_charsets_dir;
74
static int opt_port= 0;
75
static int opt_max_connect_retries;
76
static bool opt_compress= 0, silent= 0, verbose= 0;
77
static bool debug_info_flag= 0, debug_check_flag= 0;
78
static bool tty_password= 0;
79
static bool opt_mark_progress= 0;
80
static bool parsing_disabled= 0;
109
81
static bool display_result_vertically= false,
110
82
display_metadata= false, display_result_sorted= false;
111
static bool disable_query_log= false, disable_result_log= false;
112
static bool disable_warnings= false;
113
static bool disable_info= true;
114
static bool abort_on_error= true;
115
static bool server_initialized= false;
116
static bool is_windows= false;
117
static bool use_drizzle_protocol= false;
83
static bool disable_query_log= 0, disable_result_log= 0;
84
static bool disable_warnings= 0;
85
static bool disable_info= 1;
86
static bool abort_on_error= 1;
87
static bool server_initialized= 0;
88
static bool is_windows= 0;
89
static char **default_argv;
90
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
118
91
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
120
std::string opt_basedir,
133
static uint32_t start_lineno= 0; /* Start line of current command */
93
static uint start_lineno= 0; /* Start line of current command */
94
static uint my_end_arg= 0;
135
96
/* Number of lines of the result to include in failure report */
136
static uint32_t opt_tail_lines= 0;
97
static uint opt_tail_lines= 0;
138
99
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
139
static uint32_t delimiter_length= 1;
100
static uint delimiter_length= 1;
141
102
static char TMPDIR[FN_REFLEN];
3372
3231
command->last_argument= p;
3373
charset_info= get_charset_by_csname(charset_name, MY_CS_PRIMARY);
3232
charset_info= get_charset_by_csname(charset_name,MY_CS_PRIMARY,MYF(MY_WME));
3374
3233
if (!charset_info)
3375
3234
abort_not_supported_test("Test requires charset '%s'", charset_name);
3378
static void fill_global_error_names()
3237
static uint get_errcode_from_name(char *error_name, char *error_end)
3380
drizzle_result_st res;
3381
drizzle_return_t ret;
3383
drizzle_con_st *con= &cur_con->con;
3385
global_error_names.clear();
3387
const std::string ds_query("select error_name, error_code "
3388
"from data_dictionary.errors");
3389
if (drizzle_query_str(con, &res, ds_query.c_str(), &ret) == NULL ||
3390
ret != DRIZZLE_RETURN_OK)
3392
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3394
die("Error running query '%s': %d %s", ds_query.c_str(),
3395
drizzle_result_error_code(&res), drizzle_result_error(&res));
3396
drizzle_result_free(&res);
3400
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
3401
drizzle_con_error(con));
3404
if (drizzle_result_column_count(&res) == 0 ||
3405
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3407
drizzle_result_free(&res);
3408
die("Query '%s' didn't return a result set", ds_query.c_str());
3411
while ((row= drizzle_row_next(&res)) && row[0])
3239
/* SQL error as string */
3240
st_error *e= global_error_names;
3242
/* Loop through the array of known error names */
3243
for (; e->name; e++)
3414
Concatenate all fields in the first row with tab in between
3415
and assign that string to the $variable
3246
If we get a match, we need to check the length of the name we
3247
matched against in case it was longer than what we are checking
3248
(as in ER_WRONG_VALUE vs. ER_WRONG_VALUE_COUNT).
3417
size_t *lengths= drizzle_row_field_sizes(&res);
3418
const std::string error_name(row[0], lengths[0]);
3419
const std::string error_code(row[1], lengths[1]);
3423
global_error_names.insert(ErrorCodes::value_type(error_name,
3424
boost::lexical_cast<uint32_t>(error_code)));
3426
catch (boost::bad_lexical_cast &ex)
3428
drizzle_result_free(&res);
3429
die("Invalid error_code from Drizzle: %s", ex.what());
3434
drizzle_result_free(&res);
3437
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3439
size_t err_name_len= error_end - error_name;
3440
string error_name_s(error_name, err_name_len);
3442
ErrorCodes::iterator it= global_error_names.find(error_name_s);
3443
if (it != global_error_names.end())
3445
return (*it).second;
3448
die("Unknown SQL error name '%s'", error_name_s.c_str());
3250
if (!strncmp(error_name, e->name, (int) (error_end - error_name)) &&
3251
(uint) strlen(e->name) == (uint) (error_end - error_name))
3257
die("Unknown SQL error name '%s'", error_name);
3452
3261
static void do_get_errcodes(struct st_command *command)
3454
3263
struct st_match_err *to= saved_expected_errors.err;
3455
3264
char *p= command->first_argument;
4421
static struct my_option my_long_options[] =
4423
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
4425
{"basedir", 'b', "Basedir for tests.", (char**) &opt_basedir,
4426
(char**) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4427
{"character-sets-dir", OPT_CHARSETS_DIR,
4428
"Directory where character sets are.", (char**) &opt_charsets_dir,
4429
(char**) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4430
{"compress", 'C', "Use the compressed server/client protocol.",
4431
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
4433
{"database", 'D', "Database to use.", (char**) &opt_db, (char**) &opt_db, 0,
4434
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4435
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
4436
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
4437
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4438
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
4439
(char**) &debug_info_flag, (char**) &debug_info_flag,
4440
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4441
{"host", 'h', "Connect to host.", (char**) &opt_host, (char**) &opt_host, 0,
4442
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4443
{"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4444
(char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4445
{"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4446
(char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4447
{"mark-progress", OPT_MARK_PROGRESS,
4448
"Write linenumber and elapsed time to <testname>.progress ",
4449
(char**) &opt_mark_progress, (char**) &opt_mark_progress, 0,
4450
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4451
{"max-connect-retries", OPT_MAX_CONNECT_RETRIES,
4452
"Max number of connection attempts when connecting to server",
4453
(char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4454
GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4455
{"password", 'p', "Password to use when connecting to server.",
4456
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
4457
{"port", 'P', "Port number to use for connection or 0 for default to, in "
4458
"order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
4459
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4461
(char**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4462
{"quiet", 's', "Suppress all normal output.", (char**) &silent,
4463
(char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4464
{"record", 'r', "Record output of test_file into result file.",
4465
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4466
{"result-file", 'R', "Read/Store result from/in this file.",
4467
(char**) &result_file_name, (char**) &result_file_name, 0,
4468
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4469
{"server-arg", 'A', "Send option value to embedded server as a parameter.",
4470
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4471
{"server-file", 'F', "Read embedded server arguments from file.",
4472
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4473
{"silent", 's', "Suppress all normal output. Synonym for --quiet.",
4474
(char**) &silent, (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4475
{"sleep", 'T', "Sleep always this many seconds on sleep commands.",
4476
(char**) &opt_sleep, (char**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
4478
{"tail-lines", OPT_TAIL_LINES,
4479
"Number of lines of the resul to include in a failure report",
4480
(char**) &opt_tail_lines, (char**) &opt_tail_lines, 0,
4481
GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0},
4482
{"test-file", 'x', "Read test from/in this file (default stdin).",
4483
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4484
{"timer-file", 'm', "File where the timing in micro seconds is stored.",
4485
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4486
{"tmpdir", 't', "Temporary directory where sockets are put.",
4487
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4488
{"user", 'u', "User for login.", (char**) &opt_user, (char**) &opt_user, 0,
4489
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4490
{"verbose", 'v', "Write more.", (char**) &verbose, (char**) &verbose, 0,
4491
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4492
{"version", 'V', "Output version information and exit.",
4493
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4494
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
4498
static void print_version(void)
4500
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4501
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
4504
static void usage(void)
4507
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4508
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4509
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4510
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4511
my_print_help(my_long_options);
4512
printf(" --no-defaults Don't read default options from any options file.\n");
4513
my_print_variables(my_long_options);
4517
Read arguments for embedded server and put them into
4518
embedded_server_args[]
4521
static void read_embedded_server_arguments(const char *name)
4523
char argument[1024],buff[FN_REFLEN], *str=0;
4526
if (!test_if_hard_path(name))
4528
strxmov(buff, opt_basedir, name, NullS);
4531
fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
4533
if (!embedded_server_arg_count)
4535
embedded_server_arg_count=1;
4536
embedded_server_args[0]= (char*) ""; /* Progname */
4538
if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
4539
die("Failed to open file '%s'", buff);
4541
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4542
(str=fgets(argument,sizeof(argument), file)))
4544
*(strchr(str, '\0')-1)=0; /* Remove end newline */
4545
if (!(embedded_server_args[embedded_server_arg_count]=
4546
(char*) my_strdup(str,MYF(MY_WME))))
4548
my_fclose(file,MYF(0));
4549
die("Out of memory");
4552
embedded_server_arg_count++;
4554
my_fclose(file,MYF(0));
4556
die("Too many arguments in option file: %s",name);
4563
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
4572
char buff[FN_REFLEN];
4573
if (!test_if_hard_path(argument))
4575
strxmov(buff, opt_basedir, argument, NullS);
4578
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4579
assert(cur_file == file_stack && cur_file->file == 0);
4580
if (!(cur_file->file=
4581
my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0))))
4582
die("Could not open '%s' for reading: errno = %d", buff, errno);
4583
cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
4584
cur_file->lineno= 1;
4589
static char buff[FN_REFLEN];
4590
if (!test_if_hard_path(argument))
4592
strxmov(buff, opt_basedir, argument, NullS);
4595
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4597
unlink(timer_file); /* Ignore error, may not exist */
4603
my_free(opt_pass, MYF(MY_ALLOW_ZERO_PTR));
4604
opt_pass= my_strdup(argument, MYF(MY_FAE));
4605
while (*argument) *argument++= 'x'; /* Destroy argument */
4612
stpncpy(TMPDIR, argument, sizeof(TMPDIR));
4615
if (!embedded_server_arg_count)
4617
embedded_server_arg_count=1;
4618
embedded_server_args[0]= (char*) "";
4620
if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
4621
!(embedded_server_args[embedded_server_arg_count++]=
4622
my_strdup(argument, MYF(MY_FAE))))
4624
die("Can't use server argument");
4628
read_embedded_server_arguments(argument);
4641
static int parse_args(int argc, char **argv)
4643
load_defaults("my",load_default_groups,&argc,&argv);
4646
if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
4657
opt_pass= get_tty_password(NullS); /* purify tested */
4658
if (debug_info_flag)
4659
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
4660
if (debug_check_flag)
4661
my_end_arg= MY_CHECK_ERROR;
4624
4667
Write the content of str into file
4910
4949
int flags, char *query, int query_len,
4911
4950
string *ds, string *ds_warnings)
4913
drizzle_result_st res;
4914
drizzle_return_t ret;
4915
drizzle_con_st *con= &cn->con;
4918
drizzle_con_add_options(con, DRIZZLE_CON_NO_RESULT_READ);
4952
DRIZZLE_RES *res= 0;
4953
DRIZZLE *drizzle= &cn->drizzle;
4954
int err= 0, counter= 0;
4920
4956
if (flags & QUERY_SEND_FLAG)
4923
4959
* Send the query
4926
(void) drizzle_query(con, &res, query, query_len, &ret);
4927
if (ret != DRIZZLE_RETURN_OK)
4961
if (do_send_query(cn, query, query_len, flags))
4929
if (ret == DRIZZLE_RETURN_ERROR_CODE ||
4930
ret == DRIZZLE_RETURN_HANDSHAKE_FAILED)
4932
err= drizzle_result_error_code(&res);
4933
handle_error(command, err, drizzle_result_error(&res),
4934
drizzle_result_sqlstate(&res), ds);
4935
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4936
drizzle_result_free(&res);
4940
handle_error(command, ret, drizzle_con_error(con), "", ds);
4963
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4964
drizzle_sqlstate(drizzle), ds);
4946
4968
if (!(flags & QUERY_REAP_FLAG))
4951
* Read the result packet
4953
if (drizzle_result_read(con, &res, &ret) == NULL ||
4954
ret != DRIZZLE_RETURN_OK)
4974
When on first result set, call drizzle_read_query_result to retrieve
4975
answer to the query sent earlier
4977
if ((counter==0) && drizzle_read_query_result(drizzle))
4956
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4958
handle_error(command, drizzle_result_error_code(&res),
4959
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
4963
handle_error(command, ret, drizzle_con_error(con), "", ds);
4964
drizzle_result_free(&res);
4979
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4980
drizzle_sqlstate(drizzle), ds);
4970
4986
Store the result of the query if it will return any fields
4972
if (drizzle_result_column_count(&res) &&
4973
(ret= drizzle_result_buffer(&res)) != DRIZZLE_RETURN_OK)
4988
if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
4975
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4977
handle_error(command, drizzle_result_error_code(&res),
4978
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
4982
handle_error(command, ret, drizzle_con_error(con), "", ds);
4983
drizzle_result_free(&res);
4990
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4991
drizzle_sqlstate(drizzle), ds);
5374
static void mark_progress(struct st_command*, int line)
5396
static void mark_progress(struct st_command* command __attribute__((unused)),
5376
5400
uint64_t timer= timer_now();
5377
5401
if (!progress_start)
5378
5402
progress_start= timer;
5379
5403
timer-= progress_start;
5382
5405
/* Milliseconds since start */
5383
buf << timer << "\t";
5406
end= int64_t2str(timer, buf, 10);
5407
ds_progress.append(buf, (int)(end-buf));
5408
ds_progress.append("\t", 1);
5385
5410
/* Parser line number */
5386
buf << line << "\t";
5411
end= int10_to_str(line, buf, 10);
5412
ds_progress.append(buf, (int)(end-buf));
5413
ds_progress.append("\t", 1);
5389
buf << cur_file->file_name << ":";
5416
ds_progress.append(cur_file->file_name);
5417
ds_progress.append(":", 1);
5391
5419
/* Line in file */
5392
buf << cur_file->lineno << endl;
5394
ds_progress.append(buf.str());
5398
static void check_retries(uint32_t in_opt_max_connect_retries)
5400
if (in_opt_max_connect_retries > 10000 || opt_max_connect_retries<1)
5402
cout << N_("Error: Invalid Value for opt_max_connect_retries");
5405
opt_max_connect_retries= in_opt_max_connect_retries;
5408
static void check_tail_lines(uint32_t in_opt_tail_lines)
5410
if (in_opt_tail_lines > 10000)
5412
cout << N_("Error: Invalid Value for opt_tail_lines");
5415
opt_tail_lines= in_opt_tail_lines;
5418
static void check_sleep(int32_t in_opt_sleep)
5420
if (in_opt_sleep < -1)
5422
cout << N_("Error: Invalid Value for opt_sleep");
5425
opt_sleep= in_opt_sleep;
5420
end= int10_to_str(cur_file->lineno, buf, 10);
5421
ds_progress.append(buf, (int)(end-buf));
5424
ds_progress.append("\n", 1);
5428
5429
int main(int argc, char **argv)
5432
5431
struct st_command *command;
5433
5432
bool q_send_flag= 0, abort_flag= 0;
5434
uint32_t command_executed= 0, last_command_executed= 0;
5435
string save_file("");
5433
uint command_executed= 0, last_command_executed= 0;
5434
char save_file[FN_REFLEN];
5436
5435
struct stat res_info;
5440
internal::my_init();
5442
po::options_description commandline_options("Options used only in command line");
5443
commandline_options.add_options()
5444
("help,?", "Display this help and exit.")
5445
("mark-progress", po::value<bool>(&opt_mark_progress)->default_value(false)->zero_tokens(),
5446
"Write linenumber and elapsed time to <testname>.progress ")
5447
("sleep,T", po::value<int32_t>(&opt_sleep)->default_value(-1)->notifier(&check_sleep),
5448
"Sleep always this many seconds on sleep commands.")
5449
("test-file,x", po::value<string>(),
5450
"Read test from/in this file (default stdin).")
5451
("timer-file,f", po::value<string>(),
5452
"File where the timing in micro seconds is stored.")
5453
("tmpdir,t", po::value<string>(),
5454
"Temporary directory where sockets are put.")
5455
("verbose,v", po::value<bool>(&verbose)->default_value(false),
5457
("version,V", "Output version information and exit.")
5458
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
5459
"Configuration file defaults are not used if no-defaults is set")
5462
po::options_description test_options("Options specific to the drizzleimport");
5463
test_options.add_options()
5464
("basedir,b", po::value<string>(&opt_basedir)->default_value(""),
5465
"Basedir for tests.")
5466
("character-sets-dir", po::value<string>(&opt_charsets_dir)->default_value(""),
5467
"Directory where character sets are.")
5468
("database,D", po::value<string>(&opt_db)->default_value(""),
5470
("include,i", po::value<string>(&opt_include)->default_value(""),
5471
"Include SQL before each test case.")
5472
("testdir", po::value<string>(&opt_testdir)->default_value(""),
5473
"Path to use to search for test files")
5474
("logdir", po::value<string>(&opt_logdir)->default_value(""),
5475
"Directory for log files")
5476
("max-connect-retries", po::value<uint32_t>(&opt_max_connect_retries)->default_value(500)->notifier(&check_retries),
5477
"Max number of connection attempts when connecting to server")
5478
("quiet,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
5479
"Suppress all normal output.")
5480
("record,r", "Record output of test_file into result file.")
5481
("result-file,R", po::value<string>(&result_file_name)->default_value(""),
5482
"Read/Store result from/in this file.")
5483
("silent,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
5484
"Suppress all normal output. Synonym for --quiet.")
5485
("tail-lines", po::value<uint32_t>(&opt_tail_lines)->default_value(0)->notifier(&check_tail_lines),
5486
"Number of lines of the resul to include in a failure report")
5489
po::options_description client_options("Options specific to the client");
5490
client_options.add_options()
5492
("host,h", po::value<string>(&opt_host)->default_value("localhost"),
5494
("password,P", po::value<string>(&password)->default_value("PASSWORD_SENTINEL"),
5495
"Password to use when connecting to server.")
5496
("port,p", po::value<uint32_t>(&opt_port)->default_value(0),
5497
"Port number to use for connection or 0 for default")
5498
("protocol", po::value<string>(&opt_protocol),
5499
"The protocol of connection (mysql or drizzle).")
5500
("user,u", po::value<string>(&opt_user)->default_value(""),
5504
po::positional_options_description p;
5505
p.add("database", 1);
5507
po::options_description long_options("Allowed Options");
5508
long_options.add(commandline_options).add(test_options).add(client_options);
5510
std::string system_config_dir_test(SYSCONFDIR);
5511
system_config_dir_test.append("/drizzle/drizzletest.cnf");
5513
std::string system_config_dir_client(SYSCONFDIR);
5514
system_config_dir_client.append("/drizzle/client.cnf");
5516
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
5518
if (user_config_dir.compare(0, 2, "~/") == 0)
5521
homedir= getenv("HOME");
5522
if (homedir != NULL)
5523
user_config_dir.replace(0, 1, homedir);
5526
po::variables_map vm;
5528
// Disable allow_guessing
5529
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
5531
po::store(po::command_line_parser(argc, argv).options(long_options).
5532
style(style).positional(p).extra_parser(parse_password_arg).run(),
5535
if (! vm["no-defaults"].as<bool>())
5537
std::string user_config_dir_test(user_config_dir);
5538
user_config_dir_test.append("/drizzle/drizzletest.cnf");
5540
std::string user_config_dir_client(user_config_dir);
5541
user_config_dir_client.append("/drizzle/client.cnf");
5543
ifstream user_test_ifs(user_config_dir_test.c_str());
5544
po::store(parse_config_file(user_test_ifs, test_options), vm);
5546
ifstream user_client_ifs(user_config_dir_client.c_str());
5547
po::store(parse_config_file(user_client_ifs, client_options), vm);
5549
ifstream system_test_ifs(system_config_dir_test.c_str());
5550
store(parse_config_file(system_test_ifs, test_options), vm);
5552
ifstream system_client_ifs(system_config_dir_client.c_str());
5553
po::store(parse_config_file(system_client_ifs, client_options), vm);
5558
5441
/* Init expected errors */
5559
5442
memset(&saved_expected_errors, 0, sizeof(saved_expected_errors));
5591
5478
ds_progress.reserve(2048);
5592
5479
ds_warning_messages.reserve(2048);
5595
if (vm.count("record"))
5600
if (vm.count("test-file"))
5602
string tmp= vm["test-file"].as<string>();
5603
char buff[FN_REFLEN];
5604
if (!internal::test_if_hard_path(tmp.c_str()))
5606
snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str());
5609
internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME);
5610
assert(cur_file == file_stack && cur_file->file == 0);
5611
if (!(cur_file->file= fopen(buff, "r")))
5613
fprintf(stderr, _("Could not open '%s' for reading: errno = %d"), buff, errno);
5614
return EXIT_ARGUMENT_INVALID;
5616
if (!(cur_file->file_name= strdup(buff)))
5618
fprintf(stderr, _("Out of memory"));
5619
return EXIT_OUT_OF_MEMORY;
5621
cur_file->lineno= 1;
5624
if (vm.count("timer-file"))
5626
string tmp= vm["timer-file"].as<string>().c_str();
5627
static char buff[FN_REFLEN];
5628
if (!internal::test_if_hard_path(tmp.c_str()))
5630
snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str());
5633
internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME);
5635
unlink(timer_file); /* Ignore error, may not exist */
5638
if (vm.count("protocol"))
5640
std::transform(opt_protocol.begin(), opt_protocol.end(),
5641
opt_protocol.begin(), ::tolower);
5643
if (not opt_protocol.compare("mysql"))
5644
use_drizzle_protocol=false;
5645
else if (not opt_protocol.compare("drizzle"))
5646
use_drizzle_protocol=true;
5649
cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
5654
if (vm.count("port"))
5656
/* If the port number is > 65535 it is not a valid port
5657
This also helps with potential data loss casting unsigned long to a
5659
if (opt_port > 65535)
5661
fprintf(stderr, _("Value supplied for port is not valid.\n"));
5662
exit(EXIT_ARGUMENT_INVALID);
5666
if( vm.count("password") )
5668
if (!opt_password.empty())
5669
opt_password.erase();
5670
if (password == PASSWORD_SENTINEL)
5676
opt_password= password;
5677
tty_password= false;
5685
if (vm.count("tmpdir"))
5687
strncpy(TMPDIR, vm["tmpdir"].as<string>().c_str(), sizeof(TMPDIR));
5690
if (vm.count("version"))
5692
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
5693
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
5697
if (vm.count("help"))
5699
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
5700
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
5701
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
5702
printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n");
5703
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
5704
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
5705
printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname);
5711
opt_pass= client_get_tty_password(NULL); /* purify tested */
5481
parse_args(argc, argv);
5714
5483
server_initialized= 1;
5715
5484
if (cur_file == file_stack && cur_file->file == 0)
5717
5486
cur_file->file= stdin;
5718
cur_file->file_name= strdup("<stdin>");
5719
if (cur_file->file_name == NULL)
5720
die("Out of memory");
5487
cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
5721
5488
cur_file->lineno= 1;
5723
5490
cur_con= connections;
5724
if ((cur_con->drizzle= drizzle_create(NULL)) == NULL)
5491
if (!( drizzle_create(&cur_con->drizzle)))
5725
5492
die("Failed in drizzle_create()");
5726
if (!( drizzle_con_create(cur_con->drizzle, &cur_con->con)))
5727
die("Failed in drizzle_con_create()");
5728
drizzle_con_add_options(&cur_con->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
5494
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NullS);
5495
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5730
if (!(cur_con->name = strdup("default")))
5497
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5731
5498
die("Out of memory");
5732
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5500
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5733
5501
opt_db, opt_port);
5735
fill_global_error_names();
5737
5503
/* Use all time until exit if no explicit 'start_timer' */
5738
5504
timer_start= timer_now();
5741
Initialize $drizzleclient_errno with -1, so we can
5507
Initialize $drizzle_errno with -1, so we can
5742
5508
- distinguish it from valid values ( >= 0 ) and
5743
5509
- detect if there was never a command sent to the server
5745
5511
var_set_errno(-1);
5747
/* Update $drizzleclient_get_server_version to that of current connection */
5748
var_set_drizzleclient_get_server_version(&cur_con->con);
5513
/* Update $drizzle_get_server_version to that of current connection */
5514
var_set_drizzle_get_server_version(&cur_con->drizzle);
5750
if (! opt_include.empty())
5752
open_file(opt_include.c_str());
5518
open_file(opt_include);
5755
5521
while (!read_command(&command) && !abort_flag)
6644
6383
icase - flag, if set to 1 the match is case insensitive
6646
6385
int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
6647
char *replace, char *in_string, int icase, int global)
6386
char *replace, char *in_string, int icase)
6649
const char *error= NULL;
6652
pcre *re= pcre_compile(pattern,
6653
icase ? PCRE_CASELESS | PCRE_MULTILINE : PCRE_MULTILINE,
6654
&error, &erroffset, NULL);
6661
int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
6669
char *substring_to_replace= in_string + ovector[0];
6670
int substring_length= ovector[1] - ovector[0];
6671
*buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6672
char * new_buf = (char *)malloc(*buf_len_p+1);
6673
if (new_buf == NULL)
6679
memset(new_buf, 0, *buf_len_p+1);
6680
strncpy(new_buf, in_string, substring_to_replace-in_string);
6681
strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
6682
strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
6683
substring_to_replace + substring_length,
6686
- (substring_to_replace-in_string));
6694
/* Repeatedly replace the string with the matched regex */
6695
string subject(in_string);
6696
size_t replace_length= strlen(replace);
6697
size_t length_of_replacement= strlen(replace);
6698
size_t current_position= 0;
6703
rc= pcre_exec(re, NULL, subject.c_str(), subject.length(),
6704
current_position, 0, ovector, 3);
6710
current_position= static_cast<size_t>(ovector[0]);
6711
replace_length= static_cast<size_t>(ovector[1] - ovector[0]);
6712
subject.replace(current_position, replace_length, replace, length_of_replacement);
6713
current_position= current_position + length_of_replacement;
6716
char *new_buf = (char *) malloc(subject.length() + 1);
6717
if (new_buf == NULL)
6722
memset(new_buf, 0, subject.length() + 1);
6723
strncpy(new_buf, subject.c_str(), subject.length());
6724
*buf_len_p= subject.length() + 1;
6388
string string_to_match(in_string);
6389
pcrecpp::RE_Options opt;
6392
opt.set_caseless(true);
6394
if (!pcrecpp::RE(pattern, opt).Replace(replace,&string_to_match)){
6398
const char * new_str= string_to_match.c_str();
6399
*buf_len_p= strlen(new_str);
6400
char * new_buf = (char *)malloc(*buf_len_p+1);
6401
if (new_buf == NULL)
6405
strcpy(new_buf, new_str);
6733
6412
#ifndef WORD_BIT
6734
#define WORD_BIT (8*sizeof(uint32_t))
6413
#define WORD_BIT (8*sizeof(uint))
6737
6416
#define SET_MALLOC_HUNC 64
6738
6417
#define LAST_CHAR_CODE 259
6740
6419
typedef struct st_rep_set {
6741
uint32_t *bits; /* Pointer to used sets */
6420
uint *bits; /* Pointer to used sets */
6742
6421
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6743
uint32_t found_len; /* Best match to date */
6422
uint found_len; /* Best match to date */
6744
6423
int found_offset;
6745
uint32_t table_offset;
6746
uint32_t size_of_bits; /* For convinience */
6425
uint size_of_bits; /* For convinience */
6749
6428
typedef struct st_rep_sets {
6750
uint32_t count; /* Number of sets */
6751
uint32_t extra; /* Extra sets in buffer */
6752
uint32_t invisible; /* Sets not chown */
6753
uint32_t size_of_bits;
6429
uint count; /* Number of sets */
6430
uint extra; /* Extra sets in buffer */
6431
uint invisible; /* Sets not chown */
6754
6433
REP_SET *set,*set_buffer;
6755
uint32_t *bit_buffer;
6758
6437
typedef struct st_found_set {
6759
uint32_t table_offset;
6760
6439
int found_offset;
6763
6442
typedef struct st_follow {
6765
uint32_t table_offset;
6770
int init_sets(REP_SETS *sets,uint32_t states);
6449
int init_sets(REP_SETS *sets,uint states);
6771
6450
REP_SET *make_new_set(REP_SETS *sets);
6772
6451
void make_sets_invisible(REP_SETS *sets);
6773
6452
void free_last_set(REP_SETS *sets);
6774
6453
void free_sets(REP_SETS *sets);
6775
void internal_set_bit(REP_SET *set, uint32_t bit);
6776
void internal_clear_bit(REP_SET *set, uint32_t bit);
6454
void internal_set_bit(REP_SET *set, uint bit);
6455
void internal_clear_bit(REP_SET *set, uint bit);
6777
6456
void or_bits(REP_SET *to,REP_SET *from);
6778
6457
void copy_bits(REP_SET *to,REP_SET *from);
6779
6458
int cmp_bits(REP_SET *set1,REP_SET *set2);
6780
int get_next_bit(REP_SET *set,uint32_t lastpos);
6459
int get_next_bit(REP_SET *set,uint lastpos);
6781
6460
int find_set(REP_SETS *sets,REP_SET *find);
6782
int find_found(FOUND_SET *found_set,uint32_t table_offset,
6461
int find_found(FOUND_SET *found_set,uint table_offset,
6783
6462
int found_offset);
6784
uint32_t start_at_word(char * pos);
6785
uint32_t end_of_word(char * pos);
6787
static uint32_t found_sets=0;
6790
static uint32_t replace_len(char * str)
6463
uint start_at_word(char * pos);
6464
uint end_of_word(char * pos);
6466
static uint found_sets=0;
6469
static uint replace_len(char * str)
6795
6474
if (str[0] == '\\' && str[1])