Skip to content

Testing Strategy en

EnerOS Bot edited this page Jul 5, 2026 · 1 revision

中文 | English

Testing Strategy

Maintained version: v0.51.2 | Last updated: 2026-07-06

EnerOS employs a multi-layer testing strategy covering 7 levels: unit / integration / e2e / chaos / fuzz / proptest / protocol conformance. v0.51.2 test scale: 7700+ tests / 0 failed / 78 ignored / 0 clippy warnings / cargo deny green. This page is a strategy summary; for the full testing guide see the main repo docs/developer-guide.md §v0.51.0.

Test Pyramid

                    ┌──────────┐
                    │   Fuzz   │  4 protocols × 24h
                    └──────────┘
                ┌───────────────────┐
                │  Chaos            │  5 fault injections
                └───────────────────┘
            ┌─────────────────────────────┐
            │  e2e (tests/e2e)            │  HTTP API full chain
            └─────────────────────────────┘
        ┌─────────────────────────────────────┐
        │  Integration tests (cross-crate)    │
        └─────────────────────────────────────┘
    ┌─────────────────────────────────────────────┐
    │  Unit tests (within crate tests/)           │  ~7000+
    └─────────────────────────────────────────────┘

7 Test Layers

1. Unit Tests

Each crate's src/ contains #[cfg(test)] mod tests + a tests/ directory.

cargo test --workspace

v0.51.2 scale: 7700+ tests passed / 0 failed / 78 ignored.

2. Integration Tests

Cross-crate integration tests live in the tests/ directory:

Directory Purpose
tests/e2e/ HTTP API end-to-end
tests/protocol_conformance/ Protocol conformance (7 protocols, 275 tests)
tests/llm_verify/ LLM 100-scenario verification (v0.50.1+)
tests/llm_verify_semantic_20/ LLM 20-round semantic verification (v0.50.2+)
tests/chaos/ Chaos tests
tests/integration/ Cross-crate module boundary tests

3. e2e Tests

tests/e2e/ uses a real eneros-api instance + HTTP client, covering:

  • /health health check
  • /api/v1/demo/* demo APIs
  • /api/v1/devices/* device management
  • /api/v1/timeseries/* timeseries queries
  • /api/v1/analysis/* analysis computations
  • /api/v1/ops/* ops endpoints

4. Chaos Tests

tests/chaos/ injects 5 fault types:

Fault type Injection Verification
Network partition iptables block HA failover
Process crash kill -9 Daemon restart
Disk full tmpfs fill Graceful degradation
CPU saturation stress-ng Scheduling priority takes effect
Memory pressure cgroups limit OOM does not affect RT domain

5. Fuzz Testing (v0.51.0+)

The fuzz/ directory provides 4 fuzz targets using the libFuzzer engine:

Target Protocol
fuzz_iec104 IEC 104
fuzz_iec103 IEC 103
fuzz_dlt698 DL/T 698
fuzz_pmu_c37118 PMU C37.118
# Smoke test (60s)
cargo fuzz run fuzz_iec104 -- -max_total_time=60

# Long run (24h)
cargo fuzz run fuzz_iec104 -- -max_total_time=86400

Windows has a libFuzzer linking issue (LNK1104); run in a Linux / WSL2 environment.

6. proptest Property Testing (v0.51.0+)

5 crates × 256 cases = 30720 verifications (v0.51.1 expanded to 1024 cases = 30720 verifications, 0 violations):

Crate Properties Purpose
eneros-powerflow 6 Powerflow convergence + conservation laws
eneros-topology 5 Topology search invariants
eneros-linalg 6 Matrix operation properties
eneros-timeseries 7 Timeseries aggregation no-drop
eneros-constraint 6 Constraint check idempotency

eneros.toml [quality].proptest_cases = 256 configures the number of cases per property.

7. Protocol Conformance Testing (v0.51.0+)

tests/protocol_conformance/ provides 275 tests across 7 protocols; see the Protocol Support page.

Performance Benchmarks

The benches/ directory uses criterion:

cargo bench --workspace

benches/baseline.json stores the performance baseline; PRs must not cause critical-path regressions greater than 5%.

Quality Gates

Gate Command On failure
Formatting cargo fmt --all -- --check Blocks
Lint cargo clippy --workspace --all-targets -- -D warnings Blocks
Build cargo build --workspace Blocks
Test cargo test --workspace Blocks
Docs cargo doc --workspace --no-deps Warning
Dependencies cargo deny check Blocks
Coverage llvm-cov Threshold check

Known Limitations (v0.51.2)

  • Fuzz 60s smoke and 24h long runs pending Linux/WSL2 environment verification
  • proptest covers only 5 crates; expansion to all L0/L1 crates pending
  • 67 unwrap/expect remaining in non-test code (88 removed in v0.51.0)
  • WCET tests require --test-threads=1 (to avoid noise)
  • test_wcet_over_budget_under_2x_audit_sink_records is a known flaky test (timing-based)

Related Documentation

Clone this wiki locally