summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Burk <philburk@google.com>2020-05-05 06:15:48 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-05 06:15:48 +0000
commit561fa6b0506b1016b9e052bdd7bc65a92003d4f7 (patch)
treef687c78175c5e03258de52b82685e0e56fa92665
parent100a5553d08a921d5081d094725ec26131887b85 (diff)
parent5318f54e77239c6a40c1b9019f01324c047b8bc2 (diff)
Merge "Bluetooth MIDI test: flush packets" into rvc-dev am: 4b2063c9d6 am: 2920bfa09e am: ecad5a0021 am: 5318f54e77
Change-Id: I29863fd40f6f7020f41ae9819a1b2d2f43d3e547
-rw-r--r--media/packages/BluetoothMidiService/tests/unit/src/com/android/bluetoothmidiservice/BluetoothMidiEncoderTest.java29
1 files changed, 18 insertions, 11 deletions
diff --git a/media/packages/BluetoothMidiService/tests/unit/src/com/android/bluetoothmidiservice/BluetoothMidiEncoderTest.java b/media/packages/BluetoothMidiService/tests/unit/src/com/android/bluetoothmidiservice/BluetoothMidiEncoderTest.java
index a169c0d7c7f9..d48b10a81a18 100644
--- a/media/packages/BluetoothMidiService/tests/unit/src/com/android/bluetoothmidiservice/BluetoothMidiEncoderTest.java
+++ b/media/packages/BluetoothMidiService/tests/unit/src/com/android/bluetoothmidiservice/BluetoothMidiEncoderTest.java
@@ -74,10 +74,17 @@ public class BluetoothMidiEncoderTest {
}
void compareWithExpected(final byte[][] expected) {
+ // The data travels through the encoder in another thread
+ // so there is the potential for a race condition.
+ try {
+ Thread.sleep(50);
+ writeComplete(); // flushes any pending data
+ } catch (InterruptedException e) {
+ }
byte[][] actualRows = mReceiver.getBuffers();
- assertEquals(expected.length, actualRows.length);
+ int minRows = Math.min(expected.length, actualRows.length);
// Compare the gathered rows with the expected rows.
- for (int i = 0; i < expected.length; i++) {
+ for (int i = 0; i < minRows; i++) {
byte[] expectedRow = expected[i];
Log.d(TAG, "expectedRow = "
+ MidiFramer.formatMidiData(expectedRow, 0, expectedRow.length));
@@ -89,6 +96,7 @@ public class BluetoothMidiEncoderTest {
assertEquals(expectedRow[k], actualRow[k]);
}
}
+ assertEquals(expected.length, actualRows.length);
}
void writeComplete() {
@@ -115,8 +123,11 @@ public class BluetoothMidiEncoderTest {
(byte) 0x80, // high bit of header must be set
(byte) 0x80, // high bit of timestamp
(byte) 0x90, 0x40, 0x64,
- // encoder converts to running status
- 0x47, 0x72
+ },
+ {
+ (byte) 0x80, // high bit of header must be set
+ (byte) 0x80, // high bit of timestamp
+ (byte) 0x90, 0x47, 0x72
}};
EncoderChecker checker = new EncoderChecker();
checker.send(new byte[] {(byte) 0x90, 0x40, 0x64, (byte) 0x90, 0x47, 0x72});
@@ -129,7 +140,9 @@ public class BluetoothMidiEncoderTest {
(byte) 0x80, // high bit of header must be set
(byte) 0x80, // high bit of timestamp
(byte) 0x93, 0x40, 0x60,
- // two channels so no running status
+ },
+ {
+ (byte) 0x80, // high bit of header must be set
(byte) 0x80, // high bit of timestamp
(byte) 0x95, 0x47, 0x64
}};
@@ -166,9 +179,6 @@ public class BluetoothMidiEncoderTest {
checker.send(new byte[] {(byte) 0x90, 0x40, 0x64}, timestamp);
timestamp += 2 * NANOS_PER_MSEC;
checker.send(new byte[] {(byte) 0x90, 0x47, 0x72}, timestamp);
- // Tell the encoder that the first packet has been written to the
- // hardware. So it can flush the two pending notes.
- checker.writeComplete();
checker.compareWithExpected(encoded);
}
@@ -207,9 +217,6 @@ public class BluetoothMidiEncoderTest {
checker.send(new byte[] {(byte) 0xF0, 0x7D, // experimental SysEx
0x01, 0x02});
checker.send(new byte[] {0x03, 0x04, 0x05, (byte) 0xF7});
- // Tell the encoder that the first packet has been written to the
- // hardware. So it can flush the remaining data.
- checker.writeComplete();
checker.compareWithExpected(encoded);
}