11 # Mike Kinghan, mikek@symbian.org |
11 # Mike Kinghan, mikek@symbian.org |
12 # |
12 # |
13 # Contributors: |
13 # Contributors: |
14 # |
14 # |
15 # Description: |
15 # Description: |
16 # This is a tool for sending an ATS3 testdrop to an ATS3 server. |
16 # This is a tool for sending an ATS testdrop to an ATS server. |
17 |
17 |
18 use strict; |
18 use strict; |
19 use Getopt::Long; |
19 use Getopt::Long; |
20 use File::Copy; |
20 use File::Copy; |
21 use File::Spec; |
21 use File::Spec; |
22 |
22 |
23 my $username = "admin"; |
23 my $username = "admin"; # ATS server user name |
24 my $password = "admin"; |
24 my $password = "admin"; # ATS server password |
25 my $host; |
25 my $host; # ATS server hostname |
26 my $schedule; |
26 my $schedule; # Schedule string for test drop, if any |
27 my $host_drop_path; |
27 my $host_drop_path; # Directory path on the ATS server where the test drop will be placed. |
28 my $local_drop_path; |
28 # This must be physically the same path as $local_drop_path, via drive mapping. |
29 my $local_test_pkg; |
29 my $local_drop_path; # Local directory path where the test drop will be placed. |
|
30 # This must be physically the same path as $host_drop_path, via drive mapping. |
|
31 my $local_test_pkg; # Local pathname of the test drop (zip or xml file). The test drop will be |
|
32 # copied from here to $local_drop_path to make it accessible on the server, |
|
33 # unless $local_test_pkg begins with "...". This indicates the test drop is already |
|
34 # present in $local_drop_path and does need to be copied there. The remainder |
|
35 # following "..." is the filename of the test drop. |
30 my $help; |
36 my $help; |
31 my $dev_null = $^O =~ /^MSWin/ ? "nul" : "/dev/null"; |
37 my $dev_null = $^O =~ /^MSWin/ ? "nul" : "/dev/null"; |
32 |
38 |
33 sub usage($); |
39 sub usage($); |
34 sub help(); |
40 sub help(); |
58 help(); |
64 help(); |
59 } |
65 } |
60 |
66 |
61 usage_error(), unless (defined($host) && defined($local_test_pkg) && defined($local_drop_path) && defined($host_drop_path)); |
67 usage_error(), unless (defined($host) && defined($local_test_pkg) && defined($local_drop_path) && defined($host_drop_path)); |
62 |
68 |
63 my $curl_version = $^O =~ /^MSWin/ ? `curl --version 1> $dev_null 2>&1` : `curl --version 1> $dev_null 2>&1`; |
69 my $curl_version = `curl --version 1> $dev_null 2>&1`; |
64 die("Need program \"curl\". Not found"), if ($?); |
70 die("Need program \"curl\". Not found"), if ($?); |
65 die("Test drop path \"$local_drop_path\" not found"), unless ( -d "$local_drop_path"); |
71 die("Test drop path \"$local_drop_path\" not found"), unless ( -d "$local_drop_path"); |
66 |
72 |
67 $host .= ":8080", unless ($host =~ /:\d+$/); |
73 $host .= ":8080", unless ($host =~ /:\d+$/); |
68 |
74 |
69 my ($vol,$dir,$pkg); |
75 my ($vol,$dir,$pkg); |
70 my $local_test_drop; |
76 my $local_test_drop; |
71 my $host_test_drop; |
77 my $host_test_drop; |
72 |
78 |
73 if ($local_test_pkg =~ /^\.\.\.(.+)/ ) { |
79 if ($local_test_pkg =~ /^\.\.\.(.+)/ ) { # Local test package name begins with "...". No need to copy. |
74 $pkg = $1; |
80 $pkg = $1; # Get the filename of the test package. |
75 $local_test_drop = File::Spec->catfile($local_drop_path,$pkg); |
81 # Compose the full name of the test drop within the local drop path. |
|
82 $local_test_drop = File::Spec->catfile($local_drop_path,$pkg); |
76 die("Test package file \"$local_test_drop\" not found"), unless ( -f "$local_test_drop"); |
83 die("Test package file \"$local_test_drop\" not found"), unless ( -f "$local_test_drop"); |
77 } |
84 } |
78 else { |
85 else { # Local test package must be copied to local drop path. |
79 die("Test package file \"$local_test_pkg\" not found"), unless ( -f "$local_test_pkg"); |
86 die("Test package file \"$local_test_pkg\" not found"), unless ( -f "$local_test_pkg"); |
|
87 # Compose the full name of the test drop within the local drop path. |
80 ($vol,$dir,$pkg) = File::Spec->splitpath($local_test_pkg); |
88 ($vol,$dir,$pkg) = File::Spec->splitpath($local_test_pkg); |
81 $local_test_drop = File::Spec->catfile($local_drop_path,$pkg); |
89 $local_test_drop = File::Spec->catfile($local_drop_path,$pkg); |
82 if ( -f "$local_test_drop") { |
90 if ( -f "$local_test_drop") { |
83 my $cmp_local_test_drop = $local_test_drop; |
91 # A state test drop of the same name exists. Delete. |
84 my $cmp_local_test_pkg = $local_test_pkg; |
92 unlink($local_test_drop) or die("Can't delete stale test drop \"$local_test_drop\". $!"); |
85 if ($^O =~ /^MSWin/) { |
93 print("A stale test drop \"$local_test_drop\" existed. Deleted\n"); |
86 $cmp_local_test_drop = lc($local_test_drop); |
|
87 $cmp_local_test_pkg = lc($local_test_pkg); |
|
88 } |
|
89 if ("$cmp_local_test_drop" eq "$cmp_local_test_pkg") { |
|
90 if (unlink($local_test_drop) == 0) { |
|
91 die("Can't delete stale test drop \"$local_test_drop\". $!"); |
|
92 } |
|
93 else { |
|
94 print("A stale test drop \"$local_test_drop\" existed. Deleted\n"); |
|
95 } |
|
96 } |
|
97 } |
94 } |
|
95 # Copy the test drop to the local drop path. |
98 copy("$local_test_pkg","$local_test_drop") |
96 copy("$local_test_pkg","$local_test_drop") |
99 or die("Cannot copy \"$local_test_pkg\" -> \"$local_test_drop\". $!"); |
97 or die("Cannot copy \"$local_test_pkg\" -> \"$local_test_drop\". $!"); |
100 } |
98 } |
|
99 # Compose the full name of the test drop within the host drop path. |
101 $host_test_drop = File::Spec->catfile($host_drop_path,$pkg); |
100 $host_test_drop = File::Spec->catfile($host_drop_path,$pkg); |
|
101 # Compose URL to notify server of test drop, requesting run. |
102 my $url ="http://$host/ats3/XTestRunExecute.do?username=$username&password=$password&testrunpath=$host_test_drop"; |
102 my $url ="http://$host/ats3/XTestRunExecute.do?username=$username&password=$password&testrunpath=$host_test_drop"; |
103 $url .= "&schedule=$schedule", if (defined($schedule)); |
103 $url .= "&schedule=$schedule", if (defined($schedule)); |
|
104 # Post URL to server with cURL. |
104 my $curl_cmd = "curl \"$url\""; |
105 my $curl_cmd = "curl \"$url\""; |
105 system("$curl_cmd"); |
106 my $curl_response = `$curl_cmd 2>&1`; |
106 die("\nTest drop failed: $!"), if ($?); |
107 die("\nTest drop failed: $!\n"), if ($?); |
107 print("\nTest drop done"); |
108 if ($curl_response =~ /(TEST_RUN_REF_ID=\d+)/) { |
|
109 #extract test run id from cURL response. |
|
110 print "$1\n"; |
|
111 } |
|
112 else { |
|
113 print "$curl_response\n"; |
|
114 die("Test drop failed\n"); |
|
115 } |
|
116 print("Test drop done\n"); |
108 |
117 |
109 exit 0; |
118 exit 0; |
110 |
119 |
111 sub usage($) |
120 sub usage($) |
112 { |
121 { |