40
39
#define MTEST_VERSION "3.3"
42
42
#include "client_priv.h"
52
#ifdef HAVE_SYS_WAIT_H
57
#include <sys/types.h>
59
#include <boost/program_options.hpp>
51
#include <mysys/hash.h>
63
52
#include <stdarg.h>
64
#include <boost/unordered_map.hpp>
66
54
#include "errname.h"
68
/* Added this for string translation. */
69
#include "drizzled/gettext.h"
70
#include "drizzled/drizzle_time.h"
71
#include "drizzled/charset.h"
72
#include <drizzled/configmake.h>
74
#ifndef DRIZZLE_RETURN_SERVER_GONE
75
#define DRIZZLE_RETURN_HANDSHAKE_FAILED DRIZZLE_RETURN_ERROR_CODE
77
namespace po= boost::program_options;
78
56
using namespace std;
79
using namespace drizzled;
82
unsigned char *get_var_key(const unsigned char* var, size_t *len, bool);
84
int get_one_option(int optid, const struct option *, char *argument);
86
58
#define MAX_VAR_NAME_LENGTH 256
87
59
#define MAX_COLUMNS 256
60
#define MAX_EMBEDDED_SERVER_ARGS 64
88
61
#define MAX_DELIMITER_LENGTH 16
89
63
/* Flags controlling send and reap */
90
64
#define QUERY_SEND_FLAG 1
91
65
#define QUERY_REAP_FLAG 2
93
ErrorCodes global_error_names;
96
68
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,
69
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
101
72
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;
73
static char *opt_db= 0, *opt_pass= 0;
74
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
75
const char *opt_logdir= "";
76
const char *opt_include= 0, *opt_charsets_dir;
77
static int opt_port= 0;
78
static int opt_max_connect_retries;
79
static bool opt_compress= 0, silent= 0, verbose= 0;
80
static bool debug_info_flag= 0, debug_check_flag= 0;
81
static bool tty_password= 0;
82
static bool opt_mark_progress= 0;
83
static bool parsing_disabled= 0;
109
84
static bool display_result_vertically= false,
110
85
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;
86
static bool disable_query_log= 0, disable_result_log= 0;
87
static bool disable_warnings= 0;
88
static bool disable_info= 1;
89
static bool abort_on_error= 1;
90
static bool server_initialized= 0;
91
static bool is_windows= 0;
92
static char **default_argv;
93
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
118
94
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 */
96
static uint start_lineno= 0; /* Start line of current command */
97
static uint my_end_arg= 0;
135
99
/* Number of lines of the result to include in failure report */
136
static uint32_t opt_tail_lines= 0;
100
static uint opt_tail_lines= 0;
138
102
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
139
static uint32_t delimiter_length= 1;
103
static uint delimiter_length= 1;
141
105
static char TMPDIR[FN_REFLEN];
4420
static struct my_option my_long_options[] =
4422
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
4424
{"basedir", 'b', "Basedir for tests.", (char**) &opt_basedir,
4425
(char**) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4426
{"character-sets-dir", OPT_CHARSETS_DIR,
4427
"Directory where character sets are.", (char**) &opt_charsets_dir,
4428
(char**) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4429
{"compress", 'C', "Use the compressed server/client protocol.",
4430
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
4432
{"database", 'D', "Database to use.", (char**) &opt_db, (char**) &opt_db, 0,
4433
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4434
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
4435
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
4436
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4437
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
4438
(char**) &debug_info_flag, (char**) &debug_info_flag,
4439
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4440
{"host", 'h', "Connect to host.", (char**) &opt_host, (char**) &opt_host, 0,
4441
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4442
{"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4443
(char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4444
{"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4445
(char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4446
{"mark-progress", OPT_MARK_PROGRESS,
4447
"Write linenumber and elapsed time to <testname>.progress ",
4448
(char**) &opt_mark_progress, (char**) &opt_mark_progress, 0,
4449
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4450
{"max-connect-retries", OPT_MAX_CONNECT_RETRIES,
4451
"Max number of connection attempts when connecting to server",
4452
(char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4453
GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4454
{"password", 'p', "Password to use when connecting to server.",
4455
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
4456
{"port", 'P', "Port number to use for connection or 0 for default to, in "
4457
"order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
4458
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4460
(char**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4461
{"quiet", 's', "Suppress all normal output.", (char**) &silent,
4462
(char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4463
{"record", 'r', "Record output of test_file into result file.",
4464
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4465
{"result-file", 'R', "Read/Store result from/in this file.",
4466
(char**) &result_file_name, (char**) &result_file_name, 0,
4467
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4468
{"server-arg", 'A', "Send option value to embedded server as a parameter.",
4469
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4470
{"server-file", 'F', "Read embedded server arguments from file.",
4471
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4472
{"silent", 's', "Suppress all normal output. Synonym for --quiet.",
4473
(char**) &silent, (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4474
{"sleep", 'T', "Sleep always this many seconds on sleep commands.",
4475
(char**) &opt_sleep, (char**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
4477
{"tail-lines", OPT_TAIL_LINES,
4478
"Number of lines of the resul to include in a failure report",
4479
(char**) &opt_tail_lines, (char**) &opt_tail_lines, 0,
4480
GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0},
4481
{"test-file", 'x', "Read test from/in this file (default stdin).",
4482
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4483
{"timer-file", 'm', "File where the timing in micro seconds is stored.",
4484
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4485
{"tmpdir", 't', "Temporary directory where sockets are put.",
4486
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4487
{"user", 'u', "User for login.", (char**) &opt_user, (char**) &opt_user, 0,
4488
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4489
{"verbose", 'v', "Write more.", (char**) &verbose, (char**) &verbose, 0,
4490
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4491
{"version", 'V', "Output version information and exit.",
4492
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4493
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
4497
static void print_version(void)
4499
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4500
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
4503
static void usage(void)
4506
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4507
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4508
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4509
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4510
my_print_help(my_long_options);
4511
printf(" --no-defaults Don't read default options from any options file.\n");
4512
my_print_variables(my_long_options);
4516
Read arguments for embedded server and put them into
4517
embedded_server_args[]
4520
static void read_embedded_server_arguments(const char *name)
4522
char argument[1024],buff[FN_REFLEN], *str=0;
4525
if (!test_if_hard_path(name))
4527
strxmov(buff, opt_basedir, name, NULL);
4530
fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
4532
if (!embedded_server_arg_count)
4534
embedded_server_arg_count=1;
4535
embedded_server_args[0]= (char*) ""; /* Progname */
4537
if (!(file=my_fopen(buff, O_RDONLY, MYF(MY_WME))))
4538
die("Failed to open file '%s'", buff);
4540
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4541
(str=fgets(argument,sizeof(argument), file)))
4543
*(strchr(str, '\0')-1)=0; /* Remove end newline */
4544
if (!(embedded_server_args[embedded_server_arg_count]=
4545
(char*) my_strdup(str,MYF(MY_WME))))
4547
my_fclose(file,MYF(0));
4548
die("Out of memory");
4551
embedded_server_arg_count++;
4553
my_fclose(file,MYF(0));
4555
die("Too many arguments in option file: %s",name);
4562
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
4571
char buff[FN_REFLEN];
4572
if (!test_if_hard_path(argument))
4574
strxmov(buff, opt_basedir, argument, NULL);
4577
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4578
assert(cur_file == file_stack && cur_file->file == 0);
4579
if (!(cur_file->file=
4580
my_fopen(buff, O_RDONLY, MYF(0))))
4581
die("Could not open '%s' for reading: errno = %d", buff, errno);
4582
cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
4583
cur_file->lineno= 1;
4588
static char buff[FN_REFLEN];
4589
if (!test_if_hard_path(argument))
4591
strxmov(buff, opt_basedir, argument, NULL);
4594
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4596
unlink(timer_file); /* Ignore error, may not exist */
4603
opt_pass= my_strdup(argument, MYF(MY_FAE));
4604
while (*argument) *argument++= 'x'; /* Destroy argument */
4611
my_stpncpy(TMPDIR, argument, sizeof(TMPDIR));
4614
if (!embedded_server_arg_count)
4616
embedded_server_arg_count=1;
4617
embedded_server_args[0]= (char*) "";
4619
if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
4620
!(embedded_server_args[embedded_server_arg_count++]=
4621
my_strdup(argument, MYF(MY_FAE))))
4623
die("Can't use server argument");
4627
read_embedded_server_arguments(argument);
4640
static int parse_args(int argc, char **argv)
4642
load_defaults("my",load_default_groups,&argc,&argv);
4645
if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
4656
opt_pass= get_tty_password(NULL); /* purify tested */
4657
if (debug_info_flag)
4658
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
4659
if (debug_check_flag)
4660
my_end_arg= MY_CHECK_ERROR;
4586
4666
Write the content of str into file
4872
4948
int flags, char *query, int query_len,
4873
4949
string *ds, string *ds_warnings)
4875
drizzle_result_st res;
4876
drizzle_return_t ret;
4877
drizzle_con_st *con= &cn->con;
4880
drizzle_con_add_options(con, DRIZZLE_CON_NO_RESULT_READ);
4951
DRIZZLE_RES *res= 0;
4952
DRIZZLE *drizzle= &cn->drizzle;
4953
int err= 0, counter= 0;
4882
4955
if (flags & QUERY_SEND_FLAG)
4885
4958
* Send the query
4888
(void) drizzle_query(con, &res, query, query_len, &ret);
4889
if (ret != DRIZZLE_RETURN_OK)
4960
if (do_send_query(cn, query, query_len, flags))
4891
if (ret == DRIZZLE_RETURN_ERROR_CODE ||
4892
ret == DRIZZLE_RETURN_HANDSHAKE_FAILED)
4894
err= drizzle_result_error_code(&res);
4895
handle_error(command, err, drizzle_result_error(&res),
4896
drizzle_result_sqlstate(&res), ds);
4897
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4898
drizzle_result_free(&res);
4902
handle_error(command, ret, drizzle_con_error(con), "", ds);
4962
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4963
drizzle_sqlstate(drizzle), ds);
4908
4967
if (!(flags & QUERY_REAP_FLAG))
4913
* Read the result packet
4915
if (drizzle_result_read(con, &res, &ret) == NULL ||
4916
ret != DRIZZLE_RETURN_OK)
4973
When on first result set, call drizzle_read_query_result to retrieve
4974
answer to the query sent earlier
4976
if ((counter==0) && drizzle_read_query_result(drizzle))
4918
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4920
handle_error(command, drizzle_result_error_code(&res),
4921
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
4925
handle_error(command, ret, drizzle_con_error(con), "", ds);
4926
drizzle_result_free(&res);
4978
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4979
drizzle_sqlstate(drizzle), ds);
4932
4985
Store the result of the query if it will return any fields
4934
if (drizzle_result_column_count(&res) &&
4935
(ret= drizzle_result_buffer(&res)) != DRIZZLE_RETURN_OK)
4987
if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
4937
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4939
handle_error(command, drizzle_result_error_code(&res),
4940
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
4944
handle_error(command, ret, drizzle_con_error(con), "", ds);
4945
drizzle_result_free(&res);
4989
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4990
drizzle_sqlstate(drizzle), ds);
5336
static void mark_progress(struct st_command*, int line)
5395
static void mark_progress(struct st_command* command __attribute__((unused)),
5338
5399
uint64_t timer= timer_now();
5339
5400
if (!progress_start)
5340
5401
progress_start= timer;
5341
5402
timer-= progress_start;
5344
5404
/* Milliseconds since start */
5345
buf << timer << "\t";
5405
end= int64_t2str(timer, buf, 10);
5406
ds_progress.append(buf, (int)(end-buf));
5407
ds_progress.append("\t", 1);
5347
5409
/* Parser line number */
5348
buf << line << "\t";
5410
end= int10_to_str(line, buf, 10);
5411
ds_progress.append(buf, (int)(end-buf));
5412
ds_progress.append("\t", 1);
5351
buf << cur_file->file_name << ":";
5415
ds_progress.append(cur_file->file_name);
5416
ds_progress.append(":", 1);
5353
5418
/* Line in file */
5354
buf << cur_file->lineno << endl;
5356
ds_progress.append(buf.str());
5360
static void check_retries(uint32_t in_opt_max_connect_retries)
5362
if (in_opt_max_connect_retries > 10000 || opt_max_connect_retries<1)
5364
cout << N_("Error: Invalid Value for opt_max_connect_retries");
5367
opt_max_connect_retries= in_opt_max_connect_retries;
5370
static void check_tail_lines(uint32_t in_opt_tail_lines)
5372
if (in_opt_tail_lines > 10000)
5374
cout << N_("Error: Invalid Value for opt_tail_lines");
5377
opt_tail_lines= in_opt_tail_lines;
5380
static void check_sleep(int32_t in_opt_sleep)
5382
if (in_opt_sleep < -1)
5384
cout << N_("Error: Invalid Value for opt_sleep");
5387
opt_sleep= in_opt_sleep;
5419
end= int10_to_str(cur_file->lineno, buf, 10);
5420
ds_progress.append(buf, (int)(end-buf));
5423
ds_progress.append("\n", 1);
5390
5428
int main(int argc, char **argv)
5394
5430
struct st_command *command;
5395
5431
bool q_send_flag= 0, abort_flag= 0;
5396
uint32_t command_executed= 0, last_command_executed= 0;
5397
string save_file("");
5432
uint command_executed= 0, last_command_executed= 0;
5433
char save_file[FN_REFLEN];
5398
5434
struct stat res_info;
5402
internal::my_init();
5404
po::options_description commandline_options("Options used only in command line");
5405
commandline_options.add_options()
5406
("help,?", "Display this help and exit.")
5407
("mark-progress", po::value<bool>(&opt_mark_progress)->default_value(false)->zero_tokens(),
5408
"Write linenumber and elapsed time to <testname>.progress ")
5409
("sleep,T", po::value<int32_t>(&opt_sleep)->default_value(-1)->notifier(&check_sleep),
5410
"Sleep always this many seconds on sleep commands.")
5411
("test-file,x", po::value<string>(),
5412
"Read test from/in this file (default stdin).")
5413
("timer-file,f", po::value<string>(),
5414
"File where the timing in micro seconds is stored.")
5415
("tmpdir,t", po::value<string>(),
5416
"Temporary directory where sockets are put.")
5417
("verbose,v", po::value<bool>(&verbose)->default_value(false),
5419
("version,V", "Output version information and exit.")
5420
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
5421
"Configuration file defaults are not used if no-defaults is set")
5424
po::options_description test_options("Options specific to the drizzleimport");
5425
test_options.add_options()
5426
("basedir,b", po::value<string>(&opt_basedir)->default_value(""),
5427
"Basedir for tests.")
5428
("character-sets-dir", po::value<string>(&opt_charsets_dir)->default_value(""),
5429
"Directory where character sets are.")
5430
("database,D", po::value<string>(&opt_db)->default_value(""),
5432
("include,i", po::value<string>(&opt_include)->default_value(""),
5433
"Include SQL before each test case.")
5434
("testdir", po::value<string>(&opt_testdir)->default_value(""),
5435
"Path to use to search for test files")
5436
("logdir", po::value<string>(&opt_logdir)->default_value(""),
5437
"Directory for log files")
5438
("max-connect-retries", po::value<uint32_t>(&opt_max_connect_retries)->default_value(500)->notifier(&check_retries),
5439
"Max number of connection attempts when connecting to server")
5440
("quiet,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
5441
"Suppress all normal output.")
5442
("record,r", "Record output of test_file into result file.")
5443
("result-file,R", po::value<string>(&result_file_name)->default_value(""),
5444
"Read/Store result from/in this file.")
5445
("silent,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
5446
"Suppress all normal output. Synonym for --quiet.")
5447
("tail-lines", po::value<uint32_t>(&opt_tail_lines)->default_value(0)->notifier(&check_tail_lines),
5448
"Number of lines of the resul to include in a failure report")
5451
po::options_description client_options("Options specific to the client");
5452
client_options.add_options()
5454
("host,h", po::value<string>(&opt_host)->default_value("localhost"),
5456
("password,P", po::value<string>(&password)->default_value("PASSWORD_SENTINEL"),
5457
"Password to use when connecting to server.")
5458
("port,p", po::value<uint32_t>(&opt_port)->default_value(0),
5459
"Port number to use for connection or 0 for default")
5460
("protocol", po::value<string>(&opt_protocol),
5461
"The protocol of connection (mysql or drizzle).")
5462
("user,u", po::value<string>(&opt_user)->default_value(""),
5466
po::positional_options_description p;
5467
p.add("database", 1);
5469
po::options_description long_options("Allowed Options");
5470
long_options.add(commandline_options).add(test_options).add(client_options);
5472
std::string system_config_dir_test(SYSCONFDIR);
5473
system_config_dir_test.append("/drizzle/drizzletest.cnf");
5475
std::string system_config_dir_client(SYSCONFDIR);
5476
system_config_dir_client.append("/drizzle/client.cnf");
5478
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
5480
po::variables_map vm;
5482
// Disable allow_guessing
5483
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
5485
po::store(po::command_line_parser(argc, argv).options(long_options).
5486
style(style).positional(p).extra_parser(parse_password_arg).run(),
5489
if (! vm["no-defaults"].as<bool>())
5491
std::string user_config_dir_test(user_config_dir);
5492
user_config_dir_test.append("/drizzle/drizzletest.cnf");
5494
std::string user_config_dir_client(user_config_dir);
5495
user_config_dir_client.append("/drizzle/client.cnf");
5497
ifstream user_test_ifs(user_config_dir_test.c_str());
5498
po::store(parse_config_file(user_test_ifs, test_options), vm);
5500
ifstream user_client_ifs(user_config_dir_client.c_str());
5501
po::store(parse_config_file(user_client_ifs, client_options), vm);
5503
ifstream system_test_ifs(system_config_dir_test.c_str());
5504
store(parse_config_file(system_test_ifs, test_options), vm);
5506
ifstream system_client_ifs(system_config_dir_client.c_str());
5507
po::store(parse_config_file(system_client_ifs, client_options), vm);
5512
5440
/* Init expected errors */
5513
5441
memset(&saved_expected_errors, 0, sizeof(saved_expected_errors));
5545
5477
ds_progress.reserve(2048);
5546
5478
ds_warning_messages.reserve(2048);
5549
if (vm.count("record"))
5554
if (vm.count("test-file"))
5556
string tmp= vm["test-file"].as<string>();
5557
char buff[FN_REFLEN];
5558
if (!internal::test_if_hard_path(tmp.c_str()))
5560
snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str());
5563
internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME);
5564
assert(cur_file == file_stack && cur_file->file == 0);
5565
if (!(cur_file->file= fopen(buff, "r")))
5567
fprintf(stderr, _("Could not open '%s' for reading: errno = %d"), buff, errno);
5568
return EXIT_ARGUMENT_INVALID;
5570
if (!(cur_file->file_name= strdup(buff)))
5572
fprintf(stderr, _("Out of memory"));
5573
return EXIT_OUT_OF_MEMORY;
5575
cur_file->lineno= 1;
5578
if (vm.count("timer-file"))
5580
string tmp= vm["timer-file"].as<string>().c_str();
5581
static char buff[FN_REFLEN];
5582
if (!internal::test_if_hard_path(tmp.c_str()))
5584
snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str());
5587
internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME);
5589
unlink(timer_file); /* Ignore error, may not exist */
5592
if (vm.count("protocol"))
5594
std::transform(opt_protocol.begin(), opt_protocol.end(),
5595
opt_protocol.begin(), ::tolower);
5597
if (not opt_protocol.compare("mysql"))
5598
use_drizzle_protocol=false;
5599
else if (not opt_protocol.compare("drizzle"))
5600
use_drizzle_protocol=true;
5603
cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
5608
if (vm.count("port"))
5610
/* If the port number is > 65535 it is not a valid port
5611
This also helps with potential data loss casting unsigned long to a
5613
if (opt_port > 65535)
5615
fprintf(stderr, _("Value supplied for port is not valid.\n"));
5616
exit(EXIT_ARGUMENT_INVALID);
5620
if( vm.count("password") )
5622
if (!opt_password.empty())
5623
opt_password.erase();
5624
if (password == PASSWORD_SENTINEL)
5630
opt_password= password;
5631
tty_password= false;
5639
if (vm.count("tmpdir"))
5641
strncpy(TMPDIR, vm["tmpdir"].as<string>().c_str(), sizeof(TMPDIR));
5644
if (vm.count("version"))
5646
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
5647
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
5651
if (vm.count("help"))
5653
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
5654
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
5655
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
5656
printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n");
5657
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
5658
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
5659
printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname);
5665
opt_pass= client_get_tty_password(NULL); /* purify tested */
5480
parse_args(argc, argv);
5668
5482
server_initialized= 1;
5669
5483
if (cur_file == file_stack && cur_file->file == 0)
5671
5485
cur_file->file= stdin;
5672
cur_file->file_name= strdup("<stdin>");
5673
if (cur_file->file_name == NULL)
5674
die("Out of memory");
5486
cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
5675
5487
cur_file->lineno= 1;
5677
5489
cur_con= connections;
5678
if ((cur_con->drizzle= drizzle_create(NULL)) == NULL)
5490
if (!( drizzle_create(&cur_con->drizzle)))
5679
5491
die("Failed in drizzle_create()");
5680
if (!( drizzle_con_create(cur_con->drizzle, &cur_con->con)))
5681
die("Failed in drizzle_con_create()");
5682
drizzle_con_add_options(&cur_con->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
5493
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5494
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5684
if (!(cur_con->name = strdup("default")))
5496
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5685
5497
die("Out of memory");
5686
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5499
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5687
5500
opt_db, opt_port);
5689
5502
/* Use all time until exit if no explicit 'start_timer' */
5690
5503
timer_start= timer_now();
5693
Initialize $drizzleclient_errno with -1, so we can
5506
Initialize $drizzle_errno with -1, so we can
5694
5507
- distinguish it from valid values ( >= 0 ) and
5695
5508
- detect if there was never a command sent to the server
5697
5510
var_set_errno(-1);
5699
/* Update $drizzleclient_get_server_version to that of current connection */
5700
var_set_drizzleclient_get_server_version(&cur_con->con);
5512
/* Update $drizzle_get_server_version to that of current connection */
5513
var_set_drizzle_get_server_version(&cur_con->drizzle);
5702
if (! opt_include.empty())
5704
open_file(opt_include.c_str());
5517
open_file(opt_include);
5707
5520
while (!read_command(&command) && !abort_flag)
6596
6382
icase - flag, if set to 1 the match is case insensitive
6598
6384
int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
6599
char *replace, char *in_string, int icase, int global)
6385
char *replace, char *in_string, int icase)
6601
const char *error= NULL;
6604
pcre *re= pcre_compile(pattern,
6605
icase ? PCRE_CASELESS | PCRE_MULTILINE : PCRE_MULTILINE,
6606
&error, &erroffset, NULL);
6613
int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
6621
char *substring_to_replace= in_string + ovector[0];
6622
int substring_length= ovector[1] - ovector[0];
6623
*buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6624
char * new_buf = (char *)malloc(*buf_len_p+1);
6625
if (new_buf == NULL)
6631
memset(new_buf, 0, *buf_len_p+1);
6632
strncpy(new_buf, in_string, substring_to_replace-in_string);
6633
strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
6634
strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
6635
substring_to_replace + substring_length,
6638
- (substring_to_replace-in_string));
6646
/* Repeatedly replace the string with the matched regex */
6647
string subject(in_string);
6648
size_t replace_length= strlen(replace);
6649
size_t length_of_replacement= strlen(replace);
6650
size_t current_position= 0;
6655
rc= pcre_exec(re, NULL, subject.c_str(), subject.length(),
6656
current_position, 0, ovector, 3);
6662
current_position= static_cast<size_t>(ovector[0]);
6663
replace_length= static_cast<size_t>(ovector[1] - ovector[0]);
6664
subject.replace(current_position, replace_length, replace, length_of_replacement);
6665
current_position= current_position + length_of_replacement;
6668
char *new_buf = (char *) malloc(subject.length() + 1);
6669
if (new_buf == NULL)
6674
memset(new_buf, 0, subject.length() + 1);
6675
strncpy(new_buf, subject.c_str(), subject.length());
6676
*buf_len_p= subject.length() + 1;
6387
string string_to_match(in_string);
6388
pcrecpp::RE_Options opt;
6391
opt.set_caseless(true);
6393
if (!pcrecpp::RE(pattern, opt).Replace(replace,&string_to_match)){
6397
const char * new_str= string_to_match.c_str();
6398
*buf_len_p= strlen(new_str);
6399
char * new_buf = (char *)malloc(*buf_len_p+1);
6400
if (new_buf == NULL)
6404
strcpy(new_buf, new_str);
6685
6411
#ifndef WORD_BIT
6686
#define WORD_BIT (8*sizeof(uint32_t))
6412
#define WORD_BIT (8*sizeof(uint))
6689
6415
#define SET_MALLOC_HUNC 64
6690
6416
#define LAST_CHAR_CODE 259
6692
6418
typedef struct st_rep_set {
6693
uint32_t *bits; /* Pointer to used sets */
6419
uint *bits; /* Pointer to used sets */
6694
6420
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6695
uint32_t found_len; /* Best match to date */
6421
uint found_len; /* Best match to date */
6696
6422
int found_offset;
6697
uint32_t table_offset;
6698
uint32_t size_of_bits; /* For convinience */
6424
uint size_of_bits; /* For convinience */
6701
6427
typedef struct st_rep_sets {
6702
uint32_t count; /* Number of sets */
6703
uint32_t extra; /* Extra sets in buffer */
6704
uint32_t invisible; /* Sets not chown */
6705
uint32_t size_of_bits;
6428
uint count; /* Number of sets */
6429
uint extra; /* Extra sets in buffer */
6430
uint invisible; /* Sets not chown */
6706
6432
REP_SET *set,*set_buffer;
6707
uint32_t *bit_buffer;
6710
6436
typedef struct st_found_set {
6711
uint32_t table_offset;
6712
6438
int found_offset;
6715
6441
typedef struct st_follow {
6717
uint32_t table_offset;
6722
int init_sets(REP_SETS *sets,uint32_t states);
6448
int init_sets(REP_SETS *sets,uint states);
6723
6449
REP_SET *make_new_set(REP_SETS *sets);
6724
6450
void make_sets_invisible(REP_SETS *sets);
6725
6451
void free_last_set(REP_SETS *sets);
6726
6452
void free_sets(REP_SETS *sets);
6727
void internal_set_bit(REP_SET *set, uint32_t bit);
6728
void internal_clear_bit(REP_SET *set, uint32_t bit);
6453
void internal_set_bit(REP_SET *set, uint bit);
6454
void internal_clear_bit(REP_SET *set, uint bit);
6729
6455
void or_bits(REP_SET *to,REP_SET *from);
6730
6456
void copy_bits(REP_SET *to,REP_SET *from);
6731
6457
int cmp_bits(REP_SET *set1,REP_SET *set2);
6732
int get_next_bit(REP_SET *set,uint32_t lastpos);
6458
int get_next_bit(REP_SET *set,uint lastpos);
6733
6459
int find_set(REP_SETS *sets,REP_SET *find);
6734
int find_found(FOUND_SET *found_set,uint32_t table_offset,
6460
int find_found(FOUND_SET *found_set,uint table_offset,
6735
6461
int found_offset);
6736
uint32_t start_at_word(char * pos);
6737
uint32_t end_of_word(char * pos);
6739
static uint32_t found_sets=0;
6742
static uint32_t replace_len(char * str)
6462
uint start_at_word(char * pos);
6463
uint end_of_word(char * pos);
6465
static uint found_sets=0;
6468
static uint replace_len(char * str)
6747
6473
if (str[0] == '\\' && str[1])