Improve Extractor partial read tests.

Partial reads were performed once using a partial size of 1 byte.
This was not enough to detect problems which only occur in combination
with IOExceptions. Partial reads are now only applied when no exception
is thrown.

Moreover, the tests didn't check whether the total number of sampled bytes
is what it is supposed to be. Added a field to the data dumps checking
the total number of bytes in the sampled data.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181296545
This commit is contained in:
tonihei 2018-01-09 03:34:40 -08:00 committed by Oliver Woodman
parent d427a1dd62
commit 4ee971052b
57 changed files with 109 additions and 25 deletions

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 526272
sample count = 33
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 362432
sample count = 23
sample 0:
time = 853333

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 182208
sample count = 12
sample 0:
time = 1792000

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 18368
sample count = 2
sample 0:
time = 2645333

View File

@ -26,6 +26,7 @@ track 8:
drmInitData = -
initializationData:
data = length 2, hash 5F7
total output bytes = 9529
sample count = 45
sample 0:
time = 112000
@ -231,6 +232,7 @@ track 9:
initializationData:
data = length 30, hash F6F3D010
data = length 10, hash 7A0D0F2B
total output bytes = 89502
sample count = 30
sample 0:
time = 67000

View File

@ -27,6 +27,7 @@ track 1:
initializationData:
data = length 30, hash F6F3D010
data = length 10, hash 7A0D0F2B
total output bytes = 89502
sample count = 30
sample 0:
time = 67000
@ -170,6 +171,7 @@ track 2:
language = und
drmInitData = -
initializationData:
total output bytes = 12120
sample count = 29
sample 0:
time = 129000

View File

@ -27,6 +27,7 @@ track 1:
initializationData:
data = length 30, hash F6F3D010
data = length 10, hash 7A0D0F2B
total output bytes = 30995
sample count = 22
sample 0:
time = 334000
@ -138,6 +139,7 @@ track 2:
language = und
drmInitData = -
initializationData:
total output bytes = 8778
sample count = 21
sample 0:
time = 408000

View File

@ -27,6 +27,7 @@ track 1:
initializationData:
data = length 30, hash F6F3D010
data = length 10, hash 7A0D0F2B
total output bytes = 10158
sample count = 11
sample 0:
time = 700000
@ -94,6 +95,7 @@ track 2:
language = und
drmInitData = -
initializationData:
total output bytes = 4180
sample count = 10
sample 0:
time = 791000

View File

@ -27,6 +27,7 @@ track 1:
initializationData:
data = length 30, hash F6F3D010
data = length 10, hash 7A0D0F2B
total output bytes = 0
sample count = 0
track 2:
format:
@ -50,6 +51,7 @@ track 2:
language = und
drmInitData = -
initializationData:
total output bytes = 1254
sample count = 3
sample 0:
time = 1035000

View File

@ -25,6 +25,7 @@ track 1:
language = null
drmInitData = 1305012705
initializationData:
total output bytes = 39
sample count = 1
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 1:
language = null
drmInitData = 1305012705
initializationData:
total output bytes = 24
sample count = 1
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 44544
sample count = 116
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 29568
sample count = 77
sample 0:
time = 928568

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 14592
sample count = 38
sample 0:
time = 1871586

View File

@ -25,5 +25,6 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 0
sample count = 0
tracksEnded = true

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 418
sample count = 1
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 418
sample count = 1
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 418
sample count = 1
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 418
sample count = 1
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 418
sample count = 1
sample 0:
time = 0

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 29, hash 4746B5D9
data = length 10, hash 7A0D0F2B
total output bytes = 89876
sample count = 30
sample 0:
time = 0
@ -171,6 +172,7 @@ track 1:
drmInitData = -
initializationData:
data = length 2, hash 5F7
total output bytes = 9529
sample count = 45
sample 0:
time = 44000

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 29, hash 4746B5D9
data = length 10, hash 7A0D0F2B
total output bytes = 89876
sample count = 30
sample 0:
time = 0
@ -171,6 +172,7 @@ track 1:
drmInitData = -
initializationData:
data = length 2, hash 5F7
total output bytes = 7464
sample count = 33
sample 0:
time = 322639

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 29, hash 4746B5D9
data = length 10, hash 7A0D0F2B
total output bytes = 89876
sample count = 30
sample 0:
time = 0
@ -171,6 +172,7 @@ track 1:
drmInitData = -
initializationData:
data = length 2, hash 5F7
total output bytes = 4019
sample count = 18
sample 0:
time = 670938

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 29, hash 4746B5D9
data = length 10, hash 7A0D0F2B
total output bytes = 89876
sample count = 30
sample 0:
time = 0
@ -171,6 +172,7 @@ track 1:
drmInitData = -
initializationData:
data = length 2, hash 5F7
total output bytes = 470
sample count = 3
sample 0:
time = 1019238

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 29, hash 4746B5D9
data = length 10, hash 7A0D0F2B
total output bytes = 85933
sample count = 30
sample 0:
time = 66000
@ -171,6 +172,7 @@ track 1:
drmInitData = -
initializationData:
data = length 5, hash 2B7623A
total output bytes = 18257
sample count = 46
sample 0:
time = 0

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 29, hash 4746B5D9
data = length 10, hash 7A0D0F2B
total output bytes = 85933
sample count = 30
sample 0:
time = 66000
@ -171,6 +172,7 @@ track 1:
drmInitData = -
initializationData:
data = length 5, hash 2B7623A
total output bytes = 18257
sample count = 46
sample 0:
time = 0
@ -378,5 +380,6 @@ track 3:
language = null
drmInitData = -
initializationData:
total output bytes = 0
sample count = 0
tracksEnded = true

