-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmysql-test-run.pl
8163 lines (6935 loc) · 269 KB
/
mysql-test-run.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# -*- cperl -*-
# Copyright (c) 2004, 2024, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is designed to work with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have either included with
# the program or referenced in the documentation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##############################################################################
#
# mysql-test-run.pl
#
# Tool used for executing a suite of .test files
#
# See the "MySQL Test framework manual" for more information
# https://dev.mysql.com/doc/dev/mysql-server/latest/PAGE_MYSQL_TEST_RUN.html
#
##############################################################################
use strict;
use warnings;
use lib "lib";
use lib "../internal/cloud/mysql-test/lib";
use Cwd;
use Cwd 'abs_path';
use File::Basename;
use File::Copy;
use File::Find;
use File::Spec::Functions qw/splitdir/;
use File::Temp qw/tempdir/;
use Getopt::Long;
use IO::Select;
use IO::Socket::INET;
push @INC, ".";
use My::ConfigFactory;
use My::CoreDump;
use My::File::Path; # Patched version of File::Path
use My::Find;
use My::Options;
use My::Platform;
use My::SafeProcess;
use My::SysInfo;
use mtr_cases;
use mtr_cases_from_list;
use mtr_match;
use mtr_report;
use mtr_results;
use mtr_unique;
require "lib/mtr_gcov.pl";
require "lib/mtr_gprof.pl";
require "lib/mtr_io.pl";
require "lib/mtr_lock_order.pl";
require "lib/mtr_misc.pl";
require "lib/mtr_process.pl";
our $secondary_engine_support = eval 'use mtr_secondary_engine; 1';
our $primary_engine_support = eval 'use mtr_external_engine; 1';
# Global variable to keep track of completed test cases
my $completed = [];
$SIG{INT} = sub {
if ($completed) {
mtr_print_line();
mtr_report_stats("Got ^C signal", $completed);
mtr_error("Test suite aborted with ^C");
}
mtr_error("Got ^C signal");
};
sub env_or_val($$) { defined $ENV{ $_[0] } ? $ENV{ $_[0] } : $_[1] }
# Local variables
my $parent_pid;
my $opt_boot_dbx;
my $opt_boot_ddd;
my $opt_boot_gdb;
my $opt_callgrind;
my $opt_charset_for_testdb;
my $opt_compress;
my $opt_async_client;
my $opt_cursor_protocol;
my $opt_debug_common;
my $opt_do_suite;
my $opt_explain_protocol;
my $opt_helgrind;
my $opt_json_explain_protocol;
my $opt_mark_progress;
my $opt_max_connections;
my $opt_platform;
my $opt_platform_exclude;
my $opt_ps_protocol;
my $opt_report_features;
my $opt_skip_core;
my $opt_skip_test_list;
my $opt_sp_protocol;
my $opt_start;
my $opt_start_dirty;
my $opt_start_exit;
my $opt_strace_client;
my $opt_strace_server;
my @opt_perf_servers;
my $opt_stress;
my $opt_tmpdir;
my $opt_tmpdir_pid;
my $opt_trace_protocol;
my $opt_user_args;
my $opt_valgrind_path;
my $opt_view_protocol;
my $opt_wait_all;
my $opt_build_thread = $ENV{'MTR_BUILD_THREAD'} || "auto";
my $opt_colored_diff = $ENV{'MTR_COLORED_DIFF'} || 0;
my $opt_ctest_timeout = $ENV{'MTR_CTEST_TIMEOUT'} || 120; # seconds
my $opt_debug_sync_timeout = 600; # Default timeout for WAIT_FOR actions.
my $opt_do_test_list = "";
my $opt_force_restart = 0;
my $opt_include_ndbcluster = 0;
my $opt_lock_order = env_or_val(MTR_LOCK_ORDER => 0);
my $opt_max_save_core = env_or_val(MTR_MAX_SAVE_CORE => 5);
my $opt_max_save_datadir = env_or_val(MTR_MAX_SAVE_DATADIR => 20);
my $opt_max_test_fail = env_or_val(MTR_MAX_TEST_FAIL => 10);
my $opt_mysqlx_baseport = $ENV{'MYSQLXPLUGIN_PORT'} || "auto";
my $opt_port_base = $ENV{'MTR_PORT_BASE'} || "auto";
my $opt_port_exclude = $ENV{'MTR_PORT_EXCLUDE'} || "none";
my $opt_bind_local = $ENV{'MTR_BIND_LOCAL'};
my $opt_reorder = 1;
my $opt_retry = 3;
my $opt_retry_failure = env_or_val(MTR_RETRY_FAILURE => 2);
my $opt_skip_ndbcluster = 0;
my $opt_skip_sys_schema = 0;
my $opt_suite_timeout = $ENV{MTR_SUITE_TIMEOUT} || 300; # minutes
my $opt_testcase_timeout = $ENV{MTR_TESTCASE_TIMEOUT} || 15; # minutes
my $opt_valgrind_clients = 0;
my $opt_valgrind_mysqld = 0;
my $opt_valgrind_mysqltest = 0;
my $opt_accept_fail = 0;
# Options used when connecting to an already running server
my %opts_extern;
my $auth_plugin; # The path to the authentication test plugin
my $baseport;
my $ctest_parallel; # Number of parallel jobs to run unit tests
my $ctest_report; # Unit test report stored here for delayed printing
my $current_config_name; # The currently running config file template
my $exe_ndb_mgm;
my $exe_ndb_mgmd;
my $exe_ndb_waiter;
my $exe_ndbd;
my $exe_ndbmtd;
my $initial_bootstrap_cmd;
my $mysql_base_version;
my $mysqlx_baseport;
my $path_config_file; # The generated config file, var/my.cnf
my $path_vardir_trace;
my $test_fail;
my $build_thread = 0;
my $daemonize_mysqld = 0;
my $debug_d = "d";
my $exe_ndbmtd_counter = 0;
my $tmpdir_path_updated= 0;
my $source_dist = 0;
my $shutdown_report = 0;
my $valgrind_reports = 0;
my @valgrind_args;
# Storage for changed environment variables
my %old_env;
my %visited_suite_names;
# Global variables
our $opt_client_dbx;
our $opt_client_ddd;
our $opt_client_debugger;
our $opt_client_gdb;
our $opt_client_lldb;
our $opt_ctest_report;
our $opt_dbx;
our $opt_ddd;
our $opt_debug;
our $opt_debug_server;
our $opt_debugger;
our $opt_force;
our $opt_gcov;
our $opt_gdb;
our $opt_gdb_secondary_engine;
our $opt_gprof;
our $opt_lldb;
our $opt_manual_boot_gdb;
our $opt_manual_dbx;
our $opt_manual_ddd;
our $opt_manual_debug;
our $opt_manual_gdb;
our $opt_manual_lldb;
our $opt_no_skip;
our $opt_record;
our $opt_report_unstable_tests;
our $opt_skip_combinations;
our $opt_suites;
our $opt_suite_opt;
our $opt_summary_report;
our $opt_vardir;
our $opt_xml_report;
our $ports_per_thread = 30;
#
# Suites run by default (i.e. when invoking ./mtr without parameters)
#
our @DEFAULT_SUITES = qw(
auth_sec
binlog
binlog_gtid
binlog_nogtid
clone
collations
connection_control
encryption
federated
funcs_2
gcol
gis
information_schema
innodb
innodb_fts
innodb_gis
innodb_undo
innodb_zip
interactive_utilities
json
main
opt_trace
parts
perfschema
query_rewrite_plugins
rpl
rpl_gtid
rpl_nogtid
secondary_engine
service_status_var_registration
service_sys_var_registration
service_udf_registration
sys_vars
sysschema
test_service_sql_api
test_services
x
component_keyring_file
);
our $DEFAULT_SUITES = join ',', @DEFAULT_SUITES;
# End of list of default suites
our $opt_big_test = 0;
our $opt_check_testcases = 1;
our $opt_clean_vardir = $ENV{'MTR_CLEAN_VARDIR'};
our $opt_ctest = env_or_val(MTR_UNIT_TESTS => -1);
our $opt_fast = 0;
our $opt_gcov_err = "mysql-test-gcov.err";
our $opt_gcov_exe = "gcov";
our $opt_gcov_msg = "mysql-test-gcov.msg";
our $opt_hypergraph = 0;
our $opt_keep_ndbfs = 0;
our $opt_mem = $ENV{'MTR_MEM'} ? 1 : 0;
our $opt_only_big_test = 0;
our $opt_parallel = $ENV{MTR_PARALLEL};
our $opt_quiet = $ENV{'MTR_QUIET'} || 0;
our $opt_repeat = 1;
our $opt_report_times = 0;
our $opt_resfile = $ENV{'MTR_RESULT_FILE'} || 0;
our $opt_test_progress = 1;
our $opt_sanitize = 0;
our $opt_shutdown_timeout = $ENV{MTR_SHUTDOWN_TIMEOUT} || 20; # seconds
our $opt_start_timeout = $ENV{MTR_START_TIMEOUT} || 180; # seconds
our $opt_user = "root";
our $opt_valgrind = 0;
our $opt_valgrind_secondary_engine = 0;
our $opt_verbose = 0;
# Visual Studio produces executables in different sub-directories
# based on the configuration used to build them. To make life easier,
# an environment variable or command-line option may be specified to
# control which set of executables will be used by the test suite.
our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
our $opt_warnings = 1;
our @opt_cases;
our @opt_combinations;
our @opt_extra_bootstrap_opt;
our @opt_extra_mysqld_opt;
our @opt_extra_mysqltest_opt;
our @opt_mysqld_envs;
our $basedir;
our $bindir;
our $build_thread_id_dir;
our $build_thread_id_file;
our $config; # The currently running config
our $debug_compiled_binaries;
our $default_vardir;
our $excluded_string;
our $exe_libtool;
our $exe_mysql;
our $exe_mysql_ssl_rsa_setup;
our $exe_mysql_migrate_keyring;
our $exe_mysql_keyring_encryption_test;
our $exe_mysqladmin;
our $exe_mysqltest;
our $exe_openssl;
our $glob_mysql_test_dir;
our $mysql_version_extra;
our $mysql_version_id;
our $num_tests_for_report; # for test-progress option
our $path_charsetsdir;
our $path_client_bindir;
our $path_client_libdir;
our $path_current_testlog;
our $path_language;
our $path_testlog;
our $secondary_engine_plugin_dir;
our $start_only;
our $glob_debugger = 0;
our $group_replication = 0;
our $ndbcluster_enabled = 0;
our $ndbcluster_only = $ENV{'MTR_NDB_ONLY'} || 0;
our $mysqlbackup_enabled = 0;
our @share_locations;
our %gprof_dirs;
our %logs;
our %mysqld_variables;
# This section is used to declare constants
use constant { MYSQLTEST_PASS => 0,
MYSQLTEST_FAIL => 1,
MYSQLTEST_SKIPPED => 62,
MYSQLTEST_NOSKIP_PASS => 63,
MYSQLTEST_NOSKIP_FAIL => 64 };
sub check_timeout ($) { return testcase_timeout($_[0]) / 10; }
sub suite_timeout { return $opt_suite_timeout * 60; }
sub using_extern { return (keys %opts_extern > 0); }
# Return list of specific servers
sub _like { return $config ? $config->like($_[0]) : (); }
sub mysqlds { return _like('mysqld.'); }
sub ndbds { return _like('cluster_config.ndbd.'); }
sub ndb_mgmds { return _like('cluster_config.ndb_mgmd.'); }
sub clusters { return _like('mysql_cluster.'); }
sub all_servers { return (mysqlds(), ndb_mgmds(), ndbds()); }
# Return an object which refers to the group named '[mysqld]'
# from the my.cnf file. Options specified in the section can
# be accessed using it.
sub mysqld_group { return $config ? $config->group('mysqld') : (); }
sub testcase_timeout ($) {
my ($tinfo) = @_;
if (exists $tinfo->{'case-timeout'}) {
# Return test specific timeout if *longer* that the general timeout
my $test_to = $tinfo->{'case-timeout'};
# Double the testcase timeout for sanitizer (ASAN/UBSAN) runs
$test_to *= 2 if $opt_sanitize;
# Multiply the testcase timeout by 10 for valgrind runs
$test_to *= 10 if $opt_valgrind;
return $test_to * 60 if $test_to > $opt_testcase_timeout;
}
return $opt_testcase_timeout * 60;
}
BEGIN {
# Check that mysql-test-run.pl is started from mysql-test/
unless (-f "mysql-test-run.pl") {
print "**** ERROR **** ",
"You must start mysql-test-run from the mysql-test/ directory\n";
exit(1);
}
# Check that lib exist
unless (-d "lib/") {
print "**** ERROR **** ", "Could not find the lib/ directory \n";
exit(1);
}
}
END {
my $current_id = $$;
if ($parent_pid && $current_id == $parent_pid) {
remove_redundant_thread_id_file_locations();
clean_unique_id_dir();
}
if (defined $opt_tmpdir_pid and $opt_tmpdir_pid == $$) {
if (!$opt_start_exit) {
# Remove the tempdir this process has created
mtr_verbose("Removing tmpdir $opt_tmpdir");
rmtree($opt_tmpdir);
} else {
mtr_warning(
"tmpdir $opt_tmpdir should be removed after the server has finished");
}
}
}
select(STDERR);
$| = 1; # Automatically flush STDERR - output should be in sync with STDOUT
select(STDOUT);
$| = 1; # Automatically flush STDOUT
main();
sub main {
# Default, verbosity on
report_option('verbose', 0);
# This is needed for test log evaluation in "gen-build-status-page"
# in all cases where the calling tool does not log the commands directly
# before it executes them, like "make test-force-pl" in RPM builds.
mtr_report("Logging: $0 ", join(" ", @ARGV));
command_line_setup();
# Create build thread id directory
create_unique_id_dir();
$build_thread_id_file = "$build_thread_id_dir/" . $$ . "_unique_ids.log";
open(FH, ">>", $build_thread_id_file) or
die "Can't open file $build_thread_id_file: $!";
print FH "# Unique id file paths\n";
close(FH);
# --help will not reach here, so now it's safe to assume we have binaries
My::SafeProcess::find_bin($bindir, $path_client_bindir);
$secondary_engine_support =
($secondary_engine_support and find_secondary_engine($bindir)) ? 1 : 0;
if ($secondary_engine_support) {
check_secondary_engine_features(using_extern());
# Append secondary engine test suite to list of default suites if found.
add_secondary_engine_suite();
}
if ($opt_gcov) {
gcov_prepare($basedir);
}
if ($opt_lock_order) {
lock_order_prepare($bindir);
}
if ($opt_accept_fail and not $opt_force) {
$opt_force = 1;
mtr_report("accept-test-fail turned on: enabling --force");
}
# Collect test cases from a file and put them into '@opt_cases'.
if ($opt_do_test_list) {
collect_test_cases_from_list(\@opt_cases, $opt_do_test_list, \$opt_ctest);
}
my $suite_set;
if ($opt_suites) {
# Collect suite set if passed through the MTR command line
if ($opt_suites =~ /^default$/i) {
$suite_set = 0;
} elsif ($opt_suites =~ /^non[-]default$/i) {
$suite_set = 1;
} elsif ($opt_suites =~ /^all$/i) {
$suite_set = 2;
}
} else {
# Use all suites(suite set 2) in case the suite set isn't explicitly
# specified and :-
# a) A PREFIX or REGEX is specified using the --do-suite option
# b) Test cases are passed on the command line
# c) The --do-test or --do-test-list options are used
#
# If none of the above are used, use the default suite set (i.e.,
# suite set 0)
$suite_set = ($opt_do_suite or
@opt_cases or
$::do_test or
$opt_do_test_list
) ? 2 : 0;
}
# Ignore the suite set parameter in case a list of suites is explicitly
# given
if (defined $suite_set) {
mtr_print(
"Using '" . ("default", "non-default", "all")[$suite_set] . "' suites")
if @opt_cases;
if ($suite_set == 0) {
# Run default set of suites
$opt_suites = $DEFAULT_SUITES;
} else {
# Include the main suite by default when suite set is 'all'
# since it does not have a directory structure like:
# mysql-test/<suite_name>/[<t>,<r>,<include>]
$opt_suites = ($suite_set == 2) ? "main" : "";
# Scan all sub-directories for available test suites.
# The variable $opt_suites is updated by get_all_suites()
find(\&get_all_suites, "$glob_mysql_test_dir");
find({ wanted => \&get_all_suites, follow => 1 }, "$basedir/internal")
if (-d "$basedir/internal");
if ($suite_set == 1) {
# Run only with non-default suites
for my $suite (split(",", $DEFAULT_SUITES)) {
for ("$suite", "i_$suite") {
remove_suite_from_list($_);
}
}
}
# Remove cluster test suites if ndb cluster is not enabled
if (not $ndbcluster_enabled) {
for my $suite (split(",", $opt_suites)) {
next if not $suite =~ /ndb/;
remove_suite_from_list($suite);
}
}
# Remove secondary engine test suites if not supported
if (defined $::secondary_engine and not $secondary_engine_support) {
for my $suite (split(",", $opt_suites)) {
next if not $suite =~ /$::secondary_engine/;
remove_suite_from_list($suite);
}
}
}
}
my $mtr_suites = $opt_suites;
# Skip suites which don't match the --do-suite filter
if ($opt_do_suite) {
my $opt_do_suite_reg = init_pattern($opt_do_suite, "--do-suite");
for my $suite (split(",", $opt_suites)) {
if ($opt_do_suite_reg and not $suite =~ /$opt_do_suite_reg/) {
remove_suite_from_list($suite);
}
}
# Removing ',' at the end of $opt_suites if exists
$opt_suites =~ s/,$//;
}
if ($opt_skip_sys_schema) {
remove_suite_from_list("sysschema");
}
if ($opt_suites) {
# Remove extended suite if the original suite is already in
# the suite list
for my $suite (split(",", $opt_suites)) {
if ($suite =~ /^i_(.*)/) {
my $orig_suite = $1;
if ($opt_suites =~ /,$orig_suite,/ or
$opt_suites =~ /^$orig_suite,/ or
$opt_suites =~ /^$orig_suite$/ or
$opt_suites =~ /,$orig_suite$/) {
remove_suite_from_list($suite);
}
}
}
# Finally, filter out duplicate suite names if present,
# i.e., using `--suite=ab,ab mytest` should not end up
# running ab.mytest twice.
my %unique_suites = map { $_ => 1 } split(",", $opt_suites);
$opt_suites = join(",", sort keys %unique_suites);
if (@opt_cases) {
mtr_verbose("Using suite(s): $opt_suites");
} else {
mtr_report("Using suite(s): $opt_suites");
}
} else {
if ($opt_do_suite) {
mtr_error("The PREFIX/REGEX '$opt_do_suite' doesn't match any of " .
"'$mtr_suites' suite(s)");
}
}
# Environment variable to hold number of CPUs
my $sys_info = My::SysInfo->new();
$ENV{NUMBER_OF_CPUS} = $sys_info->num_cpus();
if ($opt_parallel eq "auto") {
# Try to find a suitable value for number of workers
$opt_parallel = $ENV{NUMBER_OF_CPUS};
if (defined $ENV{MTR_MAX_PARALLEL}) {
my $max_par = $ENV{MTR_MAX_PARALLEL};
$opt_parallel = $max_par if ($opt_parallel > $max_par);
}
$opt_parallel = 1 if ($opt_parallel < 1);
}
init_timers();
mtr_report("Collecting tests");
my $tests = collect_test_cases($opt_reorder, $opt_suites,
\@opt_cases, $opt_skip_test_list);
mark_time_used('collect');
# A copy of the tests list, that will not be modified even after the tests
# are executed.
my @tests_list = @{$tests};
check_secondary_engine_option($tests) if $secondary_engine_support;
if ($opt_report_features) {
# Put "report features" as the first test to run. No result file,
# prints the output on console.
my $tinfo = My::Test->new(master_opt => [],
name => 'report_features',
path => 'include/report-features.test',
shortname => 'report_features',
slave_opt => [],
template_path => "include/default_my.cnf",);
unshift(@$tests, $tinfo);
}
my $secondary_engine_suite = 0;
if (defined $::secondary_engine and $secondary_engine_support) {
foreach(@$tests) {
if ($_->{name} =~ /^$::secondary_engine/) {
$secondary_engine_suite = 1;
last;
}
}
}
if (!$secondary_engine_suite) {
$secondary_engine_support = 0;
}
my $num_tests = @$tests;
if ($num_tests == 0) {
mtr_report("No tests found, terminating");
exit(0);
}
initialize_servers();
# Run unit tests in parallel with the same number of workers as
# specified to MTR.
$ctest_parallel = $opt_parallel;
# Limit parallel workers to the number of regular tests to avoid
# idle workers.
$opt_parallel = $num_tests if $opt_parallel > $num_tests;
$ENV{MTR_PARALLEL} = $opt_parallel;
mtr_report("Using parallel: $opt_parallel");
my $is_option_mysqlx_port_set = $opt_mysqlx_baseport ne "auto";
if ($opt_parallel > 1) {
if ($opt_start_exit || $opt_stress || $is_option_mysqlx_port_set) {
mtr_warning("Parallel cannot be used neither with --start-and-exit nor",
"--stress nor --mysqlx_port.\nSetting parallel value to 1.");
$opt_parallel = 1;
}
}
$num_tests_for_report = $num_tests;
# Shutdown report is one extra test created to report
# any failures or crashes during shutdown.
$num_tests_for_report = $num_tests_for_report + 1;
# When either --valgrind or --sanitize option is enabled, a dummy
# test is created.
if ($opt_valgrind_mysqld or $opt_sanitize) {
$num_tests_for_report = $num_tests_for_report + 1;
}
# Please note, that disk_usage() will print a space to separate its
# information from the preceding string, if the disk usage report is
# enabled. Otherwise an empty string is returned.
my $disk_usage = disk_usage();
if ($disk_usage) {
mtr_report(sprintf("Disk usage of vardir in MB:%s", $disk_usage));
}
# Create server socket on any free port
my $server = new IO::Socket::INET(Listen => $opt_parallel,
LocalAddr => 'localhost',
Proto => 'tcp',);
mtr_error("Could not create testcase server port: $!") unless $server;
my $server_port = $server->sockport();
if ($opt_resfile) {
resfile_init("$opt_vardir/mtr-results.txt");
print_global_resfile();
}
if ($secondary_engine_support) {
secondary_engine_offload_count_report_init();
# Create virtual environment
create_virtual_env($bindir);
reserve_secondary_ports();
}
if ($opt_summary_report) {
mtr_summary_file_init($opt_summary_report);
}
if ($opt_xml_report) {
mtr_xml_init($opt_xml_report);
}
# Read definitions from include/plugin.defs
read_plugin_defs("include/plugin.defs", 0);
# Also read from plugin.defs files in internal and internal/cloud if they exist
my @plugin_defs = ("$basedir/internal/mysql-test/include/plugin.defs",
"$basedir/internal/cloud/mysql-test/include/plugin.defs");
for my $plugin_def (@plugin_defs) {
read_plugin_defs($plugin_def) if -e $plugin_def;
}
# Simplify reference to semisync plugins
$ENV{'SEMISYNC_PLUGIN_OPT'} = $ENV{'SEMISYNC_SOURCE_PLUGIN_OPT'};
if (IS_WINDOWS) {
$ENV{'PLUGIN_SUFFIX'} = "dll";
} else {
$ENV{'PLUGIN_SUFFIX'} = "so";
}
if ($group_replication) {
$ports_per_thread = $ports_per_thread + 10;
}
if ($secondary_engine_support) {
# Reserve 10 extra ports per worker process
$ports_per_thread = $ports_per_thread + 10;
}
create_manifest_file();
# Create child processes
my %children;
$parent_pid = $$;
for my $child_num (1 .. $opt_parallel) {
my $child_pid = My::SafeProcess::Base::_safe_fork();
if ($child_pid == 0) {
$server = undef; # Close the server port in child
$tests = {}; # Don't need the tests list in child
# Use subdir of var and tmp unless only one worker
if ($opt_parallel > 1) {
set_vardir("$opt_vardir/$child_num");
$opt_tmpdir = "$opt_tmpdir/$child_num";
$tmpdir_path_updated = 1;
}
init_timers();
run_worker($server_port, $child_num);
exit(1);
}
$children{$child_pid} = 1;
}
mtr_print_header($opt_parallel > 1);
mark_time_used('init');
my $completed = run_test_server($server, $tests, $opt_parallel);
exit(0) if $opt_start_exit;
# Send Ctrl-C to any children still running
kill("INT", keys(%children));
if (!IS_WINDOWS) {
# Wait for children to exit
foreach my $pid (keys %children) {
my $ret_pid = waitpid($pid, 0);
if ($ret_pid != $pid) {
mtr_report("Unknown process $ret_pid exited");
} else {
delete $children{$ret_pid};
}
}
}
# Remove config files for components
read_plugin_defs("include/plugin.defs", 1);
for my $plugin_def (@plugin_defs) {
read_plugin_defs($plugin_def, 1) if -e $plugin_def;
}
remove_manifest_file();
if (not $completed) {
mtr_error("Test suite aborted");
}
if (@$completed != $num_tests) {
# Not all tests completed, failure
mtr_print_line();
mtr_report(int(@$completed), " of $num_tests test(s) completed.");
foreach (@tests_list) {
$_->{key} = "$_" unless defined $_->{key};
}
my %is_completed_map = map { $_->{key} => 1 } @$completed;
my @not_completed;
foreach (@tests_list) {
if (!exists $is_completed_map{$_->{key}}) {
push (@not_completed, $_->{name});
}
}
if (int(@not_completed) <= 100) {
mtr_report("Not all tests completed:", join(" ", @not_completed));
} else {
mtr_report("Not all tests completed:", join(" ", @not_completed[0...49]), "... and", int(@not_completed)-50, "more");
}
mtr_report();
if(int(@$completed)) {
mtr_report_stats("In completed tests", $completed);
}
mtr_error("No test(s) completed");
}
mark_time_used('init');
push @$completed, run_ctest() if $opt_ctest;
# Create minimalistic "test" for the reporting failures at shutdown
my $tinfo = My::Test->new(name => 'shutdown_report',
shortname => 'shutdown_report',);
# Set dummy worker id to align report with normal tests
$tinfo->{worker} = 0 if $opt_parallel > 1;
if ($shutdown_report) {
$tinfo->{result} = 'MTR_RES_FAILED';
$tinfo->{comment} = "Mysqld reported failures at shutdown, see above";
$tinfo->{failures} = 1;
} else {
$tinfo->{result} = 'MTR_RES_PASSED';
}
mtr_report_test($tinfo);
report_option('prev_report_length', 0);
push @$completed, $tinfo;
if ($opt_valgrind_mysqld or $opt_sanitize) {
# Create minimalistic "test" for the reporting
my $tinfo = My::Test->new(
name => $opt_valgrind_mysqld ? 'valgrind_report' : 'sanitize_report',
shortname => $opt_valgrind_mysqld ? 'valgrind_report' : 'sanitize_report',
);
# Set dummy worker id to align report with normal tests
$tinfo->{worker} = 0 if $opt_parallel > 1;
if ($valgrind_reports) {
$tinfo->{result} = 'MTR_RES_FAILED';
if ($opt_valgrind_mysqld) {
$tinfo->{comment} = "Valgrind reported failures at shutdown, see above";
} else {
$tinfo->{comment} =
"Sanitizer reported failures at shutdown, see above";
}
$tinfo->{failures} = 1;
} else {
$tinfo->{result} = 'MTR_RES_PASSED';
}
mtr_report_test($tinfo);
report_option('prev_report_length', 0);
push @$completed, $tinfo;
}
if ($opt_quiet) {
my $last_test = $completed->[-1];
mtr_report() if !$last_test->is_failed();
}
mtr_print_line();
if ($opt_gcov) {
gcov_collect($bindir, $opt_gcov_exe, $opt_gcov_msg, $opt_gcov_err);
}
if ($ctest_report) {
print "$ctest_report\n";
mtr_print_line();
}
# Cleanup the build thread id files
remove_redundant_thread_id_file_locations();
clean_unique_id_dir();
# Cleanup the secondary engine environment
if ($secondary_engine_support) {
clean_virtual_env();
}
print_total_times($opt_parallel) if $opt_report_times;
mtr_report_stats("Completed", $completed, $opt_accept_fail);
remove_vardir_subs() if $opt_clean_vardir;
exit(0);
}
# The word server here refers to the main control loop of MTR, not a
# mysqld server. Worker threads have already been started when this sub
# is called. The main loop wakes up once every second and checks for new
# messages from the workers. After some special handling of new/closed
# connections, the bulk of the loop is handling the different messages.
#
# The message starts with a codeword, which can be 'TESTRESULT',
# 'START', 'SPENT' or 'VALGREP'.
#
# After 'TESTRESULT' or 'START', the master thread finds the next test
# to run by this worker. It also contains the logic to find a more
# optimal ordering of tests per worker in order to reduce number of
# restarts. When a test has been identified, it's sent to the worker
# with a message tagged 'TESTCASE'.
#
# When all tests are completed or if we abort test runs early, a message
# 'BYE' is sent to the worker.
sub run_test_server ($$$) {
my ($server, $tests, $childs) = @_;
my $num_failed_test = 0; # Number of tests failed so far
my %saved_cores_paths; # Paths of core files found in vardir/log/ so far
my $num_saved_datadir = 0; # Number of datadirs saved in vardir/log/ so far.
# Scheduler variables
my $max_ndb = $ENV{MTR_MAX_NDB} || $childs / 2;
$max_ndb = $childs if $max_ndb > $childs;
$max_ndb = 1 if $max_ndb < 1;
my $num_ndb_tests = 0;
my %running;
my $result;
my $completed_wid_count = 0;
my $non_parallel_tests = [];
my %closed_sock;
my $suite_timeout = start_timer(suite_timeout());
my $s = IO::Select->new();
$s->add($server);
while (1) {
mark_time_used('admin');
# # Wake up once every second
my @ready = $s->can_read(1);
mark_time_idle();
foreach my $sock (@ready) {
if ($sock == $server) {
# New client connected
my $child = $sock->accept();
mtr_verbose("Client connected");
$s->add($child);
print $child "HELLO\n";
} else {
my $line = <$sock>;
if (!defined $line) {
# Client disconnected
mtr_verbose("Child closed socket");
$s->remove($sock);
if (--$childs == 0) {
report_option('prev_report_length', 0);