52
#ifdef HAVE_SYS_WAIT_H
57
#include <sys/types.h>
59
#include <boost/program_options.hpp>
50
#include <mysys/hash.h>
63
51
#include <stdarg.h>
64
#include <boost/unordered_map.hpp>
66
/* Added this for string translation. */
67
#include "drizzled/gettext.h"
68
#include "drizzled/drizzle_time.h"
69
#include "drizzled/charset.h"
70
#include <drizzled/configmake.h>
72
#ifndef DRIZZLE_RETURN_SERVER_GONE
73
#define DRIZZLE_RETURN_HANDSHAKE_FAILED DRIZZLE_RETURN_ERROR_CODE
75
namespace po= boost::program_options;
76
55
using namespace std;
77
using namespace drizzled;
80
unsigned char *get_var_key(const unsigned char* var, size_t *len, bool);
82
int get_one_option(int optid, const struct option *, char *argument);
84
57
#define MAX_VAR_NAME_LENGTH 256
85
58
#define MAX_COLUMNS 256
59
#define MAX_EMBEDDED_SERVER_ARGS 64
86
60
#define MAX_DELIMITER_LENGTH 16
87
61
/* Flags controlling send and reap */
88
62
#define QUERY_SEND_FLAG 1
89
63
#define QUERY_REAP_FLAG 2
91
typedef boost::unordered_map<std::string, uint32_t> ErrorCodes;
92
ErrorCodes global_error_names;
95
66
OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
96
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES,
67
OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
100
70
static int record= 0, opt_sleep= -1;
101
static char *opt_pass= NULL;
102
const char *unix_sock= NULL;
103
static uint32_t opt_port= 0;
104
static uint32_t opt_max_connect_retries;
105
static bool silent= false, verbose= false;
106
static bool opt_mark_progress= false;
107
static bool parsing_disabled= false;
71
static char *opt_db= 0, *opt_pass= 0;
72
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
73
const char *opt_logdir= "";
74
const char *opt_include= 0, *opt_charsets_dir;
75
static int opt_port= 0;
76
static int opt_max_connect_retries;
77
static bool opt_compress= 0, silent= 0, verbose= 0;
78
static bool debug_info_flag= 0, debug_check_flag= 0;
79
static bool tty_password= 0;
80
static bool opt_mark_progress= 0;
81
static bool parsing_disabled= 0;
108
82
static bool display_result_vertically= false,
109
83
display_metadata= false, display_result_sorted= false;
110
static bool disable_query_log= false, disable_result_log= false;
111
static bool disable_warnings= false;
112
static bool disable_info= true;
113
static bool abort_on_error= true;
114
static bool server_initialized= false;
115
static bool is_windows= false;
116
static bool use_drizzle_protocol= false;
84
static bool disable_query_log= 0, disable_result_log= 0;
85
static bool disable_warnings= 0;
86
static bool disable_info= 1;
87
static bool abort_on_error= 1;
88
static bool server_initialized= 0;
89
static bool is_windows= 0;
90
static char **default_argv;
91
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
117
92
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
119
std::string opt_basedir,
132
static uint32_t start_lineno= 0; /* Start line of current command */
94
static uint start_lineno= 0; /* Start line of current command */
95
static uint my_end_arg= 0;
134
97
/* Number of lines of the result to include in failure report */
135
static uint32_t opt_tail_lines= 0;
98
static uint opt_tail_lines= 0;
137
100
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
138
static uint32_t delimiter_length= 1;
101
static uint delimiter_length= 1;
140
103
static char TMPDIR[FN_REFLEN];
3383
3229
command->last_argument= p;
3384
charset_info= get_charset_by_csname(charset_name, MY_CS_PRIMARY);
3230
charset_info= get_charset_by_csname(charset_name,MY_CS_PRIMARY,MYF(MY_WME));
3385
3231
if (!charset_info)
3386
3232
abort_not_supported_test("Test requires charset '%s'", charset_name);
3389
static void fill_global_error_names()
3235
static uint get_errcode_from_name(char *error_name, char *error_end)
3391
drizzle_result_st res;
3392
drizzle_return_t ret;
3394
drizzle_con_st *con= &cur_con->con;
3396
global_error_names.clear();
3398
const std::string ds_query("select error_name, error_code "
3399
"from data_dictionary.errors");
3400
if (drizzle_query_str(con, &res, ds_query.c_str(), &ret) == NULL ||
3401
ret != DRIZZLE_RETURN_OK)
3403
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3405
die("Error running query '%s': %d %s", ds_query.c_str(),
3406
drizzle_result_error_code(&res), drizzle_result_error(&res));
3407
drizzle_result_free(&res);
3411
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
3412
drizzle_con_error(con));
3415
if (drizzle_result_column_count(&res) == 0 ||
3416
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3418
drizzle_result_free(&res);
3419
die("Query '%s' didn't return a result set", ds_query.c_str());
3422
while ((row= drizzle_row_next(&res)) && row[0])
3237
/* SQL error as string */
3238
st_error *e= global_error_names;
3240
/* Loop through the array of known error names */
3241
for (; e->name; e++)
3425
Concatenate all fields in the first row with tab in between
3426
and assign that string to the $variable
3244
If we get a match, we need to check the length of the name we
3245
matched against in case it was longer than what we are checking
3246
(as in ER_WRONG_VALUE vs. ER_WRONG_VALUE_COUNT).
3428
size_t *lengths= drizzle_row_field_sizes(&res);
3429
const std::string error_name(row[0], lengths[0]);
3430
const std::string error_code(row[1], lengths[1]);
3434
global_error_names.insert(ErrorCodes::value_type(error_name,
3435
boost::lexical_cast<uint32_t>(error_code)));
3437
catch (boost::bad_lexical_cast &ex)
3439
drizzle_result_free(&res);
3440
die("Invalid error_code from Drizzle: %s", ex.what());
3445
drizzle_result_free(&res);
3448
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3450
size_t err_name_len= error_end - error_name;
3451
string error_name_s(error_name, err_name_len);
3453
ErrorCodes::iterator it= global_error_names.find(error_name_s);
3454
if (it != global_error_names.end())
3456
return (*it).second;
3459
die("Unknown SQL error name '%s'", error_name_s.c_str());
3248
if (!strncmp(error_name, e->name, (int) (error_end - error_name)) &&
3249
(uint) strlen(e->name) == (uint) (error_end - error_name))
3255
die("Unknown SQL error name '%s'", error_name);
3463
3259
static void do_get_errcodes(struct st_command *command)
3465
3261
struct st_match_err *to= saved_expected_errors.err;
3466
3262
char *p= command->first_argument;
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, drizzle.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 *, char *argument)
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;
4646
4665
Write the content of str into file
4932
4947
int flags, char *query, int query_len,
4933
4948
string *ds, string *ds_warnings)
4935
drizzle_result_st res;
4936
drizzle_return_t ret;
4937
drizzle_con_st *con= &cn->con;
4940
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;
4942
4954
if (flags & QUERY_SEND_FLAG)
4945
4957
* Send the query
4948
(void) drizzle_query(con, &res, query, query_len, &ret);
4949
if (ret != DRIZZLE_RETURN_OK)
4959
if (do_send_query(cn, query, query_len, flags))
4951
if (ret == DRIZZLE_RETURN_ERROR_CODE ||
4952
ret == DRIZZLE_RETURN_HANDSHAKE_FAILED)
4954
err= drizzle_result_error_code(&res);
4955
handle_error(command, err, drizzle_result_error(&res),
4956
drizzle_result_sqlstate(&res), ds);
4957
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4958
drizzle_result_free(&res);
4962
handle_error(command, ret, drizzle_con_error(con), "", ds);
4961
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4962
drizzle_sqlstate(drizzle), ds);
4968
4966
if (!(flags & QUERY_REAP_FLAG))
4973
* Read the result packet
4975
if (drizzle_result_read(con, &res, &ret) == NULL ||
4976
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))
4978
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4980
handle_error(command, drizzle_result_error_code(&res),
4981
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
4985
handle_error(command, ret, drizzle_con_error(con), "", ds);
4986
drizzle_result_free(&res);
4977
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4978
drizzle_sqlstate(drizzle), ds);
4992
4984
Store the result of the query if it will return any fields
4994
if (drizzle_result_column_count(&res) &&
4995
(ret= drizzle_result_buffer(&res)) != DRIZZLE_RETURN_OK)
4986
if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
4997
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4999
handle_error(command, drizzle_result_error_code(&res),
5000
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
5004
handle_error(command, ret, drizzle_con_error(con), "", ds);
5005
drizzle_result_free(&res);
4988
handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4989
drizzle_sqlstate(drizzle), ds);
5396
5394
static void mark_progress(struct st_command*, int line)
5398
5397
uint64_t timer= timer_now();
5399
5398
if (!progress_start)
5400
5399
progress_start= timer;
5401
5400
timer-= progress_start;
5404
5402
/* Milliseconds since start */
5405
buf << timer << "\t";
5403
end= int64_t2str(timer, buf, 10);
5404
ds_progress.append(buf, (int)(end-buf));
5405
ds_progress.append("\t", 1);
5407
5407
/* Parser line number */
5408
buf << line << "\t";
5408
end= int10_to_str(line, buf, 10);
5409
ds_progress.append(buf, (int)(end-buf));
5410
ds_progress.append("\t", 1);
5411
buf << cur_file->file_name << ":";
5413
ds_progress.append(cur_file->file_name);
5414
ds_progress.append(":", 1);
5413
5416
/* Line in file */
5414
buf << cur_file->lineno << endl;
5416
ds_progress.append(buf.str());
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;
5417
end= int10_to_str(cur_file->lineno, buf, 10);
5418
ds_progress.append(buf, (int)(end-buf));
5421
ds_progress.append("\n", 1);
5450
5426
int main(int argc, char **argv)
5454
5428
struct st_command *command;
5455
5429
bool q_send_flag= 0, abort_flag= 0;
5456
uint32_t command_executed= 0, last_command_executed= 0;
5457
string save_file("");
5430
uint command_executed= 0, last_command_executed= 0;
5431
char save_file[FN_REFLEN];
5458
5432
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
5438
/* Init expected errors */
5581
5439
memset(&saved_expected_errors, 0, sizeof(saved_expected_errors));
5613
5475
ds_progress.reserve(2048);
5614
5476
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 */
5478
parse_args(argc, argv);
5736
5480
server_initialized= 1;
5737
5481
if (cur_file == file_stack && cur_file->file == 0)
5739
5483
cur_file->file= stdin;
5740
cur_file->file_name= strdup("<stdin>");
5741
if (cur_file->file_name == NULL)
5742
die("Out of memory");
5484
cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
5743
5485
cur_file->lineno= 1;
5745
5487
cur_con= connections;
5746
if ((cur_con->drizzle= drizzle_create(NULL)) == NULL)
5488
if (!( drizzle_create(&cur_con->drizzle)))
5747
5489
die("Failed in drizzle_create()");
5748
if (!( drizzle_con_create(cur_con->drizzle, &cur_con->con)))
5749
die("Failed in drizzle_con_create()");
5750
drizzle_con_add_options(&cur_con->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
5491
drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5492
drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
5752
if (!(cur_con->name = strdup("default")))
5494
if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5753
5495
die("Out of memory");
5754
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5497
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5755
5498
opt_db, opt_port);
5757
fill_global_error_names();
5759
5500
/* Use all time until exit if no explicit 'start_timer' */
5760
5501
timer_start= timer_now();
5763
Initialize $drizzleclient_errno with -1, so we can
5504
Initialize $drizzle_errno with -1, so we can
5764
5505
- distinguish it from valid values ( >= 0 ) and
5765
5506
- detect if there was never a command sent to the server
5767
5508
var_set_errno(-1);
5769
/* Update $drizzleclient_get_server_version to that of current connection */
5770
var_set_drizzleclient_get_server_version(&cur_con->con);
5510
/* Update $drizzle_get_server_version to that of current connection */
5511
var_set_drizzle_get_server_version(&cur_con->drizzle);
5772
if (! opt_include.empty())
5774
open_file(opt_include.c_str());
5515
open_file(opt_include);
5777
5518
while (!read_command(&command) && !abort_flag)
6666
6368
icase - flag, if set to 1 the match is case insensitive
6668
6370
int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
6669
char *replace, char *in_string, int icase, int global)
6371
char *replace, char *in_string, int icase)
6373
string string_to_match(in_string);
6671
6374
const char *error= NULL;
6673
6376
int ovector[3];
6674
6377
pcre *re= pcre_compile(pattern,
6675
icase ? PCRE_CASELESS | PCRE_MULTILINE : PCRE_MULTILINE,
6378
icase ? PCRE_CASELESS : 0,
6676
6379
&error, &erroffset, NULL);
6677
6380
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;
6383
int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
6391
char *substring_to_replace= in_string + ovector[0];
6392
int substring_length= ovector[1] - ovector[0];
6393
*buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6394
char * new_buf = (char *)malloc(*buf_len_p+1);
6395
if (new_buf == NULL)
6401
memset(new_buf, 0, *buf_len_p+1);
6402
strncpy(new_buf, in_string, substring_to_replace-in_string);
6403
strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
6404
strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
6405
substring_to_replace + substring_length,
6408
- (substring_to_replace-in_string));
6755
6416
#ifndef WORD_BIT
6756
#define WORD_BIT (8*sizeof(uint32_t))
6417
#define WORD_BIT (8*sizeof(uint))
6759
6420
#define SET_MALLOC_HUNC 64
6760
6421
#define LAST_CHAR_CODE 259
6762
6423
typedef struct st_rep_set {
6763
uint32_t *bits; /* Pointer to used sets */
6424
uint *bits; /* Pointer to used sets */
6764
6425
short next[LAST_CHAR_CODE]; /* Pointer to next sets */
6765
uint32_t found_len; /* Best match to date */
6426
uint found_len; /* Best match to date */
6766
6427
int found_offset;
6767
uint32_t table_offset;
6768
uint32_t size_of_bits; /* For convinience */
6429
uint size_of_bits; /* For convinience */
6771
6432
typedef struct st_rep_sets {
6772
uint32_t count; /* Number of sets */
6773
uint32_t extra; /* Extra sets in buffer */
6774
uint32_t invisible; /* Sets not chown */
6775
uint32_t size_of_bits;
6433
uint count; /* Number of sets */
6434
uint extra; /* Extra sets in buffer */
6435
uint invisible; /* Sets not chown */
6776
6437
REP_SET *set,*set_buffer;
6777
uint32_t *bit_buffer;
6780
6441
typedef struct st_found_set {
6781
uint32_t table_offset;
6782
6443
int found_offset;
6785
6446
typedef struct st_follow {
6787
uint32_t table_offset;
6792
int init_sets(REP_SETS *sets,uint32_t states);
6453
int init_sets(REP_SETS *sets,uint states);
6793
6454
REP_SET *make_new_set(REP_SETS *sets);
6794
6455
void make_sets_invisible(REP_SETS *sets);
6795
6456
void free_last_set(REP_SETS *sets);
6796
6457
void free_sets(REP_SETS *sets);
6797
void internal_set_bit(REP_SET *set, uint32_t bit);
6798
void internal_clear_bit(REP_SET *set, uint32_t bit);
6458
void internal_set_bit(REP_SET *set, uint bit);
6459
void internal_clear_bit(REP_SET *set, uint bit);
6799
6460
void or_bits(REP_SET *to,REP_SET *from);
6800
6461
void copy_bits(REP_SET *to,REP_SET *from);
6801
6462
int cmp_bits(REP_SET *set1,REP_SET *set2);
6802
int get_next_bit(REP_SET *set,uint32_t lastpos);
6463
int get_next_bit(REP_SET *set,uint lastpos);
6803
6464
int find_set(REP_SETS *sets,REP_SET *find);
6804
int find_found(FOUND_SET *found_set,uint32_t table_offset,
6465
int find_found(FOUND_SET *found_set,uint table_offset,
6805
6466
int found_offset);
6806
uint32_t start_at_word(char * pos);
6807
uint32_t end_of_word(char * pos);
6809
static uint32_t found_sets=0;
6812
static uint32_t replace_len(char * str)
6467
uint start_at_word(char * pos);
6468
uint end_of_word(char * pos);
6470
static uint found_sets=0;
6473
static uint replace_len(char * str)
6817
6478
if (str[0] == '\\' && str[1])