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