|
1 #!/usr/bin/perl |
|
2 |
|
3 # Copyright (c) 2009 Symbian Foundation Ltd |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Symbian Foundation Ltd - initial contribution. |
|
11 # Mike Kinghan, mikek@symbian.org |
|
12 # |
|
13 # Contributors: |
|
14 # Maciej Seroka, maciejs@symbian.org |
|
15 # |
|
16 # Description: |
|
17 # This is a tool for sending an ATS testdrop to an ATS server. |
|
18 |
|
19 use strict; |
|
20 use Getopt::Long; |
|
21 use File::Copy; |
|
22 use File::Spec; |
|
23 |
|
24 my $username = "admin"; # ATS server user name |
|
25 my $password = "admin"; # ATS server password |
|
26 my $host; # ATS server hostname |
|
27 my $schedule; # Schedule string for test drop, if any |
|
28 my $host_drop_path; # Directory path on the ATS server where the test drop will be placed. |
|
29 # This must be physically the same path as $local_drop_path, via drive mapping. |
|
30 my $local_drop_path; # Local directory path where the test drop will be placed. |
|
31 # This must be physically the same path as $host_drop_path, via drive mapping. |
|
32 my $local_test_pkg; # Local pathname of the test drop (zip or xml file). The test drop will be |
|
33 # copied from here to $local_drop_path to make it accessible on the server, |
|
34 # unless $local_test_pkg begins with "...". This indicates the test drop is already |
|
35 # present in $local_drop_path and does need to be copied there. The remainder |
|
36 # following "..." is the filename of the test drop. |
|
37 my $help; |
|
38 my $dev_null = $^O =~ /^MSWin/ ? "nul" : "/dev/null"; |
|
39 my $ats_version; # The version of ATS used for running tests |
|
40 my $ats_worker_path; |
|
41 |
|
42 sub usage($); |
|
43 sub help(); |
|
44 sub usage_error(); |
|
45 |
|
46 my %optmap = ( 'host' => \$host, |
|
47 'local-test-pkg' => \$local_test_pkg, |
|
48 'host-drop-path' => \$host_drop_path, |
|
49 'local-drop-path' =>\$local_drop_path, |
|
50 'username' => \$username, |
|
51 'password' => \$password, |
|
52 'schedule' => \$schedule, |
|
53 'ats-version' => \$ats_version, |
|
54 'ats-worker-path' => \$ats_worker_path, |
|
55 'help' => \$help); |
|
56 |
|
57 GetOptions(\%optmap, |
|
58 'host=s', |
|
59 'local-test-pkg=s', |
|
60 'host-drop-path=s', |
|
61 'local-drop-path=s', |
|
62 'username=s', |
|
63 'password=s', |
|
64 'schedule=s', |
|
65 'ats-version=s', |
|
66 'ats-worker-path=s', |
|
67 'help!') |
|
68 or usage_error(); |
|
69 |
|
70 if ($help) { |
|
71 help(); |
|
72 } |
|
73 |
|
74 usage_error(), unless (defined($host) && defined($local_test_pkg) && defined($local_drop_path) && defined($host_drop_path)); |
|
75 |
|
76 # --ats-version is not mandatory. |
|
77 if (!defined($ats_version)) { # Set ats3 by default |
|
78 $ats_version = "ats3" |
|
79 } |
|
80 |
|
81 # --ats-worker-path is not mandatory. |
|
82 if (!defined($ats_worker_path)) { # Set ats3 by default |
|
83 $ats_worker_path = "c:\\apps\\$ats_version\\bin" |
|
84 } |
|
85 |
|
86 my $curl_version = `curl --version 1> $dev_null 2>&1`; |
|
87 die("Need program \"curl\". Not found"), if ($?); |
|
88 die("Test drop path \"$local_drop_path\" not found"), unless ( -d "$local_drop_path"); |
|
89 |
|
90 if (lc($ats_version) eq "ats4") { |
|
91 $host = "http:\/\/" . $host . ":7780\/ServerService", unless ($host =~ /:\d+$/); |
|
92 } else { |
|
93 $host .= ":8080", unless ($host =~ /:\d+$/); |
|
94 } |
|
95 |
|
96 my ($vol,$dir,$pkg); |
|
97 my $local_test_drop; |
|
98 my $host_test_drop; |
|
99 |
|
100 if ($local_test_pkg =~ /^\.\.\.(.+)/ ) { # Local test package name begins with "...". No need to copy. |
|
101 $pkg = $1; # Get the filename of the test package. |
|
102 # Compose the full name of the test drop within the local drop path. |
|
103 $local_test_drop = File::Spec->catfile($local_drop_path,$pkg); |
|
104 die("Test package file \"$local_test_drop\" not found"), unless ( -f "$local_test_drop"); |
|
105 } |
|
106 else { # Local test package must be copied to local drop path. |
|
107 die("Test package file \"$local_test_pkg\" not found"), unless ( -f "$local_test_pkg"); |
|
108 # Compose the full name of the test drop within the local drop path. |
|
109 ($vol,$dir,$pkg) = File::Spec->splitpath($local_test_pkg); |
|
110 $local_test_drop = File::Spec->catfile($local_drop_path,$pkg); |
|
111 if ( -f "$local_test_drop") { |
|
112 # A state test drop of the same name exists. Delete. |
|
113 unlink($local_test_drop) or die("Can't delete stale test drop \"$local_test_drop\". $!"); |
|
114 print("A stale test drop \"$local_test_drop\" existed. Deleted\n"); |
|
115 } |
|
116 # Copy the test drop to the local drop path. |
|
117 copy("$local_test_pkg","$local_test_drop") |
|
118 or die("Cannot copy \"$local_test_pkg\" -> \"$local_test_drop\". $!"); |
|
119 } |
|
120 # Compose the full name of the test drop within the host drop path. |
|
121 $host_test_drop = File::Spec->catfile($host_drop_path,$pkg); |
|
122 # Compose URL to notify server of test drop, requesting run. |
|
123 my $url; |
|
124 if (lc($ats_version) eq "ats4") { |
|
125 $url ="-Xmx512M -cp $ats_worker_path\/..\/plugins\/*;$ats_worker_path\/..\/lib\/util.jar com.nokia.ats.util.server.CommandLineClient -url $host -path $local_test_pkg"; |
|
126 } else { |
|
127 $url ="http://$host/ats3/XTestRunExecute.do?username=$username&password=$password&testrunpath=$host_test_drop"; |
|
128 $url .= "&schedule=$schedule", if (defined($schedule)); |
|
129 } |
|
130 # Post URL to server with cURL. |
|
131 my $curl_cmd; |
|
132 if (lc($ats_version) eq "ats4") { |
|
133 $curl_cmd = "java $url"; |
|
134 } else { |
|
135 $curl_cmd = "curl \"$url\""; |
|
136 } |
|
137 my $curl_response = `$curl_cmd 2>&1`; |
|
138 #die("\nTest drop failed: $!\n"), if ($?); |
|
139 die("\nTest drop failed: $curl_response\n"), if ($?); |
|
140 if (lc($ats_version) eq "ats4") { |
|
141 print "$curl_response\n"; |
|
142 } else { |
|
143 if ($curl_response =~ /(TEST_RUN_REF_ID=\d+)/) { |
|
144 #extract test run id from cURL response. |
|
145 print "$1\n"; |
|
146 } |
|
147 else { |
|
148 print "$curl_response\n"; |
|
149 die("Test drop failed\n"); |
|
150 } |
|
151 } |
|
152 print("Test drop done\n"); |
|
153 |
|
154 exit 0; |
|
155 |
|
156 sub usage($) |
|
157 { |
|
158 my $error = shift; |
|
159 my $fh = $error == 0 ? *STDOUT : *STDERR; |
|
160 print $fh "ats_testdrop.pl\n" . |
|
161 "Send a test drop to an ATS server for execution\n" . |
|
162 "usage:\n" . |
|
163 " ats_testdrop.pl --help\n" . |
|
164 " ats_testdrop.pl --host=HOSTNAME --local-test-pkg=PKGFILE --local-drop-path=LOCALPATH " . |
|
165 " --host-drop-path=HOSTPATH " . |
|
166 "[--username=ATS3USERNAME] [--password=ATS3PASSWORD] [--schedule=DD.MM.YYYY-HH:MM] [--ats-version=VERSION] [--ats-worker-path=ATSPATH]\n" . |
|
167 "options:\n" . |
|
168 " --help Display this help and exit\n" . |
|
169 " --host=HOSTAME HOSTNAME is ATS server\n" . |
|
170 " --local-test-pkg=PKGFILE PKGFILE is the test package.\n" . |
|
171 " If PKGFILE begins \"...\" a filename in LOCALPATH is assumed\n" . |
|
172 " --local-drop-path=LOCALPATH Path to local directory where PKGFILE will be dropped\n" . |
|
173 " --host-drop-path=HOSTPATH Host directory that is mapped to LOCALPATH.\n" . |
|
174 " Must agree with the properties of the registered device that the test package nominates\n" . |
|
175 " --username=ATS3USERNAME ATS3 user to whome the test will belong. Default=admin\n" . |
|
176 " --password=ATS3PASSWORD Password of ATS3 user. Default=admin\n" . |
|
177 " --schedule=DD.MM.YYYY-HH:MM Date-time at which test is to run. Default=as soon as possible\n" . |
|
178 " --ats-version=VERSION Version of ATS which will be used to run the tests. If not specified ATS3 will be set by default.\n" . |
|
179 " --ats-worker-path=ATSPATH Path to the ATS bin directory. If not specified c:\\apps\\\$ats_version\\bin will set by default.\n"; |
|
180 exit $error; |
|
181 } |
|
182 |
|
183 sub help() |
|
184 { |
|
185 usage(0); |
|
186 } |
|
187 |
|
188 sub usage_error() |
|
189 { |
|
190 usage(1); |
|
191 } |
|
192 |
|
193 # EOF |
|
194 |