home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win.exe / DATA1.CAB / Benchmark_Files / bench / run-all-tests < prev    next >
Text File  |  2000-11-22  |  7KB  |  289 lines

  1. #!/my/gnu/bin/perl5
  2. # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. # Library General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Library General Public
  15. # License along with this library; if not, write to the Free
  16. # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. # MA 02111-1307, USA
  18. #
  19. # This program runs all test that starts with 'test-' and sums
  20. # the results that the program prints.
  21. # Each time result should be of the form:
  22. # Time for|to KEYWORD (number_of_runs) 'other info': timestr()
  23. #
  24. # All options to this script is passed to all test program.
  25. # useful options:
  26. # --fast --force --lock-tables
  27. # --server   ==> mysql (default) / mSQL / Pg (postgres) / Solid
  28. # --user     ==> the user with permission to create / drop / select
  29. # --pass     ==> password for the user
  30. # --cmp      ==> Compare --server with one of the others (mysql/mSQL/Pg/Solid)
  31. # --comments ==> everything you want to say such as the extra options you
  32. #                gave to the db server. (use --comments="xxx xxx xxx"
  33. # --machine  ==> Give a OS/machine id for your logfiles.
  34. # --log         ==> puts output in output/RUN-server-machine-cmp-$opt_cmp
  35.  
  36. use DBI;
  37.  
  38. $opt_silent=1;            # Don't write header
  39. $prog_args="";
  40. foreach $arg (@ARGV)
  41. {
  42.   $prog_args.="'" . $arg . "' ";
  43. }
  44.  
  45. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  46. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  47. $opt_silent=0;
  48. $perl=$^X;
  49. $machine=machine();
  50. $redirect= !($machine =~ /windows/i || $machine =~ "^NT\s") ? "2>&1" : "";
  51. $dir= ($pwd =~ /\\/) ? '\\' : '/';    # directory symbol for shell
  52.  
  53. $prog_count=$errors=0;
  54.  
  55. if ($opt_cmp) {
  56.     $filename = "$opt_server$opt_suffix-" . machine_part() . "-cmp-$opt_cmp";
  57. } else {
  58.     $filename = "$opt_server$opt_suffix-" . machine_part();
  59. }
  60.  
  61. if (! -d $opt_dir)
  62. {
  63.   if (-e $opt_dir)
  64.   {
  65.     die "$opt_dir isn't a directory\n";
  66.   }
  67.   mkdir $opt_dir,0777 || die "Can't create directory: $opt_dir\n";
  68. }
  69.  
  70. if ($opt_skip_test) {
  71.   (@skip_tests) = split(/,\s*/, $opt_skip_test);
  72. }
  73.  
  74. if ($opt_old_headers)
  75. {
  76.   read_headers("$opt_dir/RUN-$filename");
  77. }
  78. else
  79. {
  80.   $server_version=$server->version();
  81. }
  82.  
  83. if (!$opt_log)
  84. {
  85.   open(LOG,">&STDOUT");
  86. }
  87. else
  88. {
  89.   open(LOG, "> $opt_dir/RUN-$filename") ||
  90.     die "Can't write to $opt_dir/RUN-$filename: $!\n";
  91. }
  92.  
  93. select(LOG);
  94. $|=1;
  95.  
  96. print "Benchmark DBD suite: $benchmark_version\n";
  97. print "Date of test:        $date\n";
  98. print "Running tests on:    $machine\n";
  99. print "Arguments:           $log_prog_args\n";
  100. print "Comments:            $opt_comments\n";
  101. print "Limits from:         $opt_cmp\n";
  102. print "Server version:      $server_version\n\n";
  103.  
  104.  
  105. $estimated=$warning=$got_warning=0;
  106. while (<test-*>)
  107. {
  108.   next if (/\.sh$/);        # configure script
  109.   next if (/\-fork$/);        # test script
  110.   $prog_count++;
  111.   /test-(.*)$/;            # Remove test from name
  112.   $prog=$1;
  113.   $skip_prog = 0;
  114.   foreach $skip_this (@skip_tests) {
  115.     if ($prog =~ /$skip_this/i) {
  116.       $skip_prog = 1;
  117.       last;
  118.     }
  119.   }
  120.   print "$prog: ";
  121.   if ((!$opt_use_old_results) && (!$skip_prog))
  122.   {
  123.     if (system("$perl ./test-$prog $prog_args > \"$opt_dir$dir$prog-$filename\" $redirect"))
  124.     {
  125.       printf STDERR "Warning: Can't execute $prog.  Check the file '$opt_dir$dir$prog-$filename'\n";
  126.       die "aborted" if ($opt_die_on_errors);
  127.     }
  128.   }
  129.   open(TEST,"$opt_dir/$prog-$filename");
  130.   $last_line="";
  131.   while(<TEST>)
  132.   {
  133.     chomp;
  134.     $last_line=$_ if (!(/^\s*$/));        # Search after last line
  135.   }
  136.   if ($last_line =~ /Total time:/i)
  137.   {
  138.     print $last_line . "\n";
  139.     open(TEST,"$opt_dir/$prog-$filename");
  140.     while (<TEST>)
  141.     {
  142.       if (/^(estimated |)time (to|for) ([^\s:]*)\s*\((\d*)(:\d*)*\)[^:]*:\s*([\d.]+) .*secs \(\s*([^\s]*) usr\s*\+*\s*([^\s]*) sys.*=\s+([\d.]*)\s+cpu/i)
  143.       {
  144.     $arg=$summa{$3};
  145.     if (!defined($arg))
  146.     {
  147.       $summa{$3}= [ $4,$6,$7,$8,$9,""];
  148.     }
  149.     else
  150.     {
  151.       $arg->[0]+=$4;
  152.       $arg->[1]+=$6;
  153.       $arg->[2]+=$7;
  154.       $arg->[3]+=$8;
  155.       $arg->[4]+=$9;
  156.     }
  157.     $prog_sum[0]+=$4;
  158.     $prog_sum[1]+=$6;
  159.     $prog_sum[2]+=$7;
  160.     $prog_sum[3]+=$8;
  161.     $prog_sum[4]+=$9;
  162.     if (length($1))
  163.     {
  164.       $summa{$3}->[5].="+";
  165.       $estimated=1;
  166.     }
  167.     if ($got_warning)
  168.     {
  169.       $summa{$3}->[5].="?";
  170.       $warning=1;
  171.       $got_warning=0;
  172.     }
  173.       }
  174.       elsif (/^warning/i)
  175.       {
  176.     $got_warning=1;
  177.       }
  178.       else
  179.       {
  180.     $got_warning=0;
  181.       }
  182.     }
  183.     if ($opt_debug)
  184.     {
  185.       print "Summary for $prog: ", join(" ",@prog_sum), "\n";
  186.     }
  187.   }
  188.   else
  189.   {
  190.     $errors++;
  191.     print "Failed ($opt_dir/$prog-$filename)\n";
  192.   }
  193. }
  194.  
  195. print "\n";
  196. if (!$errors)
  197. {
  198.   print "All $prog_count test executed successfully\n";
  199. }
  200. else
  201. {
  202.   print "Of $prog_count tests, $errors tests didn't work\n";
  203. }
  204. if ($estimated)
  205. {
  206.   print "Tests with estimated time have a + at end of line\n"
  207. }
  208. if ($warning)
  209. {
  210.   print "Tests with didn't return the correct result have a ? at end of line\n";
  211. }
  212.  
  213. if (%summa)
  214. {
  215.   @total=(0,0,0,0,0,"");
  216.   print "\nTotals per operation:\n";
  217.   print "Operation             seconds     usr     sys     cpu   tests\n";
  218.   foreach $key (sort(keys %summa))
  219.   {
  220.     $arg=$summa{$key};
  221.     printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
  222.        $key,$arg->[1],$arg->[2],$arg->[3],$arg->[4],$arg->[0],
  223.        $arg->[5]);
  224.  
  225.     for ($i=0 ; $i < 5 ; $i++)
  226.     {
  227.       $total[$i]+=$arg->[$i];
  228.     }
  229.     $total[5].=$arg->[$i];
  230.   }
  231.   printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
  232.      "TOTALS",$total[1],$total[2],$total[3],$total[4],$total[0],
  233.      $total[5]);
  234. }
  235.  
  236. select(STDOUT);
  237. if ($opt_log)
  238. {
  239.   print "Test finished. You can find the result in:\n$opt_dir/RUN-$filename\n";
  240. }
  241.  
  242.  
  243. #
  244. # Read headers from an old benchmark run
  245. #
  246.  
  247. sub read_headers
  248. {
  249.   my ($filename)=@_;
  250.  
  251.   # Clear current values
  252.   $benchmark_version=$date=$machine=$server_version="";
  253.  
  254.   open(TMP, "<$filename") || die "Can't open $filename\n";
  255.   while (<TMP>)
  256.   {
  257.     chop;
  258.     if (/^Benchmark DBD.*:\s+(.*)$/)
  259.     {
  260.       $benchmark_version=$1;
  261.     }
  262.     elsif (/^Date of.*:\s+(.*)/)
  263.     {
  264.       $date=$1;
  265.     }
  266.     elsif (/^Running.*:\s+(.*)$/)
  267.     {
  268.       $machine=$1;
  269.     }
  270.     elsif (/^Arguments.*:\s+(.*)$/)
  271.     {
  272.       $log_prog_args=$1;
  273.     }
  274.     elsif (/^Comments.*:\s+(.*)$/)
  275.     {
  276.       $opt_comments=$1;
  277.     }
  278.     elsif (/^Limits.*:\s+(.*)$/)
  279.     {
  280.       $opt_cmp=$1;
  281.     }
  282.     elsif (/^Server ver.*:\s+(.*)$/)
  283.     {
  284.       $server_version=$1;
  285.     }
  286.   }
  287.   close(TMP);
  288. }
  289.