summaryrefslogtreecommitdiff
path: root/sal/qa/helper/gcov/gcov_result.pl
blob: 414eac2c828b8d64c7f8e7a6d62cf26bfe7b2bcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/perl -w
#
# $Id: gcov_result.pl,v 1.2 2003-06-11 16:36:30 vg Exp $
#

# GCOV_RESULT
#
# Helper, to interpret the result and put the result via html in a database.
# Put into DB works via php.
#
# Q: Why perl?
# A: regexp ;-)
#

use strict;
use File::Basename;
use Getopt::Long;
use Time::localtime;

our $version_info = 'gcov helper $Revision: 1.2 $ ';

our $help;                    # Help option flag
our $version;                 # Version option flag
# our $infile;

our $usedFunctions;     # name of all functions filename, which have a value > 0
our $nonusedFunctions;  # name of all functions filename, which have a value == 0
our $complete;          # name of all functions filename, which have a value == 100
our $incomplete;       # name of all functions filename, which have a value > 0 && < 100

our $environment;
our $major;
our $minor;
our $cwsname;
our $outputDir;

# Prototypes
sub print_usage(*);
sub read_gcov_function_file($);
sub create2DigitNumber($);

# Parse command line options
if (!GetOptions(
                 "help"    => \$help,
                 "version" => \$version,

                 "usedfunctions=s"    => \$usedFunctions,
                 "nonusedfunctions=s" => \$nonusedFunctions,
                 "complete=s"         => \$complete,
                 "incomplete=s"       => \$incomplete,
                 "cwsname=s"          => \$cwsname,
                 "major=s"            => \$major,
                 "minor=s"            => \$minor,
                 "environment=s"      => \$environment,
                 "outputdir=s"        => \$outputDir
                 ))
{
    print_usage(*STDERR);
    exit(1);
}

# Check for help option
if ($help)
{
    print_usage(*STDOUT);
    exit(0);
}

# Check for version option
if ($version)
{
    print("$version_info\n");
    exit(0);
}

# check if enough parameters
# if ($#ARGV < 0)
# {
#     print("No input filename specified\n");
#     print_usage(*STDERR);
#     exit(1);
# }

# ------------------------------------------------------------------------------

my $sURL = "http://mahler.germany.sun.com/qadev/baselib/gcov_result_in_db_putter.php";

my $next = "?";

if ($complete)
{
    my $result = `cat $complete | wc -l`;
    chomp($result);
    $result =~ / *(\d+)/;
    $sURL = $sURL . "$next" . "complete=$1";
    $next = "&";
}

if ($nonusedFunctions)
{
    my $result = `cat $nonusedFunctions | wc -l`;
    chomp($result);
    $result =~ / *(\d+)/;
    $sURL = $sURL . "$next" . "notused=$1";
    $next = "&";
}
if ($usedFunctions)
{
    my $result = `cat $usedFunctions | wc -l`;
    chomp($result);
    $result =~ / *(\d+)/;
    $sURL = $sURL . "$next" . "used=$1";
    $next = "&";
}
if ($incomplete)
{
    my $result = `cat $incomplete | wc -l`;
    chomp($result);
    $result =~ / *(\d+)/;
    $sURL = $sURL . "$next" . "incomplete=$1";
    $next = "&";
}

if ($cwsname)
{
    # qadev8
    $sURL = $sURL . "$next" . "cwsname=$cwsname";
    $next = "&";
}
if ($major)
{
    # srx645
    $sURL = $sURL . "$next" . "major=$major";
    $next = "&";
}
if ($minor)
{
    # m3s1
    $sURL = $sURL . "$next" . "minor=$minor";
    $next = "&";
}

if ($environment)
{
    # unxlngi5
    $sURL = $sURL . "$next" . "environment=$environment";
    $next = "&";
}

my $year  = localtime->year() + 1900;
my $month = create2DigitNumber(localtime->mon() + 1);
my $day   = create2DigitNumber(localtime->mday());
$sURL = $sURL . "$next" . "date=$year-$month-$day";
$next = "&";

my $output;
if ($outputDir)
{
    chomp($outputDir);
    $output = $outputDir;
}

# check if output ends with "/"
if ( $output =~ /\/$/ )
{
    print "Output name ends with '/'\n";
}
else
{
    print "Output name does not end with '/'\n";
    $output = $output . "/";
}
$output = $output . "php_result.txt";

my $result = `wget -O $output "$sURL"`;
print "$sURL\n";

print `cat $output`;


# ----------------------------------------------------------------------------
sub print_usage(*)
{
    local *HANDLE = $_[0];
    my $tool_name = basename($0);

    print(HANDLE <<END_OF_USAGE);

Usage: $tool_name [OPTIONS]

    -u,  --usedfunctions     count of all functions, which have a value > 0
    -n,  --nonusedfunctions  count of all functions, which have a value == 0
    -co, --complete          count of all functions, which have a value == 100
    -i,  --incomplete        count of all functions, which have a value > 0 && < 100

    -cw, --cwsname           set cwsname
    -ma, --major             set major number
    -mi, --minor             set minor number
    -e,  --environment       set environment

    -o,  --outputdir         set the directory, where to store the wget result

    -h, --help               Print this help, then exit
    -v, --version            Print version number, then exit

END_OF_USAGE
    ;
}
# ------------------------------------------------------------------------------
sub create2DigitNumber($)
{
    my $digit = $_[0];
    my $str;
    my $nDigitLen = length $digit;

    if ($nDigitLen == 1)
    {
        $str = "0" . $digit;
    }
    else
    {
        if ($nDigitLen > 2)
        {
            $str = substr $digit, $nDigitLen - 2, 2;
        }
        else
        {
            $str = $digit;
        }
    }
    return $str;
}