common/tools/ats/ats3_testdrop.pl
changeset 99 2c7b53b5228f
parent 91 786a0a00701e
child 105 3aef06ac7a6a
equal deleted inserted replaced
98:aa585d28e584 99:2c7b53b5228f
     1 #!/usr/bin/perl
     1 #!/usr/bin/perl
     2 
     2 
       
     3 #curl "http://sym-build01:8080/ats3/XTestRunExecute.do?username=admin&password=admin&testrunpath=D:\smoketests\test_drops\9.zip
     3 use strict;
     4 use strict;
     4 use Getopt::Long;
     5 use Getopt::Long;
     5 use File::Copy;
     6 use File::Copy;
     6 use File::Spec;
     7 use File::Spec;
     7 
     8 
    11 my $schedule;
    12 my $schedule;
    12 my $host_drop_path;
    13 my $host_drop_path;
    13 my $local_drop_path;
    14 my $local_drop_path;
    14 my $local_test_pkg;
    15 my $local_test_pkg;
    15 my $help;
    16 my $help;
       
    17 my $dev_null = $^O =~ /^MSWin/ ? "nul" : "/dev/null";
    16 
    18 
    17 sub usage($);
    19 sub usage($);
    18 sub help();
    20 sub help();
    19 sub usage_error();
    21 sub usage_error();
    20 
    22 
    42 	help();
    44 	help();
    43 }
    45 }
    44 
    46 
    45 usage_error(), unless (defined($host) && defined($local_test_pkg) && defined($local_drop_path) && defined($host_drop_path));
    47 usage_error(), unless (defined($host) && defined($local_test_pkg) && defined($local_drop_path) && defined($host_drop_path));
    46 
    48 
    47 my $cscript_help = `cscript /?`;
    49 my $curl_version = $^O =~ /^MSWin/ ? `curl --version 1> $dev_null 2>&1` : `curl --version 1> $dev_null 2>&1`;
    48 die("Need command \"cscript\". Not in found"), if ($?);
    50 die("Need program \"curl\". Not found"), if ($?);
    49 die("Need VB script wshTestRunX.vbs. Not found"), unless ( -f "wshTestRunX.vbs");
       
    50 die("Test drop path \"$local_drop_path\" not found"), unless ( -d "$local_drop_path");
    51 die("Test drop path \"$local_drop_path\" not found"), unless ( -d "$local_drop_path");
       
    52 
       
    53 $host .= ":8080", unless ($host =~ /:\d+$/);
    51 
    54 
    52 my ($vol,$dir,$pkg);
    55 my ($vol,$dir,$pkg);
    53 my $local_test_drop;
    56 my $local_test_drop;
    54 my $host_test_drop;
    57 my $host_test_drop;
    55 
    58 
    60 }
    63 }
    61 else {
    64 else {
    62     die("Test package file \"$local_test_pkg\" not found"), unless ( -f "$local_test_pkg");
    65     die("Test package file \"$local_test_pkg\" not found"), unless ( -f "$local_test_pkg");
    63     ($vol,$dir,$pkg) = File::Spec->splitpath($local_test_pkg);
    66     ($vol,$dir,$pkg) = File::Spec->splitpath($local_test_pkg);
    64     $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);
    67     $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);
    65     my $lc_local_test_drop = lc($local_test_drop);
    68     if ( -f "$local_test_drop") {
    66     my $lc_local_test_pkg = lc($local_test_pkg);    
    69         my $cmp_local_test_drop = $local_test_drop;
    67     if ("$lc_local_test_drop" ne "$lc_local_test_pkg") {
    70         my $cmp_local_test_pkg = $local_test_pkg;
    68         if (unlink($local_test_drop) == 0) {
    71         if ($^O =~ /^MSWin/) {
    69             die("Can't delete stale testdrop \"$local_test_drop\". $!");
    72             $cmp_local_test_drop = lc($local_test_drop);
       
    73             $cmp_local_test_pkg = lc($local_test_pkg);        
       
    74         }   
       
    75         if ("$cmp_local_test_drop" eq "$cmp_local_test_pkg") {
       
    76             if (unlink($local_test_drop) == 0) {
       
    77                 die("Can't delete stale test drop \"$local_test_drop\". $!");
       
    78             }
       
    79             else {
       
    80                 print("A stale test drop \"$local_test_drop\" existed. Deleted\n");
       
    81             }
    70         }
    82         }
    71         else {
    83     }
    72             print("A stale testtop \"$local_test_drop\" existed. Deleted\n");
    84     copy("$local_test_pkg","$local_test_drop")
    73         }
    85         or die("Cannot copy \"$local_test_pkg\" -> \"$local_test_drop\". $!");
    74         copy("$local_test_pkg","$local_test_drop")
       
    75             or die("Cannot copy \"$local_test_pkg\" -> \"$local_test_drop\". $!");
       
    76     }    
       
    77 }
    86 }
    78 $host_test_drop = File::Spec->catfile($host_drop_path,$pkg);
    87 $host_test_drop = File::Spec->catfile($host_drop_path,$pkg);
    79 
    88 my $url ="http://$host/ats3/XTestRunExecute.do?username=$username&password=$password&testrunpath=$host_test_drop";
    80 $ENV{'ats3.host'} = $host;
    89 $url .= "&schedule=$schedule", if (defined($schedule));
    81 $ENV{'ats3.pathToDrop'} = $host_test_drop;
    90 my $curl_cmd = "curl \"$url\"";
    82 $ENV{'ats3.username'} = $username;
    91 system("$curl_cmd");
    83 $ENV{'ats3.password'} = $password;
       
    84 $ENV{'ats3.schedule'} = $schedule, if defined($schedule);
       
    85 system("cscript wshTestRunX.vbs");
       
    86 die("\nTest drop failed: $!"), if ($?);
    92 die("\nTest drop failed: $!"), if ($?);
    87 print("\nTest drop done");
    93 print("\nTest drop done");
    88 
    94 
    89 exit 0;
    95 exit 0;
    90 
    96