Verify error code when usage entry in use

Merge from Widevine repo of http://go/wvgerrit/98265

Previously, if we tried to shrink the usage table over an entry in
use, we expected an error. Now, we expect the specific error,
OEMCrypto_ERROR_ENTRY_IN_USE.

Test: unit tests on taimen
Bug: 124776024
Change-Id: I2b4b872943bf65401c0a6b5dc1237d77341b1f5b
This commit is contained in:
Fred Gylys-Colwell
2020-04-18 14:28:50 -07:00
parent 15b1cd9cc9
commit a3a61a68c4

View File

@@ -5719,19 +5719,29 @@ class OEMCryptoUsageTableDefragTest : public OEMCryptoUsageTableTest {
void ShrinkHeader(uint32_t new_size,
OEMCryptoResult expected_result = OEMCrypto_SUCCESS) {
// We call OEMCrypto_ShrinkUsageTableHeader once with a zero length buffer,
// so that OEMCrypto can tell us how big the buffer should be.
size_t header_buffer_length = 0;
OEMCryptoResult sts = OEMCrypto_ShrinkUsageTableHeader(
new_size, nullptr, &header_buffer_length);
// If we are expecting success, then the first call shall return
// SHORT_BUFFER. However, if we are not expecting success, this first call
// may return either SHORT_BUFFER or the expect error.
if (expected_result == OEMCrypto_SUCCESS) {
ASSERT_EQ(OEMCrypto_ERROR_SHORT_BUFFER, sts);
} else {
ASSERT_NE(OEMCrypto_SUCCESS, sts);
if (sts != OEMCrypto_ERROR_SHORT_BUFFER) return;
} else if (sts != OEMCrypto_ERROR_SHORT_BUFFER) {
// If we got any thing from the first call, it should be the expected
// error, and we don't need to call a second time.
ASSERT_EQ(expected_result, sts);
return;
}
// If the first call resulted in SHORT_BUFFER, we should resize the buffer
// and try again.
ASSERT_LT(0u, header_buffer_length);
encrypted_usage_header_.resize(header_buffer_length);
sts = OEMCrypto_ShrinkUsageTableHeader(
new_size, encrypted_usage_header_.data(), &header_buffer_length);
// For the second call, we always demand the expected result.
ASSERT_EQ(expected_result, sts);
}
};