common/tools/ats/ats3_testdrop.pl
changeset 91 786a0a00701e
child 99 2c7b53b5228f
equal deleted inserted replaced
90:5b27412eeaf0 91:786a0a00701e
       
     1 #!/usr/bin/perl
       
     2 
       
     3 use strict;
       
     4 use Getopt::Long;
       
     5 use File::Copy;
       
     6 use File::Spec;
       
     7 
       
     8 my $username = "admin";
       
     9 my $password = "admin";
       
    10 my $host;
       
    11 my $schedule;
       
    12 my $host_drop_path;
       
    13 my $local_drop_path;
       
    14 my $local_test_pkg;
       
    15 my $help;
       
    16 
       
    17 sub usage($);
       
    18 sub help();
       
    19 sub usage_error();
       
    20 
       
    21 my %optmap = (  'host' => \$host,
       
    22 			    'local-test-pkg' => \$local_test_pkg,
       
    23 				'host-drop-path' => \$host_drop_path,
       
    24 				'local-drop-path' =>\$local_drop_path,
       
    25 				'username' => \$username,
       
    26 				'password' => \$password,
       
    27 				'schedule' => \$schedule,
       
    28                 'help' => \$help);
       
    29 
       
    30 GetOptions(\%optmap,
       
    31           'host=s',
       
    32           'local-test-pkg=s',
       
    33           'host-drop-path=s',
       
    34           'local-drop-path=s',
       
    35           'username=s',
       
    36           'password=s',
       
    37           'schedule=s',
       
    38           'help!') 
       
    39           or usage_error();
       
    40 
       
    41 if ($help) {
       
    42 	help();
       
    43 }
       
    44 
       
    45 usage_error(), unless (defined($host) && defined($local_test_pkg) && defined($local_drop_path) && defined($host_drop_path));
       
    46 
       
    47 my $cscript_help = `cscript /?`;
       
    48 die("Need command \"cscript\". Not in 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 
       
    52 my ($vol,$dir,$pkg);
       
    53 my $local_test_drop;
       
    54 my $host_test_drop;
       
    55 
       
    56 if ($local_test_pkg =~ /^\.\.\.(.+)/ ) {
       
    57     $pkg = $1;
       
    58     $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);
       
    59     die("Test package file \"$local_test_drop\" not found"), unless ( -f "$local_test_drop");        
       
    60 }
       
    61 else {
       
    62     die("Test package file \"$local_test_pkg\" not found"), unless ( -f "$local_test_pkg");
       
    63     ($vol,$dir,$pkg) = File::Spec->splitpath($local_test_pkg);
       
    64     $local_test_drop = File::Spec->catfile($local_drop_path,$pkg);
       
    65     my $lc_local_test_drop = lc($local_test_drop);
       
    66     my $lc_local_test_pkg = lc($local_test_pkg);    
       
    67     if ("$lc_local_test_drop" ne "$lc_local_test_pkg") {
       
    68         if (unlink($local_test_drop) == 0) {
       
    69             die("Can't delete stale testdrop \"$local_test_drop\". $!");
       
    70         }
       
    71         else {
       
    72             print("A stale testtop \"$local_test_drop\" existed. Deleted\n");
       
    73         }
       
    74         copy("$local_test_pkg","$local_test_drop")
       
    75             or die("Cannot copy \"$local_test_pkg\" -> \"$local_test_drop\". $!");
       
    76     }    
       
    77 }
       
    78 $host_test_drop = File::Spec->catfile($host_drop_path,$pkg);
       
    79 
       
    80 $ENV{'ats3.host'} = $host;
       
    81 $ENV{'ats3.pathToDrop'} = $host_test_drop;
       
    82 $ENV{'ats3.username'} = $username;
       
    83 $ENV{'ats3.password'} = $password;
       
    84 $ENV{'ats3.schedule'} = $schedule, if defined($schedule);
       
    85 system("cscript wshTestRunX.vbs");
       
    86 die("\nTest drop failed: $!"), if ($?);
       
    87 print("\nTest drop done");
       
    88 
       
    89 exit 0;
       
    90 
       
    91 sub usage($)
       
    92 {
       
    93     my $error = shift;
       
    94     my $fh = $error == 0 ? *STDOUT : *STDERR;
       
    95     print $fh "ats3_testdrop.pl\n" .
       
    96             "Send a test drop to an ATS3 server for execution\n" .
       
    97             "usage:\n" .
       
    98             "  ats3_testdrop.pl --help\n" .
       
    99             "  ats3_testdrop.pl --host=HOSTNAME --local-test-pkg=PKGFILE --local-drop-path=LOCALPATH " .
       
   100                 " --host-drop-path=HOSTPATH " .
       
   101                 "[--username=ATS3USERNAME] [--password=ATS3PASSWORD] [--schedule=DD.MM.YYYY-HH:MM]\n" .
       
   102             "options:\n" .
       
   103             "  --help                        Display this help and exit\n" .
       
   104             "  --host=HOSTAME                HOSTNAME is ATS3 server\n" .
       
   105             "  --local-test-pkg=PKGFILE      PKGFILE is the test package.\n" .
       
   106             "                                If PKGFILE begins "..." a filename in LOCALPATH is assumed\n" .
       
   107             "  --local-drop-path=LOCALPATH   Path to local directory where PKGFILE will be dropped\n" .            
       
   108             "  --host-drop-path=HOSTPATH     Host directory that is mapped to LOCALPATH.\n" .
       
   109             "                                Must agree with the properties of the registered device that the test package nominates\n" .
       
   110             "  --username=ATS3USERNAME       ATS3 user to whome the test will belong. Default=admin\n" .
       
   111             "  --password=ATS3PASSWORD       Password of ATS3 user. Default=admin\n" .
       
   112             "  --schedule=DD.MM.YYYY-HH:MM   Date-time at which test is to run. Default=as soon as possible\n";
       
   113     exit $error;            
       
   114 }
       
   115 
       
   116 sub help()
       
   117 {
       
   118     usage(0);
       
   119 }
       
   120 
       
   121 sub usage_error()
       
   122 {
       
   123     usage(1);
       
   124 }             
       
   125 
       
   126 # EOF
       
   127