ecu-tests/TESTING_FRAMEWORK_GUIDE.md
Hosam-Eldin Mostafa 582764d410 Mark legacy BabyLIN adapter as deprecated across code and docs
The MUM (Melexis Universal Master) adapter is the current default; the
BabyLIN SDK adapter is retained only for backward compatibility with
existing rigs.

Code:
- Emit DeprecationWarning when BabyLinInterface is instantiated and
  when tests/conftest.py routes interface.type=='babylin' to it.
- Update module/class docstrings in ecu_framework/{__init__,config,
  lin/__init__,lin/babylin}.py to label BabyLIN-specific fields and
  paths as deprecated.

Config / scripts / pytest:
- pytest.ini: relabel the babylin marker as deprecated.
- config/{babylin.example,examples,test_config}.yaml: add deprecation
  banners and field comments.
- scripts/99-babylin.rules and scripts/pi_install.sh: annotate the
  udev-rule install block as legacy-only.

Documentation:
- TESTING_FRAMEWORK_GUIDE.md, docs/08_babylin_internals.md, and
  vendor/README.md: prepend explicit "DEPRECATED" banners.
- docs/{README,01,02,04,05,07,09,10,12,13,14,15,18,DEVELOPER_COMMIT_
  GUIDE}.md: relabel "legacy" to "deprecated" where babylin is
  mentioned, present MUM as the primary path, and steer new work
  toward the MUM examples.

No tests, configs, or modules were deleted; existing BabyLIN setups
keep working but now produce a clear DeprecationWarning at runtime.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 17:32:24 +02:00

14 KiB

ECU Testing Framework - Complete Guide

Heads-up: the BabyLIN LIN adapter is deprecated and retained for backward compatibility only. New tests and deployments should target the MUM (Melexis Universal Master) adapter — see docs/16_mum_internals.md. The BabyLIN-related sections below are kept so existing rigs can still be maintained.

Overview

This comprehensive ECU Testing Framework provides a robust solution for testing Electronic Control Units (ECUs) using pytest with the MUM LIN adapter (current) or the deprecated BabyLIN adapter. The framework includes detailed test documentation, enhanced reporting, mock interfaces for development, and real hardware integration capabilities.

Framework Features

Complete Implementation Status

  • pytest-based testing framework with custom plugins
  • MUM (Melexis Universal Master) LIN integration via the pylin / pymumclient packages — current default
  • ⚠️ BabyLIN LIN integration (DEPRECATED) via the official SDK Python wrapper (BabyLIN_library.py)
  • Mock interface for hardware-independent development
  • Enhanced HTML/XML reporting with test metadata
  • Detailed test documentation extraction
  • Configuration management with YAML
  • Hex file flashing capabilities (scaffold)
  • Custom pytest markers for requirement traceability

Enhanced Reporting System

Test Metadata Integration

The framework automatically extracts detailed test information from docstrings and integrates it into reports:

HTML Report Features:

  • Title Column: Clear test descriptions extracted from docstrings
  • Requirements Column: Requirement traceability (REQ-001, REQ-002, etc.)
  • Enhanced Test Details: Description, test steps, and expected results
  • Marker Integration: Custom pytest markers for categorization

Example Test Documentation Format:

@pytest.mark.smoke
@pytest.mark.req_001
def test_mock_send_receive_echo(self, mock_interface):
    """
    Title: Mock LIN Interface - Send/Receive Echo Test
    
    Description: Validates basic send/receive functionality using the mock
    LIN interface with echo behavior for development testing.
    
    Requirements: REQ-001, REQ-003
    
    Test Steps:
    1. Connect to mock LIN interface
    2. Send a test frame with ID 0x01 and data [0x55]
    3. Receive the echoed frame within 100ms timeout
    4. Verify frame ID and data integrity
    
    Expected Result:
    - Frame should be echoed back successfully
    - Received data should match sent data exactly
    - Operation should complete within timeout period
    """

Report Generation

HTML Report (reports/report.html):

  • Interactive table with sortable columns
  • Test titles and requirements clearly visible
  • Execution duration and status tracking
  • Enhanced metadata from docstrings

XML Report (reports/junit.xml):

  • Standard JUnit XML format for CI/CD integration
  • Test execution data and timing information
  • Compatible with most CI systems (Jenkins, GitLab CI, etc.)

Project Structure

