Skip to content

Commit 24f99ef

Browse files
palichoroba
authored andcommitted
Allow to run test suite against Embedded server
Currently in Makefile.PL there is a check that option --testhost cannot be embedded. It is because Makefile.PL cannot generate t/MariaDB.mtest file for connection with Embedded server. Fix it. Add a new Makfile.PL option --testembdatadir= which is specify database directory of the Embedded server and hence it is required for running test suite against Embedded server. Add a new optional Makfile.PL option --testemboptions= which specifies additional comma separate options for Embedded server. Cleanup code for checking if combination of host, port, socket and embdatadir is allowed and makes sense. Running test suite against embedded server is activated either explicitly by --testhost=embedded option or just by specifying --testembdatadir= option.
1 parent 86db0a8 commit 24f99ef

File tree

1 file changed

+94
-30
lines changed

1 file changed

+94
-30
lines changed

Makefile.PL

Lines changed: 94 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ push @mysql_headers, 'mysql.h';
2424

2525
our $opt = { "help" => \&Usage, };
2626

27-
my ($test_host, $test_port, $test_socket);
27+
my ($test_host, $test_port, $test_socket, $test_embdatadir);
2828
{
29-
local ($::test_host, $::test_port, $::test_user, $::test_socket, $::test_authplugin, $::test_password, $::test_db, $::test_mysql_config, $::test_cflags, $::test_libs);
29+
local ($::test_host, $::test_port, $::test_user, $::test_socket, $::test_embdatadir, $::test_emboptions, $::test_authplugin, $::test_password, $::test_db, $::test_mysql_config, $::test_cflags, $::test_libs);
3030
eval { require "./t/MariaDB.mtest" } and do {
3131
$opt->{'testuser'} = $::test_user;
3232
$opt->{'testpassword'} = $::test_password;
3333
$opt->{'testdb'} = $::test_db;
3434
$opt->{'mysql_config'} = $::test_mysql_config;
3535
$opt->{'cflags'} = $::test_cflags;
3636
$opt->{'libs'} = $::test_libs;
37+
$opt->{'testemboptions'} = $::test_emboptions;
3738
$opt->{'testauthplugin'} = $::test_authplugin;
3839
$test_host = $::test_host;
3940
$test_port = $::test_port;
4041
$test_socket = $::test_socket;
42+
$test_embdatadir = $::test_embdatadir;
4143
}
4244
}
4345

@@ -50,6 +52,8 @@ Getopt::Long::GetOptions(
5052
"testuser:s",
5153
"testpassword:s",
5254
"testsocket:s",
55+
"testembdatadir:s",
56+
"testemboptions:s",
5357
"testauthplugin:s",
5458
"cflags:s",
5559
"libs:s",
@@ -106,62 +110,97 @@ MSG
106110
}
107111
}
108112

109-
for my $key (qw(testdb testhost testuser testpassword testsocket testauthplugin testport cflags libs))
113+
for my $key (qw(testdb testhost testuser testpassword testsocket testport testembdatadir testemboptions testauthplugin cflags libs))
110114
{
111115
Configure($opt, $source, $key);
112116
}
113117

