summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorunknown <dfischer/df@kahlann.erinye.com>2006-11-17 17:02:28 +0100
committerunknown <dfischer/df@kahlann.erinye.com>2006-11-17 17:02:28 +0100
commit880b4e8725ce180f6496308e6ae78355ff8df70e (patch)
tree18a9200f010ee7ea5ce7b6df076539507ccde631 /mysql-test
parent69275092c90f96713f2ebd0f29a41a13f9194985 (diff)
parentc3d6927d58b32af1ec3bcd33bdad7b7b6d02ddd0 (diff)
downloadmariadb-git-880b4e8725ce180f6496308e6ae78355ff8df70e.tar.gz
adaption from 4.1
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/lib/mtr_unique.pl119
-rwxr-xr-xmysql-test/mysql-test-run.pl8
2 files changed, 126 insertions, 1 deletions
diff --git a/mysql-test/lib/mtr_unique.pl b/mysql-test/lib/mtr_unique.pl
new file mode 100644
index 00000000000..9bf86e26f4f
--- /dev/null
+++ b/mysql-test/lib/mtr_unique.pl
@@ -0,0 +1,119 @@
+#
+# This file is used from mysql-test-run.pl when choosing
+# port numbers and directories to use for running mysqld.
+#
+
+use strict;
+use Fcntl ':flock';
+
+#
+# Requested IDs are stored in a hash and released upon END.
+#
+my %mtr_unique_assigned_ids = ();
+END {
+ while(my ($id,$file) = each(%mtr_unique_assigned_ids)) {
+ print "Autoreleasing $file:$id\n";
+ mtr_release_unique_id($file, $id);
+ }
+}
+
+#
+# Require a unique, numerical ID, given a file name (where all
+# requested IDs are stored), a minimum and a maximum value.
+#
+# We use flock to implement locking for the ID file and ignore
+# possible problems arising from lack of support for it on
+# some platforms (it should work on most, and the possible
+# race condition would occur rarely). The proper solution for
+# this is a daemon that manages IDs, of course.
+#
+# If no unique ID within the specified parameters can be
+# obtained, return undef.
+#
+sub mtr_require_unique_id($$$) {
+ my $file = shift;
+ my $min = shift;
+ my $max = shift;
+ my $ret = undef;
+
+ chmod 0777, "$file.sem";
+ open SEM, ">", "$file.sem" or die "can't write to $file.sem";
+ flock SEM, LOCK_EX or die "can't lock $file.sem";
+ if(! -e $file) {
+ open FILE, ">", $file or die "can't create $file";
+ close FILE;
+ }
+ chmod 0777, $file;
+ open FILE, "+<", $file or die "can't open $file";
+ select undef,undef,undef,0.2;
+ seek FILE, 0, 0;
+ my %taken = ();
+ while(<FILE>) {
+ chomp;
+ my ($id, $pid) = split / /;
+ $taken{$id} = $pid;
+ }
+ seek FILE, 0, 2;
+ for(my $i=$min; $i<=$max; ++$i) {
+ if(! exists $taken{$i}) {
+ print FILE "$i $$\n";
+ $ret = $i;
+ last;
+ }
+ }
+ close FILE;
+ flock SEM, LOCK_UN or warn "can't unlock $file.sem";
+ close SEM;
+ $mtr_unique_assigned_ids{$ret} = $file if defined $ret;
+ return $ret;
+}
+
+#
+# Require a unique ID like above, but sleep if no ID can be
+# obtained immediately.
+#
+sub mtr_require_unique_id_and_wait($$$) {
+ my $ret = mtr_require_unique_id($_[0],$_[1],$_[2]);
+ while(! defined $ret) {
+ sleep 10;
+ $ret = mtr_require_unique_id($_[0],$_[1],$_[2]);
+ }
+ return $ret;
+}
+
+#
+# Release a unique ID.
+#
+sub mtr_release_unique_id($$) {
+ my $file = shift;
+ my $myid = shift;
+
+ open SEM, ">", "$file.sem" or die "can't write to $file.sem";
+ flock SEM, LOCK_EX or die "can't lock $file.sem";
+ if(! -e $file) {
+ open FILE, ">", $file or die "can't create $file";
+ close FILE;
+ }
+ open FILE, "+<", $file or die "can't open $file";
+ select undef,undef,undef,0.2;
+ seek FILE, 0, 0;
+ my %taken = ();
+ while(<FILE>) {
+ chomp;
+ my ($id, $pid) = split / /;
+ $taken{$id} = $pid;
+ }
+ delete $taken{$myid};
+ seek FILE, 0, 0;
+ truncate FILE, 0 or die "can't truncate $file";
+ for my $k (keys %taken) {
+ print FILE $k . ' ' . $taken{$k} . "\n";
+ }
+ close FILE;
+ flock SEM, LOCK_UN or warn "can't unlock $file.sem";
+ close SEM;
+ delete $mtr_unique_assigned_ids{$myid};
+}
+
+1;
+
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 74ec2a02c12..024d5c1c452 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -88,6 +88,7 @@ require "lib/mtr_diff.pl";
require "lib/mtr_match.pl";
require "lib/mtr_misc.pl";
require "lib/mtr_stress.pl";
+require "lib/mtr_unique.pl";
$Devel::Trace::TRACE= 1;
@@ -441,7 +442,6 @@ sub main () {
mtr_exit(0);
}
-
##############################################################################
#
# Default settings
@@ -479,6 +479,12 @@ sub command_line_setup () {
# But a fairly safe range seems to be 5001 - 32767
if ( $ENV{'MTR_BUILD_THREAD'} )
{
+ # If so requested, we try to avail ourselves of a unique build thread number.
+ if ( lc($ENV{'MTR_BUILD_THREAD'}) eq 'auto' ) {
+ print "Requesting build thread... ";
+ $ENV{'MTR_BUILD_THREAD'} = mtr_require_unique_id_and_wait("/tmp/mysql-test-ports", 200, 299);
+ print "got ".$ENV{'MTR_BUILD_THREAD'}."\n";
+ }
# Up to two masters, up to three slaves
$opt_master_myport= $ENV{'MTR_BUILD_THREAD'} * 10 + 10000; # and 1
$opt_slave_myport= $opt_master_myport + 2; # and 3 4