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