solana-program-test new features necessary for code coverage functionality#7569
solana-program-test new features necessary for code coverage functionality#7569procdump wants to merge 2 commits into
Conversation
1b90ede to
d52d74c
Compare
Make ProgramTest payer configurable Modify get_invoke_context to be public Add a new method to ProgramTestContext for registering a recent blockhash
d52d74c to
42e2e30
Compare
|
@Lichtso when you get a chance, can you take a look |
|
We are not really maintaining |
|
The problem is that you can't get Rust code coverage from compiled SBPF programs, but you can very well get statistics from program-test and that's why we've adopted it. I hope you reconsider dropping program-test as it would be of no benefit to the Solana community. This is part of a TypeScript Code Coverage solution directly in Anchor & LiteSVM. You can check what the end result looks like here. Tagging @Aursen from LiteSVM for his perspective. |
Interesting use-case, yes we currently have no direct tooling for that, but it should be possible to develop. One needs the source to instruction mapping in the form of debug info emitted by the compiler and the instruction trace recorded by the VM. Putting those together should allow you to measure code coverage. Edit: Seems to already be done this way: https://github.com/trailofbits/anchor-coverage Can you join us on Discord in the virtual-machine channel to brainstorm this?
It is not that it takes to much effort to maintain, but that the approach of program-test is fundamentally incompatible with the direction we are headed in, e.g. account data direct mapping (SIMD-0219) Thus v3.0 will probably be the last release which supports it. |
The suggested approach seems to produce inaccurate and incomplete results. This is using the instruction mapping approach as you've explained above citing the github link: This is from our approach:
I'm on Discord with username
As a matter of fact, program-test is also very useful for step debugging of programs. Now that they're compiled into SBPF step-debugging isn't nice. |
|
I think the underlying issue is that it currently only resolves at line level, not at basic blocks / conditional branches. That way it misses the
The |
The program-test crate is provided by Solana to the community and we've just taken advantage of it having for granted that you've backed some level of parity. There are lots of tutorials on this topic. While fundamentally incorrect testing on the host architecture has its benefits - for example the native Rust debugging features where step-debugging on Rust source lines (not bytecode) work out of the box. This is an invaluable weapon for catching and investigating a family of issues. At any rate, in its core as a mocking testing facility nobody expects from program-test to be perfect after all.
Do you have a roadmap for that? When is it expected to land so that the Solana community can take advantage of it? To day this approach isn't usable and as it seems with each version of Solana the emitted DWARF gets changes and hence causes the addr2line crate to fail eventually. Till this is meticulously settled can we have some sort of consensus? The program-test crate is just a testing facility and I doubt these few changes will have any negative impact at all. Then when you announce you're shutting it down we'll have to adapt and we hope you will have backed a good working substitution in advance. |
Dwarf information must be valid for every compiler release, and we are not changing it. If it is breaking the tool, then there is a bug. There was a relocation problem in dwarf generation that was fixed in platform tools v1.51. |
|
Unfortunately, I couldn't get you permissions for Discord, but I started this discussion thread here instead as there are even more people interested in code coverage. |


Problem
sol_get_processed_sibling_instructioninsolana-program-testis unimplemented. hereProgramTest'spayeris randomly chosen. hereProgramTest'sinvoke_context. heresolana-runtime::bank::Bankfor testing (gated behind featuredev-context-only-utils) but that's missing or it's not exposed from thesolana-program-testcrate. hereSummary of Changes
ProgramTestto supportsol_get_processed_sibling_instruction.ProgramTestpayerconfigurable while preserving the old logic if not explicitly configured.get_invoke_contextto bepub.ProgramTestContextfor registering a recent blockhash. Adddev-context-only-utilsfeature toProgramTest'sdependencysolana-runtimeso that theBank'smethodregister_recent_blockhash_for_testcan be used.At first glance, these changes are not directly related to code coverage but in the end unleash us with the ability to get to those statistics. A working example can be checked here. A vigilant reader will recognize the two problems we're facing with this example:
solana-program-testso that we have the proposed features upper.LiteSVM'ssolana-program-runtimeto day is tied tov2.3.The main goal is to contribute the code coverage tool from the working example to the Solana community.
Ultimately the main idea behind this PR is to have these features here in
masterand later have them also in thev2.3branch.