bump product version to 5.0.4.1
[LibreOffice.git] / sal / qa / helper / gcov / gcov_resultinterpreter.pl
blob0509850a4e1265f1239965728c64d45e455517e5
1 #!/usr/bin/perl -w
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # This file incorporates work covered by the following license notice:
12 # Licensed to the Apache Software Foundation (ASF) under one or more
13 # contributor license agreements. See the NOTICE file distributed
14 # with this work for additional information regarding copyright
15 # ownership. The ASF licenses this file to you under the Apache
16 # License, Version 2.0 (the "License"); you may not use this file
17 # except in compliance with the License. You may obtain a copy of
18 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 # GCOV_RESULTINTERPRETER
23 # Helper, to interpret the result
25 # Q: Why perl?
26 # A: regexp ;-)
29 use strict;
30 use File::Basename;
31 use Getopt::Long;
33 our $version_info = 'gcov helper: 1.3 ';
35 our $help; # Help option flag
36 our $version; # Version option flag
37 # our $infile;
39 our $usedFunctions; # show all functions, which have a value > 0
40 our $nonusedFunctions; # show all functions, which have a value == 0
41 our $nPercent; # show all functions, which have a value > $nPercent
42 our $complete; # show all functions, which have a value == 100
43 our $incomplete; # show all functions, which have a value > 0 && < 100
45 # Prototypes
46 sub print_usage(*);
47 sub read_gcov_function_file($);
49 # Parse command line options
50 if (!GetOptions(
51 "usedfunctions" => \$usedFunctions,
52 "nonusedfunctions" => \$nonusedFunctions,
53 "percent=s" => \$nPercent,
54 "complete" => \$complete,
55 "incomplete" => \$incomplete,
56 "help" => \$help,
57 "version" => \$version
60 print_usage(*STDERR);
61 exit(1);
64 # Check for help option
65 if ($help)
67 print_usage(*STDOUT);
68 exit(0);
71 # Check for version option
72 if ($version)
74 print("$version_info\n");
75 exit(0);
78 # check if enough parameters
79 if ($#ARGV < 0)
81 print("No input filename specified\n");
82 print_usage(*STDERR);
83 exit(1);
86 if ($complete)
88 $nPercent = 100.00;
90 # ------------------------------------------------------------------------------
92 my %list = read_gcov_function_file($ARGV[0]);
94 my $key;
95 my $value;
97 while (($key, $value) = each %list)
99 # print "function: $key = $value\n";
100 if ($nonusedFunctions)
102 if ($value <= 0.00)
104 print "$key\n";
107 elsif ($usedFunctions)
109 if ($value != 0.00)
111 print "$key, $value\n";
114 elsif ($nPercent)
116 if ($value >= $nPercent)
118 print "$key, $value\n";
121 elsif ($incomplete)
123 if ($value > 0.00 && $value < 100.00)
125 print "$key, $value\n";
128 else
130 print "$key, $value\n";
134 # --------------------------------------------------------------------------------
135 # Read the gcov function (gcov -f) file
136 # and compare line by line with the export function list
137 # so we get a list of functions, which are only exported, and not all stuff.
139 sub read_gcov_function_file($)
141 local *INPUT_HANDLE;
142 my $file = $_[0];
143 my %list;
144 my $line = "";
146 open(INPUT_HANDLE, $file)
147 or die("ERROR: cannot open $file!\n");
149 while ($line = <INPUT_HANDLE>)
151 chomp($line);
152 # sample line (for reg exp:)
153 # 100.00 rtl_ustr_toDouble
154 if ($line =~ /^(.*) (\w+)$/ )
156 my $percent = $1;
157 my $value = $2;
159 $list{$value} = $percent;
162 close(INPUT_HANDLE);
163 return %list;
166 # ----------------------------------------------------------------------------
167 sub print_usage(*)
169 local *HANDLE = $_[0];
170 my $tool_name = basename($0);
172 print(HANDLE <<END_OF_USAGE);
174 Usage: $tool_name [OPTIONS] INPUTFILE
176 -u, --usedFunctions show all functions, which have a value > 0
177 -n, --nonusedFunctions show all functions, which have a value == 0
178 -p, --percent show all functions, which have a value > percent
179 -c, --complete show all functions, which have a value == 100
180 -i, --incomplete show all functions, which have a value > 0 && < 100
182 -h, --help Print this help, then exit
183 -v, --version Print version number, then exit
185 END_OF_USAGE