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