-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathmysql-test-run.pl
executable file
·7050 lines (5911 loc) · 228 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, 2018, Oracle and/or its affiliates. All rights reserved.
#
# 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 also distributed 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 included with MySQL.
#
# 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 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_misc.pl";
require "lib/mtr_process.pl";
$SIG{INT} = sub { mtr_error("Got ^C signal"); };
sub env_or_val($$) { defined $ENV{ $_[0] } ? $ENV{ $_[0] } : $_[1] }
# Local variables
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_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_ps_protocol;
my $opt_report_features;
my $opt_skip_core;
my $opt_skip_ssl;
my $opt_sleep;
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_stress;
my $opt_suites;
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_ctest_timeout = $ENV{MTR_CTEST_TIMEOUT} || 120; # seconds
my $opt_debug_sync_timeout = 600; # Default timeout for WAIT_FOR actions.
my $opt_discover = 0;
my $opt_do_test_list = "";
my $opt_force_restart = 0;
my $opt_include_ndbcluster = 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_reorder = 1;
my $opt_retry = 3;
my $opt_retry_failure = env_or_val(MTR_RETRY_FAILURE => 2);
my $opt_shutdown_timeout = $ENV{MTR_SHUTDOWN_TIMEOUT} || 10; # seconds
my $opt_skip_ndbcluster = 0;
my $opt_skip_sys_schema = 0;
my $opt_start_timeout = $ENV{MTR_START_TIMEOUT} || 180; # seconds
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_skip_test_list;
# 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 $config; # The currently running config
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; # Unix formatted opt_vardir for trace files
my $DEFAULT_SUITES =
"main,sys_vars,binlog,binlog_gtid,binlog_nogtid,federated,gis,rpl,rpl_gtid,rpl_nogtid,innodb,innodb_gis,innodb_fts,innodb_zip,innodb_undo,perfschema,funcs_1,opt_trace,parts,auth_sec,query_rewrite_plugins,gcol,sysschema,test_service_sql_api,json,connection_control,test_services,collations,service_udf_registration,service_sys_var_registration,service_status_var_registration,x";
my $build_thread = 0;
my $daemonize_mysqld = 0;
my $debug_d = "d";
my $exe_ndbmtd_counter = 0;
my $ports_per_thread = 10;
my $source_dist = 0;
my $valgrind_reports = 0;
my @valgrind_args;
my %mysqld_logs;
# Storage for changed environment variables
my %old_env;
# 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_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_non_parallel_test;
our $opt_record;
our $opt_report_unstable_tests;
our $opt_ssl;
our $opt_ssl_supported;
our $opt_suite_opt;
our $opt_summary_report;
our $opt_vardir;
our $opt_xml_report;
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_mem = $ENV{'MTR_MEM'} ? 1 : 0;
our $opt_only_big_test = 0;
our $opt_parallel = $ENV{MTR_PARALLEL};
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_user = "root";
our $opt_valgrind = 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_experimentals;
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 $debug_compiled_binaries;
our $default_vardir;
our $excluded_string;
our $exe_libtool;
our $exe_mysql;
our $exe_mysql_ssl_rsa_setup;
our $exe_mysqladmin;
our $exe_mysqltest;
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 $start_only;
our $experimental_test_cases = [];
our $glob_debugger = 0;
our $group_replication = 0;
our $ndbcluster_enabled = 0;
our $xplugin = 0;
our @share_locations;
our %gprof_dirs;
our %mysqld_variables;
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 memcacheds { return _like('memcached.'); }
sub all_servers { return (mysqlds(), ndb_mgmds(), ndbds(), memcacheds()); }
# 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'};
$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 {
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(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();
if ($opt_gcov) {
gcov_prepare($basedir);
}
# 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);
}
if (!$opt_suites) {
$opt_suites = $DEFAULT_SUITES;
}
if ($opt_skip_sys_schema) {
$opt_suites =~ s/,sysschema//;
}
my $mtr_suites = $opt_suites;
# Skip the suites that doesn't match --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/) {
$opt_suites =~ s/$suite,?//;
}
}
# Removing ',' at the end of $opt_suites if exists
$opt_suites =~ s/,$//;
}
if ($opt_suites) {
mtr_report("Using suites: $opt_suites") unless @opt_cases;
} 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');
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);
}
initialize_servers();
my $num_tests = @$tests;
# Limit parallel workers to number of tests to avoid idle workers
$opt_parallel = $num_tests if ($num_tests > 0 and $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;
}
}
if ($opt_parallel == 1) {
$num_tests_for_report = $num_tests * $opt_repeat;
} else {
$num_tests_for_report = $num_tests;
}
# 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 ($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");
# Also read from any plugin local or suite specific plugin.defs
my $plugin_def =
"$basedir/plugin/*/tests/mtr/plugin.defs " .
"$basedir/internal/plugin/*/tests/mtr/plugin.defs " .
"$basedir/rapid/plugin/*/tests/mtr/plugin.defs " .
"$basedir/components/*/tests/mtr/plugin.defs " . "suite/*/plugin.defs";
for (glob $plugin_def) {
read_plugin_defs($_);
}
# Simplify reference to semisync plugins
$ENV{'SEMISYNC_PLUGIN_OPT'} = $ENV{'SEMISYNC_MASTER_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 ($xplugin) {
$ports_per_thread = $ports_per_thread + 10;
}
# Create child processes
my %children;
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";
}
init_timers();
run_worker($server_port, $child_num);
exit(1);
}
$children{$child_pid} = 1;
}
mtr_report();
mtr_print_thick_line();
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};
}
}
}
if (not $completed) {
mtr_error("Test suite aborted");
}
if (@$completed != $num_tests) {
# Not all tests completed, failure
mtr_report();
mtr_report("Only ", int(@$completed), " of $num_tests completed.");
mtr_error("Not all tests completed");
}
mark_time_used('init');
push @$completed, run_ctest() if $opt_ctest;
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);
push @$completed, $tinfo;
}
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();
print_total_times($opt_parallel) if $opt_report_times;
mtr_report_stats("Completed", $completed);
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 $num_saved_cores = 0; # Number of core files saved in vardir/log/ so far.
my $num_saved_datadir = 0; # Number of datadirs saved in vardir/log/ so far.
# Used as hint to CoreDump
my $exe_mysqld = find_mysqld($basedir) || "";
# 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 $completed = [];
my %running;
my $result;
my $completed_wid_count = 0;
my $non_parallel_tests = [];
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) {
return $completed;
}
next;
}
chomp($line);
if ($line eq 'TESTRESULT') {
$result = My::Test::read_test($sock);
# Report test status
mtr_report_test($result);
if ($result->is_failed()) {
# Save the workers "savedir" in var/log
my $worker_savedir = $result->{savedir};
my $worker_savename = basename($worker_savedir);
my $savedir = "$opt_vardir/log/$worker_savename";
if ($opt_max_save_datadir > 0 &&
$num_saved_datadir >= $opt_max_save_datadir) {
mtr_report(" - skipping '$worker_savedir/'");
rmtree($worker_savedir);
} else {
rename($worker_savedir, $savedir) if $worker_savedir ne $savedir;
# Look for the test log file and put that in savedir location
my $logfile = "$result->{shortname}" . ".log";
my $logfilepath = dirname($worker_savedir) . "/" . $logfile;
move($logfilepath, $savedir);
if ($opt_check_testcases && !defined $result->{'result_file'}) {
mtr_report("Mysqltest client output from logfile");
mtr_report("----------- MYSQLTEST OUTPUT START -----------\n");
mtr_printfile($savedir . "/" . $logfile);
mtr_report("\n------------ MYSQLTEST OUTPUT END -----------\n");
}
mtr_report(" - the logfile can be found in '$savedir/$logfile'");
# Move any core files from e.g. mysqltest
foreach my $coref (glob("core*"), glob("*.dmp")) {
mtr_report(" - found '$coref', moving it to '$savedir'");
move($coref, $savedir);
}
if ($opt_max_save_core > 0) {
# Limit number of core files saved
find(
{ no_chdir => 1,
wanted => sub {
my $core_file = $File::Find::name;
my $core_name = basename($core_file);
# Name beginning with core, not ending in .gz
if (($core_name =~ /^core/ and $core_name !~ /\.gz$/) or
(IS_WINDOWS and $core_name =~ /\.dmp$/)) {
# Ending with .dmp
mtr_report(" - found '$core_name'",
"($num_saved_cores/$opt_max_save_core)");
My::CoreDump->show($core_file, $exe_mysqld,
$opt_parallel);
if ($num_saved_cores >= $opt_max_save_core) {
mtr_report(" - deleting it, already saved",
"$opt_max_save_core");
unlink("$core_file");
} else {
mtr_compress_file($core_file) unless @opt_cases;
}
++$num_saved_cores;
}
}
},
$savedir);
}
}
resfile_print_test();
$num_saved_datadir++;
$num_failed_test++
unless ($result->{retries} ||
$result->{exp_fail});
if (!$opt_force) {
# Test has failed, force is off
push(@$completed, $result);
return $completed unless $result->{'dont_kill_server'};
# Prevent kill of server, to get valgrind report
print $sock "BYE\n";
next;
} elsif ($opt_max_test_fail > 0 and
$num_failed_test >= $opt_max_test_fail) {
push(@$completed, $result);
mtr_report_stats("Too many failed", $completed, 1);
mtr_report("Too many tests($num_failed_test) failed!",
"Terminating...");
return undef;
}
}
resfile_print_test();
# Retry test run after test failure
my $retries = $result->{retries} || 2;
my $test_has_failed = $result->{failures} || 0;
if ($test_has_failed and $retries <= $opt_retry) {
# Test should be run one more time unless it has failed
# too many times already
my $tname = $result->{name};
my $failures = $result->{failures};
if ($opt_retry > 1 and $failures >= $opt_retry_failure) {
mtr_report("\nTest $tname has failed $failures times,",
"no more retries!\n");
} else {
mtr_report("\nRetrying test $tname, " .
"attempt($retries/$opt_retry)...\n");
delete($result->{result});
$result->{retries} = $retries + 1;
$result->write_test($sock, 'TESTCASE');
next;
}
}
# Tests are already duplicated in the list if parallel value is
# greater than 1. Following code is needed only when parallel
# value is 1.
if ($opt_parallel == 1) {
# Repeat the test $opt_repeat number of times
my $repeat = $result->{repeat} || 1;
# Don't repeat if test was skipped
if ($repeat < $opt_repeat &&
$result->{'result'} ne 'MTR_RES_SKIPPED') {
$result->{retries} = 0;
$result->{rep_failures}++ if $result->{failures};
$result->{failures} = 0;
delete($result->{result});
$result->{repeat} = $repeat + 1;
$result->write_test($sock, 'TESTCASE');
next;
}
}
# Remove from list of running
mtr_error("'", $result->{name}, "' is not known to be running")
unless delete $running{ $result->key() };
# Update scheduler variables
$num_ndb_tests-- if ($result->{ndb_test});
# Save result in completed list
push(@$completed, $result);
} elsif ($line eq 'START') {
# 'START' is the initial message from a new worker, send first test
;
} elsif ($line =~ /^SPENT/) {
# 'SPENT' comes with numbers for how much time the worker spent in
# various phases of execution, to be used when 'report-times' option
# is enabled.
add_total_times($line);
} elsif ($line eq 'VALGREP' && ($opt_valgrind or $opt_sanitize)) {
# 'VALGREP' means that the worker found some valgrind reports in the
# server logs. This will cause the master to flag the pseudo test
# valgrind_report as failed.
$valgrind_reports = 1;
} else {
# Unknown message from worker
mtr_error("Unknown response: '$line' from client");
}
# Find next test to schedule
# - Try to use same configuration as worker used last time
# - Limit number of parallel ndb tests
my $next;
my $second_best;
for (my $i = 0 ; $i <= @$tests ; $i++) {
my $t = $tests->[$i];
last unless defined $t;
if (run_testcase_check_skip_test($t)) {
# Move the test to completed list
push(@$completed, splice(@$tests, $i, 1));
# Since the test at pos $i was taken away, next
# test will also be at $i -> redo
redo;
}
# Create a separate list for tests sourcing 'not_parallel.inc'
# include file.
if ($t->{'not_parallel'}) {
push(@$non_parallel_tests, splice(@$tests, $i, 1));
# Search for the next available test.
redo;
}
# Limit number of parallell NDB tests
if ($t->{ndb_test} and $num_ndb_tests >= $max_ndb) {
next;
}
# Second best choice is the first that does not fulfill
# any of the above conditions
if (!defined $second_best) {
$second_best = $i;
}
# Smart allocation of next test within this thread.
if ($opt_reorder and $opt_parallel > 1 and defined $result) {
my $wid = $result->{worker};
# Reserved for other thread, try next
next if (defined $t->{reserved} and $t->{reserved} != $wid);
if (!defined $t->{reserved}) {
# Force-restart not relevant when comparing *next* test
$t->{criteria} =~ s/force-restart$/no-restart/;
my $criteria = $t->{criteria};
# Reserve similar tests for this worker, but not too many
my $maxres = (@$tests - $i) / $opt_parallel + 1;
for (my $j = $i + 1 ; $j <= $i + $maxres ; $j++) {
my $tt = $tests->[$j];
last unless defined $tt;
last if $tt->{criteria} ne $criteria;
$tt->{reserved} = $wid;
}
}
}
# At this point we have found next suitable test
$next = splice(@$tests, $i, 1);
last;
}
# Use second best choice if no other test has been found
if (!$next and defined $second_best) {
mtr_error("Internal error, second best too large($second_best)")
if $second_best > $#$tests;
$next = splice(@$tests, $second_best, 1);
delete $next->{reserved};
}
if ($next) {
# We don't need this any more
delete $next->{criteria};
$next->write_test($sock, 'TESTCASE');
$running{ $next->key() } = $next;
$num_ndb_tests++ if ($next->{ndb_test});
} else {
# Keep track of the number of child processes completed. Last
# one will be used to run the non-parallel tests at the end.
if ($completed_wid_count < $opt_parallel) {
$completed_wid_count++;
}
# Check if there exist any non-parallel tests which should
# be run using the last active worker process.
if (int(@$non_parallel_tests) > 0 and
$completed_wid_count == $opt_parallel) {
# Fetch the next test to run from non_parallel_tests list
$next = shift @$non_parallel_tests;
# We don't need this any more
delete $next->{criteria};
$next->write_test($sock, 'TESTCASE');
$running{ $next->key() } = $next;
$num_ndb_tests++ if ($next->{ndb_test});
} else {
# No more test, tell child to exit
print $sock "BYE\n";
}
}
}
}
# Check if test suite timer expired
if (has_expired($suite_timeout)) {
mtr_report_stats("Timeout", $completed, 1);
mtr_report("Test suite timeout! Terminating...");
return undef;
}
}
}
# This is the main loop for the worker thread (which, as mentioned, is
# actually a separate process except on Windows).
#
# Its main loop reads messages from the main thread, which are either
# 'TESTCASE' with details on a test to run (also read with
# My::Test::read_test()) or 'BYE' which will make the worker clean up
# and send a 'SPENT' message. If running with valgrind, it also looks
# for valgrind reports and sends 'VALGREP' if any were found.