Below is the list of changes that have just been committed into a local
5.0 repository of msvensson. When msvensson does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-10-16 16:20:21+02:00, msvensson@shellback.(none) +5 -0
Initial version with support for cpcd
mysql-test/lib/My/CpcClient.pm@stripped, 2007-10-16 16:20:19+02:00, msvensson@shellback.(none) +308 -0
New BitKeeper file ``mysql-test/lib/My/CpcClient.pm''
mysql-test/lib/My/CpcClient.pm@stripped, 2007-10-16 16:20:19+02:00, msvensson@shellback.(none) +0 -0
mysql-test/lib/My/SafeProcess.pm@stripped, 2007-10-16 16:20:18+02:00, msvensson@shellback.(none) +6 -0
Use safe_process_cpcd.pl if host is set
mysql-test/lib/My/SafeProcess/safe_process_cpcd.pl@stripped, 2007-10-16 16:20:18+02:00, msvensson@shellback.(none) +122 -0
New BitKeeper file ``mysql-test/lib/My/SafeProcess/safe_process_cpcd.pl''
mysql-test/lib/My/SafeProcess/safe_process_cpcd.pl@stripped, 2007-10-16 16:20:18+02:00, msvensson@shellback.(none) +0 -0
mysql-test/lib/t/CpcClient.t@stripped, 2007-10-16 16:20:19+02:00, msvensson@shellback.(none) +51 -0
New BitKeeper file ``mysql-test/lib/t/CpcClient.t''
mysql-test/lib/t/CpcClient.t@stripped, 2007-10-16 16:20:19+02:00, msvensson@shellback.(none) +0 -0
mysql-test/mysql-test-run.pl@stripped, 2007-10-16 16:20:18+02:00, msvensson@shellback.(none) +36 -7
Initial version with support for cpcd
diff -Nrup a/mysql-test/lib/My/CpcClient.pm b/mysql-test/lib/My/CpcClient.pm
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/mysql-test/lib/My/CpcClient.pm 2007-10-16 16:20:19 +02:00
@@ -0,0 +1,308 @@
+# -*- cperl -*-
+package CpcClient;
+
+use base qw(IO::Socket::INET);
+
+use warnings;
+use strict;
+
+# Print commands and replies sent to and received from cpcd
+my $opt_log_io= 1;
+
+
+#
+# Create a new CpcClient that inherits everything
+# from IO::Socket::INET
+#
+sub new {
+ my ($class, $args_ref) = @_;
+ return $class->SUPER::new($args_ref);
+}
+
+
+#
+# Show "version"
+# Returns
+# - 'compile time' of cpcd
+# - undef in case of error
+#
+sub show_version {
+ my ($self)= @_;
+ my $command= "show version";
+
+ my $result;
+ if (defined($result= $self->_simple_command($command, {} )) ) {
+ return $result->{'compile time'};
+ }
+ return undef;
+}
+
+
+#
+# Define new process
+# - adds default values for all required args except "path"
+#
+# Returns
+# - id of the new process
+# - undef in case of error
+#
+sub define_process {
+ my $self= shift;
+
+ my $args=
+ {
+ name => "proc$$",
+ group => "group$$",
+ type => "temporary",
+ cwd => ".",
+ owner => getlogin(),
+ @_
+ };
+
+ # Check required args
+ die("You must pass path")
+ unless defined $args->{'path'};
+
+ my $result;
+ if (defined($result= $self->_simple_command("define process", $args)) and
+ $result->{'status'} == 0) {
+ return $result->{'id'};
+ }
+
+ warn("error: '$result->{errormessage}'");
+ return undef;
+}
+
+
+#
+# Undefine process by id
+# Returns
+# - 0 => OK
+# - 'status' from cpcd in case of failure
+#
+sub undefine_process {
+ my ($self, $id)= @_;
+
+ # Check required args
+ die("You must pass id as first arg to undefine_process")
+ unless defined $id;
+
+ my $result;
+ if (defined($result= $self->_simple_command("undefine process",
+ { id => $id })) and
+ $result->{'status'} == 0) {
+ return 0;
+ }
+
+ warn("error: '$result->{errormessage}'");
+ return $result->{'status'};
+}
+
+
+#
+# Start process by id
+# Returns
+# - 0 => OK
+# - 'status' from cpcd in case of failure
+#
+sub start_process {
+ my ($self, $id)= @_;
+
+ # Check required args
+ die("You must pass id as first arg to start_process")
+ unless defined $id;
+
+ my $result;
+ if (defined($result= $self->_simple_command("start process",
+ { id => $id })) and
+ $result->{'status'} == 0) {
+ return 0;
+ }
+
+ warn("error: '$result->{errormessage}'");
+ return $result->{'status'};
+}
+
+
+#
+# Stop process by id
+# Returns
+# - 0 => OK
+# - 'status' from cpcd in case of failure
+#
+sub stop_process {
+ my ($self, $id)= @_;
+
+ # Check required args
+ die("You must pass id as first arg to stop_process")
+ unless defined $id;
+
+ my $result;
+ if (defined($result= $self->_simple_command("stop process",
+ { id => $id })) and
+ $result->{'status'} == 0) {
+ return 0;
+ }
+
+ warn("error: '$result->{errormessage}'");
+ return $result->{'status'};
+}
+
+
+#
+# List the processes defined in cpcd
+# Returns
+# - an array of hashes(one hash for each process)
+# - undef in case of failure
+#
+sub list_processes {
+ my ($self)= @_;
+
+ if ($self->_send_command("list processes") <= 0){
+ return -1;
+ }
+
+ # First comes a "start processes" reply
+ if ($self->_read_reply(undef) ne "start processes"){
+ return undef;
+ }
+
+ # Now read "process" sections until "end processes"
+ my $process_list= (); # Array of hash
+ while (1) {
+ my $process= {};
+ my $reply= $self->_read_reply($process);
+
+ if ($reply eq "process"){
+ # Push the hash onto the list
+ push(@$process_list, $process);
+ }
+ elsif ($reply eq "end processes") {
+ last;
+ }
+ else {
+ warn("unknown command '$reply' received while listing processes");
+ return undef;
+ }
+ }
+ return $process_list;
+}
+
+#############################################################
+#
+# Private helper functions
+#
+#############################################################
+
+#
+# Send one line to the cpcd, print command if logging is on
+#
+# Returns
+# - Number of characters sent
+#
+sub _send_line {
+ my $self = shift;
+ print ">> ", @_ if $opt_log_io; # Print what is being sent
+ return $self->send(@_);
+}
+
+
+#
+# Send a complete command
+# Returns
+# - 1 if ok
+# - -1 if send fails
+#
+sub _send_command {
+ my ($self, $command, $args) = @_;
+
+ # Send the command
+ if ($self->_send_line("$command\n") <= 0 ) {
+ warn("Could not send '$command': $!");
+ return -1;
+ }
+
+ # Send the args
+ foreach my $key (keys %{$args}) {
+ next unless defined $args->{$key};
+ if ($self->_send_line("$key: $args->{$key}\n") <= 0 ) {
+ warn("Could not send '$key' for '$command': $!");
+ return -1;
+ }
+ }
+
+ # Send command terminator(empty new line)
+ if ($self->_send_line("\n") <= 0 ) {
+ warn("Could not send command terminator for '$command': $!");
+ return -1;
+ }
+ return 1;
+}
+
+
+#
+# Read a complete command
+#
+# Returns
+# - "name of reply" which usually is the same as sent command
+# - undef if error occured
+#
+sub _read_reply {
+ my ($self, $return_values)= @_;
+
+ # First line of reply is the command echoed back,
+ # return that from funcgtion if all goes well
+ my $reply= <$self>;
+ if (! defined($reply) ) {
+ warn("Could not read reply: $!");
+ return undef;
+ }
+ print "<< ", $reply if $opt_log_io;
+ chomp($reply);
+
+ # Read the : separated key value pairs until a
+ # single newline on it's own line
+ my $line;
+ while (defined($line= <$self>)) {
+ print "<< ", $line if $opt_log_io;
+
+ # List is terminated by newline on it's own
+ if ($line eq "\n") {
+ # Correctly terminated reply
+ return $reply;
+ }
+
+ chomp($line);
+
+ # Split key/value on the first ":"
+ my ($key, $value)= split(": ", $line, 2);
+ $return_values->{$key}= $value;
+ }
+
+ return undef;
+}
+
+
+#
+# Helper for simple commands, send and receive
+# - Returns a hash with result of the command or
+# undef if anything fails
+#
+sub _simple_command {
+ my ($self, $command, $args)= @_;
+ my $return_values= {};
+
+ if ($self->_send_command($command, $args) <= 0) {
+ return undef;
+ }
+
+ my $reply;
+ if (defined($reply= $self->_read_reply($return_values)) and
+ $reply ne $command ) {
+ return undef;
+ }
+
+ return $return_values;
+}
+
+1;
diff -Nrup a/mysql-test/lib/My/SafeProcess/safe_process_cpcd.pl b/mysql-test/lib/My/SafeProcess/safe_process_cpcd.pl
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/mysql-test/lib/My/SafeProcess/safe_process_cpcd.pl 2007-10-16 16:20:18 +02:00
@@ -0,0 +1,122 @@
+#!/usr/bin/perl
+# -*- cperl -*-
+
+use strict;
+use warnings;
+
+use Time::localtime;
+use lib 'lib';
+use My::SafeProcess::Base;
+use My::CpcClient;
+
+###########################################################################
+# Util functions
+###########################################################################
+
+#
+#Print message to stderr
+#
+my $verbose= 0;
+sub message {
+ if ($verbose > 0){
+ my $tm= localtime();
+ my $timestamp= sprintf("%02d%02d%02d %2d:%02d:%02d",
+ $tm->year % 100, $tm->mon+1, $tm->mday,
+ $tm->hour, $tm->min, $tm->sec);
+ print STDERR $timestamp, " monitor[$$]: ", @_, "\n";
+ }
+}
+
+
+###########################################################################
+# Main program
+###########################################################################
+
+my $parent_pid= getppid();
+my $child_xit_code= 1;
+
+use Getopt::Long;
+GetOptions(
+ 'verbose' => \$verbose,
+ ) or die "GetOptions failed";
+shift(@ARGV) if defined($ARGV[0]) and $ARGV[0] eq "--";
+my $path= shift(@ARGV); # Executable
+
+die "usage:\n" .
+ " safe_process.pl [opts] -- <path> [<args> [...<args_n>]]"
+ unless defined $path;
+
+
+message("started");
+#message("path: '$path'");
+message("parent: $parent_pid");
+
+# Start process to monitor
+my $remote= "localhost:1234";
+my $cpc= CpcClient->new($remote) or die $!;
+my $child= $cpc->define_process(
+ path => $path,
+ args => join(" ", @ARGV),
+ ) or
+ die "Failed to define process";
+
+if ($cpc->start_process($child) != 0) {
+ die "Failed to start process";
+}
+
+message("started child: $child");
+
+$SIG{TERM}= 'IGNORE';
+$SIG{INT}= 'IGNORE';
+
+sub handle_signal {
+ message("Got signal @_");
+ die "signaled\n";
+}
+
+eval {
+ local $SIG{TERM}= \&handle_signal;
+ local $SIG{INT}= \&handle_signal;
+
+ # Monitoring loop
+ while(1) {
+
+ # Check if parent is still alive
+ if (kill(0, $parent_pid) < 1){
+ message("Parent is not alive anymore");
+ last;
+ }
+
+ # Wait for child to terminate
+ my $is_running= 0;
+ foreach my $proc (@{$cpc->list_processes()}) {
+ if ($proc->{id} == $child and
+ $proc->{status} eq "running") {
+ $is_running= 1;
+ }
+ }
+
+ if (!$is_running){
+ message("Child exit: $child_xit_code");
+ # MASV How to get exitcode?
+ $child_xit_code= 0;
+ last;
+ }
+ sleep(1);
+ }
+};
+if ( $@ ) {
+ # The monitoring loop should have been
+ # broken by handle_signal
+ warn "Unexpected: $@" unless ( $@ =~ /signaled/ );
+}
+
+# Just exit, cpcd will kill the process
+# when connection is broken
+
+message("DONE!");
+
+# Exit from monitor with exit status of the child
+exit ($child_xit_code);
+
+
diff -Nrup a/mysql-test/lib/My/SafeProcess.pm b/mysql-test/lib/My/SafeProcess.pm
--- a/mysql-test/lib/My/SafeProcess.pm 2007-09-18 07:51:57 +02:00
+++ b/mysql-test/lib/My/SafeProcess.pm 2007-10-16 16:20:18 +02:00
@@ -77,8 +77,14 @@ sub new {
my $output = delete($opts{'output'});
my $error = delete($opts{'error'});
my $verbose = delete($opts{'verbose'});
+ my $host = delete($opts{'host'});
my $safe_script= "lib/My/SafeProcess/safe_process.pl";
+
+ if (defined $host) {
+ $safe_script= "lib/My/SafeProcess/safe_process_cpcd.pl";
+ }
+
$safe_script= "../$safe_script" unless -f $safe_script;
die "Could not find safe_process.pl" unless -f $safe_script;
diff -Nrup a/mysql-test/lib/t/CpcClient.t b/mysql-test/lib/t/CpcClient.t
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/mysql-test/lib/t/CpcClient.t 2007-10-16 16:20:19 +02:00
@@ -0,0 +1,51 @@
+# -*- cperl -*-
+use strict;
+use Test::More qw(no_plan);
+
+use_ok ("My::CpcClient");
+
+
+SKIP: {
+ my $remote= "localhost:1234";
+ my $cpc= CpcClient->new($remote) or skip("Could not connect to cpcd", 2);
+
+ print $cpc->show_version(), "\n";
+
+ my $id= $cpc->define_process(
+ path => "/bin/sleep",
+ args => 60,
+ );
+ print "$id \n";
+
+ my $id2= $cpc->define_process(
+ name => "proc2",
+ group => "group1",
+ env => "",
+ path => "/bin/sleep",
+ type => "temporary",
+ cwd => ".",
+ owner => "ms",
+ args => "60",
+ stdout => "/tmp/ms.txt",
+ );
+ print "$id2 \n";
+
+ $cpc->start_process( $id );
+ $cpc->start_process( $id2 );
+ $cpc->stop_process( $id );
+
+ my $plist= $cpc->list_processes();
+ foreach my $process (@$plist) {
+ print "process '$process->{'name'}' is ";
+ if ($process->{'status'} eq "running") {
+ print "started\n";
+ } else {
+ print "NOT started\n";
+ }
+ }
+ ok($plist->[1]->{name} eq "proc2" and $plist->[1]->{status} eq "running",
+ "proc2 running");
+ ok($plist->[0]->{name} ne "proc2" and $plist->[0]->{status} ne "running",
+ "Other proc not running");
+}
+
diff -Nrup a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
--- a/mysql-test/mysql-test-run.pl 2007-09-18 07:57:15 +02:00
+++ b/mysql-test/mysql-test-run.pl 2007-10-16 16:20:18 +02:00
@@ -129,7 +129,7 @@ our $opt_vs_config = $ENV{'MTR_VS_CONFIG
our $default_vardir;
our $opt_usage;
-our $opt_suite;
+our $opt_suite= "main";
our $opt_script_debug= 0; # Script debugging, enable with --script-debug
our $opt_verbose= 0; # Verbose output, enable with --verbose
@@ -141,6 +141,7 @@ our $exe_mysqld;
our $exe_mysqltest;
our $exe_ndbd;
our $exe_ndb_mgmd;
+our $exe_cpcd;
our $exe_slave_mysqld;
our $exe_im;
our $exe_libtool;
@@ -290,6 +291,8 @@ my $num_saved_cores= 0; # Number of cor
my $opt_unit= 1;
+my $opt_cpcd= 0;
+
######################################################################
#
# Function declarations
@@ -333,6 +336,7 @@ sub stop_all_servers ();
sub run_mysqltest ($);
sub usage ($);
+my $cpcd;
######################################################################
#
@@ -438,6 +442,25 @@ sub main () {
initialize_servers();
+
+ if ($opt_cpcd) {
+ my $args;
+ mtr_init_args(\$args);
+ mtr_add_arg($args, "--work-dir=%s", "$opt_vardir/run/");
+# mtr_add_arg($args, "--port=%d", $im_mysqld2_port+1);
+ mtr_add_arg($args, "--logfile=%s", "$opt_vardir/log/cpcd.log");
+ mtr_add_arg($args, "--debug");
+ $cpcd= My::SafeProcess->new
+ (
+ path => $exe_cpcd,
+ args => \$args,
+ output => "$opt_vardir/log/cpcd.out",
+ error => "$opt_vardir/log/cpcd.err",
+ verbose => $opt_verbose,
+ ) or die "Failed to start cpcd";
+ }
+
+
if ( $opt_report_features ) {
run_report_features();
}
@@ -458,7 +481,6 @@ sub command_line_setup () {
# These are defaults for things that are set on the command line
- $opt_suite= "main"; # Special default suite
my $opt_comment;
$opt_master_myport= 9306;
@@ -597,7 +619,7 @@ sub command_line_setup () {
'reorder' => \$opt_reorder,
'enable-disabled' => \$opt_enable_disabled,
'script-debug' => \$opt_script_debug,
- 'verbose!' => \$opt_verbose,
+ 'verbose+' => \$opt_verbose,
'sleep=i' => \$opt_sleep,
'socket=s' => \$opt_socket,
'start-dirty' => \$opt_start_dirty,
@@ -608,6 +630,7 @@ sub command_line_setup () {
'suite-timeout=i' => \$opt_suite_timeout,
'warnings|log-warnings' => \$opt_warnings,
'unit!' => \$opt_unit,
+ 'cpcd!' => \$opt_cpcd,
'help|h' => \$opt_usage,
) or usage("Can't read options");
@@ -1470,6 +1493,12 @@ sub executable_setup () {
$exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin");
$exe_mysql= mtr_exe_exists("$path_client_bindir/mysql");
+ if ($opt_cpcd) {
+ $exe_cpcd=
+ mtr_exe_exists("$glob_basedir/ndb/src/cw/cpcd/ndb_cpcd",
+ "$glob_basedir/ndb_cpcd");
+ }
+
if (!$opt_extern)
{
@@ -2687,10 +2716,7 @@ sub initialize_servers () {
}
else
{
- if ($opt_verbose)
- {
- mtr_report("No need to create '$opt_vardir' it already exists");
- }
+ mtr_verbose("No need to create '$opt_vardir' it already exists");
}
}
else
@@ -3113,6 +3139,8 @@ sub run_testcase_mark_logs($)
{
my ($log_msg)= @_;
+ # MASV foreach (glob($opt_vardir/log/*.err)
+
# Write a marker to all log files
# The file indicating current test name
@@ -3826,6 +3854,7 @@ sub mysqld_start ($$$) {
error => $mysqld->{'path_myerr'},
append => 1,
verbose => $opt_verbose,
+ host => $opt_cpcd ? "localhost" : undef,
);
}
| Thread |
|---|
| • bk commit into 5.0 tree (msvensson:1.2536) | msvensson | 16 Oct |