bump product version to 5.0.4.1
[LibreOffice.git] / sal / qa / helper / gcov / gcov_result.pl
blob783d055ffba78cfe2562cb8d8b92fb267e95b6a2
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_RESULT
23 # Helper, to interpret the result and put the result via html in a database.
24 # Put into DB works via php.
26 # Q: Why perl?
27 # A: regexp ;-)
30 use strict;
31 use File::Basename;
32 use Getopt::Long;
33 use Time::localtime;
35 our $version_info = 'gcov helper: 1.2 ';
37 our $help; # Help option flag
38 our $version; # Version option flag
39 # our $infile;
41 our $usedFunctions; # name of all functions filename, which have a value > 0
42 our $nonusedFunctions; # name of all functions filename, which have a value == 0
43 our $complete; # name of all functions filename, which have a value == 100
44 our $incomplete; # name of all functions filename, which have a value > 0 && < 100
46 our $environment;
47 our $major;
48 our $minor;
49 our $cwsname;
50 our $outputDir;
52 # Prototypes
53 sub print_usage(*);
54 sub read_gcov_function_file($);
55 sub create2DigitNumber($);
57 # Parse command line options
58 if (!GetOptions(
59 "help" => \$help,
60 "version" => \$version,
62 "usedfunctions=s" => \$usedFunctions,
63 "nonusedfunctions=s" => \$nonusedFunctions,
64 "complete=s" => \$complete,
65 "incomplete=s" => \$incomplete,
66 "cwsname=s" => \$cwsname,
67 "major=s" => \$major,
68 "minor=s" => \$minor,
69 "environment=s" => \$environment,
70 "outputdir=s" => \$outputDir
73 print_usage(*STDERR);
74 exit(1);
77 # Check for help option
78 if ($help)
80 print_usage(*STDOUT);
81 exit(0);
84 # Check for version option
85 if ($version)
87 print("$version_info\n");
88 exit(0);
91 # check if enough parameters
92 # if ($#ARGV < 0)
93 # {
94 # print("No input filename specified\n");
95 # print_usage(*STDERR);
96 # exit(1);
97 # }
99 # ------------------------------------------------------------------------------
101 my $sURL = "http://mahler.germany.sun.com/qadev/baselib/gcov_result_in_db_putter.php";
103 my $next = "?";
105 if ($complete)
107 my $result = `cat $complete | wc -l`;
108 chomp($result);
109 $result =~ / *(\d+)/;
110 $sURL = $sURL . "$next" . "complete=$1";
111 $next = "&";
114 if ($nonusedFunctions)
116 my $result = `cat $nonusedFunctions | wc -l`;
117 chomp($result);
118 $result =~ / *(\d+)/;
119 $sURL = $sURL . "$next" . "notused=$1";
120 $next = "&";
122 if ($usedFunctions)
124 my $result = `cat $usedFunctions | wc -l`;
125 chomp($result);
126 $result =~ / *(\d+)/;
127 $sURL = $sURL . "$next" . "used=$1";
128 $next = "&";
130 if ($incomplete)
132 my $result = `cat $incomplete | wc -l`;
133 chomp($result);
134 $result =~ / *(\d+)/;
135 $sURL = $sURL . "$next" . "incomplete=$1";
136 $next = "&";
139 if ($cwsname)
141 # qadev8
142 $sURL = $sURL . "$next" . "cwsname=$cwsname";
143 $next = "&";
145 if ($major)
147 # srx645
148 $sURL = $sURL . "$next" . "major=$major";
149 $next = "&";
151 if ($minor)
153 # m3s1
154 $sURL = $sURL . "$next" . "minor=$minor";
155 $next = "&";
158 if ($environment)
160 # unxlngi5
161 $sURL = $sURL . "$next" . "environment=$environment";
162 $next = "&";
165 my $year = localtime->year() + 1900;
166 my $month = create2DigitNumber(localtime->mon() + 1);
167 my $day = create2DigitNumber(localtime->mday());
168 $sURL = $sURL . "$next" . "date=$year-$month-$day";
169 $next = "&";
171 my $output;
172 if ($outputDir)
174 chomp($outputDir);
175 $output = $outputDir;
178 # check if output ends with "/"
179 if ( $output =~ /\/$/ )
181 print "Output name ends with '/'\n";
183 else
185 print "Output name does not end with '/'\n";
186 $output = $output . "/";
188 $output = $output . "php_result.txt";
190 my $result = `wget -O $output "$sURL"`;
191 print "$sURL\n";
193 print `cat $output`;
196 # ----------------------------------------------------------------------------
197 sub print_usage(*)
199 local *HANDLE = $_[0];
200 my $tool_name = basename($0);
202 print(HANDLE <<END_OF_USAGE);
204 Usage: $tool_name [OPTIONS]
206 -u, --usedfunctions count of all functions, which have a value > 0
207 -n, --nonusedfunctions count of all functions, which have a value == 0
208 -co, --complete count of all functions, which have a value == 100
209 -i, --incomplete count of all functions, which have a value > 0 && < 100
211 -cw, --cwsname set cwsname
212 -ma, --major set major number
213 -mi, --minor set minor number
214 -e, --environment set environment
216 -o, --outputdir set the directory, where to store the wget result
218 -h, --help Print this help, then exit
219 -v, --version Print version number, then exit
221 END_OF_USAGE
224 # ------------------------------------------------------------------------------
225 sub create2DigitNumber($)
227 my $digit = $_[0];
228 my $str;
229 my $nDigitLen = length $digit;
231 if ($nDigitLen == 1)
233 $str = "0" . $digit;
235 else
237 if ($nDigitLen > 2)
239 $str = substr $digit, $nDigitLen - 2, 2;
241 else
243 $str = $digit;
246 return $str;