bisect_ppx icon indicating copy to clipboard operation
bisect_ppx copied to clipboard

Does bisect_ppx work with dynamic libraries

Open wanghuibin0 opened this issue 1 year ago • 4 comments

I have some questions about using bisect_ppx and was hoping you could help!

It works fine for regular library modules, and I can generate coverage files without any problems. But when I try to use bisect_ppx with dynamic libraries (like .cmxs files) that are loaded into the main program using Dynlink, no coverage files get generated. Any idea why this happens? Does bisect_ppx not support dynamic libraries yet?

wanghuibin0 avatar Nov 23 '24 14:11 wanghuibin0

Is Bisect_ppx applied to the dynamic libraries when they are compiled (preprocessed, actually)?

I think Bisect should support dynamic libraries, as long as they are also compiled with Bisect enabled.

Do you have a small example of your setup?

aantron avatar Nov 24 '24 17:11 aantron

I compiled the dynamic library with the config "(instrumentation (backend bisect_ppx))" in plugin/dune file. Is this not enough? How can I inspect whether the compiled libraries are preprocessed by bisect_ppx?

I have made a tarball bisect_test.tar.gz of my minimized dune project that uses dynlink, for your convinience to see where I did wrong. Build :

dune build --instrument-with bisect_ppx

run:

cd _build/default
bin/main.exe plugin/plugin.cmxs

wanghuibin0 avatar Nov 25 '24 06:11 wanghuibin0

Thank you! I downloaded the project and ran it with these commands:

rm -rf *.coverage
dune build --root . --instrument-with bisect_ppx
_build/default/bin/main.exe _build/default/plugin/plugin.cmxs
bisect-ppx-report html

This produced *.coverage files and a report in ./_coverage/index.html that looks like this:

image

image

The output was

rm -rf *.coverage
dune build --root . --instrument-with bisect_ppx
_build/default/bin/main.exe _build/default/plugin/plugin.cmxs
Plugin loaded successfully!
Hello from the plugin!
bisect-ppx-report html

As far as I can tell, coverage analysis is working for both the main program and the loaded plugin. What happens when you run the same commands?

aantron avatar Nov 25 '24 09:11 aantron

Thank you! This time, I followed your instructions and succeeded—Bisect_ppx is working properly now. I must have made a mistake somewhere before, though I’m not exactly sure where—perhaps it was an issue with the working directory. Anyway, I’m really happy that I can now use Bisect_ppx to measure my project’s coverage. Thanks again!

wanghuibin0 avatar Nov 25 '24 13:11 wanghuibin0