4544
static struct my_option my_long_options[] =
4546
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
4548
{"basedir", 'b', "Basedir for tests.", (char**) &opt_basedir,
4549
(char**) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4550
{"character-sets-dir", OPT_CHARSETS_DIR,
4551
"Directory where character sets are.", (char**) &opt_charsets_dir,
4552
(char**) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4553
{"compress", 'C', "Use the compressed server/client protocol.",
4554
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
4556
{"database", 'D', "Database to use.", (char**) &opt_db, (char**) &opt_db, 0,
4557
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4558
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
4559
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
4560
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4561
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
4562
(char**) &debug_info_flag, (char**) &debug_info_flag,
4563
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4564
{"host", 'h', "Connect to host.", (char**) &opt_host, (char**) &opt_host, 0,
4565
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4566
{"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4567
(char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4568
{"testdir", OPT_TESTDIR, "Path to use to search for test files",
4569
(char**) &opt_testdir,
4570
(char**) &opt_testdir, 0,GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4571
{"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4572
(char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4573
{"mark-progress", OPT_MARK_PROGRESS,
4574
"Write linenumber and elapsed time to <testname>.progress ",
4575
(char**) &opt_mark_progress, (char**) &opt_mark_progress, 0,
4576
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4577
{"max-connect-retries", OPT_MAX_CONNECT_RETRIES,
4578
"Max number of connection attempts when connecting to server",
4579
(char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4580
GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4581
{"password", 'P', "Password to use when connecting to server.",
4582
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
4583
{"port", 'p', "Port number to use for connection or 0 for default to, in "
4584
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
4585
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4586
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4587
{"quiet", 's', "Suppress all normal output.", (char**) &silent,
4588
(char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4589
{"record", 'r', "Record output of test_file into result file.",
4590
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4591
{"result-file", 'R', "Read/Store result from/in this file.",
4592
(char**) &result_file_name, (char**) &result_file_name, 0,
4593
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4594
{"server-arg", 'A', "Send option value to embedded server as a parameter.",
4595
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4596
{"server-file", 'F', "Read embedded server arguments from file.",
4597
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4598
{"silent", 's', "Suppress all normal output. Synonym for --quiet.",
4599
(char**) &silent, (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4600
{"sleep", 'T', "Sleep always this many seconds on sleep commands.",
4601
(char**) &opt_sleep, (char**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
4603
{"tail-lines", OPT_TAIL_LINES,
4604
"Number of lines of the resul to include in a failure report",
4605
(char**) &opt_tail_lines, (char**) &opt_tail_lines, 0,
4606
GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0},
4607
{"test-file", 'x', "Read test from/in this file (default stdin).",
4608
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4609
{"timer-file", 'm', "File where the timing in micro seconds is stored.",
4610
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4611
{"tmpdir", 't', "Temporary directory where sockets are put.",
4612
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4613
{"user", 'u', "User for login.", (char**) &opt_user, (char**) &opt_user, 0,
4614
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4615
{"verbose", 'v', "Write more.", (char**) &verbose, (char**) &verbose, 0,
4616
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4617
{"version", 'V', "Output version information and exit.",
4618
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4619
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
4623
static void print_version(void)
4625
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4626
drizzle_version(),SYSTEM_TYPE,MACHINE_TYPE);
4629
static void usage(void)
4632
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4633
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4634
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4635
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4636
my_print_help(my_long_options);
4637
printf(" --no-defaults Don't read default options from any options file.\n");
4638
my_print_variables(my_long_options);
4642
Read arguments for embedded server and put them into
4643
embedded_server_args[]
4646
static void read_embedded_server_arguments(const char *name)
4648
char argument[1024],buff[FN_REFLEN], *str=0;
4651
if (!test_if_hard_path(name))
4653
sprintf(buff,"%s%s",opt_basedir,name);
4656
fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
4658
if (!embedded_server_arg_count)
4660
embedded_server_arg_count=1;
4661
embedded_server_args[0]= (char*) ""; /* Progname */
4663
if (!(file= fopen(buff, "r")))
4664
die("Failed to open file '%s'", buff);
4666
while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4667
(str=fgets(argument,sizeof(argument), file)))
4669
*(strchr(str, '\0')-1)=0; /* Remove end newline */
4670
if (!(embedded_server_args[embedded_server_arg_count]=
4671
(char*) strdup(str)))
4674
die("Out of memory");
4677
embedded_server_arg_count++;
4681
die("Too many arguments in option file: %s",name);
4688
get_one_option(int optid, const struct my_option *, char *argument)
4690
char *endchar= NULL;
4691
uint64_t temp_drizzle_port= 0;
4699
char buff[FN_REFLEN];
4700
if (!test_if_hard_path(argument))
4702
sprintf(buff,"%s%s",opt_basedir,argument);
4705
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4706
assert(cur_file == file_stack && cur_file->file == 0);
4707
if (!(cur_file->file= fopen(buff, "r")))
4708
die("Could not open '%s' for reading: errno = %d", buff, errno);
4709
if (!(cur_file->file_name= strdup(buff)))
4710
die("Out of memory");
4711
cur_file->lineno= 1;
4716
static char buff[FN_REFLEN];
4717
if (!test_if_hard_path(argument))
4719
sprintf(buff,"%s%s",opt_basedir,argument);
4722
fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4724
unlink(timer_file); /* Ignore error, may not exist */
4728
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
4729
/* if there is an alpha character this is not a valid port */
4730
if (strlen(endchar) != 0)
4732
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
4735
/* If the port number is > 65535 it is not a valid port
4736
This also helps with potential data loss casting unsigned long to a
4738
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
4740
fprintf(stderr, _("Value supplied for port is not valid.\n"));
4745
opt_port= (uint32_t) temp_drizzle_port;
4753
opt_pass = strdup(argument);
4754
if (opt_pass == NULL)
4755
die("Out of memory");
4758
/* Overwriting password with 'x' */
4767
strncpy(TMPDIR, argument, sizeof(TMPDIR));
4770
if (!embedded_server_arg_count)
4772
embedded_server_arg_count=1;
4773
embedded_server_args[0]= (char*) "";
4775
if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
4776
!(embedded_server_args[embedded_server_arg_count++]=
4779
die("Can't use server argument");
4783
read_embedded_server_arguments(argument);
4796
static int parse_args(int argc, char **argv)
4798
load_defaults("drizzle",load_default_groups,&argc,&argv);
4801
if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
4812
opt_pass= client_get_tty_password(NULL); /* purify tested */
4813
if (debug_info_flag)
4814
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
4815
if (debug_check_flag)
4816
my_end_arg= MY_CHECK_ERROR;
4646
4822
Write the content of str into file
5420
static void check_retries(uint32_t in_opt_max_connect_retries)
5422
if (in_opt_max_connect_retries > 10000 || opt_max_connect_retries<1)
5424
cout << N_("Error: Invalid Value for opt_max_connect_retries");
5427
opt_max_connect_retries= in_opt_max_connect_retries;
5430
static void check_tail_lines(uint32_t in_opt_tail_lines)
5432
if (in_opt_tail_lines > 10000)
5434
cout << N_("Error: Invalid Value for opt_tail_lines");
5437
opt_tail_lines= in_opt_tail_lines;
5440
static void check_sleep(int32_t in_opt_sleep)
5442
if (in_opt_sleep < -1)
5444
cout << N_("Error: Invalid Value for opt_sleep");
5447
opt_sleep= in_opt_sleep;
5450
5597
int main(int argc, char **argv)
5454
5599
struct st_command *command;
5455
5600
bool q_send_flag= 0, abort_flag= 0;
5456
5601
uint32_t command_executed= 0, last_command_executed= 0;
5457
string save_file("");
5602
char save_file[FN_REFLEN];
5458
5603
struct stat res_info;
5462
internal::my_init();
5464
po::options_description commandline_options("Options used only in command line");
5465
commandline_options.add_options()
5466
("help,?", "Display this help and exit.")
5467
("mark-progress", po::value<bool>(&opt_mark_progress)->default_value(false)->zero_tokens(),
5468
"Write linenumber and elapsed time to <testname>.progress ")
5469
("sleep,T", po::value<int32_t>(&opt_sleep)->default_value(-1)->notifier(&check_sleep),
5470
"Sleep always this many seconds on sleep commands.")
5471
("test-file,x", po::value<string>(),
5472
"Read test from/in this file (default stdin).")
5473
("timer-file,f", po::value<string>(),
5474
"File where the timing in micro seconds is stored.")
5475
("tmpdir,t", po::value<string>(),
5476
"Temporary directory where sockets are put.")
5477
("verbose,v", po::value<bool>(&verbose)->default_value(false),
5479
("version,V", "Output version information and exit.")
5480
("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(),
5481
"Configuration file defaults are not used if no-defaults is set")
5484
po::options_description test_options("Options specific to the drizzleimport");
5485
test_options.add_options()
5486
("basedir,b", po::value<string>(&opt_basedir)->default_value(""),
5487
"Basedir for tests.")
5488
("character-sets-dir", po::value<string>(&opt_charsets_dir)->default_value(""),
5489
"Directory where character sets are.")
5490
("database,D", po::value<string>(&opt_db)->default_value(""),
5492
("include,i", po::value<string>(&opt_include)->default_value(""),
5493
"Include SQL before each test case.")
5494
("testdir", po::value<string>(&opt_testdir)->default_value(""),
5495
"Path to use to search for test files")
5496
("logdir", po::value<string>(&opt_logdir)->default_value(""),
5497
"Directory for log files")
5498
("max-connect-retries", po::value<uint32_t>(&opt_max_connect_retries)->default_value(500)->notifier(&check_retries),
5499
"Max number of connection attempts when connecting to server")
5500
("quiet,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
5501
"Suppress all normal output.")
5502
("record,r", "Record output of test_file into result file.")
5503
("result-file,R", po::value<string>(&result_file_name)->default_value(""),
5504
"Read/Store result from/in this file.")
5505
("silent,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(),
5506
"Suppress all normal output. Synonym for --quiet.")
5507
("tail-lines", po::value<uint32_t>(&opt_tail_lines)->default_value(0)->notifier(&check_tail_lines),
5508
"Number of lines of the resul to include in a failure report")
5511
po::options_description client_options("Options specific to the client");
5512
client_options.add_options()
5514
("host,h", po::value<string>(&opt_host)->default_value("localhost"),
5516
("password,P", po::value<string>(&password)->default_value("PASSWORD_SENTINEL"),
5517
"Password to use when connecting to server.")
5518
("port,p", po::value<uint32_t>(&opt_port)->default_value(0),
5519
"Port number to use for connection or 0 for default")
5520
("protocol", po::value<string>(&opt_protocol),
5521
"The protocol of connection (mysql or drizzle).")
5522
("user,u", po::value<string>(&opt_user)->default_value(""),
5526
po::positional_options_description p;
5527
p.add("database", 1);
5529
po::options_description long_options("Allowed Options");
5530
long_options.add(commandline_options).add(test_options).add(client_options);
5532
std::string system_config_dir_test(SYSCONFDIR);
5533
system_config_dir_test.append("/drizzle/drizzletest.cnf");
5535
std::string system_config_dir_client(SYSCONFDIR);
5536
system_config_dir_client.append("/drizzle/client.cnf");
5538
std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
5540
if (user_config_dir.compare(0, 2, "~/") == 0)
5543
homedir= getenv("HOME");
5544
if (homedir != NULL)
5545
user_config_dir.replace(0, 1, homedir);
5548
po::variables_map vm;
5550
// Disable allow_guessing
5551
int style = po::command_line_style::default_style & ~po::command_line_style::allow_guessing;
5553
po::store(po::command_line_parser(argc, argv).options(long_options).
5554
style(style).positional(p).extra_parser(parse_password_arg).run(),
5557
if (! vm["no-defaults"].as<bool>())
5559
std::string user_config_dir_test(user_config_dir);
5560
user_config_dir_test.append("/drizzle/drizzletest.cnf");
5562
std::string user_config_dir_client(user_config_dir);
5563
user_config_dir_client.append("/drizzle/client.cnf");
5565
ifstream user_test_ifs(user_config_dir_test.c_str());
5566
po::store(parse_config_file(user_test_ifs, test_options), vm);
5568
ifstream user_client_ifs(user_config_dir_client.c_str());
5569
po::store(parse_config_file(user_client_ifs, client_options), vm);
5571
ifstream system_test_ifs(system_config_dir_test.c_str());
5572
store(parse_config_file(system_test_ifs, test_options), vm);
5574
ifstream system_client_ifs(system_config_dir_client.c_str());
5575
po::store(parse_config_file(system_client_ifs, client_options), vm);
5580
5609
/* Init expected errors */
5581
5610
memset(&saved_expected_errors, 0, sizeof(saved_expected_errors));
5613
5646
ds_progress.reserve(2048);
5614
5647
ds_warning_messages.reserve(2048);
5617
if (vm.count("record"))
5622
if (vm.count("test-file"))
5624
string tmp= vm["test-file"].as<string>();
5625
char buff[FN_REFLEN];
5626
if (!internal::test_if_hard_path(tmp.c_str()))
5628
snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str());
5631
internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME);
5632
assert(cur_file == file_stack && cur_file->file == 0);
5633
if (!(cur_file->file= fopen(buff, "r")))
5635
fprintf(stderr, _("Could not open '%s' for reading: errno = %d"), buff, errno);
5636
return EXIT_ARGUMENT_INVALID;
5638
if (!(cur_file->file_name= strdup(buff)))
5640
fprintf(stderr, _("Out of memory"));
5641
return EXIT_OUT_OF_MEMORY;
5643
cur_file->lineno= 1;
5646
if (vm.count("timer-file"))
5648
string tmp= vm["timer-file"].as<string>().c_str();
5649
static char buff[FN_REFLEN];
5650
if (!internal::test_if_hard_path(tmp.c_str()))
5652
snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str());
5655
internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME);
5657
unlink(timer_file); /* Ignore error, may not exist */
5660
if (vm.count("protocol"))
5662
std::transform(opt_protocol.begin(), opt_protocol.end(),
5663
opt_protocol.begin(), ::tolower);
5665
if (not opt_protocol.compare("mysql"))
5666
use_drizzle_protocol=false;
5667
else if (not opt_protocol.compare("drizzle"))
5668
use_drizzle_protocol=true;
5671
cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
5676
if (vm.count("port"))
5678
/* If the port number is > 65535 it is not a valid port
5679
This also helps with potential data loss casting unsigned long to a
5681
if (opt_port > 65535)
5683
fprintf(stderr, _("Value supplied for port is not valid.\n"));
5684
exit(EXIT_ARGUMENT_INVALID);
5688
if( vm.count("password") )
5690
if (!opt_password.empty())
5691
opt_password.erase();
5692
if (password == PASSWORD_SENTINEL)
5698
opt_password= password;
5699
tty_password= false;
5707
if (vm.count("tmpdir"))
5709
strncpy(TMPDIR, vm["tmpdir"].as<string>().c_str(), sizeof(TMPDIR));
5712
if (vm.count("version"))
5714
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
5715
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
5719
if (vm.count("help"))
5721
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
5722
drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
5723
printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
5724
printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n");
5725
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
5726
printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
5727
printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname);
5733
opt_pass= client_get_tty_password(NULL); /* purify tested */
5649
parse_args(argc, argv);
5736
5651
server_initialized= 1;
5737
5652
if (cur_file == file_stack && cur_file->file == 0)
6666
6548
icase - flag, if set to 1 the match is case insensitive
6668
6550
int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
6669
char *replace, char *in_string, int icase, int global)
6551
char *replace, char *in_string, int icase)
6553
string string_to_match(in_string);
6671
6554
const char *error= NULL;
6673
6556
int ovector[3];
6674
6557
pcre *re= pcre_compile(pattern,
6675
icase ? PCRE_CASELESS | PCRE_MULTILINE : PCRE_MULTILINE,
6558
icase ? PCRE_CASELESS : 0,
6676
6559
&error, &erroffset, NULL);
6677
6560
if (re == NULL)
6683
int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
6691
char *substring_to_replace= in_string + ovector[0];
6692
int substring_length= ovector[1] - ovector[0];
6693
*buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6694
char * new_buf = (char *)malloc(*buf_len_p+1);
6695
if (new_buf == NULL)
6701
memset(new_buf, 0, *buf_len_p+1);
6702
strncpy(new_buf, in_string, substring_to_replace-in_string);
6703
strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
6704
strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
6705
substring_to_replace + substring_length,
6708
- (substring_to_replace-in_string));
6716
/* Repeatedly replace the string with the matched regex */
6717
string subject(in_string);
6718
size_t replace_length= strlen(replace);
6719
size_t length_of_replacement= strlen(replace);
6720
size_t current_position= 0;
6725
rc= pcre_exec(re, NULL, subject.c_str(), subject.length(),
6726
current_position, 0, ovector, 3);
6732
current_position= static_cast<size_t>(ovector[0]);
6733
replace_length= static_cast<size_t>(ovector[1] - ovector[0]);
6734
subject.replace(current_position, replace_length, replace, length_of_replacement);
6735
current_position= current_position + length_of_replacement;
6738
char *new_buf = (char *) malloc(subject.length() + 1);
6739
if (new_buf == NULL)
6744
memset(new_buf, 0, subject.length() + 1);
6745
strncpy(new_buf, subject.c_str(), subject.length());
6746
*buf_len_p= subject.length() + 1;
6563
int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
6571
char *substring_to_replace= in_string + ovector[0];
6572
int substring_length= ovector[1] - ovector[0];
6573
*buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6574
char * new_buf = (char *)malloc(*buf_len_p+1);
6575
if (new_buf == NULL)
6581
memset(new_buf, 0, *buf_len_p+1);
6582
strncpy(new_buf, in_string, substring_to_replace-in_string);
6583
strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
6584
strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
6585
substring_to_replace + substring_length,
6588
- (substring_to_replace-in_string));