Merge lp:~vjsamuel/drizzle/refactor-drizzletest into lp:~drizzle-trunk/drizzle/development

Proposed by Vijay Samuel
Status: Merged
Approved by: Brian Aker
Approved revision: 1614
Merged at revision: 1624
Proposed branch: lp:~vjsamuel/drizzle/refactor-drizzletest
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 898 lines (+349/-268)
3 files modified
client/drizzle.cc (+1/-1)
client/drizzletest.cc (+347/-266)
client/include.am (+1/-1)
To merge this branch: bzr merge lp:~vjsamuel/drizzle/refactor-drizzletest
Reviewer Review Type Date Requested Status
Brian Aker Pending
Drizzle Developers Pending
Review via email: mp+27680@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/drizzle.cc'
--- client/drizzle.cc 2010-06-09 21:36:07 +0000
+++ client/drizzle.cc 2010-06-16 07:57:30 +0000
@@ -1531,7 +1531,7 @@
1531 po::variables_map vm;1531 po::variables_map vm;
15321532
1533 po::positional_options_description p;1533 po::positional_options_description p;
1534 p.add("database", -1);1534 p.add("database", 1);
15351535
1536 po::store(po::command_line_parser(argc, argv).options(long_options).1536 po::store(po::command_line_parser(argc, argv).options(long_options).
1537 positional(p).extra_parser(parse_password_arg).run(), vm);1537 positional(p).extra_parser(parse_password_arg).run(), vm);
15381538
=== modified file 'client/drizzletest.cc'
--- client/drizzletest.cc 2010-06-03 07:59:07 +0000
+++ client/drizzletest.cc 2010-06-16 07:57:30 +0000
@@ -44,6 +44,7 @@
44#include <map>44#include <map>
45#include <string>45#include <string>
46#include <sstream>46#include <sstream>
47#include <fstream>
47#include <iostream>48#include <iostream>
48#include <vector>49#include <vector>
49#include <algorithm>50#include <algorithm>
@@ -54,6 +55,7 @@
54#include <sys/stat.h>55#include <sys/stat.h>
55#include <sys/types.h>56#include <sys/types.h>
56#include <fcntl.h>57#include <fcntl.h>
58#include <boost/program_options.hpp>
5759
58#include PCRE_HEADER60#include PCRE_HEADER
5961
@@ -66,11 +68,12 @@
66#include "drizzled/gettext.h"68#include "drizzled/gettext.h"
67#include "drizzled/drizzle_time.h"69#include "drizzled/drizzle_time.h"
68#include "drizzled/charset.h"70#include "drizzled/charset.h"
71#include <drizzled/configmake.h>
6972
70#ifndef DRIZZLE_RETURN_SERVER_GONE73#ifndef DRIZZLE_RETURN_SERVER_GONE
71#define DRIZZLE_RETURN_HANDSHAKE_FAILED DRIZZLE_RETURN_ERROR_CODE74#define DRIZZLE_RETURN_HANDSHAKE_FAILED DRIZZLE_RETURN_ERROR_CODE
72#endif75#endif
7376namespace po= boost::program_options;
74using namespace std;77using namespace std;
75using namespace drizzled;78using namespace drizzled;
7679
@@ -95,14 +98,10 @@
95};98};
9699
97static int record= 0, opt_sleep= -1;100static int record= 0, opt_sleep= -1;
98static char *opt_db= NULL, *opt_pass= NULL;101static char *opt_pass= NULL;
99const char *opt_user= NULL, *opt_host= NULL, *unix_sock= NULL,102const char *unix_sock= NULL;
100 *opt_basedir= "./";
101const char *opt_logdir= "";
102const char *opt_include= NULL, *opt_charsets_dir;
103const char *opt_testdir= NULL;
104static uint32_t opt_port= 0;103static uint32_t opt_port= 0;
105static int opt_max_connect_retries;104static uint32_t opt_max_connect_retries;
106static bool silent= false, verbose= false;105static bool silent= false, verbose= false;
107static bool tty_password= false;106static bool tty_password= false;
108static bool opt_mark_progress= false;107static bool opt_mark_progress= false;
@@ -116,10 +115,21 @@
116static bool server_initialized= false;115static bool server_initialized= false;
117static bool is_windows= false;116static bool is_windows= false;
118static bool opt_mysql= false;117static bool opt_mysql= false;
119static char **default_argv;118const string PASSWORD_SENTINEL("\0\0\0\0\0", 5);
120static const char *load_default_groups[]= { "drizzletest", "client", 0 };
121static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;119static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
122120
121std::string opt_basedir,
122 opt_charsets_dir,
123 opt_db,
124 opt_host,
125 opt_include,
126 opt_testdir,
127 opt_logdir,
128 password,
129 opt_password,
130 result_file_name,
131 opt_user;
132
123static uint32_t start_lineno= 0; /* Start line of current command */133static uint32_t start_lineno= 0; /* Start line of current command */
124134
125/* Number of lines of the result to include in failure report */135/* Number of lines of the result to include in failure report */
@@ -189,7 +199,6 @@
189master_pos_st master_pos;199master_pos_st master_pos;
190200
191/* if set, all results are concated and compared against this file */201/* if set, all results are concated and compared against this file */
192const char *result_file_name= NULL;
193202
194typedef struct st_var203typedef struct st_var
195{204{
@@ -920,7 +929,6 @@
920929
921 free_all_replace();930 free_all_replace();
922 free(opt_pass);931 free(opt_pass);
923 internal::free_defaults(default_argv);
924932
925 return;933 return;
926}934}
@@ -1002,11 +1010,11 @@
1002 }1010 }
10031011
1004 /* Dump the result that has been accumulated so far to .log file */1012 /* Dump the result that has been accumulated so far to .log file */
1005 if (result_file_name && ds_res.length())1013 if (! result_file_name.empty() && ds_res.length())
1006 dump_result_to_log_file(ds_res.c_str(), ds_res.length());1014 dump_result_to_log_file(ds_res.c_str(), ds_res.length());
10071015
1008 /* Dump warning messages */1016 /* Dump warning messages */
1009 if (result_file_name && ds_warning_messages.length())1017 if (! result_file_name.empty() && ds_warning_messages.length())
1010 dump_warning_messages();1018 dump_warning_messages();
10111019
1012 /*1020 /*
@@ -1354,7 +1362,7 @@
1354 if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0)1362 if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0)
1355 {1363 {
1356 internal::my_close(fd, MYF(0));1364 internal::my_close(fd, MYF(0));
1357 if (opt_testdir != NULL)1365 if (! opt_testdir.empty())
1358 {1366 {
1359 tmpfile= opt_testdir;1367 tmpfile= opt_testdir;
1360 if (tmpfile[tmpfile.length()] != '/')1368 if (tmpfile[tmpfile.length()] != '/')
@@ -1494,12 +1502,12 @@
1494 const char* mess= "Result content mismatch\n";1502 const char* mess= "Result content mismatch\n";
14951503
14961504
1497 assert(result_file_name);1505 assert(result_file_name.c_str());
14981506
1499 if (access(result_file_name, F_OK) != 0)1507 if (access(result_file_name.c_str(), F_OK) != 0)
1500 die("The specified result file does not exist: '%s'", result_file_name);1508 die("The specified result file does not exist: '%s'", result_file_name.c_str());
15011509
1502 switch (string_cmp(ds, result_file_name)) {1510 switch (string_cmp(ds, result_file_name.c_str())) {
1503 case RESULT_OK:1511 case RESULT_OK:
1504 break; /* ok */1512 break; /* ok */
1505 case RESULT_LENGTH_MISMATCH:1513 case RESULT_LENGTH_MISMATCH:
@@ -1513,25 +1521,25 @@
1513 */1521 */
1514 char reject_file[FN_REFLEN];1522 char reject_file[FN_REFLEN];
1515 size_t reject_length;1523 size_t reject_length;
1516 internal::dirname_part(reject_file, result_file_name, &reject_length);1524 internal::dirname_part(reject_file, result_file_name.c_str(), &reject_length);
15171525
1518 if (access(reject_file, W_OK) == 0)1526 if (access(reject_file, W_OK) == 0)
1519 {1527 {
1520 /* Result file directory is writable, save reject file there */1528 /* Result file directory is writable, save reject file there */
1521 internal::fn_format(reject_file, result_file_name, NULL,1529 internal::fn_format(reject_file, result_file_name.c_str(), NULL,
1522 ".reject", MY_REPLACE_EXT);1530 ".reject", MY_REPLACE_EXT);
1523 }1531 }
1524 else1532 else
1525 {1533 {
1526 /* Put reject file in opt_logdir */1534 /* Put reject file in opt_logdir */
1527 internal::fn_format(reject_file, result_file_name, opt_logdir,1535 internal::fn_format(reject_file, result_file_name.c_str(), opt_logdir.c_str(),
1528 ".reject", MY_REPLACE_DIR | MY_REPLACE_EXT);1536 ".reject", MY_REPLACE_DIR | MY_REPLACE_EXT);
1529 }1537 }
1530 str_to_file(reject_file, ds->c_str(), ds->length());1538 str_to_file(reject_file, ds->c_str(), ds->length());
15311539
1532 ds->erase(); /* Don't create a .log file */1540 ds->erase(); /* Don't create a .log file */
15331541
1534 show_diff(NULL, result_file_name, reject_file);1542 show_diff(NULL, result_file_name.c_str(), reject_file);
1535 die("%s",mess);1543 die("%s",mess);
1536 break;1544 break;
1537 }1545 }
@@ -2147,7 +2155,7 @@
21472155
2148 if (!internal::test_if_hard_path(name))2156 if (!internal::test_if_hard_path(name))
2149 {2157 {
2150 snprintf(buff, sizeof(buff), "%s%s",opt_basedir,name);2158 snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),name);
2151 name=buff;2159 name=buff;
2152 }2160 }
2153 internal::fn_format(buff, name, "", "", MY_UNPACK_FILENAME);2161 internal::fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
@@ -2201,7 +2209,7 @@
2201 ; /* Do nothing */2209 ; /* Do nothing */
2202 else2210 else
2203 {2211 {
2204 if (opt_testdir != NULL)2212 if (! opt_testdir.empty())
2205 {2213 {
2206 string testdir(opt_testdir);2214 string testdir(opt_testdir);
2207 if (testdir[testdir.length()] != '/')2215 if (testdir[testdir.length()] != '/')
@@ -3348,7 +3356,7 @@
3348 if (*p)3356 if (*p)
3349 *p++= 0;3357 *p++= 0;
3350 command->last_argument= p;3358 command->last_argument= p;
3351 if (opt_testdir != NULL)3359 if (! opt_testdir.empty())
3352 {3360 {
3353 dest= opt_testdir;3361 dest= opt_testdir;
3354 if (dest[dest.length()] != '/')3362 if (dest[dest.length()] != '/')
@@ -3685,16 +3693,16 @@
3685*/3693*/
36863694
3687static void safe_connect(drizzle_con_st *con, const char *name,3695static void safe_connect(drizzle_con_st *con, const char *name,
3688 const char *host, const char *user, const char *pass,3696 const string host, const string user, const char *pass,
3689 const char *db, int port)3697 const string db, uint32_t port)
3690{3698{
3691 int failed_attempts= 0;3699 uint32_t failed_attempts= 0;
3692 static uint32_t connection_retry_sleep= 100000; /* Microseconds */3700 static uint32_t connection_retry_sleep= 100000; /* Microseconds */
3693 drizzle_return_t ret;3701 drizzle_return_t ret;
36943702
3695 drizzle_con_set_tcp(con, host, port);3703 drizzle_con_set_tcp(con, host.c_str(), port);
3696 drizzle_con_set_auth(con, user, pass);3704 drizzle_con_set_auth(con, user.c_str(), pass);
3697 drizzle_con_set_db(con, db);3705 drizzle_con_set_db(con, db.c_str());
3698 while((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)3706 while((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
3699 {3707 {
3700 /*3708 /*
@@ -3836,7 +3844,7 @@
38363844
3837static void do_connect(struct st_command *command)3845static void do_connect(struct st_command *command)
3838{3846{
3839 int con_port= opt_port;3847 uint32_t con_port= opt_port;
3840 const char *con_options;3848 const char *con_options;
3841 bool con_ssl= 0, con_compress= 0;3849 bool con_ssl= 0, con_compress= 0;
3842 struct st_connection* con_slot;3850 struct st_connection* con_slot;
@@ -4496,8 +4504,6 @@
4496 return;4504 return;
4497}4505}
44984506
4499
4500
4501/*4507/*
4502 Create a command from a set of lines4508 Create a command from a set of lines
45034509
@@ -4577,217 +4583,6 @@
4577 return(0);4583 return(0);
4578}4584}
45794585
4580
4581static struct option my_long_options[] =
4582{
4583 {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
4584 0, 0, 0, 0, 0, 0},
4585 {"basedir", 'b', "Basedir for tests.", (char**) &opt_basedir,
4586 (char**) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4587 {"character-sets-dir", OPT_CHARSETS_DIR,
4588 "Directory where character sets are.", (char**) &opt_charsets_dir,
4589 (char**) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4590 {"database", 'D', "Database to use.", (char**) &opt_db, (char**) &opt_db, 0,
4591 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4592 {"host", 'h', "Connect to host.", (char**) &opt_host, (char**) &opt_host, 0,
4593 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4594 {"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4595 (char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4596 {"testdir", OPT_TESTDIR, "Path to use to search for test files",
4597 (char**) &opt_testdir,
4598 (char**) &opt_testdir, 0,GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4599 {"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4600 (char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4601 {"mark-progress", OPT_MARK_PROGRESS,
4602 "Write linenumber and elapsed time to <testname>.progress ",
4603 (char**) &opt_mark_progress, (char**) &opt_mark_progress, 0,
4604 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4605 {"max-connect-retries", OPT_MAX_CONNECT_RETRIES,
4606 "Max number of connection attempts when connecting to server",
4607 (char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4608 GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4609 {"mysql", 'm', N_("Use MySQL Protocol."),
4610 (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
4611 0, 0, 0},
4612 {"password", 'P', "Password to use when connecting to server.",
4613 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
4614 {"port", 'p', "Port number to use for connection or 0 for default to, in "
4615 "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
4616 "built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4617 0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4618 {"quiet", 's', "Suppress all normal output.", (char**) &silent,
4619 (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4620 {"record", 'r', "Record output of test_file into result file.",
4621 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4622 {"result-file", 'R', "Read/Store result from/in this file.",
4623 (char**) &result_file_name, (char**) &result_file_name, 0,
4624 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4625 {"silent", 's', "Suppress all normal output. Synonym for --quiet.",
4626 (char**) &silent, (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4627 {"sleep", 'T', "Sleep always this many seconds on sleep commands.",
4628 (char**) &opt_sleep, (char**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
4629 0, 0, 0},
4630 {"tail-lines", OPT_TAIL_LINES,
4631 "Number of lines of the resul to include in a failure report",
4632 (char**) &opt_tail_lines, (char**) &opt_tail_lines, 0,
4633 GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0},
4634 {"test-file", 'x', "Read test from/in this file (default stdin).",
4635 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4636 {"timer-file", 'm', "File where the timing in micro seconds is stored.",
4637 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4638 {"tmpdir", 't', "Temporary directory where sockets are put.",
4639 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4640 {"user", 'u', "User for login.", (char**) &opt_user, (char**) &opt_user, 0,
4641 GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4642 {"verbose", 'v', "Write more.", (char**) &verbose, (char**) &verbose, 0,
4643 GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4644 {"version", 'V', "Output version information and exit.",
4645 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
4646 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
4647};
4648
4649
4650static void print_version(void)
4651{
4652 printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
4653 drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
4654}
4655
4656static void usage(void)
4657{
4658 print_version();
4659 printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
4660 printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n");
4661 printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4662 printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4663 printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname);
4664 my_print_help(my_long_options);
4665 printf(" --no-defaults Don't read default options from any options file.\n");
4666 my_print_variables(my_long_options);
4667}
4668
4669int get_one_option(int optid, const struct option *, char *argument)
4670{
4671 char *endchar= NULL;
4672 uint64_t temp_drizzle_port= 0;
4673
4674 switch(optid) {
4675 case 'r':
4676 record = 1;
4677 break;
4678 case 'x':
4679 {
4680 char buff[FN_REFLEN];
4681 if (!internal::test_if_hard_path(argument))
4682 {
4683 snprintf(buff, sizeof(buff), "%s%s",opt_basedir,argument);
4684 argument= buff;
4685 }
4686 internal::fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4687 assert(cur_file == file_stack && cur_file->file == 0);
4688 if (!(cur_file->file= fopen(buff, "r")))
4689 {
4690 fprintf(stderr, _("Could not open '%s' for reading: errno = %d"), buff, errno);
4691 return EXIT_ARGUMENT_INVALID;
4692 }
4693 if (!(cur_file->file_name= strdup(buff)))
4694 {
4695 fprintf(stderr, _("Out of memory"));
4696 return EXIT_OUT_OF_MEMORY;
4697 }
4698 cur_file->lineno= 1;
4699 break;
4700 }
4701 case 'm':
4702 {
4703 static char buff[FN_REFLEN];
4704 if (!internal::test_if_hard_path(argument))
4705 {
4706 snprintf(buff, sizeof(buff), "%s%s",opt_basedir,argument);
4707 argument= buff;
4708 }
4709 internal::fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4710 timer_file= buff;
4711 unlink(timer_file); /* Ignore error, may not exist */
4712 break;
4713 }
4714 case 'p':
4715 temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
4716 /* if there is an alpha character this is not a valid port */
4717 if (strlen(endchar) != 0)
4718 {
4719 fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
4720 return EXIT_ARGUMENT_INVALID;
4721 }
4722 /* If the port number is > 65535 it is not a valid port
4723 This also helps with potential data loss casting unsigned long to a
4724 uint32_t. */
4725 if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
4726 {
4727 fprintf(stderr, _("Value supplied for port is not valid.\n"));
4728 return EXIT_ARGUMENT_INVALID;
4729 }
4730 else
4731 {
4732 opt_port= (uint32_t) temp_drizzle_port;
4733 }
4734 break;
4735 case 'P':
4736 if (argument)
4737 {
4738 if (opt_pass)
4739 free(opt_pass);
4740 opt_pass = strdup(argument);
4741 if (opt_pass == NULL)
4742 {
4743 fprintf(stderr, _("Out of memory"));
4744 return EXIT_OUT_OF_MEMORY;
4745 }
4746 while (*argument)
4747 {
4748 /* Overwriting password with 'x' */
4749 *argument++= 'x';
4750 }
4751 tty_password= 0;
4752 }
4753 else
4754 tty_password= 1;
4755 break;
4756 case 't':
4757 strncpy(TMPDIR, argument, sizeof(TMPDIR));
4758 break;
4759 case 'V':
4760 print_version();
4761 exit(0);
4762 case '?':
4763 usage();
4764 exit(0);
4765 }
4766 return 0;
4767}
4768
4769
4770static int parse_args(int argc, char **argv)
4771{
4772 internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
4773 default_argv= argv;
4774
4775 if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
4776 exit(1);
4777
4778 if (argc > 1)
4779 {
4780 usage();
4781 exit(1);
4782 }
4783 if (argc == 1)
4784 opt_db= *argv;
4785 if (tty_password)
4786 opt_pass= client_get_tty_password(NULL); /* purify tested */
4787
4788 return 0;
4789}
4790
4791/*4586/*
4792 Write the content of str into file4587 Write the content of str into file
47934588
@@ -4806,7 +4601,7 @@
4806 int flags= O_WRONLY | O_CREAT;4601 int flags= O_WRONLY | O_CREAT;
4807 if (!internal::test_if_hard_path(fname))4602 if (!internal::test_if_hard_path(fname))
4808 {4603 {
4809 snprintf(buff, sizeof(buff), "%s%s",opt_basedir,fname);4604 snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),fname);
4810 fname= buff;4605 fname= buff;
4811 }4606 }
4812 internal::fn_format(buff, fname, "", "", MY_UNPACK_FILENAME);4607 internal::fn_format(buff, fname, "", "", MY_UNPACK_FILENAME);
@@ -4842,8 +4637,8 @@
4842void dump_result_to_log_file(const char *buf, int size)4637void dump_result_to_log_file(const char *buf, int size)
4843{4638{
4844 char log_file[FN_REFLEN];4639 char log_file[FN_REFLEN];
4845 str_to_file(internal::fn_format(log_file, result_file_name, opt_logdir, ".log",4640 str_to_file(internal::fn_format(log_file, result_file_name.c_str(), opt_logdir.c_str(), ".log",
4846 *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT :4641 ! opt_logdir.empty() ? MY_REPLACE_DIR | MY_REPLACE_EXT :
4847 MY_REPLACE_EXT),4642 MY_REPLACE_EXT),
4848 buf, size);4643 buf, size);
4849 fprintf(stderr, "\nMore results from queries before failure can be found in %s\n",4644 fprintf(stderr, "\nMore results from queries before failure can be found in %s\n",
@@ -4853,9 +4648,9 @@
4853void dump_progress(void)4648void dump_progress(void)
4854{4649{
4855 char progress_file[FN_REFLEN];4650 char progress_file[FN_REFLEN];
4856 str_to_file(internal::fn_format(progress_file, result_file_name,4651 str_to_file(internal::fn_format(progress_file, result_file_name.c_str(),
4857 opt_logdir, ".progress",4652 opt_logdir.c_str(), ".progress",
4858 *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT :4653 ! opt_logdir.empty() ? MY_REPLACE_DIR | MY_REPLACE_EXT :
4859 MY_REPLACE_EXT),4654 MY_REPLACE_EXT),
4860 ds_progress.c_str(), ds_progress.length());4655 ds_progress.c_str(), ds_progress.length());
4861}4656}
@@ -4864,8 +4659,8 @@
4864{4659{
4865 char warn_file[FN_REFLEN];4660 char warn_file[FN_REFLEN];
48664661
4867 str_to_file(internal::fn_format(warn_file, result_file_name, opt_logdir, ".warnings",4662 str_to_file(internal::fn_format(warn_file, result_file_name.c_str(), opt_logdir.c_str(), ".warnings",
4868 *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT :4663 ! opt_logdir.empty() ? MY_REPLACE_DIR | MY_REPLACE_EXT :
4869 MY_REPLACE_EXT),4664 MY_REPLACE_EXT),
4870 ds_warning_messages.c_str(), ds_warning_messages.length());4665 ds_warning_messages.c_str(), ds_warning_messages.length());
4871}4666}
@@ -5563,18 +5358,185 @@
55635358
5564}5359}
55655360
5361static void check_retries(uint32_t in_opt_max_connect_retries)
5362{
5363 if (in_opt_max_connect_retries > 10000 || opt_max_connect_retries<1)
5364 {
5365 cout<<N_("Error: Invalid Value for opt_max_connect_retries");
5366 exit(-1);
5367 }
5368 opt_max_connect_retries= in_opt_max_connect_retries;
5369}
5370
5371static void check_tail_lines(uint32_t in_opt_tail_lines)
5372{
5373 if (in_opt_tail_lines > 10000)
5374 {
5375 cout<<N_("Error: Invalid Value for opt_tail_lines");
5376 exit(-1);
5377 }
5378 opt_tail_lines= in_opt_tail_lines;
5379}
5380
5381static void check_sleep(int32_t in_opt_sleep)
5382{
5383 if (in_opt_sleep < -1)
5384 {
5385 cout<<N_("Error: Invalid Value for opt_sleep");
5386 exit(-1);
5387 }
5388 opt_sleep= in_opt_sleep;
5389}
5390
5391static pair<string, string> parse_password_arg(std::string s)
5392{
5393 if (s.find("--password") == 0)
5394 {
5395 if (s == "--password")
5396 {
5397 tty_password= true;
5398 //check if no argument is passed.
5399 return make_pair("password", PASSWORD_SENTINEL);
5400 }
5401
5402 if (s.substr(10,3) == "=\"\"" || s.substr(10,3) == "=''")
5403 {
5404 // Check if --password="" or --password=''
5405 return make_pair("password", PASSWORD_SENTINEL);
5406 }
5407
5408 if(s.substr(10) == "=" && s.length() == 11)
5409 {
5410 // check if --password= and return a default value
5411 return make_pair("password", PASSWORD_SENTINEL);
5412 }
5413
5414 if(s.length()>12 && (s[10] == '"' || s[10] == '\''))
5415 {
5416 // check if --password has quotes, remove quotes and return the value
5417 return make_pair("password", s.substr(11,s.length()-1));
5418 }
5419
5420 // if all above are false, it implies that --password=value, return value.
5421 return make_pair("password", s.substr(11));
5422 }
5423
5424 else
5425 {
5426 return make_pair(string(""), string(""));
5427 }
5428}
55665429
5567int main(int argc, char **argv)5430int main(int argc, char **argv)
5568{5431{
5432try
5433{
5569 struct st_command *command;5434 struct st_command *command;
5570 bool q_send_flag= 0, abort_flag= 0;5435 bool q_send_flag= 0, abort_flag= 0;
5571 uint32_t command_executed= 0, last_command_executed= 0;5436 uint32_t command_executed= 0, last_command_executed= 0;
5572 string save_file("");5437 string save_file("");
5573 struct stat res_info;5438 struct stat res_info;
5574 MY_INIT(argv[0]);
55755439
5576 TMPDIR[0]= 0;5440 TMPDIR[0]= 0;
55775441
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),
5456 "Write more.")
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")
5460 ;
5461
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(""),
5469 "Database to use.")
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(0)->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")
5487 ;
5488
5489 po::options_description client_options("Options specific to the client");
5490 client_options.add_options()
5491
5492 ("host,h", po::value<string>(&opt_host)->default_value("localhost"),
5493 "Connect to host.")
5494 ("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(),
5495 N_("Use MySQL Protocol."))
5496 ("password,P", po::value<string>(&password)->default_value("PASSWORD_SENTINEL"),
5497 "Password to use when connecting to server.")
5498 ("port,p", po::value<uint32_t>(&opt_port)->default_value(0),
5499 "Port number to use for connection or 0 for default")
5500 ("protocol", po::value<string>(),
5501 "The protocol of connection (tcp,socket,pipe,memory).")
5502 ("user,u", po::value<string>(&opt_user)->default_value(""),
5503 "User for login.")
5504 ;
5505
5506 po::positional_options_description p;
5507 p.add("database", 1);
5508
5509 po::options_description long_options("Allowed Options");
5510 long_options.add(commandline_options).add(test_options).add(client_options);
5511
5512 std::string system_config_dir_test(SYSCONFDIR);
5513 system_config_dir_test.append("/drizzle/drizzletest.cnf");
5514
5515 std::string system_config_dir_client(SYSCONFDIR);
5516 system_config_dir_client.append("/drizzle/client.cnf");
5517
5518 po::variables_map vm;
5519
5520 po::store(po::command_line_parser(argc, argv).options(long_options).
5521 positional(p).extra_parser(parse_password_arg).run(), vm);
5522
5523 if (! vm["no-defaults"].as<bool>())
5524 {
5525 ifstream user_test_ifs("~/.drizzle/drizzletest.cnf");
5526 po::store(parse_config_file(user_test_ifs, test_options), vm);
5527
5528 ifstream system_test_ifs(system_config_dir_test.c_str());
5529 store(parse_config_file(system_test_ifs, test_options), vm);
5530
5531 ifstream user_client_ifs("~/.drizzle/client.cnf");
5532 po::store(parse_config_file(user_client_ifs, client_options), vm);
5533
5534 ifstream system_client_ifs(system_config_dir_client.c_str());
5535 po::store(parse_config_file(system_client_ifs, client_options), vm);
5536 }
5537
5538 po::notify(vm);
5539
5578 /* Init expected errors */5540 /* Init expected errors */
5579 memset(&saved_expected_errors, 0, sizeof(saved_expected_errors));5541 memset(&saved_expected_errors, 0, sizeof(saved_expected_errors));
55805542
@@ -5611,7 +5573,120 @@
5611 ds_progress.reserve(2048);5573 ds_progress.reserve(2048);
5612 ds_warning_messages.reserve(2048);5574 ds_warning_messages.reserve(2048);
56135575
5614 parse_args(argc, argv);5576
5577 if (vm.count("record"))
5578 {
5579 record = 1;
5580 }
5581
5582 if (vm.count("test-file"))
5583 {
5584 string tmp= vm["test-file"].as<string>();
5585 char buff[FN_REFLEN];
5586 if (!internal::test_if_hard_path(tmp.c_str()))
5587 {
5588 snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str());
5589 tmp= buff;
5590 }
5591 internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME);
5592 assert(cur_file == file_stack && cur_file->file == 0);
5593 if (!(cur_file->file= fopen(buff, "r")))
5594 {
5595 fprintf(stderr, _("Could not open '%s' for reading: errno = %d"), buff, errno);
5596 return EXIT_ARGUMENT_INVALID;
5597 }
5598 if (!(cur_file->file_name= strdup(buff)))
5599 {
5600 fprintf(stderr, _("Out of memory"));
5601 return EXIT_OUT_OF_MEMORY;
5602 }
5603 cur_file->lineno= 1;
5604 }
5605
5606 if (vm.count("timer-file"))
5607 {
5608 string tmp= vm["timer-file"].as<string>().c_str();
5609 static char buff[FN_REFLEN];
5610 if (!internal::test_if_hard_path(tmp.c_str()))
5611 {
5612 snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str());
5613 tmp= buff;
5614 }
5615 internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME);
5616 timer_file= buff;
5617 unlink(timer_file); /* Ignore error, may not exist */
5618 }
5619
5620 if (vm.count("port"))
5621 {
5622 /* If the port number is > 65535 it is not a valid port
5623 This also helps with potential data loss casting unsigned long to a
5624 uint32_t. */
5625 if (opt_port > 65535)
5626 {
5627 fprintf(stderr, _("Value supplied for port is not valid.\n"));
5628 exit(EXIT_ARGUMENT_INVALID);
5629 }
5630 }
5631
5632 if (vm.count("password"))
5633 {
5634 if (!opt_password.empty())
5635 opt_password.erase();
5636 if (password == PASSWORD_SENTINEL)
5637 {
5638 opt_password= "";
5639 }
5640 else
5641 {
5642 opt_password= password;
5643 tty_password= false;
5644 }
5645 char *start= (char *)password.c_str();
5646 char *temp_pass= (char *)password.c_str();
5647 while (*temp_pass)
5648 {
5649 /* Overwriting password with 'x' */
5650 *temp_pass++= 'x';
5651 }
5652 if (*start)
5653 {
5654 start[1]= 0;
5655 }
5656 }
5657 else
5658 {
5659 tty_password= true;
5660 }
5661
5662 if (vm.count("tmpdir"))
5663 {
5664 strncpy(TMPDIR, vm["tmpdir"].as<string>().c_str(), sizeof(TMPDIR));
5665 }
5666
5667 if (vm.count("version"))
5668 {
5669 printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
5670 drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
5671 exit(0);
5672 }
5673
5674 if (vm.count("help"))
5675 {
5676 printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION,
5677 drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
5678 printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
5679 printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n");
5680 printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
5681 printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
5682 printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname);
5683 exit(0);
5684 }
5685
5686 if (tty_password)
5687 {
5688 opt_pass= client_get_tty_password(NULL); /* purify tested */
5689 }
56155690
5616 server_initialized= 1;5691 server_initialized= 1;
5617 if (cur_file == file_stack && cur_file->file == 0)5692 if (cur_file == file_stack && cur_file->file == 0)
@@ -5632,7 +5707,6 @@
56325707
5633 if (!(cur_con->name = strdup("default")))5708 if (!(cur_con->name = strdup("default")))
5634 die("Out of memory");5709 die("Out of memory");
5635
5636 safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,5710 safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5637 opt_db, opt_port);5711 opt_db, opt_port);
56385712
@@ -5649,9 +5723,9 @@
5649 /* Update $drizzleclient_get_server_version to that of current connection */5723 /* Update $drizzleclient_get_server_version to that of current connection */
5650 var_set_drizzleclient_get_server_version(&cur_con->con);5724 var_set_drizzleclient_get_server_version(&cur_con->con);
56515725
5652 if (opt_include)5726 if (! opt_include.empty())
5653 {5727 {
5654 open_file(opt_include);5728 open_file(opt_include.c_str());
5655 }5729 }
56565730
5657 while (!read_command(&command) && !abort_flag)5731 while (!read_command(&command) && !abort_flag)
@@ -5955,14 +6029,14 @@
5955 */6029 */
5956 if (ds_res.length())6030 if (ds_res.length())
5957 {6031 {
5958 if (result_file_name)6032 if (! result_file_name.empty())
5959 {6033 {
5960 /* A result file has been specified */6034 /* A result file has been specified */
59616035
5962 if (record)6036 if (record)
5963 {6037 {
5964 /* Recording - dump the output from test to result file */6038 /* Recording - dump the output from test to result file */
5965 str_to_file(result_file_name, ds_res.c_str(), ds_res.length());6039 str_to_file(result_file_name.c_str(), ds_res.c_str(), ds_res.length());
5966 }6040 }
5967 else6041 else
5968 {6042 {
@@ -5985,7 +6059,7 @@
5985 }6059 }
59866060
5987 if (!command_executed &&6061 if (!command_executed &&
5988 result_file_name && !stat(result_file_name, &res_info))6062 ! result_file_name.empty() && !stat(result_file_name.c_str(), &res_info))
5989 {6063 {
5990 /*6064 /*
5991 my_stat() successful on result file. Check if we have not run a6065 my_stat() successful on result file. Check if we have not run a
@@ -5997,16 +6071,23 @@
5997 die("No queries executed but result file found!");6071 die("No queries executed but result file found!");
5998 }6072 }
59996073
6000 if ( opt_mark_progress && result_file_name )6074 if ( opt_mark_progress && ! result_file_name.empty() )
6001 dump_progress();6075 dump_progress();
60026076
6003 /* Dump warning messages */6077 /* Dump warning messages */
6004 if (result_file_name && ds_warning_messages.length())6078 if (! result_file_name.empty() && ds_warning_messages.length())
6005 dump_warning_messages();6079 dump_warning_messages();
60066080
6007 timer_output();6081 timer_output();
6008 /* Yes, if we got this far the test has suceeded! Sakila smiles */6082 /* Yes, if we got this far the test has suceeded! Sakila smiles */
6009 cleanup_and_exit(0);6083 cleanup_and_exit(0);
6084}
6085
6086 catch(exception &err)
6087 {
6088 cerr<<err.what()<<endl;
6089 }
6090
6010 return 0; /* Keep compiler happy too */6091 return 0; /* Keep compiler happy too */
6011}6092}
60126093
60136094
=== modified file 'client/include.am'
--- client/include.am 2010-06-12 21:25:45 +0000
+++ client/include.am 2010-06-16 07:57:30 +0000
@@ -65,7 +65,7 @@
65client_drizzleslap_CXXFLAGS= ${CLIENT_CXXFLAGS}65client_drizzleslap_CXXFLAGS= ${CLIENT_CXXFLAGS}
6666
67client_drizzletest_SOURCES= client/drizzletest.cc client/errname.cc67client_drizzletest_SOURCES= client/drizzletest.cc client/errname.cc
68client_drizzletest_LDADD= ${CLIENT_LDADD} ${LIBPCRE}68client_drizzletest_LDADD= ${CLIENT_LDADD} ${BOOST_LIBS} ${LIBPCRE}
69client_drizzletest_CXXFLAGS= ${CLIENT_CXXFLAGS}69client_drizzletest_CXXFLAGS= ${CLIENT_CXXFLAGS}
70 70
7171