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