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