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