View File

@ -28,6 +28,7 @@ track 0:
data = length 19, hash BFE794DB
data = length 8, hash CA22068C
data = length 8, hash 79C07075
total output bytes = 25541
sample count = 275
sample 0:
time = 0

View File

@ -28,6 +28,7 @@ track 0:
data = length 19, hash BFE794DB
data = length 8, hash CA22068C
data = length 8, hash 79C07075
total output bytes = 17031
sample count = 184
sample 0:
time = 910000

View File

@ -28,6 +28,7 @@ track 0:
data = length 19, hash BFE794DB
data = length 8, hash CA22068C
data = length 8, hash 79C07075
total output bytes = 8698
sample count = 92
sample 0:
time = 1830000

View File

@ -28,6 +28,7 @@ track 0:
data = length 19, hash BFE794DB
data = length 8, hash CA22068C
data = length 8, hash 79C07075
total output bytes = 126
sample count = 1
sample 0:
time = 2741000

View File

@ -28,6 +28,7 @@ track 0:
data = length 19, hash BFE794DB
data = length 8, hash CA22068C
data = length 8, hash 79C07075
total output bytes = 25541
sample count = 275
sample 0:
time = 0

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 164431
sample count = 33
sample 0:
time = 0

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 113666
sample count = 23
sample 0:
time = 853333

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 55652
sample count = 12
sample 0:
time = 1792000

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 445
sample count = 1
sample 0:
time = 2730666

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 164431
sample count = 33
sample 0:
time = 0

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 164431
sample count = 33
sample 0:
time = 0

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 113666
sample count = 23
sample 0:
time = 853333

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 55652
sample count = 12
sample 0:
time = 1792000

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 445
sample count = 1
sample 0:
time = 2730666

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 42, hash 83F6895
total output bytes = 164431
sample count = 33
sample 0:
time = 0

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 30, hash 9A8FF207
data = length 3832, hash 8A406249
total output bytes = 26873
sample count = 180
sample 0:
time = 0

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 30, hash 9A8FF207
data = length 3832, hash 8A406249
total output bytes = 17598
sample count = 109
sample 0:
time = 896000

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 30, hash 9A8FF207
data = length 3832, hash 8A406249
total output bytes = 8658
sample count = 49
sample 0:
time = 1821333

View File

@ -27,5 +27,6 @@ track 0:
initializationData:
data = length 30, hash 9A8FF207
data = length 3832, hash 8A406249
total output bytes = 0
sample count = 0
tracksEnded = true

View File

@ -27,6 +27,7 @@ track 0:
initializationData:
data = length 30, hash 9A8FF207
data = length 3832, hash 8A406249
total output bytes = 26873
sample count = 180
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 978
sample count = 150
sample 0:
time = 37657512133

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 13281
sample count = 8
sample 0:
time = 0

View File

@ -26,6 +26,7 @@ track 0:
drmInitData = -
initializationData:
data = length 2, hash 5F7
total output bytes = 30797
sample count = 144
sample 0:
time = 0
@ -625,5 +626,6 @@ track 1:
language = null
drmInitData = -
initializationData:
total output bytes = 0
sample count = 0
tracksEnded = true

View File

@ -25,6 +25,7 @@ track 192:
language = null
drmInitData = -
initializationData:
total output bytes = 1671
sample count = 4
sample 0:
time = 29088
@ -65,6 +66,7 @@ track 224:
drmInitData = -
initializationData:
data = length 22, hash 743CC6F8
total output bytes = 44056
sample count = 2
sample 0:
time = 40000

View File

@ -26,6 +26,7 @@ track 256:
drmInitData = -
initializationData:
data = length 22, hash CE183139
total output bytes = 45026
sample count = 2
sample 0:
time = 33366
@ -57,6 +58,7 @@ track 257:
language = und
drmInitData = -
initializationData:
total output bytes = 5015
sample count = 4
sample 0:
time = 22455

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 88200
sample count = 3
sample 0:
time = 0

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 58802
sample count = 2
sample 0:
time = 333310

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 29402
sample count = 1
sample 0:
time = 666643

