Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class API_0000X_ByteCommunicationShimmer3 extends BasicProcessWithCallBac
@Before
public void setUp() {
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class API_0000X_ByteCommunicationShimmer3R extends BasicProcessWithCallBa
@Before
public void setUp() {
mByteCommunicationSimulatorS3R = new ByteCommunicationSimulatorS3R("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3R);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class API_0000X_ByteCommunicationShimmer3_CRC_Streaming extends BasicProc
@Before
public void setUp() {
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_instream_crc("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class API_0000X_ByteCommunicationShimmer3_Streaming extends BasicProcessW
@Before
public void setUp() {
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class API_0000X_ByteCommunicationShimmer3_Streaming_Contiguous_Check exte
@Before
public void setUp() {
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_timestamp_contiguous_check("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class API_0000X_ByteCommunicationShimmer3_Streaming_Contiguous_Check_Fail
@Before
public void setUp() {
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_timestamp_contiguous_check_fail("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class API_0000X_ByteCommunicationShimmer3_Streaming_Contiguous_Check_Over
@Before
public void setUp() {
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_timestamp_contiguous_check_overflow("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class API_0000X_ByteCommunicationShimmer3_Streaming_Throw_Bytes extends B
@Before
public void setUp() {
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_with_improved_throw_bytes("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class API_0000X_ByteCommunicationShimmer3_Streaming_Throw_Bytes_2 extends
@Before
public void setUp() {
mByteCommunicationSimulatorS3 = new ByteCommunicationSimulatorS3_streaming_with_improved_throw_bytes_2("COM99");
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(mByteCommunicationSimulatorS3);
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class API_0000X_ByteCommunicationShimmer3lns0_16_11 extends BasicProcessW
ShimmerPC mDevice;
@Before
public void setUp() {
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(new ByteCommunicationSimulatorS3LNS0_16_11("COM99"));
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class API_0000X_ByteCommunicationShimmer3lns0_16_11_w_sd_bt_streaming ext
ShimmerPC mDevice;
@Before
public void setUp() {
mDevice = new ShimmerPC("COM99");
mDevice = ByteCommunicationTestUtils.newShimmerPCWithoutStatusTimer("COM99");
mDevice.setTestRadio(new ByteCommunicationSimulatorS3LNS0_16_11_w_sd_bt_streaming("COM99"));
setWaitForData(mDevice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import static org.junit.Assert.fail;

import java.lang.management.LockInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.MonitorInfo;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

import com.shimmerresearch.bluetooth.ShimmerBluetooth.BT_STATE;
import com.shimmerresearch.pcDriver.ShimmerPC;

Expand All @@ -12,6 +18,26 @@ public class ByteCommunicationTestUtils {
* but a loaded CI runner can stall it for several. Only a genuine hang should hit this. */
public static final long CONNECT_TIMEOUT_MS = 30000;

/**
* A ShimmerPC for the simulator tests whose periodic read-status timer never starts.
* <p>
* The connect sequence unlocks the instruction stack and then starts that timer with no delay,
* so its first readStatusTask (which locks the device, then the instruction list) runs just as
* the IOThread takes the first post-connect instruction in ShimmerBluetooth.getInstruction()
* (which locks the list, then the device). When the two meet they deadlock and the connect never
* finishes. That hung these tests on Linux CI every time (DEV-1198). The driver is deliberately
* left as it is; the tests only lose the 5 s status poll, and the connect sequence still reads
* the status once.
*/
public static ShimmerPC newShimmerPCWithoutStatusTimer(String comPort) {
return new ShimmerPC(comPort) {
@Override
public void startTimerReadStatus() {
// Deliberately empty - see above
}
};
}

/**
* Connects and blocks until the device has finished its post-connect config read (infomem,
* calibration, etc.), i.e. isInitialised() is set and the state has moved to CONNECTED.
Expand All @@ -23,6 +49,9 @@ public static void connectAndWaitUntilInitialised(ShimmerPC device) {
long deadline = System.currentTimeMillis() + CONNECT_TIMEOUT_MS;
while (!(device.isInitialised() && device.getBluetoothRadioState()==BT_STATE.CONNECTED)) {
if (System.currentTimeMillis() > deadline) {
// A hang here has so far only reproduced on CI, so print where every thread is
// before failing - the log is the only evidence there is.
System.out.println(dumpAllThreads());
fail("Device did not finish initialising within " + CONNECT_TIMEOUT_MS + " ms (state: " + device.getBluetoothRadioState() + ")");
}
try {
Expand All @@ -34,4 +63,48 @@ public static void connectAndWaitUntilInitialised(ShimmerPC device) {
}
}

/** Every thread's full stack with the monitors it holds and the lock it waits on, plus any
* deadlock the JVM can see. ThreadInfo.toString() stops at 8 frames, too few for the driver. */
public static String dumpAllThreads() {
ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
StringBuilder sb = new StringBuilder("==== Thread dump ====\n");

long[] deadlocked = mxBean.findDeadlockedThreads();
if (deadlocked != null) {
sb.append("DEADLOCK between thread ids:");
for (long id : deadlocked) {
sb.append(' ').append(id);
}
sb.append('\n');
}

for (ThreadInfo ti : mxBean.dumpAllThreads(true, true)) {
sb.append('"').append(ti.getThreadName()).append("\" id=").append(ti.getThreadId())
.append(' ').append(ti.getThreadState());
if (ti.getLockName() != null) {
sb.append(" on ").append(ti.getLockName());
}
if (ti.getLockOwnerName() != null) {
sb.append(" owned by \"").append(ti.getLockOwnerName()).append("\" id=").append(ti.getLockOwnerId());
}
sb.append('\n');

StackTraceElement[] stack = ti.getStackTrace();
MonitorInfo[] monitors = ti.getLockedMonitors();
for (int i = 0; i < stack.length; i++) {
sb.append("\tat ").append(stack[i]).append('\n');
for (MonitorInfo mi : monitors) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked ").append(mi).append('\n');
}
}
}
for (LockInfo li : ti.getLockedSynchronizers()) {
sb.append("\t- locked synchronizer ").append(li).append('\n');
}
sb.append('\n');
}
return sb.append("==== End of thread dump ====").toString();
}

}
Loading