Skip to content
hw.dev
hw.dev/signal/esp32-testing-library-deep-sleep-timing-2026
SignalESP32 Testing Library

An ESP32 Test Harness Measures Sleep From the Chip, Not the Last Log Line

ESP32 Testing Library turns deep sleep into a timestamped hardware event instead of inferring it from serial output.

Thesis connection

Firmware tests become precise when the harness observes the chip state that matters instead of using a nearby log message.

#embedded#testing#verification#tools
Read Original

Tests on Espressif's 32-bit microcontroller (ESP32) recorded the chip waking up but had no event for deep-sleep entry. The harness inferred the start from the firmware's last serial message, which could occur an unknown time before sleep, then allowed an error of a second or more. That made a two-second sleep test too loose to catch the timing bugs it claimed to cover.

ESP32 Testing Library now watches the simulated chip's power and processor state at each one-millisecond slice. When both cores are waiting and the power-down controls are set, it records a sleep event with earliest and latest timestamps plus the enabled wake sources. A timer-wake test now checks a requested two-second interval within two milliseconds short and one millisecond long, including the chip's documented 400-microsecond entry overhead.

The feature currently covers only the classic ESP32 simulator; other chips and physical boards remain outside its evidence. The next convincing step is to capture the same sleep boundary from current measurement on real hardware and compare it with the simulator's timestamp. Until then, this patch makes simulated timing honest without pretending it proves board behavior.