Code Coverage#
Trident's code coverage feature analyzes which parts of your Solana program are tested during fuzzing sessions, helping you identify untested code paths and improve test effectiveness.
Key features:
- Real-time Analysis: Monitor coverage as fuzzing progresses
- Multiple Formats: Generate reports in JSON and HTML formats
- VS Code Integration: Visualize coverage directly in your IDE using Solana VS Code extension
- Detailed Reporting: Get insights into line coverage, branch coverage, and execution paths
Gathering Coverage Data#
- Enable coverage in the Trident manifest
- Deploy your program through the entrypoint
- Run the fuzz test
Viewing Coverage Reports#
You have two options for displaying coverage data: generate an HTML report for browser viewing, or generate a JSON report for VS Code integration.
Live Coverage Updates#
For real-time coverage monitoring during fuzzing:
- Set
format = "json"in the Trident manifest - Set
loopcountto a value other than0e.g.,5for frequent updates, for more info check out Trident manifest - Install the Solana VS Code extension
- Choose one of these options:
- Automatic: Set
attach_extension = truein the Trident manifest to automatically show live updates while the fuzz test is running - Manual: Use the command
Solana: Show Code Coverageand select the "Attach to active fuzzing session" option
- Automatic: Set
Post-Session Coverage Analysis#
- Set
format = "json"in the Trident manifest before running the fuzz test - Run the fuzz test
- Install the Solana VS Code extension
- Run the VS Code command
Solana: Show Code Coverageand select the "Load generated JSON report" option
HTML Report#
- Set
format = "html"in the Trident manifest before running the fuzz test - Run the fuzz test
- After the fuzz test finishes, the HTML report will be stored in the
<fuzz-test-name>-coverage-reportfolder - Open the HTML report in your browser