summaryrefslogtreecommitdiff
path: root/sal/qa/helper/gcov/gcov_resultinterpreter.pl
blob: b01506b2063462f1ef4c21b305a834cb9b763437 (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
#!/usr/bin/perl -w
#
# $Id: gcov_resultinterpreter.pl,v 1.3 2005-11-02 17:24:12 kz Exp $
#

# GCOV_RESULTINTERPRETER
#
# Helper, to interpret the result
#
# Q: Why perl?
# A: regexp ;-)
#

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

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

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

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

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

# Parse command line options
if (!GetOptions(
                "usedfunctions" => \$usedFunctions,
                "nonusedfunctions" => \$nonusedFunctions,
                "percent=s" => \$nPercent,
                "complete" => \$complete,
                "incomplete" => \$incomplete,
                "help"   => \$help,
                "version" => \$version
                ))
{
    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);
}

if ($complete)
{
    $nPercent = 100.00;
}
# ------------------------------------------------------------------------------

my %list = read_gcov_function_file($ARGV[0]);

my $key;
my $value;

while (($key, $value) = each %list)
{
    # print "function: $key = $value\n";
    if ($nonusedFunctions)
    {
        if ($value <= 0.00)
        {
            print "$key\n";
        }
    }
    elsif ($usedFunctions)
    {
        if ($value != 0.00)
        {
            print "$key, $value\n";
        }
    }
    elsif ($nPercent)
    {
        if ($value >= $nPercent)
        {
            print "$key, $value\n";
        }
    }
    elsif ($incomplete)
    {
        if ($value > 0.00 && $value < 100.00)
        {
            print "$key, $value\n";
        }
    }
    else
    {
        print "$key, $value\n";
    }
}

# --------------------------------------------------------------------------------
# Read the gcov function (gcov -f) file
# and compare line by line with the export function list
# so we get a list of functions, which are only exported, and not all stuff.

sub read_gcov_function_file($)
{
    local *INPUT_HANDLE;
    my $file = $_[0];
    my %list;
    my $line = "";

    open(INPUT_HANDLE, $file)
        or die("ERROR: cannot open $file!\n");

    while ($line = <INPUT_HANDLE>)
    {
        chomp($line);
        # sample line (for reg exp:)
        # 100.00 rtl_ustr_toDouble
        if ($line =~ /^(.*) (\w+)$/ )
        {
            my $percent = $1;
            my $value = $2;

            $list{$value} = $percent;
        }
    }
    close(INPUT_HANDLE);
    return %list;
}

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

    print(HANDLE <<END_OF_USAGE);

Usage: $tool_name [OPTIONS] INPUTFILE

    -u, --usedFunctions     show all functions, which have a value > 0
    -n, --nonusedFunctions  show all functions, which have a value == 0
    -p, --percent           show all functions, which have a value > percent
    -c, --complete          show all functions, which have a value == 100
    -i, --incomplete        show all functions, which have a value > 0 && < 100

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

END_OF_USAGE
    ;
}