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