From b60c9afee53ea067c3f0247b09fdd17681f8adbf Mon Sep 17 00:00:00 2001 From: JongChern Date: Fri, 23 Oct 2026 21:25:36 +0800 Subject: [PATCH] DEV-1306 Android HIL: samplingRates, configuring straight after a stop 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 --- .../hiltest/HilScenariosTest.java | 75 +++++++++++++++++++ tools/hil/README.md | 1 + tools/hil/run-android-hil.ps1 | 4 +- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/ShimmerAndroidInstrumentDriver/shimmerHilTest/src/androidTest/java/com/shimmerresearch/hiltest/HilScenariosTest.java b/ShimmerAndroidInstrumentDriver/shimmerHilTest/src/androidTest/java/com/shimmerresearch/hiltest/HilScenariosTest.java index 9ccb679..24bf703 100644 --- a/ShimmerAndroidInstrumentDriver/shimmerHilTest/src/androidTest/java/com/shimmerresearch/hiltest/HilScenariosTest.java +++ b/ShimmerAndroidInstrumentDriver/shimmerHilTest/src/androidTest/java/com/shimmerresearch/hiltest/HilScenariosTest.java @@ -606,6 +606,81 @@ private static double[] toArray(List values) { return out; } + /** The rates samplingRates writes in turn, as the Java and shimmer-logandstream HILs' scenarios of the same name do */ + private static final double[] SAMPLING_RATES_HZ = {51.2, 256, 512}; + + /** + * Writes each rate in SAMPLING_RATES_HZ in turn, the way the examples configure, and streams 5 s + * at each; then writes the unit's own rate back. Every configure but the first comes straight + * after a stopStreaming(), as an app that changes the rate does. Up to driver 0.11.10_beta the + * stop's reply then retired the configuration's first chunk, the one holding the sampling rate, + * and the unit kept its old rate (DEV-1306). No SD card is needed. + */ + @Test + public void samplingRates() throws Exception { + begin("sampling_rates"); + double maxLoss = arg("maxLossPercent", 1.0); + long start = System.currentTimeMillis(); + boolean connected = session.connect(30000); + report.put("connectMs", System.currentTimeMillis() - start); + report.check(connected, "did not connect and initialise within 30 s (state " + session.state() + ")"); + ShimmerBluetooth d = connected ? session.device() : null; + if (d != null) { + report.put("hardware", d.getHardwareVersionParsed()); + report.put("firmware", d.getFirmwareVersionParsed()); + report.put("crcMode", String.valueOf(d.getCurrentBtCommsCrcMode())); + double ownRate = d.getSamplingRateShimmer(); + report.put("ownRateHz", ownRate); + List streams = new ArrayList<>(); + for (double rate : SAMPLING_RATES_HZ) { + if (session.hung != null) { + break; + } + String what = String.format(Locale.ROOT, "%.1f Hz", rate); + if (!configureRate(rate, what)) { + continue; + } + double deviceRate = session.rateOnDevice(); + String marker = session.logMarker("sampling_rates " + what); + session.startRecording(); + report.check(session.startStreaming(10000), what + ": streaming did not start within 10 s"); + Thread.sleep(5000); + double stoppedAtMs = session.nowMs(); + List samples = session.stopRecording(); + report.check(session.stopStreaming(10000), what + ": streaming did not stop within 10 s"); + StreamAnalysis a = StreamAnalysis.analyse(samples, deviceRate); + session.event(what + " stream: " + a); + streams.add(what + ": " + a); + checkStream(a, samples, stoppedAtMs, maxLoss, deviceRate, what); + int parserErrors = session.parserErrorsSince(marker); + report.check(parserErrors == 0, what + ": " + parserErrors + " streaming parser errors logged"); + } + report.put("streams", new org.json.JSONArray(streams)); + if (session.hung == null) { + configureRate(ownRate, "the unit's own rate"); + } + report.put("rateOnDeviceHz", session.rateOnDevice()); + report.check(session.disconnect(10000), "did not disconnect within 10 s"); + } + finish(); + } + + /** + * Writes rateHz and checks the unit took it. The configure ends by reading the configuration + * back, so the API's rate is then the unit's. configureAccelOnly can finish on the manager's + * SUCCESS alone, without looking at the rate, so the rate is checked here. + */ + private boolean configureRate(double rateHz, String what) throws InterruptedException { + boolean configured = session.configureAccelOnly(rateHz, 20000); + double onDevice = session.rateOnDevice(); + report.check(configured, String.format(Locale.ROOT, "%s: the configuration did not complete within 20 s (rate on device %.2f Hz, state %s)", + what, onDevice, session.state())); + boolean took = Math.abs(onDevice - rateHz) < 0.5; + report.check(!configured || took, String.format(Locale.ROOT, + "%s: the unit kept %.2f Hz after %.2f Hz was written (straight after a stop, that is DEV-1306)", what, onDevice, rateHz)); + return configured && took; + } + /** queueStress: the app threads, the most instructions they keep queued, and how long a stuck call or queue takes to count as one */ private static final int QUEUE_STRESS_THREADS = 4; private static final int QUEUE_STRESS_MAX_QUEUED = 8; diff --git a/tools/hil/README.md b/tools/hil/README.md index 10ab087..5db379f 100644 --- a/tools/hil/README.md +++ b/tools/hil/README.md @@ -58,6 +58,7 @@ To find regressions before release day, schedule step 2 nightly with Windows Tas | `inStream` | While streaming, three times: starts SD logging, stops it, and reads the battery and the status every 40 ms for 400 ms, so some reads land in the ~100 ms the unit pauses its data packets while it closes its file (DEV-1291). Then, three times, stops and starts logging back to back, so the queued start goes out in that pause. | A battery read isn't answered, or fewer status replies than reads are decoded; logging doesn't stop or restart, or a command stays queued; a command times out; there's a parser error; more than `-MaxLossPercent` of packets are lost away from the SD transitions and the reads; or the timestamps fail the same rate and silence checks as `streamRest`. Loss near the reads is reported, not failed: a Shimmer3 now and then skips a sample around a battery read itself. The report's `repliesInAPause` counts the replies that came with no data packet before them. Needs an SD card in the unit. | | `connectReady` | Connects to the unit idle, starts SD logging, disconnects and connects again while it logs, then stops logging. | 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 marks the end of the connect sequence (DEV-1275); or the connect doesn't end in CONNECTED, or SDLOGGING while logging. Needs an SD card in the unit. | | `queueStress` | Connected and idle, with the API's timers on as in an app: four threads queue battery and status reads in tight loops for 60 s, keeping the queue under 8. Each queued read takes the device's lock and then the queue's while the IO thread fetches the next instruction, the window DEV-1266's lock-order deadlock needs. Idle, because while streaming Android writes these reads straight out, unqueued. | A read doesn't return within 10 s, or no read returns for 10 s (the report then holds every thread's stack); a read throws; or the queue doesn't drain within 15 s after the reads stop. No SD card needed. On driver 0.11.7_beta, which has the deadlock, this is the scenario to reproduce it. | +| `samplingRates` | Writes 51.2, 256 and 512 Hz in turn, the way the examples configure, and streams 5 s at each; then writes the unit's own rate back. Every configure but the first comes straight after a `stopStreaming()`, as an app that changes the rate does: up to driver 0.11.10_beta the stop's reply then retired the configuration's first chunk, the one holding the sampling rate (DEV-1306). | A configuration doesn't complete within 20 s, or the rate read back from the unit isn't the one written; or a stream fails `streamRest`'s loss, timestamp, rate and silence checks, or logs a parser error. No SD card needed. | `-Scenario resetUnit` is not a check and is not part of a default run: it connects, stops SD logging if a run left the unit logging, and disconnects. diff --git a/tools/hil/run-android-hil.ps1 b/tools/hil/run-android-hil.ps1 index b588e70..3aab2cb 100644 --- a/tools/hil/run-android-hil.ps1 +++ b/tools/hil/run-android-hil.ps1 @@ -26,8 +26,8 @@ Before "Release Android API": the full run on this commit, recorded on GitHub as #> param( [string]$Rig = (Join-Path $PSScriptRoot 'rig-android.json'), - [ValidateSet('streamRest', 'midStreamSet', 'reconnectLoop', 'inStream', 'connectReady', 'queueStress', 'resetUnit')] - [string[]]$Scenario = @('streamRest', 'midStreamSet', 'reconnectLoop', 'inStream', 'connectReady', 'queueStress'), + [ValidateSet('streamRest', 'midStreamSet', 'reconnectLoop', 'inStream', 'connectReady', 'queueStress', 'samplingRates', 'resetUnit')] + [string[]]$Scenario = @('streamRest', 'midStreamSet', 'reconnectLoop', 'inStream', 'connectReady', 'queueStress', 'samplingRates'), [string[]]$Unit, [ValidateSet('classic', 'ble')] [string[]]$Transport,