4.3 KiB
4.3 KiB
Configuration Resolution: What is read and when
This document explains how configuration is loaded, merged, and provided to tests and interfaces.
Sources and precedence
From highest to lowest precedence:
- In-code overrides (if
load_config(..., overrides=...)is used) - Environment variable
ECU_TESTS_CONFIG(absolute/relative path to YAML) config/test_config.yaml(if present under the workspace root)- Built-in defaults
Data model (dataclasses)
EcuTestConfiginterface: InterfaceConfigtype:mockorbabylinchannel: LIN channel index (0-based in SDK wrapper)bitrate: LIN bitrate (e.g., 19200); usually defined by SDFsdf_path: Path to SDF file (hardware; required for typical operation)schedule_nr: Schedule number to start on connect (hardware)node_name: Optional node identifier (informational)dll_path,func_names: Legacy fields from the old ctypes adapter; not used with the SDK wrapper
flash: FlashConfigenabled: whether to flash before testshex_path: path to HEX file
power_supply: PowerSupplyConfigenabled: whether PSU features/tests are activeport: Serial device (e.g.,COM4,/dev/ttyUSB0)baudrate,timeout,eol: line settings (e.g.,"\n"or"\r\n")parity:N|E|Ostopbits:1or2xonxoff,rtscts,dsrdtr: flow control flagsidn_substr: optional substring to assert in*IDN?do_set,set_voltage,set_current: optional demo/test actions
YAML examples
Minimal mock configuration (default):
interface:
type: mock
channel: 1
bitrate: 19200
flash:
enabled: false
Hardware (BabyLIN SDK wrapper) configuration:
interface:
type: babylin
channel: 0 # 0-based channel index
bitrate: 19200 # optional; typically driven by SDF
node_name: "ECU_TEST_NODE"
sdf_path: "./vendor/Example.sdf"
schedule_nr: 0
flash:
enabled: true
hex_path: "firmware/ecu_firmware.hex"
Power supply configuration (either inline or merged from a dedicated YAML):
```yaml
power_supply:
enabled: true
port: COM4 # or /dev/ttyUSB0 on Linux
baudrate: 115200
timeout: 1.0
eol: "\n" # or "\r\n" if your device requires CRLF
parity: N # N|E|O
stopbits: 1 # 1|2
xonxoff: false
rtscts: false
dsrdtr: false
idn_substr: OWON
do_set: false
set_voltage: 5.0
set_current: 0.1
## Load flow
```text
tests/conftest.py: config() fixture
→ load_config(workspace_root)
→ check env var ECU_TESTS_CONFIG
→ else check config/test_config.yaml
→ else use defaults
→ convert dicts to EcuTestConfig dataclasses
→ provide to other fixtures/tests
Additionally, if present, a dedicated PSU YAML is merged into `power_supply`:
- Environment variable `OWON_PSU_CONFIG` (path to YAML), else
- `config/owon_psu.yaml` under the workspace root
This lets you keep machine-specific serial settings separate while still having
central defaults in `config/test_config.yaml`.
How tests and adapters consume config
linfixture picksmockorbabylinbased oninterface.type- Mock adapter uses
bitrateandchannelto simulate timing/behavior - BabyLIN adapter (SDK wrapper) uses
sdf_path,schedule_nr,channelto open the device, load the SDF, and start a schedule.bitrateis informational unless explicitly applied via commands/SDF. flash_ecuusesflash.enabledandflash.hex_path- PSU-related tests or utilities read
config.power_supplyfor serial parameters and optional actions (IDN assertions, on/off toggle, set/measure). The reference implementation isecu_framework/power/owon_psu.py, with a hardware test intests/hardware/test_owon_psu.pyand a tryout script invendor/Owon/tryout.py.
Tips
- Keep multiple YAMLs and switch via
ECU_TESTS_CONFIG - Check path validity for
sdf_pathandhex_pathbefore running hardware tests - Ensure
vendor/BabyLIN_library.pyand the platform-specific libraries from the SDK are available onPYTHONPATH - Use environment-specific YAML files for labs vs. CI
- For PSU, prefer
OWON_PSU_CONFIGorconfig/owon_psu.yamlto avoid committing local COM port settings. Central defaults can live inconfig/test_config.yaml.