mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / sql-bench / run-all-tests.sh
blob4e4b372b759f6e757e9960def6f5713bd805420b
1 #!/usr/bin/perl
2 # Copyright (c) 2000, 2001, 2003, 2006, 2007 MySQL AB, 2009 Sun Microsystems, Inc.
3 # Use is subject to license terms.
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Library General Public
7 # License as published by the Free Software Foundation; version 2
8 # of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Library General Public License for more details.
15 # You should have received a copy of the GNU Library General Public
16 # License along with this library; if not, write to the Free
17 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 # MA 02110-1301, USA
20 # This program runs all test that starts with 'test-' and sums
21 # the results that the program prints.
22 # Each time result should be of the form:
23 # Time for|to KEYWORD (number_of_runs) 'other info': timestr()
25 # All options to this script is passed to all test program.
26 # useful options:
27 # --fast --force --lock-tables
28 # --server ==> mysql (default) / mSQL / Pg (postgres) / Solid
29 # --user ==> the user with permission to create / drop / select
30 # --pass ==> password for the user
31 # --cmp ==> Compare --server with one of the others (mysql/mSQL/Pg/Solid)
32 # --comments ==> everything you want to say such as the extra options you
33 # gave to the db server. (use --comments="xxx xxx xxx"
34 # --machine ==> Give a OS/machine id for your logfiles.
35 # --log ==> puts output in output/RUN-server-machine-cmp-$opt_cmp
37 use DBI;
38 use Cwd;
40 $opt_silent=1; # Don't write header
42 @ORG_ARGV=@ARGV;
43 $pwd = cwd(); $pwd = "." if ($pwd eq '');
44 require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
45 $opt_silent=0;
46 $perl=$^X;
47 $machine=machine();
48 $redirect= !($machine =~ /windows/i || $machine =~ "^NT\s") ? "2>&1" : "";
49 $dir= ($pwd =~ /\\/) ? '\\' : '/'; # directory symbol for shell
51 $prog_args="";
52 foreach $arg (@ORG_ARGV)
54 if ($redirect)
56 $prog_args.="'" . $arg . "' ";
58 else
60 # Windows/NT can't handle ' around arguments
61 $prog_args.=$arg . " ";
65 $prog_count=$errors=0;
67 if ($opt_cmp) {
68 $filename = "$opt_server$opt_suffix-" . machine_part() . "-cmp-$opt_cmp";
69 } else {
70 $filename = "$opt_server$opt_suffix-" . machine_part();
73 if (! -d $opt_dir)
75 if (-e $opt_dir)
77 die "$opt_dir isn't a directory\n";
79 mkdir $opt_dir,0777 || die "Can't create directory: $opt_dir\n";
82 if ($opt_skip_test) {
83 (@skip_tests) = split(/,\s*/, $opt_skip_test);
86 if ($opt_old_headers)
88 read_headers("$opt_dir/RUN-$filename");
90 else
92 $server_version=$server->version();
95 if (!$opt_log)
97 open(LOG,">&STDOUT");
99 else
101 open(LOG, "> $opt_dir/RUN-$filename") ||
102 die "Can't write to $opt_dir/RUN-$filename: $!\n";
105 select(LOG);
106 $|=1;
108 print "Benchmark DBD suite: $benchmark_version\n";
109 print "Date of test: $date\n";
110 print "Running tests on: $machine\n";
111 print "Arguments: $log_prog_args\n";
112 print "Comments: $opt_comments\n";
113 print "Limits from: $opt_cmp\n";
114 print "Server version: $server_version\n";
115 print "Optimization: $opt_optimization\n";
116 print "Hardware: $opt_hw\n\n";
118 $estimated=$warning=$got_warning=0;
119 while (<test-*>)
121 next if (/\.sh$/); # configure script
122 next if (/\-fork$/); # test script
123 $prog_count++;
124 /test-(.*)$/; # Remove test from name
125 $prog=$1;
126 $skip_prog = 0;
127 foreach $skip_this (@skip_tests) {
128 if ($prog =~ /$skip_this/i) {
129 $skip_prog = 1;
130 last;
133 if ($opt_only_missing_tests && -f "$opt_dir$dir$prog-$filename")
135 # Test already run, skip it
136 $skip_prog= 1;
138 print "$prog: ";
139 if ((!$opt_use_old_results) && (!$skip_prog))
141 if (system("$perl ./test-$prog $prog_args > \"$opt_dir$dir$prog-$filename\" $redirect"))
143 printf STDERR "Warning: Can't execute $prog. Check the file '$opt_dir$dir$prog-$filename'\n";
144 die "aborted" if ($opt_die_on_errors);
147 open(TEST,"$opt_dir/$prog-$filename");
148 $last_line="";
149 while(<TEST>)
151 chomp;
152 $last_line=$_ if (!(/^\s*$/)); # Search after last line
154 if ($last_line =~ /Total time:/i)
156 print $last_line . "\n";
157 open(TEST,"$opt_dir/$prog-$filename");
158 while (<TEST>)
160 if (/^(estimated |)time (to|for) ([^\s:]*)\s*\((\d*)(:\d*)*\)[^:]*:\s*([\d.]+) .*secs \(\s*([^\s]*) usr\s*\+*\s*([^\s]*) sys.*=\s+([\d.]*)\s+cpu/i)
162 $arg=$summa{$3};
163 if (!defined($arg))
165 $summa{$3}= [ $4,$6,$7,$8,$9,""];
167 else
169 $arg->[0]+=$4;
170 $arg->[1]+=$6;
171 $arg->[2]+=$7;
172 $arg->[3]+=$8;
173 $arg->[4]+=$9;
175 $prog_sum[0]+=$4;
176 $prog_sum[1]+=$6;
177 $prog_sum[2]+=$7;
178 $prog_sum[3]+=$8;
179 $prog_sum[4]+=$9;
180 if (length($1))
182 $summa{$3}->[5].="+";
183 $estimated=1;
185 if ($got_warning)
187 $summa{$3}->[5].="?";
188 $warning=1;
189 $got_warning=0;
192 elsif (/^warning/i)
194 $got_warning=1;
196 else
198 $got_warning=0;
201 if ($opt_debug)
203 print "Summary for $prog: ", join(" ",@prog_sum), "\n";
206 elsif ($last_line =~ /^Test skipped/i)
208 print "$last_line\n";
210 else
212 $errors++;
213 print "Failed ($opt_dir/$prog-$filename)\n";
217 print "\n";
218 if (!$errors)
220 print "All $prog_count test executed successfully\n";
222 else
224 print "Of $prog_count tests, $errors tests didn't work\n";
226 if ($estimated)
228 print "Tests with estimated time have a + at end of line\n"
230 if ($warning)
232 print "Tests with didn't return the correct result have a ? at end of line\n";
235 if (%summa)
237 @total=(0,0,0,0,0,"");
238 print "\nTotals per operation:\n";
239 print "Operation seconds usr sys cpu tests\n";
240 foreach $key (sort(keys %summa))
242 $arg=$summa{$key};
243 printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
244 $key,$arg->[1],$arg->[2],$arg->[3],$arg->[4],$arg->[0],
245 $arg->[5]);
247 for ($i=0 ; $i < 5 ; $i++)
249 $total[$i]+=$arg->[$i];
251 $total[5].=$arg->[$i];
253 printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
254 "TOTALS",$total[1],$total[2],$total[3],$total[4],$total[0],
255 $total[5]);
258 select(STDOUT);
259 if ($opt_log)
261 print "Test finished. You can find the result in:\n$opt_dir/RUN-$filename\n";
266 # Read headers from an old benchmark run
269 sub read_headers
271 my ($filename)=@_;
273 # Clear current values
274 $benchmark_version=$date=$machine=$server_version="";
276 open(TMP, "<$filename") || die "Can't open $filename\n";
277 while (<TMP>)
279 chop;
280 if (/^Benchmark DBD.*:\s+(.*)$/)
282 $benchmark_version=$1;
284 elsif (/^Date of.*:\s+(.*)/)
286 $date=$1;
288 elsif (/^Running.*:\s+(.*)$/)
290 $machine=$1;
292 elsif (/^Arguments.*:\s+(.*)$/)
294 $log_prog_args=$1;
296 elsif (/^Limits.*:\s+(.*)$/)
298 $opt_cmp=$1;
300 elsif (/^Server ver.*:\s+(.*)$/)
302 $server_version=$1;
304 elsif (/^Optimiz.*:\s+(.*)$/)
306 $opt_optimization=$1;
308 elsif (/^Hardwar.*:\s+(.*)$/)
310 $opt_hw=$1;
313 close(TMP);