Getting coverage info for Rust code called from C

Librsvg uses RUSTFLAGS=-Zinstrument-coverage and grcov, and it works pretty well for a plain cargo test, which tests the library and its only binary rsvg-convert.

However, for the C API tests there is a small api.c test program, which links to librsvg and then gets run. I don't seem to be getting code coverage information for the Rust code that implements the C API. For that test program, main() comes from the C code, and it calls a bunch of Rust code from librsvg.so.

Does anyone know how to do this - get coverage for a Rust library called from a main C program?

This is librsvg's CI script for coverage, by the way. You can see that src/c_api/*.rs has basically no coverage information, even though pretty much all of that code gets called. (The coverage that is there for that directory comes from Rust tests.)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.