@@ -24,20 +24,22 @@ push @mysql_headers, 'mysql.h';
24
24
25
25
our $opt = { " help" => \&Usage, };
26
26
27
- my ($test_host , $test_port , $test_socket , $test_authplugin );
27
+ my ($test_host , $test_port , $test_socket , $test_embdatadir );
28
28
{
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);
30
30
eval { require " ./t/MariaDB.mtest" } and do {
31
31
$opt -> {' testuser' } = $: :test_user;
32
32
$opt -> {' testpassword' } = $: :test_password;
33
33
$opt -> {' testdb' } = $: :test_db;
34
34
$opt -> {' mysql_config' } = $: :test_mysql_config;
35
35
$opt -> {' cflags' } = $: :test_cflags;
36
36
$opt -> {' libs' } = $: :test_libs;
37
+ $opt -> {' testemboptions' } = $: :test_emboptions;
38
+ $opt -> {' testauthplugin' } = $: :test_authplugin;
37
39
$test_host = $: :test_host;
38
40
$test_port = $: :test_port;
39
41
$test_socket = $: :test_socket;
40
- $test_authplugin = $: :test_authplugin ;
42
+ $test_embdatadir = $: :test_embdatadir ;
41
43
}
42
44
}
43
45
@@ -50,7 +52,10 @@ Getopt::Long::GetOptions(
50
52
" testuser:s" ,
51
53
" testpassword:s" ,
52
54
" testsocket:s" ,
55
+ " testembdatadir:s" ,
56
+ " testemboptions:s" ,
53
57
" testauthplugin:s" ,
58
+ " requireembsup!" ,
54
59
" cflags:s" ,
55
60
" libs:s" ,
56
61
" mysql_config:s" ,
@@ -106,62 +111,112 @@ MSG
106
111
}
107
112
}
108
113
109
- for my $key (qw( testdb testhost testuser testpassword testsocket testauthplugin testport cflags libs) )
114
+ if (exists $opt -> {requireembsup })
115
+ {
116
+ $source -> {' requireembsup' } = " User's choice" ;
117
+ }
118
+ elsif (defined $ENV {' DBD_MARIADB_REQUIREEMBSUP' })
119
+ {
120
+ $source -> {' requireembsup' } = ' environment' ;
121
+ $opt -> {' requireembsup' } = !!$ENV {DBD_MARIADB_REQUIREEMBSUP };
122
+ }
123
+ else
124
+ {
125
+ $source -> {' requireembsup' } = ' default' ;
126
+ $opt -> {' requireembsup' } = 0;
127
+ }
128
+
129
+ for my $key (qw( testdb testhost testuser testpassword testsocket testport testembdatadir testemboptions testauthplugin cflags libs) )
110
130
{
111
131
Configure($opt , $source , $key );
112
132
}
113
133
114
- if (!$opt -> {testport } && (!$opt -> {testhost } || $opt -> {testhost } eq ' localhost' ) && !defined $opt -> {testsocket } && $test_socket ) {
134
+ # Reusing old test host is possible if it does not conflict with new test port, new test socket or new test embdatadir
135
+ if (!defined $opt -> {testhost } && defined $test_host && length $test_host &&
136
+ ((defined $opt -> {testport } && $test_host ne ' localhost' && $test_host ne ' embedded' ) ||
137
+ (defined $opt -> {testsocket } && $test_host eq ' localhost' ) ||
138
+ (defined $opt -> {testembdatadir } && $test_host eq ' embedded' ) ||
139
+ (!defined $opt -> {testsocket } && !defined $opt -> {testembdatadir } && !defined $opt -> {testport }))) {
140
+ $opt -> {testhost } = $test_host ;
141
+ $source -> {testhost } = " User's choice" ;
142
+ }
143
+
144
+ # Reusing old test port is possible if it does not conflict with new test host, new test socket or new test embdatadir
145
+ if (!defined $opt -> {testport } && defined $test_port && length $test_port &&
146
+ (!defined $opt -> {testhost } || ($opt -> {testhost } ne ' localhost' && $opt -> {testhost } ne ' embedded' )) &&
147
+ !defined $opt -> {testsocket } &&
148
+ !defined $opt -> {testembdatadir }) {
149
+ $opt -> {testport } = $test_port ;
150
+ $source -> {testport } = " User's choice" ;
151
+ }
152
+
153
+ # Reusing old test socket is possible if it does not conflict with new test host, new test port or new test embdatadir
154
+ if (!defined $opt -> {testsocket } && defined $test_socket && length $test_socket &&
155
+ (!defined $opt -> {testhost } || $opt -> {testhost } eq ' localhost' ) &&
156
+ !defined $opt -> {testport } &&
157
+ !defined $opt -> {testembdatadir }) {
115
158
$opt -> {testsocket } = $test_socket ;
116
159
$source -> {testsocket } = " User's choice" ;
117
160
}
118
161
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
- }
162
+ # Reusing old test embdatadir is possible if it does not conflict with new test host, new test port or new test socket
163
+ if (!defined $opt -> {testembdatadir } && defined $test_embdatadir && length $test_embdatadir &&
164
+ (!defined $opt -> {testhost } || $opt -> {testhost } eq ' embedded' ) &&
165
+ !defined $opt -> {testport } &&
166
+ !defined $opt -> {testsocket }) {
167
+ $opt -> {testembdatadir } = $test_embdatadir ;
168
+ $source -> {testembdatadir } = " User's choice" ;
169
+ }
170
+
171
+ # if we have a testsocket but no host, set localhost
172
+ if (defined $opt -> {testsocket } && !defined $opt -> {testhost }) {
173
+ $opt -> {testhost } = ' localhost' ;
174
+ $source -> {testhost } = ' guessed' ;
133
175
}
134
176
135
- # if we have a testport but no host, assume 127.0.0.1
136
- if ( $opt -> {testport } && !$opt -> {testhost } ) {
177
+ # if we have a testembdatadir but no host, set embedded
178
+ if (defined $opt -> {testembdatadir } && !defined $opt -> {testhost }) {
179
+ $opt -> {testhost } = ' embedded' ;
180
+ $source -> {testhost } = ' guessed' ;
181
+ }
182
+
183
+ # if we have a testport but no host, assume 127.0.0.1
184
+ if (defined $opt -> {testport } && !defined $opt -> {testhost }) {
137
185
$opt -> {testhost } = ' 127.0.0.1' ;
138
186
$source -> {testhost } = ' guessed' ;
139
187
}
140
188
141
- foreach (qw( testhost testport testsocket testauthplugin ) ) {
189
+ foreach (qw( testhost testport testsocket testembdatadir ) ) {
142
190
next if defined $opt -> {$_ };
143
191
$opt -> {$_ } = ' ' ;
144
192
$source -> {$_ } = ' default' ;
145
193
}
146
194
147
195
# testsocket makes sense only when testhost is localhost
148
- if ($opt -> { testsocket } && $opt -> {testhost } && $opt -> {testhost } ne ' localhost' ) {
196
+ if (length $opt -> {testsocket } && $opt -> {testhost } ne ' localhost' ) {
149
197
die << "MSG" ;
150
- Option --testport or -- testhost different from localhost cannot be specified together with option --testsocket.
198
+ Option --testhost different from localhost cannot be specified together with option --testsocket.
151
199
MSG
152
200
}
153
201
154
- # testport cannot be specified when host is localhost
155
- if ($opt -> { testport } && $opt -> {testhost } && $opt -> {testhost } eq ' localhost ' ) {
202
+ # testembdatadir makes sense only when testhost is embedded
203
+ if (length $opt -> {testembdatadir } && $opt -> {testhost } ne ' embedded ' ) {
156
204
die << "MSG" ;
157
- Option --testport cannot be specified when --testhost is localhost .
205
+ Option --testhost different from embedded cannot be specified together with option --testembdatadir .
158
206
MSG
159
207
}
160
208
161
- # testhost cannot be embedded
162
- if ($opt -> {testhost } && $opt -> {testhost } eq ' embedded ' ) {
209
+ # there is no default testembdatadir, so check that it is set
210
+ if ($opt -> {testhost } eq ' embedded ' && ! length $opt -> {testembdatadir } ) {
163
211
die << "MSG" ;
164
- Option --testhost cannot be embedded.
212
+ Option --testembdatadir must be specified when --testhost is embedded.
213
+ MSG
214
+ }
215
+
216
+ # testport cannot be specified when host is localhost or embedded
217
+ if (length $opt -> {testport } && ($opt -> {testhost } eq ' localhost' || $opt -> {testhost } eq ' embedded' )) {
218
+ die << "MSG" ;
219
+ Option --testport cannot be specified when --testhost is localhost or embedded.
165
220
MSG
166
221
}
167
222
@@ -262,6 +317,14 @@ my $have_embedded = check_lib(
262
317
263
318
print " Embedded server: " . ($have_embedded ? " supported" : " not supported by client library" ) . " \n\n " ;
264
319
320
+ if (!$have_embedded && ($opt -> {testhost } eq ' embedded' || $opt -> {requireembsup })) {
321
+ die << "MSG" ;
322
+ Cannot run test suite against Embedded server (specified via
323
+ option --testhost=embedded or option --requireembsup) because
324
+ Embedded server is not supported by client library.
325
+ MSG
326
+ }
327
+
265
328
my $have_get_charset_number = check_lib(
266
329
LIBS => (join ' ' , @libdirs , $main_lib ),
267
330
ccflags => $opt -> {cflags },
@@ -414,20 +477,26 @@ EOF
414
477
print " Client library deinitialize OpenSSL library functions: " . ($have_problem_with_openssl ? " yes" : " no" ) . " \n\n " ;
415
478
416
479
my $fileName = File::Spec-> catfile(" t" , " MariaDB.mtest" );
480
+ print " Writing $fileName for test suite\n " ;
417
481
(open (FILE, " >$fileName " ) &&
418
- (print FILE (" { local " . Data::Dumper-> Dump([$opt ], [" opt" ]) .
419
- " local " . Data::Dumper-> Dump([$source ], [" source" ]) .
482
+ (print FILE (" {\n " .
483
+ " local " . Data::Dumper-> new([$opt ], [" opt" ])-> Sortkeys(1)-> Indent(1)-> Dump() .
484
+ " local " . Data::Dumper-> new([$source ], [" source" ])-> Sortkeys(1)-> Indent(1)-> Dump() .
420
485
" \$ ::test_host = \$ opt->{'testhost'};\n " .
421
486
" \$ ::test_port = \$ opt->{'testport'};\n " .
422
487
" \$ ::test_user = \$ opt->{'testuser'};\n " .
423
488
" \$ ::test_socket = \$ opt->{'testsocket'};\n " .
489
+ " \$ ::test_embdatadir = \$ opt->{'testembdatadir'};\n " .
490
+ " \$ ::test_emboptions = \$ opt->{'testemboptions'};\n " .
424
491
" \$ ::test_authplugin = \$ opt->{'testauthplugin'};\n " .
425
492
" \$ ::test_password = \$ opt->{'testpassword'};\n " .
426
493
" \$ ::test_db = \$ opt->{'testdb'};\n " .
427
494
" \$ ::test_dsn = \" DBI:MariaDB:\$ ::test_db\" ;\n " .
428
495
" \$ ::test_dsn .= \" :\$ ::test_host\" if \$ ::test_host;\n " .
429
496
" \$ ::test_dsn .= \" :\$ ::test_port\" if \$ ::test_port;\n " .
430
497
" \$ ::test_dsn .= \" ;mariadb_socket=\$ ::test_socket\" if \$ ::test_socket;\n " .
498
+ " \$ ::test_dsn .= \" ;mariadb_embedded_options=--datadir=\$ ::test_embdatadir\" if \$ ::test_embdatadir;\n " .
499
+ " \$ ::test_dsn .= \" ,\$ ::test_emboptions\" if \$ ::test_embdatadir and \$ ::test_emboptions;\n " .
431
500
" \$ ::test_dsn .= \" ;mariadb_auth_plugin=\$ ::test_authplugin\" if \$ ::test_authplugin;\n " .
432
501
" \$ ::test_dsn .= \" ;mariadb_connect_timeout=120;mariadb_read_timeout=120;mariadb_write_timeout=120\" ;\n " .
433
502
" \$ ::test_mysql_config = \$ opt->{'mysql_config'} if \$ source->{'mysql_config'} eq 'User\\ 's choice';\n " .
@@ -661,9 +730,19 @@ Possible options are:
661
730
the database server; by default unix socket is chosen
662
731
by mariadb/mysqlclient library; takes effect only
663
732
when --testhost is set to "localhost"
733
+ --testembdatadir=<dir> Use <dir> as database directory for embedded server,
734
+ it may be and it is suggested to be empty, which means
735
+ that database is uninitialized; takes effect only when
736
+ --testhost is set to "embedded"
737
+ --testemboptions=<op> Use <op> as additional options for embedded server
738
+ separated by comma, it is recommended to set output
739
+ log file (e.g. '--log-error=/dev/null') and language
740
+ directory (e.g. '--language=/usr/local/share/mysql')
741
+ if language directory is different than system one
664
742
--testauthplugin=<ap> Use <ap> auth plugin when doing user authentication
665
743
handshake with server; for older server versions it is
666
744
needed to pass "mysql_native_password"
745
+ --requireembsup Require client library with embedded server support
667
746
--mariadb_config Synonym for --mysql_config, override it
668
747
--mysql_config=<path> Specify <path> for mariadb_config or mysql_config script
669
748
--help Print this message and exit
@@ -858,6 +937,14 @@ perl Makefile.PL --testuser=username
858
937
$source -> {$param } = " default" ;
859
938
$opt -> {$param } = " " ;
860
939
}
940
+ elsif ($param eq " testauthplugin" ) {
941
+ $source -> {$param } = " default" ;
942
+ $opt -> {$param } = " " ;
943
+ }
944
+ elsif ($param eq " testemboptions" ) {
945
+ $source -> {$param } = " default" ;
946
+ $opt -> {$param } = " " ;
947
+ }
861
948
elsif ($param eq " cflags" ) {
862
949
$source -> {$param } = " guessed" ;
863
950
my ($dir , $file ) = SearchFor(' include' , ' mysql.h' );
@@ -900,7 +987,7 @@ section "Linker flags" or type
900
987
perl Makefile.PL --help
901
988
MSG
902
989
}
903
- elsif ($param eq " testhost" || $param eq " testport" || $param eq " testsocket" || $param eq " testauthplugin " ) {
990
+ elsif (grep { $param eq $_ } ( " testhost" , " testport" , " testsocket" , " testembdatadir " ) ) {
904
991
# known parameter, but do nothing
905
992
}
906
993
else {
0 commit comments