Skip to content

DEV-1291 DEV-1275: Android HIL inStream and connectReady scenarios - #134

Merged
JongChern merged 8 commits into
DEV-1242_android_hilfrom
DEV-1291_android_hil_scenarios
Oct 23, 2026
Merged

JongChern merged 8 commits into
DEV-1242_android_hilfrom
DEV-1291_android_hil_scenarios

Conversation

@JongChern

Copy link
Copy Markdown
Contributor

Two Android HIL scenarios for the DEV-1291 and DEV-1275 ports, plus HIL fixes they needed. Stacked on #128 (the Android HIL); merge #128 first.

New scenarios

  • inStream (DEV-1291): while streaming, start SD logging, stop it, and read the battery and the status every 40 ms for 400 ms. Android writes those reads straight out, so some land in the ~100 ms the unit pauses its data packets while it closes its SD file. Then stop and start logging back to back, so the queued start goes out in the pause. It fails when a battery read goes unanswered, fewer status replies than reads are decoded, logging doesn't stop or restart, a command times out, or there's a parser error. Loss near the reads is reported, not failed: a Shimmer3 skips a sample there now and then on its own (DEV-1297).
  • connectReady (DEV-1275): connect to the unit idle, then again while it logs. It fails when the unit is reported ready (a CONNECTED or SDLOGGING state, in a message or the API) more than 250 ms before NOTIFICATION_SHIMMER_FULLY_INITIALIZED. The HIL's own connect waits for isInitialised(), so the existing scenarios never saw the early report.
  • resetUnit, manual only: stops logging on a unit a failed run left logging.

The runner runs inStream and connectReady by default, and the README lists them.

HIL fixes

  • Never leave a unit logging: if connectReady's connect to a logging unit fails, the HIL connects again to stop logging. Before, every later run failed to connect to it as idle.
  • A connect that doesn't finish now dumps every thread, as a hung call does, so a stalled connect sequence (such as the DEV-1266 deadlock) shows where it stopped.
  • The instruction queue is read without the device's lock, which had widened DEV-1266's window.
  • inStream places a log marker per round and counts right after it. The phone's log buffer, with the Bluetooth snoop log on, rolled past a single start marker within a run and made 15 decoded replies read as 0. If a marker is gone anyway it fails saying so, rather than counting none.
  • A timestamp jump within 3 s of an SD logging start or stop is reported, not failed, as loss there already is: captured bytes show a Shimmer3 sending two held packets after a 1.5 s file-open pause, then the next one 385 periods on.

Tested

On a Shimmer3 (3E36, Classic, from a phone): both scenarios fail on a build without the ports and pass with them. Results are in the DEV-1275 and DEV-1291 port PRs.

🤖 Generated with Claude Code

JongChern and others added 5 commits October 22, 2026 13:55
inStream (DEV-1291): while streaming, start SD logging, stop it, and read the
battery and the status every 40 ms for 400 ms. Android writes those reads
straight out, so some land in the ~100 ms the unit pauses its data packets
while it closes its SD file, and their replies come with no data packet
before them. Then stop and start logging back to back, so the queued start
goes out in the pause. It fails when:
- a battery read goes unanswered, or fewer status replies than reads are decoded;
- logging doesn't stop or restart;
- a command times out;
- there's a parser error.
Loss near the reads is reported, not failed: a Shimmer3 skips a sample there
now and then on its own.

connectReady (DEV-1275): connect to the unit idle, then again while it logs.
It fails when the unit is reported ready (a CONNECTED or SDLOGGING state
message, or that state in the API) more than 250 ms before
NOTIFICATION_SHIMMER_FULLY_INITIALIZED, which ends the connect sequence. The
HIL's own connect waits for isInitialised(), which on Classic comes only at
the end, so the existing scenarios never saw the early report.

The runner runs both by default, and the README lists them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s lock

The IO thread takes the queue's lock and then the device's (DEV-1198). Polling
the queue through the synchronized getListofInstructions() made the IO thread
wait on the device's lock while it held the queue's, which widened that
deadlock's window. Read the field directly instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stalled connect

connectReady's second connect, to the unit while it logs, can fail. The unit
was then left logging, and every later run failed to connect to it as idle.
It now connects again to stop logging, and resetUnit does the same by hand.

A connect that doesn't finish now dumps every thread, as a hung call does.
The connect call itself returns at once, so nothing showed a stalled connect
sequence, such as the DEV-1198 lock-order deadlock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at an SD start are the unit's

The phone's log buffer is small, and with the Bluetooth snoop log on it rolled
past inStream's start marker within a run. Every count then read 0, so 15
decoded battery replies were reported as none. inStream now places a marker
per round and counts right after it. If a marker is gone anyway, it fails
saying the lines could not be counted, rather than counting none.

A timestamp jump within 3 s after an SD logging start or stop is now reported
rather than failed, just as the loss there is. The captured bytes show
a Shimmer3 doing this itself. After a 1.5 s pause while it opened its file, it
sent two packets it had held, and a millisecond later the next one it
sampled, 385 periods on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The driver guards its instruction queue with two locks, the device and the
queue. Up to 0.11.10_beta its IO thread took them queue first when it
fetched the next instruction, and every call that queues one takes them
device first, so the two could deadlock and every later call hung. On
Android it hung 5 of 12 inStream runs on driver 0.11.7_beta, but inStream
needs SD logging and catches it only by chance.

queueStress makes the window wide on purpose, as the Java HIL's scenario of
the same name does. With the unit connected and idle, timers on, four
threads queue battery and status reads in tight loops for 60 s, keeping the
queue under 8. Idle, because while streaming Android writes these reads
straight out, unqueued, and they never take the queue's lock. It needs no
SD card, so it also runs on a docked or charging unit.

It fails when a read doesn't return within 10 s or no read returns for 10 s,
with every thread's stack in the events; when a read throws; or when the
queue doesn't drain within 15 s. The runner runs it by default and the
README lists it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Up to driver 0.11.10_beta, a configuration written straight after
stopStreaming() could lose its first chunk, the one holding the sampling
rate: operationPrepare() cleared the instruction list while the STOP was
still in flight, and the stop's reply then retired the next instruction in
its place. The unit kept its old rate. The Java HIL's samplingRates found it
on a Shimmer3 and a Shimmer3R. Android configures through the same driver
code over both transports, and had no scenario for it.

samplingRates, as in the Java and shimmer-logandstream HILs, writes 51.2, 256
and 512 Hz in turn and streams 5 s at each, then writes the unit's own rate
back; every configure but the first comes straight after a stop. Unlike the
Java HIL's configure, the Android one can finish on the manager's SUCCESS
without looking at the rate, so the scenario checks that the rate read back
is the one written. No SD card is needed. The runner runs it by default and
the README lists it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pling_rates

DEV-1306: Android HIL samplingRates, configuring straight after a stop
…ue_stress

DEV-1266: Android HIL queueStress, to reproduce the lock-order deadlock
@JongChern
JongChern merged commit eb708e3 into DEV-1242_android_hil Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant