diff options
author | Phil Burk <philburk@google.com> | 2020-04-02 15:06:45 -0700 |
---|---|---|
committer | Phil Burk <philburk@google.com> | 2020-05-04 23:54:25 +0000 |
commit | f765984c694767b86bb26137ef08f90156ccedbb (patch) | |
tree | 22705e96ca2dfcac819147da152f0a5e32f86fb7 /media/packages | |
parent | 9ddbdbf2b58a56aa57d40c881fae06a8872b42fb (diff) |
Bluetooth MIDI test: flush packets
The simulation of the device timing was not very accurate.
That caused two encoder tests to fail:
testTwoNoteOnsTwoChannels and testTwoNoteOnsSameChannel.
This patch simulates a delayed completion
and is more accurate.
Bug: 35669198
Test: atest BluetoothMidiTests
Change-Id: I8d04900a792ffc29928ed0e358536f8d961bcb77
Diffstat (limited to 'media/packages')
-rw-r--r-- | media/packages/BluetoothMidiService/tests/unit/src/com/android/bluetoothmidiservice/BluetoothMidiEncoderTest.java | 29 |
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); } |