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