886223c70aa9233a194487ce52c77335eb618bc9
[cascardo/ovs.git] / lib / coverage-scan.pl
1 # Copyright (c) 2009 Nicira Networks.
2 #
3 # Permission to use, copy, modify, and/or distribute this software for any
4 # purpose with or without fee is hereby granted, provided that the above
5 # copyright notice and this permission notice appear in all copies.
6 #
7 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15 use strict;
16 use warnings;
17
18 my %counters;
19 while (<>) {
20     my ($counter) = /^\s*COVERAGE_(?:INC|ADD)\s*\(\s*([a-zA-Z_][a-zA-Z_0-9]*)/
21       or next;
22     push (@{$counters{$counter}}, "$ARGV:$.");
23 } continue {
24     # This magic resets $. from one file to the next.  See "perldoc -f eof".
25     close ARGV if eof;
26 }
27
28 print <<EOF;
29 #include "coverage-counters.h"
30 #include <stddef.h>
31 #include "coverage.h"
32 #include "util.h"
33
34 EOF
35
36 for my $counter (sort(keys(%counters))) {
37     my $locations = join(', ', @{$counters{$counter}});
38     print <<EOF;
39 /* $locations */
40 struct coverage_counter ${counter}_count = { "$counter", 0, 0 };
41
42 EOF
43 }
44 print "struct coverage_counter *coverage_counters[] = {\n";
45 print "    \&${_}_count,\n" foreach (sort(keys(%counters)));
46 print "};\n";
47 print "size_t coverage_n_counters = ARRAY_SIZE(coverage_counters);\n";