Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/cexenum: Add '--callback' option and refactor enumeration loop #256

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions tools/cexenum/callbacks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Callback JSON Protocol

The `--callback` option allows controlling the counter-example enumeration using a JSON based protocol.

With `--callback '-'`, callback events are output to stdout and callback responses are read from stdin.

With `--callback '<command-line>'` the given command line is launched as subprocess which recieves callback events on stdin and produces callback responses on stdout.

Each event and response consists of a single line containing a JSON object.

## Callback Events

A callback event is emitted whenever:

* a step is entered for the first time (`"event": "step"`),
* a new counter-example trace was found (`"event": "trace"`) or
* no counter-examples remain for the current step (`"event": "unsat"`).

Every callback event includes the current step (`"step": <step>`) and a list of enabled named blocked patterns (`"enabled": [...]`, see below).

A trace event also includes a path to the `.yw` file of the counter-example trace. The `.aiw` file can be found by replacing the file extension.

After an event is emitted, the enumeration script waits for one or multiple callback responses, continuing when a callback response includes the `"action"` key.

## Callback Responses

### Actions

An action hands control back to the enumeration script. The following three actions are available:

* `{"action": "search"}`: Search for a further counter-example in the current time step.
* `{"action": "advance"}`: Advance to the next time step, abandoning any not-yet-enumerated counter-examples of the current time step.
* `{"action": "next"}`: Search for the next counter-example, automatically advancing to the next time-step when necessary.

Note that an `{"action": "search"}` response to an `"unsat"` event remains at the same time step, which can be used to disable a named blocked pattern, which can make further counter-examples available.

In the interactive callback mode (`--callback '-'`) it is possible to use single letter shortcuts `s`, `a` and `n` instead of the JSON syntax `{"action": "search"}`, `{"action": "advance"}` and `{"action": "next"}` respectively.

### Blocking Patterns

A specific input pattern given as an `.yw` or `.aiw` file can be blocked.
During enumeration, only counter-examples that differ from in at least one non-`x` bit from every blocked pattern are considered.

A `.yw` pattern can be blocked using `{"block_yw": "<file-path>"}` and a `.aiw` pattern using `{"block_aiw": "<file-path>"}`. Additionally a pattern can be given a name by using `{"block_...": "<file-path>", "name": "<name>"}`, in which case it will be possible to disable and reenable the blocked pattern. By default a newly added named blocked pattern is enabled.

A named pattern can be disable with the `{"disable": "<name>"}` response and re-enabled with the `{"enable": "<name>"}` response.
Loading