2017-09-18 12:35:50 +00:00
|
|
|
#!/usr/bin/env perl
|
2017-04-07 14:07:49 +00:00
|
|
|
|
|
|
|
my %noninlined;
|
|
|
|
my %mocked;
|
|
|
|
|
|
|
|
# Functions in public header don't get the noinline annotation
|
|
|
|
# so whitelist them here
|
|
|
|
$noninlined{"virEventAddTimeout"} = 1;
|
|
|
|
|
|
|
|
foreach my $arg (@ARGV) {
|
|
|
|
if ($arg =~ /\.h$/) {
|
|
|
|
#print "Scan header $arg\n";
|
|
|
|
&scan_annotations($arg);
|
|
|
|
} elsif ($arg =~ /mock\.c$/) {
|
|
|
|
#print "Scan mock $arg\n";
|
|
|
|
&scan_overrides($arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $warned = 0;
|
|
|
|
foreach my $func (keys %mocked) {
|
|
|
|
next if exists $noninlined{$func};
|
|
|
|
|
|
|
|
$warned++;
|
|
|
|
print STDERR "$func is mocked at $mocked{$func} but missing noinline annotation\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
exit $warned ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
|
|
sub scan_annotations {
|
|
|
|
my $file = shift;
|
|
|
|
|
|
|
|
open FH, $file or die "cannot read $file: $!";
|
|
|
|
|
|
|
|
my $func;
|
|
|
|
while (<FH>) {
|
|
|
|
if (/^\s*(\w+)\(/ || /^(?:\w+\*?\s+)+(?:\*\s*)?(\w+)\(/) {
|
|
|
|
my $name = $1;
|
|
|
|
if ($name !~ /ATTRIBUTE/) {
|
|
|
|
$func = $name;
|
|
|
|
}
|
|
|
|
} elsif (/^\s*$/) {
|
|
|
|
$func = undef;
|
|
|
|
}
|
2017-07-12 10:07:17 +00:00
|
|
|
if (/ATTRIBUTE_NOINLINE/) {
|
2017-04-07 14:07:49 +00:00
|
|
|
if (defined $func) {
|
|
|
|
$noninlined{$func} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close FH
|
|
|
|
}
|
|
|
|
|
|
|
|
sub scan_overrides {
|
|
|
|
my $file = shift;
|
|
|
|
|
|
|
|
open FH, $file or die "cannot read $file: $!";
|
|
|
|
|
|
|
|
my $func;
|
|
|
|
while (<FH>) {
|
|
|
|
if (/^(\w+)\(/ || /^\w+\s*(?:\*\s*)?(\w+)\(/) {
|
|
|
|
my $name = $1;
|
|
|
|
if ($name =~ /^vir/) {
|
|
|
|
$mocked{$name} = "$file:$.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close FH
|
|
|
|
}
|