velxio/test/backend/unit
David Montero Crespo 5b277e85e4 fix(esp32): the emulated chip keeps its radio, whatever the scan thinks (#260)
`WiFi.begin()` panicked the guest: `Guru Meditation Error: Core 0 panic'ed
(LoadStorePIFAddrError)`, EXCVADDR 0x60033c00. Reported against a self-hosted
dev setup, and it did not reproduce on velxio.dev — which routes every
supported ESP32 kind to the in-browser engines. The engines are not in this
repo, so anyone self-hosting from it always runs QEMU, which is where the crash
lives. It was verified away on a path the reporter cannot take.

0x60033c00 is the WiFi MAC at its APB alias, and the fork only instantiates
that device when a NIC is attached (`qemu_find_nic_info(TYPE_ESP32_WIFI)` in
hw/xtensa/esp32.c). The worker attached one only when `wifi_enabled` was true,
so a regex over the user's source decided whether the machine had a radio at
all. Reproduced against the real worker: same sketch, same firmware, only the
flag differs — true connects on 192.168.4.x, false panics exactly as reported.

Two things were wrong, and the second is why the first was fatal.

The scan was too narrow. Arduino mode read only the entry sketch while pure-IDF
mode read every file, so `#include <WiFi.h>` in a project header was judged
WiFi-less. Verified against the live backend: main sketch -> has_wifi=true, the
same include one file away -> false. Both branches read the whole project now.
The frontend also trusted a false over its own all-files scan; the two signals
are OR'd, because a stale or narrower false is the direction that hurts.

But no scan should have been load-bearing. A real ESP32 has a radio whether or
not the sketch uses it, so the emulated one does too: the NIC is attached
unconditionally on machines that model a MAC. A misread sketch now fails to
connect instead of faulting. Only those machines — the S3 machine models no
radio (hw/xtensa/esp32s3.c never looks for the NIC), so handing it one would
leave an unconsumed netdev. `wifi_enabled` still gates the host forward, which
exposes the guest's server and does belong to the sketch.

Measured before making it unconditional, on a sketch that never touches WiFi:
boot time, guest-clock-vs-real-time and container CPU unchanged over 4 paired
runs. The AP's beacon timer runs on QEMU_CLOCK_REALTIME — the reason -icount is
off for Xtensa, b0fe5b5d — but idle beacons cost nothing measurable. One host,
Linux x86-64, one sim at a time; small effects would not show.

With the radio always present, the MicroPython `network` stub loses its reason
to exist on this path: it was there because `WLAN(STA_IF)` hangs forever with no
NIC behind it. Keeping the old condition would put the stub in front of a
working device whenever the scan misread the sketch — #262, from the other
direction. It now depends only on whether the backend models a radio.

And when this class of fault does happen, the dump says "memory" and nothing
else; a week went into #260 for that reason. LoadStorePIFAddrError is always an
unmapped peripheral, so the worker now says so in the serial monitor, naming
the WiFi MAC when the address is in its page.

test_esp32_wifi_args re-implemented the arg logic in its own `_simulate_args`,
so it would have passed unchanged through this entire bug — the same trap
1800f572 called out for the detector. The decision is now `wifi_nic_arg()` and
the test calls it.

Verified end to end against the QEMU worker: the multi-file WiFi project
compiles with has_wifi=true and connects, and a WiFi-less sketch still boots and
runs with the radio attached.
2026-08-21 22:05:10 +02:00
..
__init__.py
…
test_arduino_cli_attinycore.py
…
test_arduino_cli_error_messages.py fix(arduino-cli): library search/install failures become one actionable sentence 2026-08-18 00:28:07 +02:00
test_boot_images.py fix(pi3): show kernel boot + autologin SD + sidecar cache invalidation 2026-05-16 06:23:22 +02:00
test_compile_build_lock.py test(compile): the build-lock test still asserted the pre-82f25a03 contract 2026-08-20 07:49:09 +02:00
test_compile_dedup.py
…
test_dht22_worker.py test(dht22): skip absolute-timing busy_wait checks under CI 2026-05-17 22:31:37 +02:00
test_esp32_wifi_args.py fix(esp32): the emulated chip keeps its radio, whatever the scan thinks (#260) 2026-08-21 22:05:10 +02:00
test_esp32_wifi_webserver.py
…
test_esp32c3_wifi_args.py
…
test_espidf_compiler.py fix(espidf): one include root per library — kill the header-shadow class 2026-08-20 00:15:51 +02:00
test_espidf_core_first.py espidf: never resolve generic platform headers against user libraries 2026-08-04 05:23:42 +02:00
test_espidf_include_roots.py fix(espidf): one include root per library — kill the header-shadow class 2026-08-20 00:15:51 +02:00
test_espidf_include_scanner.py fix(espidf): unknown #if must not prune its #else in the include scanner 2026-08-15 04:14:00 +02:00
test_espidf_library_ranking.py feat(libraries): manifest auto-migration + name-affinity ranking + install-declares 2026-08-04 06:03:32 +02:00
test_espidf_pure_mode.py merge: master (produccion) dentro de v3.2 2026-07-25 21:52:00 +02:00
test_espidf_real_paths.py
…
test_i2c_slaves.py
…
test_mcp_tools.py
…
test_micropython_libs.py feat(micropython): install libraries from the micropython-lib index (#214) 2026-08-18 21:50:10 +02:00
test_signal_router.py fix(esp32): LEDC signal IDs are 71-86 per ESP32 TRM, not 72-87 2026-05-17 05:42:52 +02:00
test_wifi_detection_scope.py fix(esp32): the emulated chip keeps its radio, whatever the scan thinks (#260) 2026-08-21 22:05:10 +02:00
test_wifi_status_parser.py
…