home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 July & August / PCWorld_2003-07-08_cd.bin / Software / Vyzkuste / mysql / data1.cab / Development / bench / run-all-tests < prev    next >
Text File  |  2003-05-17  |  7KB  |  309 lines

  1. #!/usr/bin/perl
  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.  
  40. @ORG_ARGV=@ARGV;
  41. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  42. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  43. $opt_silent=0;
  44. $perl=$^X;
  45. $machine=machine();
  46. $redirect= !($machine =~ /windows/i || $machine =~ "^NT\s") ? "2>&1" : "";
  47. $dir= ($pwd =~ /\\/) ? '\\' : '/';    # directory symbol for shell
  48.  
  49. $prog_args="";
  50. foreach $arg (@ORG_ARGV)
  51. {
  52.   if ($redirect)
  53.   {
  54.     $prog_args.="'" . $arg . "' ";
  55.   }
  56.   else
  57.   {
  58.     # Windows/NT can't handle ' around arguments
  59.     $prog_args.=$arg . " ";    
  60.   }
  61. }
  62.  
  63. $prog_count=$errors=0;
  64.  
  65. if ($opt_cmp) {
  66.     $filename = "$opt_server$opt_suffix-" . machine_part() . "-cmp-$opt_cmp";
  67. } else {
  68.     $filename = "$opt_server$opt_suffix-" . machine_part();
  69. }
  70.  
  71. if (! -d $opt_dir)
  72. {
  73.   if (-e $opt_dir)
  74.   {
  75.     die "$opt_dir isn't a directory\n";
  76.   }
  77.   mkdir $opt_dir,0777 || die "Can't create directory: $opt_dir\n";
  78. }
  79.  
  80. if ($opt_skip_test) {
  81.   (@skip_tests) = split(/,\s*/, $opt_skip_test);
  82. }
  83.  
  84. if ($opt_old_headers)
  85. {
  86.   read_headers("$opt_dir/RUN-$filename");
  87. }
  88. else
  89. {
  90.   $server_version=$server->version();
  91. }
  92.  
  93. if (!$opt_log)
  94. {
  95.   open(LOG,">&STDOUT");
  96. }
  97. else
  98. {
  99.   open(LOG, "> $opt_dir/RUN-$filename") ||
  100.     die "Can't write to $opt_dir/RUN-$filename: $!\n";
  101. }
  102.  
  103. select(LOG);
  104. $|=1;
  105.  
  106. print "Benchmark DBD suite: $benchmark_version\n";
  107. print "Date of test:        $date\n";
  108. print "Running tests on:    $machine\n";
  109. print "Arguments:           $log_prog_args\n";
  110. print "Comments:            $opt_comments\n";
  111. print "Limits from:         $opt_cmp\n";
  112. print "Server version:      $server_version\n";
  113. print "Optimization:        $opt_optimization\n";
  114. print "Hardware:            $opt_hw\n\n";
  115.  
  116.  
  117. $estimated=$warning=$got_warning=0;
  118. while (<test-*>)
  119. {
  120.   next if (/\.sh$/);        # configure script
  121.   next if (/\-fork$/);        # test script
  122.   $prog_count++;
  123.   /test-(.*)$/;            # Remove test from name
  124.   $prog=$1;
  125.   $skip_prog = 0;
  126.   foreach $skip_this (@skip_tests) {
  127.     if ($prog =~ /$skip_this/i) {
  128.       $skip_prog = 1;
  129.       last;
  130.     }
  131.   }
  132.   print "$prog: ";
  133.   if ((!$opt_use_old_results) && (!$skip_prog))
  134.   {
  135.     if (system("$perl ./test-$prog $prog_args > \"$opt_dir$dir$prog-$filename\" $redirect"))
  136.     {
  137.       printf STDERR "Warning: Can't execute $prog.  Check the file '$opt_dir$dir$prog-$filename'\n";
  138.       die "aborted" if ($opt_die_on_errors);
  139.     }
  140.   }
  141.   open(TEST,"$opt_dir/$prog-$filename");
  142.   $last_line="";
  143.   while(<TEST>)
  144.   {
  145.     chomp;
  146.     $last_line=$_ if (!(/^\s*$/));        # Search after last line
  147.   }
  148.   if ($last_line =~ /Total time:/i)
  149.   {
  150.     print $last_line . "\n";
  151.     open(TEST,"$opt_dir/$prog-$filename");
  152.     while (<TEST>)
  153.     {
  154.       if (/^(estimated |)time (to|for) ([^\s:]*)\s*\((\d*)(:\d*)*\)[^:]*:\s*([\d.]+) .*secs \(\s*([^\s]*) usr\s*\+*\s*([^\s]*) sys.*=\s+([\d.]*)\s+cpu/i)
  155.       {
  156.     $arg=$summa{$3};
  157.     if (!defined($arg))
  158.     {
  159.       $summa{$3}= [ $4,$6,$7,$8,$9,""];
  160.     }
  161.     else
  162.     {
  163.       $arg->[0]+=$4;
  164.       $arg->[1]+=$6;
  165.       $arg->[2]+=$7;
  166.       $arg->[3]+=$8;
  167.       $arg->[4]+=$9;
  168.     }
  169.     $prog_sum[0]+=$4;
  170.     $prog_sum[1]+=$6;
  171.     $prog_sum[2]+=$7;
  172.     $prog_sum[3]+=$8;
  173.     $prog_sum[4]+=$9;
  174.     if (length($1))
  175.     {
  176.       $summa{$3}->[5].="+";
  177.       $estimated=1;
  178.     }
  179.     if ($got_warning)
  180.     {
  181.       $summa{$3}->[5].="?";
  182.       $warning=1;
  183.       $got_warning=0;
  184.     }
  185.       }
  186.       elsif (/^warning/i)
  187.       {
  188.     $got_warning=1;
  189.       }
  190.       else
  191.       {
  192.     $got_warning=0;
  193.       }
  194.     }
  195.     if ($opt_debug)
  196.     {
  197.       print "Summary for $prog: ", join(" ",@prog_sum), "\n";
  198.     }
  199.   }
  200.   elsif ($last_line =~ /^Test skipped/i)
  201.   {
  202.     print "$last_line\n";
  203.   }
  204.   else
  205.   {
  206.     $errors++;
  207.     print "Failed ($opt_dir/$prog-$filename)\n";
  208.   }
  209. }
  210.  
  211. print "\n";
  212. if (!$errors)
  213. {
  214.   print "All $prog_count test executed successfully\n";
  215. }
  216. else
  217. {
  218.   print "Of $prog_count tests, $errors tests didn't work\n";
  219. }
  220. if ($estimated)
  221. {
  222.   print "Tests with estimated time have a + at end of line\n"
  223. }
  224. if ($warning)
  225. {
  226.   print "Tests with didn't return the correct result have a ? at end of line\n";
  227. }
  228.  
  229. if (%summa)
  230. {
  231.   @total=(0,0,0,0,0,"");
  232.   print "\nTotals per operation:\n";
  233.   print "Operation             seconds     usr     sys     cpu   tests\n";
  234.   foreach $key (sort(keys %summa))
  235.   {
  236.     $arg=$summa{$key};
  237.     printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
  238.        $key,$arg->[1],$arg->[2],$arg->[3],$arg->[4],$arg->[0],
  239.        $arg->[5]);
  240.  
  241.     for ($i=0 ; $i < 5 ; $i++)
  242.     {
  243.       $total[$i]+=$arg->[$i];
  244.     }
  245.     $total[5].=$arg->[$i];
  246.   }
  247.   printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
  248.      "TOTALS",$total[1],$total[2],$total[3],$total[4],$total[0],
  249.      $total[5]);
  250. }
  251.  
  252. select(STDOUT);
  253. if ($opt_log)
  254. {
  255.   print "Test finished. You can find the result in:\n$opt_dir/RUN-$filename\n";
  256. }
  257.  
  258.  
  259. #
  260. # Read headers from an old benchmark run
  261. #
  262.  
  263. sub read_headers
  264. {
  265.   my ($filename)=@_;
  266.  
  267.   # Clear current values
  268.   $benchmark_version=$date=$machine=$server_version="";
  269.  
  270.   open(TMP, "<$filename") || die "Can't open $filename\n";
  271.   while (<TMP>)
  272.   {
  273.     chop;
  274.     if (/^Benchmark DBD.*:\s+(.*)$/)
  275.     {
  276.       $benchmark_version=$1;
  277.     }
  278.     elsif (/^Date of.*:\s+(.*)/)
  279.     {
  280.       $date=$1;
  281.     }
  282.     elsif (/^Running.*:\s+(.*)$/)
  283.     {
  284.       $machine=$1;
  285.     }
  286.     elsif (/^Arguments.*:\s+(.*)$/)
  287.     {
  288.       $log_prog_args=$1;
  289.     }
  290.     elsif (/^Limits.*:\s+(.*)$/)
  291.     {
  292.       $opt_cmp=$1;
  293.     }
  294.     elsif (/^Server ver.*:\s+(.*)$/)
  295.     {
  296.       $server_version=$1;
  297.     }
  298.     elsif (/^Optimiz.*:\s+(.*)$/)
  299.     {
  300.       $opt_optimization=$1;
  301.     }
  302.     elsif (/^Hardwar.*:\s+(.*)$/)
  303.     {
  304.       $opt_hw=$1;
  305.     }
  306.   }
  307.   close(TMP);
  308. }
  309.