You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add code coverage support using native-simulator
- Add ctor dependency and coverage_flush module to native-simulator template
- Add coverage targets to workspace Makefile (coverage, coverage-html, coverage-lcov)
- Add coverage documentation to README.md with clear prerequisites
- Add coverage test step to CI workflow (ubuntu-latest only, not ARM)
- Update test templates to use deploy_cell_by_name() for native-simulator support
Note: Only the 'contract' template supports native-simulator feature and coverage.
Other templates (atomics-contract, stack-reorder-contract, contract-without-simulator,
standalone-contract) do not support coverage.
Copy file name to clipboardExpand all lines: README.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -255,3 +255,47 @@ make generate-native-simulator CRATE=example_crate
255
255
256
256
- The `CRATE` parameter must refer to a subproject.
257
257
- Missing subprojects will cause the command to fail.
258
+
259
+
### Code Coverage
260
+
261
+
The templates include built-in support for code coverage reporting using LLVM's coverage tools.
262
+
263
+
**Requirements:**
264
+
- Only contracts created with the `contract` template support coverage (pure Rust contracts with `native-simulator` feature)
265
+
- Other templates (`atomics-contract`, `stack-reorder-contract`, `contract-without-simulator`, `standalone-contract`) do not support coverage
266
+
- Native simulators must be generated for each contract you want coverage for
267
+
- Only works on x86_64 Linux (not ARM)
268
+
269
+
**Setup:**
270
+
271
+
1. Install llvm-tools:
272
+
```bash
273
+
make coverage-install
274
+
```
275
+
276
+
2. Generate native simulators for your contracts:
277
+
```bash
278
+
make generate-native-simulator CRATE=<contract_name>
279
+
```
280
+
281
+
**Generate Reports:**
282
+
```bash
283
+
make coverage # Text report to console
284
+
make coverage-html # HTML report in target/coverage/html/
285
+
make coverage-lcov # LCOV format for CI integration
286
+
```
287
+
288
+
**Example:**
289
+
```bash
290
+
# Create a contract using the default 'contract' template
291
+
make generate CRATE=my-contract
292
+
293
+
# Generate native simulator for it
294
+
make generate-native-simulator CRATE=my-contract
295
+
296
+
# Install tools and run coverage
297
+
make coverage-install
298
+
make coverage
299
+
```
300
+
301
+
Coverage works by running tests with the `native-simulator` feature, which executes contract code natively on x86_64 instead of in CKB-VM. This allows LLVM's coverage instrumentation to track which lines of code are executed.
0 commit comments