common/tools/ats/ats3_testdrop.pl
changeset 134 039d0b7e56f3
parent 113 7f0174848f99
child 139 7f5b4e3699cb
--- a/common/tools/ats/ats3_testdrop.pl	Thu May 28 14:55:09 2009 +0100
+++ b/common/tools/ats/ats3_testdrop.pl	Wed Jun 03 11:21:24 2009 +0100
@@ -13,20 +13,26 @@
 # Contributors:
 #
 # Description:
-#   This is a tool for sending an ATS3 testdrop to an ATS3 server.
+#   This is a tool for sending an ATS testdrop to an ATS server.
 
 use strict;
 use Getopt::Long;
 use File::Copy;
 use File::Spec;
 
-my $username = "admin";
-my $password = "admin";
-my $host;
-my $schedule;
-my $host_drop_path;
-my $local_drop_path;
-my $local_test_pkg;
+my $username = "admin"; # ATS server user name
+my $password = "admin"; # ATS server password
+my $host;   # ATS server hostname
+my $schedule;   # Schedule string for test drop, if any
+my $host_drop_path; # Directory path on the ATS server where the test drop will be placed.
+                    # This must be physically the same path as $local_drop_path, via drive mapping. 
+my $local_drop_path; # Local directory path where the test drop will be placed.
+                    # This must be physically the same path as $host_drop_path, via drive mapping.
+my $local_test_pkg; # Local pathname of the test drop (zip or xml file). The test drop will be
+                    # copied from here to $local_drop_path to make it accessible on the server,
+                    # unless $local_test_pkg begins with "...". This indicates the test drop is already
+                    # present in $local_drop_path and does need to be copied there. The remainder
+                    # following "..." is the filename of the test drop.    
 my $help;
 my $dev_null = $^O =~ /^MSWin/ ? "nul" : "/dev/null";
 
@@ -60,7 +66,7 @@
 
 usage_error(), unless (defined($host) && defined($local_test_pkg) && defined($local_drop_path) && defined($host_drop_path));
 
-my $curl_version = $^O =~ /^MSWin/ ? `curl --version 1> $dev_null 2>&1` : `curl --version 1> $dev_null 2>&1`;
+my $curl_version = `curl --version 1> $dev_null 2>&1`;
 die("Need program \"curl\". Not found"), if ($?);
 die("Test drop path \"$local_drop_path\" not found"), unless ( -d "$local_drop_path");
 
@@ -70,41 +76,44 @@
 my $local_test_drop;
 my $host_test_drop;
 
-if ($local_test_pkg =~ /^\.\.\.(.+)/ ) {
-    $pkg = $1;
-    $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);
+if ($local_test_pkg =~ /^\.\.\.(.+)/ ) { # Local test package name begins with "...". No need to copy. 
+    $pkg = $1; # Get the filename of the test package.
+    # Compose the full name of the test drop within the local drop path.
+    $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);    
     die("Test package file \"$local_test_drop\" not found"), unless ( -f "$local_test_drop");        
 }
-else {
+else { # Local test package must be copied to local drop path.
     die("Test package file \"$local_test_pkg\" not found"), unless ( -f "$local_test_pkg");
+    # Compose the full name of the test drop within the local drop path.    
     ($vol,$dir,$pkg) = File::Spec->splitpath($local_test_pkg);
     $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);
     if ( -f "$local_test_drop") {
-        my $cmp_local_test_drop = $local_test_drop;
-        my $cmp_local_test_pkg = $local_test_pkg;
-        if ($^O =~ /^MSWin/) {
-            $cmp_local_test_drop = lc($local_test_drop);
-            $cmp_local_test_pkg = lc($local_test_pkg);        
-        }   
-        if ("$cmp_local_test_drop" eq "$cmp_local_test_pkg") {
-            if (unlink($local_test_drop) == 0) {
-                die("Can't delete stale test drop \"$local_test_drop\". $!");
-            }
-            else {
-                print("A stale test drop \"$local_test_drop\" existed. Deleted\n");
-            }
-        }
+        # A state test drop of the same name exists. Delete.
+        unlink($local_test_drop) or die("Can't delete stale test drop \"$local_test_drop\". $!");
+        print("A stale test drop \"$local_test_drop\" existed. Deleted\n");
     }
+    # Copy the test drop to the local drop path.
     copy("$local_test_pkg","$local_test_drop")
         or die("Cannot copy \"$local_test_pkg\" -> \"$local_test_drop\". $!");
 }
+# Compose the full name of the test drop within the host drop path.
 $host_test_drop = File::Spec->catfile($host_drop_path,$pkg);
+# Compose URL to notify server of test drop, requesting run.
 my $url ="http://$host/ats3/XTestRunExecute.do?username=$username&password=$password&testrunpath=$host_test_drop";
 $url .= "&schedule=$schedule", if (defined($schedule));
+# Post URL to server with cURL.
 my $curl_cmd = "curl \"$url\"";
-system("$curl_cmd");
-die("\nTest drop failed: $!"), if ($?);
-print("\nTest drop done");
+my $curl_response = `$curl_cmd 2>$1`;
+die("\nTest drop failed: $!\n"), if ($?);
+if ($curl_response =~ /(TEST_RUN_REF_ID=\d+)/) {
+    #extract test run id from cURL response.
+    print "$1\n";
+}
+else {
+    print "$curl_response\n";
+    die("Test drop failed\n");
+} 
+print("Test drop done\n");
 
 exit 0;