mariadb/mysql-test/lib/My/Test.pm
Sergei Golubchik 8da7be6302 generalization of mtr to support suite.pm extensions:
* no automatic --loose-skip-innodb added by mtr based on the test name.
  instead loose-skip-innodb is now in the default_mysqld.cnf
* have_innodb_plugin.inc is changed to give a verbose "skip" message
  (instead of "require: true")
* My::Suite class. It's support in mtr, and everywhere
* support for suite.pm
* when sorting tests, take combinations into account
* support for SUITENAME_COMBINATIONS
* no special treatment for innodb_plugin in mtr_cases.pm
* two special pre-created config groups: ENV and OPT
* allow option names to start from #
* allow magic option to have an argument
* remove dead code
* fix @-substitution to works as expected
* new processes take the value of $opt_verbose automatically, no need to pass it to a constructor
* innodb_plugin suite uses suite.pm and combinations file to test as much as possible
  (innodb plugin, xtradb plugin, xtradb static - whatever available)
* besides test-master.opt and test-slave.opt a test.opt file is also
  loaded, both for master and slave
* .opt files for all included files are loaded too
* progress report in the xterm titlebar
2010-08-17 11:14:46 +04:00

74 lines
1.3 KiB
Perl

# -*- cperl -*-
#
# One test
#
package My::Test;
use strict;
use warnings;
use Carp;
use Storable();
sub new {
my $class= shift;
my $self= bless {
@_,
}, $class;
return $self;
}
sub fullname {
my ($self)= @_;
$self->{name} . (defined $self->{combination}
? " '$self->{combination}'"
: "")
}
#
# Return a unique key that can be used to
# identify this test in a hash
#
sub key {
my ($self)= @_;
return $self->{key};
}
sub is_failed {
my ($self)= @_;
my $result= $self->{result};
croak "'is_failed' can't be called until test has been run!"
unless defined $result;
return ($result eq 'MTR_RES_FAILED');
}
sub write_test {
my ($test, $sock, $header)= @_;
# Give the test a unique key before serializing it
$test->{key}= "$test" unless defined $test->{key};
my $serialized= Storable::freeze($test);
$serialized =~ s/([\x0d\x0a\\])/sprintf("\\%02x", ord($1))/eg;
print $sock $header, "\n", $serialized, "\n";
}
sub read_test {
my ($sock)= @_;
my $serialized= <$sock>;
chomp($serialized);
$serialized =~ s/\\([0-9a-fA-F]{2})/chr(hex($1))/eg;
my $test= Storable::thaw($serialized);
die "wrong class (hack attempt?)"
unless ref($test) eq 'My::Test';
return $test;
}
1;