~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/mysql-test-run.pl

  • Committer: Brian Aker
  • Date: 2008-07-07 21:55:15 UTC
  • Revision ID: brian@tangent.org-20080707215515-fhl7e9vzonwyye4b
First pass on cleaning out mysql-test-run

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
$| = 1; # Automatically flush STDOUT
75
75
 
76
76
our $glob_win32_perl=  ($^O eq "MSWin32"); # ActiveState Win32 Perl
77
 
our $glob_cygwin_perl= ($^O eq "cygwin");  # Cygwin Perl
78
 
our $glob_win32=       ($glob_win32_perl or $glob_cygwin_perl);
79
77
our $glob_netware=     ($^O eq "NetWare"); # NetWare
80
78
 
81
79
require "lib/mtr_cases.pl";
360
358
 
361
359
  command_line_setup();
362
360
 
363
 
  check_ndbcluster_support(\%mysqld_variables);
364
 
  check_ssl_support(\%mysqld_variables);
365
361
  check_debug_support(\%mysqld_variables);
366
362
 
367
363
  executable_setup();
692
688
 
693
689
  # Find the absolute path to the test directory
694
690
  $glob_mysql_test_dir=  cwd();
695
 
  if ( $glob_cygwin_perl )
696
 
  {
697
 
    # Windows programs like 'mysqld' needs Windows paths
698
 
    $glob_mysql_test_dir= `cygpath -m "$glob_mysql_test_dir"`;
699
 
    chomp($glob_mysql_test_dir);
700
 
  }
701
691
  $default_vardir= "$glob_mysql_test_dir/var";
702
692
 
703
693
  # In most cases, the base directory we find everything relative to,
726
716
 
727
717
  $glob_timers= mtr_init_timers();
728
718
 
729
 
  # --------------------------------------------------------------------------
730
 
  # Embedded server flag
731
 
  # --------------------------------------------------------------------------
732
 
  if ( $opt_embedded_server )
733
 
  {
734
 
    $glob_use_embedded_server= 1;
735
 
    # Add the location for libmysqld.dll to the path.
736
 
    if ( $glob_win32 )
737
 
    {
738
 
      my $lib_mysqld=
739
 
        mtr_path_exists(vs_config_dirs('libmysqld',''));
740
 
          $lib_mysqld= $glob_cygwin_perl ? ":".`cygpath "$lib_mysqld"` 
741
 
                                     : ";".$lib_mysqld;
742
 
      chomp($lib_mysqld);
743
 
      $ENV{'PATH'}="$ENV{'PATH'}".$lib_mysqld;
744
 
    }
745
 
 
746
 
    push(@glob_test_mode, "embedded");
747
 
    $opt_skip_rpl= 1;              # We never run replication with embedded
748
 
    $opt_skip_ndbcluster= 1;       # Turn off use of NDB cluster
749
 
    $opt_skip_ssl= 1;              # Turn off use of SSL
750
 
 
751
 
    # Turn off use of bin log
752
 
    push(@opt_extra_mysqld_opt, "--skip-log-bin");
753
 
 
754
 
    if ( $opt_extern )
755
 
    {
756
 
      mtr_error("Can't use --extern with --embedded-server");
757
 
    }
758
 
  }
759
 
 
760
719
  #
761
720
  # Find the mysqld executable to be able to find the mysqld version
762
721
  # number as early as possible
913
872
    # Version 4.1 and --vardir was specified
914
873
    # Only supported as a symlink from var/
915
874
    # by setting up $opt_mem that symlink will be created
916
 
    if ( ! $glob_win32 )
