xref: /trunk/main/sal/qa/helper/gcov/gcov_resultcompare.pl (revision 0a27d2e79413e4d5d7189d275120fd9249a93402)
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# GCOV_RESULTCOMPARE
24#
25# Helper, to compare two different results
26#
27# Q: Why perl?
28# A: regexp ;-)
29#
30
31use strict;
32use File::Basename;
33use Getopt::Long;
34
35our $version_info = 'gcov_resultcompare $Revision: 1.2 $ ';
36
37our $help;                    # Help option flag
38our $version;                 # Version option flag
39# our $infile;
40
41our $orig;
42our $compare;
43
44# Prototypes
45sub print_usage(*);
46sub read_gcov_function_file($);
47
48# Parse command line options
49if (!GetOptions(
50                "o=s" => \$orig,
51                "c=s" => \$compare,
52                 "help" => \$help,
53                 "version" => \$version
54                 ))
55{
56    print_usage(*STDERR);
57    exit(1);
58}
59
60# Check for help option
61if ($help)
62{
63    print_usage(*STDOUT);
64    exit(0);
65}
66
67# Check for version option
68if ($version)
69{
70    print("$version_info\n");
71    exit(0);
72}
73
74# check if enough parameters
75# if ($#ARGV < 1)
76# {
77#     print("No input filenames specified\n");
78#     print_usage(*STDERR);
79#     exit(1);
80# }
81
82if (! $orig)
83{
84    print_usage(*STDOUT);
85    exit(0);
86}
87if (! $compare)
88{
89    print_usage(*STDOUT);
90    exit(0);
91}
92
93# ------------------------------------------------------------------------------
94
95my %origlist = read_gcov_function_file($orig);
96my %cmplist = read_gcov_function_file($compare);
97
98my $key;
99my $value;
100
101while (($key, $value) = each %origlist)
102{
103    my $cmpvalue = $cmplist{$key};
104
105    if ($cmpvalue != 0.00)
106    {
107        if ($value < 100.00)
108        {
109            if ($cmpvalue > $value && $value < 90.0)
110            {
111                print "$key, $value,   CMP:$cmpvalue\n";
112            }
113        }
114    }
115}
116
117# --------------------------------------------------------------------------------
118# Read the gcov function (gcov -f) file
119# and compare line by line with the export function list
120# so we get a list of functions, which are only exported, and not all stuff.
121
122sub read_gcov_function_file($)
123{
124    local *INPUT_HANDLE;
125    my $file = shift;
126    my %list;
127    my $line = "";
128
129    open(INPUT_HANDLE, $file)
130        or die("ERROR: cannot open $file!\n");
131
132    while ($line = <INPUT_HANDLE>)
133    {
134        chomp($line);
135        # sample line (for reg exp:)
136        # 100.00 rtl_ustr_toDouble
137        if ($line =~ /^(.{6}) (\w+)$/ )
138        {
139            my $percent = $1;
140            my $value = $2;
141
142            $list{$value} = $percent;
143        }
144    }
145    close(INPUT_HANDLE);
146    return %list;
147}
148
149# ----------------------------------------------------------------------------
150sub print_usage(*)
151{
152    local *HANDLE = $_[0];
153    my $tool_name = basename($0);
154
155    print(HANDLE <<END_OF_USAGE);
156
157Usage: $tool_name [OPTIONS] INPUTFILE
158
159    -o                      Original File, which gives the main values
160                            if here a value is smaller than in compare, the found value is a candidate for better check.
161    -c                      Compare file.
162
163    -h, --help              Print this help, then exit
164    -v, --version           Print version number, then exit
165
166END_OF_USAGE
167    ;
168}
169