ecu_tests/
├── ecu_framework/              # Core framework package
│   ├── config.py              # YAML configuration management
│   ├── lin/                   # LIN communication interfaces
│   │   ├── base.py           # Abstract LinInterface definition
│   │   ├── mock.py           # Mock interface for development
│   │   └── babylin.py        # DEPRECATED BabyLin hardware interface (kept for legacy rigs)
│   └── flashing/             # Hex file flashing capabilities
│       └── hex_flasher.py    # ECU flash programming
├── tests/                     # Test suite
│   ├── conftest.py           # pytest fixtures and configuration
│   ├── test_smoke_mock.py    # Mock interface validation tests
│   ├── test_babylin_hardware_smoke.py    # Hardware smoke tests (deprecated BabyLIN)
│   └── test_hardware_placeholder.py      # Future hardware tests
├── config/                    # Configuration files
│   ├── test_config.yaml      # Main test configuration
│   └── babylin.example.yaml  # DEPRECATED BabyLin configuration template
├── vendor/                   # SDK placement (BabyLIN paths are deprecated)
|   ├── BabyLIN_library.py   # Official SDK Python wrapper (deprecated)
|   └── platform libs        # OS-specific native libs (DLL/.so/.dylib) — deprecated
├── reports/                  # Generated test reports
│   ├── report.html          # Enhanced HTML report
│   └── junit.xml           # JUnit XML report
├── conftest_plugin.py       # Custom pytest plugin for enhanced reporting
├── pytest.ini             # pytest configuration with custom markers
├── requirements.txt        # Python dependencies
└── README.md              # Project documentation

Running Tests

Basic Test Execution

# Run all tests with verbose output
python -m pytest -v

# Run specific test suite
python -m pytest tests\test_smoke_mock.py -v

# Run tests with specific markers
python -m pytest -m "smoke" -v
python -m pytest -m "req_001" -v

# Run hardware tests (requires deprecated BabyLIN hardware); join with adapter marker
# Prefer MUM for new work: pytest -m "hardware and mum" -v
python -m pytest -m "hardware and babylin" -v

Unit Tests (fast, no hardware)

Run only unit tests using the dedicated marker or by path:

# By marker
python -m pytest -m unit -q

# By path
python -m pytest tests\unit -q

# Plugin self-tests (verifies reporting artifacts)
python -m pytest tests\plugin -q

Reports still go to reports/ (HTML and JUnit per defaults). Open the HTML on Windows with:

start .\reports\report.html

Coverage: enabled by default via pytest.ini. To disable locally:

python -m pytest -q -o addopts=""

Optional HTML coverage:

python -m pytest --cov=ecu_framework --cov-report=html -q
start .\htmlcov\index.html

See also: docs/13_unit_testing_guide.md for more details and examples.

Report Generation

Tests automatically generate enhanced reports:

  • HTML Report: reports/report.html - Interactive report with metadata
  • XML Report: reports/junit.xml - CI/CD compatible format

Configuration

Test Configuration (config/test_config.yaml)

interface:
  type: mock  # or "mum" for hardware (current); "babylin" is deprecated
  timeout: 1.0

flash:
  hex_file_path: firmware/ecu_firmware.hex
  flash_timeout: 30.0

ecu:
  name: Test ECU
  lin_id_range: [0x01, 0x3F]

BabyLIN Configuration (config/babylin.example.yaml) — DEPRECATED

Retained for backward compatibility. Prefer config/mum.example.yaml for new work.

interface:
  type: babylin           # deprecated; prefer "mum"
  channel: 0              # channel index used by the SDK wrapper
  bitrate: 19200          # typically set by SDF
  sdf_path: ./vendor/Example.sdf
  schedule_nr: 0          # schedule to start on connect

Test Categories

1. Mock Interface Tests (test_smoke_mock.py)

Purpose: Hardware-independent development and validation

  • Send/receive echo functionality
  • Master request/response testing
  • Timeout behavior validation
  • Frame validation boundary testing
  • Parameterized boundary tests for comprehensive coverage

Status: 7 tests passing - Complete implementation

2. Hardware Smoke Tests (test_babylin_hardware_smoke.py) — DEPRECATED

Purpose: Basic BabyLIN hardware connectivity validation (deprecated path; prefer the MUM smoke tests under tests/hardware/)

  • SDK wrapper import and device open
  • Interface connection establishment
  • Basic send/receive operations
  • Error handling and cleanup

Status: Ready for hardware testing

3. Hardware Integration Tests (test_hardware_placeholder.py)

Purpose: Full ECU testing workflow with real hardware

  • ECU flashing with hex files
  • Communication protocol validation
  • Diagnostic command testing
  • Performance and stress testing

Status: Framework ready, awaiting ECU specifications

Custom Pytest Markers

The framework includes custom markers for test categorization and requirement traceability:

