Debian Codegraph @

mysql-test/suite/rpl/extension/checksum.pl

raw
1 #!/usr/bin/perl
2
3 use File::Basename;
4 use File::Copy qw(copy);
5 use File::Spec qw(catdir);
6 use File::Path;
7 use IO::File;
8 use strict;
9
10 # Constants and variables with default values
11 my $suites;
12 my $suffix = "_checksum";
13 my $percent_random_test = 10;
14 my $mtr_script;
15 my @mtr_argv;
16 my @mtr_suites;
17
18 # Check some arguments
19 foreach my $arg ( @ARGV )
20 {
21 if ($arg =~ m/\-\-suite\=(.+)/i)
22 {
23 $suites = $1;
24 }
25 elsif ($arg =~ m/\-\-percent\=(\d{1,2})/i)
26 {
27 $percent_random_test= $1;
28 }
29 else
30 {
31 push(@mtr_argv, $arg);
32 }
33
34 }
35 if (! defined( $suites ) )
36 {
37 die("The script requires --suite argument");
38 }
39
40 print "#################################################################\n";
41 print "# Binlog checksum testing\n";
42 print "# Run randomly $percent_random_test\% of tests from following suites: $suites\n";
43 print "#################################################################\n";
44
45 # Set extension directory
46 my $ext_dir= dirname(File::Spec->rel2abs($0));
47 # Set mysql-test directory
48 my $mysql_test_dir= $ext_dir;
49 $mysql_test_dir =~ s/(\/|\\)suite(\/|\\)rpl(\/|\\)extension$//;
50
51 # Main loop
52 foreach my $src_suite (split(",", $suites))
53 {
54 $src_suite=~ s/ //g;
55 my $dest_suite= $src_suite . $suffix;
56 push( @mtr_suites, $dest_suite);
57 print "Creating suite $dest_suite\n";
58 # *** Set platform-independent pathes ***
59 # Set source directory of suite
60 my $src_suite_dir = File::Spec->catdir($mysql_test_dir, "suite", $src_suite);
61 # Set destination directory of suite
62 my $dest_suite_dir = File::Spec->catdir($mysql_test_dir, "suite", $dest_suite);
63 print "Copying files\n\tfrom '$src_suite_dir'\n\tto '$dest_suite_dir'\n";
64 dircopy($src_suite_dir, $dest_suite_dir);
65 my $test_case_dir= File::Spec->catdir($dest_suite_dir, "t");
66 # Read disabled.def
67 my %disabled = ();
68 print "Read disabled.def\n";
69 my $fh = new IO::File File::Spec->catdir($test_case_dir, "disabled.def"), "r";
70 if ( defined $fh )
71 {
72 my @lines = <$fh>;
73 undef $fh;
74 foreach my $line ( @lines )
75 {
76 if ($line =~ m/^([a-zA-Z0-9_]+).+\:.+/i)
77 {
78 $disabled{$1}= 1;
79 }
80 }
81 }
82 # Read test case list
83 my %tests = ();
84 print "Generate test case list\n";
85 opendir my ($dh), $test_case_dir or die "Could not open dir '$test_case_dir': $!";
86 for my $entry (readdir $dh)
87 {
88 if ( $entry =~ m/^([a-zA-Z0-9_]+)\.test$/i )
89 {
90 my $test= $1;
91 if ( ! defined( $disabled{$test}) )
92 {
93 $tests{$test}= 1;
94 }
95 }
96 }
97 closedir($dh);
98 #
99 my @excluded = ();
100 my $excluded_test= int((((100 - $percent_random_test)/100) * scalar( keys %tests )));
101 while ( $excluded_test > 0 )
102 {
103 my @cases = keys %tests;
104 my $test = $cases[int(rand(scalar(@cases)))];
105 push ( @excluded, $test . "\t\t: Excluded for $dest_suite\n" );
106 delete $tests{$test};
107 $excluded_test--;
108 }
109 my $fh = new IO::File File::Spec->catdir($test_case_dir, "disabled.def"), O_WRONLY|O_APPEND;
110 if (defined $fh) {
111 print $fh join ("", sort @excluded);
112 undef $fh;
113 }
114 print "\t" . join("\n\t", sort keys %tests) . "\n";
115
116 }
117
118 # Set path to mtr with arguments
119 my $mtr_script = "perl " . File::Spec->catdir($mysql_test_dir, "mysql-test-run.pl") .
120 " --suite=" . join(",", @mtr_suites) . " " .
121 " --mysqld=--binlog-checksum=CRC32 " .
122 join (" ", @mtr_argv);
123
124 print "Run $mtr_script\n";
125 system( $mtr_script );
126
127 sub dircopy
128 {
129 my ($from_dir, $to_dir)= @_;
130 mkdir $to_dir if (! -e $to_dir);
131 opendir my($dh), $from_dir or die "Could not open dir '$from_dir': $!";
132 for my $entry (readdir $dh)
133 {
134 next if $entry =~ /^(\.|\.\.)$/;
135 my $source = File::Spec->catdir($from_dir, $entry);
136 my $destination = File::Spec->catdir($to_dir, $entry);
137 if (-d $source)
138 {
139 mkdir $destination or die "mkdir '$destination' failed: $!" if not -e $destination;
140 dircopy($source, $destination);
141 }
142 else
143 {
144 copy($source, $destination) or die "copy '$source' to '$destination' failed: $!";
145 }
146 }
147 closedir $dh;
148 return;
149 }