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