|
| 1 | +# Multiplex - Parameter Expansion Engine |
| 2 | + |
| 3 | +## Purpose |
| 4 | +Multiplex translates multi-value benchmark parameters into single-value test matrices. Given a set of parameters with multiple possible values, it produces all valid combinations (the Cartesian product), respecting parameter roles and constraints. Output feeds into rickshaw-run as `bench-params.json`. |
| 5 | + |
| 6 | +## Language |
| 7 | +Python 3 — single main file `multiplex.py` (~510 lines), no dependencies beyond `jsonschema`. |
| 8 | + |
| 9 | +## Key Files |
| 10 | +| File | Purpose | |
| 11 | +|------|---------| |
| 12 | +| `multiplex.py` | Core parameter expansion logic and CLI entry point | |
| 13 | +| `params` | Default CLI arguments file (read by argparse `fromfile_prefix_chars`) | |
| 14 | +| `JSON/schema.json` | JSON schema for multi-value input validation | |
| 15 | +| `JSON/req-schema.json` | JSON schema for requirements file validation | |
| 16 | + |
| 17 | +## Key Functions |
| 18 | +| Function | Purpose | |
| 19 | +|----------|---------| |
| 20 | +| `multiplex_sets()` | Main driver: expands all parameter sets | |
| 21 | +| `multiplex_set()` | Expands one multi-value set into multiple single-value sets (Cartesian product via `itertools.product`) | |
| 22 | +| `load_param_sets()` | Resolves `include` references from global-options into sets | |
| 23 | +| `override_presets()` | Applies defaults, essentials, and named presets from requirements | |
| 24 | +| `transform_param_val()` | Applies validation regex, unit conversion, and regex transformation | |
| 25 | +| `validate_schema()` | Validates input JSON against schema | |
| 26 | + |
| 27 | +## Exit Codes |
| 28 | +| Code | Constant | Meaning | |
| 29 | +|------|----------|---------| |
| 30 | +| 0 | `EC_SUCCESS` | Success | |
| 31 | +| 1 | `EC_SCHEMA_FAIL` | Input JSON schema validation failed | |
| 32 | +| 2 | `EC_JSON_FAIL` | JSON file loading failed | |
| 33 | +| 3 | `EC_REQUIREMENTS_FAIL` | Requirements file loading failed | |
| 34 | +| 4 | `EC_VALIDATIONS_FAIL` | Parameter validation failed | |
| 35 | +| 5 | `EC_REQ_SCHEMA_FAIL` | Requirements JSON schema validation failed | |
| 36 | +| 6 | `EC_EMPTY_SET_FAIL` | Empty param set after preset override | |
| 37 | + |
| 38 | +## Input/Output |
| 39 | +- **Input**: JSON with `global-options` and `sets` arrays; params use `arg` and `vals` (multi-value list) keys, optional `role` (client/server/all), `id`, `enabled` |
| 40 | +- **Output**: JSON array of arrays; each inner array is one test iteration with single-value params using `arg`, `val`, and `role` keys |
| 41 | +- **Requirements** (optional): Defines `presets` (defaults, essentials, named), `validations` (regex), and `units` (conversion factors) |
| 42 | + |
| 43 | +## Tests |
| 44 | +Run with `cd` to project root, then `pytest tests/`: |
| 45 | +- `tests/test-json.py` — Parameter loading, multiplexing, Cartesian expansion, value conversion |
| 46 | +- `tests/test-requirements.py` — Validation regex, presets, unit conversion, preset precedence |
| 47 | +- `tests/test-schema.py` — Schema validation for valid and invalid inputs |
| 48 | +- 60+ JSON fixtures in `tests/JSON/` |
| 49 | + |
| 50 | +## Conventions |
| 51 | +- 4-space indentation, PEP 8 naming |
| 52 | +- Module-level dicts for state: `validation_dict`, `convert_dict`, `transform_dict`, `presets_dict` |
| 53 | +- Uses Python `logging` module for debug/info/warning/error output |
0 commit comments