summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Schmidt <janosch@webgods.de>2013-02-13 17:06:43 +0100
committerJan Schmidt <janosch@webgods.de>2013-02-25 10:25:05 +0100
commit357016f736ca59ece0ce6f1b2d89a21912cbaa48 (patch)
treefba9955e6f4123531eebced3076756113c88cbcb
parentf9ad755f89981a59de3b700473cb737d6a3ccdd6 (diff)
downloadfar-progs-357016f736ca59ece0ce6f1b2d89a21912cbaa48.tar.gz
far-progs: added ssh master/slave to test.pl
A single ssh connection is now used to multiplex all ssh commands. This speeds up tests by approximately 1sec per test.
-rwxr-xr-xtest.pl37
1 files changed, 35 insertions, 2 deletions
diff --git a/test.pl b/test.pl
index bcc3a4c..8f137dd 100755
--- a/test.pl
+++ b/test.pl
@@ -25,6 +25,7 @@ use Symbol qw(gensym);
my @fs = qw(btrfs zfs);
my %opts = ();
+my $ssh_chld = 0;
sub usage {
print STDERR <<EO_USAGE;
@@ -56,9 +57,10 @@ sub do_local {
}
my $remote_host;
+my $ssh_socket;
sub args_for_remote {
return @_ if !$remote_host;
- return ("ssh", "-l", "root", $remote_host,
+ return ("ssh", "-l", "root", "-S", $ssh_socket, $remote_host,
map {ref($_) ? $_ : quotemeta($_)} @_);
}
@@ -132,7 +134,7 @@ sub capture_local {
}
waitpid($pid, 0);
if ($? && !$args->{mayfail}) {
- die "\nERROR from command: @_\noutput:\n$data\n";
+ die "\nERROR from command ($?): @_\noutput:\n$data\n";
}
my $t_elapsed = int((time - $t_start) * 100)/100;
verbose("done ($t_elapsed sec)\n");
@@ -206,6 +208,7 @@ my $src_mnt = "$p_fardir/mnt-src";
my $verbose = $opts{v} ? "-v" : "";
my $keep_temp = $opts{k};
$remote_host = $opts{r};
+$ssh_socket = "$p_fardir/ssh_sock";
my ($src_type_opt, @p_send, $src_send, $dst_subvol, $send_incr_opt);
if ($src_type eq "zfs") {
@@ -225,6 +228,18 @@ if ($src_type eq "zfs") {
die;
}
+sub cleanup {
+ if ($ssh_chld) {
+ kill "TERM", $ssh_chld;
+ unlink $ssh_socket;
+ }
+}
+local $SIG{INT} = sub {
+ $SIG{INT} = "DEFAULT";
+ cleanup();
+ kill "INT", $$;
+};
+
sub snapshot_path {
return "$src_mnt/\@$_[0]" if ($src_type eq "btrfs");
return "$src_mnt/.zfs/snapshot/$_[0]" if ($src_type eq "zfs");
@@ -288,6 +303,20 @@ if ($opts{t}) {
mkdir($p_fardir) or die "mkdir for temp dir $p_fardir failed: $!\n";
mkdir($dst_mnt) or die "mkdir $dst_mnt failed: $!\n";
if ($remote_host) {
+ # setup shared socket
+ $ssh_chld = fork();
+ if (!defined $ssh_chld) {
+ die "fork failed: $!\n";
+ }
+ if (!$ssh_chld) {
+ close(STDIN);
+ close(STDOUT);
+ close(STDERR);
+ exec("ssh", "-M", "-N", "-l", "root", "-S",
+ $ssh_socket, $remote_host);
+ die "exec failed: $!\n";
+ }
+ verbose("ssh master has pid $ssh_chld, socket $ssh_socket\n");
do_remote("mkdir", $p_fardir);
do_remote("mkdir", $src_mnt);
} else {
@@ -383,3 +412,7 @@ if (!$keep_temp) {
}
exit($ex_ret);
+
+END {
+ cleanup();
+};