# Code coverage not tracking custom EnzymeRules.augmented\_primal and EnzymeRules.reverse implementations

**URL:** <https://discourse.julialang.org/t/code-coverage-not-tracking-custom-enzymerules-augmented-primal-and-enzymerules-reverse-implementations/133359>\
**Category:** General Usage\
**Tags:** package, enzyme\
**Created:** [October 22, 2025, 1:08pm UTC](https://discourse.julialang.org/t/code-coverage-not-tracking-custom-enzymerules-augmented-primal-and-enzymerules-reverse-implementations/133359 "2025-10-22T13:08:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kongdd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kongdd/32/17058_2.png) [@kongdd](https://discourse.julialang.org/u/kongdd)\
**Post date:** [October 22, 2025, 1:08pm UTC](https://discourse.julialang.org/t/code-coverage-not-tracking-custom-enzymerules-augmented-primal-and-enzymerules-reverse-implementations/133359/1 "2025-10-22T13:08:30Z")

</div>

I’m working on a package that implements custom autodiff rules for Enzyme. I’ve defined `augmented_primal` and `reverse` methods for `EnzymeRules`.

> <https://github.com/jl-pkgs/ModelAutoGrads.jl/blob/master/src/solver/ad_reverse.jl#L32-L121>

These functions are called indirectly through `autodiff`.

> <https://github.com/jl-pkgs/ModelAutoGrads.jl/blob/master/src/solver/gradient.jl#L41-L49>

> <https://github.com/jl-pkgs/ModelAutoGrads.jl/blob/master/test/test-gradient.jl#L36-L48>

When I run my test suite, the code coverage tool doesn’t track that these `augmented_primal` and `reverse` methods are being executed, even though the tests pass and produce correct results.

I suspect this is because Enzyme calls these rules at **compile-time/code generation** rather than through normal Julia runtime dispatch, so coverage tools can’t track them.

My Questions:

- What’s the recommended way to test custom Enzyme rules to ensure they’re covered in tests?

- Is there a way to directly call `augmented_primal` and `reverse` in tests (e.g., by manually constructing the `RevConfigWidth{1}` config)?

> **[Code coverage done right.](https://app.codecov.io/gh/jl-pkgs/ModelAutoGrads.jl/blob/master/src%2Fsolver%2Fad_reverse.jl)**
>
> Hosted coverage report highly integrated with GitHub, Bitbucket and GitLab. Awesome pull request comments to enhance your QA.

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [October 22, 2025, 3:48pm UTC](https://discourse.julialang.org/t/code-coverage-not-tracking-custom-enzymerules-augmented-primal-and-enzymerules-reverse-implementations/133359/2 "2025-10-22T15:48:05Z")

</div>

Yes, Enzyme code is bypassing code coverage and fixing that is quite hard.

We test the rules, by just directly calling `autodiff(Reverse, fixed_point!, Duplicated...)`

> <https://github.com/EnzymeAD/Enzyme.jl/blob/dae703caff9208af1906f28e7ee6901d365dfbc7/test/rules/rules.jl#L61>

---

<div class="post-metadata">

**Author:** ![kongdd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kongdd/32/17058_2.png) [@kongdd](https://discourse.julialang.org/u/kongdd)\
**Post date:** [October 23, 2025, 3:08am UTC](https://discourse.julialang.org/t/code-coverage-not-tracking-custom-enzymerules-augmented-primal-and-enzymerules-reverse-implementations/133359/3 "2025-10-23T03:08:39Z")

</div>

Directly call not work for unknown reason:

> <https://github.com/jl-pkgs/ModelAutoGrads.jl/blob/master/test/test-reverse_hard.jl#L24-L32>

Finally, I tested those function in a hard way:

> <https://github.com/jl-pkgs/ModelAutoGrads.jl/blob/master/test/test-reverse_hard.jl#L44-L68>
