1*b1cdbd2cSJim Jagielski:
2*b1cdbd2cSJim Jagielskieval 'exec perl -wS $0 ${1+"$@"}'
3*b1cdbd2cSJim Jagielski    if 0;
4*b1cdbd2cSJim Jagielski
5*b1cdbd2cSJim Jagielski#**************************************************************
6*b1cdbd2cSJim Jagielski#
7*b1cdbd2cSJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
8*b1cdbd2cSJim Jagielski#  or more contributor license agreements.  See the NOTICE file
9*b1cdbd2cSJim Jagielski#  distributed with this work for additional information
10*b1cdbd2cSJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
11*b1cdbd2cSJim Jagielski#  to you under the Apache License, Version 2.0 (the
12*b1cdbd2cSJim Jagielski#  "License"); you may not use this file except in compliance
13*b1cdbd2cSJim Jagielski#  with the License.  You may obtain a copy of the License at
14*b1cdbd2cSJim Jagielski#
15*b1cdbd2cSJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
16*b1cdbd2cSJim Jagielski#
17*b1cdbd2cSJim Jagielski#  Unless required by applicable law or agreed to in writing,
18*b1cdbd2cSJim Jagielski#  software distributed under the License is distributed on an
19*b1cdbd2cSJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20*b1cdbd2cSJim Jagielski#  KIND, either express or implied.  See the License for the
21*b1cdbd2cSJim Jagielski#  specific language governing permissions and limitations
22*b1cdbd2cSJim Jagielski#  under the License.
23*b1cdbd2cSJim Jagielski#
24*b1cdbd2cSJim Jagielski#**************************************************************
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski#
29*b1cdbd2cSJim Jagielski# cwstestresult.pl - publish results of CWS tests to EIS
30*b1cdbd2cSJim Jagielski#
31*b1cdbd2cSJim Jagielski
32*b1cdbd2cSJim Jagielskiuse strict;
33*b1cdbd2cSJim Jagielskiuse Getopt::Long;
34*b1cdbd2cSJim Jagielskiuse Cwd;
35*b1cdbd2cSJim Jagielski
36*b1cdbd2cSJim Jagielski#### module lookup
37*b1cdbd2cSJim Jagielskimy @lib_dirs;
38*b1cdbd2cSJim JagielskiBEGIN {
39*b1cdbd2cSJim Jagielski    if ( !defined($ENV{SOLARENV}) ) {
40*b1cdbd2cSJim Jagielski        die "No environment found (environment variable SOLARENV is undefined)";
41*b1cdbd2cSJim Jagielski    }
42*b1cdbd2cSJim Jagielski    push(@lib_dirs, "$ENV{SOLARENV}/bin/modules");
43*b1cdbd2cSJim Jagielski    push(@lib_dirs, "$ENV{COMMON_ENV_TOOLS}/modules") if defined($ENV{COMMON_ENV_TOOLS});
44*b1cdbd2cSJim Jagielski}
45*b1cdbd2cSJim Jagielskiuse lib (@lib_dirs);
46*b1cdbd2cSJim Jagielski
47*b1cdbd2cSJim Jagielskiuse Cws;
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim Jagielski#### global #####
50*b1cdbd2cSJim Jagielski( my $script_name = $0 ) =~ s/^.*\b(\w+)\.pl$/$1/;
51*b1cdbd2cSJim Jagielski
52*b1cdbd2cSJim Jagielskimy $is_debug = 1;       	# enable debug
53*b1cdbd2cSJim Jagielskimy $opt_master;          	# option: master workspace
54*b1cdbd2cSJim Jagielskimy $opt_child;    	        # option: child workspace
55*b1cdbd2cSJim Jagielskimy $opt_milestone;    	        # option: milestone
56*b1cdbd2cSJim Jagielskimy $opt_testrunName;  		# option: testrunName
57*b1cdbd2cSJim Jagielskimy $opt_testrunPlatform;	# option: testrunPlatfrom
58*b1cdbd2cSJim Jagielskimy $opt_resultPage;     	# option: resultPage
59*b1cdbd2cSJim Jagielski
60*b1cdbd2cSJim Jagielski
61*b1cdbd2cSJim Jagielski#### main #####
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielskimy $arg_status= parse_options();
64*b1cdbd2cSJim Jagielskitestresult($arg_status);
65*b1cdbd2cSJim Jagielskiexit(0);
66*b1cdbd2cSJim Jagielski
67*b1cdbd2cSJim Jagielski#### subroutines ####
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim Jagielskisub testresult
70*b1cdbd2cSJim Jagielski{
71*b1cdbd2cSJim Jagielski    my $status = shift;
72*b1cdbd2cSJim Jagielski    # get master and child workspace
73*b1cdbd2cSJim Jagielski    my $masterws = $opt_master ? uc($opt_master) : $ENV{WORK_STAMP};
74*b1cdbd2cSJim Jagielski    my $milestone = $opt_milestone ? $opt_milestone : $ENV{UPDMINOR};
75*b1cdbd2cSJim Jagielski    my $childws  = $opt_milestone ? undef : ( $opt_child  ? $opt_child  : $ENV{CWS_WORK_STAMP} );
76*b1cdbd2cSJim Jagielski
77*b1cdbd2cSJim Jagielski    if ( !defined($masterws) ) {
78*b1cdbd2cSJim Jagielski        print_error("Can't determine master workspace environment.\n"
79*b1cdbd2cSJim Jagielski                    . "Please initialize environment with setsolar ...", 1);
80*b1cdbd2cSJim Jagielski    }
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski    if ( !defined($childws) && !defined($milestone) ) {
83*b1cdbd2cSJim Jagielski        print_error("Can't determine child workspace environment or milestone.\n"
84*b1cdbd2cSJim Jagielski                    . "Please initialize environment with setsolar ...", 1);
85*b1cdbd2cSJim Jagielski    }
86*b1cdbd2cSJim Jagielski    if ( !defined($opt_resultPage) ) {
87*b1cdbd2cSJim Jagielski	$opt_resultPage="";
88*b1cdbd2cSJim Jagielski    }
89*b1cdbd2cSJim Jagielski    my $cws = Cws->new();
90*b1cdbd2cSJim Jagielski    if ( defined($childws) ) {
91*b1cdbd2cSJim Jagielski	    $cws->child($childws);
92*b1cdbd2cSJim Jagielski    }
93*b1cdbd2cSJim Jagielski    $cws->master($masterws);
94*b1cdbd2cSJim Jagielski    my $eis = $cws->eis();
95*b1cdbd2cSJim Jagielski
96*b1cdbd2cSJim Jagielski    no strict;
97*b1cdbd2cSJim Jagielski    my $result='';
98*b1cdbd2cSJim Jagielski
99*b1cdbd2cSJim Jagielski    if ( defined($childws) ) {
100*b1cdbd2cSJim Jagielski        $opt_resultPage=SOAP::Data->type(string => $opt_resultPage);
101*b1cdbd2cSJim Jagielski        my $id = $cws->eis_id();
102*b1cdbd2cSJim Jagielski        if ( is_valid_cws($cws) ) {
103*b1cdbd2cSJim Jagielski            $result=$eis->submitTestResult($id,$opt_testrunName,$opt_testrunPlatform, $opt_resultPage, $status);
104*b1cdbd2cSJim Jagielski	} else {
105*b1cdbd2cSJim Jagielski	     print STDERR "cws is not valid";
106*b1cdbd2cSJim Jagielski	}
107*b1cdbd2cSJim Jagielski    } else {
108*b1cdbd2cSJim Jagielski        $opt_resultPage=SOAP::Data->type(string => $opt_resultPage);
109*b1cdbd2cSJim Jagielski        $result=$eis->submitTestResultMWS($masterws,$milestone,$opt_testrunName,$opt_testrunPlatform, $opt_resultPage, $status);
110*b1cdbd2cSJim Jagielski    }
111*b1cdbd2cSJim Jagielski
112*b1cdbd2cSJim Jagielski    exit(0)
113*b1cdbd2cSJim Jagielski}
114*b1cdbd2cSJim Jagielski
115*b1cdbd2cSJim Jagielski
116*b1cdbd2cSJim Jagielskisub is_valid_cws
117*b1cdbd2cSJim Jagielski{
118*b1cdbd2cSJim Jagielski    my $cws = shift;
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim Jagielski    my $masterws = $cws->master();
121*b1cdbd2cSJim Jagielski    my $childws  = $cws->child();
122*b1cdbd2cSJim Jagielski    # check if we got a valid child workspace
123*b1cdbd2cSJim Jagielski    my $id = $cws->eis_id();
124*b1cdbd2cSJim Jagielski    if ( !$id ) {
125*b1cdbd2cSJim Jagielski        print_error("Child workspace '$childws' for master workspace '$masterws' not found in EIS database.", 2);
126*b1cdbd2cSJim Jagielski    }
127*b1cdbd2cSJim Jagielski    return 1;
128*b1cdbd2cSJim Jagielski}
129*b1cdbd2cSJim Jagielski
130*b1cdbd2cSJim Jagielskisub parse_options
131*b1cdbd2cSJim Jagielski{
132*b1cdbd2cSJim Jagielski    # parse options and do some sanity checks
133*b1cdbd2cSJim Jagielski    Getopt::Long::Configure("no_ignore_case");
134*b1cdbd2cSJim Jagielski    my $help = 0;
135*b1cdbd2cSJim Jagielski    my $success = GetOptions('h' => \$help,
136*b1cdbd2cSJim Jagielski                             'M=s' => \$opt_master,
137*b1cdbd2cSJim Jagielski                             'm=s' => \$opt_milestone,
138*b1cdbd2cSJim Jagielski                             'c=s' => \$opt_child,
139*b1cdbd2cSJim Jagielski                             'n=s' => \$opt_testrunName,
140*b1cdbd2cSJim Jagielski                             'p=s' => \$opt_testrunPlatform ,
141*b1cdbd2cSJim Jagielski                             'r=s' => \$opt_resultPage );
142*b1cdbd2cSJim Jagielski    if ( $help || !$success || $#ARGV < 0 || (!defined($opt_testrunName)) || ( !defined($opt_testrunPlatform)) ) {
143*b1cdbd2cSJim Jagielski        usage();
144*b1cdbd2cSJim Jagielski        exit(1);
145*b1cdbd2cSJim Jagielski    }
146*b1cdbd2cSJim Jagielski
147*b1cdbd2cSJim Jagielski      print "$opt_master\n";
148*b1cdbd2cSJim Jagielski      print "$opt_milestone\n";
149*b1cdbd2cSJim Jagielski      print "$opt_child\n";
150*b1cdbd2cSJim Jagielski      print "$opt_testrunName\n";
151*b1cdbd2cSJim Jagielski      print "$opt_testrunPlatform\n";
152*b1cdbd2cSJim Jagielski      print "$opt_resultPage\n";
153*b1cdbd2cSJim Jagielski
154*b1cdbd2cSJim Jagielski    if ( defined($opt_milestone) && defined($opt_child) ) {
155*b1cdbd2cSJim Jagielski	print_error("-m and -c are mutually exclusive options",1);
156*b1cdbd2cSJim Jagielski    }
157*b1cdbd2cSJim Jagielski
158*b1cdbd2cSJim Jagielski    return $ARGV[0];
159*b1cdbd2cSJim Jagielski}
160*b1cdbd2cSJim Jagielski
161*b1cdbd2cSJim Jagielski# sub print_message
162*b1cdbd2cSJim Jagielski# {
163*b1cdbd2cSJim Jagielski#     my $message     = shift;
164*b1cdbd2cSJim Jagielski#
165*b1cdbd2cSJim Jagielski#     print STDERR "$script_name: ";
166*b1cdbd2cSJim Jagielski#     print STDERR "$message\n";
167*b1cdbd2cSJim Jagielski#     return;
168*b1cdbd2cSJim Jagielski# }
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim Jagielskisub print_error
171*b1cdbd2cSJim Jagielski{
172*b1cdbd2cSJim Jagielski    my $message     = shift;
173*b1cdbd2cSJim Jagielski    my $error_code  = shift;
174*b1cdbd2cSJim Jagielski
175*b1cdbd2cSJim Jagielski    print STDERR "$script_name: ";
176*b1cdbd2cSJim Jagielski    print STDERR "ERROR: $message\n";
177*b1cdbd2cSJim Jagielski
178*b1cdbd2cSJim Jagielski    if ( $error_code ) {
179*b1cdbd2cSJim Jagielski        print STDERR "\nFAILURE: $script_name aborted.\n";
180*b1cdbd2cSJim Jagielski        exit($error_code);
181*b1cdbd2cSJim Jagielski    }
182*b1cdbd2cSJim Jagielski    return;
183*b1cdbd2cSJim Jagielski}
184*b1cdbd2cSJim Jagielski
185*b1cdbd2cSJim Jagielskisub usage
186*b1cdbd2cSJim Jagielski{
187*b1cdbd2cSJim Jagielski    print STDERR "Usage: cwstestresult[-h] [-M masterws] [-m milestone|-c childws] <-n testrunName> <-p testrunPlatform> <-r resultPage> statusName\n";
188*b1cdbd2cSJim Jagielski    print STDERR "\n";
189*b1cdbd2cSJim Jagielski    print STDERR "Publish result of CWS- or milestone-test to EIS\n";
190*b1cdbd2cSJim Jagielski    print STDERR "\n";
191*b1cdbd2cSJim Jagielski    print STDERR "Options:\n";
192*b1cdbd2cSJim Jagielski    print STDERR "\t-h\t\t\thelp\n";
193*b1cdbd2cSJim Jagielski    print STDERR "\t-M master\t\toverride MWS specified in environment\n";
194*b1cdbd2cSJim Jagielski    print STDERR "\t-m milestone\t\toverride milestone specified in environment\n";
195*b1cdbd2cSJim Jagielski    print STDERR "\t-c child\t\toverride CWS specified in environment\n";
196*b1cdbd2cSJim Jagielski    print STDERR "\t-n testrunName\t\tspecifiy name of the test\n";
197*b1cdbd2cSJim Jagielski    print STDERR "\t-p testrunPlatform\tspecify platform where the test ran on\n";
198*b1cdbd2cSJim Jagielski    print STDERR "\t-r resultPage\t\tspecify name of attachment or hyperlink\n";
199*b1cdbd2cSJim Jagielski    print STDERR "\t\t\t\tfor resultPage\n";
200*b1cdbd2cSJim Jagielski
201*b1cdbd2cSJim Jagielski
202*b1cdbd2cSJim Jagielski    print STDERR "\nExample:\n";
203*b1cdbd2cSJim Jagielski    print STDERR "\tcwstestresult -c mycws -n Performance -p Windows -r PerfomanceTestWindows.html ok\n";
204*b1cdbd2cSJim Jagielski}
205