velxio/test/backend/e2e
David Montero Crespo 3197935461 feat: add ESP32 + ngspice co-simulation E2E tests
Three new end-to-end tests that combine ESP32 QEMU emulation (via backend
WebSocket) with ngspice-WASM analog circuit solving:

1. test_esp32_spice_analog.mjs — voltage divider sweep
   - Compiles a sketch that reads analogRead(34)
   - Solves two voltage dividers with ngspice (R1/R2=10k/10k then 10k/30k)
   - Injects solved V(mid) into ESP32's ADC via esp32_adc_set
   - Verifies Serial output matches within +-50 counts (12-bit ADC)
   - Confirms circuit change is detected (different ADC values)

2. test_esp32_spice_ntc_bridge.mjs — Wheatstone bridge temperature sweep
   - NTC thermistor in a bridge (0C / 25C / 50C)
   - ngspice solves the bridge for each temperature
   - ESP32 reads both legs (ADC34+ADC35), computes R_ntc and T via beta model
   - Verifies temperature within +-5C tolerance across sweep

3. test_esp32_spice_smoke.mjs — ngspice-only smoke test (no backend needed)

Also adds eecircuit-engine to test/backend/e2e/package.json.

Prerequisites: backend on localhost:8001 with esp32 core installed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 23:28:47 -03:00
..
README.md feat: Enhance CI workflows for backend unit and e2e tests; add environment setup and skip timing-sensitive tests in CI 2026-04-10 23:47:25 -03:00
package-lock.json Add end-to-end test for MicroPython on Raspberry Pi Pico using rp2040js 2026-04-13 10:02:21 -03:00
package.json feat: add ESP32 + ngspice co-simulation E2E tests 2026-04-15 23:28:47 -03:00
rp2040-bootrom.mjs Add end-to-end test for MicroPython on Raspberry Pi Pico using rp2040js 2026-04-13 10:02:21 -03:00
test_dht22_simulation.mjs Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser 2026-04-10 23:39:51 -03:00
test_esp32_spice_analog.mjs feat: add ESP32 + ngspice co-simulation E2E tests 2026-04-15 23:28:47 -03:00
test_esp32_spice_ntc_bridge.mjs feat: add ESP32 + ngspice co-simulation E2E tests 2026-04-15 23:28:47 -03:00
test_esp32_spice_smoke.mjs feat: add ESP32 + ngspice co-simulation E2E tests 2026-04-15 23:28:47 -03:00
test_hcsr04_simulation.mjs Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser 2026-04-10 23:39:51 -03:00
test_micropython_esp32.mjs feat: Update MicroPython firmware handling for ESP32; add end-to-end test and mark subproject commits as dirty 2026-04-12 23:55:11 -03:00
test_micropython_pico.mjs Add end-to-end test for MicroPython on Raspberry Pi Pico using rp2040js 2026-04-13 10:02:21 -03:00
test_mpu6050_simulation.mjs Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser 2026-04-10 23:39:51 -03:00

README.md

Backend E2E Tests (JavaScript / Node.js)

These tests compile real firmware via the backend API and run the full simulation through a WebSocket, verifying sensor readings in the serial output.

CI status

These tests run in GitHub Actions via .github/workflows/backend-e2e-tests.yml.

The CI workflow:

  1. Downloads libqemu-xtensa-amd64.so and libqemu-riscv32-amd64.so from the qemu-prebuilt release.
  2. Downloads ROM files: esp32-v3-rom.bin, esp32-v3-rom-app.bin, esp32c3-rom.bin.
  3. Installs arduino-cli + esp32:esp32 core.
  4. Starts uvicorn app.main:app --port 8001 with QEMU_ESP32_LIB and QEMU_RISCV32_LIB set.
  5. Runs all three JS tests.

Local prerequisites

  1. Backend running with QEMU libs in PATH:

    cd backend
    QEMU_ESP32_LIB=/path/to/libqemu-xtensa.so \
    QEMU_RISCV32_LIB=/path/to/libqemu-riscv32.so \
    uvicorn app.main:app --reload --port 8001
    

    On Windows the .dll files live in backend/app/services/.

  2. Node.js 18+ installed.

Run all e2e tests

Use the convenience script from the repo root:

# Windows
scripts\run-e2e-tests.bat

# Or individually (from repo root):
node test/backend/e2e/test_dht22_simulation.mjs   --timeout=60
node test/backend/e2e/test_hcsr04_simulation.mjs  --timeout=75
node test/backend/e2e/test_mpu6050_simulation.mjs --timeout=60

Tests

File Sensor What it verifies Typical runtime
test_dht22_simulation.mjs DHT22 (GPIO4) Temperature & humidity readings, sensor_update changes values ~50 s
test_hcsr04_simulation.mjs HC-SR04 (GPIO18/19) Distance at 10/40/100/200 cm, sensor_update changes distance ~60 s
test_mpu6050_simulation.mjs MPU-6050 (I2C) Accelerometer/gyroscope I2C readings ~40 s

Pass criteria

Test Passes when
DHT22 First reading received + values change after sensor_update
HC-SR04 ≥3 correct readings, ≥2 distances, miss rate ≤30%
MPU-6050 I2C communication established, sensor data in serial output