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
62
/* Flags controlling send and reap */
90
63
#define QUERY_SEND_FLAG 1
91
64
#define QUERY_REAP_FLAG 2
93
ErrorCodes global_error_names;
96
67
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,
68
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
101
71
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;
72
static char *opt_db= 0, *opt_pass= 0;
73
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
74
const char *opt_logdir= "";
75
const char *opt_include= 0, *opt_charsets_dir;
76
static int opt_port= 0;
77
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;
109
83
static bool display_result_vertically= false,
110
84
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;
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;
91
static char **default_argv;
92
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
118
93
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 */
95
static uint start_lineno= 0; /* Start line of current command */
96
static uint my_end_arg= 0;
135
98
/* Number of lines of the result to include in failure report */
136
static uint32_t opt_tail_lines= 0;
99
static uint opt_tail_lines= 0;
138
101
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
139
static uint32_t delimiter_length= 1;
102
static uint delimiter_length= 1;
141
104
static char TMPDIR[FN_REFLEN];
4419
static struct my_option my_long_options[] =
4421
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
4423
{"basedir", 'b', "Basedir for tests.", (char**) &opt_basedir,
4424
(char**) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4425
{"character-sets-dir", OPT_CHARSETS_DIR,
4426
"Directory where character sets are.", (char**) &opt_charsets_dir,
4427
(char**) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4428
{"compress", 'C', "Use the compressed server/client protocol.",
4429
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
4431
{"database", 'D', "Database to use.", (char**) &opt_db, (char**) &opt_db, 0,
4432
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4433
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
4434
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
4435
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4436
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
4437
(char**) &debug_info_flag, (char**) &debug_info_flag,
4438
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4439
{"host", 'h', "Connect to host.", (char**) &opt_host, (char**) &opt_host, 0,
4440
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4441
{"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4442
(char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4443
{"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4444
(char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4445
{"mark-progress", OPT_MARK_PROGRESS,
4446
"Write linenumber and elapsed time to <testname>.progress ",
4447
(char**) &opt_mark_progress, (char**) &opt_mark_progress, 0,
4448
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4449
{"max-connect-retries", OPT_MAX_CONNECT_RETRIES,
4450
"Max number of connection attempts when connecting to server",
4451
(char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4452
GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4453
{"password", 'p', "Password to use when connecting to server.",
4454
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, drizzle.cnf, $DRIZZLE_TCP_PORT, "
4457
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4459
(char**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4460
{"quiet", 's', "Suppress all normal output.", (char**) &silent,
4461
(char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4462
{"record", 'r', "Record output of test_file into result file.",
4463
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4464
{"result-file", 'R', "Read/Store result from/in this file.",
4465
(char**) &result_file_name, (char**) &result_file_name, 0,
4466
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4467
{"server-arg", 'A', "Send option value to embedded server as a parameter.",
4468
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4469
{"server-file", 'F', "Read embedded server arguments from file.",
4470
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4471
{"silent", 's', "Suppress all normal output. Synonym for --quiet.",
4472
(char**) &silent, (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4473
{"sleep", 'T', "Sleep always this many seconds on sleep commands.",
4474
(char**) &opt_sleep, (char**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
4476
{"tail-lines", OPT_TAIL_LINES,
4477
"Number of lines of the resul to include in a failure report",
4478
(char**) &opt_tail_lines, (char**) &opt_tail_lines, 0,
4479
GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0},
4480
{"test-file", 'x', "Read test from/in this file (default stdin).",
4481
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4482
{"timer-file", 'm', "File where the timing in micro seconds is stored.",
4483
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4484
{"tmpdir", 't', "Temporary directory where sockets are put.",
4485
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4486
{"user", 'u', "User for login.", (char**) &opt_user, (char**) &opt_user, 0,
4487
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4488
{"verbose", 'v', "Write more.", (char**) &verbose, (char**) &verbose, 0,
4489
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4490
{"version", 'V', "Output version information and exit.",
4491
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4492
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
4496
static void print_version(void)
4498
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4499
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
4502
static void usage(void)
4505
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4506
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4507
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4508
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4509
my_print_help(my_long_options);
4510
printf(" --no-defaults Don't read default options from any options file.\n");
4511
my_print_variables(my_long_options);
4515
Read arguments for embedded server and put them into
4516
embedded_server_args[]
4519
static void read_embedded_server_arguments(const char *name)
4521
char argument[1024],buff[FN_REFLEN], *str=0;
4524
if (!test_if_hard_path(name))
4526
strxmov(buff, opt_basedir, name, NULL);
4529
fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
4531
if (!embedded_server_arg_count)
4533
embedded_server_arg_count=1;
4534
embedded_server_args[0]= (char*) ""; /* Progname */
4536
if (!(file=my_fopen(buff, O_RDONLY, MYF(MY_WME))))
4537
die("Failed to open file '%s'", buff);
4539
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4540
(str=fgets(argument,sizeof(argument), file)))
4542
*(strchr(str, '\0')-1)=0; /* Remove end newline */
4543
if (!(embedded_server_args[embedded_server_arg_count]=
4544
(char*) my_strdup(str,MYF(MY_WME))))
4546
my_fclose(file,MYF(0));
4547
die("Out of memory");
4550
embedded_server_arg_count++;
4552
my_fclose(file,MYF(0));
4554
die("Too many arguments in option file: %s",name);
4561
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
4570
char buff[FN_REFLEN];
4571
if (!test_if_hard_path(argument))
4573
strxmov(buff, opt_basedir, argument, NULL);
4576
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4577
assert(cur_file == file_stack && cur_file->file == 0);
4578
if (!(cur_file->file=
4579
my_fopen(buff, O_RDONLY, MYF(0))))
4580
die("Could not open '%s' for reading: errno = %d", buff, errno);
4581
cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
4582
cur_file->lineno= 1;
4587
static char buff[FN_REFLEN];
4588
if (!test_if_hard_path(argument))
4590
strxmov(buff, opt_basedir, argument, NULL);
4593
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4595
unlink(timer_file); /* Ignore error, may not exist */
4602
opt_pass= my_strdup(argument, MYF(MY_FAE));
4603
while (*argument) *argument++= 'x'; /* Destroy argument */
4610
my_stpncpy(TMPDIR, argument, sizeof(TMPDIR));
4613
if (!embedded_server_arg_count)
4615
embedded_server_arg_count=1;
4616
embedded_server_args[0]= (char*) "";
4618
if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
4619
!(embedded_server_args[embedded_server_arg_count++]=
4620
my_strdup(argument, MYF(MY_FAE))))
4622
die("Can't use server argument");
4626
read_embedded_server_arguments(argument);
4639
static int parse_args(int argc, char **argv)
4641
load_defaults("drizzle",load_default_groups,&argc,&argv);
4644
if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
4655
opt_pass= get_tty_password(NULL); /* purify tested */
4656
if (debug_info_flag)
4657
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
4658
if (debug_check_flag)
4659
my_end_arg= MY_CHECK_ERROR;
4586
4665
Write the content of str into file
4872
4947
int flags, char *query, int query_len,
4873
4948
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);
4950
DRIZZLE_RES *res= 0;
4951
DRIZZLE *drizzle= &cn->drizzle;
4952
int err= 0, counter= 0;
4882
4954
if (flags & QUERY_SEND_FLAG)
4885
4957
* Send the query
4888
(void) drizzle_query(con, &res, query, query_len, &ret);
4889
if (ret != DRIZZLE_RETURN_OK)
4959
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);
4961
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4962
drizzle_sqlstate(drizzle), ds);
4908
4966
if (!(flags & QUERY_REAP_FLAG))
4913
* Read the result packet
4915
if (drizzle_result_read(con, &res, &ret) == NULL ||
4916
ret != DRIZZLE_RETURN_OK)
4972
When on first result set, call drizzle_read_query_result to retrieve
4973
answer to the query sent earlier
4975
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);
4977
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4978
drizzle_sqlstate(drizzle), ds);
4932
4984
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)
4986
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);
4988
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4989
drizzle_sqlstate(drizzle), ds);
5336
static void mark_progress(struct st_command*, int line)
5394
static void mark_progress(struct st_command* command __attribute__((unused)),
5338
5398
uint64_t timer= timer_now();
5339
5399
if (!progress_start)
5340
5400
progress_start= timer;
5341
5401
timer-= progress_start;
5344
5403
/* Milliseconds since start */
5345
buf << timer << "\t";
5404
end= int64_t2str(timer, buf, 10);
5405
ds_progress.append(buf, (int)(end-buf));
5406
ds_progress.append("\t", 1);
5347
5408
/* Parser line number */
5348
buf << line << "\t";
5409
end= int10_to_str(line, buf, 10);
5410
ds_progress.append(buf, (int)(end-buf));
5411
ds_progress.append("\t", 1);
5351
buf << cur_file->file_name << ":";
5414
ds_progress.append(cur_file->file_name);
5415
ds_progress.append(":", 1);
5353
5417
/* 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;
5418
end= int10_to_str(cur_file->lineno, buf, 10);
5419
ds_progress.append(buf, (int)(end-buf));
5422
ds_progress.append("\n", 1);
5390
5427
int main(int argc, char **argv)
5394
5429
struct st_command *command;
5395
5430
bool q_send_flag= 0, abort_flag= 0;
5396
uint32_t command_executed= 0, last_command_executed= 0;
5397
string save_file("");
5431
uint command_executed= 0, last_command_executed= 0;
5432
char save_file[FN_REFLEN];
5398
5433
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
5439
/* Init expected errors */
5513
5440
memset(&saved_expected_errors, 0, sizeof(saved_expected_errors));
5545
5476
ds_progress.reserve(2048);
5546
5477
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 */
5479
parse_args(argc, argv);
5668
5481
server_initialized= 1;
5669
5482
if (cur_file == file_stack && cur_file->file == 0)
5671
5484
cur_file->file= stdin;
5672
cur_file->file_name= strdup("<stdin>");
5673
if (cur_file->file_name == NULL)
5674
die("Out of memory");
5485
cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
5675
5486
cur_file->lineno= 1;
5677
5488
cur_con= connections;
5678
if ((cur_con->drizzle= drizzle_create(NULL)) == NULL)
5489
if (!( drizzle_create(&cur_con->drizzle)))
5679
5490
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);
5492
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5493
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5684
if (!(cur_con->name = strdup("default")))
5495
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5685
5496
die("Out of memory");
5686
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5498
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5687
5499
opt_db, opt_port);
5689
5501
/* Use all time until exit if no explicit 'start_timer' */
5690
5502
timer_start= timer_now();
5693
Initialize $drizzleclient_errno with -1, so we can
5505
Initialize $drizzle_errno with -1, so we can
5694
5506
- distinguish it from valid values ( >= 0 ) and
5695
5507
- detect if there was never a command sent to the server
5697
5509
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);
5511
/* Update $drizzle_get_server_version to that of current connection */
5512
var_set_drizzle_get_server_version(&cur_con->drizzle);
5702
if (! opt_include.empty())
5704
open_file(opt_include.c_str());
5516
open_file(opt_include);
5707
5519
while (!read_command(&command) && !abort_flag)
6596
6369
icase - flag, if set to 1 the match is case insensitive
6598
6371
int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
6599
char *replace, char *in_string, int icase, int global)
6372
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;
6374
string string_to_match(in_string);
6375
pcrecpp::RE_Options opt;
6378
opt.set_caseless(true);
6380
if (!pcrecpp::RE(pattern, opt).Replace(replace,&string_to_match)){
6384
const char * new_str= string_to_match.c_str();
6385
*buf_len_p= strlen(new_str);
6386
char * new_buf = (char *)malloc(*buf_len_p+1);
6387
if (new_buf == NULL)
6391
strcpy(new_buf, new_str);
6685
6398
#ifndef WORD_BIT
6686
#define WORD_BIT (8*sizeof(uint32_t))
6399
#define WORD_BIT (8*sizeof(uint))
6689
6402
#define SET_MALLOC_HUNC 64
6690
6403
#define LAST_CHAR_CODE 259
6692
6405
typedef struct st_rep_set {
6693
uint32_t *bits; /* Pointer to used sets */
6406
uint *bits; /* Pointer to used sets */
6694
6407
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6695
uint32_t found_len; /* Best match to date */
6408
uint found_len; /* Best match to date */
6696
6409
int found_offset;
6697
uint32_t table_offset;
6698
uint32_t size_of_bits; /* For convinience */
6411
uint size_of_bits; /* For convinience */
6701
6414
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;
6415
uint count; /* Number of sets */
6416
uint extra; /* Extra sets in buffer */
6417
uint invisible; /* Sets not chown */
6706
6419
REP_SET *set,*set_buffer;
6707
uint32_t *bit_buffer;
6710
6423
typedef struct st_found_set {
6711
uint32_t table_offset;
6712
6425
int found_offset;
6715
6428
typedef struct st_follow {
6717
uint32_t table_offset;
6722
int init_sets(REP_SETS *sets,uint32_t states);
6435
int init_sets(REP_SETS *sets,uint states);
6723
6436
REP_SET *make_new_set(REP_SETS *sets);
6724
6437
void make_sets_invisible(REP_SETS *sets);
6725
6438
void free_last_set(REP_SETS *sets);
6726
6439
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);
6440
void internal_set_bit(REP_SET *set, uint bit);
6441
void internal_clear_bit(REP_SET *set, uint bit);
6729
6442
void or_bits(REP_SET *to,REP_SET *from);
6730
6443
void copy_bits(REP_SET *to,REP_SET *from);
6731
6444
int cmp_bits(REP_SET *set1,REP_SET *set2);
6732
int get_next_bit(REP_SET *set,uint32_t lastpos);
6445
int get_next_bit(REP_SET *set,uint lastpos);
6733
6446
int find_set(REP_SETS *sets,REP_SET *find);
6734
int find_found(FOUND_SET *found_set,uint32_t table_offset,
6447
int find_found(FOUND_SET *found_set,uint table_offset,
6735
6448
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)
6449
uint start_at_word(char * pos);
6450
uint end_of_word(char * pos);
6452
static uint found_sets=0;
6455
static uint replace_len(char * str)
6747
6460
if (str[0] == '\\' && str[1])