Francois Gouget : testbot/scripts: Add a TestAgent script to test the TestAgentd server.

Alexandre Julliard julliard at winehq.org
Thu Oct 18 14:00:10 CDT 2012


Module: tools
Branch: master
Commit: 655c406c0a44b561cc3810d16bb87c24f3cf9bce
URL:    http://source.winehq.org/git/tools.git/?a=commit;h=655c406c0a44b561cc3810d16bb87c24f3cf9bce

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Thu Oct 18 15:37:21 2012 +0200

testbot/scripts: Add a TestAgent script to test the TestAgentd server.

---

 testbot/scripts/TestAgent |  179 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 179 insertions(+), 0 deletions(-)

diff --git a/testbot/scripts/TestAgent b/testbot/scripts/TestAgent
new file mode 100755
index 0000000..2e9850d
--- /dev/null
+++ b/testbot/scripts/TestAgent
@@ -0,0 +1,179 @@
+#!/usr/bin/perl -w
+#
+# This is a testagentd client. It can be used to exchange files or run
+# commands on VMs, mostly for testing purposes.
+#
+# Copyright 2012 Francois Gouget
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+use strict;
+
+my $name0=$0;
+$name0 =~ s+^.*/++;
+
+
+my $Dir;
+sub BEGIN
+{
+  $0 =~ m=^(.*)/[^/]*$=;
+  $Dir = $1;
+}
+use lib "$Dir/../lib";
+
+use WineTestBot::Config;
+use WineTestBot::TestAgent;
+use WineTestBot::Log;
+
+sub error(@)
+{
+    print STDERR "$name0:error: ", @_;
+}
+
+my ($Cmd, $Hostname, $HostPathName, $GuestPathName, $Script, $ScriptTimeout);
+my $Port;
+my $Timeout;
+my $Usage;
+
+sub check_opt_val($$)
+{
+    my ($option, $val)=@_;
+
+    if (defined $val)
+    {
+        error("$option can only be specified once\n");
+        $Usage=2; # but continue processing this option
+    }
+    if (!@ARGV)
+    {
+        error("missing value for $option\n");
+        $Usage=2;
+        return undef;
+    }
+    return shift @ARGV;
+}
+
+while (@ARGV)
+{
+    my $arg=shift @ARGV;
+    if ($arg eq "--help")
+    {
+        $Usage=0;
+    }
+    elsif ($arg eq "--port")
+    {
+        $Port=check_opt_val($arg, $Port);
+    }
+    elsif ($arg eq "--timeout")
+    {
+        $ScriptTimeout=check_opt_val($arg, $ScriptTimeout);
+    }
+    elsif (!defined $Hostname)
+    {
+        $Hostname = $arg;
+    }
+    elsif ($arg eq "send")
+    {
+        $HostPathName=check_opt_val($arg, $HostPathName);
+        $GuestPathName=check_opt_val($arg, $GuestPathName) if (!$Usage);
+        $Cmd = $arg;
+    }
+    elsif ($arg eq "get")
+    {
+        $GuestPathName=check_opt_val($arg, $GuestPathName);
+        $HostPathName=check_opt_val($arg, $HostPathName) if (!$Usage);
+        $Cmd = $arg;
+    }
+    elsif ($arg eq "runscript")
+    {
+        $Script=check_opt_val($arg, $Script);
+        $Cmd = $arg;
+    }
+    elsif ($arg eq "status")
+    {
+        $Cmd = $arg;
+    }
+    else
+    {
+        error("unknown command $arg\n");
+        $Usage = 2;
+    }
+}
+
+if (!defined $Usage)
+{
+    if (!defined $Cmd)
+    {
+        error("you must specify a command to run\n");
+        $Usage = 2;
+    }
+    $AgentPort = $Port if (defined $Port);
+}
+if (defined $Usage)
+{
+    if ($Usage)
+    {
+        error("try '$name0 --help' for more information\n");
+        exit $Usage;
+    }
+    print "Usage: $name0 [options] <hostname> send <hostpath> <guestpath>\n";
+    print "or     $name0 [options] <hostname> get <guestpath> <hostpath>\n";
+    print "or     $name0 [options] <hostname> runscript <command>\n";
+    print "or     $name0 [options] <hostname> status\n";
+    print "\n";
+    print "This is a testagentd client. It can be used to send/receive files and to run scripts on the specified guest host.\n";
+    print "\n";
+    print "Where:\n";
+    print "  send          Sends the <hostpath> file and saves it as <guestpath> on the\n";
+    print "                 guest.\n";
+    print "  get           Retrieves the <guestpath> file from the guest and saves it as\n";
+    print "                 <hostpath>.\n";
+    print "  runscript     Runs the specified <command> on the guest.\n";
+    print "  status        Retrieves the status of the last command that was run on the\n";
+    print "                 guest.\n";
+    print "  <hostname>    Is the hostname of the guest.\n";
+    print "  --port <port> Use the specified port number instead of the default one.\n";
+    print "  --timeout <timeout> Use the specified timeout (in seconds) instead of the\n";
+    print "                 default one.\n";
+    print "  --help        Shows this usage message.\n";
+    exit 0;
+}
+
+my $Err;
+if ($Cmd eq "send")
+{
+    $Err = TestAgent::SendFile($Hostname, $HostPathName, $GuestPathName);
+}
+elsif ($Cmd eq "get")
+{
+    $Err = TestAgent::GetFile($Hostname, $GuestPathName, $HostPathName);
+}
+elsif ($Cmd eq "runscript")
+{
+    $Err = TestAgent::RunScript($Hostname, $Script, $ScriptTimeout);
+}
+elsif ($Cmd eq "status")
+{
+    my $Status;
+    ($Status, $Err) = TestAgent::GetStatus($Hostname);
+    print "Status=$Status";
+}
+
+if ($Err)
+{
+    error("$Err\n");
+    exit 1;
+}
+
+exit 0;




More information about the wine-cvs mailing list