114-
if (!$opt->{testport} && (!$opt->{testhost} || $opt->{testhost} eq 'localhost') && !defined $opt->{testsocket} && $test_socket) {
118+
# Reusing old test host is possible if it does not conflict with new test port, new test socket or new test embdatadir
119+
if (!defined $opt->{testhost} && defined $test_host && length $test_host &&
120+
((defined $opt->{testport} && $test_host ne 'localhost' && $test_host ne 'embedded') ||
121+
(defined $opt->{testsocket} && $test_host eq 'localhost') ||
122+
(defined $opt->{testembdatadir} && $test_host eq 'embedded') ||
123+
(!defined $opt->{testsocket} && !defined $opt->{testembdatadir} && !defined $opt->{testport}))) {
124+
$opt->{testhost} = $test_host;
125+
$source->{testhost} = "User's choice";
126+
}
127+
128+
# Reusing old test port is possible if it does not conflict with new test host, new test socket or new test embdatadir
129+
if (!defined $opt->{testport} && defined $test_port && length $test_port &&
130+
(!defined $opt->{testhost} || ($opt->{testhost} ne 'localhost' && $opt->{testhost} ne 'embedded')) &&
131+
!defined $opt->{testsocket} &&
132+
!defined $opt->{testembdatadir}) {
133+
$opt->{testport} = $test_port;
134+
$source->{testport} = "User's choice";
135+
}
136+
137+
# Reusing old test socket is possible if it does not conflict with new test host, new test port or new test embdatadir
138+
if (!defined $opt->{testsocket} && defined $test_socket && length $test_socket &&
139+
(!defined $opt->{testhost} || $opt->{testhost} eq 'localhost') &&
140+
!defined $opt->{testport} &&
141+
!defined $opt->{testembdatadir}) {
115142
$opt->{testsocket} = $test_socket;
116143
$source->{testsocket} = "User's choice";
117144
}
118145

119-
if (!$opt->{testsocket}) {
120-
if (!defined $opt->{testhost} && $test_host && (!$opt->{testport} || $test_host ne 'localhost')) {
121-
$opt->{testhost} = $test_host;
122-
$source->{testhost} = "User's choice";
123-
}
124-
if (!defined $opt->{testport} && $test_port && (!$opt->{testhost} || $opt->{testhost} ne 'localhost')) {
125-
$opt->{testport} = $test_port;
126-
$source->{testport} = "User's choice";
127-
}
128-
} else {
129-
if (!defined $opt->{testhost} && $test_host && $test_host eq 'localhost') {
130-
$opt->{testhost} = 'localhost';
131-
$source->{testhost} = "User's choice";
132-
}
146+
# Reusing old test embdatadir is possible if it does not conflict with new test host, new test port or new test socket
147+
if (!defined $opt->{testembdatadir} && defined $test_embdatadir && length $test_embdatadir &&
148+
(!defined $opt->{testhost} || $opt->{testhost} eq 'embedded') &&
149+
!defined $opt->{testport} &&
150+
!defined $opt->{testsocket}) {
151+
$opt->{testembdatadir} = $test_embdatadir;
152+
$source->{testembdatadir} = "User's choice";
153+
}
154+
155+
# if we have a testsocket but no host, set localhost
156+
if (defined $opt->{testsocket} && !defined $opt->{testhost}) {
157+
$opt->{testhost} = 'localhost';
158+
$source->{testhost} = 'guessed';
133159
}
134160

135-
#if we have a testport but no host, assume 127.0.0.1
136-
if ( $opt->{testport} && !$opt->{testhost} ) {
161+
# if we have a testembdatadir but no host, set embedded
162+
if (defined $opt->{testembdatadir} && !defined $opt->{testhost}) {
163+
$opt->{testhost} = 'embedded';
164+
$source->{testhost} = 'guessed';
165+
}
166+
167+
# if we have a testport but no host, assume 127.0.0.1
168+
if (defined $opt->{testport} && !defined $opt->{testhost}) {
137169
$opt->{testhost} = '127.0.0.1';
138170
$source->{testhost} = 'guessed';
139171
}
140172

141-
foreach (qw(testhost testport testsocket)) {
173+
foreach (qw(testhost testport testsocket testembdatadir)) {
142174
next if defined $opt->{$_};
143175
$opt->{$_} = '';
144176
$source->{$_} = 'default';
145177
}
146178

147179
# testsocket makes sense only when testhost is localhost
148-
if ($opt->{testsocket} && $opt->{testhost} && $opt->{testhost} ne 'localhost') {
180+
if (length $opt->{testsocket} && $opt->{testhost} ne 'localhost') {
181+
die << "MSG";
182+
Option --testhost different from localhost cannot be specified together with option --testsocket.
183+
MSG
184+
}
185+
186+
# testembdatadir makes sense only when testhost is embedded
187+
if (length $opt->{testembdatadir} && $opt->{testhost} ne 'embedded') {
149188
die << "MSG";
150-
Option --testport or --testhost different from localhost cannot be specified together with option --testsocket.
189+
Option --testhost different from embedded cannot be specified together with option --testembdatadir.
151190
MSG
152191
}
153192

154-
# testport cannot be specified when host is localhost
155-
if ($opt->{testport} && $opt->{testhost} && $opt->{testhost} eq 'localhost') {
193+
# there is no default testembdatadir, so check that it is set
194+
if ($opt->{testhost} eq 'embedded' && !length $opt->{testembdatadir}) {
156195
die << "MSG";
157-
Option --testport cannot be specified when --testhost is localhost.
196+
Option --testembdatadir must be specified when --testhost is embedded.
158197
MSG
159198
}
160199

161-
# testhost cannot be embedded
162-
if ($opt->{testhost} && $opt->{testhost} eq 'embedded') {
200+
# testport cannot be specified when host is localhost or embedded
201+
if (length $opt->{testport} && ($opt->{testhost} eq 'localhost' || $opt->{testhost} eq 'embedded')) {
163202
die << "MSG";
164-
Option --testhost cannot be embedded.
203+
Option --testport cannot be specified when --testhost is localhost or embedded.
165204
MSG
166205
}
167206

@@ -262,6 +301,14 @@ my $have_embedded = check_lib(
262301

263302
print "Embedded server: " . ($have_embedded ? "supported" : "not supported by client library") . "\n\n";
264303

304+
if (!$have_embedded && $opt->{testhost} eq 'embedded') {
305+
die << "MSG";
306+
Cannot run test suite against Embedded server (specified via
307+
option --testhost=embedded) because Embedded server is not
308+
supported by client library.
309+
MSG
310+
}
311+
265312
my $have_get_charset_number = check_lib(
266313
LIBS => (join ' ', @libdirs, $main_lib),
267314
ccflags => $opt->{cflags},
@@ -423,13 +470,17 @@ print "Writing $fileName for test suite\n";
423470
"\$::test_port = \$opt->{'testport'};\n" .
424471
"\$::test_user = \$opt->{'testuser'};\n" .
425472
"\$::test_socket = \$opt->{'testsocket'};\n" .
473+
"\$::test_embdatadir = \$opt->{'testembdatadir'};\n" .
474+
"\$::test_emboptions = \$opt->{'testemboptions'};\n" .
426475
"\$::test_authplugin = \$opt->{'testauthplugin'};\n" .
427476
"\$::test_password = \$opt->{'testpassword'};\n" .
428477
"\$::test_db = \$opt->{'testdb'};\n" .
429478
"\$::test_dsn = \"DBI:MariaDB:\$::test_db\";\n" .
430479
"\$::test_dsn .= \":\$::test_host\" if \$::test_host;\n" .
431480
"\$::test_dsn .= \":\$::test_port\" if \$::test_port;\n".
432481
"\$::test_dsn .= \";mariadb_socket=\$::test_socket\" if \$::test_socket;\n" .
482+
"\$::test_dsn .= \";mariadb_embedded_options=--datadir=\$::test_embdatadir\" if \$::test_embdatadir;\n" .
483+
"\$::test_dsn .= \",\$::test_emboptions\" if \$::test_embdatadir and \$::test_emboptions;\n" .
433484
"\$::test_dsn .= \";mariadb_auth_plugin=\$::test_authplugin\" if \$::test_authplugin;\n" .
434485
"\$::test_dsn .= \";mariadb_connect_timeout=120;mariadb_read_timeout=120;mariadb_write_timeout=120\";\n" .
435486
"\$::test_mysql_config = \$opt->{'mysql_config'} if \$source->{'mysql_config'} eq 'User\\'s choice';\n" .
@@ -663,6 +714,15 @@ Possible options are:
663714
the database server; by default unix socket is chosen
664715
by mariadb/mysqlclient library; takes effect only
665716
when --testhost is set to "localhost"
717+
--testembdatadir=<dir> Use <dir> as database directory for embedded server,
718+
it may be and it is suggested to be empty, which means
719+
that database is uninitialized; takes effect only when
720+
--testhost is set to "embedded"
721+
--testemboptions=<op> Use <op> as additional options for embedded server
722+
separated by comma, it is recommended to set output
723+
log file (e.g. '--log-error=/dev/null') and language
724+
directory (e.g. '--language=/usr/local/share/mysql')
725+
if language directory is different than system one
666726
--testauthplugin=<ap> Use <ap> auth plugin when doing user authentication
667727
handshake with server; for older server versions it is
668728
needed to pass "mysql_native_password"
@@ -864,6 +924,10 @@ perl Makefile.PL --testuser=username
864924
$source->{$param} = "default";
865925
$opt->{$param} = "";
866926
}
927+
elsif ($param eq "testemboptions") {
928+
$source->{$param} = "default";
929+
$opt->{$param} = "";
930+
}
867931
elsif ($param eq "cflags") {
868932
$source->{$param} = "guessed";
869933
my ($dir, $file) = SearchFor('include', 'mysql.h');
@@ -906,7 +970,7 @@ section "Linker flags" or type
906970
perl Makefile.PL --help
907971
MSG
908972
}
909-
elsif ($param eq "testhost" || $param eq "testport" || $param eq "testsocket") {
973+
elsif (grep { $param eq $_ } ("testhost", "testport", "testsocket", "testembdatadir")) {
910974
# known parameter, but do nothing
911975
}
912976
else {

0 commit comments

Comments
 (0)