1 # Copyright 2012, INRIA
2 # Julia Lawall, Gilles Muller
3 # Copyright 2010-2011, INRIA, University of Copenhagen
4 # Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
5 # Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
6 # Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
7 # This file is part of Coccinelle.
9 # Coccinelle is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, according to version 2 of the License.
13 # Coccinelle is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
21 # The authors reserve the right to distribute this or future versions of
22 # Coccinelle under other licenses.
31 #use Date::Manip qw(ParseDate UnixDate); #sudo apt-get install libdate-manip-perl
32 #use Date::Calc qw(Delta_Days); #sudo apt-get install libdate-calc-perl
34 #------------------------------------------------------------------------------
36 #------------------------------------------------------------------------------
40 sub pr2
{ print STDERR
"@_\n"; }
41 sub pr
{ print "@_\n"; }
42 sub mylog
{ print STDERR
"@_\n" if $debug; }
49 #------------------------------------------------------------------------------
51 #------------------------------------------------------------------------------
54 my $so = 0; #spatch ok
68 my $sumlineP = 0; #whole git
70 my $sumlinePchange = 0;
79 my $duration = 0; # in days
83 #------------------------------------------------------------------------------
85 #------------------------------------------------------------------------------
86 $spfile = `make sp_file`;
89 if($spfile =~ /(rule|mega|bt)(\d+)\.cocci/) { $ruleno = "$2"; }
91 #------------------------------------------------------------------------------
93 #------------------------------------------------------------------------------
95 #$cedescr = `make ce_descr`;
97 #print STDERR (Dumper($cedescr));
98 open TMP
, "Makefile" or die "no Makefile file ?";
100 if(/^(CE)?DESCRIPTION=["'](.*)["']/) { $cedescr = $2; }
105 #$cedescr =~ s/\\/\\\\/g;
106 #$cedescr =~ s/\f/\\f/g;
107 #$cedescr =~ s/\t/\\t/g;
109 #------------------------------------------------------------------------------
111 #------------------------------------------------------------------------------
112 my $files = `make source_files`;
114 @cfiles = split /\s+/, $files;
116 $nbfiles = scalar(@cfiles);
118 #------------------------------------------------------------------------------
120 #------------------------------------------------------------------------------
122 my ($linefile) = `wc -l $_`;
124 die "wierd wc output" unless $linefile =~ /^(\d+) /;
126 mylog
"filesize $_ $1";
130 #------------------------------------------------------------------------------
132 #------------------------------------------------------------------------------
134 `cat $spfile | perl -p -e "s/\\/\\/.*//g;" | grep -v '^[ \t]*\$' | wc -l`;
138 #------------------------------------------------------------------------------
140 #------------------------------------------------------------------------------
141 if(!(-e
"README")) { pr2
"no README file ?"; }
143 open TMP
, "README" or die "no README file ?";
145 if (/\[bug\]/ || /status\]\s*bug/ || /status\]\s*BUG/ ) {
147 # can also look for [semibug] but it's often related to [corrected_c] kind of pbs
148 #|| /status\]\s*semi-bug/
150 #pr2 "OLD BUG FORMAT: $_";
158 #------------------------------------------------------------------------------
160 #------------------------------------------------------------------------------
163 ($sumlineP) = `cat gitinfo |wc -l`;
169 #------------------------------------------------------------------------------
170 # Number of authors and duration
171 #------------------------------------------------------------------------------
176 open TMP
, "gitinfo" or die "no gitinfo file ?";
187 #can also do: egrep "^Author" gitinfo | sort | uniq | wc -l
188 if (/^Author: (.*)/) {
192 # if(/^Date: (.*) ([-+]\d+)?/) {
193 # my $date = ParseDate($1);
194 # if (!$date) { die "bad date" }
196 # my ($year, $month, $day) = UnixDate($date, "%Y", "%m", "%d");
197 # my @current = ($year, $month, $day);
199 # @mindate = @current;
200 # @maxdate = @current;
203 # my $diff1 = Delta_Days(@mindate, @current);
204 # if($diff1 < 0) { @mindate = @current; }
205 # my $diff2 = Delta_Days(@current, @maxdate);
206 # if($diff2 < 0) { @maxdate = @current; }
208 # #pr2 "$diff1, $diff2";
217 # my $diff = Delta_Days(@mindate, @maxdate);
218 # if($diff == 1 || $diff == 0) {
219 # $duration = "1 day";
221 # elsif($diff < 31) {
222 # $duration = "$diff days";
224 # elsif($diff > 365) {
225 # my $years = int($diff / 365);
226 # my $s = plural($years);
227 # $duration = "$years year$s";
229 # elsif($diff > 31) {
230 # my $months = int($diff / 31);
231 # my $s = plural($months);
232 # $duration = "$months month$s";
234 # else { die "impossible"; }
236 $duration = "xxx months";
238 $numauthors = scalar(keys %{$h});
244 #------------------------------------------------------------------------------
245 # Size P (only change for .c in drivers/ or sounds/ (the test files))
246 #------------------------------------------------------------------------------
249 foreach my $c (@cfiles) {
250 die "wierd: $c, with $spfile" unless ($c =~ /(.*)\.c$/);
253 my $aft = "$base.res";
254 if(-e
"corrected_$base.res") {
255 $aft = "corrected_$base.res";
256 mylog
"found corrected";
259 open TMP
, "diff -u -b -B $bef $aft |";
265 if (/^\+[^+]/) { $onlychange++; }
266 if (/^\-[^-]/) { $onlychange++; }
268 $sumlinePchange += $onlychange;
269 $sumlineP2 += $count;
272 #------------------------------------------------------------------------------
274 #------------------------------------------------------------------------------
275 foreach my $c (@cfiles) {
276 die "" unless ($c =~ /(.*)\.c$/);
279 my $diagnosefile = "";
282 if(-e
"$base.c.ok") { $ok++; $diagnosefile = "$base.c.ok"; }
283 if(-e
"$base.c.failed") { $fa++; $diagnosefile = "$base.c.failed"; }
284 if(-e
"$base.c.spatch_ok") { $so++; $diagnosefile = "$base.c.spatch_ok"; }
285 if(-e
"$base.c.gave_up") { $gu++; $diagnosefile = "$base.c.gave_up"; }
287 open TMP
, $diagnosefile or die "no diagnose $base: $diagnosefile";
291 # before -test_okfailed
292 # if (/real[ \t]+([0-9])+m([0-9]+)[.]([0-9]+)/) {
295 # $time = $1 * 60.0; # minutes
296 # $time += $2; # seconds
297 # $time += $3 / 1000.0; # 1/1000th sec.
299 # pr2 (sprintf "%4.1fs\n", $time);
300 # printf "I: %15s & %4.1fs\n", $c, $time;
308 mylog
(sprintf "%4.1fs\n", $time);
309 printf "I: %15s & %4.1fs\n", $c, $time;
315 die "not found time information in $diagnosefile" unless $found == 1;
318 $maxtime = $time if $time > $maxtime;
322 #------------------------------------------------------------------------------
324 #------------------------------------------------------------------------------
326 my $correct = $ok + $so;
328 my $pourcentcorrect = ($correct * 100.0) / $nbfiles;
329 my $avglines = $sumlinefiles / $nbfiles;
330 my $avgtime = $sumtime / $nbfiles;
333 my $ratioPvsSP = $sumlineP / $sizeSP;
334 my $ratioPvsSP2 = $sumlineP2 / $sizeSP;
337 #------------------------------------------------------------------------------
339 #------------------------------------------------------------------------------
344 map { mylog
"\t$_"; } @cfiles;
345 pr
"----------------------------------------";
348 pr
"!!Total files = $nbfiles";
349 printf "!!AvgLine = %.1fl\n", $avglines;
351 #pr " Correct number = $correct";
352 printf "!!Correct = %.1f%s\n", $pourcentcorrect, "%";
354 pr
"!!Human errors = $errors";
356 pr
"!!Size SP = $sizeSP";
357 pr
"!!Size P = $sumlineP";
358 pr
"!!Size P (change only) = $sumlinePchange";
360 printf "!!Ratio P/SP = %3.1f\n", $ratioPvsSP;
363 printf "!!RunTime = %.1fs\n", $sumtime;
364 printf "!!MaxTime = %.1fs\n", $maxtime;
365 printf "!!AvgTime = %.1fs\n", $avgtime;
367 my $totalstatus = $ok + $fa + $so + $gu;
368 mylog
"----------------------------------------------------------------";
369 mylog
"Sanity checks: nb files vs total status: $nbfiles =? $totalstatus";
373 printf "L: %20s (r%3s) & %5.1f%% & %5dfi & %2de & %6.1fx & %6.1fs \n",
374 $cedescr, $ruleno, $pourcentcorrect, $nbfiles, $errors, $ratioPvsSP, $sumtime;
377 # Mega, Complex, Bluetooth
379 printf "M: %60s & %5d & %6d (%d) & %2d & %s & %2d & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n",
380 $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $numauthors, $duration, $errors, $sizeSP, $ratioPvsSP,
381 $avgtime, $maxtime, $pourcentcorrect, $spfile;
383 printf "C: %60s & %5d & %6d (%d) & %2d & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n",
384 $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $errors, $sizeSP, $ratioPvsSP,
385 $avgtime, $maxtime, $pourcentcorrect, $spfile;
387 printf "B: %60s & %5d & %5d (%d) & %3d & %6.0fx & %6.1fs (%.1fs) & %5.0f\\%% \\\\\\hline%% SP: %s \n",
388 $cedescr, $nbfiles, $sumlineP, $sumlinePchange, $sizeSP, $ratioPvsSP,
389 $avgtime, $maxtime, $pourcentcorrect, $spfile;