Repository navigation
Fix debug assertion in determine_targets for autoharness with --harness - #5063
Conversation
…rness` The debug build of `kani-driver` re-filters the harnesses that the compiler kept and asserts that both lists are equal. The compiler filters only manual harnesses and keeps every automatic harness. `find_proof_harnesses` skips automatic harnesses. So the assertion failed, and the driver panicked, for every `kani autoharness --harness <name>` run that generates at least one automatic harness. Compare only the manual harnesses in the debug check. The check still detects retained manual harnesses that do not satisfy the filter. Add a regression test. Resolves model-checking#4939
|
@acearyanarun @CYJ904 @Tianshu-Huang @wodex1nhaoIeng @srivatsansamraj, could you review this PR? |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Fixes a debug-build panic in KaniSession::determine_targets when using kani autoharness with a --harness filter by ensuring the debug assertion compares only manual harnesses (since automatic harnesses are intentionally retained by the compiler but skipped by find_proof_harnesses).
Changes:
- Update the debug assertion in
kani-driverto re-filter and compare only manual harnesses. - Add a new
script-based-preregression test coveringkani autoharness ... --harness <name>with both manual and automatic harnesses.
| File | Description |
|---|---|
kani-driver/src/metadata.rs |
Adjusts debug-only verification to compare filtered manual harnesses only, preventing a false assertion failure. |
tests/script-based-pre/autoharness_harness_filter/harness_filter.sh |
Adds a regression script validating no panic and correct harness selection behavior. |
tests/script-based-pre/autoharness_harness_filter/harness_filter.expected |
Defines the expected success output for the new regression test. |
tests/script-based-pre/autoharness_harness_filter/fixture.rs |
Provides a fixture with two manual harnesses and one autoharness-selected function. |
tests/script-based-pre/autoharness_harness_filter/config.yml |
Registers the new script-based-pre test. |
Review effort: Lite
feliperodri
left a comment
There was a problem hiding this comment.
The fix is right: the debug check compared lists that could never match for automatic harnesses. Narrowing it to manual harnesses keeps the check where it can hold, and release builds are unchanged.
Before merge:
- The test's
manual_otherassertion matches anywhere in the output, including harness lists. Match the execution line instead. - The code comment should say that automatic harness selection is not checked by this assertion.
- Nit: the
clone()could go iffind_proof_harnessestook a slice. - Three macOS jobs are cancelled. Please re-run them.
Match the `Checking harness manual_other...` line in the regression test, so that a harness list that names `manual_other` does not fail the test. State in the comment that the debug check does not cover automatic harness selection. Pass the manual harnesses by reference instead of cloning them; `find_proof_harnesses` already accepts any iterator of harness references.
Issue model-checking#4939 also reports the panic for a filter that matches nothing. Add that case to the regression test: the run must fail with the no-match error and must not panic. Match the summary lines as fixed strings.
|
Thanks for the review. Fixed in 38c81ab and 74ea9db:
The test also covers the issue's |
feliperodri
left a comment
There was a problem hiding this comment.
Thanks @ivmat, this addresses everything from my last review: the test now checks Checking harness manual_other... rather than the bare name, the comment states what the assertion does not cover, and the clone() is gone.
I built the head as a debug build and ran the new test; it passes, and with the base metadata.rs it panics at the assertion from #4939, so the test covers the regression. I also tried --exact and a filter matching both manual harnesses; neither panics, and the right harnesses run.
Please ignore my earlier request to re-run the macOS jobs: macos-14 runners were retired, and #5138 moves those jobs to macos-15.
948f8d2


Description
In debug builds,
kani autoharness -Z autoharness <file> --harness <name>panics inKaniSession::determine_targetswhen autoharness generates at least one automatic harness.The debug check re-filters the harnesses that the compiler kept with
find_proof_harnessesand asserts that both lists are equal. The compiler filters only manual harnesses and keeps
every automatic harness, but
find_proof_harnessesskips automatic harnesses. So the listsdiffer.
This change makes the debug check compare only the manual harnesses of the compiler list
with their re-filtered list. The check still detects retained manual harnesses that do not
satisfy the filter. It does not check the selection of automatic harnesses. Release builds do
not run this check and are not changed.
Resolves #4939
Testing
New test
tests/script-based-pre/autoharness_harness_filter, on a file with two manualharnesses and one function that autoharness selects:
--harness manual_selected: exit code 0, no panic, one verified manual harness and oneverified automatic harness; the line
Checking harness manual_selected...is present andthe line
Checking harness manual_other...is absent.--harness nomatch: a non-zero exit code, no panic, and the usualFailed to match the following harness(es):error.Both cases panic on the unfixed debug build. The test passes with the change.
A temporary change that makes the debug check use a wrong filter makes the test fail with the
assertion, so the check is still active for retained manual harnesses.
scripts/kani-regression.sh(which includesscripts/kani-fmt.sh --checkand the debug build),both CI clippy commands, and the copyright check pass.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.