917
875
    {
918
876
      # Only platforms that have native symlinks can use the vardir trick
919
877
      $opt_mem= $opt_vardir;
928
886
  $path_vardir_trace=~ s/^\w://;
929
887
 
930
888
  # We make the path absolute, as the server will do a chdir() before usage
931
 
  unless ( $opt_vardir =~ m,^/, or
932
 
           ($glob_win32 and $opt_vardir =~ m,^[a-z]:/,i) )
 
889
  unless ( $opt_vardir =~ m,^/,)
933
890
  {
934
891
    # Make absolute path, relative test dir
935
892
    $opt_vardir= "$glob_mysql_test_dir/$opt_vardir";
1053
1010
  {
1054
1011
    $opt_testcase_timeout= $default_testcase_timeout;
1055
1012
    $opt_testcase_timeout*= 10 if $opt_valgrind;
1056
 
    $opt_testcase_timeout*= 10 if ($opt_debug and $glob_win32);
1057
1013
  }
1058
1014
 
1059
1015
  if ( ! $opt_suite_timeout )
1060
1016
  {
1061
1017
    $opt_suite_timeout= $default_suite_timeout;
1062
1018
    $opt_suite_timeout*= 6 if $opt_valgrind;
1063
 
    $opt_suite_timeout*= 6 if ($opt_debug and $glob_win32);
1064
1019
  }
1065
1020
 
1066
1021
  if ( ! $opt_user )
1912
1867
  # ----------------------------------------------------
1913
1868
  # Setup env so childs can execute mysql_fix_system_tables
1914
1869
  # ----------------------------------------------------
1915
 
  #if ( !$opt_extern && ! $glob_win32 )
 
1870
  #if ( !$opt_extern)
1916
1871
  if ( 0 )
1917
1872
  {
1918
1873
    my $cmdline_mysql_fix_system_tables=
1982
1937
    print "Using SLAVE_MYPORT          = $ENV{SLAVE_MYPORT}\n";
1983
1938
    print "Using SLAVE_MYPORT1         = $ENV{SLAVE_MYPORT1}\n";
1984
1939
    print "Using SLAVE_MYPORT2         = $ENV{SLAVE_MYPORT2}\n";
1985
 
    if ( ! $opt_skip_ndbcluster )
1986
 
    {
1987
 
      print "Using NDBCLUSTER_PORT       = $ENV{NDBCLUSTER_PORT}\n";
1988
 
      if ( ! $opt_skip_ndbcluster_slave )
1989
 
      {
1990
 
        print "Using NDBCLUSTER_PORT_SLAVE = $ENV{NDBCLUSTER_PORT_SLAVE}\n";
1991
 
      }
1992
 
    }
1993
1940
  }
1994
1941
 
1995
1942
  # Create an environment variable to make it possible
2194
2141
  }
2195
2142
 
2196
2143
  # Make a link std_data_ln in var/ that points to std_data
2197
 
  if ( ! $glob_win32 )
2198
 
  {
2199
 
    symlink("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data_ln");
2200
 
  }
2201
 
  else
2202
 
  {
2203
 
    # on windows, copy all files from std_data into var/std_data_ln
2204
 
    mkpath("$opt_vardir/std_data_ln");
2205
 
    opendir(DIR, "$glob_mysql_test_dir/std_data")
2206
 
      or mtr_error("Can't find the std_data directory: $!");
2207
 
    for(readdir(DIR)) {
2208
 
      next if -d "$glob_mysql_test_dir/std_data/$_";
2209
 
      copy("$glob_mysql_test_dir/std_data/$_", "$opt_vardir/std_data_ln/$_");
2210
 
    }
2211
 
    closedir(DIR);
2212
 
  }
 
2144
  symlink("$glob_mysql_test_dir/std_data", "$opt_vardir/std_data_ln");
2213
2145
 
2214
2146
  # Remove old log files
2215
2147
  foreach my $name (glob("r/*.progress r/*.log r/*.warnings"))
2330
2262
 
2331
2263
##############################################################################
2332
2264
#
2333
 
#  Start the ndb cluster
2334
 
#
2335
 
##############################################################################
2336
 
 
2337
 
sub check_ndbcluster_support ($) {
2338
 
  my $mysqld_variables= shift;
2339
 
 
2340
 
  if ($opt_skip_ndbcluster || $opt_extern)
2341
 
  {
2342
 
    if (!$opt_extern)
2343
 
    {
2344
 
      mtr_report("Skipping ndbcluster");
2345
 
    }
2346
 
    $opt_skip_ndbcluster_slave= 1;
2347
 
    return;
2348
 
  }
2349
 
 
2350
 
  if ( ! $mysqld_variables->{'ndb-connectstring'} )
2351
 
  {
2352
 
    mtr_report("Skipping ndbcluster, mysqld not compiled with ndbcluster");
2353
 
    $opt_skip_ndbcluster= 1;
2354
 
    $opt_skip_ndbcluster_slave= 1;
2355
 
    return;
2356
 
  }
2357
 
  $glob_ndbcluster_supported= 1;
2358
 
  mtr_report("Using ndbcluster when necessary, mysqld supports it");
2359
 
 
2360
 
  if ( $mysql_version_id < 50100 )
2361
 
  {
2362
 
    # Slave cluster is not supported until 5.1
2363
 
    $opt_skip_ndbcluster_slave= 1;
2364
 
 
2365
 
  }
2366
 
 
2367
 
  return;
2368
 
}
2369
 
 
2370
 
 
2371
 
sub ndbcluster_start_install ($) {
2372
 
  my $cluster= shift;
2373
 
 
2374
 
  mtr_report("Installing $cluster->{'name'} Cluster");
2375
 
 
2376
 
  mkdir($cluster->{'data_dir'});
2377
 
 
2378
 
  # Create a config file from template
2379
 
  my $ndb_no_ord=512;
2380
 
  my $ndb_no_attr=2048;
2381
 
  my $ndb_con_op=105000;
2382
 
  my $ndb_dmem="80M";
2383
 
  my $ndb_imem="24M";
2384
 
  my $ndb_pbmem="32M";
2385
 
  my $nodes= $cluster->{'nodes'};
2386
 
  my $ndb_host= "localhost";
2387
 
  my $ndb_diskless= 0;
2388
 
 
2389
 
  if (!$opt_bench)
2390
 
  {
2391
 
    # Use a smaller configuration
2392
 
    if (  $mysql_version_id < 50100 )
2393
 
    {
2394
 
      # 4.1 and 5.0 is using a "larger" --small configuration
2395
 
      $ndb_no_ord=128;
2396
 
      $ndb_con_op=10000;
2397
 
      $ndb_dmem="40M";
2398
 
      $ndb_imem="12M";
2399
 
    }
2400
 
    else
2401
 
    {
2402
 
      $ndb_no_ord=32;
2403
 
      $ndb_con_op=10000;
2404
 
      $ndb_dmem="20M";
2405
 
      $ndb_imem="1M";
2406
 
      $ndb_pbmem="4M";
2407
 
    }
2408
 
  }
2409
 
 
2410
 
  my $config_file_template=     "ndb/ndb_config_${nodes}_node.ini";
2411
 
  my $config_file= "$cluster->{'data_dir'}/config.ini";
2412
 
 
2413
 
  open(IN, $config_file_template)
2414
 
    or mtr_error("Can't open $config_file_template: $!");
2415
 
  open(OUT, ">", $config_file)
2416
 
    or mtr_error("Can't write to $config_file: $!");
2417
 
  while (<IN>)
2418
 
  {
2419
 
    chomp;
2420
 
 
2421
 
    s/CHOOSE_MaxNoOfAttributes/$ndb_no_attr/;
2422
 
    s/CHOOSE_MaxNoOfOrderedIndexes/$ndb_no_ord/;
2423
 
    s/CHOOSE_MaxNoOfConcurrentOperations/$ndb_con_op/;
2424
 
    s/CHOOSE_DataMemory/$ndb_dmem/;
2425
 
    s/CHOOSE_IndexMemory/$ndb_imem/;
2426
 
    s/CHOOSE_Diskless/$ndb_diskless/;
2427
 
    s/CHOOSE_HOSTNAME_.*/$ndb_host/;
2428
 
    s/CHOOSE_FILESYSTEM/$cluster->{'data_dir'}/;
2429
 
    s/CHOOSE_PORT_MGM/$cluster->{'port'}/;
2430
 
    if ( $mysql_version_id < 50000 )
2431
 
    {
2432
 
      my $base_port= $cluster->{'port'} + 1;
2433
 
      s/CHOOSE_PORT_TRANSPORTER/$base_port/;
2434
 
    }
2435
 
    s/CHOOSE_DiskPageBufferMemory/$ndb_pbmem/;
2436
 
 
2437
 
    print OUT "$_ \n";
2438
 
  }
2439
 
  close OUT;
2440
 
  close IN;
2441
 
 
2442
 
 
2443
 
  # Start cluster with "--initial"
2444
 
 
2445
 
  ndbcluster_start($cluster, "--initial");
2446
 
 
2447
 
  return 0;
2448
 
}
2449
 
 
2450
 
 
2451
 
sub ndbcluster_wait_started($$){
2452
 
  my $cluster= shift;
2453
 
  my $ndb_waiter_extra_opt= shift;
2454
 
  my $path_waiter_log= "$cluster->{'data_dir'}/ndb_waiter.log";
2455
 
  my $args;
2456
 
 
2457
 
  mtr_init_args(\$args);
2458
 
 
2459
 
  mtr_add_arg($args, "--no-defaults");
2460
 
  mtr_add_arg($args, "--core");
2461
 
  mtr_add_arg($args, "--ndb-connectstring=%s", $cluster->{'connect_string'});
2462
 
  mtr_add_arg($args, "--timeout=60");
2463
 
 
2464
 
  if ($ndb_waiter_extra_opt)
2465
 
  {
2466
 
    mtr_add_arg($args, "$ndb_waiter_extra_opt");
2467
 
  }
2468
 
 
2469
 
  # Start the ndb_waiter which will connect to the ndb_mgmd
2470
 
  # and poll it for state of the ndbd's, will return when
2471
 
  # all nodes in the cluster is started
2472
 
  my $res= mtr_run($exe_ndb_waiter, $args,
2473
 
                   "", $path_waiter_log, $path_waiter_log, "");
2474
 
  mtr_verbose("ndbcluster_wait_started, returns: $res") if $res;
2475
 
  return $res;
2476
 
}
2477
 
 
2478
 
 
2479
 
 
2480
 
sub mysqld_wait_started($){
2481
 
  my $mysqld= shift;
2482
 
 
2483
 
  if (sleep_until_file_created($mysqld->{'path_pid'},
2484
 
                               $mysqld->{'start_timeout'},
2485
 
                               $mysqld->{'pid'}) == 0)
2486
 
  {
2487
 
    # Failed to wait for pid file
2488
 
    return 1;
2489
 
  }
2490
 
 
2491
 
  # Get the "real pid" of the process, it will be used for killing
2492
 
  # the process in ActiveState's perl on windows
2493
 
  $mysqld->{'real_pid'}= mtr_get_pid_from_file($mysqld->{'path_pid'});
2494
 
 
2495
 
  return 0;
2496
 
}
2497
 
 
2498
 
 
2499
 
sub ndb_mgmd_wait_started($) {
2500
 
  my ($cluster)= @_;
2501
 
 
2502
 
  my $retries= 100;
2503
 
  while (ndbcluster_wait_started($cluster, "--no-contact") and
2504
 
         $retries)
2505
 
  {
2506
 
    # Millisceond sleep emulated with select
2507
 
    select(undef, undef, undef, (0.1));
2508
 
 
2509
 
    $retries--;
2510
 
  }
2511
 
 
2512
 
  return $retries == 0;
2513
 
 
2514
 
}
2515
 
 
2516
 
sub ndb_mgmd_start ($) {
2517
 
  my $cluster= shift;
2518
 
 
2519
 
  my $args;                             # Arg vector
2520
 
  my $pid= -1;
2521
 
 
2522
 
  mtr_init_args(\$args);
2523
 
  mtr_add_arg($args, "--no-defaults");
2524
 
  mtr_add_arg($args, "--core");
2525
 
  mtr_add_arg($args, "--nodaemon");
2526
 
  mtr_add_arg($args, "--config-file=%s", "$cluster->{'data_dir'}/config.ini");
2527
 
 
2528
 
 
2529
 
  my $path_ndb_mgmd_log= "$cluster->{'data_dir'}/\l$cluster->{'name'}_ndb_mgmd.log";
2530
 
  $pid= mtr_spawn($exe_ndb_mgmd, $args, "",
2531
 
                  $path_ndb_mgmd_log,
2532
 
                  $path_ndb_mgmd_log,
2533
 
                  "",
2534
 
                  { append_log_file => 1 });
2535
 
 
2536
 
  # FIXME Should not be needed
2537
 
  # Unfortunately the cluster nodes will fail to start
2538
 
  # if ndb_mgmd has not started properly
2539
 
  if (ndb_mgmd_wait_started($cluster))
2540
 
  {
2541
 
    mtr_error("Failed to wait for start of ndb_mgmd");
2542
 
  }
2543
 
 
2544
 
  # Remember pid of ndb_mgmd
2545
 
  $cluster->{'pid'}= $pid;
2546
 
 
2547
 
  mtr_verbose("ndb_mgmd_start, pid: $pid");
2548
 
 
2549
 
  return $pid;
2550
 
}
2551
 
 
2552
 
 
2553
 
sub ndbd_start ($$$) {
2554
 
  my $cluster= shift;
2555
 
  my $idx= shift;
2556
 
  my $extra_args= shift;
2557
 
 
2558
 
  my $args;                             # Arg vector
2559
 
  my $pid= -1;
2560
 
 
2561
 
  mtr_init_args(\$args);
2562
 
  mtr_add_arg($args, "--no-defaults");
2563
 
  mtr_add_arg($args, "--core");
2564
 
  mtr_add_arg($args, "--ndb-connectstring=%s", "$cluster->{'connect_string'}");
2565
 
  if ( $mysql_version_id >= 50000)
2566
 
  {
2567
 
    mtr_add_arg($args, "--character-sets-dir=%s", "$path_charsetsdir");
2568
 
  }
2569
 
  mtr_add_arg($args, "--nodaemon");
2570
 
  mtr_add_arg($args, "$extra_args");
2571
 
 
2572
 
  my $nodeid= $cluster->{'ndbds'}->[$idx]->{'nodeid'};
2573
 
  my $path_ndbd_log= "$cluster->{'data_dir'}/ndb_${nodeid}.log";
2574
 
  $pid= mtr_spawn($exe_ndbd, $args, "",
2575
 
                  $path_ndbd_log,
2576
 
                  $path_ndbd_log,
2577
 
                  "",
2578
 
                  { append_log_file => 1 });
2579
 
 
2580
 
  # Add pid to list of pids for this cluster
2581
 
  $cluster->{'ndbds'}->[$idx]->{'pid'}= $pid;
2582
 
 
2583
 
  # Rememeber options used when starting
2584
 
  $cluster->{'ndbds'}->[$idx]->{'start_extra_args'}= $extra_args;
2585
 
  $cluster->{'ndbds'}->[$idx]->{'idx'}= $idx;
2586
 
 
2587
 
  mtr_verbose("ndbd_start, pid: $pid");
2588
 
 
2589
 
  return $pid;
2590
 
}
2591
 
 
2592
 
 
2593
 
sub ndbcluster_start ($$) {
2594
 
  my $cluster= shift;
2595
 
  my $extra_args= shift;
2596
 
 
2597
 
  mtr_verbose("ndbcluster_start '$cluster->{'name'}'");
2598
 
 
2599
 
  if ( $cluster->{'use_running'} )
2600
 
  {
2601
 
    return 0;
2602
 
  }
2603
 
 
2604
 
  if ( $cluster->{'pid'} )
2605
 
  {
2606
 
    mtr_error("Cluster '$cluster->{'name'}' already started");
2607
 
  }
2608
 
 
2609
 
  ndb_mgmd_start($cluster);
2610
 
 
2611
 
  for ( my $idx= 0; $idx < $cluster->{'nodes'}; $idx++ )
2612
 
  {
2613
 
    ndbd_start($cluster, $idx, $extra_args);
2614
 
  }
2615
 
 
2616
 
  return 0;
2617
 
}
2618
 
 
2619
 
 
2620
 
sub rm_ndbcluster_tables ($) {
2621
 
  my $dir=       shift;
2622
 
  foreach my $bin ( glob("$dir/mysql/ndb_apply_status*"),
2623
 
                    glob("$dir/mysql/ndb_schema*"))
2624
 
  {
2625
 
    unlink($bin);
2626
 
  }
2627
 
}
2628
 
 
2629
 
 
2630
 
##############################################################################
2631
 
#
2632
2265
#  Run the benchmark suite
2633
2266
#
2634
2267
##############################################################################
3470
3103
  # When mysqld is run by a root user(euid is 0), it will fail
3471
3104
  # to start unless we specify what user to run as, see BUG#30630
3472
3105
  my $euid= $>;
3473
 
  if (!$glob_win32 and $euid == 0 and
3474
 
      grep(/^--user/, @$extra_opt, @opt_extra_mysqld_opt) == 0) {
 
3106
  if (grep(/^--user/, @$extra_opt, @opt_extra_mysqld_opt) == 0) {
3475
3107
    mtr_add_arg($args, "%s--user=root", $prefix);
3476
3108
  }
3477
3109
 
3846
3478
 
3847
3479
  # Make sure that process has shutdown else try to kill them
3848
3480
  mtr_check_stop_servers(\@kill_pids);
3849
 
 
3850
 
  foreach my $mysqld (@{$master}, @{$slave})
3851
 
  {
3852
 
    rm_ndbcluster_tables($mysqld->{'path_myddir'});
3853
 
  }
3854
3481
}
3855
3482
 
3856
3483
 
4119
3746
 
4120
3747
  # Make sure that process has shutdown else try to kill them
4121
3748
  mtr_check_stop_servers(\@kill_pids);
4122
 
 
4123
 
  foreach my $mysqld (@{$master}, @{$slave})
4124
 
  {
4125
 
    if ( ! $mysqld->{'pid'} )
4126
 
    {
4127
 
      # Remove ndbcluster tables if server is stopped
4128
 
      rm_ndbcluster_tables($mysqld->{'path_myddir'});
4129
 
    }
4130
 
  }
4131
3749
}
4132
3750
 
4133
3751
 
4744
4362
}
4745
4363
 
4746
4364
 
 
4365
sub mysqld_wait_started($){
 
4366
  my $mysqld= shift;
 
4367
 
 
4368
  if (sleep_until_file_created($mysqld->{'path_pid'},
 
4369
            $mysqld->{'start_timeout'},
 
4370
            $mysqld->{'pid'}) == 0)
 
4371
  {
 
4372
    # Failed to wait for pid file
 
4373
    return 1;
 
4374
  }
 
4375
 
 
4376
  # Get the "real pid" of the process, it will be used for killing
 
4377
  # the process in ActiveState's perl on windows
 
4378
  $mysqld->{'real_pid'}= mtr_get_pid_from_file($mysqld->{'path_pid'});
 
4379
 
 
4380
  return 0;
 
4381
}
 
4382
 
 
4383
 
4747
4384
##############################################################################
4748
4385
#
4749
4386
#  Usage