1#!/usr/bin/perl -w 2# ************************************************************* 3# 4# Licensed to the Apache Software Foundation (ASF) under one 5# or more contributor license agreements. See the NOTICE file 6# distributed with this work for additional information 7# regarding copyright ownership. The ASF licenses this file 8# to you under the Apache License, Version 2.0 (the 9# "License"); you may not use this file except in compliance 10# with the License. You may obtain a copy of the License at 11# 12# http://www.apache.org/licenses/LICENSE-2.0 13# 14# Unless required by applicable law or agreed to in writing, 15# software distributed under the License is distributed on an 16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17# KIND, either express or implied. See the License for the 18# specific language governing permissions and limitations 19# under the License. 20# 21# ************************************************************* 22 23# GCOV_RESULT 24# 25# Helper, to interpret the result and put the result via HTML in a database. 26# Put into DB works via php. 27# 28# Q: Why perl? 29# A: regexp ;-) 30# 31 32use strict; 33use File::Basename; 34use Getopt::Long; 35use Time::localtime; 36 37our $version_info = 'gcov helper $Revision: 1.2 $ '; 38 39our $help; # Help option flag 40our $version; # Version option flag 41# our $infile; 42 43our $usedFunctions; # name of all functions filename, which have a value > 0 44our $nonusedFunctions; # name of all functions filename, which have a value == 0 45our $complete; # name of all functions filename, which have a value == 100 46our $incomplete; # name of all functions filename, which have a value > 0 && < 100 47 48our $environment; 49our $major; 50our $minor; 51our $cwsname; 52our $outputDir; 53 54# Prototypes 55sub print_usage(*); 56sub read_gcov_function_file($); 57sub create2DigitNumber($); 58 59# Parse command line options 60if (!GetOptions( 61 "help" => \$help, 62 "version" => \$version, 63 64 "usedfunctions=s" => \$usedFunctions, 65 "nonusedfunctions=s" => \$nonusedFunctions, 66 "complete=s" => \$complete, 67 "incomplete=s" => \$incomplete, 68 "cwsname=s" => \$cwsname, 69 "major=s" => \$major, 70 "minor=s" => \$minor, 71 "environment=s" => \$environment, 72 "outputdir=s" => \$outputDir 73 )) 74{ 75 print_usage(*STDERR); 76 exit(1); 77} 78 79# Check for help option 80if ($help) 81{ 82 print_usage(*STDOUT); 83 exit(0); 84} 85 86# Check for version option 87if ($version) 88{ 89 print("$version_info\n"); 90 exit(0); 91} 92 93# check if enough parameters 94# if ($#ARGV < 0) 95# { 96# print("No input filename specified\n"); 97# print_usage(*STDERR); 98# exit(1); 99# } 100 101# ------------------------------------------------------------------------------ 102 103my $sURL = "http://mahler.germany.sun.com/qadev/baselib/gcov_result_in_db_putter.php"; 104 105my $next = "?"; 106 107if ($complete) 108{ 109 my $result = `cat $complete | wc -l`; 110 chomp($result); 111 $result =~ / *(\d+)/; 112 $sURL = $sURL . "$next" . "complete=$1"; 113 $next = "&"; 114} 115 116if ($nonusedFunctions) 117{ 118 my $result = `cat $nonusedFunctions | wc -l`; 119 chomp($result); 120 $result =~ / *(\d+)/; 121 $sURL = $sURL . "$next" . "notused=$1"; 122 $next = "&"; 123} 124if ($usedFunctions) 125{ 126 my $result = `cat $usedFunctions | wc -l`; 127 chomp($result); 128 $result =~ / *(\d+)/; 129 $sURL = $sURL . "$next" . "used=$1"; 130 $next = "&"; 131} 132if ($incomplete) 133{ 134 my $result = `cat $incomplete | wc -l`; 135 chomp($result); 136 $result =~ / *(\d+)/; 137 $sURL = $sURL . "$next" . "incomplete=$1"; 138 $next = "&"; 139} 140 141if ($cwsname) 142{ 143 # qadev8 144 $sURL = $sURL . "$next" . "cwsname=$cwsname"; 145 $next = "&"; 146} 147if ($major) 148{ 149 # srx645 150 $sURL = $sURL . "$next" . "major=$major"; 151 $next = "&"; 152} 153if ($minor) 154{ 155 # m3s1 156 $sURL = $sURL . "$next" . "minor=$minor"; 157 $next = "&"; 158} 159 160if ($environment) 161{ 162 # unxlngi5 163 $sURL = $sURL . "$next" . "environment=$environment"; 164 $next = "&"; 165} 166 167my $year = localtime->year() + 1900; 168my $month = create2DigitNumber(localtime->mon() + 1); 169my $day = create2DigitNumber(localtime->mday()); 170$sURL = $sURL . "$next" . "date=$year-$month-$day"; 171$next = "&"; 172 173my $output; 174if ($outputDir) 175{ 176 chomp($outputDir); 177 $output = $outputDir; 178} 179 180# check if output ends with "/" 181if ( $output =~ /\/$/ ) 182{ 183 print "Output name ends with '/'\n"; 184} 185else 186{ 187 print "Output name does not end with '/'\n"; 188 $output = $output . "/"; 189} 190$output = $output . "php_result.txt"; 191 192my $result = `wget -O $output "$sURL"`; 193print "$sURL\n"; 194 195print `cat $output`; 196 197 198# ---------------------------------------------------------------------------- 199sub print_usage(*) 200{ 201 local *HANDLE = $_[0]; 202 my $tool_name = basename($0); 203 204 print(HANDLE <<END_OF_USAGE); 205 206Usage: $tool_name [OPTIONS] 207 208 -u, --usedfunctions count of all functions, which have a value > 0 209 -n, --nonusedfunctions count of all functions, which have a value == 0 210 -co, --complete count of all functions, which have a value == 100 211 -i, --incomplete count of all functions, which have a value > 0 && < 100 212 213 -cw, --cwsname set cwsname 214 -ma, --major set major number 215 -mi, --minor set minor number 216 -e, --environment set environment 217 218 -o, --outputdir set the directory, where to store the wget result 219 220 -h, --help Print this help, then exit 221 -v, --version Print version number, then exit 222 223END_OF_USAGE 224 ; 225} 226# ------------------------------------------------------------------------------ 227sub create2DigitNumber($) 228{ 229 my $digit = $_[0]; 230 my $str; 231 my $nDigitLen = length $digit; 232 233 if ($nDigitLen == 1) 234 { 235 $str = "0" . $digit; 236 } 237 else 238 { 239 if ($nDigitLen > 2) 240 { 241 $str = substr $digit, $nDigitLen - 2, 2; 242 } 243 else 244 { 245 $str = $digit; 246 } 247 } 248 return $str; 249} 250