Merge lp:~vjsamuel/drizzle/refactor-drizzletest into lp:~drizzle-trunk/drizzle/development
- refactor-drizzletest
- Merge into 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 |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brian Aker | Pending | ||
Drizzle Developers | Pending | ||
Review via email: mp+27680@code.launchpad.net |
Commit message
Description of the change
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
1 | === modified file 'client/drizzle.cc' | |||
2 | --- client/drizzle.cc 2010-06-09 21:36:07 +0000 | |||
3 | +++ client/drizzle.cc 2010-06-16 07:57:30 +0000 | |||
4 | @@ -1531,7 +1531,7 @@ | |||
5 | 1531 | po::variables_map vm; | 1531 | po::variables_map vm; |
6 | 1532 | 1532 | ||
7 | 1533 | po::positional_options_description p; | 1533 | po::positional_options_description p; |
9 | 1534 | p.add("database", -1); | 1534 | p.add("database", 1); |
10 | 1535 | 1535 | ||
11 | 1536 | po::store(po::command_line_parser(argc, argv).options(long_options). | 1536 | po::store(po::command_line_parser(argc, argv).options(long_options). |
12 | 1537 | positional(p).extra_parser(parse_password_arg).run(), vm); | 1537 | positional(p).extra_parser(parse_password_arg).run(), vm); |
13 | 1538 | 1538 | ||
14 | === modified file 'client/drizzletest.cc' | |||
15 | --- client/drizzletest.cc 2010-06-03 07:59:07 +0000 | |||
16 | +++ client/drizzletest.cc 2010-06-16 07:57:30 +0000 | |||
17 | @@ -44,6 +44,7 @@ | |||
18 | 44 | #include <map> | 44 | #include <map> |
19 | 45 | #include <string> | 45 | #include <string> |
20 | 46 | #include <sstream> | 46 | #include <sstream> |
21 | 47 | #include <fstream> | ||
22 | 47 | #include <iostream> | 48 | #include <iostream> |
23 | 48 | #include <vector> | 49 | #include <vector> |
24 | 49 | #include <algorithm> | 50 | #include <algorithm> |
25 | @@ -54,6 +55,7 @@ | |||
26 | 54 | #include <sys/stat.h> | 55 | #include <sys/stat.h> |
27 | 55 | #include <sys/types.h> | 56 | #include <sys/types.h> |
28 | 56 | #include <fcntl.h> | 57 | #include <fcntl.h> |
29 | 58 | #include <boost/program_options.hpp> | ||
30 | 57 | 59 | ||
31 | 58 | #include PCRE_HEADER | 60 | #include PCRE_HEADER |
32 | 59 | 61 | ||
33 | @@ -66,11 +68,12 @@ | |||
34 | 66 | #include "drizzled/gettext.h" | 68 | #include "drizzled/gettext.h" |
35 | 67 | #include "drizzled/drizzle_time.h" | 69 | #include "drizzled/drizzle_time.h" |
36 | 68 | #include "drizzled/charset.h" | 70 | #include "drizzled/charset.h" |
37 | 71 | #include <drizzled/configmake.h> | ||
38 | 69 | 72 | ||
39 | 70 | #ifndef DRIZZLE_RETURN_SERVER_GONE | 73 | #ifndef DRIZZLE_RETURN_SERVER_GONE |
40 | 71 | #define DRIZZLE_RETURN_HANDSHAKE_FAILED DRIZZLE_RETURN_ERROR_CODE | 74 | #define DRIZZLE_RETURN_HANDSHAKE_FAILED DRIZZLE_RETURN_ERROR_CODE |
41 | 72 | #endif | 75 | #endif |
43 | 73 | 76 | namespace po= boost::program_options; | |
44 | 74 | using namespace std; | 77 | using namespace std; |
45 | 75 | using namespace drizzled; | 78 | using namespace drizzled; |
46 | 76 | 79 | ||
47 | @@ -95,14 +98,10 @@ | |||
48 | 95 | }; | 98 | }; |
49 | 96 | 99 | ||
50 | 97 | static int record= 0, opt_sleep= -1; | 100 | static int record= 0, opt_sleep= -1; |
57 | 98 | static char *opt_db= NULL, *opt_pass= NULL; | 101 | static char *opt_pass= NULL; |
58 | 99 | const char *opt_user= NULL, *opt_host= NULL, *unix_sock= NULL, | 102 | const char *unix_sock= NULL; |
53 | 100 | *opt_basedir= "./"; | ||
54 | 101 | const char *opt_logdir= ""; | ||
55 | 102 | const char *opt_include= NULL, *opt_charsets_dir; | ||
56 | 103 | const char *opt_testdir= NULL; | ||
59 | 104 | static uint32_t opt_port= 0; | 103 | static uint32_t opt_port= 0; |
61 | 105 | static int opt_max_connect_retries; | 104 | static uint32_t opt_max_connect_retries; |
62 | 106 | static bool silent= false, verbose= false; | 105 | static bool silent= false, verbose= false; |
63 | 107 | static bool tty_password= false; | 106 | static bool tty_password= false; |
64 | 108 | static bool opt_mark_progress= false; | 107 | static bool opt_mark_progress= false; |
65 | @@ -116,10 +115,21 @@ | |||
66 | 116 | static bool server_initialized= false; | 115 | static bool server_initialized= false; |
67 | 117 | static bool is_windows= false; | 116 | static bool is_windows= false; |
68 | 118 | static bool opt_mysql= false; | 117 | static bool opt_mysql= false; |
71 | 119 | static char **default_argv; | 118 | const string PASSWORD_SENTINEL("\0\0\0\0\0", 5); |
70 | 120 | static const char *load_default_groups[]= { "drizzletest", "client", 0 }; | ||
72 | 121 | static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer; | 119 | static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer; |
73 | 122 | 120 | ||
74 | 121 | std::string opt_basedir, | ||
75 | 122 | opt_charsets_dir, | ||
76 | 123 | opt_db, | ||
77 | 124 | opt_host, | ||
78 | 125 | opt_include, | ||
79 | 126 | opt_testdir, | ||
80 | 127 | opt_logdir, | ||
81 | 128 | password, | ||
82 | 129 | opt_password, | ||
83 | 130 | result_file_name, | ||
84 | 131 | opt_user; | ||
85 | 132 | |||
86 | 123 | static uint32_t start_lineno= 0; /* Start line of current command */ | 133 | static uint32_t start_lineno= 0; /* Start line of current command */ |
87 | 124 | 134 | ||
88 | 125 | /* Number of lines of the result to include in failure report */ | 135 | /* Number of lines of the result to include in failure report */ |
89 | @@ -189,7 +199,6 @@ | |||
90 | 189 | master_pos_st master_pos; | 199 | master_pos_st master_pos; |
91 | 190 | 200 | ||
92 | 191 | /* if set, all results are concated and compared against this file */ | 201 | /* if set, all results are concated and compared against this file */ |
93 | 192 | const char *result_file_name= NULL; | ||
94 | 193 | 202 | ||
95 | 194 | typedef struct st_var | 203 | typedef struct st_var |
96 | 195 | { | 204 | { |
97 | @@ -920,7 +929,6 @@ | |||
98 | 920 | 929 | ||
99 | 921 | free_all_replace(); | 930 | free_all_replace(); |
100 | 922 | free(opt_pass); | 931 | free(opt_pass); |
101 | 923 | internal::free_defaults(default_argv); | ||
102 | 924 | 932 | ||
103 | 925 | return; | 933 | return; |
104 | 926 | } | 934 | } |
105 | @@ -1002,11 +1010,11 @@ | |||
106 | 1002 | } | 1010 | } |
107 | 1003 | 1011 | ||
108 | 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 */ |
110 | 1005 | if (result_file_name && ds_res.length()) | 1013 | if (! result_file_name.empty() && ds_res.length()) |
111 | 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()); |
112 | 1007 | 1015 | ||
113 | 1008 | /* Dump warning messages */ | 1016 | /* Dump warning messages */ |
115 | 1009 | if (result_file_name && ds_warning_messages.length()) | 1017 | if (! result_file_name.empty() && ds_warning_messages.length()) |
116 | 1010 | dump_warning_messages(); | 1018 | dump_warning_messages(); |
117 | 1011 | 1019 | ||
118 | 1012 | /* | 1020 | /* |
119 | @@ -1354,7 +1362,7 @@ | |||
120 | 1354 | if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0) | 1362 | if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0) |
121 | 1355 | { | 1363 | { |
122 | 1356 | internal::my_close(fd, MYF(0)); | 1364 | internal::my_close(fd, MYF(0)); |
124 | 1357 | if (opt_testdir != NULL) | 1365 | if (! opt_testdir.empty()) |
125 | 1358 | { | 1366 | { |
126 | 1359 | tmpfile= opt_testdir; | 1367 | tmpfile= opt_testdir; |
127 | 1360 | if (tmpfile[tmpfile.length()] != '/') | 1368 | if (tmpfile[tmpfile.length()] != '/') |
128 | @@ -1494,12 +1502,12 @@ | |||
129 | 1494 | const char* mess= "Result content mismatch\n"; | 1502 | const char* mess= "Result content mismatch\n"; |
130 | 1495 | 1503 | ||
131 | 1496 | 1504 | ||
138 | 1497 | assert(result_file_name); | 1505 | assert(result_file_name.c_str()); |
139 | 1498 | 1506 | ||
140 | 1499 | if (access(result_file_name, F_OK) != 0) | 1507 | if (access(result_file_name.c_str(), F_OK) != 0) |
141 | 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()); |
142 | 1501 | 1509 | ||
143 | 1502 | switch (string_cmp(ds, result_file_name)) { | 1510 | switch (string_cmp(ds, result_file_name.c_str())) { |
144 | 1503 | case RESULT_OK: | 1511 | case RESULT_OK: |
145 | 1504 | break; /* ok */ | 1512 | break; /* ok */ |
146 | 1505 | case RESULT_LENGTH_MISMATCH: | 1513 | case RESULT_LENGTH_MISMATCH: |
147 | @@ -1513,25 +1521,25 @@ | |||
148 | 1513 | */ | 1521 | */ |
149 | 1514 | char reject_file[FN_REFLEN]; | 1522 | char reject_file[FN_REFLEN]; |
150 | 1515 | size_t reject_length; | 1523 | size_t reject_length; |
152 | 1516 | internal::dirname_part(reject_file, result_file_name, &reject_length); | 1524 | internal::dirname_part(reject_file, result_file_name.c_str(), &reject_length); |
153 | 1517 | 1525 | ||
154 | 1518 | if (access(reject_file, W_OK) == 0) | 1526 | if (access(reject_file, W_OK) == 0) |
155 | 1519 | { | 1527 | { |
156 | 1520 | /* Result file directory is writable, save reject file there */ | 1528 | /* Result file directory is writable, save reject file there */ |
158 | 1521 | internal::fn_format(reject_file, result_file_name, NULL, | 1529 | internal::fn_format(reject_file, result_file_name.c_str(), NULL, |
159 | 1522 | ".reject", MY_REPLACE_EXT); | 1530 | ".reject", MY_REPLACE_EXT); |
160 | 1523 | } | 1531 | } |
161 | 1524 | else | 1532 | else |
162 | 1525 | { | 1533 | { |
163 | 1526 | /* Put reject file in opt_logdir */ | 1534 | /* Put reject file in opt_logdir */ |
165 | 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(), |
166 | 1528 | ".reject", MY_REPLACE_DIR | MY_REPLACE_EXT); | 1536 | ".reject", MY_REPLACE_DIR | MY_REPLACE_EXT); |
167 | 1529 | } | 1537 | } |
168 | 1530 | str_to_file(reject_file, ds->c_str(), ds->length()); | 1538 | str_to_file(reject_file, ds->c_str(), ds->length()); |
169 | 1531 | 1539 | ||
170 | 1532 | ds->erase(); /* Don't create a .log file */ | 1540 | ds->erase(); /* Don't create a .log file */ |
171 | 1533 | 1541 | ||
173 | 1534 | show_diff(NULL, result_file_name, reject_file); | 1542 | show_diff(NULL, result_file_name.c_str(), reject_file); |
174 | 1535 | die("%s",mess); | 1543 | die("%s",mess); |
175 | 1536 | break; | 1544 | break; |
176 | 1537 | } | 1545 | } |
177 | @@ -2147,7 +2155,7 @@ | |||
178 | 2147 | 2155 | ||
179 | 2148 | if (!internal::test_if_hard_path(name)) | 2156 | if (!internal::test_if_hard_path(name)) |
180 | 2149 | { | 2157 | { |
182 | 2150 | snprintf(buff, sizeof(buff), "%s%s",opt_basedir,name); | 2158 | snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),name); |
183 | 2151 | name=buff; | 2159 | name=buff; |
184 | 2152 | } | 2160 | } |
185 | 2153 | internal::fn_format(buff, name, "", "", MY_UNPACK_FILENAME); | 2161 | internal::fn_format(buff, name, "", "", MY_UNPACK_FILENAME); |
186 | @@ -2201,7 +2209,7 @@ | |||
187 | 2201 | ; /* Do nothing */ | 2209 | ; /* Do nothing */ |
188 | 2202 | else | 2210 | else |
189 | 2203 | { | 2211 | { |
191 | 2204 | if (opt_testdir != NULL) | 2212 | if (! opt_testdir.empty()) |
192 | 2205 | { | 2213 | { |
193 | 2206 | string testdir(opt_testdir); | 2214 | string testdir(opt_testdir); |
194 | 2207 | if (testdir[testdir.length()] != '/') | 2215 | if (testdir[testdir.length()] != '/') |
195 | @@ -3348,7 +3356,7 @@ | |||
196 | 3348 | if (*p) | 3356 | if (*p) |
197 | 3349 | *p++= 0; | 3357 | *p++= 0; |
198 | 3350 | command->last_argument= p; | 3358 | command->last_argument= p; |
200 | 3351 | if (opt_testdir != NULL) | 3359 | if (! opt_testdir.empty()) |
201 | 3352 | { | 3360 | { |
202 | 3353 | dest= opt_testdir; | 3361 | dest= opt_testdir; |
203 | 3354 | if (dest[dest.length()] != '/') | 3362 | if (dest[dest.length()] != '/') |
204 | @@ -3685,16 +3693,16 @@ | |||
205 | 3685 | */ | 3693 | */ |
206 | 3686 | 3694 | ||
207 | 3687 | static void safe_connect(drizzle_con_st *con, const char *name, | 3695 | static void safe_connect(drizzle_con_st *con, const char *name, |
210 | 3688 | const char *host, const char *user, const char *pass, | 3696 | const string host, const string user, const char *pass, |
211 | 3689 | const char *db, int port) | 3697 | const string db, uint32_t port) |
212 | 3690 | { | 3698 | { |
214 | 3691 | int failed_attempts= 0; | 3699 | uint32_t failed_attempts= 0; |
215 | 3692 | static uint32_t connection_retry_sleep= 100000; /* Microseconds */ | 3700 | static uint32_t connection_retry_sleep= 100000; /* Microseconds */ |
216 | 3693 | drizzle_return_t ret; | 3701 | drizzle_return_t ret; |
217 | 3694 | 3702 | ||
221 | 3695 | drizzle_con_set_tcp(con, host, port); | 3703 | drizzle_con_set_tcp(con, host.c_str(), port); |
222 | 3696 | drizzle_con_set_auth(con, user, pass); | 3704 | drizzle_con_set_auth(con, user.c_str(), pass); |
223 | 3697 | drizzle_con_set_db(con, db); | 3705 | drizzle_con_set_db(con, db.c_str()); |
224 | 3698 | while((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK) | 3706 | while((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK) |
225 | 3699 | { | 3707 | { |
226 | 3700 | /* | 3708 | /* |
227 | @@ -3836,7 +3844,7 @@ | |||
228 | 3836 | 3844 | ||
229 | 3837 | static void do_connect(struct st_command *command) | 3845 | static void do_connect(struct st_command *command) |
230 | 3838 | { | 3846 | { |
232 | 3839 | int con_port= opt_port; | 3847 | uint32_t con_port= opt_port; |
233 | 3840 | const char *con_options; | 3848 | const char *con_options; |
234 | 3841 | bool con_ssl= 0, con_compress= 0; | 3849 | bool con_ssl= 0, con_compress= 0; |
235 | 3842 | struct st_connection* con_slot; | 3850 | struct st_connection* con_slot; |
236 | @@ -4496,8 +4504,6 @@ | |||
237 | 4496 | return; | 4504 | return; |
238 | 4497 | } | 4505 | } |
239 | 4498 | 4506 | ||
240 | 4499 | |||
241 | 4500 | |||
242 | 4501 | /* | 4507 | /* |
243 | 4502 | Create a command from a set of lines | 4508 | Create a command from a set of lines |
244 | 4503 | 4509 | ||
245 | @@ -4577,217 +4583,6 @@ | |||
246 | 4577 | return(0); | 4583 | return(0); |
247 | 4578 | } | 4584 | } |
248 | 4579 | 4585 | ||
249 | 4580 | |||
250 | 4581 | static struct option my_long_options[] = | ||
251 | 4582 | { | ||
252 | 4583 | {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, | ||
253 | 4584 | 0, 0, 0, 0, 0, 0}, | ||
254 | 4585 | {"basedir", 'b', "Basedir for tests.", (char**) &opt_basedir, | ||
255 | 4586 | (char**) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
256 | 4587 | {"character-sets-dir", OPT_CHARSETS_DIR, | ||
257 | 4588 | "Directory where character sets are.", (char**) &opt_charsets_dir, | ||
258 | 4589 | (char**) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
259 | 4590 | {"database", 'D', "Database to use.", (char**) &opt_db, (char**) &opt_db, 0, | ||
260 | 4591 | GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
261 | 4592 | {"host", 'h', "Connect to host.", (char**) &opt_host, (char**) &opt_host, 0, | ||
262 | 4593 | GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
263 | 4594 | {"include", 'i', "Include SQL before each test case.", (char**) &opt_include, | ||
264 | 4595 | (char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
265 | 4596 | {"testdir", OPT_TESTDIR, "Path to use to search for test files", | ||
266 | 4597 | (char**) &opt_testdir, | ||
267 | 4598 | (char**) &opt_testdir, 0,GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
268 | 4599 | {"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir, | ||
269 | 4600 | (char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
270 | 4601 | {"mark-progress", OPT_MARK_PROGRESS, | ||
271 | 4602 | "Write linenumber and elapsed time to <testname>.progress ", | ||
272 | 4603 | (char**) &opt_mark_progress, (char**) &opt_mark_progress, 0, | ||
273 | 4604 | GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
274 | 4605 | {"max-connect-retries", OPT_MAX_CONNECT_RETRIES, | ||
275 | 4606 | "Max number of connection attempts when connecting to server", | ||
276 | 4607 | (char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0, | ||
277 | 4608 | GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0}, | ||
278 | 4609 | {"mysql", 'm', N_("Use MySQL Protocol."), | ||
279 | 4610 | (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0, | ||
280 | 4611 | 0, 0, 0}, | ||
281 | 4612 | {"password", 'P', "Password to use when connecting to server.", | ||
282 | 4613 | 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, | ||
283 | 4614 | {"port", 'p', "Port number to use for connection or 0 for default to, in " | ||
284 | 4615 | "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, " | ||
285 | 4616 | "built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").", | ||
286 | 4617 | 0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
287 | 4618 | {"quiet", 's', "Suppress all normal output.", (char**) &silent, | ||
288 | 4619 | (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
289 | 4620 | {"record", 'r', "Record output of test_file into result file.", | ||
290 | 4621 | 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
291 | 4622 | {"result-file", 'R', "Read/Store result from/in this file.", | ||
292 | 4623 | (char**) &result_file_name, (char**) &result_file_name, 0, | ||
293 | 4624 | GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
294 | 4625 | {"silent", 's', "Suppress all normal output. Synonym for --quiet.", | ||
295 | 4626 | (char**) &silent, (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
296 | 4627 | {"sleep", 'T', "Sleep always this many seconds on sleep commands.", | ||
297 | 4628 | (char**) &opt_sleep, (char**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0, | ||
298 | 4629 | 0, 0, 0}, | ||
299 | 4630 | {"tail-lines", OPT_TAIL_LINES, | ||
300 | 4631 | "Number of lines of the resul to include in a failure report", | ||
301 | 4632 | (char**) &opt_tail_lines, (char**) &opt_tail_lines, 0, | ||
302 | 4633 | GET_INT, REQUIRED_ARG, 0, 0, 10000, 0, 0, 0}, | ||
303 | 4634 | {"test-file", 'x', "Read test from/in this file (default stdin).", | ||
304 | 4635 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
305 | 4636 | {"timer-file", 'm', "File where the timing in micro seconds is stored.", | ||
306 | 4637 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
307 | 4638 | {"tmpdir", 't', "Temporary directory where sockets are put.", | ||
308 | 4639 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
309 | 4640 | {"user", 'u', "User for login.", (char**) &opt_user, (char**) &opt_user, 0, | ||
310 | 4641 | GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, | ||
311 | 4642 | {"verbose", 'v', "Write more.", (char**) &verbose, (char**) &verbose, 0, | ||
312 | 4643 | GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
313 | 4644 | {"version", 'V', "Output version information and exit.", | ||
314 | 4645 | 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, | ||
315 | 4646 | { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} | ||
316 | 4647 | }; | ||
317 | 4648 | |||
318 | 4649 | |||
319 | 4650 | static void print_version(void) | ||
320 | 4651 | { | ||
321 | 4652 | printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION, | ||
322 | 4653 | drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU); | ||
323 | 4654 | } | ||
324 | 4655 | |||
325 | 4656 | static void usage(void) | ||
326 | 4657 | { | ||
327 | 4658 | print_version(); | ||
328 | 4659 | printf("MySQL AB, by Sasha, Matt, Monty & Jani\n"); | ||
329 | 4660 | printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n"); | ||
330 | 4661 | printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); | ||
331 | 4662 | printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n"); | ||
332 | 4663 | printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname); | ||
333 | 4664 | my_print_help(my_long_options); | ||
334 | 4665 | printf(" --no-defaults Don't read default options from any options file.\n"); | ||
335 | 4666 | my_print_variables(my_long_options); | ||
336 | 4667 | } | ||
337 | 4668 | |||
338 | 4669 | int get_one_option(int optid, const struct option *, char *argument) | ||
339 | 4670 | { | ||
340 | 4671 | char *endchar= NULL; | ||
341 | 4672 | uint64_t temp_drizzle_port= 0; | ||
342 | 4673 | |||
343 | 4674 | switch(optid) { | ||
344 | 4675 | case 'r': | ||
345 | 4676 | record = 1; | ||
346 | 4677 | break; | ||
347 | 4678 | case 'x': | ||
348 | 4679 | { | ||
349 | 4680 | char buff[FN_REFLEN]; | ||
350 | 4681 | if (!internal::test_if_hard_path(argument)) | ||
351 | 4682 | { | ||
352 | 4683 | snprintf(buff, sizeof(buff), "%s%s",opt_basedir,argument); | ||
353 | 4684 | argument= buff; | ||
354 | 4685 | } | ||
355 | 4686 | internal::fn_format(buff, argument, "", "", MY_UNPACK_FILENAME); | ||
356 | 4687 | assert(cur_file == file_stack && cur_file->file == 0); | ||
357 | 4688 | if (!(cur_file->file= fopen(buff, "r"))) | ||
358 | 4689 | { | ||
359 | 4690 | fprintf(stderr, _("Could not open '%s' for reading: errno = %d"), buff, errno); | ||
360 | 4691 | return EXIT_ARGUMENT_INVALID; | ||
361 | 4692 | } | ||
362 | 4693 | if (!(cur_file->file_name= strdup(buff))) | ||
363 | 4694 | { | ||
364 | 4695 | fprintf(stderr, _("Out of memory")); | ||
365 | 4696 | return EXIT_OUT_OF_MEMORY; | ||
366 | 4697 | } | ||
367 | 4698 | cur_file->lineno= 1; | ||
368 | 4699 | break; | ||
369 | 4700 | } | ||
370 | 4701 | case 'm': | ||
371 | 4702 | { | ||
372 | 4703 | static char buff[FN_REFLEN]; | ||
373 | 4704 | if (!internal::test_if_hard_path(argument)) | ||
374 | 4705 | { | ||
375 | 4706 | snprintf(buff, sizeof(buff), "%s%s",opt_basedir,argument); | ||
376 | 4707 | argument= buff; | ||
377 | 4708 | } | ||
378 | 4709 | internal::fn_format(buff, argument, "", "", MY_UNPACK_FILENAME); | ||
379 | 4710 | timer_file= buff; | ||
380 | 4711 | unlink(timer_file); /* Ignore error, may not exist */ | ||
381 | 4712 | break; | ||
382 | 4713 | } | ||
383 | 4714 | case 'p': | ||
384 | 4715 | temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10); | ||
385 | 4716 | /* if there is an alpha character this is not a valid port */ | ||
386 | 4717 | if (strlen(endchar) != 0) | ||
387 | 4718 | { | ||
388 | 4719 | fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n")); | ||
389 | 4720 | return EXIT_ARGUMENT_INVALID; | ||
390 | 4721 | } | ||
391 | 4722 | /* If the port number is > 65535 it is not a valid port | ||
392 | 4723 | This also helps with potential data loss casting unsigned long to a | ||
393 | 4724 | uint32_t. */ | ||
394 | 4725 | if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535)) | ||
395 | 4726 | { | ||
396 | 4727 | fprintf(stderr, _("Value supplied for port is not valid.\n")); | ||
397 | 4728 | return EXIT_ARGUMENT_INVALID; | ||
398 | 4729 | } | ||
399 | 4730 | else | ||
400 | 4731 | { | ||
401 | 4732 | opt_port= (uint32_t) temp_drizzle_port; | ||
402 | 4733 | } | ||
403 | 4734 | break; | ||
404 | 4735 | case 'P': | ||
405 | 4736 | if (argument) | ||
406 | 4737 | { | ||
407 | 4738 | if (opt_pass) | ||
408 | 4739 | free(opt_pass); | ||
409 | 4740 | opt_pass = strdup(argument); | ||
410 | 4741 | if (opt_pass == NULL) | ||
411 | 4742 | { | ||
412 | 4743 | fprintf(stderr, _("Out of memory")); | ||
413 | 4744 | return EXIT_OUT_OF_MEMORY; | ||
414 | 4745 | } | ||
415 | 4746 | while (*argument) | ||
416 | 4747 | { | ||
417 | 4748 | /* Overwriting password with 'x' */ | ||
418 | 4749 | *argument++= 'x'; | ||
419 | 4750 | } | ||
420 | 4751 | tty_password= 0; | ||
421 | 4752 | } | ||
422 | 4753 | else | ||
423 | 4754 | tty_password= 1; | ||
424 | 4755 | break; | ||
425 | 4756 | case 't': | ||
426 | 4757 | strncpy(TMPDIR, argument, sizeof(TMPDIR)); | ||
427 | 4758 | break; | ||
428 | 4759 | case 'V': | ||
429 | 4760 | print_version(); | ||
430 | 4761 | exit(0); | ||
431 | 4762 | case '?': | ||
432 | 4763 | usage(); | ||
433 | 4764 | exit(0); | ||
434 | 4765 | } | ||
435 | 4766 | return 0; | ||
436 | 4767 | } | ||
437 | 4768 | |||
438 | 4769 | |||
439 | 4770 | static int parse_args(int argc, char **argv) | ||
440 | 4771 | { | ||
441 | 4772 | internal::load_defaults("drizzle",load_default_groups,&argc,&argv); | ||
442 | 4773 | default_argv= argv; | ||
443 | 4774 | |||
444 | 4775 | if ((handle_options(&argc, &argv, my_long_options, get_one_option))) | ||
445 | 4776 | exit(1); | ||
446 | 4777 | |||
447 | 4778 | if (argc > 1) | ||
448 | 4779 | { | ||
449 | 4780 | usage(); | ||
450 | 4781 | exit(1); | ||
451 | 4782 | } | ||
452 | 4783 | if (argc == 1) | ||
453 | 4784 | opt_db= *argv; | ||
454 | 4785 | if (tty_password) | ||
455 | 4786 | opt_pass= client_get_tty_password(NULL); /* purify tested */ | ||
456 | 4787 | |||
457 | 4788 | return 0; | ||
458 | 4789 | } | ||
459 | 4790 | |||
460 | 4791 | /* | 4586 | /* |
461 | 4792 | Write the content of str into file | 4587 | Write the content of str into file |
462 | 4793 | 4588 | ||
463 | @@ -4806,7 +4601,7 @@ | |||
464 | 4806 | int flags= O_WRONLY | O_CREAT; | 4601 | int flags= O_WRONLY | O_CREAT; |
465 | 4807 | if (!internal::test_if_hard_path(fname)) | 4602 | if (!internal::test_if_hard_path(fname)) |
466 | 4808 | { | 4603 | { |
468 | 4809 | snprintf(buff, sizeof(buff), "%s%s",opt_basedir,fname); | 4604 | snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),fname); |
469 | 4810 | fname= buff; | 4605 | fname= buff; |
470 | 4811 | } | 4606 | } |
471 | 4812 | internal::fn_format(buff, fname, "", "", MY_UNPACK_FILENAME); | 4607 | internal::fn_format(buff, fname, "", "", MY_UNPACK_FILENAME); |
472 | @@ -4842,8 +4637,8 @@ | |||
473 | 4842 | void dump_result_to_log_file(const char *buf, int size) | 4637 | void dump_result_to_log_file(const char *buf, int size) |
474 | 4843 | { | 4638 | { |
475 | 4844 | char log_file[FN_REFLEN]; | 4639 | char log_file[FN_REFLEN]; |
478 | 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", |
479 | 4846 | *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT : | 4641 | ! opt_logdir.empty() ? MY_REPLACE_DIR | MY_REPLACE_EXT : |
480 | 4847 | MY_REPLACE_EXT), | 4642 | MY_REPLACE_EXT), |
481 | 4848 | buf, size); | 4643 | buf, size); |
482 | 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", |
483 | @@ -4853,9 +4648,9 @@ | |||
484 | 4853 | void dump_progress(void) | 4648 | void dump_progress(void) |
485 | 4854 | { | 4649 | { |
486 | 4855 | char progress_file[FN_REFLEN]; | 4650 | char progress_file[FN_REFLEN]; |
490 | 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(), |
491 | 4857 | opt_logdir, ".progress", | 4652 | opt_logdir.c_str(), ".progress", |
492 | 4858 | *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT : | 4653 | ! opt_logdir.empty() ? MY_REPLACE_DIR | MY_REPLACE_EXT : |
493 | 4859 | MY_REPLACE_EXT), | 4654 | MY_REPLACE_EXT), |
494 | 4860 | ds_progress.c_str(), ds_progress.length()); | 4655 | ds_progress.c_str(), ds_progress.length()); |
495 | 4861 | } | 4656 | } |
496 | @@ -4864,8 +4659,8 @@ | |||
497 | 4864 | { | 4659 | { |
498 | 4865 | char warn_file[FN_REFLEN]; | 4660 | char warn_file[FN_REFLEN]; |
499 | 4866 | 4661 | ||
502 | 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", |
503 | 4868 | *opt_logdir ? MY_REPLACE_DIR | MY_REPLACE_EXT : | 4663 | ! opt_logdir.empty() ? MY_REPLACE_DIR | MY_REPLACE_EXT : |
504 | 4869 | MY_REPLACE_EXT), | 4664 | MY_REPLACE_EXT), |
505 | 4870 | ds_warning_messages.c_str(), ds_warning_messages.length()); | 4665 | ds_warning_messages.c_str(), ds_warning_messages.length()); |
506 | 4871 | } | 4666 | } |
507 | @@ -5563,18 +5358,185 @@ | |||
508 | 5563 | 5358 | ||
509 | 5564 | } | 5359 | } |
510 | 5565 | 5360 | ||
511 | 5361 | static void check_retries(uint32_t in_opt_max_connect_retries) | ||
512 | 5362 | { | ||
513 | 5363 | if (in_opt_max_connect_retries > 10000 || opt_max_connect_retries<1) | ||
514 | 5364 | { | ||
515 | 5365 | cout<<N_("Error: Invalid Value for opt_max_connect_retries"); | ||
516 | 5366 | exit(-1); | ||
517 | 5367 | } | ||
518 | 5368 | opt_max_connect_retries= in_opt_max_connect_retries; | ||
519 | 5369 | } | ||
520 | 5370 | |||
521 | 5371 | static void check_tail_lines(uint32_t in_opt_tail_lines) | ||
522 | 5372 | { | ||
523 | 5373 | if (in_opt_tail_lines > 10000) | ||
524 | 5374 | { | ||
525 | 5375 | cout<<N_("Error: Invalid Value for opt_tail_lines"); | ||
526 | 5376 | exit(-1); | ||
527 | 5377 | } | ||
528 | 5378 | opt_tail_lines= in_opt_tail_lines; | ||
529 | 5379 | } | ||
530 | 5380 | |||
531 | 5381 | static void check_sleep(int32_t in_opt_sleep) | ||
532 | 5382 | { | ||
533 | 5383 | if (in_opt_sleep < -1) | ||
534 | 5384 | { | ||
535 | 5385 | cout<<N_("Error: Invalid Value for opt_sleep"); | ||
536 | 5386 | exit(-1); | ||
537 | 5387 | } | ||
538 | 5388 | opt_sleep= in_opt_sleep; | ||
539 | 5389 | } | ||
540 | 5390 | |||
541 | 5391 | static pair<string, string> parse_password_arg(std::string s) | ||
542 | 5392 | { | ||
543 | 5393 | if (s.find("--password") == 0) | ||
544 | 5394 | { | ||
545 | 5395 | if (s == "--password") | ||
546 | 5396 | { | ||
547 | 5397 | tty_password= true; | ||
548 | 5398 | //check if no argument is passed. | ||
549 | 5399 | return make_pair("password", PASSWORD_SENTINEL); | ||
550 | 5400 | } | ||
551 | 5401 | |||
552 | 5402 | if (s.substr(10,3) == "=\"\"" || s.substr(10,3) == "=''") | ||
553 | 5403 | { | ||
554 | 5404 | // Check if --password="" or --password='' | ||
555 | 5405 | return make_pair("password", PASSWORD_SENTINEL); | ||
556 | 5406 | } | ||
557 | 5407 | |||
558 | 5408 | if(s.substr(10) == "=" && s.length() == 11) | ||
559 | 5409 | { | ||
560 | 5410 | // check if --password= and return a default value | ||
561 | 5411 | return make_pair("password", PASSWORD_SENTINEL); | ||
562 | 5412 | } | ||
563 | 5413 | |||
564 | 5414 | if(s.length()>12 && (s[10] == '"' || s[10] == '\'')) | ||
565 | 5415 | { | ||
566 | 5416 | // check if --password has quotes, remove quotes and return the value | ||
567 | 5417 | return make_pair("password", s.substr(11,s.length()-1)); | ||
568 | 5418 | } | ||
569 | 5419 | |||
570 | 5420 | // if all above are false, it implies that --password=value, return value. | ||
571 | 5421 | return make_pair("password", s.substr(11)); | ||
572 | 5422 | } | ||
573 | 5423 | |||
574 | 5424 | else | ||
575 | 5425 | { | ||
576 | 5426 | return make_pair(string(""), string("")); | ||
577 | 5427 | } | ||
578 | 5428 | } | ||
579 | 5566 | 5429 | ||
580 | 5567 | int main(int argc, char **argv) | 5430 | int main(int argc, char **argv) |
581 | 5568 | { | 5431 | { |
582 | 5432 | try | ||
583 | 5433 | { | ||
584 | 5569 | struct st_command *command; | 5434 | struct st_command *command; |
585 | 5570 | bool q_send_flag= 0, abort_flag= 0; | 5435 | bool q_send_flag= 0, abort_flag= 0; |
586 | 5571 | uint32_t command_executed= 0, last_command_executed= 0; | 5436 | uint32_t command_executed= 0, last_command_executed= 0; |
587 | 5572 | string save_file(""); | 5437 | string save_file(""); |
588 | 5573 | struct stat res_info; | 5438 | struct stat res_info; |
589 | 5574 | MY_INIT(argv[0]); | ||
590 | 5575 | 5439 | ||
591 | 5576 | TMPDIR[0]= 0; | 5440 | TMPDIR[0]= 0; |
592 | 5577 | 5441 | ||
593 | 5442 | po::options_description commandline_options("Options used only in command line"); | ||
594 | 5443 | commandline_options.add_options() | ||
595 | 5444 | ("help,?", "Display this help and exit.") | ||
596 | 5445 | ("mark-progress", po::value<bool>(&opt_mark_progress)->default_value(false)->zero_tokens(), | ||
597 | 5446 | "Write linenumber and elapsed time to <testname>.progress ") | ||
598 | 5447 | ("sleep,T", po::value<int32_t>(&opt_sleep)->default_value(-1)->notifier(&check_sleep), | ||
599 | 5448 | "Sleep always this many seconds on sleep commands.") | ||
600 | 5449 | ("test-file,x", po::value<string>(), | ||
601 | 5450 | "Read test from/in this file (default stdin).") | ||
602 | 5451 | ("timer-file,f", po::value<string>(), | ||
603 | 5452 | "File where the timing in micro seconds is stored.") | ||
604 | 5453 | ("tmpdir,t", po::value<string>(), | ||
605 | 5454 | "Temporary directory where sockets are put.") | ||
606 | 5455 | ("verbose,v", po::value<bool>(&verbose)->default_value(false), | ||
607 | 5456 | "Write more.") | ||
608 | 5457 | ("version,V", "Output version information and exit.") | ||
609 | 5458 | ("no-defaults", po::value<bool>()->default_value(false)->zero_tokens(), | ||
610 | 5459 | "Configuration file defaults are not used if no-defaults is set") | ||
611 | 5460 | ; | ||
612 | 5461 | |||
613 | 5462 | po::options_description test_options("Options specific to the drizzleimport"); | ||
614 | 5463 | test_options.add_options() | ||
615 | 5464 | ("basedir,b", po::value<string>(&opt_basedir)->default_value(""), | ||
616 | 5465 | "Basedir for tests.") | ||
617 | 5466 | ("character-sets-dir", po::value<string>(&opt_charsets_dir)->default_value(""), | ||
618 | 5467 | "Directory where character sets are.") | ||
619 | 5468 | ("database,D", po::value<string>(&opt_db)->default_value(""), | ||
620 | 5469 | "Database to use.") | ||
621 | 5470 | ("include,i", po::value<string>(&opt_include)->default_value(""), | ||
622 | 5471 | "Include SQL before each test case.") | ||
623 | 5472 | ("testdir", po::value<string>(&opt_testdir)->default_value(""), | ||
624 | 5473 | "Path to use to search for test files") | ||
625 | 5474 | ("logdir", po::value<string>(&opt_logdir)->default_value(""), | ||
626 | 5475 | "Directory for log files") | ||
627 | 5476 | ("max-connect-retries", po::value<uint32_t>(&opt_max_connect_retries)->default_value(500)->notifier(&check_retries), | ||
628 | 5477 | "Max number of connection attempts when connecting to server") | ||
629 | 5478 | ("quiet,s", po::value<bool>(&silent)->default_value(0)->zero_tokens(), | ||
630 | 5479 | "Suppress all normal output.") | ||
631 | 5480 | ("record,r", "Record output of test_file into result file.") | ||
632 | 5481 | ("result-file,R", po::value<string>(&result_file_name)->default_value(""), | ||
633 | 5482 | "Read/Store result from/in this file.") | ||
634 | 5483 | ("silent,s", po::value<bool>(&silent)->default_value(false)->zero_tokens(), | ||
635 | 5484 | "Suppress all normal output. Synonym for --quiet.") | ||
636 | 5485 | ("tail-lines", po::value<uint32_t>(&opt_tail_lines)->default_value(0)->notifier(&check_tail_lines), | ||
637 | 5486 | "Number of lines of the resul to include in a failure report") | ||
638 | 5487 | ; | ||
639 | 5488 | |||
640 | 5489 | po::options_description client_options("Options specific to the client"); | ||
641 | 5490 | client_options.add_options() | ||
642 | 5491 | |||
643 | 5492 | ("host,h", po::value<string>(&opt_host)->default_value("localhost"), | ||
644 | 5493 | "Connect to host.") | ||
645 | 5494 | ("mysql,m", po::value<bool>(&opt_mysql)->default_value(true)->zero_tokens(), | ||
646 | 5495 | N_("Use MySQL Protocol.")) | ||
647 | 5496 | ("password,P", po::value<string>(&password)->default_value("PASSWORD_SENTINEL"), | ||
648 | 5497 | "Password to use when connecting to server.") | ||
649 | 5498 | ("port,p", po::value<uint32_t>(&opt_port)->default_value(0), | ||
650 | 5499 | "Port number to use for connection or 0 for default") | ||
651 | 5500 | ("protocol", po::value<string>(), | ||
652 | 5501 | "The protocol of connection (tcp,socket,pipe,memory).") | ||
653 | 5502 | ("user,u", po::value<string>(&opt_user)->default_value(""), | ||
654 | 5503 | "User for login.") | ||
655 | 5504 | ; | ||
656 | 5505 | |||
657 | 5506 | po::positional_options_description p; | ||
658 | 5507 | p.add("database", 1); | ||
659 | 5508 | |||
660 | 5509 | po::options_description long_options("Allowed Options"); | ||
661 | 5510 | long_options.add(commandline_options).add(test_options).add(client_options); | ||
662 | 5511 | |||
663 | 5512 | std::string system_config_dir_test(SYSCONFDIR); | ||
664 | 5513 | system_config_dir_test.append("/drizzle/drizzletest.cnf"); | ||
665 | 5514 | |||
666 | 5515 | std::string system_config_dir_client(SYSCONFDIR); | ||
667 | 5516 | system_config_dir_client.append("/drizzle/client.cnf"); | ||
668 | 5517 | |||
669 | 5518 | po::variables_map vm; | ||
670 | 5519 | |||
671 | 5520 | po::store(po::command_line_parser(argc, argv).options(long_options). | ||
672 | 5521 | positional(p).extra_parser(parse_password_arg).run(), vm); | ||
673 | 5522 | |||
674 | 5523 | if (! vm["no-defaults"].as<bool>()) | ||
675 | 5524 | { | ||
676 | 5525 | ifstream user_test_ifs("~/.drizzle/drizzletest.cnf"); | ||
677 | 5526 | po::store(parse_config_file(user_test_ifs, test_options), vm); | ||
678 | 5527 | |||
679 | 5528 | ifstream system_test_ifs(system_config_dir_test.c_str()); | ||
680 | 5529 | store(parse_config_file(system_test_ifs, test_options), vm); | ||
681 | 5530 | |||
682 | 5531 | ifstream user_client_ifs("~/.drizzle/client.cnf"); | ||
683 | 5532 | po::store(parse_config_file(user_client_ifs, client_options), vm); | ||
684 | 5533 | |||
685 | 5534 | ifstream system_client_ifs(system_config_dir_client.c_str()); | ||
686 | 5535 | po::store(parse_config_file(system_client_ifs, client_options), vm); | ||
687 | 5536 | } | ||
688 | 5537 | |||
689 | 5538 | po::notify(vm); | ||
690 | 5539 | |||
691 | 5578 | /* Init expected errors */ | 5540 | /* Init expected errors */ |
692 | 5579 | memset(&saved_expected_errors, 0, sizeof(saved_expected_errors)); | 5541 | memset(&saved_expected_errors, 0, sizeof(saved_expected_errors)); |
693 | 5580 | 5542 | ||
694 | @@ -5611,7 +5573,120 @@ | |||
695 | 5611 | ds_progress.reserve(2048); | 5573 | ds_progress.reserve(2048); |
696 | 5612 | ds_warning_messages.reserve(2048); | 5574 | ds_warning_messages.reserve(2048); |
697 | 5613 | 5575 | ||
699 | 5614 | parse_args(argc, argv); | 5576 | |
700 | 5577 | if (vm.count("record")) | ||
701 | 5578 | { | ||
702 | 5579 | record = 1; | ||
703 | 5580 | } | ||
704 | 5581 | |||
705 | 5582 | if (vm.count("test-file")) | ||
706 | 5583 | { | ||
707 | 5584 | string tmp= vm["test-file"].as<string>(); | ||
708 | 5585 | char buff[FN_REFLEN]; | ||
709 | 5586 | if (!internal::test_if_hard_path(tmp.c_str())) | ||
710 | 5587 | { | ||
711 | 5588 | snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str()); | ||
712 | 5589 | tmp= buff; | ||
713 | 5590 | } | ||
714 | 5591 | internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME); | ||
715 | 5592 | assert(cur_file == file_stack && cur_file->file == 0); | ||
716 | 5593 | if (!(cur_file->file= fopen(buff, "r"))) | ||
717 | 5594 | { | ||
718 | 5595 | fprintf(stderr, _("Could not open '%s' for reading: errno = %d"), buff, errno); | ||
719 | 5596 | return EXIT_ARGUMENT_INVALID; | ||
720 | 5597 | } | ||
721 | 5598 | if (!(cur_file->file_name= strdup(buff))) | ||
722 | 5599 | { | ||
723 | 5600 | fprintf(stderr, _("Out of memory")); | ||
724 | 5601 | return EXIT_OUT_OF_MEMORY; | ||
725 | 5602 | } | ||
726 | 5603 | cur_file->lineno= 1; | ||
727 | 5604 | } | ||
728 | 5605 | |||
729 | 5606 | if (vm.count("timer-file")) | ||
730 | 5607 | { | ||
731 | 5608 | string tmp= vm["timer-file"].as<string>().c_str(); | ||
732 | 5609 | static char buff[FN_REFLEN]; | ||
733 | 5610 | if (!internal::test_if_hard_path(tmp.c_str())) | ||
734 | 5611 | { | ||
735 | 5612 | snprintf(buff, sizeof(buff), "%s%s",opt_basedir.c_str(),tmp.c_str()); | ||
736 | 5613 | tmp= buff; | ||
737 | 5614 | } | ||
738 | 5615 | internal::fn_format(buff, tmp.c_str(), "", "", MY_UNPACK_FILENAME); | ||
739 | 5616 | timer_file= buff; | ||
740 | 5617 | unlink(timer_file); /* Ignore error, may not exist */ | ||
741 | 5618 | } | ||
742 | 5619 | |||
743 | 5620 | if (vm.count("port")) | ||
744 | 5621 | { | ||
745 | 5622 | /* If the port number is > 65535 it is not a valid port | ||
746 | 5623 | This also helps with potential data loss casting unsigned long to a | ||
747 | 5624 | uint32_t. */ | ||
748 | 5625 | if (opt_port > 65535) | ||
749 | 5626 | { | ||
750 | 5627 | fprintf(stderr, _("Value supplied for port is not valid.\n")); | ||
751 | 5628 | exit(EXIT_ARGUMENT_INVALID); | ||
752 | 5629 | } | ||
753 | 5630 | } | ||
754 | 5631 | |||
755 | 5632 | if (vm.count("password")) | ||
756 | 5633 | { | ||
757 | 5634 | if (!opt_password.empty()) | ||
758 | 5635 | opt_password.erase(); | ||
759 | 5636 | if (password == PASSWORD_SENTINEL) | ||
760 | 5637 | { | ||
761 | 5638 | opt_password= ""; | ||
762 | 5639 | } | ||
763 | 5640 | else | ||
764 | 5641 | { | ||
765 | 5642 | opt_password= password; | ||
766 | 5643 | tty_password= false; | ||
767 | 5644 | } | ||
768 | 5645 | char *start= (char *)password.c_str(); | ||
769 | 5646 | char *temp_pass= (char *)password.c_str(); | ||
770 | 5647 | while (*temp_pass) | ||
771 | 5648 | { | ||
772 | 5649 | /* Overwriting password with 'x' */ | ||
773 | 5650 | *temp_pass++= 'x'; | ||
774 | 5651 | } | ||
775 | 5652 | if (*start) | ||
776 | 5653 | { | ||
777 | 5654 | start[1]= 0; | ||
778 | 5655 | } | ||
779 | 5656 | } | ||
780 | 5657 | else | ||
781 | 5658 | { | ||
782 | 5659 | tty_password= true; | ||
783 | 5660 | } | ||
784 | 5661 | |||
785 | 5662 | if (vm.count("tmpdir")) | ||
786 | 5663 | { | ||
787 | 5664 | strncpy(TMPDIR, vm["tmpdir"].as<string>().c_str(), sizeof(TMPDIR)); | ||
788 | 5665 | } | ||
789 | 5666 | |||
790 | 5667 | if (vm.count("version")) | ||
791 | 5668 | { | ||
792 | 5669 | printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION, | ||
793 | 5670 | drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU); | ||
794 | 5671 | exit(0); | ||
795 | 5672 | } | ||
796 | 5673 | |||
797 | 5674 | if (vm.count("help")) | ||
798 | 5675 | { | ||
799 | 5676 | printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,MTEST_VERSION, | ||
800 | 5677 | drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU); | ||
801 | 5678 | printf("MySQL AB, by Sasha, Matt, Monty & Jani\n"); | ||
802 | 5679 | printf("Drizzle version modified by Brian, Jay, Monty Taylor, PatG and Stewart\n"); | ||
803 | 5680 | printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); | ||
804 | 5681 | printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n"); | ||
805 | 5682 | printf("Usage: %s [OPTIONS] [database] < test_file\n", internal::my_progname); | ||
806 | 5683 | exit(0); | ||
807 | 5684 | } | ||
808 | 5685 | |||
809 | 5686 | if (tty_password) | ||
810 | 5687 | { | ||
811 | 5688 | opt_pass= client_get_tty_password(NULL); /* purify tested */ | ||
812 | 5689 | } | ||
813 | 5615 | 5690 | ||
814 | 5616 | server_initialized= 1; | 5691 | server_initialized= 1; |
815 | 5617 | if (cur_file == file_stack && cur_file->file == 0) | 5692 | if (cur_file == file_stack && cur_file->file == 0) |
816 | @@ -5632,7 +5707,6 @@ | |||
817 | 5632 | 5707 | ||
818 | 5633 | if (!(cur_con->name = strdup("default"))) | 5708 | if (!(cur_con->name = strdup("default"))) |
819 | 5634 | die("Out of memory"); | 5709 | die("Out of memory"); |
820 | 5635 | |||
821 | 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, |
822 | 5637 | opt_db, opt_port); | 5711 | opt_db, opt_port); |
823 | 5638 | 5712 | ||
824 | @@ -5649,9 +5723,9 @@ | |||
825 | 5649 | /* Update $drizzleclient_get_server_version to that of current connection */ | 5723 | /* Update $drizzleclient_get_server_version to that of current connection */ |
826 | 5650 | var_set_drizzleclient_get_server_version(&cur_con->con); | 5724 | var_set_drizzleclient_get_server_version(&cur_con->con); |
827 | 5651 | 5725 | ||
829 | 5652 | if (opt_include) | 5726 | if (! opt_include.empty()) |
830 | 5653 | { | 5727 | { |
832 | 5654 | open_file(opt_include); | 5728 | open_file(opt_include.c_str()); |
833 | 5655 | } | 5729 | } |
834 | 5656 | 5730 | ||
835 | 5657 | while (!read_command(&command) && !abort_flag) | 5731 | while (!read_command(&command) && !abort_flag) |
836 | @@ -5955,14 +6029,14 @@ | |||
837 | 5955 | */ | 6029 | */ |
838 | 5956 | if (ds_res.length()) | 6030 | if (ds_res.length()) |
839 | 5957 | { | 6031 | { |
841 | 5958 | if (result_file_name) | 6032 | if (! result_file_name.empty()) |
842 | 5959 | { | 6033 | { |
843 | 5960 | /* A result file has been specified */ | 6034 | /* A result file has been specified */ |
844 | 5961 | 6035 | ||
845 | 5962 | if (record) | 6036 | if (record) |
846 | 5963 | { | 6037 | { |
847 | 5964 | /* Recording - dump the output from test to result file */ | 6038 | /* Recording - dump the output from test to result file */ |
849 | 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()); |
850 | 5966 | } | 6040 | } |
851 | 5967 | else | 6041 | else |
852 | 5968 | { | 6042 | { |
853 | @@ -5985,7 +6059,7 @@ | |||
854 | 5985 | } | 6059 | } |
855 | 5986 | 6060 | ||
856 | 5987 | if (!command_executed && | 6061 | if (!command_executed && |
858 | 5988 | result_file_name && !stat(result_file_name, &res_info)) | 6062 | ! result_file_name.empty() && !stat(result_file_name.c_str(), &res_info)) |
859 | 5989 | { | 6063 | { |
860 | 5990 | /* | 6064 | /* |
861 | 5991 | my_stat() successful on result file. Check if we have not run a | 6065 | my_stat() successful on result file. Check if we have not run a |
862 | @@ -5997,16 +6071,23 @@ | |||
863 | 5997 | die("No queries executed but result file found!"); | 6071 | die("No queries executed but result file found!"); |
864 | 5998 | } | 6072 | } |
865 | 5999 | 6073 | ||
867 | 6000 | if ( opt_mark_progress && result_file_name ) | 6074 | if ( opt_mark_progress && ! result_file_name.empty() ) |
868 | 6001 | dump_progress(); | 6075 | dump_progress(); |
869 | 6002 | 6076 | ||
870 | 6003 | /* Dump warning messages */ | 6077 | /* Dump warning messages */ |
872 | 6004 | if (result_file_name && ds_warning_messages.length()) | 6078 | if (! result_file_name.empty() && ds_warning_messages.length()) |
873 | 6005 | dump_warning_messages(); | 6079 | dump_warning_messages(); |
874 | 6006 | 6080 | ||
875 | 6007 | timer_output(); | 6081 | timer_output(); |
876 | 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 */ |
877 | 6009 | cleanup_and_exit(0); | 6083 | cleanup_and_exit(0); |
878 | 6084 | } | ||
879 | 6085 | |||
880 | 6086 | catch(exception &err) | ||
881 | 6087 | { | ||
882 | 6088 | cerr<<err.what()<<endl; | ||
883 | 6089 | } | ||
884 | 6090 | |||
885 | 6010 | return 0; /* Keep compiler happy too */ | 6091 | return 0; /* Keep compiler happy too */ |
886 | 6011 | } | 6092 | } |
887 | 6012 | 6093 | ||
888 | 6013 | 6094 | ||
889 | === modified file 'client/include.am' | |||
890 | --- client/include.am 2010-06-12 21:25:45 +0000 | |||
891 | +++ client/include.am 2010-06-16 07:57:30 +0000 | |||
892 | @@ -65,7 +65,7 @@ | |||
893 | 65 | client_drizzleslap_CXXFLAGS= ${CLIENT_CXXFLAGS} | 65 | client_drizzleslap_CXXFLAGS= ${CLIENT_CXXFLAGS} |
894 | 66 | 66 | ||
895 | 67 | client_drizzletest_SOURCES= client/drizzletest.cc client/errname.cc | 67 | client_drizzletest_SOURCES= client/drizzletest.cc client/errname.cc |
897 | 68 | client_drizzletest_LDADD= ${CLIENT_LDADD} ${LIBPCRE} | 68 | client_drizzletest_LDADD= ${CLIENT_LDADD} ${BOOST_LIBS} ${LIBPCRE} |
898 | 69 | client_drizzletest_CXXFLAGS= ${CLIENT_CXXFLAGS} | 69 | client_drizzletest_CXXFLAGS= ${CLIENT_CXXFLAGS} |
899 | 70 | 70 | ||
900 | 71 | 71 |