Simulator and Testing
Overview
Section titled “Overview”The PC simulator (make simulator, binary build_sim/picodeck_simulator) runs the firmware’s Lua bridge and launcher on your computer with an SDL2 window in place of the LCD, so you can run and debug apps without a device. See simulator/README.md for building and running it.
- Lua apps run on the same bridge as the device.
- Native (ELF) apps run under the Unicorn CPU emulator, against the same
PicoCalcAPItable as on the device. They are much slower than on the RP2350’s real cores, so judge performance on hardware. - Game controllers plugged into the computer drive
picocalc.gamepad; the keyboard drives everything else. - Differences from the device that matter to app code:
picocalc.cryptois absent, networking uses the host’s network, Bluetooth is a scripted radio, there is far more memory (--real-ummuses the firmware’s heap allocator for realistic fragmentation), and the display post-effects (effectInverttoeffectPosterize) do nothing in native apps.simulator/CLAUDE.mdhas the complete list. - In the browser, picodeck.net/try runs the same sources compiled to WebAssembly (built by PicoDeck/web-sim). It runs Lua apps and native apps compiled into the page, but has no networking and cannot run ELF apps.
Simulator control protocol (TCP 127.0.0.1, or the ./picodeck_control UNIX socket)
Section titled “Simulator control protocol (TCP 127.0.0.1, or the ./picodeck_control UNIX socket)”launch_app→{queued, busy, launch_id};app.exitednotifications carry{name, id, found, result: returned|error|exit_sentinel|load_failed, error, runtime_ms, launch_id};get_last_outcomereturns the last one.get_log_buffer {since_seq, tail}→{lines:[{seq,t_ms,src,text}], next_seq, dropped, more};subscribe {"logs":true}pusheslognotifications.inject_*returninput_seq;get_input_statereportsconsumed_seq.dev_command {"cmd": "..."}runsping/exit/unzip/rm/mv/list [all]/pad/btthrough the firmware’s handlers.- Bluetooth controllers are a scripted radio in the simulator:
bt sim add <addr> <class hex> <name>puts a device in pairing mode in range (bt sim clearempties it),bt sim press <buttons|none>sends the connected pad’s state,bt sim dropdrops its link andbt sim wake <addr>makes a paired pad reconnect. The Bluetooth page, the setting and the pairing file are the firmware’s. step_time {ms}andset_time_multiplierdrive the virtual clock.- Flags:
--test-mode(error screens return at once; constantmath.randomseed and string hash seed; clock pinned to 2026-01-01),--virtual-time,--unix-socket PATH|none,--real-umm(firmware allocator; real fragmentation),--build-info,--gamepad/--no-gamepad. - A game controller plugged into the computer drives
picocalc.gamepad(D-pad or left stick, A/B/X/Y, shoulders = L/R, Start, Back = Select, Guide opens or closes the system menu), with hotplug. It is read unless--no-gamepad, and not under--test-modeunless--gamepadis given, so tests never see the host’s controller. The browser demo (picodeck.net/try) reads controllers too, once the browser has seen one of their buttons pressed.
Running the tests
Section titled “Running the tests”SDL_VIDEODRIVER=dummy pytest tests/e2e -n auto(release simulator).- Sanitizers:
make simulator-asan/simulator-tsan, thenPICODECK_SIM_BINARY=build_sim_asan/picodeck_simulator pytest tests/e2e -n auto. - Firmware network stack in the simulator:
make simulator-net,PICODECK_SIM_BINARY=build_sim_net/picodeck_simulator pytest tests/e2e/test_network_firmware.py. - On a real device:
pytest tests/e2e --target hw:/dev/serial/by-id/<PicoDeck device>runs thehardware/bothtests. - Host unit tests:
make test-unit; fuzzers:make fuzz.
Dev commands (USB serial)
Section titled “Dev commands (USB serial)”stackprintsmsp_peak,core1_peak, the running app’s stack peak andos_cmd_peak(the last launcher command’s peak on its 32 KB PSRAM stack).exitwith no app running repliesError: exit: no app running.listprints the apps the launcher shows;list alladds the hidden ones (aHidden apps:section tagged[.test]or[.dev], before theTotal: N apps, M hiddenline). Apps under/apps/.testand/apps/.devare not shown by the launcher and do not count towards its 64-app limit, butlaunch <dir name or id>still starts them (a listed app of the same name wins;.testbefore.dev).launch .test/<name>andlaunch .dev/<name>look only in that root, so nothing listed can run in their place; the whole argument is at most 69 characters, and a longer one is refused. The MCPpush_app(..., hidden="test"|"dev")stages there andlaunch_app(..., hidden="test"|"dev")uses the root form.mv <src> <dst>moves or renames a file or directory on the card, across directories (mv /apps/old_probe /apps/.dev/old_probe). It creates missing parent directories of the target and refuses: an existing target, anything at or under/system(either side), the top-level directories (/,/apps,/data,/system), a directory moved into itself, and the running app’s directory. Paths are canonicalised (\and//, no./..or names ending in.or a space), and the checks compare directories by their identity on the card, not by spelling; if that cannot be checked (the card’s 16 open files are all in use) the move is refused with “cannot verify the move”.pad <buttons|none|off> [hold_ms]drives a test gamepad, as a connected controller would:pad up+aholds Up and A until the nextpadcommand,pad a 100holds A for 100 ms,pad nonereleases everything,pad offdisconnects it, andhomeopens the system menu (and closes it again when it is open:pad home 100). Buttons:up down left right a b x y l r start select home, joined by+. RepliesPad: up+a. The MCPpadtool sends it (pad("home, up, a")presses each in turn).btreports Bluetooth (available,enabled,power,scanning,link,peer,ready,profile,reports,paired,found,radio_in_use,bus_errors, thennote="...");bt on|off,bt scan,bt scan stop,bt found,bt paired,bt connect <addr>,bt disconnectandbt forget <addr>do what the Bluetooth page does.- While an app runs:
rebootandreboot-flashact at once (no teardown);reboot-ota(apply a staged, signed update) is dropped;usbwaits for the launcher. Exit to the launcher before flashing.