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