I am trying to extract coverage information for a project. Without going into too many details, I am trying to use the coverage information to provide feedback to a grey-box fuzzer (AFL).
My application (OOAnalyzer) uses incremental tabling quite heavily, and the results from using show_coverage/1
have been strange. I am not sure if I’m doing something wrong with my hook, or if show_coverage/1
does not support tabled code.
Here is a small program that demonstrates the problem:
% This seems to be needed to force prolog_cover to load.
:- show_coverage(true).
my_file_coverage(Succeeded, Failed, Options) :-
forall(member(Cl, Succeeded),
(prolog_cover:clause_source(Cl, File, Line),
prolog_cover:clause_pi(Cl, Name),
format('~w ~w ~w~n', [Name, File, Line]))).
prolog_cover:report_hook(Succ, Fail) :- my_file_coverage(Succ, Fail, []).
:- table iamtabled/1 as incremental.
iamtabled(X) :- what(X).
iamnottabled(X) :- what(X).
what(X) :- X = 4.
test :-
% This will display the default "Coverage by File" table...
show_coverage(iamtabled(X)),
writeln('The first call has ended.'),
% This will not
show_coverage(iamnottabled(X)).
To see the problem, query test
. Here I will print out the results separately so it is easier to see.
First, the expected behavior:
?- show_coverage(iamnottabled(X)).
user:what/1 /tmp/test.pl 17
user:iamnottabled/1 /tmp/test.pl 15
system:once/1 /home/ed/Documents/swipl-devel/build/home/boot/init.pl 537
X = 4.
My hook is used as desired.
Next, the unexpected behavior:
?- show_coverage(iamtabled(X)).
$tabling:reset_delays/0 /home/ed/Documents/swipl-devel/build/home/boot/tabling.pl 926
system:call/1 /home/ed/Documents/swipl-devel/build/home/boot/init.pl 501
==============================================================================
Coverage by File
==============================================================================
File Clauses %Cov %Fail
==============================================================================
/tmp/test.pl 8 25.0 0.0
...uments/swipl-devel/build/home/library/test_cover.pl 65 1.5 1.5
==============================================================================
X = 4.
My hook is used a bit, but then the non-hooked summary is printed?
What is going on?!