Catalli's threaded switch
[sliver-openvswitch.git] / lib / coverage-scan.pl
1 # Copyright (c) 2009 Nicira Networks.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
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";