diff --git a/ShimmerDriverPC/src/test/java/com/shimmerresearch/hil/HilSession.java b/ShimmerDriverPC/src/test/java/com/shimmerresearch/hil/HilSession.java index b9a9b896b..3fc9c48a9 100644 --- a/ShimmerDriverPC/src/test/java/com/shimmerresearch/hil/HilSession.java +++ b/ShimmerDriverPC/src/test/java/com/shimmerresearch/hil/HilSession.java @@ -67,6 +67,17 @@ interface Condition { volatile String connectFailure; /** jssc's message when Windows refuses to open a COM port that another program already has open. */ private static final Pattern PORT_BUSY = Pattern.compile("Port busy"); + /** + * Per connect: whether the driver has sent NOTIFICATION_SHIMMER_FULLY_INITIALIZED (the end of + * its connect sequence), and whether the first CONNECTED state is still to come. + */ + private volatile boolean fullyInitialisedSinceConnect; + private volatile boolean awaitingFirstConnected; + /** + * Connects whose first CONNECTED came before the end of the connect sequence: the app was told + * the unit was ready while the sequence was still queued (DEV-1275). + */ + volatile int connectedBeforeReady; HilSession(String port, String mac, String type) { this.port = port; @@ -102,7 +113,18 @@ protected void processMsgFromCallback(ShimmerMsg msg) { lastState = state; stateChanges++; event("state " + state); + if (state == BT_STATE.CONNECTED && awaitingFirstConnected) { + awaitingFirstConnected = false; + if (!fullyInitialisedSinceConnect) { + connectedBeforeReady++; + event("CONNECTED reported before the connect sequence ended (no FULLY_INITIALIZED yet; DEV-1275)"); + } + } } + } else if (msg.mIdentifier == HilShimmerPC.MSG_IDENTIFIER_NOTIFICATION_MESSAGE && msg.mB instanceof CallbackObject + && ((CallbackObject) msg.mB).mIndicator == HilShimmerPC.NOTIFICATION_SHIMMER_FULLY_INITIALIZED) { + fullyInitialisedSinceConnect = true; + event("fully initialised"); } else if (msg.mIdentifier == HilShimmerPC.MSG_IDENTIFIER_DATA_PACKET && msg.mB instanceof ObjectCluster) { if (recording) { recordPacket((ObjectCluster) msg.mB); @@ -186,6 +208,8 @@ boolean call(String what, long timeoutMs, Call call) { boolean connect(long timeoutMs) throws InterruptedException { connects++; connectFailure = null; + fullyInitialisedSinceConnect = false; + awaitingFirstConnected = true; int mark = stateChanges; int logMark = device.logSize(); Condition failed = () -> stateChanges > mark && device.getBluetoothRadioState() == BT_STATE.CONNECTION_FAILED; diff --git a/ShimmerDriverPC/src/test/java/com/shimmerresearch/hil/JavaHilScenariosTest.java b/ShimmerDriverPC/src/test/java/com/shimmerresearch/hil/JavaHilScenariosTest.java index 21c08539b..b075df706 100644 --- a/ShimmerDriverPC/src/test/java/com/shimmerresearch/hil/JavaHilScenariosTest.java +++ b/ShimmerDriverPC/src/test/java/com/shimmerresearch/hil/JavaHilScenariosTest.java @@ -104,6 +104,8 @@ public void end() { } private void finish() { + report.check(session.connectedBeforeReady == 0, session.connectedBeforeReady + " of " + session.connects + + " connects reported CONNECTED before the connect sequence ended (DEV-1275)"); if (session.hung != null) { report.put("hungCall", session.hung); report.check(false, session.hung + " never returned: the API call blocked (thread dump in the report's events)"); @@ -116,6 +118,7 @@ private void finish() { /** What the driver did in this session: replies by type, decodes, timer requests, connects. */ private void putDriverCounts() { report.put("connects", session.connects); + report.put("connectedBeforeReady", session.connectedBeforeReady); report.put("inStreamReplies", device.inStreamReplies()); report.put("statusesDecoded", device.statusesDecoded()); report.put("batteryReadings", device.batteryReadings()); diff --git a/tools/hil/README.md b/tools/hil/README.md index 5edd52517..0cacbd5c9 100644 --- a/tools/hil/README.md +++ b/tools/hil/README.md @@ -56,6 +56,8 @@ A connect is never retried. If the COM port can't be opened, the scenario fails - **CONNECTION_FAILED** for any other reason: the unit is off, out of range, or connected to another host such as a phone. +Every connect, in every scenario, is also checked for DEV-1275: the first CONNECTED must come only after the driver's NOTIFICATION_SHIMMER_FULLY_INITIALIZED, which marks the end of its connect sequence. `connectedBeforeReady` counts the connects that broke this, and any one fails the scenario. + Each report counts what the session covered: connects, in-stream replies by type, statuses and battery readings decoded, the status timer's requests, and command timeouts. Its events also say which driver timers were running after connect, after configure and while streaming.