View File

@ -25,6 +25,7 @@ track 0:
language = null
drmInitData = -
initializationData:
total output bytes = 2
sample count = 1
sample 0:
time = 999977

View File

@ -91,23 +91,16 @@ public final class FakeExtractorInput implements ExtractorInput {
@Override
public int read(byte[] target, int offset, int length) throws IOException {
checkIOException(readPosition, failedReadPositions);
length = getReadLength(length);
if (readFully(target, offset, length, true)) {
return length;
}
return C.RESULT_END_OF_INPUT;
return readFullyInternal(target, offset, length, true) ? length : C.RESULT_END_OF_INPUT;
}
@Override
public boolean readFully(byte[] target, int offset, int length, boolean allowEndOfInput)
throws IOException {
if (!checkXFully(allowEndOfInput, readPosition, length, failedReadPositions)) {
return false;
}
System.arraycopy(data, readPosition, target, offset, length);
readPosition += length;
peekPosition = readPosition;
return true;
checkIOException(readPosition, failedReadPositions);
return readFullyInternal(target, offset, length, allowEndOfInput);
}
@Override
@ -117,21 +110,15 @@ public final class FakeExtractorInput implements ExtractorInput {
@Override
public int skip(int length) throws IOException {
checkIOException(readPosition, failedReadPositions);
length = getReadLength(length);
if (skipFully(length, true)) {
return length;
}
return C.RESULT_END_OF_INPUT;
return skipFullyInternal(length, true) ? length : C.RESULT_END_OF_INPUT;
}
@Override
public boolean skipFully(int length, boolean allowEndOfInput) throws IOException {
if (!checkXFully(allowEndOfInput, readPosition, length, failedReadPositions)) {
return false;
}
readPosition += length;
peekPosition = readPosition;
return true;
checkIOException(readPosition, failedReadPositions);
return skipFullyInternal(length, allowEndOfInput);
}
@Override
@ -142,7 +129,8 @@ public final class FakeExtractorInput implements ExtractorInput {
@Override
public boolean peekFully(byte[] target, int offset, int length, boolean allowEndOfInput)
throws IOException {
if (!checkXFully(allowEndOfInput, peekPosition, length, failedPeekPositions)) {
checkIOException(peekPosition, failedPeekPositions);
if (!checkXFully(allowEndOfInput, peekPosition, length)) {
return false;
}
System.arraycopy(data, peekPosition, target, offset, length);
@ -157,7 +145,8 @@ public final class FakeExtractorInput implements ExtractorInput {
@Override
public boolean advancePeekPosition(int length, boolean allowEndOfInput) throws IOException {
if (!checkXFully(allowEndOfInput, peekPosition, length, failedPeekPositions)) {
checkIOException(peekPosition, failedPeekPositions);
if (!checkXFully(allowEndOfInput, peekPosition, length)) {
return false;
}
peekPosition += length;
@ -196,13 +185,17 @@ public final class FakeExtractorInput implements ExtractorInput {
throw e;
}
private boolean checkXFully(boolean allowEndOfInput, int position, int length,
SparseBooleanArray failedPositions) throws IOException {
private void checkIOException(int position, SparseBooleanArray failedPositions)
throws SimulatedIOException {
if (simulateIOErrors && !failedPositions.get(position)) {
failedPositions.put(position, true);
peekPosition = readPosition;
throw new SimulatedIOException("Simulated IO error at position: " + position);
}
}
private boolean checkXFully(boolean allowEndOfInput, int position, int length)
throws EOFException {
if (length > 0 && position == data.length) {
if (allowEndOfInput) {
return false;
@ -230,6 +223,26 @@ public final class FakeExtractorInput implements ExtractorInput {
return Math.min(requestedLength, data.length - readPosition);
}
private boolean readFullyInternal(byte[] target, int offset, int length, boolean allowEndOfInput)
throws EOFException {
if (!checkXFully(allowEndOfInput, readPosition, length)) {
return false;
}
System.arraycopy(data, readPosition, target, offset, length);
readPosition += length;
peekPosition = readPosition;
return true;
}
private boolean skipFullyInternal(int length, boolean allowEndOfInput) throws EOFException {
if (!checkXFully(allowEndOfInput, readPosition, length)) {
return false;
}
readPosition += length;
peekPosition = readPosition;
return true;
}
/**
* Builder of {@link FakeExtractorInput} instances.
*/

View File

@ -160,6 +160,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
}
dumper.endBlock().endBlock();
dumper.add("total output bytes", sampleData.length);
dumper.add("sample count", sampleTimesUs.size());
for (int i = 0; i < sampleTimesUs.size(); i++) {