# eaxsim scenario checks and eaxsimctl test

> Pass/fail checks in an eaxsim scenario (expect), how eaxsimctl test, eaxsim -report and eaxsim-cloud run them in virtual time, their exit codes, the eaxsim.checks/1 JSON report and a CI gate example.

Product: Platform · Type: Reference · Editions: Cloud
Source: https://eaxware.com/docs/platform/reference/eaxsim-scenario-checks/
Verified against commit 28cabb6.

A scenario can carry pass/fail checks (`expect`). `eaxsimctl test` runs the scenario locally in virtual time and checks them; `eaxsim -report` and eaxsim-cloud check them too, so a build pipeline can gate on the result either on its own machine or on eaxsim-cloud. Every key of an `expect` entry is in the generated [eaxsim scenario](/docs/platform/reference/generated/config/sim-scenario/#expect) reference.

## Checks

```json
"expect": [
  {"id": "settled", "plc": "tank-*", "signal": "T1.level_m", "check": "at", "at_s": 95, "cmp": "within", "value": 2.0, "tol": 0.1},
  {"id": "no-spill", "signal": "T1.level_pct", "check": "never", "cmp": ">", "value": 95},
  {"id": "alarm-on-fault", "plc": "tank-*", "var": "HighAlarm", "check": "eventually", "after_fault": "pump-on", "within_s": 30, "cmp": "==", "value": true},
  {"id": "alarm-clears", "plc": "tank-00", "var": "%QX0.1", "check": "always", "from_s": 250, "to_s": 300, "cmp": "==", "value": false}
]
```

- **What is checked:** a plant signal (`signal`, a model port) or a PLC variable (`var`, by name, or a direct address with its type such as `%MD104:REAL`). Exactly one of the two.
- **`check`:**
  - `at`: the first sample at or after `at_s`;
  - `always`: every sample from `from_s` to `to_s`;
  - `never`: no sample in that window;
  - `eventually`: some sample in the window, or within `within_s`.

  A window without `to_s` runs to the end of the run.
- **`cmp`:** `==`, `!=`, `<`, `<=`, `>`, `>=`, or `within` (`|x - value| <= tol`). `value` is a number, or `true` / `false`.
- **Times** are simulated seconds from the start of the run, or from the start of the fault that `after_fault` names, on each PLC that has it.
- **`plc`** is a pattern over PLC ids; empty means every PLC. Every matching PLC must pass.
- **Read only.** A check never writes a variable, forces a signal or injects a fault. An unknown key is refused, as everywhere else in a scenario. A scenario holds at most 1000 checks, and their ids are unique.
- The checks are evaluated at every virtual tick, so the verdict is the same at any speed. They are evaluated by `eaxsimctl test`, by `eaxsim -report` and, through it, by eaxsim-cloud (below). A realtime run is never checked.

## `eaxsimctl test`

```text
eaxsimctl test [-until S] [-speed X] [-workers N] [-report FILE] [-timeout D] SCENARIO.json
```

The scenario runs locally, in virtual time, with no broker and no API: nothing outside the process sees or commands its PLCs. The flags are in the [eaxPLC command-line reference](/docs/eaxplc/reference/generated/cli/). The JSON report goes to standard output, and also to `-report` when given.

| Exit code | Meaning |
|---|---|
| `0` | every check passed |
| `1` | a check failed, or was not covered by the run (inconclusive), or a PLC stopped |
| `2` | no run: a usage error, an invalid scenario, a build error, or a timeout |

## `eaxsim -report`

```text
eaxsim -scenario SCENARIO.json -report FILE [other flags]
```

With `-report`, a virtual run evaluates the scenario's `expect` entries at every tick, writes the `eaxsim.checks/1` report to `FILE` when the run ends, and adds `"verdict"` to the file named by `-stats-file`. Without `-report`, eaxsim runs and exits as before.

| Exit code | Meaning |
|---|---|
| `0` | the run ended and every check passed |
| `1` | a check failed, was not covered by the run (inconclusive), or a PLC stopped; also any run that failed |
| `2` | usage error: `-report` on a realtime run or on a scenario without `expect` entries, refused before anything runs |

## eaxsim-cloud: verdict and report

- **Checked runs.** A start in virtual time of a scenario with `expect` entries runs eaxsim with `-report`. Any other start is not checked.
- **Run state.** A checked run whose checks do not pass still ended: it ends `stopped`, not `failed`, and is metered as usual. eaxsim exiting `1` without its report is a failed run.
- **`verdict`.** The simulation (`GET /v1/sims/{id}`) carries `"verdict": "pass"` or `"fail"` for its last checked run (`fail` covers a report verdict of `fail` or `error`). It is cleared at each start, and absent when the last run was not checked.
- **`GET /v1/sims/{id}/report`** (tenant API key, the tenant's own simulations only) returns the last checked run's report. `404` when the last run was not checked or has not ended. A report file uploaded with the scenario is removed at start and never served. The route is in the [eaxsim-cloud HTTP API reference](/docs/platform/reference/generated/http-api-eaxsim-cloud/).

## `eaxsimctl wait` and `eaxsimctl report`

```text
eaxsimctl wait [-timeout 10m] [-interval 1s] SIM
eaxsimctl report [-o FILE] SIM
```

| Command | Exit `0` | Exit `1` | Other |
|---|---|---|---|
| `wait` | the run ended (stopped) and, for a checked run, its verdict is `pass` | the run failed, or a checked run ended with a verdict other than `pass` | `3`: timeout |
| `report` | the report's verdict is `pass` | the verdict is not `pass`, or there is no report | `2`: usage error |

Behaviour change: `eaxsimctl wait` used to exit `0` for any run that ended, whatever its checks. A run without checks is unchanged. `eaxsimctl report` prints the report and, with `-o`, also writes it to `FILE`.

## CI gate example

The eaxPLC repository has a ready example: the scenario `examples/sim/ci/checks/tankfarm.json` (4 tanks, PI level control with a high-level alarm, 5 checks) and the gate script `examples/sim/ci/checks-gate.sh`. Its exit code is the verdict, and it writes the report to `REPORT` (default `checks-report.json`) for the job's artifacts.

```text
sh examples/sim/ci/checks-gate.sh                    # local: eaxsimctl test, no key
EAXSIM_KEY=... sh examples/sim/ci/checks-gate.sh cloud   # eaxsim-cloud: create, start, wait, report, delete
```

- **Local** runs `eaxsimctl test` on the CI machine: no broker, no API, no key.
- **`cloud`** uploads the scenario with its program, starts it in virtual time, waits, fetches the report and deletes the simulation. `EAXSIM_URL` is the eaxsim-cloud address. Keep `EAXSIM_KEY` in the CI's secret store, never on the command line, where it would show in the job log.
- **Exit codes:** `0` pass, `1` a check failed or was not covered, or a PLC stopped, `2` no run, `3` (cloud) the run did not end within `TIMEOUT` (default `15m`).

## Report (`eaxsim.checks/1`)

| Key | Meaning |
|---|---|
| `schema` | `eaxsim.checks/1` |
| `scenario` | the scenario's name |
| `verdict` | `pass`, `fail` or `error` |
| `error` | why there was no run (verdict `error`) |
| `start_s`, `end_s`, `ticks` | the simulated time of the first and last sample, and the ticks run |
| `summary` | counts: `pass`, `fail`, `inconclusive` |
| `checks` | one result per check (below) |
| `plc_errors` | PLCs stopped during the run: `plc`, `error` |

Each result repeats the check (`id`, `description`, `check`, `plc`, `signal` or `var`, `cmp`, `value`, `tol`, the times, `after_fault`) and adds:

| Key | Meaning |
|---|---|
| `status` | `pass`, `fail` or `inconclusive` (the run did not cover it; counts as a failure) |
| `plcs`, `failed`, `inconclusive` | PLCs checked, and how many failed or were not covered |
| `first_fail_s`, `first_fail_plc` | the first failure: when (simulated seconds; for `eventually`, its deadline) and on which PLC |
| `met_s`, `met_plc` | for `at` and `eventually`: when the last PLC met it |
| `observed` | the value at the first failure, or at `met_s` |
| `min`, `max`, `samples` | the range of the samples taken on every PLC, and their number |
| `note` | a remark on the result |