# In pytest.ini
markers =
    smoke: Basic functionality tests
    integration: Integration tests requiring hardware
    hardware: Tests requiring physical hardware (MUM or, deprecated, BabyLin)
  babylin: DEPRECATED. Tests targeting the legacy BabyLIN SDK adapter
  mum: Tests targeting the current MUM (Melexis Universal Master) adapter
  unit: Fast unit tests (no hardware)
    boundary: Boundary condition and edge case tests
    req_001: Tests validating requirement REQ-001 (LIN Interface Basic Operations)
    req_002: Tests validating requirement REQ-002 (Master Request/Response)
    req_003: Tests validating requirement REQ-003 (Frame Validation)
    req_004: Tests validating requirement REQ-004 (Timeout Handling)

BabyLIN Integration Details (DEPRECATED)

Kept for backward compatibility only. New tests should use the MUM adapter (docs/16_mum_internals.md).

SDK Python wrapper

The deprecated BabyLIN adapter uses the official SDK Python wrapper BabyLIN_library.py (placed under vendor/) and calls its BLC_* APIs.

Key calls in the adapter (ecu_framework/lin/babylin.py):

  • BLC_getBabyLinPorts, BLC_openPort — discovery and open
  • BLC_loadSDF, BLC_getChannelHandle, BLC_sendCommand('start schedule N;') — SDF + scheduling
  • BLC_mon_set_xmit — transmit
  • BLC_getNextFrameTimeout — receive
  • BLC_sendRawMasterRequest — master request (length then bytes)

Development Workflow

1. Development Phase

# Use mock interface for development
python -m pytest tests\test_smoke_mock.py -v

2. Hardware Integration Phase

# Test with deprecated BabyLIN hardware (legacy rigs only)
# Prefer MUM: python -m pytest -m "hardware and mum" -v
python -m pytest -m "hardware and babylin" -v

3. Full System Testing

# Complete test suite including ECU flashing
python -m pytest -v

Enhanced Reporting Output Example

The enhanced HTML report includes:

Result Test Title Requirements Duration Links
Passed test_mock_send_receive_echo Mock LIN Interface - Send/Receive Echo Test REQ-001, REQ-003 1 ms
Passed test_mock_request_synthesized_response Mock LIN Interface - Master Request Response Test REQ-002 0 ms
Passed test_mock_receive_timeout_behavior Mock LIN Interface - Receive Timeout Test REQ-004 106 ms

Framework Validation Results

Current Status: All core features implemented and tested

Mock Interface Tests: 7/7 passing (0.14s execution time)

  • Send/receive operations: Working
  • Timeout handling: Working
  • Frame validation: Working
  • Boundary testing: Working

Enhanced Reporting: Fully functional

  • HTML report with metadata: Working
  • XML report generation: Working
  • Custom pytest plugin: Working
  • Docstring metadata extraction: Working

Configuration System: Complete

  • YAML configuration loading: Working
  • Environment variable override: Working
  • BabyLIN SDF/schedule configuration: Working (deprecated path)
  • Power supply (PSU) configuration: Working (see config/test_config.yamlpower_supply)

Owon Power Supply (PSU) Integration

The framework includes a serial SCPI controller for Owon PSUs and a hardware test wired to the central config.

  • Library: ecu_framework/power/owon_psu.py (pyserial)
  • Config: config/test_config.yaml (power_supply section)
    • Optionally merge machine-specific settings from config/owon_psu.yaml or env OWON_PSU_CONFIG
  • Hardware test: tests/hardware/test_owon_psu.py (skips unless power_supply.enabled and port present)
  • quick demo: vendor/Owon/owon_psu_quickdemo.py

Quick run:

pip install -r .\requirements.txt
copy .\config\owon_psu.example.yaml .\config\owon_psu.yaml
# edit COM port in .\config\owon_psu.yaml
pytest -k test_owon_psu_idn_and_optional_set -m hardware -q
python .\vendor\Owon\owon_psu_quick_demo.py

Common config keys:

power_supply:
  enabled: true
  port: COM4
  baudrate: 115200
  timeout: 1.0
  eol: "\n"
  parity: N
  stopbits: 1
  idn_substr: OWON

Next Steps

  1. Hardware Testing: Connect MUM hardware (or, for legacy rigs, BabyLin) and validate the corresponding hardware smoke tests
  2. ECU Integration: Define ECU-specific communication protocols and diagnostic commands
  3. Hex Flashing: Implement complete hex file flashing workflow
  4. CI/CD Integration: Set up automated testing pipeline with generated reports

Dependencies

pytest>=8.4.2
pytest-html>=4.1.1
pytest-xdist>=3.8.0
pyyaml>=6.0.2

This framework provides a complete, production-ready testing solution for ECU development. The current LIN path uses the MUM adapter; the BabyLIN adapter is retained as a deprecated fallback for legacy rigs. Enhanced documentation, traceability, and reporting are available regardless of the adapter in use.